[clang] [CIR] Handle ImportDecl in emitTopLevelDecl (PR #221720)

Berkay Sahin via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 9 07:07:30 PDT 2026


================
@@ -2538,6 +2538,11 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
     emitDeclContext(cast<ExportDecl>(decl));
     break;
 
+  case Decl::Import:
+    // Nothing to emit for C++20 module imports. Initializers run through
----------------
berkaysahiin wrote:

```cpp
case Decl::Import: {
    auto *Import = cast<ImportDecl>(D);

    // If we've already imported this module, we're done.
    if (!ImportedModules.insert(Import->getImportedModule()))
      break;

    // Emit debug information for direct imports.
    if (!Import->getImportedOwningModule()) {
      if (CGDebugInfo *DI = getModuleDebugInfo())
        DI->EmitImportDecl(*Import);
    }

    // For C++ standard modules we are done - we will call the module
    // initializer for imported modules, and that will likewise call those for
    // any imports it has.
    if (CXX20ModuleInits && Import->getImportedModule() &&
        Import->getImportedModule()->isNamedModule())
      break;
```

For C++20 modules, we break out early. The missing part is debug info generation which is a missing feature in CIR (`MissingFeatures::generateDebugInfo`).

The first check is for dedup which is not necessary here since its noop. 

We might need to come back here once CIR supports generating debug info. Wdyt ?

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


More information about the cfe-commits mailing list