-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[clang] Ensure type aware allocators handle transparent decl contexts #138616
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
[clang] Ensure type aware allocators handle transparent decl contexts #138616
Conversation
We were testing the immediate DeclContext for found new and delete operators, which is incorrect if the declarations are contained by a transparent decl as can be induced with extern or export statements.
@llvm/pr-subscribers-clang Author: Oliver Hunt (ojhunt) ChangesWe were testing the immediate DeclContext for found new and delete operators, which is incorrect if the declarations are contained by a transparent decl as can be induced with extern or export statements. Full diff: https://github.com/llvm/llvm-project/pull/138616.diff 1 Files Affected:
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 235ea1529b0b8..5bfd608afba04 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -3070,10 +3070,16 @@ bool Sema::FindAllocationFunctions(
Filter.done();
}
+ auto GetRedeclContext = [](Decl *D) {
+ return D->getDeclContext()->getRedeclContext();
+ };
+
+ DeclContext *OperatorNewContext = GetRedeclContext(OperatorNew);
+
bool FoundGlobalDelete = FoundDelete.empty();
bool IsClassScopedTypeAwareNew =
isTypeAwareAllocation(IAP.PassTypeIdentity) &&
- OperatorNew->getDeclContext()->isRecord();
+ OperatorNewContext->isRecord();
auto DiagnoseMissingTypeAwareCleanupOperator = [&](bool IsPlacementOperator) {
assert(isTypeAwareAllocation(IAP.PassTypeIdentity));
if (Diagnose) {
@@ -3081,7 +3087,7 @@ bool Sema::FindAllocationFunctions(
<< OperatorNew->getDeclName() << IsPlacementOperator << DeleteName;
Diag(OperatorNew->getLocation(), diag::note_type_aware_operator_declared)
<< OperatorNew->isTypeAwareOperatorNewOrDelete()
- << OperatorNew->getDeclName() << OperatorNew->getDeclContext();
+ << OperatorNew->getDeclName() << OperatorNewContext;
}
};
if (IsClassScopedTypeAwareNew && FoundDelete.empty()) {
@@ -3224,6 +3230,7 @@ bool Sema::FindAllocationFunctions(
// deallocation function will be called.
if (Matches.size() == 1) {
OperatorDelete = Matches[0].second;
+ DeclContext *OperatorDeleteContext = GetRedeclContext(OperatorDelete);
bool FoundTypeAwareOperator =
OperatorDelete->isTypeAwareOperatorNewOrDelete() ||
OperatorNew->isTypeAwareOperatorNewOrDelete();
@@ -3231,8 +3238,7 @@ bool Sema::FindAllocationFunctions(
bool MismatchedTypeAwareness =
OperatorDelete->isTypeAwareOperatorNewOrDelete() !=
OperatorNew->isTypeAwareOperatorNewOrDelete();
- bool MismatchedContext =
- OperatorDelete->getDeclContext() != OperatorNew->getDeclContext();
+ bool MismatchedContext = OperatorDeleteContext != OperatorNewContext;
if (MismatchedTypeAwareness || MismatchedContext) {
FunctionDecl *Operators[] = {OperatorDelete, OperatorNew};
bool TypeAwareOperatorIndex =
@@ -3241,16 +3247,15 @@ bool Sema::FindAllocationFunctions(
<< Operators[TypeAwareOperatorIndex]->getDeclName()
<< isPlacementNew
<< Operators[!TypeAwareOperatorIndex]->getDeclName()
- << Operators[TypeAwareOperatorIndex]->getDeclContext();
+ << GetRedeclContext(Operators[TypeAwareOperatorIndex]);
Diag(OperatorNew->getLocation(),
diag::note_type_aware_operator_declared)
<< OperatorNew->isTypeAwareOperatorNewOrDelete()
- << OperatorNew->getDeclName() << OperatorNew->getDeclContext();
+ << OperatorNew->getDeclName() << OperatorNewContext;
Diag(OperatorDelete->getLocation(),
diag::note_type_aware_operator_declared)
<< OperatorDelete->isTypeAwareOperatorNewOrDelete()
- << OperatorDelete->getDeclName()
- << OperatorDelete->getDeclContext();
+ << OperatorDelete->getDeclName() << OperatorDeleteContext;
}
}
|
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.
Can you add tests? Thanks
sigh, I thought I had :D please hold |
…llvm#138616) We were testing the immediate DeclContext for found new and delete operators, which is incorrect if the declarations are contained by a transparent decl as can be induced with extern or export statements.
We were testing the immediate DeclContext for found new and delete operators, which is incorrect if the declarations are contained by a transparent decl as can be induced with extern or export statements.