Skip to content

[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

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3070,18 +3070,24 @@ 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) {
Diag(StartLoc, diag::err_mismatching_type_aware_cleanup_deallocator)
<< 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()) {
Expand Down Expand Up @@ -3224,15 +3230,15 @@ 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();
if (Diagnose && FoundTypeAwareOperator) {
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 =
Expand All @@ -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;
}
}

Expand Down
Loading