[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-02-18 Thread Mark de Wever via cfe-commits

mordante wrote:

> (This is another example that the github review can't work well with the 
> reverted patches...)
> 
> @mordante I think you can add `// REQUIRES: x86-registered-target` to the 
> test if @kaz7 can't respond quickly. It will skip the test on targets other 
> than x86. And it should keep the CI green and enable us to backport this 
> clang18.
> 
> We can still improve this later.

I've created https://github.com/llvm/llvm-project/pull/82160 as you suggested.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-02-17 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

(This is another example that the github review can't work well with the 
reverted patches...)

@mordante I think you can add `// REQUIRES: x86-registered-target` to the test 
if @kaz7 can't respond quickly. It will skip the test on targets other than 
x86. And it should keep the CI green and enable us to backport this clang18.

We can still improve this later.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-02-17 Thread Mark de Wever via cfe-commits

mordante wrote:

@kaz7 ping, can you have a look at the patch, I really like to reland this 
patch.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-02-10 Thread Mark de Wever via cfe-commits

mordante wrote:

@kaz7 ping

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-02-04 Thread Mark de Wever via cfe-commits

mordante wrote:

Thanks for reverting @AaronBallman I somehow missed this comment.

@kaz7 it should work on all platforms AFAIK. I don't have access to a VE 
system. Looking at some VE tests I wonder whether the following patch would 
work.
[patch.txt](https://github.com/llvm/llvm-project/files/14157135/patch.txt)


https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-23 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

The build is still failing, so I've reverted these changes in 
https://github.com/llvm/llvm-project/commit/82f424f766be00b037a706a835d0a0663a2680f1

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-22 Thread Kazushi Marukawa via cfe-commits

kaz7 wrote:

Hi @mordante,

Does this test, `Driver/modules-print-library-module-manifest-path.cpp`, work 
on other than x86?  It is failing on VE build bot like below.

https://lab.llvm.org/buildbot/#/builders/91/builds/22189

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-22 Thread Mark de Wever via cfe-commits

https://github.com/mordante closed 
https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-22 Thread Mark de Wever via cfe-commits

mordante wrote:

> LGTM with a few nits. Can you double check modules.json is inside `lib/` 
> (`usr/lib/x86_64-linux-gnu{{/|\\}}modules.json`) instead of some directory 
> under `include`?

Thanks for the review. The json will indeed be installed in the lib dir in 
libc++.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-22 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76451

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 01/13] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9bd..2e1e3b128744fff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,
+const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499cc..890257e11485b65 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4e..8d682f9238c6b87 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+}
+
 std::string 

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-21 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.

LGTM with a few nits. Can you double check modules.json is inside `lib/` 
(`usr/lib/x86_64-linux-gnu{{/|\\}}modules.json`) instead of some directory 
under `include`?

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-21 Thread Fangrui Song via cfe-commits


@@ -6135,6 +6141,45 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetStdModuleManifestPath(const Compilation ,
+ const ToolChain ) const {
+  std::string error = "";
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = GetFilePath("libc++.so", TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+// These flavours do not exist at the moment, but there are plans to
+// provide a variant that is built with sanitizer instrumentation enabled.
+
+// For example
+//  StringRef modules = [&] {
+//const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+//if (Sanitize.needsAsanRt())
+//  return "modules-asan.json";
+//return "modules.json";
+//  }();
+StringRef modules = "modules.json";

MaskRay wrote:

`modules` is only used once. inline it

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-21 Thread Fangrui Song via cfe-commits


@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.

MaskRay wrote:

Remove the FIXME. `CompilationInfo` has been removed long ago.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-21 Thread Mark de Wever via cfe-commits

mordante wrote:

@MaskRay can you have another look, it would be great to land this before LLVM 
18 branches, thanks!

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-21 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76451

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 01/12] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,
+const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+}
+
 std::string 

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-21 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76451

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 01/11] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9bd..2e1e3b128744fff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,
+const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499cc..890257e11485b65 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4e..8d682f9238c6b87 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+}
+
 std::string 

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-21 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76451

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 01/10] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9bd..2e1e3b128744fff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,
+const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499cc..890257e11485b65 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4e..8d682f9238c6b87 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+}
+
 std::string 

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-21 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76451

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 1/9] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9bd..2e1e3b128744fff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,
+const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499cc..890257e11485b65 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4e..8d682f9238c6b87 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+}
+
 std::string 

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-21 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76451

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 1/8] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,
+const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+}
+
 std::string 

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-20 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76451

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 1/7] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,
+const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+}
+
 std::string 

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-19 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76451

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 1/6] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,
+const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+}
+
 std::string 

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-19 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,40 @@
+// Test that -print-library-module-manifest-path finds the correct file.

mordante wrote:

not per se, I thought this was common in clang, I'll remove it.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-19 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,40 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: touch %t/libc++.so
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libc++ \
+// RUN: --sysroot=%t \
+// RUN: --target=x86_64-linux-gnu 2>&1 \
+// RUN:   | FileCheck libcxx-no-module-json.cpp
+
+// RUN: touch %t/modules.json
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libc++ \
+// RUN: --sysroot=%t \
+// RUN: --target=x86_64-linux-gnu 2>&1 \
+// RUN:   | FileCheck libcxx.cpp
+
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libstdc++ \
+// RUN: --sysroot=%S/Inputs/cxx23_modules \

mordante wrote:

No this is a left-over when it used on-disc files. Nice catch.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-19 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,40 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: rm -rf %t

mordante wrote:

I copied the 3 line version from another test, I'll fix it.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \

MaskRay wrote:

A lot of new options do support only the `--` form. For `--print-*` options, 
many support both `-` and `--`. Since it's difficult to remember, I think 
supporting both for the new option is fine. 

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,40 @@
+// Test that -print-library-module-manifest-path finds the correct file.

MaskRay wrote:

Is the `cxx23-` prefix useful?

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,40 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: touch %t/libc++.so
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libc++ \
+// RUN: --sysroot=%t \
+// RUN: --target=x86_64-linux-gnu 2>&1 \
+// RUN:   | FileCheck libcxx-no-module-json.cpp
+
+// RUN: touch %t/modules.json
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libc++ \
+// RUN: --sysroot=%t \
+// RUN: --target=x86_64-linux-gnu 2>&1 \
+// RUN:   | FileCheck libcxx.cpp

MaskRay wrote:

`GetFilePath("libc++.so")` may return `libc++.so` (no directory), which does 
not exist.

I think a better test is

```
%clang --target=x86_64-unknown-linux-gnu -ccc-install-dir 
%S/Inputs/basic_linux_libcxx_tree/usr/bin -stdlib=libc++ ...
```
and create an empty file 
`Inputs/basic_linux_libcxx_tree/usr/lib/x86_64-unknown-linux-gnu/libc++.so`

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Fangrui Song via cfe-commits


@@ -6135,6 +6141,42 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetStdModuleManifestPath(const Compilation ,
+ const ToolChain ) const {
+
+  std::string error = "";
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+   // These flavours do not exist at the moment, but there are plans to
+   // provide a variant that is built with sanitizer instrumentation 
enabled.
+
+// For example
+//  const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+//  if (Sanitize.needsAsanRt())
+//return path.replace(path.size() - lib.size(), lib.size(),
+//"modules-asan.json");
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");

MaskRay wrote:

`llvm::sys::path::remove_filename` + `appen`

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Fangrui Song via cfe-commits


@@ -6135,6 +6141,42 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetStdModuleManifestPath(const Compilation ,
+ const ToolChain ) const {
+

MaskRay wrote:

delete blank line

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Fangrui Song via cfe-commits


@@ -602,6 +602,17 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetStdModuleManifestPath - Lookup the path to the Standard library module

MaskRay wrote:

Remove `GetStdModuleManifestPath - ` for new code per 
https://llvm.org/docs/CodingStandards.html# "Don’t duplicate function or class 
name at the beginning of the comment." 

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,40 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: touch %t/libc++.so
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libc++ \
+// RUN: --sysroot=%t \
+// RUN: --target=x86_64-linux-gnu 2>&1 \
+// RUN:   | FileCheck libcxx-no-module-json.cpp
+
+// RUN: touch %t/modules.json
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libc++ \
+// RUN: --sysroot=%t \
+// RUN: --target=x86_64-linux-gnu 2>&1 \
+// RUN:   | FileCheck libcxx.cpp
+
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libstdc++ \
+// RUN: --sysroot=%S/Inputs/cxx23_modules \

MaskRay wrote:

Does `%S/Inputs/cxx23_modules` exist?

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,40 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: rm -rf %t

MaskRay wrote:

You can remove `mkdir -p %t` and simplify this to `rm -rf %t && split-file %s 
%t && cd %t`. This does place 3 commands on one line, but is pretty common.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-18 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76451

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 1/5] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,
+const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+}
+
 std::string 

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-17 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> > LGTM.
> > We need to delete 
> > `clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so` 
> > and 
> > `clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json`,
> >  we should generate them with `split-file`
> 
> Are you sure that is the proper way? Should these tests not use a complete 
> installation to make sure it works on installations?

We can use `mkdir` to generate more complex paths. For example,

```
// RUN: split-file %s %t
//
// RUN: mkdir %t/
// RUN: touch %t/.../libc++.so
```


The intention is to remove the use of `Inputs` in test. It is really hard to 
read.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-16 Thread Mark de Wever via cfe-commits

mordante wrote:

> LGTM.
> 
> We need to delete 
> `clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so` 
> and 
> `clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json`,
>  we should generate them with `split-file`

Are you sure that is the proper way? Should these tests not use a complete 
installation to make sure it works on installations?

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-14 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 edited 
https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-14 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 edited 
https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-14 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 approved this pull request.

LGTM.

While we need to delete 
`clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so` and 
`clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json`.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-12 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 8cf6bcf5a30673dd8a234ae3ef4ab4c1e63786b1 
a8f9dc9edd98416a84d524ca6b233a27882f5085 -- 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.cpp 
clang/include/clang/Driver/Driver.h clang/lib/Driver/Driver.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a3cae06fc6..0f9022f23f 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6153,8 +6153,8 @@ std::string Driver::GetStdModuleManifestPath(const 
Compilation ,
 
 // Note when there are multiple flavours of libc++ the module json needs to
 // look at the command-line arguments for the proper json.
-   // These flavours do not exist at the moment, but there are plans to
-   // provide a variant that is built with sanitizer instrumentation 
enabled.
+// These flavours do not exist at the moment, but there are plans to
+// provide a variant that is built with sanitizer instrumentation enabled.
 
 // For example
 //  const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());

``




https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-12 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76451

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 1/4] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,
+const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+}
+
 std::string 

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-12 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,9 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+//
+// Note this file is currently not available on Apple platforms

mordante wrote:

I'll remove this test for now. It can be added later when it's known where 
Apple will store this file.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-12 Thread Mark de Wever via cfe-commits


@@ -6135,6 +6141,42 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetStdModuleManifestPath(const Compilation ,
+ const ToolChain ) const {
+
+  std::string error = "";
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.

mordante wrote:

We don't have multiple flavours yet, but I've updated the comment to give a bit 
more information.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-11 Thread Chuanqi Xu via cfe-commits


@@ -6135,6 +6141,42 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetStdModuleManifestPath(const Compilation ,
+ const ToolChain ) const {
+
+  std::string error = "";
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*

ChuanqiXu9 wrote:

I rarely see the `/**/` comments in clang. Let's try to use multiple `//`

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-11 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libc++ \
+// RUN: --sysroot=%S/Inputs/cxx23_modules \
+// RUN: --target=x86_64-linux-gnu 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX %s
+// CHECK-LIBCXX: 
{{.*}}/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json

ChuanqiXu9 wrote:

Let's try to avoid use `Inputs` pattern nowadays. We can use `split-file` to 
multiple files into a single lit test. You can find the use example by 
searching `split-file` in `clang/test/Modules`

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-11 Thread Chuanqi Xu via cfe-commits


@@ -6135,6 +6141,42 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetStdModuleManifestPath(const Compilation ,
+ const ToolChain ) const {
+
+  std::string error = "";
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.

ChuanqiXu9 wrote:

As a people who don't super know libc++, it is confusing to understand 
`multiple flavous of libc++`, so if necessary, let's try to add a link here.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-11 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 commented:

LGTM generally.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-11 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,9 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+//
+// Note this file is currently not available on Apple platforms

ChuanqiXu9 wrote:

I don't get the intention for the test since there is standard library related 
things under `%S/Inputs/resource_dir`. Do you mean to search standard library 
things from the system path? If yes, that is not good and let's move this.

Generally we need a `// UNSUPPORTED:` directive when a lit test can't work in 
some platforms.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-11 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 edited 
https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-11 Thread Mark de Wever via cfe-commits

mordante wrote:

@ChuanqiXu9 can you do a full review? I'd like to have this reviewed so we can 
land it when the libc++ side is ready.


https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-11 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76451

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 1/3] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,
+const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+}
+
 std::string 

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-03 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76451

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 1/2] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,
+const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+}
+
 std::string 

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-03 Thread Mark de Wever via cfe-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-03 Thread Mark de Wever via cfe-commits

mordante wrote:

> If this is the right thing to do (i.e., printing this information as part of 
> `-print-search-dirs`), then perhaps it's still worth it to try and fix? Once 
> you add a separate option, you will have to drag it forever (for backwards 
> compatibility).
I have a feeling how deep that rabbit hole is. This is not something I really 
want to dive into. Especially since I'm unfamiliar with this part of the code.



https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-03 Thread Mark de Wever via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

mordante wrote:

I removed the prefix and return "" when the manifest is not 
present.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-30 Thread Boris Kolpackov via cfe-commits

boris-kolpackov wrote:

> I had looked at `-print-search-dirs` but it seems buggy. For example, it 
> ignores the `-stdlib` flag to the compiler invocation. 

True. I couldn't find a bug report for this so I filed one: 
https://github.com/llvm/llvm-project/issues/76614

> Solving this seems a lot of work. So didn't want to add new features to that 
> code.

If this is the right thing to do (i.e., printing this information as part of 
`-print-search-dirs`), then perhaps it's still worth it to try and fix? Once 
you add a separate option, you will have to drag it forever (for backwards 
compatibility).

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-30 Thread Mark de Wever via cfe-commits

mordante wrote:

I had looked at `-print-search-dirs` but it seems buggy. For example, it 
ignores the `-stdlib` flag to the compiler invocation. Solving this seems a lot 
of work. So didn't want to add new features to that code.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-29 Thread Boris Kolpackov via cfe-commits

boris-kolpackov wrote:

If I understand correctly, this invents a new option just to print the std 
modules path. Is there a reason why we cannot just print this information as 
part of `-print-search-dirs`? The benefit of this will be saving an extra 
compiler invocation in case the build system already uses this option, for 
example, to extract the library search paths (`build2` does this). BTW, this 
would also allow you to sidestep the whole "what to print if there is no path" 
issue -- just omit the entry from the output.

If for some reason a separate option is desirable, can we then also print this 
information as part of `-print-search-dirs`?

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-29 Thread Ben Boeckel via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

mathstuf wrote:

I suppose that's good enough; we also don't get reasons why `-stdlib=libstdc++` 
fails due to non-install either.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-29 Thread Mark de Wever via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

mordante wrote:

> I'd like there to be some distinction between "modules not present because 
> Clang was built without them" and "modules not present but expected to be 
> there" (maybe distro packagers split things and the modules package is 
> missing?).

However that is hard to do and might be wrong. Currently stdlibc++ does not 
ship modules. I don't know how clang-18 will ever find them stdlibc++-15 since 
it's unknown whether that version will have modules nor do I know the name of 
their manifest file.

Same for Clang and libc++,  Clang has no idea whether libc++ was build with or 
without modules. They are build independently. So it would need to look at the 
version information of libc++ to detect whether it's libc++-18 or earlier. 
Earlier never has the manifest.

IMO tool vendors should look at the output of this command; it either contains 
a path or a single error value. If it's the error value they should not attempt 
to build the std module.

What would be the benefit of different errors @mathstuf ? Especially 
considering the above that it's hard to determine the proper error message.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-29 Thread Thorsten Schütt via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

tschuett wrote:

If the output starts with a /, then it is the path. If the output starts with 
error:, then there will be some actionable information. 

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-29 Thread Ben Boeckel via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

mathstuf wrote:

I'd like there to be some distinction between "modules not present because 
Clang was built without them" and "modules not present but expected to be 
there" (maybe distro packagers split things and the modules package is 
missing?).

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-28 Thread Chuanqi Xu via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

ChuanqiXu9 wrote:

But "module: =" doesn't look like an error value too. And I feel it just adds 
the work the tool vendors need to do. @mathstuf @boris-kolpackov do you have an 
opinion here?

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-28 Thread Mark de Wever via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

mordante wrote:

returning an empty string gives an empty output. This feels wrong, returning an 
error value indicates the tool has done something with the request. No output 
may mean the request has been ignored.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-28 Thread Chuanqi Xu via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

ChuanqiXu9 wrote:

I don't get why we can't just return empty string if we can't find it.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-28 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.

ChuanqiXu9 wrote:

Let's change the suffix of this file to `.cpp`

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-28 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,9 @@
+// Test that -print-library-module-manifest-path finds the correct file.

ChuanqiXu9 wrote:

Let's change the suffix.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-28 Thread Chuanqi Xu via cfe-commits


@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.

ChuanqiXu9 wrote:

Got it. I didn't look into the context.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-28 Thread Mark de Wever via cfe-commits


@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.

mordante wrote:

I copied it from the functions above, I have not investigated why the FIXME is 
there.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-28 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libc++ \
+// RUN: --sysroot=%S/Inputs/cxx23_modules \
+// RUN: --target=x86_64-linux-gnu 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX %s
+// CHECK-LIBCXX: module: 
={{.*}}/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
+

mordante wrote:

not sure, I've never used --gcc-toolchain either.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-28 Thread Mark de Wever via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

mordante wrote:

some places do some don't. Since I had an empty string as "error-code" it makes 
sense to print a prefix. If we use another error-code we could remove the 
prefix.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-28 Thread Thorsten Schütt via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

tschuett wrote:

```shell
> clang --print-resource-dir

prints just a path without any prefix.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Chuanqi Xu via cfe-commits


@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.

ChuanqiXu9 wrote:

If possible, let's explain the reason why we choose to put it here.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Chuanqi Xu via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

ChuanqiXu9 wrote:

Do we need the prefix? I am wondering if the plain path are good enough.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libc++ \
+// RUN: --sysroot=%S/Inputs/cxx23_modules \
+// RUN: --target=x86_64-linux-gnu 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX %s
+// CHECK-LIBCXX: module: 
={{.*}}/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
+

ChuanqiXu9 wrote:

Is there a path for libc++ like `--gcc-toolchain=` so that we can choose the 
different locations for libstdc++?

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Chuanqi Xu via cfe-commits


@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,

ChuanqiXu9 wrote:

```suggestion
  std::string GetStdModuleManifestPath(const Compilation ,
```

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Chuanqi Xu via cfe-commits


@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,

ChuanqiXu9 wrote:

```suggestion
def print_std_module_manifest_path : Flag<["-", "--"], 
"print-std-module-manifest-path">,
```

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Chuanqi Xu via cfe-commits


@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.

ChuanqiXu9 wrote:

```suggestion
  /// GetStdModuleManifestPath - Lookup the path to the module of the Standard 
library manifest.
```

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \

mordante wrote:

I wasn't aware of that. I got used to using one dash using clang.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits


@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";

mordante wrote:

I like one error value, the goal of the output is to be usable by tools. 

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Thorsten Schütt via cfe-commits


@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";

tschuett wrote:

Note: found unknown STL.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Thorsten Schütt via cfe-commits


@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";

tschuett wrote:

Note: libstdc++ is not supported.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Thorsten Schütt via cfe-commits


@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";

tschuett wrote:

Note: path foo does not exist.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Thorsten Schütt via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \

tschuett wrote:

The trend seems to go to two dashes and there are no tests for 2 dashes.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits


@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,

mordante wrote:

That is an option, I could do `` or something like that. I'm not 
sure what the tool vendors prefer. A magic string or an empty string.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \

mordante wrote:

They work with one or two dashes, `Flag<["-", "--"]`, in `Options.td` does 
that. This option does the same.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Thorsten Schütt via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \

tschuett wrote:

--print-runtime-dir, --print-target-triple,  --print-supported-cpus, and 
--print-supported-extensions take 2 dashes.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Thorsten Schütt via cfe-commits


@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,

tschuett wrote:

Could this be something fallible instead? Printing "" for GNU is suboptimal.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Mark de Wever (mordante)


Changes

This implements a way for the compiler to find the modules.json associated with 
the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library 
installs this manifest. #75741 adds this feature in libc++.

---
Full diff: https://github.com/llvm/llvm-project/pull/76451.diff


7 Files Affected:

- (modified) clang/include/clang/Driver/Driver.h (+10) 
- (modified) clang/include/clang/Driver/Options.td (+3) 
- (modified) clang/lib/Driver/Driver.cpp (+40) 
- (added) 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so () 
- (added) 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json () 
- (added) clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c 
(+15) 
- (added) clang/test/Driver/darwin-print-library-module-manifest-path.c (+9) 


``diff
diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,
+const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+}
+
 std::string Driver::GetTemporaryPath(StringRef Prefix, StringRef Suffix) const 
{
   SmallString<128> Path;
   std::error_code EC = llvm::sys::fs::createTemporaryFile(Prefix, Suffix, 
Path);
diff --git 
a/clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so 
b/clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
new file mode 100644
index 

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/76451

This implements a way for the compiler to find the modules.json associated with 
the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library 
installs this manifest. #75741 adds this feature in libc++.

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation ,
+const ToolChain ) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain ) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation ,
+  const ToolChain ) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs  = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(),