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).
It's been a couple of weeks since we looked at this together, and I already had trouble following the logic here.
I think it would be slightly clearer by:
Something like
I'd also consider inlining+dropping the ShouldAddImport variable, since the comment explains pretty well what the condition represents
all up to you though