[PATCH] D148901: [clang][Interp] Fix post-inc/dec operator result
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 26 00:36:28 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3185e47b5a84: [clang][Interp] Fix post-inc/dec operator result (authored by tbaeder).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D148901/new/
https://reviews.llvm.org/D148901
Files:
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/literals.cpp
Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -719,6 +719,23 @@
// 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
Index: clang/lib/AST/Interp/Interp.h
===================================================================
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -436,7 +436,7 @@
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)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148901.517077.patch
Type: text/x-patch
Size: 1038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230426/5a09c231/attachment.bin>
More information about the cfe-commits
mailing list