[clang] [clang][bytecode] Fix operator new source expression (PR #126870)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 11 23:46:11 PST 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/126870
... for composite element types. Looks like I forgot this in e6030d389571b3f1b0f0c5a35b7fa45937ed0f6c
>From 56245b317f3b71a2c11a188ac0bb4de114ea012c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Wed, 12 Feb 2025 08:44:01 +0100
Subject: [PATCH] [clang][bytecode] Fix operator new source expression
... for composite element types. Looks like I forgot this in
e6030d389571b3f1b0f0c5a35b7fa45937ed0f6c
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 2 +-
clang/test/AST/ByteCode/new-delete.cpp | 12 ++++++++++--
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 0e586725b5869..55ac41736344d 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1683,7 +1683,7 @@ static bool interp__builtin_operator_new(InterpState &S, CodePtr OpPC,
assert(!ElemT);
// Structs etc.
const Descriptor *Desc = S.P.createDescriptor(
- Call, ElemType.getTypePtr(), Descriptor::InlineDescMD,
+ NewCall, ElemType.getTypePtr(), Descriptor::InlineDescMD,
/*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false,
/*Init=*/nullptr);
diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp
index e60ff894c9715..31f066b37858d 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -840,10 +840,17 @@ template <typename T>
struct SS {
constexpr SS(unsigned long long N)
: data(nullptr){
- data = alloc.allocate(N); // #call
+ data = alloc.allocate(N);
for(std::size_t i = 0; i < N; i ++)
- std::construct_at<T>(data + i, i); // #construct_call
+ std::construct_at<T>(data + i, i);
}
+
+ constexpr SS()
+ : data(nullptr){
+ data = alloc.allocate(1);
+ std::construct_at<T>(data);
+ }
+
constexpr T operator[](std::size_t i) const {
return data[i];
}
@@ -855,6 +862,7 @@ struct SS {
T* data;
};
constexpr unsigned short ssmall = SS<unsigned short>(100)[42];
+constexpr auto Ss = SS<S>()[0];
More information about the cfe-commits
mailing list