r306753 - [ODRHash] Improve typedef handling.

Richard Trieu via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 29 15:53:04 PDT 2017


Author: rtrieu
Date: Thu Jun 29 15:53:04 2017
New Revision: 306753

URL: http://llvm.org/viewvc/llvm-project?rev=306753&view=rev
Log:
[ODRHash] Improve typedef handling.

Follow typedef chains to find the root type when processing types, and also
keep track of qualifiers.

Modified:
    cfe/trunk/lib/AST/ODRHash.cpp
    cfe/trunk/test/Modules/odr_hash.cpp

Modified: cfe/trunk/lib/AST/ODRHash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=306753&r1=306752&r2=306753&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ODRHash.cpp (original)
+++ cfe/trunk/lib/AST/ODRHash.cpp Thu Jun 29 15:53:04 2017
@@ -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);
   }
 

Modified: cfe/trunk/test/Modules/odr_hash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash.cpp?rev=306753&r1=306752&r2=306753&view=diff
==============================================================================
--- cfe/trunk/test/Modules/odr_hash.cpp (original)
+++ cfe/trunk/test/Modules/odr_hash.cpp Thu Jun 29 15:53:04 2017
@@ -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.




More information about the cfe-commits mailing list