https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/242785
The result is supposed to point to the first element. >From e3996726552734e351dc3041b893b7a90e57c000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Sun, 15 Nov 2026 07:15:11 +0100 Subject: [PATCH] [clang][bytecode] Decay pointers when adding a zero offset --- clang/lib/AST/ByteCode/Interp.h | 2 +- clang/test/AST/ByteCode/placement-new.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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); } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
