-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[clang] "modular_format" attribute for functions using format strings #147431
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
base: users/mysterymath/modular-printf/ir
Are you sure you want to change the base?
[clang] "modular_format" attribute for functions using format strings #147431
Conversation
3ba5f13
to
813226e
Compare
215f1f9
to
619dfb7
Compare
This provides a C language version of the new IR modular-format attribute. This, in concert with the format attribute, allows a library function to declare that a modular version of its implementation is available. See issue #146159 for context.
619dfb7
to
e77a856
Compare
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.
One thing that would help me is if the PR came with tests so we could see examples of its usage. (The docs could use examples as well.) I'm having a bit of a hard time understanding the attribute and its effects.
|
||
The second argument is a implementation name, and the remaining arguments are | ||
aspects of the format string for the compiler to report. If the compiler does | ||
not understand a aspect, it must summarily report that the format string has |
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.
not understand a aspect, it must summarily report that the format string has | |
not understand an aspect, it must summarily report that the format string has |
not understand a aspect, it must summarily report that the format string has | ||
that aspect. | ||
|
||
The compiler reports an aspect by issing a relocation for the symbol |
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.
The compiler reports an aspect by issing a relocation for the symbol | |
The compiler reports an aspect by issuing a relocation for the symbol |
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.
No real comments here. I still don't really understand what this is for, which tells me we probably need some additional work on the commit message and documentation.
@@ -2569,6 +2569,18 @@ void CodeGenModule::ConstructAttributeList(StringRef Name, | |||
|
|||
if (TargetDecl->hasAttr<ArmLocallyStreamingAttr>()) | |||
FuncAttrs.addAttribute("aarch64_pstate_sm_body"); | |||
|
|||
if (auto *ModularFormat = TargetDecl->getAttr<ModularFormatAttr>()) { | |||
// TODO: Error checking |
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.
This is a heck of a TODO :) Though, I'd expect us to do diagnostics during our normal checking of the format string, so we shouldn't really require anything here.
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.
Hah, fair; this is very much a Draft PR. My intent was to get this in front of a bunch of eyes sooner rather than later, as this PR set touches everything every layer from the compiler through to libc (skipping the linker).
Very fair; I was relying a lot on the tracking issue and RFC discussion for context. I've added some meat to the PR description, and I've added a brief example to the attribute docs. I'll add a test once I get the chance. |
This provides a C language
modular_format
attribute. This combines with information from the existingformat
to set the new IRmodular-format
attribute.The purpose of these attributes is to enable "modular printf". A statically linked libc can provide a modular variant of printf that only weakly references implementation routines. Regular printf would strongly reference those routines, and the compiler would transform calls with constant format strings to calls to the modular printf, along with strong references to aspect symbols that bring in those aspects.
See issue #146159 for context.