-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CIR] Upstream basic support for sizeof and alignof #130847
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
AmrDeveloper
merged 6 commits into
llvm:main
from
AmrDeveloper:cir_upstream_sizeof_alignof
Mar 14, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
337b23e
[CIR] Upstream basic support for sizeof and alignof
AmrDeveloper 858383e
Update VisitUnaryExprOrTypeTraitExpr
AmrDeveloper ec780a7
Add recovering value for NYI cases
AmrDeveloper 2857d49
Merge branch 'main' of https://github.com/AmrDeveloper/llvm-project i…
AmrDeveloper 2997d72
Add test for fixed size array type
AmrDeveloper 744687f
Merge branch 'main' into cir_upstream_sizeof_alignof
AmrDeveloper 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,47 @@ | ||
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - 2>&1 | filecheck %s | ||
|
||
void foo() { | ||
unsigned long b = sizeof(bool); | ||
// CHECK: cir.const #cir.int<1> : !cir.int<u, 64> | ||
|
||
unsigned long i = sizeof(int); | ||
// CHECK: cir.const #cir.int<4> : !cir.int<u, 64> | ||
|
||
unsigned long l = sizeof(long); | ||
// CHECK: cir.const #cir.int<8> : !cir.int<u, 64> | ||
|
||
unsigned long f = sizeof(float); | ||
// CHECK: cir.const #cir.int<4> : !cir.int<u, 64> | ||
|
||
unsigned long d = sizeof(double); | ||
// CHECK: cir.const #cir.int<8> : !cir.int<u, 64> | ||
|
||
unsigned long iArr = sizeof(int[5]); | ||
// CHECK: cir.const #cir.int<20> : !cir.int<u, 64> | ||
|
||
unsigned long dArr = sizeof(double[5]); | ||
// CHECK: cir.const #cir.int<40> : !cir.int<u, 64> | ||
} | ||
|
||
void foo2() { | ||
unsigned long b = alignof(bool); | ||
// CHECK: cir.const #cir.int<1> : !cir.int<u, 64> | ||
|
||
unsigned long i = alignof(int); | ||
// CHECK: cir.const #cir.int<4> : !cir.int<u, 64> | ||
|
||
unsigned long l = alignof(long); | ||
// CHECK: cir.const #cir.int<8> : !cir.int<u, 64> | ||
|
||
unsigned long f = alignof(float); | ||
// CHECK: cir.const #cir.int<4> : !cir.int<u, 64> | ||
|
||
unsigned long d = alignof(double); | ||
// CHECK: cir.const #cir.int<8> : !cir.int<u, 64> | ||
|
||
unsigned long iArr = alignof(int[5]); | ||
// CHECK: cir.const #cir.int<4> : !cir.int<u, 64> | ||
|
||
unsigned long dArr = alignof(double[5]); | ||
// CHECK: cir.const #cir.int<8> : !cir.int<u, 64> | ||
} |
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,47 @@ | ||
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o - 2>&1 | FileCheck %s | ||
|
||
void foo() { | ||
unsigned long b = sizeof(bool); | ||
// CHECK: store i64 1, ptr {{%.*}}, align 4 | ||
|
||
unsigned long i = sizeof(int); | ||
// CHECK: store i64 4, ptr {{%.*}}, align 4 | ||
|
||
unsigned long l = sizeof(long); | ||
// CHECK: store i64 8, ptr {{%.*}}, align 4 | ||
|
||
unsigned long f = sizeof(float); | ||
// CHECK: store i64 4, ptr {{%.*}}, align 4 | ||
|
||
unsigned long d = sizeof(double); | ||
// CHECK: store i64 8, ptr {{%.*}}, align 4 | ||
|
||
unsigned long iArr = sizeof(float[5]); | ||
// CHECK: store i64 20, ptr {{%.*}}, align 4 | ||
|
||
unsigned long dArr = sizeof(double[5]); | ||
// CHECK: store i64 40, ptr {{%.*}}, align 4 | ||
} | ||
|
||
void foo2() { | ||
unsigned long b = alignof(bool); | ||
// CHECK: store i64 1, ptr {{%.*}}, align 4 | ||
|
||
unsigned long i = alignof(int); | ||
// CHECK: store i64 4, ptr {{%.*}}, align 4 | ||
|
||
unsigned long l = alignof(long); | ||
// CHECK: store i64 8, ptr {{%.*}}, align 4 | ||
|
||
unsigned long f = alignof(float); | ||
// CHECK: store i64 4, ptr {{%.*}}, align 4 | ||
|
||
unsigned long d = alignof(double); | ||
// CHECK: store i64 8, ptr {{%.*}}, align 4 | ||
|
||
unsigned long iArr = alignof(int[5]); | ||
// CHECK: store i64 4, ptr {{%.*}}, align 4 | ||
|
||
unsigned long dArr = alignof(double[5]); | ||
// CHECK: store i64 8, ptr {{%.*}}, align 4 | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this recovering? Will there be a known-const-int in this case to give a valid value? Same on 169.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check
EvaluateKnownConstInt
and create a dummy value for recoveringThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead that after each of these
errorNYI
diagnostics, we are better just returning a constant value that is reasonably sensible. A1
or aptr-size
both seem reasonable to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice i used 1 as recovering value for unimplemented yet cases