[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-06-24 Thread Michael Klemm via cfe-commits

mjklemm wrote:

Yeah, go ahead and revert. I can create a new PR from it just print the 
resource dir. 

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-06-24 Thread David Truby via cfe-commits

DavidTruby wrote:

Hi @mjklemm, this appears to be breaking linking entirely on Windows, I'm not 
sure how it's taken us so long to notice...
With the patch I get errors trying to find compiler-rt but without it I can 
build fine. I wonder why this patch _changed_ the resource directory, as well 
as making it printable with a flag?

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-14 Thread Michael Klemm via cfe-commits

mjklemm wrote:

@tblah @banach-space Thanks for the reviews! 

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-14 Thread Michael Klemm via cfe-commits

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-13 Thread Tom Eccles via cfe-commits

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

Apologies for losing track of this, I was on holiday all of last week.

This LGTM

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-13 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/90886

>From 1a994159025f127f0f7d11da80b74035788d52c9 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 14:50:45 +0200
Subject: [PATCH 1/8] Enable -print-resource-dir also for Flang

---
 clang/include/clang/Driver/Options.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 864da4e1157f7..a3b81fa338bdc 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5474,7 +5474,7 @@ def print_prog_name_EQ : Joined<["-", "--"], 
"print-prog-name=">,
   Visibility<[ClangOption, CLOption]>;
 def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
   HelpText<"Print the resource directory pathname">,
-  Visibility<[ClangOption, CLOption]>;
+  Visibility<[ClangOption, CLOption, FlangOption]>;
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;

>From beee04f6f2d411694f5ae1ee6130a81a632164df Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 16:19:38 +0200
Subject: [PATCH 2/8] Add setResourceDir function to set resource directory for
 Flang

This should be an NFC change for anythign, but Flang.
---
 clang/include/clang/Driver/Driver.h |  3 +++
 clang/lib/Driver/Driver.cpp | 23 ---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 2ffc52bcb7ad3..c36595e62e2da 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -752,6 +752,9 @@ class Driver {
   /// option.
   void setDriverMode(StringRef DriverModeValue);
 
+  /// Set the resource directory, depending on which driver is being used.
+  void setResourceDirectory();
+
   /// Parse the \p Args list for LTO options and record the type of LTO
   /// compilation based on which -f(no-)?lto(=.*)? option occurs last.
   void setLTOMode(const llvm::opt::ArgList );
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 114320f5d3146..d75d2e88fc102 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -229,9 +229,6 @@ Driver::Driver(StringRef ClangExecutable, StringRef 
TargetTriple,
 UserConfigDir = static_cast(P);
   }
 #endif
-
-  // Compute the path to the resource directory.
-  ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
 }
 
 void Driver::setDriverMode(StringRef Value) {
@@ -250,6 +247,25 @@ void Driver::setDriverMode(StringRef Value) {
 Diag(diag::err_drv_unsupported_option_argument) << OptName << Value;
 }
 
+void Driver::setResourceDirectory() {
+  // Compute the path to the resource directory, depending on the driver mode.
+  switch (Mode) {
+  case GCCMode:
+  case GXXMode:
+  case CPPMode:
+  case CLMode:
+  case DXCMode:
+ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
+break;
+  case FlangMode:
+// TODO: Is there a better way to add the "../include/flang/" component?
+SmallString<64> relPath{};
+llvm::sys::path::append(relPath, "..", "include", "flang");
+ResourceDir = GetResourcesPath(ClangExecutable, relPath);
+break;
+  }
+}
+
 InputArgList Driver::ParseArgStrings(ArrayRef ArgStrings,
  bool UseDriverMode, bool ) {
   llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
@@ -1202,6 +1218,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   if (!DriverMode.empty())
 setDriverMode(DriverMode);
 
+  setResourceDirectory();
   // FIXME: What are we going to do with -V and -b?
 
   // Arguments specified in command line.

>From 5ca34138043ab621582085e7034349c7e726a970 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 20:31:04 +0200
Subject: [PATCH 3/8] Update/add tests fir -print-resource-dir

---
 flang/test/Driver/driver-help-hidden.f90 | 1 +
 flang/test/Driver/print-resource-dir.F90 | 3 +++
 2 files changed, 4 insertions(+)
 create mode 100644 flang/test/Driver/print-resource-dir.F90

diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 706b2cb6c2452..73b34bd321c5f 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -143,6 +143,7 @@
 ! CHECK-NEXT: -oWrite output to 
 ! CHECK-NEXT: -pedantic   Warn on language extensions
 ! CHECK-NEXT: -print-effective-triple Print the effective target triple
+! CHECK-NEXT: -print-resource-dir Print the resource directory pathname
 ! CHECK-NEXT: -print-target-triplePrint the normalized target triple
 ! CHECK-NEXT: -pthreadSupport POSIX threads in generated code
 ! CHECK-NEXT: -P  Disable linemarker 

[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-07 Thread Michael Klemm via cfe-commits

mjklemm wrote:

@tblah Ping :-)

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Michael Klemm via cfe-commits

mjklemm wrote:

> and for addressing my comments

More than happy to!  Still learning how to be a proper Flang developer, so I'm 
thankful for all the comments!

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Andrzej Warzyński via cfe-commits

https://github.com/banach-space approved this pull request.

LGTM, thanks for working on this and for addressing my comments  

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Michael Klemm via cfe-commits

mjklemm wrote:

> Do you know the meaning for Classic Flang?

The way `-print-resource-dir` now works should be consistent with how Classic 
Flang works.  If that's not the right response, I guess I got my wires crossed 
and you need to explain it to me. :-) 

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Michael Klemm via cfe-commits


@@ -5474,7 +5474,7 @@ def print_prog_name_EQ : Joined<["-", "--"], 
"print-prog-name=">,
   Visibility<[ClangOption, CLOption]>;
 def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
   HelpText<"Print the resource directory pathname">,
-  Visibility<[ClangOption, CLOption]>;
+  Visibility<[ClangOption, CLOption, FlangOption]>;

mjklemm wrote:

You're correct that user-friendliness should be preferred.  I have updated the 
text to be more explicit about where the path printed will point to.

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/90886

>From 1a994159025f127f0f7d11da80b74035788d52c9 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 14:50:45 +0200
Subject: [PATCH 1/7] Enable -print-resource-dir also for Flang

---
 clang/include/clang/Driver/Options.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 864da4e1157f7d..a3b81fa338bdcd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5474,7 +5474,7 @@ def print_prog_name_EQ : Joined<["-", "--"], 
"print-prog-name=">,
   Visibility<[ClangOption, CLOption]>;
 def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
   HelpText<"Print the resource directory pathname">,
-  Visibility<[ClangOption, CLOption]>;
+  Visibility<[ClangOption, CLOption, FlangOption]>;
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;

>From beee04f6f2d411694f5ae1ee6130a81a632164df Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 16:19:38 +0200
Subject: [PATCH 2/7] Add setResourceDir function to set resource directory for
 Flang

This should be an NFC change for anythign, but Flang.
---
 clang/include/clang/Driver/Driver.h |  3 +++
 clang/lib/Driver/Driver.cpp | 23 ---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 2ffc52bcb7ad3b..c36595e62e2daf 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -752,6 +752,9 @@ class Driver {
   /// option.
   void setDriverMode(StringRef DriverModeValue);
 
+  /// Set the resource directory, depending on which driver is being used.
+  void setResourceDirectory();
+
   /// Parse the \p Args list for LTO options and record the type of LTO
   /// compilation based on which -f(no-)?lto(=.*)? option occurs last.
   void setLTOMode(const llvm::opt::ArgList );
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 114320f5d31468..d75d2e88fc1024 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -229,9 +229,6 @@ Driver::Driver(StringRef ClangExecutable, StringRef 
TargetTriple,
 UserConfigDir = static_cast(P);
   }
 #endif
-
-  // Compute the path to the resource directory.
-  ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
 }
 
 void Driver::setDriverMode(StringRef Value) {
@@ -250,6 +247,25 @@ void Driver::setDriverMode(StringRef Value) {
 Diag(diag::err_drv_unsupported_option_argument) << OptName << Value;
 }
 
+void Driver::setResourceDirectory() {
+  // Compute the path to the resource directory, depending on the driver mode.
+  switch (Mode) {
+  case GCCMode:
+  case GXXMode:
+  case CPPMode:
+  case CLMode:
+  case DXCMode:
+ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
+break;
+  case FlangMode:
+// TODO: Is there a better way to add the "../include/flang/" component?
+SmallString<64> relPath{};
+llvm::sys::path::append(relPath, "..", "include", "flang");
+ResourceDir = GetResourcesPath(ClangExecutable, relPath);
+break;
+  }
+}
+
 InputArgList Driver::ParseArgStrings(ArrayRef ArgStrings,
  bool UseDriverMode, bool ) {
   llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
@@ -1202,6 +1218,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   if (!DriverMode.empty())
 setDriverMode(DriverMode);
 
+  setResourceDirectory();
   // FIXME: What are we going to do with -V and -b?
 
   // Arguments specified in command line.

>From 5ca34138043ab621582085e7034349c7e726a970 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 20:31:04 +0200
Subject: [PATCH 3/7] Update/add tests fir -print-resource-dir

---
 flang/test/Driver/driver-help-hidden.f90 | 1 +
 flang/test/Driver/print-resource-dir.F90 | 3 +++
 2 files changed, 4 insertions(+)
 create mode 100644 flang/test/Driver/print-resource-dir.F90

diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 706b2cb6c2452c..73b34bd321c5f6 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -143,6 +143,7 @@
 ! CHECK-NEXT: -oWrite output to 
 ! CHECK-NEXT: -pedantic   Warn on language extensions
 ! CHECK-NEXT: -print-effective-triple Print the effective target triple
+! CHECK-NEXT: -print-resource-dir Print the resource directory pathname
 ! CHECK-NEXT: -print-target-triplePrint the normalized target triple
 ! CHECK-NEXT: -pthreadSupport POSIX threads in generated code
 ! CHECK-NEXT: -P  Disable 

[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Andrzej Warzyński via cfe-commits

banach-space wrote:

> > How does this compare to GFortran and Classic Flang? Anything resembling 
> > this flag?
> 
> GFortran does not have it, but Classic Flang does. So, it's closing a gap to 
> Classic Flang here as well.

Do you know the meaning for Classic Flang? Would be great to make "LLVM Flang" 
consistent with any "prior art". Nice to have ;-)

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,3 @@
+! RUN: %flang -print-resource-dir -resource-dir=%S/Inputs/resource_dir \
+! RUN:  | FileCheck -check-prefix=PRINT-RESOURCE-DIR 
-DFILE=%S/Inputs/resource_dir %s

banach-space wrote:

> So, my feeling is that this refactoring should take place in a different PR.

Makes sense.

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Andrzej Warzyński via cfe-commits


@@ -5474,7 +5474,7 @@ def print_prog_name_EQ : Joined<["-", "--"], 
"print-prog-name=">,
   Visibility<[ClangOption, CLOption]>;
 def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
   HelpText<"Print the resource directory pathname">,
-  Visibility<[ClangOption, CLOption]>;
+  Visibility<[ClangOption, CLOption, FlangOption]>;

banach-space wrote:

> Do you suggest that the help message needs to be more verbose for Flang? 

Yes. Why not make it more user-friendly? It's a nice to have though.

> Print the resource directory pathname where Flang stores the 'lib' and 
> 'include' folder

Looking at your reply earlier:

> I'd like to at least have it point to where the MODULE files live.

Shouldn't help text mention MODULEs?

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/90886

>From 1a994159025f127f0f7d11da80b74035788d52c9 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 14:50:45 +0200
Subject: [PATCH 1/6] Enable -print-resource-dir also for Flang

---
 clang/include/clang/Driver/Options.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 864da4e1157f7d..a3b81fa338bdcd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5474,7 +5474,7 @@ def print_prog_name_EQ : Joined<["-", "--"], 
"print-prog-name=">,
   Visibility<[ClangOption, CLOption]>;
 def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
   HelpText<"Print the resource directory pathname">,
-  Visibility<[ClangOption, CLOption]>;
+  Visibility<[ClangOption, CLOption, FlangOption]>;
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;

>From beee04f6f2d411694f5ae1ee6130a81a632164df Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 16:19:38 +0200
Subject: [PATCH 2/6] Add setResourceDir function to set resource directory for
 Flang

This should be an NFC change for anythign, but Flang.
---
 clang/include/clang/Driver/Driver.h |  3 +++
 clang/lib/Driver/Driver.cpp | 23 ---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 2ffc52bcb7ad3b..c36595e62e2daf 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -752,6 +752,9 @@ class Driver {
   /// option.
   void setDriverMode(StringRef DriverModeValue);
 
+  /// Set the resource directory, depending on which driver is being used.
+  void setResourceDirectory();
+
   /// Parse the \p Args list for LTO options and record the type of LTO
   /// compilation based on which -f(no-)?lto(=.*)? option occurs last.
   void setLTOMode(const llvm::opt::ArgList );
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 114320f5d31468..d75d2e88fc1024 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -229,9 +229,6 @@ Driver::Driver(StringRef ClangExecutable, StringRef 
TargetTriple,
 UserConfigDir = static_cast(P);
   }
 #endif
-
-  // Compute the path to the resource directory.
-  ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
 }
 
 void Driver::setDriverMode(StringRef Value) {
@@ -250,6 +247,25 @@ void Driver::setDriverMode(StringRef Value) {
 Diag(diag::err_drv_unsupported_option_argument) << OptName << Value;
 }
 
+void Driver::setResourceDirectory() {
+  // Compute the path to the resource directory, depending on the driver mode.
+  switch (Mode) {
+  case GCCMode:
+  case GXXMode:
+  case CPPMode:
+  case CLMode:
+  case DXCMode:
+ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
+break;
+  case FlangMode:
+// TODO: Is there a better way to add the "../include/flang/" component?
+SmallString<64> relPath{};
+llvm::sys::path::append(relPath, "..", "include", "flang");
+ResourceDir = GetResourcesPath(ClangExecutable, relPath);
+break;
+  }
+}
+
 InputArgList Driver::ParseArgStrings(ArrayRef ArgStrings,
  bool UseDriverMode, bool ) {
   llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
@@ -1202,6 +1218,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   if (!DriverMode.empty())
 setDriverMode(DriverMode);
 
+  setResourceDirectory();
   // FIXME: What are we going to do with -V and -b?
 
   // Arguments specified in command line.

>From 5ca34138043ab621582085e7034349c7e726a970 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 20:31:04 +0200
Subject: [PATCH 3/6] Update/add tests fir -print-resource-dir

---
 flang/test/Driver/driver-help-hidden.f90 | 1 +
 flang/test/Driver/print-resource-dir.F90 | 3 +++
 2 files changed, 4 insertions(+)
 create mode 100644 flang/test/Driver/print-resource-dir.F90

diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 706b2cb6c2452c..73b34bd321c5f6 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -143,6 +143,7 @@
 ! CHECK-NEXT: -oWrite output to 
 ! CHECK-NEXT: -pedantic   Warn on language extensions
 ! CHECK-NEXT: -print-effective-triple Print the effective target triple
+! CHECK-NEXT: -print-resource-dir Print the resource directory pathname
 ! CHECK-NEXT: -print-target-triplePrint the normalized target triple
 ! CHECK-NEXT: -pthreadSupport POSIX threads in generated code
 ! CHECK-NEXT: -P  Disable 

[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Michael Klemm via cfe-commits


@@ -5474,7 +5474,7 @@ def print_prog_name_EQ : Joined<["-", "--"], 
"print-prog-name=">,
   Visibility<[ClangOption, CLOption]>;
 def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
   HelpText<"Print the resource directory pathname">,
-  Visibility<[ClangOption, CLOption]>;
+  Visibility<[ClangOption, CLOption, FlangOption]>;

mjklemm wrote:

Do you suggest that the help message needs to be more verbose for Flang?  Clang 
and Classic Flang use the same message.  If it should be more verbose, how 
about this:

*Print the resource directory pathname where Flang stores the 'lib' and 
'include' folder*

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/90886

>From 1a994159025f127f0f7d11da80b74035788d52c9 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 14:50:45 +0200
Subject: [PATCH 1/5] Enable -print-resource-dir also for Flang

---
 clang/include/clang/Driver/Options.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 864da4e1157f7d..a3b81fa338bdcd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5474,7 +5474,7 @@ def print_prog_name_EQ : Joined<["-", "--"], 
"print-prog-name=">,
   Visibility<[ClangOption, CLOption]>;
 def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
   HelpText<"Print the resource directory pathname">,
-  Visibility<[ClangOption, CLOption]>;
+  Visibility<[ClangOption, CLOption, FlangOption]>;
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;

>From beee04f6f2d411694f5ae1ee6130a81a632164df Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 16:19:38 +0200
Subject: [PATCH 2/5] Add setResourceDir function to set resource directory for
 Flang

This should be an NFC change for anythign, but Flang.
---
 clang/include/clang/Driver/Driver.h |  3 +++
 clang/lib/Driver/Driver.cpp | 23 ---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 2ffc52bcb7ad3b..c36595e62e2daf 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -752,6 +752,9 @@ class Driver {
   /// option.
   void setDriverMode(StringRef DriverModeValue);
 
+  /// Set the resource directory, depending on which driver is being used.
+  void setResourceDirectory();
+
   /// Parse the \p Args list for LTO options and record the type of LTO
   /// compilation based on which -f(no-)?lto(=.*)? option occurs last.
   void setLTOMode(const llvm::opt::ArgList );
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 114320f5d31468..d75d2e88fc1024 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -229,9 +229,6 @@ Driver::Driver(StringRef ClangExecutable, StringRef 
TargetTriple,
 UserConfigDir = static_cast(P);
   }
 #endif
-
-  // Compute the path to the resource directory.
-  ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
 }
 
 void Driver::setDriverMode(StringRef Value) {
@@ -250,6 +247,25 @@ void Driver::setDriverMode(StringRef Value) {
 Diag(diag::err_drv_unsupported_option_argument) << OptName << Value;
 }
 
+void Driver::setResourceDirectory() {
+  // Compute the path to the resource directory, depending on the driver mode.
+  switch (Mode) {
+  case GCCMode:
+  case GXXMode:
+  case CPPMode:
+  case CLMode:
+  case DXCMode:
+ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
+break;
+  case FlangMode:
+// TODO: Is there a better way to add the "../include/flang/" component?
+SmallString<64> relPath{};
+llvm::sys::path::append(relPath, "..", "include", "flang");
+ResourceDir = GetResourcesPath(ClangExecutable, relPath);
+break;
+  }
+}
+
 InputArgList Driver::ParseArgStrings(ArrayRef ArgStrings,
  bool UseDriverMode, bool ) {
   llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
@@ -1202,6 +1218,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   if (!DriverMode.empty())
 setDriverMode(DriverMode);
 
+  setResourceDirectory();
   // FIXME: What are we going to do with -V and -b?
 
   // Arguments specified in command line.

>From 5ca34138043ab621582085e7034349c7e726a970 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 20:31:04 +0200
Subject: [PATCH 3/5] Update/add tests fir -print-resource-dir

---
 flang/test/Driver/driver-help-hidden.f90 | 1 +
 flang/test/Driver/print-resource-dir.F90 | 3 +++
 2 files changed, 4 insertions(+)
 create mode 100644 flang/test/Driver/print-resource-dir.F90

diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 706b2cb6c2452c..73b34bd321c5f6 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -143,6 +143,7 @@
 ! CHECK-NEXT: -oWrite output to 
 ! CHECK-NEXT: -pedantic   Warn on language extensions
 ! CHECK-NEXT: -print-effective-triple Print the effective target triple
+! CHECK-NEXT: -print-resource-dir Print the resource directory pathname
 ! CHECK-NEXT: -print-target-triplePrint the normalized target triple
 ! CHECK-NEXT: -pthreadSupport POSIX threads in generated code
 ! CHECK-NEXT: -P  Disable 

[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Michael Klemm via cfe-commits


@@ -0,0 +1,3 @@
+! RUN: %flang -print-resource-dir -resource-dir=%S/Inputs/resource_dir \
+! RUN:  | FileCheck -check-prefix=PRINT-RESOURCE-DIR 
-DFILE=%S/Inputs/resource_dir %s

mjklemm wrote:

I'll make the variable a bit clearer in the next update.  That's a good 
suggestion, thanks!

As for `ClangExecutable`, I haven't looked at where this is being defined.  
It's indeed the driver name and not the name of the Clang driver.  So, for 
Flang is actually contains the full path to `flang-new`.

I'm not opposed to renaming it as part of this PR, but it may widen the scope 
and make approval a bit more complex.  So, my feeling is that this refactoring 
should take place in a different PR.  But I can be convinced otherwise.

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Michael Klemm via cfe-commits


@@ -0,0 +1,3 @@
+! RUN: %flang -print-resource-dir -resource-dir=%S/Inputs/resource_dir \
+! RUN:  | FileCheck -check-prefix=PRINT-RESOURCE-DIR 
-DFILE=%S/Inputs/resource_dir %s
+! PRINT-RESOURCE-DIR: [[FILE]]

mjklemm wrote:

It does not.  The `/Inputs/resource_dir` part has no relevance and I have 
copied that verbatim from what Clang does for its driver test.  I will change 
this to use DEFINE to simplify it.

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Michael Klemm via cfe-commits

mjklemm wrote:

> How does this compare to GFortran and Classic Flang? Anything resembling this 
> flag?

GFortran does not have it, but Classic Flang does.  So, it's closing a gap to 
Classic Flang here as well.

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Andrzej Warzyński via cfe-commits


@@ -5474,7 +5474,7 @@ def print_prog_name_EQ : Joined<["-", "--"], 
"print-prog-name=">,
   Visibility<[ClangOption, CLOption]>;
 def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
   HelpText<"Print the resource directory pathname">,
-  Visibility<[ClangOption, CLOption]>;
+  Visibility<[ClangOption, CLOption, FlangOption]>;

banach-space wrote:

You can use `HelpVariant` to and help text specific to Flang. Example:
* 
https://github.com/llvm/llvm-project/blob/6d44a1ef55b559e59d725b07ffe1da988b4e5f1c/clang/include/clang/Driver/Options.td#L813-L815

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,3 @@
+! RUN: %flang -print-resource-dir -resource-dir=%S/Inputs/resource_dir \
+! RUN:  | FileCheck -check-prefix=PRINT-RESOURCE-DIR 
-DFILE=%S/Inputs/resource_dir %s
+! PRINT-RESOURCE-DIR: [[FILE]]

banach-space wrote:

I have a suspicion that this would also print clang-specific stuff?

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,3 @@
+! RUN: %flang -print-resource-dir -resource-dir=%S/Inputs/resource_dir \
+! RUN:  | FileCheck -check-prefix=PRINT-RESOURCE-DIR 
-DFILE=%S/Inputs/resource_dir %s

banach-space wrote:

You should be able to avoid repeating "%S/Inputs/resource_dir" if you use 
`define`/`redefine`:
* example: 
https://github.com/llvm/llvm-project/blob/6d44a1ef55b559e59d725b07ffe1da988b4e5f1c/mlir/test/Integration/Dialect/Linalg/CPU/ArmSVE/matmul.mlir#L1-L14
* docs: https://llvm.org/docs/TestingGuide.html (search for `DEFINE`)

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Andrzej Warzyński via cfe-commits


@@ -250,6 +247,25 @@ void Driver::setDriverMode(StringRef Value) {
 Diag(diag::err_drv_unsupported_option_argument) << OptName << Value;
 }
 
+void Driver::setResourceDirectory() {
+  // Compute the path to the resource directory, depending on the driver mode.
+  switch (Mode) {
+  case GCCMode:
+  case GXXMode:
+  case CPPMode:
+  case CLMode:
+  case DXCMode:
+ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
+break;
+  case FlangMode:
+// TODO: Is there a better way to add the "../include/flang/" component?
+SmallString<64> relPath{};
+llvm::sys::path::append(relPath, "..", "include", "flang");
+ResourceDir = GetResourcesPath(ClangExecutable, relPath);
+break;

banach-space wrote:

Presumably `relPath` stands for "relative path"? Why not `customResoursePath` 
as in 
https://github.com/llvm/llvm-project/blob/6d44a1ef55b559e59d725b07ffe1da988b4e5f1c/clang/lib/Driver/Driver.cpp#L166-L192
?

Or, probably more accurate, `customResourcePathReleativeToDriver` (long names 
are fine with me).

Wouldn't the above also add things that are only relevant for Clang? As in, 
shouldn't `GetResourcesPath` be specialised for Flang?

Btw, where is `ClangExecutable` defined? In ideal world it would be something 
more generic, e.g. `DriverExecutable`. But I appreciate that that's tangential 
to this change :)

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-03 Thread Andrzej Warzyński via cfe-commits

banach-space wrote:

> > What's the definition of "resource dir" for Fortran?
> 
> I'd like to at least have it point to where the MODULE files live.
> 
> When I look at what clang emits, then Flang's resource directory should 
> rather point to the place, where Flang has its `lib` and `include` 
> directories. So, one level above of what I have done in this PR right now.
> 

How does this compare to GFortran and Classic Flang? Anything resembling this 
flag?

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-02 Thread Michael Klemm via cfe-commits

mjklemm wrote:

> What's the definition of "resource dir" for Fortran?

I'd like to at least have it point to where the MODULE files live.

When I look at what clang emits, then Flang's resource directory should rather 
point to the place, where Flang has its `lib` and `include` directories.  So, 
one level above of what I have done in this PR right now.

For reference, Clang outputs this:

```
$ which clang
clang is /usr/bin/clang
$ clang -print-resource-dir
/usr/lib/llvm-14/lib/clang/14.0.0
$ ls /usr/lib/llvm-14/lib/clang/14.0.0
total 36
24 include/   4 lib/   4 share/   4 README.txt
```

At some point, I guess Flang might also have to switch to a scheme that 
includes version numbers to differentiate different resource directories, so 
that multiple different versions of Flang can coexist.  But that's for a later 
PR.

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-02 Thread Andrzej Warzyński via cfe-commits

https://github.com/banach-space commented:

What's the definition of "resource dir" for Fortran?

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-02 Thread Michael Klemm via cfe-commits


@@ -250,6 +247,25 @@ void Driver::setDriverMode(StringRef Value) {
 Diag(diag::err_drv_unsupported_option_argument) << OptName << Value;
 }
 
+void Driver::setResourceDirectory() {
+  // Compute the path to the resource directory, depending on the driver mode.
+  switch (Mode) {
+  case GCCMode:
+  case GXXMode:
+  case CPPMode:
+  case CLMode:
+  case DXCMode:
+ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
+break;
+  case FlangMode:
+// TODO: Is there a better way to add the "../include/flang/" component?
+SmallString<64> relPath{};
+llvm::sys::path::append(relPath, "..", "include", "flang");
+ResourceDir = GetResourcesPath(ClangExecutable, relPath);
+break;

mjklemm wrote:

Reviewers, please let me know if that approach is too simplistic.  I would also 
like to get your feedback on whether this should be pointing to 
`$FLANG_BIN/../include` instead.  Please suggest.

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


[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-02 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Michael Klemm (mjklemm)


Changes

This should be a NFC change for all drivers, but Flang.

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


5 Files Affected:

- (modified) clang/include/clang/Driver/Driver.h (+3) 
- (modified) clang/include/clang/Driver/Options.td (+1-1) 
- (modified) clang/lib/Driver/Driver.cpp (+20-3) 
- (modified) flang/test/Driver/driver-help-hidden.f90 (+1) 
- (added) flang/test/Driver/print-resource-dir.F90 (+3) 


``diff
diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 2ffc52bcb7ad3b..c36595e62e2daf 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -752,6 +752,9 @@ class Driver {
   /// option.
   void setDriverMode(StringRef DriverModeValue);
 
+  /// Set the resource directory, depending on which driver is being used.
+  void setResourceDirectory();
+
   /// Parse the \p Args list for LTO options and record the type of LTO
   /// compilation based on which -f(no-)?lto(=.*)? option occurs last.
   void setLTOMode(const llvm::opt::ArgList );
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 864da4e1157f7d..a3b81fa338bdcd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5474,7 +5474,7 @@ def print_prog_name_EQ : Joined<["-", "--"], 
"print-prog-name=">,
   Visibility<[ClangOption, CLOption]>;
 def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
   HelpText<"Print the resource directory pathname">,
-  Visibility<[ClangOption, CLOption]>;
+  Visibility<[ClangOption, CLOption, FlangOption]>;
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 114320f5d31468..d75d2e88fc1024 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -229,9 +229,6 @@ Driver::Driver(StringRef ClangExecutable, StringRef 
TargetTriple,
 UserConfigDir = static_cast(P);
   }
 #endif
-
-  // Compute the path to the resource directory.
-  ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
 }
 
 void Driver::setDriverMode(StringRef Value) {
@@ -250,6 +247,25 @@ void Driver::setDriverMode(StringRef Value) {
 Diag(diag::err_drv_unsupported_option_argument) << OptName << Value;
 }
 
+void Driver::setResourceDirectory() {
+  // Compute the path to the resource directory, depending on the driver mode.
+  switch (Mode) {
+  case GCCMode:
+  case GXXMode:
+  case CPPMode:
+  case CLMode:
+  case DXCMode:
+ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
+break;
+  case FlangMode:
+// TODO: Is there a better way to add the "../include/flang/" component?
+SmallString<64> relPath{};
+llvm::sys::path::append(relPath, "..", "include", "flang");
+ResourceDir = GetResourcesPath(ClangExecutable, relPath);
+break;
+  }
+}
+
 InputArgList Driver::ParseArgStrings(ArrayRef ArgStrings,
  bool UseDriverMode, bool ) {
   llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
@@ -1202,6 +1218,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   if (!DriverMode.empty())
 setDriverMode(DriverMode);
 
+  setResourceDirectory();
   // FIXME: What are we going to do with -V and -b?
 
   // Arguments specified in command line.
diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 706b2cb6c2452c..73b34bd321c5f6 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -143,6 +143,7 @@
 ! CHECK-NEXT: -oWrite output to 
 ! CHECK-NEXT: -pedantic   Warn on language extensions
 ! CHECK-NEXT: -print-effective-triple Print the effective target triple
+! CHECK-NEXT: -print-resource-dir Print the resource directory pathname
 ! CHECK-NEXT: -print-target-triplePrint the normalized target triple
 ! CHECK-NEXT: -pthreadSupport POSIX threads in generated code
 ! CHECK-NEXT: -P  Disable linemarker output in -E mode
diff --git a/flang/test/Driver/print-resource-dir.F90 
b/flang/test/Driver/print-resource-dir.F90
new file mode 100644
index 00..5c934312e1f68a
--- /dev/null
+++ b/flang/test/Driver/print-resource-dir.F90
@@ -0,0 +1,3 @@
+! RUN: %flang -print-resource-dir -resource-dir=%S/Inputs/resource_dir \
+! RUN:  | FileCheck -check-prefix=PRINT-RESOURCE-DIR 
-DFILE=%S/Inputs/resource_dir %s
+! PRINT-RESOURCE-DIR: [[FILE]]

``




https://github.com/llvm/llvm-project/pull/90886
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang] [flang] [Flang][Driver] Add -print-resource-dir command line flag to emit Flang's resource directory (PR #90886)

2024-05-02 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm created 
https://github.com/llvm/llvm-project/pull/90886

This should be a NFC change for all drivers, but Flang.

>From 1a994159025f127f0f7d11da80b74035788d52c9 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 14:50:45 +0200
Subject: [PATCH 1/3] Enable -print-resource-dir also for Flang

---
 clang/include/clang/Driver/Options.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 864da4e1157f7d..a3b81fa338bdcd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5474,7 +5474,7 @@ def print_prog_name_EQ : Joined<["-", "--"], 
"print-prog-name=">,
   Visibility<[ClangOption, CLOption]>;
 def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
   HelpText<"Print the resource directory pathname">,
-  Visibility<[ClangOption, CLOption]>;
+  Visibility<[ClangOption, CLOption, FlangOption]>;
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;

>From beee04f6f2d411694f5ae1ee6130a81a632164df Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 16:19:38 +0200
Subject: [PATCH 2/3] Add setResourceDir function to set resource directory for
 Flang

This should be an NFC change for anythign, but Flang.
---
 clang/include/clang/Driver/Driver.h |  3 +++
 clang/lib/Driver/Driver.cpp | 23 ---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 2ffc52bcb7ad3b..c36595e62e2daf 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -752,6 +752,9 @@ class Driver {
   /// option.
   void setDriverMode(StringRef DriverModeValue);
 
+  /// Set the resource directory, depending on which driver is being used.
+  void setResourceDirectory();
+
   /// Parse the \p Args list for LTO options and record the type of LTO
   /// compilation based on which -f(no-)?lto(=.*)? option occurs last.
   void setLTOMode(const llvm::opt::ArgList );
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 114320f5d31468..d75d2e88fc1024 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -229,9 +229,6 @@ Driver::Driver(StringRef ClangExecutable, StringRef 
TargetTriple,
 UserConfigDir = static_cast(P);
   }
 #endif
-
-  // Compute the path to the resource directory.
-  ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
 }
 
 void Driver::setDriverMode(StringRef Value) {
@@ -250,6 +247,25 @@ void Driver::setDriverMode(StringRef Value) {
 Diag(diag::err_drv_unsupported_option_argument) << OptName << Value;
 }
 
+void Driver::setResourceDirectory() {
+  // Compute the path to the resource directory, depending on the driver mode.
+  switch (Mode) {
+  case GCCMode:
+  case GXXMode:
+  case CPPMode:
+  case CLMode:
+  case DXCMode:
+ResourceDir = GetResourcesPath(ClangExecutable, CLANG_RESOURCE_DIR);
+break;
+  case FlangMode:
+// TODO: Is there a better way to add the "../include/flang/" component?
+SmallString<64> relPath{};
+llvm::sys::path::append(relPath, "..", "include", "flang");
+ResourceDir = GetResourcesPath(ClangExecutable, relPath);
+break;
+  }
+}
+
 InputArgList Driver::ParseArgStrings(ArrayRef ArgStrings,
  bool UseDriverMode, bool ) {
   llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
@@ -1202,6 +1218,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   if (!DriverMode.empty())
 setDriverMode(DriverMode);
 
+  setResourceDirectory();
   // FIXME: What are we going to do with -V and -b?
 
   // Arguments specified in command line.

>From 5ca34138043ab621582085e7034349c7e726a970 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Thu, 2 May 2024 20:31:04 +0200
Subject: [PATCH 3/3] Update/add tests fir -print-resource-dir

---
 flang/test/Driver/driver-help-hidden.f90 | 1 +
 flang/test/Driver/print-resource-dir.F90 | 3 +++
 2 files changed, 4 insertions(+)
 create mode 100644 flang/test/Driver/print-resource-dir.F90

diff --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 706b2cb6c2452c..73b34bd321c5f6 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -143,6 +143,7 @@
 ! CHECK-NEXT: -oWrite output to 
 ! CHECK-NEXT: -pedantic   Warn on language extensions
 ! CHECK-NEXT: -print-effective-triple Print the effective target triple
+! CHECK-NEXT: -print-resource-dir Print the resource directory pathname
 ! CHECK-NEXT: -print-target-triplePrint the normalized target triple
 ! CHECK-NEXT: -pthreadSupport POSIX threads in