[clang] [TBAA] Don't emit pointer tbaa for unnamed structs or unions. (PR #116596)
John McCall via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 21 13:07:14 PST 2024
================
@@ -249,6 +249,21 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
if (!Ty->isRecordType())
return AnyPtr;
+ // For unnamed structs or unions C's compatible types rule applies. Two
+ // compatible types in different compilation units can have different
+ // mangled names, meaning the metadata emitted below would incorrectly
+ // mark them as no-alias. Use AnyPtr for such types in both C and C++, as
+ // C and C++ types may be visible when doing LTO.
+ //
+ // Note that using AnyPtr is overly conservative. We could summarize the
+ // members of the type, as per the C compatibility rule in the future.
+ // This also covers anonymous structs and unions, which have a different
+ // compatibility rule, but it doesn't matter because you can never have a
+ // pointer to an anonymous struct or union.
+ const auto *RT = Ty->getAs<RecordType>();
+ if (RT && !RT->getDecl()->getDeclName())
----------------
rjmccall wrote:
This `getAs<>` is now redundant with the `isRecordType()` above; please do the `getAs<>` above and test `RT` there, and then you can test this here.
https://github.com/llvm/llvm-project/pull/116596
More information about the cfe-commits
mailing list