]> granicus.if.org Git - clang/commitdiff
[ODRHash] Improve typedef handling.
authorRichard Trieu <rtrieu@google.com>
Thu, 29 Jun 2017 22:53:04 +0000 (22:53 +0000)
committerRichard Trieu <rtrieu@google.com>
Thu, 29 Jun 2017 22:53:04 +0000 (22:53 +0000)
Follow typedef chains to find the root type when processing types, and also
keep track of qualifiers.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306753 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ODRHash.cpp
test/Modules/odr_hash.cpp

index 05bed658f3fcc52f93cc8454aa959f08b390400c..5c8d151e081832b871e23f451941aa7b23ead632 100644 (file)
@@ -430,6 +430,13 @@ public:
     Hash.AddQualType(T);
   }
 
+  void AddType(const Type *T) {
+    Hash.AddBoolean(T);
+    if (T) {
+      Hash.AddType(T);
+    }
+  }
+
   void AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
     Hash.AddNestedNameSpecifier(NNS);
   }
@@ -517,7 +524,13 @@ public:
 
   void VisitTypedefType(const TypedefType *T) {
     AddDecl(T->getDecl());
-    AddQualType(T->getDecl()->getUnderlyingType().getCanonicalType());
+    QualType UnderlyingType = T->getDecl()->getUnderlyingType();
+    VisitQualifiers(UnderlyingType.getQualifiers());
+    while (const TypedefType *Underlying =
+               dyn_cast<TypedefType>(UnderlyingType.getTypePtr())) {
+      UnderlyingType = Underlying->getDecl()->getUnderlyingType();
+    }
+    AddType(UnderlyingType.getTypePtr());
     VisitType(T);
   }
 
index c94940c73eb66b90f7a49b3263e2a50dd8bfa32d..f01c4e836a30f285c7ca34c6b0db456134fd62e3 100644 (file)
@@ -1762,6 +1762,22 @@ struct S2 {
 #else
 S2 s2;
 #endif
+
+#if defined(FIRST)
+using A3 = const int;
+using B3 = volatile A3;
+struct S3 {
+  B3 x = 1;
+};
+#elif defined(SECOND)
+using A3 = volatile const int;
+using B3 = A3;
+struct S3 {
+  B3 x = 1;
+};
+#else
+S3 s3;
+#endif
 }
 
 // Keep macros contained to one file.