https://github.com/naveen-seth updated https://github.com/llvm/llvm-project/pull/161486
>From 52a54eeb0bccb871c7addcf3236f40ffb7a226a9 Mon Sep 17 00:00:00 2001 From: Naveen Seth Hanig <[email protected]> Date: Wed, 1 Oct 2025 03:51:58 +0200 Subject: [PATCH 1/2] [clang][DependencyScanning] Reset options generated for named module compilations. The driver-generated -cc1 command-lines for C++ named module inputs introduce some command-line options which affect the canonical module build command (and therefore the context hash). This resets those options. --- .../DependencyScanning/ModuleDepCollector.cpp | 4 + ...modules-context-hash-from-named-module.cpp | 111 ++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 clang/test/ClangScanDeps/modules-context-hash-from-named-module.cpp diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index d67178c153e88..a117bec0d656e 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -263,6 +263,10 @@ makeCommonInvocationForModuleBuild(CompilerInvocation CI) { // units. CI.getFrontendOpts().Inputs.clear(); CI.getFrontendOpts().OutputFile.clear(); + CI.getFrontendOpts().GenReducedBMI = false; + CI.getFrontendOpts().ModuleOutputPath.clear(); + CI.getHeaderSearchOpts().ModulesSkipHeaderSearchPaths = false; + CI.getHeaderSearchOpts().ModulesSkipDiagnosticOptions = false; // LLVM options are not going to affect the AST CI.getFrontendOpts().LLVMArgs.clear(); diff --git a/clang/test/ClangScanDeps/modules-context-hash-from-named-module.cpp b/clang/test/ClangScanDeps/modules-context-hash-from-named-module.cpp new file mode 100644 index 0000000000000..04148953b5683 --- /dev/null +++ b/clang/test/ClangScanDeps/modules-context-hash-from-named-module.cpp @@ -0,0 +1,111 @@ +// Check that the driver-generated command line options for C++ module inputs +// do not unexpectedly change the context hash of imported Clang modules +// compared to the command line for an otherwise equal non-module input. + +// RUN: rm -rf %t +// RUN: split-file %s %t + +//--- main.cpp +#include "root.h" +import A; +import B; + +auto main() -> int { return 1; } + +//--- A.cppm +module; +#include "root.h" +export module A; + +//--- B.cppm +module; +#include "root.h" +export module B; + +//--- module.modulemap +module root { header "root.h" } + +//--- root.h +// empty + +// RUN: %clang++ -std=c++23 -fmodules %t/main.cpp %t/A.cppm %t/B.cppm -fsyntax-only -fdriver-only -MJ %t/deps.json +// RUN: sed -e '1s/^/[/' -e '$s/,$/]/' %t/deps.json | sed 's:\\\\\?:/:g' > %t/compile_commands.json +// RUN: clang-scan-deps -compilation-database=%t/compile_commands.json -format experimental-full > %t/result.json +// RUN: cat %t/result.json + +// RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t + +// CHECK: { +// CHECK-NEXT: "modules": [ +// CHECK-NEXT: { +// CHECK-NEXT: "clang-module-deps": [], +// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap", +// CHECK: "context-hash": "[[HASH_ROOT:.*]]", +// CHECK-NEXT: "file-deps": [ +// CHECK-NEXT: "[[PREFIX]]/module.modulemap", +// CHECK-NEXT: "[[PREFIX]]/root.h" +// CHECK-NEXT: ], +// CHECK-NEXT: "link-libraries": [], +// CHECK-NEXT: "name": "root" +// CHECK-NEXT: } +// CHECK-NEXT: ], +// CHECK-NEXT: "translation-units": [ +// CHECK-NEXT: { +// CHECK-NEXT: "commands": [ +// CHECK-NEXT: { +// CHECK-NEXT: "clang-context-hash": "{{.*}}", +// CHECK-NEXT: "named-module-deps": [ +// CHECK-NEXT: "A", +// CHECK-NEXT: "B" +// CHECK-NEXT: ], +// CHECK-NEXT: "clang-module-deps": [ +// CHECK-NEXT: { +// CHECK-NEXT: "context-hash": "[[HASH_ROOT]]", +// CHECK-NEXT: "module-name": "root" +// CHECK-NEXT: } +// CHECK-NEXT: ], +// CHECK: "file-deps": [ +// CHECK-NEXT: "[[PREFIX]]/main.cpp" +// CHECK-NEXT: ], +// CHECK-NEXT: "input-file": "[[PREFIX]]/main.cpp" +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT: "commands": [ +// CHECK-NEXT: { +// CHECK-NEXT: "clang-context-hash": "{{.*}}", +// CHECK-NEXT: "named-module": "A", +// CHECK-NEXT: "clang-module-deps": [ +// CHECK-NEXT: { +// CHECK-NEXT: "context-hash": "[[HASH_ROOT]]", +// CHECK-NEXT: "module-name": "root" +// CHECK-NEXT: } +// CHECK-NEXT: ], +// CHECK: "file-deps": [ +// CHECK-NEXT: "[[PREFIX]]/A.cppm" +// CHECK-NEXT: ], +// CHECK-NEXT: "input-file": "[[PREFIX]]/A.cppm" +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT: "commands": [ +// CHECK-NEXT: { +// CHECK-NEXT: "clang-context-hash": "{{.*}}", +// CHECK-NEXT: "named-module": "B", +// CHECK-NEXT: "clang-module-deps": [ +// CHECK-NEXT: { +// CHECK-NEXT: "context-hash": "[[HASH_ROOT]]", +// CHECK-NEXT: "module-name": "root" +// CHECK-NEXT: } +// CHECK-NEXT: ], +// CHECK: "file-deps": [ +// CHECK-NEXT: "[[PREFIX]]/B.cppm" +// CHECK-NEXT: ], +// CHECK-NEXT: "input-file": "[[PREFIX]]/B.cppm" +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: } >From ea317fc4850ecb06b12a8bc48bf6467677466c1e Mon Sep 17 00:00:00 2001 From: Naveen Seth Hanig <[email protected]> Date: Wed, 1 Oct 2025 09:58:50 +0200 Subject: [PATCH 2/2] Fix test for windows --- .../ClangScanDeps/modules-context-hash-from-named-module.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/ClangScanDeps/modules-context-hash-from-named-module.cpp b/clang/test/ClangScanDeps/modules-context-hash-from-named-module.cpp index 04148953b5683..af3fad9a2e8e0 100644 --- a/clang/test/ClangScanDeps/modules-context-hash-from-named-module.cpp +++ b/clang/test/ClangScanDeps/modules-context-hash-from-named-module.cpp @@ -28,7 +28,7 @@ module root { header "root.h" } //--- root.h // empty -// RUN: %clang++ -std=c++23 -fmodules %t/main.cpp %t/A.cppm %t/B.cppm -fsyntax-only -fdriver-only -MJ %t/deps.json +// RUN: %clang -std=c++23 -fmodules %t/main.cpp %t/A.cppm %t/B.cppm -fsyntax-only -fdriver-only -MJ %t/deps.json // RUN: sed -e '1s/^/[/' -e '$s/,$/]/' %t/deps.json | sed 's:\\\\\?:/:g' > %t/compile_commands.json // RUN: clang-scan-deps -compilation-database=%t/compile_commands.json -format experimental-full > %t/result.json // RUN: cat %t/result.json _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
