-
Notifications
You must be signed in to change notification settings - Fork 155
[CIR][CIRGen] Implement array cookie ABI for AppleARM64 targets #1301
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// RUN: %clang_cc1 -std=c++20 -triple=arm64e-apple-darwin -fclangir -emit-cir %s -o %t.cir | ||
// RUN: FileCheck --input-file=%t.cir %s | ||
|
||
class C { | ||
public: | ||
~C(); | ||
}; | ||
|
||
void t_constant_size_nontrivial() { | ||
auto p = new C[3]; | ||
} | ||
|
||
// CHECK: cir.func @_Z26t_constant_size_nontrivialv() | ||
// CHECK: %0 = cir.alloca !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_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<19> : !u64i | ||
// CHECK: %4 = cir.call @_Znam(%[[#ALLOCATION_SIZE]]) : (!u64i) -> !cir.ptr<!void> | ||
bcardosolopes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// CHECK: %5 = cir.cast(bitcast, %4 : !cir.ptr<!void>), !cir.ptr<!u64i> | ||
// CHECK: %[[#ELEMENT_SIZE:]] = cir.const #cir.int<1> : !u64i | ||
// CHECK: cir.store %[[#ELEMENT_SIZE]], %5 : !u64i, !cir.ptr<!u64i> | ||
// CHECK: %[[#SECOND_COOKIE_OFFSET:]] = cir.const #cir.int<1> : !s32i | ||
// CHECK: %8 = cir.ptr_stride(%5 : !cir.ptr<!u64i>, %[[#SECOND_COOKIE_OFFSET]] : !s32i), !cir.ptr<!u64i> | ||
// CHECK: cir.store %[[#NUM_ELEMENTS]], %8 : !u64i, !cir.ptr<!u64i> | ||
// CHECK: %[[#COOKIE_SIZE:]] = cir.const #cir.int<16> : !s32i | ||
// CHECK: %10 = cir.cast(bitcast, %4 : !cir.ptr<!void>), !cir.ptr<!u8i> | ||
// CHECK: %11 = cir.ptr_stride(%10 : !cir.ptr<!u8i>, %[[#COOKIE_SIZE]] : !s32i), !cir.ptr<!u8i> | ||
// CHECK: %12 = cir.cast(bitcast, %11 : !cir.ptr<!u8i>), !cir.ptr<!ty_C> | ||
// CHECK: cir.store %12, %0 : !cir.ptr<!ty_C>, !cir.ptr<!cir.ptr<!ty_C>> | ||
// CHECK: cir.return | ||
// CHECK: } | ||
|
||
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: %0 = cir.alloca !cir.ptr<!ty_D>, !cir.ptr<!cir.ptr<!ty_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<28> : !u64i | ||
// CHECK: %4 = cir.call @_Znam(%[[#ALLOCATION_SIZE]]) : (!u64i) -> !cir.ptr<!void> | ||
// CHECK: %5 = cir.cast(bitcast, %4 : !cir.ptr<!void>), !cir.ptr<!u64i> | ||
// CHECK: %[[#ELEMENT_SIZE:]] = cir.const #cir.int<4> : !u64i | ||
// CHECK: cir.store %[[#ELEMENT_SIZE]], %5 : !u64i, !cir.ptr<!u64i> | ||
// CHECK: %[[#SECOND_COOKIE_OFFSET:]] = cir.const #cir.int<1> : !s32i | ||
// CHECK: %8 = cir.ptr_stride(%5 : !cir.ptr<!u64i>, %[[#SECOND_COOKIE_OFFSET]] : !s32i), !cir.ptr<!u64i> | ||
// CHECK: cir.store %[[#NUM_ELEMENTS]], %8 : !u64i, !cir.ptr<!u64i> | ||
// CHECK: %[[#COOKIE_SIZE:]] = cir.const #cir.int<16> : !s32i | ||
// CHECK: %10 = cir.cast(bitcast, %4 : !cir.ptr<!void>), !cir.ptr<!u8i> | ||
// CHECK: %11 = cir.ptr_stride(%10 : !cir.ptr<!u8i>, %[[#COOKIE_SIZE]] : !s32i), !cir.ptr<!u8i> | ||
// CHECK: %12 = cir.cast(bitcast, %11 : !cir.ptr<!u8i>), !cir.ptr<!ty_D> | ||
// CHECK: cir.store %12, %0 : !cir.ptr<!ty_D>, !cir.ptr<!cir.ptr<!ty_D>> | ||
// CHECK: cir.return | ||
// CHECK: } |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// RUN: %clang_cc1 -triple=arm64e-apple-darwin -fclangir -emit-llvm %s -o %t.ll | ||
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM | ||
|
||
class C { | ||
public: | ||
~C(); | ||
}; | ||
|
||
void t_constant_size_nontrivial() { | ||
auto p = new C[3]; | ||
} | ||
|
||
// Note: The below differs from the IR emitted by clang without -fclangir in | ||
// several respects. (1) The alloca here has an extra "i64 1" | ||
// (2) The operator new call is missing "noalias noundef nonnull" on | ||
// the call and "noundef" on the argument, (3) The getelementptr is | ||
// missing "inbounds" | ||
|
||
// LLVM: @_Z26t_constant_size_nontrivialv() | ||
// LLVM: %[[ALLOCA:.*]] = alloca ptr, i64 1, align 8 | ||
// LLVM: %[[COOKIE_PTR:.*]] = call ptr @_Znam(i64 19) | ||
// LLVM: store i64 1, ptr %[[COOKIE_PTR]], align 8 | ||
// LLVM: %[[NUM_ELEMENTS_PTR:.*]] = getelementptr i64, ptr %[[COOKIE_PTR]], i64 1 | ||
// LLVM: store i64 3, ptr %[[NUM_ELEMENTS_PTR]], align 8 | ||
// LLVM: %[[ALLOCATED_PTR:.*]] = getelementptr i8, ptr %[[COOKIE_PTR]], i64 16 | ||
// LLVM: store ptr %[[ALLOCATED_PTR]], ptr %[[ALLOCA]], align 8 | ||
|
||
class D { | ||
public: | ||
int x; | ||
~D(); | ||
}; | ||
|
||
void t_constant_size_nontrivial2() { | ||
auto p = new D[3]; | ||
} | ||
|
||
// LLVM: @_Z27t_constant_size_nontrivial2v() | ||
// LLVM: %[[ALLOCA:.*]] = alloca ptr, i64 1, align 8 | ||
// LLVM: %[[COOKIE_PTR:.*]] = call ptr @_Znam(i64 28) | ||
// LLVM: store i64 4, ptr %[[COOKIE_PTR]], align 8 | ||
// LLVM: %[[NUM_ELEMENTS_PTR:.*]] = getelementptr i64, ptr %[[COOKIE_PTR]], i64 1 | ||
// LLVM: store i64 3, ptr %[[NUM_ELEMENTS_PTR]], align 8 | ||
// LLVM: %[[ALLOCATED_PTR:.*]] = getelementptr i8, ptr %[[COOKIE_PTR]], i64 16 | ||
// LLVM: store ptr %[[ALLOCATED_PTR]], ptr %[[ALLOCA]], align 8 |
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.