[PATCH] D91162: Give up on evaluating value-dependent potential constexpr before hitting the assertion.
Adam Czachorowski via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 10 07:02:25 PST 2020
adamcz created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
adamcz requested review of this revision.
This addresses a new type of assert() crash since
f7f2e4261a98b2da519d58e7f6794b013cda7a4b <https://reviews.llvm.org/rGf7f2e4261a98b2da519d58e7f6794b013cda7a4b>.
EvaluateInPlace assumes it's never called on value-dependent expression,
but it is possible for this to happen when inside CallExpr and errors
were encountered earlier.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91162
Files:
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constexpr-value-dependent.cpp
Index: clang/test/SemaCXX/constexpr-value-dependent.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/constexpr-value-dependent.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -verify
+
+template<int x> constexpr int f(int y) {
+ return x * y;
+}
+
+// The error makes the CallExpr become potentially value-dependent. This used to
+// cause a crash.
+constexpr int test(int x) {
+ return f<1>(f<x>(1)); // expected-error {{no matching function for call to 'f'}} expected-note at -7{{candidate template ignored}}
+}
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -5981,6 +5981,9 @@
static bool EvaluateCallArg(const ParmVarDecl *PVD, const Expr *Arg,
CallRef Call, EvalInfo &Info,
bool NonNull = false) {
+ if (Arg->isValueDependent())
+ return false;
+
LValue LV;
// Create the parameter slot and register its destruction. For a vararg
// argument, create a temporary.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91162.304177.patch
Type: text/x-patch
Size: 1152 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201110/d10bb22f/attachment.bin>
More information about the cfe-commits
mailing list