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@-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.
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@-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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits