diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -635,6 +635,21 @@ llvm_unreachable("Unknown ident kind for PredefinedExpr"); } +namespace { +class PPCallbacks final : public PrintingCallbacks { + const LangOptions &LO; + +public: + PPCallbacks(const LangOptions &LO) : LO(LO) {} + + std::string remapPath(StringRef Path) const override { + SmallString<256> Buffer(Path); + LO.remapPathPrefix(Buffer); + return static_cast(Buffer); + } +}; +} // namespace + // FIXME: Maybe this should use DeclPrinter with a special "print predefined // expr" policy instead. std::string PredefinedExpr::ComputeName(IdentKind IK, const Decl *CurrentDecl) { @@ -700,6 +715,9 @@ } PrintingPolicy Policy(Context.getLangOpts()); + PPCallbacks Callbacks(Context.getLangOpts()); + Policy.Callbacks = &Callbacks; + std::string Proto; llvm::raw_string_ostream POut(Proto); diff --git a/clang/test/CodeGenCXX/macro-prefix-map.cpp b/clang/test/CodeGenCXX/macro-prefix-map.cpp new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenCXX/macro-prefix-map.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fmacro-prefix-map=%p=/UNLIKELY/PATH -emit-llvm -o - %s | FileCheck %s +// +// CHECK: /UNLIKELY/PATH{{/|\\\\}}macro-prefix-map.cpp +template +const char *pretty(T) { + return __PRETTY_FUNCTION__; +} + +const char *testEnum() { + enum { + A + }; + return pretty(A); +}