[clang] [clang][Modules] Diagnosing Module Redefinition Across ModuleMaps (PR #190085)
Cyndy Ishida via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 7 09:19:33 PDT 2026
================
@@ -0,0 +1,73 @@
+// Test duplicating module decls discovered during by-name module scanning with
+// a shared compiler instance.
+// This tests covers the case where the current modulemap we are loading
+// contains a module decl that satisfies two conditions:
+// 1. The compiler has seen the module decl during previous lookups.
+// 2. The previous decl comes from a different modulemap.
+// In this case, an error is produced with no dependency information returned.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+
+// Scenario setup:
+// - "A" is a framework module whose modulemap also declares an empty "B".
+// - A separate include path has its own B/module.modulemap that declares "B"
+// with a header depending on module "Dep"
+// We scan B first, and during A's scan, the compiler should report an error.
+
+// RUN: not clang-scan-deps -compilation-database %t/cdb.json -format \
+// RUN: experimental-full -module-names=B,A > %t/result_ab.json 2> %t/err.txt
+// RUN: cat %t/result_ab.json | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t %s
+// RUN: cat %t/err.txt | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t \
----------------
cyndyishida wrote:
You don't need to pipe the output to files. I don't think clang-scan-deps writes out a module graph if a fatal error happens, so theres no need to check a module exists in it. Running FileCheck against the direct `clang-scan-deps` command is enough to compare the error message.
https://github.com/llvm/llvm-project/pull/190085
More information about the cfe-commits
mailing list