Page MenuHomePhabricator

Apply -fmacro-prefix-map to __builtin_FILE()

Authored by Svenny on Aug 3 2021, 1:00 PM.



This will match the behavior of GCC.
Patch does not change remapping logic itself, so adding one simple smoke test should be enough.

Diff Detail

Event Timeline

Svenny created this revision.Aug 3 2021, 1:00 PM
Svenny requested review of this revision.Aug 3 2021, 1:00 PM
MaskRay accepted this revision.Aug 4 2021, 10:43 AM


1 ↗(On Diff #363838)

The test may be placed in CodeGenCXX/builtin-source-location.cpp

This revision is now accepted and ready to land.Aug 4 2021, 10:43 AM
Svenny updated this revision to Diff 364195.Aug 4 2021, 11:15 AM

Moved new test to CodeGenCXX/builtin-source-location.cpp.

Svenny marked an inline comment as done.Aug 4 2021, 11:25 AM

Could you please land it? I don't have commit access.

Also, any chance this patch can get into 13.x release branch? Not sure if it counts as a feature or a bugfix :)

I can push it on your behalf, I want to wait a bit for more comments.
(You need to provide name/email so that you can get the proper attribution git commit --amend --author='...')

Looks like a good candidate for release/13.x for build reproducibility.
absl has a macro saying whether __builtin_FILE can be used.
I can find a few other places where people do something like -D__builtin_FILE()="" probably to work around Clang.

clang/include/clang/Driver/ HelpText for -fmacro-prefix-map= needs an update. has more documentation

Great! My commit author string is Pavel Asyutchenko <>.

I have an even uglier hack to work around this: to offset the value of __builtin_FILE() by compile-time calculated location of some known substring like src or include.

Svenny updated this revision to Diff 364217.Aug 4 2021, 12:24 PM

Updated ffile-prefix-map and fmacro-prefix-map in clang/include/clang/Driver/

This revision was automatically updated to reflect the committed changes.

Created release/13.x merge request:
The release manager makes the call.