[clang] [clang][bytecode] Fix operator new source expression (PR #126870)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 11 23:46:49 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
... for composite element types. Looks like I forgot this in e6030d389571b3f1b0f0c5a35b7fa45937ed0f6c
---
Full diff: https://github.com/llvm/llvm-project/pull/126870.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+1-1)
- (modified) clang/test/AST/ByteCode/new-delete.cpp (+10-2)
``````````diff
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];
``````````
</details>
https://github.com/llvm/llvm-project/pull/126870
More information about the cfe-commits
mailing list