-
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
Conversation
bcardosolopes
left a comment
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.
LGTM with one minor nit!
| @@ -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 | |||
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!
|
The windows failure seems exposed after rebase, we should probably REQUIRES linux / darwin for it right now |
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: 1958776 Pull-Request: #1988
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: 1958776 Pull-Request: #1988
Stack from ghstack (oldest at bottom):
This patch implements SourceLocExpr code generation, which enables
support for the following builtin functions:
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:
Test coverage includes: