[PATCH] D137527: [C++20] [Modules] [ClangScanDeps] Add ClangScanDeps support for C++20 Named Modules in P1689 format (2/4)

2023-02-12 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 496823.
ChuanqiXu added a comment.

Add `unsupported: windows`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137527/new/

https://reviews.llvm.org/D137527

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/P1689.cppm
  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
@@ -133,12 +133,15 @@
 
 static llvm::cl::opt Format(
 "format", llvm::cl::desc("The output format for the dependencies"),
-llvm::cl::values(clEnumValN(ScanningOutputFormat::Make, "make",
-"Makefile compatible dep file"),
- clEnumValN(ScanningOutputFormat::Full, "experimental-full",
-"Full dependency graph suitable"
-" for explicitly building modules. This format "
-"is experimental and will change.")),
+llvm::cl::values(
+clEnumValN(ScanningOutputFormat::Make, "make",
+   "Makefile compatible dep file"),
+clEnumValN(ScanningOutputFormat::P1689, "p1689",
+   "Generate standard c++ modules dependency P1689 format"),
+clEnumValN(ScanningOutputFormat::Full, "experimental-full",
+   "Full dependency graph suitable"
+   " for explicitly building modules. This format "
+   "is experimental and will change.")),
 llvm::cl::init(ScanningOutputFormat::Make),
 llvm::cl::cat(DependencyScannerCategory));
 
@@ -463,6 +466,92 @@
   return false;
 }
 
+class P1689Deps {
+public:
+  void printDependencies(raw_ostream &OS) {
+addSourcePathsToRequires();
+// Sort the modules by name to get a deterministic order.
+llvm::sort(Rules, [](const P1689Rule &A, const P1689Rule &B) {
+  return A.PrimaryOutput < B.PrimaryOutput;
+});
+
+using namespace llvm::json;
+Array OutputRules;
+for (const P1689Rule &R : Rules) {
+  Object O{{"primary-output", R.PrimaryOutput}};
+
+  if (R.Provides) {
+Array Provides;
+Object Provided{{"logical-name", R.Provides->ModuleName},
+{"source-path", R.Provides->SourcePath},
+{"is-interface", R.Provides->IsStdCXXModuleInterface}};
+Provides.push_back(std::move(Provided));
+O.insert({"provides", std::move(Provides)});
+  }
+
+  Array Requires;
+  for (const P1689ModuleInfo &Info : R.Requires) {
+Object RequiredInfo{{"logical-name", Info.ModuleName}};
+if (!Info.SourcePath.empty())
+  RequiredInfo.insert({"source-path", Info.SourcePath});
+Requires.push_back(std::move(RequiredInfo));
+  }
+
+  if (!Requires.empty())
+O.insert({"requires", std::move(Requires)});
+
+  OutputRules.push_back(std::move(O));
+}
+
+Object Output{
+{"version", 1}, {"revision", 0}, {"rules", std::move(OutputRules)}};
+
+OS << llvm::formatv("{0:2}\n", Value(std::move(Output)));
+  }
+
+  void addRules(P1689Rule &Rule) {
+std::unique_lock LockGuard(Lock);
+Rules.push_back(Rule);
+  }
+
+private:
+  void addSourcePathsToRequires() {
+llvm::DenseMap ModuleSourceMapper;
+for (const P1689Rule &R : Rules)
+  if (R.Provides && !R.Provides->SourcePath.empty())
+ModuleSourceMapper[R.Provides->ModuleName] = R.Provides->SourcePath;
+
+for (P1689Rule &R : Rules) {
+  for (P1689ModuleInfo &Info : R.Requires) {
+auto Iter = ModuleSourceMapper.find(Info.ModuleName);
+if (Iter != ModuleSourceMapper.end())
+  Info.SourcePath = Iter->second;
+  }
+}
+  }
+
+  std::mutex Lock;
+  std::vector Rules;
+};
+
+static bool
+handleP1689DependencyToolResult(const std::string &Input,
+llvm::Expected &MaybeRule,
+P1689Deps &PD, SharedStream &Errs) {
+  if (!MaybeRule) {
+llvm::handleAllErrors(
+MaybeRule.takeError(), [&Input, &Errs](llvm::StringError &Err) {
+  Errs.applyLocked([&](raw_ostream &OS) {
+OS << "Error while scanning dependencies for " << Input << ":\n";
+OS << Err.getMessage();
+  });
+});
+return true;
+  }
+  PD.addRules(*MaybeRule);
+  return false;
+}
+
 /// Construct a path for the explic

[PATCH] D137527: [C++20] [Modules] [ClangScanDeps] Add ClangScanDeps support for C++20 Named Modules in P1689 format (2/4)

2023-02-12 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 496821.
ChuanqiXu added a comment.

While I failed to reproduce the failure in my local environment, I found a 
thread-safe defect in my code. I forgot to add a Lock for `P1689::addRules`. 
I'd like to recommit this one and see if the bot would still complain. Thank 
you for reporting and reverting this.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137527/new/

https://reviews.llvm.org/D137527

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/P1689.cppm
  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
@@ -133,12 +133,15 @@
 
 static llvm::cl::opt Format(
 "format", llvm::cl::desc("The output format for the dependencies"),
-llvm::cl::values(clEnumValN(ScanningOutputFormat::Make, "make",
-"Makefile compatible dep file"),
- clEnumValN(ScanningOutputFormat::Full, "experimental-full",
-"Full dependency graph suitable"
-" for explicitly building modules. This format "
-"is experimental and will change.")),
+llvm::cl::values(
+clEnumValN(ScanningOutputFormat::Make, "make",
+   "Makefile compatible dep file"),
+clEnumValN(ScanningOutputFormat::P1689, "p1689",
+   "Generate standard c++ modules dependency P1689 format"),
+clEnumValN(ScanningOutputFormat::Full, "experimental-full",
+   "Full dependency graph suitable"
+   " for explicitly building modules. This format "
+   "is experimental and will change.")),
 llvm::cl::init(ScanningOutputFormat::Make),
 llvm::cl::cat(DependencyScannerCategory));
 
@@ -463,6 +466,92 @@
   return false;
 }
 
+class P1689Deps {
+public:
+  void printDependencies(raw_ostream &OS) {
+addSourcePathsToRequires();
+// Sort the modules by name to get a deterministic order.
+llvm::sort(Rules, [](const P1689Rule &A, const P1689Rule &B) {
+  return A.PrimaryOutput < B.PrimaryOutput;
+});
+
+using namespace llvm::json;
+Array OutputRules;
+for (const P1689Rule &R : Rules) {
+  Object O{{"primary-output", R.PrimaryOutput}};
+
+  if (R.Provides) {
+Array Provides;
+Object Provided{{"logical-name", R.Provides->ModuleName},
+{"source-path", R.Provides->SourcePath},
+{"is-interface", R.Provides->IsStdCXXModuleInterface}};
+Provides.push_back(std::move(Provided));
+O.insert({"provides", std::move(Provides)});
+  }
+
+  Array Requires;
+  for (const P1689ModuleInfo &Info : R.Requires) {
+Object RequiredInfo{{"logical-name", Info.ModuleName}};
+if (!Info.SourcePath.empty())
+  RequiredInfo.insert({"source-path", Info.SourcePath});
+Requires.push_back(std::move(RequiredInfo));
+  }
+
+  if (!Requires.empty())
+O.insert({"requires", std::move(Requires)});
+
+  OutputRules.push_back(std::move(O));
+}
+
+Object Output{
+{"version", 1}, {"revision", 0}, {"rules", std::move(OutputRules)}};
+
+OS << llvm::formatv("{0:2}\n", Value(std::move(Output)));
+  }
+
+  void addRules(P1689Rule &Rule) {
+std::unique_lock LockGuard(Lock);
+Rules.push_back(Rule);
+  }
+
+private:
+  void addSourcePathsToRequires() {
+llvm::DenseMap ModuleSourceMapper;
+for (const P1689Rule &R : Rules)
+  if (R.Provides && !R.Provides->SourcePath.empty())
+ModuleSourceMapper[R.Provides->ModuleName] = R.Provides->SourcePath;
+
+for (P1689Rule &R : Rules) {
+  for (P1689ModuleInfo &Info : R.Requires) {
+auto Iter = ModuleSourceMapper.find(Info.ModuleName);
+if (Iter != ModuleSourceMapper.end())
+  Info.SourcePath = Iter->second;
+  }
+}
+  }
+
+  std::mutex Lock;
+  std::vector Rules;
+};
+
+static bool
+handleP1689DependencyToolResult(const std::string &Input,
+llvm::Expected &MaybeRule,
+P1689Deps &PD, SharedStream &Errs) {
+  if (!MaybeRule) {
+llvm::handleAllErrors(
+MaybeRule.takeError(), [&Input, &Errs](llvm::StringError &Err) {
+  Errs.applyLocked([&](raw_ostream &OS) {
+  

[PATCH] D137527: [C++20] [Modules] [ClangScanDeps] Add ClangScanDeps support for C++20 Named Modules in P1689 format (2/4)

2023-02-12 Thread NAKAMURA Takumi via Phabricator via cfe-commits
chapuni added a comment.

Excuse me, I have reverted 79a3803bb2cc 
, D137534 
 and this.
See also https://lab.llvm.org/buildbot/#/builders/239/builds/922

I guess `P1689Deps` would not be thread-safe.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137527/new/

https://reviews.llvm.org/D137527

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137527: [C++20] [Modules] [ClangScanDeps] Add ClangScanDeps support for C++20 Named Modules in P1689 format (2/4)

2023-02-11 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

I'm still seeing random crashes today on a linux buildbot in the test you added 
P1689 .cppm. Can you either fix or revert?

- https://lab.llvm.org/buildbot/#/builders/139/builds/35899
- https://lab.llvm.org/buildbot/#/builders/139/builds/35886

  corrupted size vs. prev_size while consolidating
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace.
   #0 0x55baf810283f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang-scan-deps+0x3f)
   #1 0x55baf8100214 SignalHandler(int) Signals.cpp:0:0
   #2 0x7fa226358420 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
   #3 0x7fa225e2500b raise 
/build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
   #4 0x7fa225e04859 abort 
/build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:81:7
   #5 0x7fa225e6f26e __libc_message 
/build/glibc-SzIz7B/glibc-2.31/libio/../sysdeps/posix/libc_fatal.c:155:5
   #6 0x7fa225e772fc /build/glibc-SzIz7B/glibc-2.31/malloc/malloc.c:5348:3
   #7 0x7fa225e7904e _int_free 
/build/glibc-SzIz7B/glibc-2.31/malloc/malloc.c:4245:6
   #8 0x7fa225e7c88d tcache_thread_shutdown 
/build/glibc-SzIz7B/glibc-2.31/malloc/malloc.c:2960:33
   #9 0x7fa225e7c88d __malloc_arena_thread_freeres 
/build/glibc-SzIz7B/glibc-2.31/malloc/arena.c:951:3
  #10 0x7fa22634c62f start_thread 
/build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:496:7
  #11 0x7fa225f01133 __clone 
/build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:97:0


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137527/new/

https://reviews.llvm.org/D137527

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137527: [C++20] [Modules] [ClangScanDeps] Add ClangScanDeps support for C++20 Named Modules in P1689 format (2/4)

2023-02-10 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D137527#4117675 , @uabelho wrote:

> Hi,
>
> There seems to be something funny going on with the
>
>   ClangScanDeps/P1689.cppm
>
> testcase added in this patch.
>
> It fails randomly for me on top of tree (4ad8f7a189570 
> ).
> Roughly 1 in 10 runs fail for me.
> E.g. with a crash like
>
>   Exit Code: 2
>   
>   Command Output (stderr):
>   --
>   PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
> and include the crash backtrace.
>   #0 0x004ef8b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
> (/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x4ef8b8)
>   #1 0x004ed5ae llvm::sys::RunSignalHandlers() 
> (/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x4ed5ae)
>   #2 0x004f0096 SignalHandler(int) Signals.cpp:0:0
>   #3 0x7f6518263630 __restore_rt sigaction.c:0:0
>   #4 0x00474f40 P1689Deps::addSourcePathsToRequires() crtstuff.c:0:0
>   #5 0x004666d1 P1689Deps::printDependencies(llvm::raw_ostream&) 
> crtstuff.c:0:0
>   #6 0x0046204a main 
> (/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x46204a)
>   #7 0x7f6515996555 __libc_start_main (/lib64/libc.so.6+0x22555)
>   #8 0x0045fcad _start 
> (/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x45fcad)
>   FileCheck error: '' is empty.
>   FileCheck command line:  
> /repo/uabelho/main-github/llvm/build-all/bin/FileCheck 
> /repo/uabelho/main-github/llvm/build-all/tools/clang/test/ClangScanDeps/Output/P1689.cppm.tmp/Checks.cpp
>  
> -DPREFIX=/repo/uabelho/main-github/llvm/build-all/tools/clang/test/ClangScanDeps/Output/P1689.cppm.tmp
>   
>   --
>   
>   
>   
>   Failed Tests (1):
> Clang :: ClangScanDeps/P1689.cppm
>
> or
>
>   Exit Code: 2
>   
>   Command Output (stderr):
>   --
>   PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
> and include the crash backtrace.
>#0 0x004ef8b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
> (/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x4ef8b8)
>#1 0x004ed5ae llvm::sys::RunSignalHandlers() 
> (/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x4ed5ae)
>#2 0x004f0096 SignalHandler(int) Signals.cpp:0:0
>#3 0x7f422b33e630 __restore_rt sigaction.c:0:0
>#4 0x7f4228a85387 raise (/lib64/libc.so.6+0x36387)
>#5 0x7f4228a86a78 abort (/lib64/libc.so.6+0x37a78)
>#6 0x7f4228ac7f67 __libc_message (/lib64/libc.so.6+0x78f67)
>#7 0x7f4228ad0329 _int_free malloc.c:0:0
>#8 0x0047e7ef void 
> std::vector std::allocator>::_M_realloc_insert  
> const&>(__gnu_cxx::__normal_iterator  std::vector std::allocator>>, 
> clang::tooling::dependencies::P1689Rule const&) 
> (/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x47e7ef)
>#9 0x0047cea1 std::_Function_handler main::$_1>::_M_invoke(std::_Any_data const&) ClangScanDeps.cpp:0:0
>   #10 0x0047ba3c std::_Function_handler llvm::ThreadPool::createTaskAndFuture(std::function ()>)::'lambda'()>::_M_invoke(std::_Any_data const&) crtstuff.c:0:0
>   #11 0x004b73e9 
> llvm::ThreadPool::processTasks(llvm::ThreadPoolTaskGroup*) 
> (/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x4b73e9)
>   #12 0x004b8358 void* 
> llvm::thread::ThreadProxy>(void*)
>  ThreadPool.cpp:0:0
>   #13 0x7f422b336ea5 start_thread pthread_create.c:0:0
>   #14 0x7f4228b4db0d clone (/lib64/libc.so.6+0xfeb0d)
>   FileCheck error: '' is empty.
>   FileCheck command line:  
> /repo/uabelho/main-github/llvm/build-all/bin/FileCheck 
> /repo/uabelho/main-github/llvm/build-all/tools/clang/test/ClangScanDeps/Output/P1689.cppm.tmp/Checks.cpp
>  
> -DPREFIX=/repo/uabelho/main-github/llvm/build-all/tools/clang/test/ClangScanDeps/Output/P1689.cppm.tmp
>   
>   --
>   
>   
>   
>   Failed Tests (1):
> Clang :: ClangScanDeps/P1689.cppm
>
> but I've also seen things like
>
>   *** Error in 
> `/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps': corrupted 
> size vs. prev_size: 0x7faf74000fc0 ***
>   === Backtrace: =
>   /lib64/libc.so.6(+0x7f474)[0x7fafa1ffa474]
>   /lib64/libc.so.6(+0x8156b)[0x7fafa1ffc56b]
>   /repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps[0x47e7ef]
>   /repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps[0x47cea1]
>   /repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps[0x47ba3c]
>   /repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps[0x4b73e9]
>   /repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps[0x4b8358]
>   /lib64/libpthread.so.0(+0x7ea5)[0x7fafa4862ea5]
>   /lib64/libc.so.6(clone+0x6d)[0x7fafa2079b0d]
>   === Memory map: 
>   0040-08ffa00

[PATCH] D137527: [C++20] [Modules] [ClangScanDeps] Add ClangScanDeps support for C++20 Named Modules in P1689 format (2/4)

2023-02-10 Thread Tom Weaver via Phabricator via cfe-commits
TWeaver added a comment.

@thakis @ChuanqiXu I have a revision up for review here 
https://reviews.llvm.org/D143749 that adds back the UNSUPPORTED: system-windows 
that was reverted in https://reviews.llvm.org/D139168


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137527/new/

https://reviews.llvm.org/D137527

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137527: [C++20] [Modules] [ClangScanDeps] Add ClangScanDeps support for C++20 Named Modules in P1689 format (2/4)

2023-02-10 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Either this or D139168  is breaking tests on 
Windows: http://45.33.8.238/win/74780/step_7.txt

Please take a look and revert for now if it takes a while to fix.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137527/new/

https://reviews.llvm.org/D137527

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137527: [C++20] [Modules] [ClangScanDeps] Add ClangScanDeps support for C++20 Named Modules in P1689 format (2/4)

2023-02-10 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

Hi,

There seems to be something funny going on with the ClangScanDeps/P1689 
.cppm testcase added in this patch.

It fails randomly for me on top of tree (4ad8f7a189570 
).
Roughly 1 in 10 runs fail for me.
E.g. with a crash like

  Exit Code: 2
  
  Command Output (stderr):
  --
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace.
  #0 0x004ef8b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x4ef8b8)
  #1 0x004ed5ae llvm::sys::RunSignalHandlers() 
(/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x4ed5ae)
  #2 0x004f0096 SignalHandler(int) Signals.cpp:0:0
  #3 0x7f6518263630 __restore_rt sigaction.c:0:0
  #4 0x00474f40 P1689Deps::addSourcePathsToRequires() crtstuff.c:0:0
  #5 0x004666d1 P1689Deps::printDependencies(llvm::raw_ostream&) 
crtstuff.c:0:0
  #6 0x0046204a main 
(/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x46204a)
  #7 0x7f6515996555 __libc_start_main (/lib64/libc.so.6+0x22555)
  #8 0x0045fcad _start 
(/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x45fcad)
  FileCheck error: '' is empty.
  FileCheck command line:  
/repo/uabelho/main-github/llvm/build-all/bin/FileCheck 
/repo/uabelho/main-github/llvm/build-all/tools/clang/test/ClangScanDeps/Output/P1689.cppm.tmp/Checks.cpp
 
-DPREFIX=/repo/uabelho/main-github/llvm/build-all/tools/clang/test/ClangScanDeps/Output/P1689.cppm.tmp
  
  --
  
  
  
  Failed Tests (1):
Clang :: ClangScanDeps/P1689.cppm

or

  Exit Code: 2
  
  Command Output (stderr):
  --
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace.
   #0 0x004ef8b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x4ef8b8)
   #1 0x004ed5ae llvm::sys::RunSignalHandlers() 
(/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x4ed5ae)
   #2 0x004f0096 SignalHandler(int) Signals.cpp:0:0
   #3 0x7f422b33e630 __restore_rt sigaction.c:0:0
   #4 0x7f4228a85387 raise (/lib64/libc.so.6+0x36387)
   #5 0x7f4228a86a78 abort (/lib64/libc.so.6+0x37a78)
   #6 0x7f4228ac7f67 __libc_message (/lib64/libc.so.6+0x78f67)
   #7 0x7f4228ad0329 _int_free malloc.c:0:0
   #8 0x0047e7ef void 
std::vector>::_M_realloc_insert(__gnu_cxx::__normal_iterator>>, 
clang::tooling::dependencies::P1689Rule const&) 
(/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x47e7ef)
   #9 0x0047cea1 std::_Function_handler::_M_invoke(std::_Any_data const&) ClangScanDeps.cpp:0:0
  #10 0x0047ba3c std::_Function_handler)::'lambda'()>::_M_invoke(std::_Any_data const&) crtstuff.c:0:0
  #11 0x004b73e9 
llvm::ThreadPool::processTasks(llvm::ThreadPoolTaskGroup*) 
(/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps+0x4b73e9)
  #12 0x004b8358 void* 
llvm::thread::ThreadProxy>(void*) 
ThreadPool.cpp:0:0
  #13 0x7f422b336ea5 start_thread pthread_create.c:0:0
  #14 0x7f4228b4db0d clone (/lib64/libc.so.6+0xfeb0d)
  FileCheck error: '' is empty.
  FileCheck command line:  
/repo/uabelho/main-github/llvm/build-all/bin/FileCheck 
/repo/uabelho/main-github/llvm/build-all/tools/clang/test/ClangScanDeps/Output/P1689.cppm.tmp/Checks.cpp
 
-DPREFIX=/repo/uabelho/main-github/llvm/build-all/tools/clang/test/ClangScanDeps/Output/P1689.cppm.tmp
  
  --
  
  
  
  Failed Tests (1):
Clang :: ClangScanDeps/P1689.cppm

but I've also seen things like

  *** Error in `/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps': 
corrupted size vs. prev_size: 0x7faf74000fc0 ***
  === Backtrace: =
  /lib64/libc.so.6(+0x7f474)[0x7fafa1ffa474]
  /lib64/libc.so.6(+0x8156b)[0x7fafa1ffc56b]
  /repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps[0x47e7ef]
  /repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps[0x47cea1]
  /repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps[0x47ba3c]
  /repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps[0x4b73e9]
  /repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps[0x4b8358]
  /lib64/libpthread.so.0(+0x7ea5)[0x7fafa4862ea5]
  /lib64/libc.so.6(clone+0x6d)[0x7fafa2079b0d]
  === Memory map: 
  0040-08ffa000 r-xp  fd:01 63551  
/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps
  08ffa000-09b44000 rw-p 08bf9000 fd:01 63551  
/repo/uabelho/main-github/llvm/build-all/bin/clang-scan-deps
  09b44000-09bbf000 rw-p  00:00 0 
  0a86a000-0a8f3000 rw-p  00:00 0  
[heap]
  7f

[PATCH] D137527: [C++20] [Modules] [ClangScanDeps] Add ClangScanDeps support for C++20 Named Modules in P1689 format (2/4)

2023-02-09 Thread Chuanqi Xu via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGde17c665e3f9: [C++20] [Modules] [ClangScanDeps] Add 
ClangScanDeps support for C++20 Named… (authored by ChuanqiXu).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D137527?vs=493475&id=496306#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137527/new/

https://reviews.llvm.org/D137527

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/P1689.cppm
  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
@@ -132,12 +132,15 @@
 
 static llvm::cl::opt Format(
 "format", llvm::cl::desc("The output format for the dependencies"),
-llvm::cl::values(clEnumValN(ScanningOutputFormat::Make, "make",
-"Makefile compatible dep file"),
- clEnumValN(ScanningOutputFormat::Full, "experimental-full",
-"Full dependency graph suitable"
-" for explicitly building modules. This format "
-"is experimental and will change.")),
+llvm::cl::values(
+clEnumValN(ScanningOutputFormat::Make, "make",
+   "Makefile compatible dep file"),
+clEnumValN(ScanningOutputFormat::P1689, "p1689",
+   "Generate standard c++ modules dependency P1689 format"),
+clEnumValN(ScanningOutputFormat::Full, "experimental-full",
+   "Full dependency graph suitable"
+   " for explicitly building modules. This format "
+   "is experimental and will change.")),
 llvm::cl::init(ScanningOutputFormat::Make),
 llvm::cl::cat(DependencyScannerCategory));
 
@@ -462,6 +465,88 @@
   return false;
 }
 
+class P1689Deps {
+public:
+  void printDependencies(raw_ostream &OS) {
+addSourcePathsToRequires();
+// Sort the modules by name to get a deterministic order.
+llvm::sort(Rules, [](const P1689Rule &A, const P1689Rule &B) {
+  return A.PrimaryOutput < B.PrimaryOutput;
+});
+
+using namespace llvm::json;
+Array OutputRules;
+for (const P1689Rule &R : Rules) {
+  Object O{{"primary-output", R.PrimaryOutput}};
+
+  if (R.Provides) {
+Array Provides;
+Object Provided{{"logical-name", R.Provides->ModuleName},
+{"source-path", R.Provides->SourcePath},
+{"is-interface", R.Provides->IsStdCXXModuleInterface}};
+Provides.push_back(std::move(Provided));
+O.insert({"provides", std::move(Provides)});
+  }
+
+  Array Requires;
+  for (const P1689ModuleInfo &Info : R.Requires) {
+Object RequiredInfo{{"logical-name", Info.ModuleName}};
+if (!Info.SourcePath.empty())
+  RequiredInfo.insert({"source-path", Info.SourcePath});
+Requires.push_back(std::move(RequiredInfo));
+  }
+
+  if (!Requires.empty())
+O.insert({"requires", std::move(Requires)});
+
+  OutputRules.push_back(std::move(O));
+}
+
+Object Output{
+{"version", 1}, {"revision", 0}, {"rules", std::move(OutputRules)}};
+
+OS << llvm::formatv("{0:2}\n", Value(std::move(Output)));
+  }
+
+  void addRules(P1689Rule &Rule) { Rules.push_back(Rule); }
+
+private:
+  void addSourcePathsToRequires() {
+llvm::DenseMap ModuleSourceMapper;
+for (const P1689Rule &R : Rules)
+  if (R.Provides && !R.Provides->SourcePath.empty())
+ModuleSourceMapper[R.Provides->ModuleName] = R.Provides->SourcePath;
+
+for (P1689Rule &R : Rules) {
+  for (P1689ModuleInfo &Info : R.Requires) {
+auto Iter = ModuleSourceMapper.find(Info.ModuleName);
+if (Iter != ModuleSourceMapper.end())
+  Info.SourcePath = Iter->second;
+  }
+}
+  }
+
+  std::vector Rules;
+};
+
+static bool
+handleP1689DependencyToolResult(const std::string &Input,
+llvm::Expected &MaybeRule,
+P1689Deps &PD, SharedStream &Errs) {
+  if (!MaybeRule) {
+llvm::handleAllErrors(
+