[clang] [clang][ExprConst] Don't try to evaluate value-dependent DeclRefExprs (PR #67778)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 29 02:27:40 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
<details>
<summary>Changes</summary>
The Expression here migth be value dependent, which makes us run into an assertion later on. Just bail out early.
Fixes #<!-- -->67690
---
Full diff: https://github.com/llvm/llvm-project/pull/67778.diff
2 Files Affected:
- (modified) clang/lib/AST/ExprConstant.cpp (+3)
- (modified) clang/test/SemaCXX/constant-expression-cxx1z.cpp (+13)
``````````diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index fea06b97259fe31..8372d81234669fd 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -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.
diff --git a/clang/test/SemaCXX/constant-expression-cxx1z.cpp b/clang/test/SemaCXX/constant-expression-cxx1z.cpp
index 9335626a5c90a4f..a36b8f15f826f41 100644
--- a/clang/test/SemaCXX/constant-expression-cxx1z.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx1z.cpp
@@ -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;
+ }
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/67778
More information about the cfe-commits
mailing list