Skip to content

Commit 792fb35

Browse files
Test only reduced BMI
1 parent 12d918f commit 792fb35

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

clang/include/clang/AST/DeclTemplate.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,8 @@ class NonTypeTemplateParmDecl final
13661366
DefaultArgStorage<NonTypeTemplateParmDecl, TemplateArgumentLoc *>;
13671367
DefArgStorage DefaultArgument;
13681368

1369+
bool PlaceholderTypeConstraintInitialized = false;
1370+
13691371
// FIXME: Collapse this into TemplateParamPosition; or, just move depth/index
13701372
// down here to save memory.
13711373

@@ -1534,13 +1536,11 @@ class NonTypeTemplateParmDecl final
15341536
/// Return the constraint introduced by the placeholder type of this non-type
15351537
/// template parameter (if any).
15361538
Expr *getPlaceholderTypeConstraint() const {
1537-
return hasPlaceholderTypeConstraint() ? *getTrailingObjects<Expr *>() :
1538-
nullptr;
1539+
return PlaceholderTypeConstraintInitialized ? *getTrailingObjects<Expr *>()
1540+
: nullptr;
15391541
}
15401542

1541-
void setPlaceholderTypeConstraint(Expr *E) {
1542-
*getTrailingObjects<Expr *>() = E;
1543-
}
1543+
void setPlaceholderTypeConstraint(Expr *E);
15441544

15451545
/// Determine whether this non-type template parameter's type has a
15461546
/// placeholder with a type-constraint.

clang/lib/AST/DeclTemplate.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,16 @@ void NonTypeTemplateParmDecl::setDefaultArgument(
853853
DefaultArgument.set(new (C) TemplateArgumentLoc(DefArg));
854854
}
855855

856+
void NonTypeTemplateParmDecl::setPlaceholderTypeConstraint(Expr *E) {
857+
assert(hasPlaceholderTypeConstraint() &&
858+
"setPlaceholderTypeConstraint called on a NonTypeTemplateParmDecl "
859+
"without constraint");
860+
assert(!PlaceholderTypeConstraintInitialized && "PlaceholderTypeConstraint "
861+
"was already initialized!");
862+
*getTrailingObjects<Expr *>() = E;
863+
PlaceholderTypeConstraintInitialized = true;
864+
}
865+
856866
//===----------------------------------------------------------------------===//
857867
// TemplateTemplateParmDecl Method Implementations
858868
//===----------------------------------------------------------------------===//

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2684,7 +2684,7 @@ void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
26842684
// TemplateParmPosition.
26852685
D->setDepth(Record.readInt());
26862686
D->setPosition(Record.readInt());
2687-
if (D->hasPlaceholderTypeConstraint())
2687+
if (Record.readBool()) // PlaceholderTypeConstraintInitialized
26882688
D->setPlaceholderTypeConstraint(Record.readExpr());
26892689
if (D->isExpandedParameterPack()) {
26902690
auto TypesAndInfos =

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,15 +1983,17 @@ void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
19831983
// For an expanded parameter pack, record the number of expansion types here
19841984
// so that it's easier for deserialization to allocate the right amount of
19851985
// memory.
1986-
Expr *TypeConstraint = D->getPlaceholderTypeConstraint();
1987-
Record.push_back(!!TypeConstraint);
1986+
Record.push_back(D->hasPlaceholderTypeConstraint());
19881987
if (D->isExpandedParameterPack())
19891988
Record.push_back(D->getNumExpansionTypes());
19901989

19911990
VisitDeclaratorDecl(D);
19921991
// TemplateParmPosition.
19931992
Record.push_back(D->getDepth());
19941993
Record.push_back(D->getPosition());
1994+
Expr *TypeConstraint = D->getPlaceholderTypeConstraint();
1995+
Record.push_back(/*PlaceholderTypeConstraintInitialized=*/TypeConstraint !=
1996+
nullptr);
19951997
if (TypeConstraint)
19961998
Record.AddStmt(TypeConstraint);
19971999

clang/test/Modules/malformed-constraint-template-non-type-parm-decl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// RUN: %clang_cc1 -std=c++20 mod.cppm -emit-module-interface -o mod.pcm -fallow-pcm-with-compiler-errors -verify
66
// RUN: %clang_cc1 -std=c++20 main.cpp -fmodule-file=mod=mod.pcm -verify -fallow-pcm-with-compiler-errors -fsyntax-only -ast-dump-all | FileCheck %s
77

8+
// RUN: %clang_cc1 -std=c++20 mod.cppm -emit-reduced-module-interface -o mod.pcm -fallow-pcm-with-compiler-errors -verify
9+
// RUN: %clang_cc1 -std=c++20 main.cpp -fmodule-file=mod=mod.pcm -verify -fallow-pcm-with-compiler-errors -fsyntax-only -ast-dump-all | FileCheck %s
10+
811
//--- mod.cppm
912
export module mod;
1013

@@ -29,7 +32,6 @@ import mod;
2932

3033
// CHECK: |-FunctionTemplateDecl {{.*}} <line:11:1, line:12:22> col:6 imported in mod hidden invalid cos
3134
// CHECK-NEXT: | |-NonTypeTemplateParmDecl {{.*}} <line:11:10, col:34> col:34 imported in mod hidden referenced invalid 'ReferenceOf<angle> auto' depth 0 index 0 R
32-
// CHECK-NEXT: | | `-RecoveryExpr {{.*}} <col:10, col:34> 'ReferenceOf<angle> auto' contains-errors lvalue
3335
// CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} <col:37, col:46> col:46 imported in mod hidden referenced typename depth 0 index 1 Rep
3436
// CHECK-NEXT: | |-RequiresExpr {{.*}} <col:60, col:84> 'bool'
3537
// CHECK-NEXT: | | |-ParmVarDecl {{.*}} <col:69, col:73> col:73 imported in mod hidden referenced v 'Rep'
@@ -42,7 +44,6 @@ import mod;
4244

4345
// CHECK: |-FunctionTemplateDecl {{.*}} <line:15:1, line:16:22> col:6 imported in mod hidden invalid tan
4446
// CHECK-NEXT: | |-NonTypeTemplateParmDecl {{.*}} <line:15:10, col:34> col:34 imported in mod hidden referenced invalid 'ReferenceOf<angle> auto' depth 0 index 0 R
45-
// CHECK-NEXT: | | `-RecoveryExpr {{.*}} <col:10, col:34> 'ReferenceOf<angle> auto' contains-errors lvalue
4647
// CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} <col:37, col:46> col:46 imported in mod hidden referenced typename depth 0 index 1 Rep
4748
// CHECK-NEXT: | |-RequiresExpr {{.*}} <col:60, col:84> 'bool'
4849
// CHECK-NEXT: | | |-ParmVarDecl {{.*}} <col:69, col:73> col:73 imported in mod hidden referenced v 'Rep'

0 commit comments

Comments
 (0)