Index: lib/Serialization/ASTWriter.cpp =================================================================== --- lib/Serialization/ASTWriter.cpp +++ lib/Serialization/ASTWriter.cpp @@ -2187,7 +2187,8 @@ // Write out any exported module macros. bool EmittedModuleMacros = false; - if (IsModule) { + // We write out exported module macros for PCH as well. + if (true) { auto Leafs = PP.getLeafModuleMacros(Name); SmallVector Worklist(Leafs.begin(), Leafs.end()); llvm::DenseMap Visits; Index: test/Modules/Inputs/MacroFabs1.h =================================================================== --- test/Modules/Inputs/MacroFabs1.h +++ test/Modules/Inputs/MacroFabs1.h @@ -0,0 +1,6 @@ + +#undef fabs +#define fabs(x) (x) + +#undef my_fabs +#define my_fabs(x) (x) Index: test/Modules/Inputs/module.map =================================================================== --- test/Modules/Inputs/module.map +++ test/Modules/Inputs/module.map @@ -414,3 +414,7 @@ } module Empty {} + +module MacroFabs1 { + header "MacroFabs1.h" +} Index: test/Modules/Inputs/pch-import-module-with-macro.pch =================================================================== --- test/Modules/Inputs/pch-import-module-with-macro.pch +++ test/Modules/Inputs/pch-import-module-with-macro.pch @@ -0,0 +1,3 @@ + +@import MacroFabs1; + Index: test/Modules/pch-module-macro.m =================================================================== --- test/Modules/pch-module-macro.m +++ test/Modules/pch-module-macro.m @@ -0,0 +1,9 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -emit-pch -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -o %t.pch -I %S/Inputs -x objective-c-header %S/Inputs/pch-import-module-with-macro.pch +// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -fsyntax-only -I %S/Inputs -include-pch %t.pch %s -verify +// expected-no-diagnostics + +int test(int x) { + return my_fabs(x) + fabs(x); +} +