Page MenuHomePhabricator

Apply -fmacro-prefix-map to __builtin_FILE()
ClosedPublic

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

Details

Summary

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

Thanks!

clang/test/CodeGen/macro-prefix-map.c
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()="file.cc" probably to work around Clang.

clang/include/clang/Driver/Options.td HelpText for -fmacro-prefix-map= needs an update.

https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html has more documentation

Great! My commit author string is Pavel Asyutchenko <sventeam@yandex.ru>.

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/Options.td.

This revision was automatically updated to reflect the committed changes.

Created release/13.x merge request: https://bugs.llvm.org/show_bug.cgi?id=51350
The release manager makes the call.