Commit 63b1a20
committed
[CIR] Add support for SourceLocExpr (__builtin_LINE, etc.)
This patch implements SourceLocExpr code generation, which enables
support for the following builtin functions:
- __builtin_LINE
- __builtin_FILE
- __builtin_FUNCTION
- __builtin_COLUMN
These builtins are evaluated at compile-time and emit constant values
or global string literals. The implementation follows the traditional
CodeGen approach of using ConstantEmitter to emit abstract constants
from evaluated APValues.
A key challenge was handling synthetic StringLiterals created during
constant evaluation (for __builtin_FILE and __builtin_FUNCTION).
These synthetic literals don't have valid source locations, which
caused assertion failures when creating global string constants.
The fix adds a check in getGlobalForStringLiteral to use
UnknownLoc when the StringLiteral has an invalid source range.
This feature unblocks:
- std::source_location (C++20)
- Logging and debugging macros that use source location builtins
- Assertion/diagnostic frameworks
Test coverage includes:
- Basic __builtin_LINE, __builtin_FILE, __builtin_FUNCTION, __builtin_COLUMN
- Usage in global variable initializers
- Default function arguments
- Lambda expressions
- Combined usage of multiple source location builtins
ghstack-source-id: 6d3f35e
Pull-Request: #19881 parent ca31760 commit 63b1a20
File tree
3 files changed
+89
-2
lines changed- clang
- lib/CIR/CodeGen
- test/CIR/CodeGen
3 files changed
+89
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
705 | 706 | | |
706 | 707 | | |
707 | 708 | | |
708 | | - | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
709 | 720 | | |
710 | 721 | | |
711 | 722 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1855 | 1855 | | |
1856 | 1856 | | |
1857 | 1857 | | |
1858 | | - | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
1859 | 1862 | | |
1860 | 1863 | | |
1861 | 1864 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
0 commit comments