diff options
author | Kadir Cetinkaya <kadircet@google.com> | 2023-05-26 23:14:41 +0200 |
---|---|---|
committer | Kadir Cetinkaya <kadircet@google.com> | 2023-06-16 09:26:45 +0200 |
commit | 4d0cfa6d09e2a84cceb669949d72df58c031a8c5 (patch) | |
tree | 6ebb02ac9e3e61ac35ecf33b7f55eed928d548c4 /clang/lib/Sema/SemaModule.cpp | |
parent | be37d17f1c8215b6868a1edc385b34bda0b48a21 (diff) | |
download | llvm-4d0cfa6d09e2a84cceb669949d72df58c031a8c5.zip llvm-4d0cfa6d09e2a84cceb669949d72df58c031a8c5.tar.gz llvm-4d0cfa6d09e2a84cceb669949d72df58c031a8c5.tar.bz2 |
[clang] Don't create import decls without -fmodules
When modules are disabled, there's no loaded module for these import
decls to point at. This results in crashes when there are modulemap
files but no -fmodules flag (this configuration is used for layering
check violations).
This patch makes sure import declarations are introduced only when
modules are enabled, which makes this case similar to textual headers
(no import decls are created for #include of textual headers from a
modulemap).
Differential Revision: https://reviews.llvm.org/D152274
Diffstat (limited to 'clang/lib/Sema/SemaModule.cpp')
-rw-r--r-- | clang/lib/Sema/SemaModule.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index 67c6556..5ce5330 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -636,11 +636,9 @@ void Sema::BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod) { TUKind == TU_Module && getSourceManager().isWrittenInMainFile(DirectiveLoc); - bool ShouldAddImport = !IsInModuleIncludes; - - // If this module import was due to an inclusion directive, create an - // implicit import declaration to capture it in the AST. - if (ShouldAddImport) { + // If we are really importing a module (not just checking layering) due to an + // #include in the main file, synthesize an ImportDecl. + if (getLangOpts().Modules && !IsInModuleIncludes) { TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl(); ImportDecl *ImportD = ImportDecl::CreateImplicit(getASTContext(), TU, DirectiveLoc, Mod, |