[clang] [clang][ExprConst] Don't try to evaluate value-dependent DeclRefExprs (PR #67778)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 29 02:25:59 PDT 2023
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/67778
The Expression here migth be value dependent, which makes us run into an assertion later on. Just bail out early.
Fixes #67690
>From c696a6e15404235cf9cab8fc69a39e828d5da03e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 29 Sep 2023 11:23:55 +0200
Subject: [PATCH] [clang][ExprConst] Don't try to evaluate value-dependent
DeclRefExprs
The Expression here migth be value dependent, which makes us run into an
assertion later on. Just bail out early.
Fixes #67690
---
clang/lib/AST/ExprConstant.cpp | 3 +++
clang/test/SemaCXX/constant-expression-cxx1z.cpp | 13 +++++++++++++
2 files changed, 16 insertions(+)
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;
+ }
+}
More information about the cfe-commits
mailing list