From: Bruno Cardoso Lopes Date: Thu, 10 Aug 2017 15:16:24 +0000 (+0000) Subject: [Modules] Prevent #import to reenter header if not building a module. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15f32a5cedf2ebf7f24cf76a91dbdd49d70a33de;p=clang [Modules] Prevent #import to reenter header if not building a module. When non-modular headers are imported while not building a module but in -fmodules mode, be conservative and preserve the default #import semantic: do not reenter headers. rdar://problem/33745031 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@310605 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index 1ebcc0a1c6..4b5df8c1cc 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -1143,7 +1143,7 @@ bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor &PP, // headers find in the wild might rely only on #import and do not contain // controlling macros, be conservative and only try to enter textual headers // if such macro is present. - if (!FileInfo.isModuleHeader && + if (FileInfo.isCompilingModuleHeader && !FileInfo.isModuleHeader && FileInfo.getControllingMacro(ExternalLookup)) TryEnterHdr = true; return TryEnterHdr; diff --git a/test/Modules/Inputs/import-textual/x.h b/test/Modules/Inputs/import-textual/x.h new file mode 100644 index 0000000000..9b41ccd0bd --- /dev/null +++ b/test/Modules/Inputs/import-textual/x.h @@ -0,0 +1,6 @@ +#ifndef RANDOM_DEP + +@interface X +@end + +#endif // RANDOM_DEP diff --git a/test/Modules/import-textual-nomodules.m b/test/Modules/import-textual-nomodules.m new file mode 100644 index 0000000000..7cf8c1e186 --- /dev/null +++ b/test/Modules/import-textual-nomodules.m @@ -0,0 +1,8 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -I%S/Inputs/import-textual -fmodules-cache-path=%t %s -verify + +// expected-no-diagnostics + +#import "x.h" +#import "x.h" +