[PATCH] D104963: [ODR] Fix using uninitialized FunctionTypeBits.FastTypeQuals in FunctionNoProtoType.

Volodymyr Sapsai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 25 17:24:54 PDT 2021


vsapsai created this revision.
vsapsai added reviewers: rsmith, riccibruno.
Herald added a subscriber: ributzka.
vsapsai requested review of this revision.
Herald added a project: clang.

FastTypeQuals are used only by FunctionProtoType and put in
FunctionTypeBitfields in FunctionType to pack with the other bitfields.
So in ODR-hashing they should be used only for FunctionProtoType but not
for FunctionNoProtoType or for common FunctionType.

rdar://65305646


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104963

Files:
  clang/lib/AST/ODRHash.cpp
  clang/test/Modules/odr_hash-record.c


Index: clang/test/Modules/odr_hash-record.c
===================================================================
--- clang/test/Modules/odr_hash-record.c
+++ clang/test/Modules/odr_hash-record.c
@@ -381,6 +381,21 @@
 struct TSS1 *tss1;
 #endif
 
+// Function pointer in a struct.
+#if defined(FIRST)
+typedef void (*HandlerProcPtr)();
+struct Handler {
+    HandlerProcPtr procPtr;
+};
+#elif defined(SECOND)
+typedef void (*HandlerProcPtr)();
+struct Handler {
+    HandlerProcPtr procPtr;
+};
+#else
+struct Handler h;
+#endif
+
 // Keep macros contained to one file.
 #ifdef FIRST
 #undef FIRST
Index: clang/lib/AST/ODRHash.cpp
===================================================================
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -910,9 +910,6 @@
   void VisitFunctionType(const FunctionType *T) {
     AddQualType(T->getReturnType());
     T->getExtInfo().Profile(ID);
-    Hash.AddBoolean(T->isConst());
-    Hash.AddBoolean(T->isVolatile());
-    Hash.AddBoolean(T->isRestrict());
     VisitType(T);
   }
 
@@ -921,6 +918,9 @@
   }
 
   void VisitFunctionProtoType(const FunctionProtoType *T) {
+    Hash.AddBoolean(T->isConst());
+    Hash.AddBoolean(T->isVolatile());
+    Hash.AddBoolean(T->isRestrict());
     ID.AddInteger(T->getNumParams());
     for (auto ParamType : T->getParamTypes())
       AddQualType(ParamType);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104963.354635.patch
Type: text/x-patch
Size: 1360 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210626/4cc76974/attachment.bin>


More information about the cfe-commits mailing list