diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 1eda38e9fa5b1..152a876a42964 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -436,7 +436,7 @@ bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { T Result; if constexpr (DoPush == PushVal::Yes) - S.Stk.push(Result); + S.Stk.push(Value); if constexpr (Op == IncDecOp::Inc) { if (!T::increment(Value, &Result)) { diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index 54f3aefcef2b1..598d748c266b4 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -719,6 +719,23 @@ namespace IncDec { // ref-note {{cannot refer to element -1 of array of 3 elements}} return *p; } + + /// This used to leave a 0 on the stack instead of the previous + /// value of a. + constexpr int bug1Inc() { + int a = 3; + int b = a++; + return b; + } + static_assert(bug1Inc() == 3); + + constexpr int bug1Dec() { + int a = 3; + int b = a--; + return b; + } + static_assert(bug1Dec() == 3); + }; #endif