Skip to content

Commit 5ef904b

Browse files
authored
[clang][ExprConst] Don't try to evaluate value-dependent DeclRefExprs (#67778)
The Expression here migth be value dependent, which makes us run into an assertion later on. Just bail out early. Fixes #67690
1 parent eef35c2 commit 5ef904b

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

clang/docs/ReleaseNotes.rst

+3
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ Bug Fixes in This Version
339339
(`#64462 <https://github.com/llvm/llvm-project/issues/64462>`_)
340340
- Fixes a regression where the ``UserDefinedLiteral`` was not properly preserved
341341
while evaluating consteval functions. (`#63898 <https://github.com/llvm/llvm-project/issues/63898>`_).
342+
- Fix a crash when evaluating value-dependent structured binding
343+
variables at compile time.
344+
Fixes (`#67690 <https://github.com/llvm/llvm-project/issues/67690>`_)
342345

343346
Bug Fixes to Compiler Builtins
344347
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/ExprConstant.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3357,6 +3357,9 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E,
33573357
return false;
33583358
}
33593359

3360+
if (E->isValueDependent())
3361+
return false;
3362+
33603363
// Dig out the initializer, and use the declaration which it's attached to.
33613364
// FIXME: We should eventually check whether the variable has a reachable
33623365
// initializing declaration.

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

+13
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,16 @@ namespace LambdaCallOp {
177177
p();
178178
}
179179
}
180+
181+
// This used to crash due to an assertion failure,
182+
// see gh#67690
183+
namespace {
184+
struct C {
185+
int x;
186+
};
187+
188+
template <const C *p> void f() {
189+
const auto &[c] = *p;
190+
&c; // expected-warning {{expression result unused}}
191+
}
192+
}

0 commit comments

Comments
 (0)