jansvoboda11 created this revision. jansvoboda11 added reviewers: Bigcheese, dexonsmith. jansvoboda11 requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
One of main goals of the dependency scanner is to be strict about module compatibility. This is achieved through strict context hash. This patch ensures that strict context hash is enabled not only during the scan itself (and its minimized implicit build), but also when actually reporting the dependency. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D111720 Files: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp clang/test/ClangScanDeps/Inputs/modules-context-hash/a/dep.h clang/test/ClangScanDeps/Inputs/modules-context-hash/b/dep.h clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb.json.template clang/test/ClangScanDeps/Inputs/modules-context-hash/mod.h clang/test/ClangScanDeps/Inputs/modules-context-hash/module.modulemap clang/test/ClangScanDeps/Inputs/modules-context-hash/tu.c clang/test/ClangScanDeps/modules-context-hash.c
Index: clang/test/ClangScanDeps/modules-context-hash.c =================================================================== --- /dev/null +++ clang/test/ClangScanDeps/modules-context-hash.c @@ -0,0 +1,89 @@ +// RUN: rm -rf %t && mkdir %t +// RUN: cp -r %S/Inputs/modules-context-hash/* %t + +// Check that the scanner reports the same module as distinct dependencies when +// a single translation unit gets compiled with multiple command-lines that +// produce different **strict** context hashes. + +// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb.json.template > %t/cdb.json +// RUN: echo -%t > %t/result.json +// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full -j 1 >> %t/result.json +// RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s -check-prefix=CHECK + +// CHECK: -[[PREFIX:.*]] +// CHECK-NEXT: { +// CHECK-NEXT: "modules": [ +// CHECK-NEXT: { +// CHECK-NEXT: "clang-module-deps": [], +// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap", +// CHECK-NEXT: "command-line": [ +// CHECK-NEXT: "-cc1" +// CHECK: "-emit-module" +// CHECK: "-I" +// CHECK: "[[PREFIX]]/a" +// CHECK: "-fmodule-name=mod" +// CHECK: ], +// CHECK-NEXT: "context-hash": "[[HASH_MOD_A:.*]]", +// CHECK-NEXT: "file-deps": [ +// CHECK-NEXT: "[[PREFIX]]/a/dep.h", +// CHECK-NEXT: "[[PREFIX]]/mod.h", +// CHECK-NEXT: "[[PREFIX]]/module.modulemap" +// CHECK-NEXT: ], +// CHECK-NEXT: "name": "mod" +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT: "clang-module-deps": [], +// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap", +// CHECK-NEXT: "command-line": [ +// CHECK-NEXT: "-cc1" +// CHECK: "-emit-module" +// CHECK: "-I" +// CHECK: "[[PREFIX]]/b" +// CHECK: "-fmodule-name=mod" +// CHECK: ], +// CHECK-NEXT: "context-hash": "[[HASH_MOD_B:.*]]", +// CHECK-NEXT: "file-deps": [ +// CHECK-NEXT: "[[PREFIX]]/b/dep.h", +// CHECK-NEXT: "[[PREFIX]]/mod.h", +// CHECK-NEXT: "[[PREFIX]]/module.modulemap" +// CHECK-NEXT: ], +// CHECK-NEXT: "name": "mod" +// CHECK-NEXT: } +// CHECK-NEXT: ], +// CHECK-NEXT: "translation-units": [ +// CHECK-NEXT: { +// CHECK-NEXT: "clang-context-hash": "{{.*}}", +// CHECK-NEXT: "clang-module-deps": [ +// CHECK-NEXT: { +// CHECK-NEXT: "context-hash": "[[HASH_MOD_A]]", +// CHECK-NEXT: "module-name": "mod" +// CHECK-NEXT: } +// CHECK-NEXT: ], +// CHECK-NEXT: "command-line": [ +// CHECK-NEXT: "-fno-implicit-modules", +// CHECK-NEXT: "-fno-implicit-module-maps" +// CHECK-NEXT: ], +// CHECK-NEXT: "file-deps": [ +// CHECK-NEXT: "[[PREFIX]]/tu.c" +// CHECK-NEXT: ], +// CHECK-NEXT: "input-file": "[[PREFIX]]/tu.c" +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT: "clang-context-hash": "{{.*}}", +// CHECK-NEXT: "clang-module-deps": [ +// CHECK-NEXT: { +// CHECK-NEXT: "context-hash": "[[HASH_MOD_B]]", +// CHECK-NEXT: "module-name": "mod" +// CHECK-NEXT: } +// CHECK-NEXT: ], +// CHECK-NEXT: "command-line": [ +// CHECK-NEXT: "-fno-implicit-modules", +// CHECK-NEXT: "-fno-implicit-module-maps" +// CHECK-NEXT: ], +// CHECK-NEXT: "file-deps": [ +// CHECK-NEXT: "[[PREFIX]]/tu.c" +// CHECK-NEXT: ], +// CHECK-NEXT: "input-file": "[[PREFIX]]/tu.c" +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: } Index: clang/test/ClangScanDeps/Inputs/modules-context-hash/tu.c =================================================================== --- /dev/null +++ clang/test/ClangScanDeps/Inputs/modules-context-hash/tu.c @@ -0,0 +1 @@ +#include "mod.h" Index: clang/test/ClangScanDeps/Inputs/modules-context-hash/module.modulemap =================================================================== --- /dev/null +++ clang/test/ClangScanDeps/Inputs/modules-context-hash/module.modulemap @@ -0,0 +1 @@ +module mod { header "mod.h" } Index: clang/test/ClangScanDeps/Inputs/modules-context-hash/mod.h =================================================================== --- /dev/null +++ clang/test/ClangScanDeps/Inputs/modules-context-hash/mod.h @@ -0,0 +1 @@ +#include "dep.h" Index: clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb.json.template =================================================================== --- /dev/null +++ clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb.json.template @@ -0,0 +1,12 @@ +[ + { + "directory": "DIR", + "command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/a -o DIR/tu_a.o", + "file": "DIR/tu.c" + }, + { + "directory": "DIR", + "command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/b -o DIR/tu_b.o", + "file": "DIR/tu.c" + } +] Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -53,6 +53,9 @@ CI.getFrontendOpts().ModuleMapFiles.push_back(PrebuiltModule.ModuleMapFile); } + // Ensure the reported context hash is strict. + CI.getHeaderSearchOpts().ModulesStrictContextHash = true; + Optimize(CI); return CI;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits