akyrtzi created this revision. Herald added a project: All. akyrtzi requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This is particularly useful to avoid diverging the modules between a PCH and a translation-unit compilation. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D148369 Files: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c clang/tools/clang-scan-deps/ClangScanDeps.cpp Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp =================================================================== --- clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ clang/tools/clang-scan-deps/ClangScanDeps.cpp @@ -226,6 +226,12 @@ llvm::cl::init(false), llvm::cl::cat(DependencyScannerCategory)); +llvm::cl::opt<bool> + BriefResult("brief", llvm::cl::Optional, + llvm::cl::desc("Use brief dependency info output."), + llvm::cl::init(false), + llvm::cl::cat(DependencyScannerCategory)); + } // end anonymous namespace /// Takes the result of a dependency scan and prints error / dependency files @@ -402,6 +408,8 @@ OS << llvm::formatv("{0:2}\n", Value(std::move(Output))); } + size_t getNumModules() const { return Modules.size(); } + private: struct IndexedModuleID { ModuleID ID; @@ -893,6 +901,11 @@ if (FD && FD->roundTripCommands(llvm::errs())) HadErrors = true; + if (BriefResult) { + llvm::outs() << "num modules: " << FD->getNumModules() << '\n'; + return HadErrors; + } + if (Format == ScanningOutputFormat::Full) FD->printFullOutput(llvm::outs()); else if (Format == ScanningOutputFormat::P1689) Index: clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c =================================================================== --- /dev/null +++ clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c @@ -0,0 +1,42 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t + +// RUN: sed "s|DIR|%/t|g" %t/cdb.json.debug.template > %t/cdb.debug.json +// RUN: sed "s|DIR|%/t|g" %t/cdb.json.release.template > %t/cdb.release.json + +// RUN: clang-scan-deps -compilation-database %t/cdb.debug.json -format=experimental-full -optimize-args -brief | FileCheck %s +// RUN: clang-scan-deps -compilation-database %t/cdb.release.json -format=experimental-full -optimize-args -brief | FileCheck %s +// CHECK: num modules: 1 + +//--- cdb.json.debug.template +[{ + "directory": "DIR", + "file": "DIR/tu.c", + "command": "clang -target x86_64-apple-macosx12 -x c -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.c -o DIR/tu.o -O0 -g" +}, +{ + "directory": "DIR", + "file": "DIR/tu.prefix.h", + "command": "clang -target x86_64-apple-macosx12 -x c-header -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.prefix.h -o DIR/tu.pch -O0 -g" +}] +//--- cdb.json.release.template +[{ + "directory": "DIR", + "file": "DIR/tu.c", + "command": "clang -target x86_64-apple-macosx12 -x c -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.c -o DIR/tu.o -Os -g" +}, +{ + "directory": "DIR", + "file": "DIR/tu.prefix.h", + "command": "clang -target x86_64-apple-macosx12 -x c-header -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.prefix.h -o DIR/tu.pch -Os -g" +}] + +//--- include/module.modulemap +module Top { header "top.h" } +//--- include/top.h +#define TOP int +//--- tu.c +#include "top.h" +TOP fn(void); +//--- tu.prefix.h +#include "top.h" Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -102,6 +102,7 @@ CI.getCodeGenOpts().CoverageCompilationDir.clear(); CI.getCodeGenOpts().CoverageDataFile.clear(); CI.getCodeGenOpts().CoverageNotesFile.clear(); + CI.getCodeGenOpts().RelaxAll = false; } // Map output paths that affect behaviour to "-" so their existence is in the
Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp =================================================================== --- clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ clang/tools/clang-scan-deps/ClangScanDeps.cpp @@ -226,6 +226,12 @@ llvm::cl::init(false), llvm::cl::cat(DependencyScannerCategory)); +llvm::cl::opt<bool> + BriefResult("brief", llvm::cl::Optional, + llvm::cl::desc("Use brief dependency info output."), + llvm::cl::init(false), + llvm::cl::cat(DependencyScannerCategory)); + } // end anonymous namespace /// Takes the result of a dependency scan and prints error / dependency files @@ -402,6 +408,8 @@ OS << llvm::formatv("{0:2}\n", Value(std::move(Output))); } + size_t getNumModules() const { return Modules.size(); } + private: struct IndexedModuleID { ModuleID ID; @@ -893,6 +901,11 @@ if (FD && FD->roundTripCommands(llvm::errs())) HadErrors = true; + if (BriefResult) { + llvm::outs() << "num modules: " << FD->getNumModules() << '\n'; + return HadErrors; + } + if (Format == ScanningOutputFormat::Full) FD->printFullOutput(llvm::outs()); else if (Format == ScanningOutputFormat::P1689) Index: clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c =================================================================== --- /dev/null +++ clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c @@ -0,0 +1,42 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t + +// RUN: sed "s|DIR|%/t|g" %t/cdb.json.debug.template > %t/cdb.debug.json +// RUN: sed "s|DIR|%/t|g" %t/cdb.json.release.template > %t/cdb.release.json + +// RUN: clang-scan-deps -compilation-database %t/cdb.debug.json -format=experimental-full -optimize-args -brief | FileCheck %s +// RUN: clang-scan-deps -compilation-database %t/cdb.release.json -format=experimental-full -optimize-args -brief | FileCheck %s +// CHECK: num modules: 1 + +//--- cdb.json.debug.template +[{ + "directory": "DIR", + "file": "DIR/tu.c", + "command": "clang -target x86_64-apple-macosx12 -x c -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.c -o DIR/tu.o -O0 -g" +}, +{ + "directory": "DIR", + "file": "DIR/tu.prefix.h", + "command": "clang -target x86_64-apple-macosx12 -x c-header -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.prefix.h -o DIR/tu.pch -O0 -g" +}] +//--- cdb.json.release.template +[{ + "directory": "DIR", + "file": "DIR/tu.c", + "command": "clang -target x86_64-apple-macosx12 -x c -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.c -o DIR/tu.o -Os -g" +}, +{ + "directory": "DIR", + "file": "DIR/tu.prefix.h", + "command": "clang -target x86_64-apple-macosx12 -x c-header -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.prefix.h -o DIR/tu.pch -Os -g" +}] + +//--- include/module.modulemap +module Top { header "top.h" } +//--- include/top.h +#define TOP int +//--- tu.c +#include "top.h" +TOP fn(void); +//--- tu.prefix.h +#include "top.h" Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -102,6 +102,7 @@ CI.getCodeGenOpts().CoverageCompilationDir.clear(); CI.getCodeGenOpts().CoverageDataFile.clear(); CI.getCodeGenOpts().CoverageNotesFile.clear(); + CI.getCodeGenOpts().RelaxAll = false; } // Map output paths that affect behaviour to "-" so their existence is in the
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits