[clang] Don't create import decls without -fmodules
authorKadir Cetinkaya <kadircet@google.com>
Fri, 26 May 2023 21:14:41 +0000 (23:14 +0200)
committerKadir Cetinkaya <kadircet@google.com>
Fri, 16 Jun 2023 07:26:45 +0000 (09:26 +0200)
commit4d0cfa6d09e2a84cceb669949d72df58c031a8c5
tree6ebb02ac9e3e61ac35ecf33b7f55eed928d548c4
parentbe37d17f1c8215b6868a1edc385b34bda0b48a21
[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
clang/lib/Sema/SemaModule.cpp
clang/test/Modules/Inputs/modulemaps-nomodules/header.h [new file with mode: 0644]
clang/test/Modules/Inputs/modulemaps-nomodules/module.modulemap [new file with mode: 0644]
clang/test/Modules/getSourceDescriptor-crash.cpp
clang/test/Modules/modulemaps-nomodules.cpp [new file with mode: 0644]
clang/test/PCH/Inputs/modulemaps-nomodules/header.h [new file with mode: 0644]
clang/test/PCH/Inputs/modulemaps-nomodules/module.modulemap [new file with mode: 0644]
clang/test/PCH/modulemaps-nomodules.cpp [new file with mode: 0644]