-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[CIR] CountOf VLA with Array element type #169404
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 2 commits into
llvm:main
from
AmrDeveloper:cir_count_of_vla_of_array
Nov 26, 2025
+103
−8
Merged
Changes from all commits
Commits
Show all changes
2 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
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,52 @@ | ||
| // RUN: %clang_cc1 -std=c2y -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir | ||
| // RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR | ||
| // RUN: %clang_cc1 -std=c2y -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll | ||
| // RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM | ||
| // RUN: %clang_cc1 -std=c2y -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll | ||
| // RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG | ||
|
|
||
| unsigned long vla_with_array_element_type_with_const_size() { | ||
| long size; | ||
| return _Countof(int[5][size]); | ||
| } | ||
|
|
||
| // CIR: %[[RET_ADDR:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["__retval"] | ||
| // CIR: %[[SIZE_ADDR:.*]] = cir.alloca !s64i, !cir.ptr<!s64i>, ["size"] | ||
| // CIR: %[[CONST_5:.*]] = cir.const #cir.int<5> : !u64i | ||
| // CIR: cir.store %[[CONST_5]], %[[RET_ADDR]] : !u64i, !cir.ptr<!u64i> | ||
| // CIR: %[[RET_VAL:.*]] = cir.load %[[RET_ADDR]] : !cir.ptr<!u64i>, !u64i | ||
| // CIR: cir.return %[[RET_VAL]] : !u64i | ||
|
|
||
| // LLVM: %[[RET_ADDR:.*]] = alloca i64, i64 1, align 8 | ||
| // LLVM: %[[SIZE_ADDR:.*]] = alloca i64, i64 1, align 8 | ||
| // LLVM: store i64 5, ptr %[[RET_ADDR]], align 8 | ||
| // LLVM: %[[RET_VAL:.*]] = load i64, ptr %[[RET_ADDR]], align 8 | ||
| // LLVM: ret i64 %[[RET_VAL]] | ||
|
|
||
| // OGCG: %[[SIZE_ADDR:.*]] = alloca i64, align 8 | ||
| // OGCG: ret i64 5 | ||
|
|
||
| unsigned long vla_with_array_element_type_non_const_size() { | ||
| long size; | ||
| return _Countof(int[size][size]); | ||
| } | ||
|
|
||
| // CIR: %[[REET_ADDR:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["__retval"] | ||
| // CIR: %[[SIZE_ADDR:.*]] = cir.alloca !s64i, !cir.ptr<!s64i>, ["size"] | ||
| // CIR: %[[TMP_SIZE:.*]] = cir.load {{.*}} %[[SIZE_ADDR]] : !cir.ptr<!s64i>, !s64i | ||
| // CIR: %[[TMP_SIZE_U64:.*]] = cir.cast integral %[[TMP_SIZE]] : !s64i -> !u64i | ||
| // CIR: cir.store %[[TMP_SIZE_U64]], %[[RET_ADDR]] : !u64i, !cir.ptr<!u64i> | ||
| // CIR: %[[TMP_RET:.*]] = cir.load %[[RET_ADDR]] : !cir.ptr<!u64i>, !u64i | ||
| // CIR: cir.return %[[TMP_RET]] : !u64i | ||
|
|
||
| // LLVM: %[[RET_ADDR:.*]] = alloca i64, i64 1, align 8 | ||
| // LLVM: %[[SIZE_ADDR:.*]] = alloca i64, i64 1, align 8 | ||
| // LLVM: %[[TMP_SIZE:.*]] = load i64, ptr %[[SIZE_ADDR]], align 8 | ||
| // LLVM: store i64 %[[TMP_SIZE]], ptr %[[RET_ADDR]], align 8 | ||
| // LLVM: %[[TMP_RET:.*]] = load i64, ptr %[[RET_ADDR]], align 8 | ||
| // LLVM: ret i64 %[[TMP_RET]] | ||
|
|
||
| // OGCG: %[[SIZE_ADDR:.*]] = alloca i64, align 8 | ||
| // OGCG: %[[TMP_SIZE:.*]] = load i64, ptr %[[SIZE_ADDR]], align 8 | ||
| // OGCG: %[[TMP_SIZE_2:.*]] = load i64, ptr %[[SIZE_ADDR]], align 8 | ||
| // OGCG: ret i64 %[[TMP_SIZE]] |
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.
vlaSizeisn't a pointer, so this fails to build:Note this seems to have been caught by pre-commit CI as well.
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'm preparing a fix for it now.
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.
#169715
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.
Thank you for catching it