Skip to content

Commit 6b47f50

Browse files
committed
Use -fmacro-prefix-map for annot unit path in bc
Clang emits source unit path with every annotation in llvm.metadata section in bitcode. For example, for every stdlib function annotated with `__attribute__((annotate("introduced_in=XXX")))` bitcode will contain a path to the unit the function was declared in. In order to make bitcode builds reproducible, these paths should be normalized just like `__FILE__` macro paths are. This commit reuses `-fmacro-prefix-map` machinery for annotation paths in bitcode.
1 parent fb492d2 commit 6b47f50

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3311,9 +3311,10 @@ llvm::Constant *CodeGenModule::EmitAnnotationString(StringRef Str) {
33113311
llvm::Constant *CodeGenModule::EmitAnnotationUnit(SourceLocation Loc) {
33123312
SourceManager &SM = getContext().getSourceManager();
33133313
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
3314-
if (PLoc.isValid())
3315-
return EmitAnnotationString(PLoc.getFilename());
3316-
return EmitAnnotationString(SM.getBufferName(Loc));
3314+
StringRef Path = PLoc.isValid() ? PLoc.getFilename() : SM.getBufferName(Loc);
3315+
SmallString<256> RemappedPath(Path);
3316+
LangOpts.remapPathPrefix(RemappedPath);
3317+
return EmitAnnotationString(StringRef(RemappedPath.data(), RemappedPath.size()));
33173318
}
33183319

33193320
llvm::Constant *CodeGenModule::EmitAnnotationLineNo(SourceLocation L) {

0 commit comments

Comments
 (0)