-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[CIR] Add array new cookie support #163649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jiang1997
wants to merge
9
commits into
llvm:main
Choose a base branch
from
jiang1997:port-#1297
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+290
−16
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e5d686b
[CIR] Add array new cookie support
jiang1997 2c79974
Update clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
jiang1997 0976fa1
Update clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
jiang1997 76a3022
Update clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
jiang1997 b5434f0
Update clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
jiang1997 162579f
Update clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
jiang1997 f5fca25
Update clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
jiang1997 eaea17d
Update clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
jiang1997 66ccc09
Merge branch 'llvm:main' into port-#1297
jiang1997 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,6 +208,125 @@ void t_new_constant_size() { | |
// OGCG: %[[CALL:.*]] = call noalias noundef nonnull ptr @_Znam(i64 noundef 128) | ||
// OGCG: store ptr %[[CALL]], ptr %[[P_ADDR]], align 8 | ||
|
||
class C { | ||
public: | ||
~C(); | ||
}; | ||
|
||
void t_constant_size_nontrivial() { | ||
auto p = new C[3]; | ||
} | ||
|
||
// CHECK: cir.func{{.*}} @_Z26t_constant_size_nontrivialv() | ||
// CHECK: %[[P_ADDR:.*]] = cir.alloca !cir.ptr<!rec_C>, !cir.ptr<!cir.ptr<!rec_C>>, ["p", init] {alignment = 8 : i64} | ||
// CHECK: %[[#NUM_ELEMENTS:]] = cir.const #cir.int<3> : !u64i | ||
// CHECK: %[[#SIZE_WITHOUT_COOKIE:]] = cir.const #cir.int<3> : !u64i | ||
// CHECK: %[[#ALLOCATION_SIZE:]] = cir.const #cir.int<11> : !u64i | ||
// CHECK: %[[RAW_PTR:.*]] = cir.call @_Znam(%[[#ALLOCATION_SIZE]]) : (!u64i) -> !cir.ptr<!void> | ||
// CHECK: %[[COOKIE_PTR_BASE:.*]] = cir.cast bitcast %[[RAW_PTR]] : !cir.ptr<!void> -> !cir.ptr<!cir.ptr<!u8i>> | ||
// CHECK: %[[COOKIE_PTR:.*]] = cir.cast bitcast %[[COOKIE_PTR_BASE]] : !cir.ptr<!cir.ptr<!u8i>> -> !cir.ptr<!u64i> | ||
// CHECK: cir.store align(8) %[[#NUM_ELEMENTS]], %[[COOKIE_PTR]] : !u64i, !cir.ptr<!u64i> | ||
// CHECK: %[[#COOKIE_SIZE:]] = cir.const #cir.int<8> : !s32i | ||
// CHECK: %[[DATA_PTR_RAW:.*]] = cir.ptr_stride %[[COOKIE_PTR_BASE]], %[[#COOKIE_SIZE]] : (!cir.ptr<!cir.ptr<!u8i>>, !s32i) -> !cir.ptr<!cir.ptr<!u8i>> | ||
// CHECK: %[[DATA_PTR_VOID:.*]] = cir.cast bitcast %[[DATA_PTR_RAW]] : !cir.ptr<!cir.ptr<!u8i>> -> !cir.ptr<!void> | ||
// CHECK: %[[DATA_PTR:.*]] = cir.cast bitcast %[[DATA_PTR_VOID]] : !cir.ptr<!void> -> !cir.ptr<!rec_C> | ||
// CHECK: cir.store align(8) %[[DATA_PTR]], %[[P_ADDR]] : !cir.ptr<!rec_C>, !cir.ptr<!cir.ptr<!rec_C>> | ||
// CHECK: cir.return | ||
// CHECK: } | ||
|
||
// LLVM: @_Z26t_constant_size_nontrivialv() | ||
// LLVM: %[[ALLOCA:.*]] = alloca ptr, i64 1, align 8 | ||
// LLVM: %[[COOKIE_PTR:.*]] = call ptr @_Znam(i64 11) | ||
// LLVM: store i64 3, ptr %[[COOKIE_PTR]], align 8 | ||
// LLVM: %[[ALLOCATED_PTR:.*]] = getelementptr ptr, ptr %[[COOKIE_PTR]], i64 8 | ||
// LLVM: store ptr %[[ALLOCATED_PTR]], ptr %[[ALLOCA]], align 8 | ||
|
||
// OGCG: @_Z26t_constant_size_nontrivialv() | ||
// OGCG: %[[ALLOCA:.*]] = alloca ptr, align 8 | ||
// OGCG: %[[COOKIE_PTR:.*]] = call noalias noundef nonnull ptr @_Znam(i64 noundef 11) | ||
// OGCG: store i64 3, ptr %[[COOKIE_PTR]], align 8 | ||
// OGCG: %[[ALLOCATED_PTR:.*]] = getelementptr inbounds i8, ptr %[[COOKIE_PTR]], i64 8 | ||
// OGCG: store ptr %[[ALLOCATED_PTR]], ptr %[[ALLOCA]], align 8 | ||
|
||
class D { | ||
public: | ||
int x; | ||
~D(); | ||
}; | ||
|
||
void t_constant_size_nontrivial2() { | ||
auto p = new D[3]; | ||
} | ||
|
||
// In this test SIZE_WITHOUT_COOKIE isn't used, but it would be if there were | ||
// an initializer. | ||
|
||
// CHECK: cir.func{{.*}} @_Z27t_constant_size_nontrivial2v() | ||
// CHECK: %[[P_ADDR:.*]] = cir.alloca !cir.ptr<!rec_D>, !cir.ptr<!cir.ptr<!rec_D>>, ["p", init] {alignment = 8 : i64} | ||
// CHECK: %[[#NUM_ELEMENTS:]] = cir.const #cir.int<3> : !u64i | ||
// CHECK: %[[#SIZE_WITHOUT_COOKIE:]] = cir.const #cir.int<12> : !u64i | ||
// CHECK: %[[#ALLOCATION_SIZE:]] = cir.const #cir.int<20> : !u64i | ||
// CHECK: %[[RAW_PTR:.*]] = cir.call @_Znam(%[[#ALLOCATION_SIZE]]) : (!u64i) -> !cir.ptr<!void> | ||
// CHECK: %[[COOKIE_PTR_BASE:.*]] = cir.cast bitcast %[[RAW_PTR]] : !cir.ptr<!void> -> !cir.ptr<!cir.ptr<!u8i>> | ||
// CHECK: %[[COOKIE_PTR:.*]] = cir.cast bitcast %[[COOKIE_PTR_BASE]] : !cir.ptr<!cir.ptr<!u8i>> -> !cir.ptr<!u64i> | ||
// CHECK: cir.store align(8) %[[#NUM_ELEMENTS]], %[[COOKIE_PTR]] : !u64i, !cir.ptr<!u64i> | ||
// CHECK: %[[#COOKIE_SIZE:]] = cir.const #cir.int<8> : !s32i | ||
// CHECK: %[[DATA_PTR_RAW:.*]] = cir.ptr_stride %[[COOKIE_PTR_BASE]], %[[#COOKIE_SIZE]] : (!cir.ptr<!cir.ptr<!u8i>>, !s32i) -> !cir.ptr<!cir.ptr<!u8i>> | ||
// CHECK: %[[DATA_PTR_VOID:.*]] = cir.cast bitcast %[[DATA_PTR_RAW]] : !cir.ptr<!cir.ptr<!u8i>> -> !cir.ptr<!void> | ||
// CHECK: %[[DATA_PTR:.*]] = cir.cast bitcast %[[DATA_PTR_VOID]] : !cir.ptr<!void> -> !cir.ptr<!rec_D> | ||
// CHECK: cir.store align(8) %[[DATA_PTR]], %[[P_ADDR]] : !cir.ptr<!rec_D>, !cir.ptr<!cir.ptr<!rec_D>> | ||
// CHECK: cir.return | ||
// CHECK: } | ||
|
||
// LLVM: @_Z27t_constant_size_nontrivial2v() | ||
// LLVM: %[[ALLOCA:.*]] = alloca ptr, i64 1, align 8 | ||
// LLVM: %[[COOKIE_PTR:.*]] = call ptr @_Znam(i64 20) | ||
// LLVM: store i64 3, ptr %[[COOKIE_PTR]], align 8 | ||
// LLVM: %[[ALLOCATED_PTR:.*]] = getelementptr ptr, ptr %[[COOKIE_PTR]], i64 8 | ||
// LLVM: store ptr %[[ALLOCATED_PTR]], ptr %[[ALLOCA]], align 8 | ||
|
||
struct alignas(16) E { | ||
int x; | ||
~E(); | ||
}; | ||
|
||
void t_align16_nontrivial() { | ||
auto p = new E[2]; | ||
} | ||
|
||
// CHECK: cir.func{{.*}} @_Z20t_align16_nontrivialv() | ||
// CHECK: %[[P_ADDR:.*]] = cir.alloca !cir.ptr<!rec_E>, !cir.ptr<!cir.ptr<!rec_E>>, ["p", init] {alignment = 8 : i64} | ||
// CHECK: %[[#NUM_ELEMENTS:]] = cir.const #cir.int<2> : !u64i | ||
// CHECK: %[[#SIZE_WITHOUT_COOKIE:]] = cir.const #cir.int<32> : !u64i | ||
// CHECK: %[[#ALLOCATION_SIZE:]] = cir.const #cir.int<48> : !u64i | ||
// CHECK: %[[RAW_PTR:.*]] = cir.call @_Znam(%[[#ALLOCATION_SIZE]]) : (!u64i) -> !cir.ptr<!void> | ||
// CHECK: %[[COOKIE_PTR_BASE:.*]] = cir.cast bitcast %[[RAW_PTR]] : !cir.ptr<!void> -> !cir.ptr<!cir.ptr<!u8i>> | ||
// CHECK: %[[COOKIE_OFFSET:.*]] = cir.const #cir.int<8> : !s32i | ||
// CHECK: %[[COOKIE_PTR_RAW:.*]] = cir.ptr_stride %[[COOKIE_PTR_BASE]], %[[COOKIE_OFFSET]] : (!cir.ptr<!cir.ptr<!u8i>>, !s32i) -> !cir.ptr<!cir.ptr<!u8i>> | ||
// CHECK: %[[COOKIE_PTR:.*]] = cir.cast bitcast %[[COOKIE_PTR_RAW]] : !cir.ptr<!cir.ptr<!u8i>> -> !cir.ptr<!u64i> | ||
// CHECK: cir.store align(8) %[[#NUM_ELEMENTS]], %[[COOKIE_PTR]] : !u64i, !cir.ptr<!u64i> | ||
// CHECK: %[[#COOKIE_SIZE:]] = cir.const #cir.int<16> : !s32i | ||
// CHECK: %[[DATA_PTR_RAW:.*]] = cir.ptr_stride %[[COOKIE_PTR_BASE]], %[[#COOKIE_SIZE]] : (!cir.ptr<!cir.ptr<!u8i>>, !s32i) -> !cir.ptr<!cir.ptr<!u8i>> | ||
// CHECK: %[[DATA_PTR_VOID:.*]] = cir.cast bitcast %[[DATA_PTR_RAW]] : !cir.ptr<!cir.ptr<!u8i>> -> !cir.ptr<!void> | ||
// CHECK: %[[DATA_PTR:.*]] = cir.cast bitcast %[[DATA_PTR_VOID]] : !cir.ptr<!void> -> !cir.ptr<!rec_E> | ||
// CHECK: cir.store align(8) %[[DATA_PTR]], %[[P_ADDR]] : !cir.ptr<!rec_E>, !cir.ptr<!cir.ptr<!rec_E>> | ||
// CHECK: cir.return | ||
// CHECK: } | ||
|
||
// LLVM: @_Z20t_align16_nontrivialv() | ||
// LLVM: %[[ALLOCA:.*]] = alloca ptr, i64 1, align 8 | ||
// LLVM: %[[RAW_PTR:.*]] = call ptr @_Znam(i64 48) | ||
// LLVM: %[[COOKIE_PTR:.*]] = getelementptr ptr, ptr %[[RAW_PTR]], i64 8 | ||
// LLVM: store i64 2, ptr %[[COOKIE_PTR]], align 8 | ||
// LLVM: %[[ALLOCATED_PTR:.*]] = getelementptr ptr, ptr %[[RAW_PTR]], i64 16 | ||
// LLVM: store ptr %[[ALLOCATED_PTR]], ptr %[[ALLOCA]], align 8 | ||
|
||
// OGCG: @_Z27t_constant_size_nontrivial2v() | ||
// OGCG: %[[ALLOCA:.*]] = alloca ptr, align 8 | ||
// OGCG: %[[COOKIE_PTR:.*]] = call noalias noundef nonnull ptr @_Znam(i64 noundef 20) | ||
// OGCG: store i64 3, ptr %[[COOKIE_PTR]], align 8 | ||
// OGCG: %[[ALLOCATED_PTR:.*]] = getelementptr inbounds i8, ptr %[[COOKIE_PTR]], i64 8 | ||
// OGCG: store ptr %[[ALLOCATED_PTR]], ptr %[[ALLOCA]], align 8 | ||
|
||
|
||
void t_new_multidim_constant_size() { | ||
auto p = new double[2][3][4]; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.