diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 38caee0e7a609..87bcf8130a73b 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -177,13 +177,12 @@ enum class ArithOp { Add, Sub }; // Returning values //===----------------------------------------------------------------------===// -template ::T> +template ::T> bool Ret(InterpState &S, CodePtr &PC, APValue &Result) { const T &Ret = S.Stk.pop(); assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame"); - if (Builtin || !S.checkingPotentialConstantExpression()) + if (!S.checkingPotentialConstantExpression() || S.Current->Caller) S.Current->popArgs(); if (InterpFrame *Caller = S.Current->Caller) { @@ -200,10 +199,9 @@ bool Ret(InterpState &S, CodePtr &PC, APValue &Result) { return true; } -template inline bool RetVoid(InterpState &S, CodePtr &PC, APValue &Result) { assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame"); - if (Builtin || !S.checkingPotentialConstantExpression()) + if (!S.checkingPotentialConstantExpression() || S.Current->Caller) S.Current->popArgs(); if (InterpFrame *Caller = S.Current->Caller) { diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp b/clang/lib/AST/Interp/InterpBuiltin.cpp index c11f22aa94cac..0d0859a4cd284 100644 --- a/clang/lib/AST/Interp/InterpBuiltin.cpp +++ b/clang/lib/AST/Interp/InterpBuiltin.cpp @@ -64,12 +64,12 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) { switch (F->getBuiltinID()) { case Builtin::BI__builtin_is_constant_evaluated: S.Stk.push(Boolean::from(S.inConstantContext())); - return Ret(S, OpPC, Dummy); + return Ret(S, OpPC, Dummy); case Builtin::BI__builtin_assume: - return RetVoid(S, OpPC, Dummy); + return RetVoid(S, OpPC, Dummy); case Builtin::BI__builtin_strcmp: if (interp__builtin_strcmp(S, OpPC, Frame)) - return Ret(S, OpPC, Dummy); + return Ret(S, OpPC, Dummy); return false; default: return false; diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 5bb48ffc54dd5..629d0323e1d2e 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -257,3 +257,11 @@ namespace InvalidCall { // ref-note {{in call to 'SS()'}} } + +namespace CallWithArgs { + /// This used to call problems during checkPotentialConstantExpression() runs. + constexpr void g(int a) {} + constexpr void f() { + g(0); + } +}