-
Notifications
You must be signed in to change notification settings - Fork 182
[CIR] Add support for SourceLocExpr (__builtin_LINE, etc.) #1988
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
lanza
wants to merge
9
commits into
gh/lanza/2/base
Choose a base branch
from
gh/lanza/2/head
base: gh/lanza/2/base
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.
+89
−2
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7c2bc83
Update
lanza 780256e
Update
lanza 086c8ba
Update
lanza 56d8e03
Update
lanza 219cbaa
Update
lanza a9b1449
Update
lanza 3f3f2ca
Update
lanza 2bea57e
Update
lanza a713f36
Update
lanza 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -fclangir -emit-cir %s -o %t.cir | ||
| // RUN: FileCheck --input-file=%t.cir %s | ||
|
|
||
| // Test __builtin_LINE | ||
| int test_builtin_LINE() { | ||
| // CHECK-LABEL: cir.func {{.*}}@{{.*}}test_builtin_LINE | ||
| // CHECK: %{{.*}} = cir.const #cir.int<8> : !u32i | ||
| return __builtin_LINE(); | ||
| } | ||
|
|
||
| // Test __builtin_FILE | ||
| const char* test_builtin_FILE() { | ||
| // CHECK-LABEL: cir.func {{.*}}@{{.*}}test_builtin_FILE | ||
| // CHECK: %{{.*}} = cir.const #cir.global_view<@".str{{.*}}"> : !cir.ptr<!s8i> | ||
| return __builtin_FILE(); | ||
| } | ||
|
|
||
| // Test __builtin_FUNCTION | ||
| const char* test_builtin_FUNCTION() { | ||
| // CHECK-LABEL: cir.func {{.*}}@{{.*}}test_builtin_FUNCTION | ||
| // CHECK: %{{.*}} = cir.const #cir.global_view<@".str{{.*}}"> : !cir.ptr<!s8i> | ||
| return __builtin_FUNCTION(); | ||
| } | ||
|
|
||
| // Test __builtin_COLUMN | ||
| int test_builtin_COLUMN() { | ||
| // CHECK-LABEL: cir.func {{.*}}@{{.*}}test_builtin_COLUMN | ||
| // The column number is the position of '__builtin_COLUMN' | ||
| // CHECK: %{{.*}} = cir.const #cir.int<10> : !u32i | ||
| return __builtin_COLUMN(); | ||
| } | ||
|
|
||
| // Test in global context | ||
| #line 100 "test_file.cpp" | ||
| int global_line = __builtin_LINE(); | ||
| // CHECK: cir.global external @global_line = #cir.int<100> : !s32i | ||
|
|
||
| // Test default argument | ||
| int get_line(int l = __builtin_LINE()) { | ||
| return l; | ||
| } | ||
|
|
||
| void test_default_arg() { | ||
| // CHECK-LABEL: cir.func {{.*}}@{{.*}}test_default_arg | ||
| // The LINE should be from the call site, not the default argument definition | ||
| #line 111 | ||
| int x = get_line(); | ||
| // CHECK: %{{.*}} = cir.const #cir.int<111> : !u32i | ||
| // CHECK: %{{.*}} = cir.call @{{.*}}get_line{{.*}}({{.*}}) : | ||
| } | ||
|
|
||
| #line 200 "lambda-test.cpp" | ||
| // Test in lambda (this tests that source location correctly captures context) | ||
| void test_in_lambda() { | ||
| // CHECK-LABEL: cir.func {{.*}}@{{.*}}test_in_lambda | ||
| auto lambda = []() { | ||
| return __builtin_LINE(); | ||
| }; | ||
| int x = lambda(); | ||
| } | ||
|
|
||
| #line 214 "combined-test.cpp" | ||
| // Test multiple builtins in one expression | ||
| void test_combined() { | ||
| // CHECK-LABEL: cir.func {{.*}}@{{.*}}test_combined | ||
| const char* file = __builtin_FILE(); | ||
| int line = __builtin_LINE(); | ||
| const char* func = __builtin_FUNCTION(); | ||
| // All should produce constants | ||
| // CHECK: cir.const | ||
| // CHECK: cir.const | ||
| // CHECK: cir.const | ||
| } | ||
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.
Please add LLVM and OGCG checks too!