Skip to content

Commit f758735

Browse files
committed
Update code that considers target flags when determining "correct" type signatures
We rely on sema checks on the declaration of type aware new and delete to ensure the correct signature is present, and then overload resolution priority to ensure that type aware operators will always be selected, but there are multiple places where we decide on *different* versions of usual allocation operator type signatures.
1 parent 76ccacb commit f758735

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

clang/lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3428,7 +3428,7 @@ bool FunctionDecl::isUsableAsGlobalAllocationFunctionInConstantEvaluation(
34283428

34293429
// In C++14, the next parameter can be a 'std::size_t' for sized delete.
34303430
bool IsSizedDelete = false;
3431-
if (Ctx.getLangOpts().SizedDeallocation &&
3431+
if ((IsTypeAware || Ctx.getLangOpts().SizedDeallocation) &&
34323432
(getDeclName().getCXXOverloadedOperator() == OO_Delete ||
34333433
getDeclName().getCXXOverloadedOperator() == OO_Array_Delete) &&
34343434
Ctx.hasSameType(Ty, Ctx.getSizeType())) {
@@ -3438,7 +3438,7 @@ bool FunctionDecl::isUsableAsGlobalAllocationFunctionInConstantEvaluation(
34383438

34393439
// In C++17, the next parameter can be a 'std::align_val_t' for aligned
34403440
// new/delete.
3441-
if (Ctx.getLangOpts().AlignedAllocation && !Ty.isNull() && Ty->isAlignValT()) {
3441+
if ((IsTypeAware || Ctx.getLangOpts().AlignedAllocation) && !Ty.isNull() && Ty->isAlignValT()) {
34423442
Consume();
34433443
if (AlignmentParam)
34443444
*AlignmentParam = Params;

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,11 +1753,12 @@ static bool isNonPlacementDeallocationFunction(Sema &S, FunctionDecl *FD) {
17531753
FD->getOverloadedOperator() != OO_Array_Delete)
17541754
return false;
17551755

1756-
unsigned UsualParams = 1;
1757-
if (S.getLangOpts().TypeAwareAllocators && UsualParams < FD->getNumParams() &&
1758-
FD->isTypeAwareOperatorNewOrDelete())
1759-
++UsualParams;
1756+
if (S.getLangOpts().TypeAwareAllocators && FD->isTypeAwareOperatorNewOrDelete()) {
1757+
unsigned UsualParams = /* type-identity */ 1 + /* address */ 1 + /* size */ 1 + /* align*/ 1;
1758+
return UsualParams == FD->getNumParams();
1759+
}
17601760

1761+
unsigned UsualParams = 1;
17611762
if (S.getLangOpts().SizedDeallocation && UsualParams < FD->getNumParams() &&
17621763
S.Context.hasSameUnqualifiedType(
17631764
FD->getParamDecl(UsualParams)->getType(),

clang/test/CodeGenCXX/type-aware-placement-operators.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %clang_cc1 %s -triple arm64-apple-macosx -fexperimental-cxx-type-aware-allocators -emit-llvm -fcxx-exceptions -fexceptions -std=c++23 -o - | FileCheck %s
1+
// RUN: %clang_cc1 %s -triple arm64-apple-macosx -fexperimental-cxx-type-aware-allocators -emit-llvm -fcxx-exceptions -fexceptions -std=c++23 -fsized-deallocation -faligned-allocation -o - | FileCheck %s
2+
// RUN: %clang_cc1 %s -triple arm64-apple-macosx -fexperimental-cxx-type-aware-allocators -emit-llvm -fcxx-exceptions -fexceptions -std=c++23 -fno-sized-deallocation -faligned-allocation -o - | FileCheck %s
3+
// RUN: %clang_cc1 %s -triple arm64-apple-macosx -fexperimental-cxx-type-aware-allocators -emit-llvm -fcxx-exceptions -fexceptions -std=c++23 -fsized-deallocation -fno-aligned-allocation -o - | FileCheck %s
4+
// RUN: %clang_cc1 %s -triple arm64-apple-macosx -fexperimental-cxx-type-aware-allocators -emit-llvm -fcxx-exceptions -fexceptions -std=c++23 -fno-aligned-allocation -fno-sized-deallocation -o - | FileCheck %s
25

36
namespace std {
47
template <class T> struct type_identity {};

clang/test/SemaCXX/type-aware-class-scoped-mismatched-constraints.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions -fcxx-exceptions
1+
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions -fcxx-exceptions -fsized-deallocation -faligned-allocation
2+
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions -fcxx-exceptions -fno-sized-deallocation -faligned-allocation
3+
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions -fcxx-exceptions -fsized-deallocation -fno-aligned-allocation
4+
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions -fcxx-exceptions -fno-sized-deallocation -fno-aligned-allocation
25

36
namespace std {
47
template <class T> struct type_identity {};

clang/test/SemaCXX/type-aware-new-constexpr.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions
2-
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions -fexperimental-new-constant-interpreter
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions -fsized-deallocation -faligned-allocation
2+
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions -fno-sized-deallocation -faligned-allocation
3+
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions -fsized-deallocation -fno-aligned-allocation
4+
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions -fno-sized-deallocation -fno-aligned-allocation
5+
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions -fexperimental-new-constant-interpreter -fsized-deallocation -faligned-allocation
6+
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions -fexperimental-new-constant-interpreter -fno-sized-deallocation -faligned-allocation
7+
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions -fexperimental-new-constant-interpreter -fsized-deallocation -fno-aligned-allocation
8+
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++23 -fexperimental-cxx-type-aware-allocators -fexceptions -fexperimental-new-constant-interpreter -fno-sized-deallocation -fno-aligned-allocation
9+
310

411
namespace std {
512
template <class T> struct type_identity {};

0 commit comments

Comments
 (0)