[PATCH] D135472: [ODRHash] Hash attributes on declarations.

Volodymyr Sapsai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 13 12:14:36 PDT 2022


vsapsai updated this revision to Diff 467564.
vsapsai added a comment.

- Small fixes to address review comments.
- Try to make diagnostics more understandable.
- Check attributes on typedefs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135472/new/

https://reviews.llvm.org/D135472

Files:
  clang/lib/AST/ODRDiagsEmitter.cpp
  clang/lib/AST/ODRHash.cpp
  clang/test/Modules/odr_hash.cpp


Index: clang/test/Modules/odr_hash.cpp
===================================================================
--- clang/test/Modules/odr_hash.cpp
+++ clang/test/Modules/odr_hash.cpp
@@ -3788,6 +3788,32 @@
 // expected-note at second.h:* {{attribute specified here}}
 #endif
 
+#if defined(FIRST)
+struct TypedefAttributePresence {
+  typedef double *AlignedDoublePtr __attribute__((align_value(64)));
+};
+struct TypedefDifferentAttributeValue {
+  typedef double *AlignedDoublePtr __attribute__((align_value(64)));
+};
+#elif defined(SECOND)
+struct TypedefAttributePresence {
+  typedef double *AlignedDoublePtr;
+};
+struct TypedefDifferentAttributeValue {
+  typedef double *AlignedDoublePtr __attribute__((align_value(32)));
+};
+#else
+TypedefAttributePresence testTypedefAttrPresence;
+// expected-error at first.h:* {{'Types::Attributes::TypedefAttributePresence' has different definitions in different modules; first difference is definition in module 'FirstModule' found 'AlignedDoublePtr' with attribute 'align_value'}}
+// expected-note at first.h:* {{attribute specified here}}
+// expected-note at second.h:* {{but in 'SecondModule' found 'AlignedDoublePtr' with no attribute}}
+TypedefDifferentAttributeValue testDifferentArgumentsInTypedefAttribute;
+// expected-error at first.h:* {{'Types::Attributes::TypedefDifferentAttributeValue' has different definitions in different modules; first difference is definition in module 'FirstModule' found 'AlignedDoublePtr' with attribute ' __attribute__((align_value(64)))'}}
+// expected-note at first.h:* {{attribute specified here}}
+// expected-note at second.h:* {{but in 'SecondModule' found 'AlignedDoublePtr' with different attribute argument ' __attribute__((align_value(32)))'}}
+// expected-note at second.h:* {{attribute specified here}}
+#endif
+
 #if defined(FIRST)
 #define PACKED __attribute__((packed))
 struct PACKED AttributeInMacro {
Index: clang/lib/AST/ODRHash.cpp
===================================================================
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -506,6 +506,14 @@
     }
     break;
   }
+  case attr::AlignValue: {
+    auto *M = cast<AlignValueAttr>(A);
+    Expr *AlignmentExpr = M->getAlignment();
+    ID.AddBoolean(AlignmentExpr);
+    if (AlignmentExpr)
+      AddStmt(AlignmentExpr);
+    break;
+  }
   case attr::EnumExtensibility: {
     auto *M = cast<EnumExtensibilityAttr>(A);
     ID.AddInteger(M->getExtensibility());
Index: clang/lib/AST/ODRDiagsEmitter.cpp
===================================================================
--- clang/lib/AST/ODRDiagsEmitter.cpp
+++ clang/lib/AST/ODRDiagsEmitter.cpp
@@ -193,6 +193,10 @@
     DiagNote(TypedefType) << IsTypeAlias << SecondName << SecondType;
     return true;
   }
+
+  if (diagnoseSubMismatchAttr(FirstRecord, FirstModule, SecondModule, FirstTD,
+                              SecondTD))
+    return true;
   return false;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135472.467564.patch
Type: text/x-patch
Size: 2900 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221013/6683902e/attachment.bin>


More information about the cfe-commits mailing list