Skip to content

[clang][ExprConst] Don't try to evaluate value-dependent DeclRefExprs #67778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}}
}
}