llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> For primitive array elements, we would accidentally activate the element and then immediate de-activate the array root, which is wrong. Ignore the element from the beginning to the later check never even compares with the element. --- Full diff: https://github.com/llvm/llvm-project/pull/191772.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Pointer.cpp (+5) - (modified) clang/test/AST/ByteCode/placement-new.cpp (+14) ``````````diff diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp index 16c364d279020..a0a1c64bfd975 100644 --- a/clang/lib/AST/ByteCode/Pointer.cpp +++ b/clang/lib/AST/ByteCode/Pointer.cpp @@ -669,6 +669,11 @@ void Pointer::activate() const { }; Pointer B = *this; + // Primitive array elements can't be activated individually, so + // look at the array root instead. + if (B.getFieldDesc()->isPrimitiveArray() && B.isArrayElement()) + B = B.getArray(); + while (!B.isRoot() && B.inUnion()) { activate(B); diff --git a/clang/test/AST/ByteCode/placement-new.cpp b/clang/test/AST/ByteCode/placement-new.cpp index 6091ab5602121..0175d7cfac785 100644 --- a/clang/test/AST/ByteCode/placement-new.cpp +++ b/clang/test/AST/ByteCode/placement-new.cpp @@ -539,3 +539,17 @@ namespace DirectBaseHasNoRecord { static_assert(test_multidim_single_start() == 13); // both-error {{not an integral constant expression}} \ // both-note {{in call to}} } + +namespace PrimArray { + constexpr int test_start_lifetime_array() { + struct S { + union { int storage[4]; }; + }; + S s; + s.storage[0] = 10; + ::new (&s.storage[0]) int(10); + ::new (&s.storage[1]) int(20); + return s.storage[0] + s.storage[1]; + } + static_assert(test_start_lifetime_array() == 30); +} `````````` </details> https://github.com/llvm/llvm-project/pull/191772 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
