[clang] [clang][modules] Headers meant to be included multiple times can be completely invisible in clang module builds (PR #83660)

Ian Anderson via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 12 15:09:21 PDT 2024


ian-twilightcoder wrote:

> The end result should be that #imported and #pragma once-guarded files are treated the same way as #ifndef-guarded files.

While I don't necessarily disagree with that goal in principle, it wasn't true before this change either. There was already some special casing to defeat `#import`. This change just adds another special case to the `#import` path. `#include` doesn't even go through the modified code that is `MaybeReenterImportedFile` (née `TryEnterImported`).

> I know you weren't trying to fix that -- but I'm saying that's the thing that _should_ be fixed, and that doing so would fix the _serious_ part of the problem you described in the initial message.

Modular headers including non-modular headers is a special problem. If we let every module enter the non-modular header (which Jan's patch does), its declarations will build into multiple modules/pcm files, where they will 1) conflict and cause errors in the several cases where type merging can't handle them, and 2) come from multiple modules which is undefined behavior for Swift (i.e. Swift will see `mod1.type` and `mod2.type` and won't know how to resolve un-qualified `type` in code). So I don't think that case really _can_ be fixed.

https://github.com/llvm/llvm-project/pull/83660


More information about the cfe-commits mailing list