llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

The result is supposed to point to the first element.

---
Full diff: https://github.com/llvm/llvm-project/pull/242785.diff


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Interp.h (+1-1) 
- (modified) clang/test/AST/ByteCode/placement-new.cpp (+10) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 3b1df5fe7615e5..0ffc8492297dcb 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2629,7 +2629,7 @@ bool AddOffset(InterpState &S, CodePtr OpPC) {
   const Pointer &Ptr = S.Stk.pop<Pointer>().expand();
 
   if (Offset.isZero()) {
-    S.Stk.push<Pointer>(Ptr);
+    S.Stk.push<Pointer>(Ptr.atIndex(0).narrow());
     return true;
   }
 
diff --git a/clang/test/AST/ByteCode/placement-new.cpp 
b/clang/test/AST/ByteCode/placement-new.cpp
index 33dc2e595f4858..b734586182a76c 100644
--- a/clang/test/AST/ByteCode/placement-new.cpp
+++ b/clang/test/AST/ByteCode/placement-new.cpp
@@ -584,6 +584,16 @@ namespace PrimArray {
   }
   static_assert(primElem() == 30); // both-error {{not an integral constant 
expression}} \
                                    // both-note {{in call to}}
+}
 
+namespace ZeroOffset {
+  struct S {};
+  constexpr int test() {
+    S *p = std::allocator<S>{}.allocate(1);
+    new (p + 0) S{};
 
+    std::allocator<S>{}.deallocate(p);
+    return 0;
+  }
+  static_assert(test() == 0);
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/242785
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to