Skip to content

Commit bc24bde

Browse files
committed
[Clang] Treat constexpr-unknown value as invalid in evaluateValue
1 parent 1cea7d4 commit bc24bde

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

clang/lib/AST/Decl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2587,6 +2587,9 @@ APValue *VarDecl::evaluateValueImpl(SmallVectorImpl<PartialDiagnosticAt> &Notes,
25872587
!Notes.empty())
25882588
Result = false;
25892589

2590+
if (Eval->Evaluated.allowConstexprUnknown())
2591+
Result = false;
2592+
25902593
// Ensure the computed APValue is cleaned up later if evaluation succeeded,
25912594
// or that it's empty (so that there's nothing to clean up) if evaluation
25922595
// failed.

clang/lib/AST/ExprConstant.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3628,8 +3628,6 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E,
36283628
if (AllowConstexprUnknown) {
36293629
if (!Result)
36303630
Result = &Info.CurrentCall->createConstexprUnknownAPValues(VD, Base);
3631-
else
3632-
Result->setConstexprUnknown();
36333631
}
36343632
return true;
36353633
}

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,9 +1884,11 @@ llvm::Constant *ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &D) {
18841884
// Try to emit the initializer. Note that this can allow some things that
18851885
// are not allowed by tryEmitPrivateForMemory alone.
18861886
// Bail out on constexpr-unknown values since they are invalid in CodeGen.
1887-
if (APValue *value = D.evaluateValue();
1888-
value && !value->allowConstexprUnknown())
1887+
if (APValue *value = D.evaluateValue()) {
1888+
assert(!value->allowConstexprUnknown() &&
1889+
"Constexpr unknown values are not allowed in CodeGen");
18891890
return tryEmitPrivateForMemory(*value, destType);
1891+
}
18901892

18911893
return nullptr;
18921894
}

clang/test/SemaCXX/constant-expression-cxx11.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ namespace CaseStatements {
122122
}
123123

124124
extern int &Recurse1;
125-
int &Recurse2 = Recurse1; // expected-note {{declared here}}
125+
int &Recurse2 = Recurse1; // pre-cxx23-note {{declared here}}
126126
int &Recurse1 = Recurse2;
127-
constexpr int &Recurse3 = Recurse2; // expected-error {{must be initialized by a constant expression}} expected-note {{initializer of 'Recurse2' is not a constant expression}}
127+
constexpr int &Recurse3 = Recurse2; // expected-error {{must be initialized by a constant expression}} pre-cxx23-note {{initializer of 'Recurse2' is not a constant expression}}
128128

129129
extern const int RecurseA;
130130
const int RecurseB = RecurseA; // expected-note {{declared here}}

0 commit comments

Comments
 (0)