Index: lib/Serialization/ASTReader.cpp =================================================================== --- lib/Serialization/ASTReader.cpp +++ lib/Serialization/ASTReader.cpp @@ -1945,15 +1945,13 @@ Module *PrevOwner = nullptr; if (SubmoduleID PrevModID = PrevMI->getOwningModuleID()) PrevOwner = Reader.getSubmodule(PrevModID); - SourceManager &SrcMgr = Reader.getSourceManager(); - bool PrevInSystem - = PrevOwner? PrevOwner->IsSystem - : SrcMgr.isInSystemHeader(PrevMI->getDefinitionLoc()); - bool NewInSystem - = NewOwner? NewOwner->IsSystem - : SrcMgr.isInSystemHeader(NewMI->getDefinitionLoc()); if (PrevOwner && PrevOwner == NewOwner) return false; + SourceManager &SrcMgr = Reader.getSourceManager(); + bool PrevInSystem = (PrevOwner && PrevOwner->IsSystem) || + SrcMgr.isInSystemHeader(PrevMI->getDefinitionLoc()); + bool NewInSystem = (NewOwner && NewOwner->IsSystem) || + SrcMgr.isInSystemHeader(NewMI->getDefinitionLoc()); return PrevInSystem && NewInSystem; } Index: test/Modules/Inputs/macro-ambiguity/a/foo.h =================================================================== --- /dev/null +++ test/Modules/Inputs/macro-ambiguity/a/foo.h @@ -0,0 +1,6 @@ +#ifndef A_FOO_H +#define A_FOO_H + +#include_next + +#endif // FOO_H Index: test/Modules/Inputs/macro-ambiguity/b/foo.h =================================================================== --- /dev/null +++ test/Modules/Inputs/macro-ambiguity/b/foo.h @@ -0,0 +1,6 @@ +#ifndef B_FOO_H +#define B_FOO_H + +#include + +#endif // B_FOO_H Index: test/Modules/Inputs/macro-ambiguity/c/bar.h =================================================================== --- /dev/null +++ test/Modules/Inputs/macro-ambiguity/c/bar.h @@ -0,0 +1,10 @@ +#ifndef C_BAR_H +#define C_BAR_H + +#define FOO(x) x + x + +#define MORE_META(x) (x) + +#define META_FOO(x) MORE_META(FOO(x)) + +#endif Index: test/Modules/Inputs/macro-ambiguity/c/d/baz.h =================================================================== --- /dev/null +++ test/Modules/Inputs/macro-ambiguity/c/d/baz.h @@ -0,0 +1,6 @@ +#ifndef C_D_BAZ_H +#define C_D_BAZ_H + +#define FOO(x) 2 * x + +#endif // C_D_BAZ_H Index: test/Modules/Inputs/macro-ambiguity/module.modulemap =================================================================== --- /dev/null +++ test/Modules/Inputs/macro-ambiguity/module.modulemap @@ -0,0 +1,6 @@ +module a { header "Inputs/macro-ambiguity/a/foo.h" export * use bc } +module bc [system] { + textual header "Inputs/macro-ambiguity/b/foo.h" + textual header "Inputs/macro-ambiguity/c/bar.h" + textual header "Inputs/macro-ambiguity/c/d/baz.h" +} Index: test/Modules/macro-ambiguity.cpp =================================================================== --- /dev/null +++ test/Modules/macro-ambiguity.cpp @@ -0,0 +1,35 @@ +// RUN: rm -rf %t +// RUN: cd %S +// +// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \ +// RUN: -v -iquote . \ +// RUN: -isystem Inputs/macro-ambiguity/a \ +// RUN: -isystem Inputs/macro-ambiguity/b \ +// RUN: -isystem Inputs/macro-ambiguity/c \ +// RUN: -fno-modules-implicit-maps -fmodule-map-file-home-is-cwd \ +// RUN: -emit-module -fmodule-name=a -o %t/a.pcm \ +// RUN: Inputs/macro-ambiguity/module.modulemap +// +// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \ +// RUN: -v -iquote . \ +// RUN: -isystem Inputs/macro-ambiguity/a \ +// RUN: -isystem Inputs/macro-ambiguity/b \ +// RUN: -isystem Inputs/macro-ambiguity/c \ +// RUN: -fno-implicit-modules -fno-modules-implicit-maps \ +// RUN: -fmodule-map-file-home-is-cwd \ +// RUN: -fmodule-map-file=Inputs/macro-ambiguity/module.modulemap \ +// RUN: -fmodule-file=%t/a.pcm \ +// RUN: -Wambiguous-macro -verify macro-ambiguity.cpp + +// FIXME: We should add tests for cases which *will* issue the diagnostic as +// well. +// expected-no-diagnostics + +#include +#include + +int test(int x) { + int foo = META_FOO(x) + FOO(x); + + return foo; +}