Skip to content

Commit

Permalink
[clang][ExprConst] Don't try to evaluate value-dependent DeclRefExprs (
Browse files Browse the repository at this point in the history
…#67778)

The Expression here migth be value dependent, which makes us run into an
assertion later on. Just bail out early.

Fixes #67690
  • Loading branch information
tbaederr authored Oct 5, 2023
1 parent eef35c2 commit 5ef904b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ Bug Fixes in This Version
(`#64462 <https://github.com/llvm/llvm-project/issues/64462>`_)
- Fixes a regression where the ``UserDefinedLiteral`` was not properly preserved
while evaluating consteval functions. (`#63898 <https://github.com/llvm/llvm-project/issues/63898>`_).
- Fix a crash when evaluating value-dependent structured binding
variables at compile time.
Fixes (`#67690 <https://github.com/llvm/llvm-project/issues/67690>`_)

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3357,6 +3357,9 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E,
return false;
}

if (E->isValueDependent())
return false;

// Dig out the initializer, and use the declaration which it's attached to.
// FIXME: We should eventually check whether the variable has a reachable
// initializing declaration.
Expand Down
13 changes: 13 additions & 0 deletions clang/test/SemaCXX/constant-expression-cxx1z.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,16 @@ namespace LambdaCallOp {
p();
}
}

// This used to crash due to an assertion failure,
// see gh#67690
namespace {
struct C {
int x;
};

template <const C *p> void f() {
const auto &[c] = *p;
&c; // expected-warning {{expression result unused}}
}
}

0 comments on commit 5ef904b

Please sign in to comment.