Author: Timm Bäder Date: 2023-04-26T09:36:08+02:00 New Revision: 3185e47b5a8444e9fd70b746a7ad679dd131ffe4
URL: https://github.com/llvm/llvm-project/commit/3185e47b5a8444e9fd70b746a7ad679dd131ffe4 DIFF: https://github.com/llvm/llvm-project/commit/3185e47b5a8444e9fd70b746a7ad679dd131ffe4.diff LOG: [clang][Interp] Fix post-inc/dec operator result We pushed the wrong value on the stack, always leaving a 0 behind. Differential Revision: https://reviews.llvm.org/D148901 Added: Modified: clang/lib/AST/Interp/Interp.h clang/test/AST/Interp/literals.cpp Removed: ################################################################################ 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<T>(Result); + S.Stk.push<T>(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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits