-
Notifications
You must be signed in to change notification settings - Fork 15.6k
[TBAA] Don't emit pointer tbaa for unnamed structs or unions. #116596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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()) | ||
|
||
| return AnyPtr; | ||
|
|
||
| // For non-builtin types use the mangled name of the canonical type. | ||
| llvm::raw_svector_ostream TyOut(TyName); | ||
| MangleCtx->mangleCanonicalTypeName(QualType(Ty, 0), TyOut); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like this to note that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, added the clarifications as suggested!