Skip to content

[Flang][Driver] Enable the -B option #109965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 1, 2024

Conversation

kiranchandramohan
Copy link
Contributor

The option provides the search prefix for executables, libraries and data files.

The option is implemented in the common portion of the Driver and only needs to be enabled in Flang. Test added is a copy of the relevant test in Clang.

@llvmbot llvmbot added clang Clang issues not falling into any other category flang:driver flang Flang issues not falling into any other category labels Sep 25, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 25, 2024

@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-flang-driver

@llvm/pr-subscribers-clang

Author: Kiran Chandramohan (kiranchandramohan)

Changes

The option provides the search prefix for executables, libraries and data files.

The option is implemented in the common portion of the Driver and only needs to be enabled in Flang. Test added is a copy of the relevant test in Clang.


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

6 Files Affected:

  • (modified) clang/include/clang/Driver/Options.td (+1)
  • (added) flang/test/Driver/B-opt.c (+12)
  • (added) flang/test/Driver/Inputs/B_opt_tree/dir1/i386-unknown-linux-ld ()
  • (added) flang/test/Driver/Inputs/B_opt_tree/dir1/ld ()
  • (added) flang/test/Driver/Inputs/B_opt_tree/dir2/ld ()
  • (added) flang/test/Driver/Inputs/B_opt_tree/dir3/prefix-ld ()
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 002f60350543d9..020f4f92e8735a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -816,6 +816,7 @@ def _DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>,
 def A : JoinedOrSeparate<["-"], "A">, Flags<[RenderJoined]>,
   Group<gfortran_Group>;
 def B : JoinedOrSeparate<["-"], "B">, MetaVarName<"<prefix>">,
+    Visibility<[ClangOption, FlangOption]>,
     HelpText<"Search $prefix$file for executables, libraries, and data files. "
     "If $prefix is a directory, search $prefix/$file">;
 def gcc_install_dir_EQ : Joined<["--"], "gcc-install-dir=">,
diff --git a/flang/test/Driver/B-opt.c b/flang/test/Driver/B-opt.c
new file mode 100644
index 00000000000000..16f3b87aee65e6
--- /dev/null
+++ b/flang/test/Driver/B-opt.c
@@ -0,0 +1,12 @@
+// Check -B driver option.
+
+/// Target triple prefix is not detected for -B.
+// RUN: %flang %s -### -o %t.o -target i386-unknown-linux \
+// RUN:     -B %S/Inputs/B_opt_tree/dir1 -fuse-ld=ld 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-B-OPT-TRIPLE %s
+// CHECK-B-OPT-TRIPLE-NOT: "{{.*}}/Inputs/B_opt_tree/dir1{{/|\\\\}}i386-unknown-linux-ld"
+//
+// RUN: %flang %s -### -o %t.o -target i386-unknown-linux \
+// RUN:     -B %S/Inputs/B_opt_tree/dir2 -fuse-ld=ld 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-B-OPT-DIR %s
+// CHECK-B-OPT-DIR: "{{.*}}/Inputs/B_opt_tree/dir2{{/|\\\\}}ld" 
diff --git a/flang/test/Driver/Inputs/B_opt_tree/dir1/i386-unknown-linux-ld b/flang/test/Driver/Inputs/B_opt_tree/dir1/i386-unknown-linux-ld
new file mode 100755
index 00000000000000..e69de29bb2d1d6
diff --git a/flang/test/Driver/Inputs/B_opt_tree/dir1/ld b/flang/test/Driver/Inputs/B_opt_tree/dir1/ld
new file mode 100755
index 00000000000000..e69de29bb2d1d6
diff --git a/flang/test/Driver/Inputs/B_opt_tree/dir2/ld b/flang/test/Driver/Inputs/B_opt_tree/dir2/ld
new file mode 100755
index 00000000000000..e69de29bb2d1d6
diff --git a/flang/test/Driver/Inputs/B_opt_tree/dir3/prefix-ld b/flang/test/Driver/Inputs/B_opt_tree/dir3/prefix-ld
new file mode 100755
index 00000000000000..e69de29bb2d1d6

Copy link

github-actions bot commented Sep 25, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

The option provides the search prefix for executables, libraries
and data files.

The option is implemented in the common portion of the Driver and
only needs to be enabled in Flang. Test added is a copy of the
relevant test in Clang.
Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

! RUN: -B %S/Inputs/B_opt_tree/dir3/prefix- \
! RUN: -B %S/Inputs/B_opt_tree/dir2 2>&1 -fuse-ld=ld \
! RUN: | FileCheck --check-prefix=CHECK-B-OPT-MULT %s
! CHECK-B-OPT-MULT: "{{.*}}/Inputs/B_opt_tree/dir3{{/|\\\\}}prefix-ld"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a bit surprising that we take the first version of -B. Most things use the last argument.

But if this is just copied from clang, it is better to mimic clang's behavior, and I don't think this would be safe to fix in clang because it could break existing build scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good spot.

This seems to be the behaviour for similar options like -I. There is probably a difference between overriding options (last one wins) and appending options (the latter paths are in the search patch but will be used only after searching the first ones).

! Check -B driver option.
!
! Target triple prefix is not detected for -B.
! RUN: %flang %s -### -o %t.o -target i386-unknown-linux \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use --target=

-target has been deprecated since around clang 3.4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Done. Modified tests for both drivers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaskRay Is it OK to land this?

@llvmbot llvmbot added the clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' label Sep 26, 2024
Copy link
Contributor

@banach-space banach-space left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Looks like you've addressed all comments, so feel free to land it.

@kiranchandramohan kiranchandramohan merged commit 28be39f into llvm:main Oct 1, 2024
9 checks passed
Sterling-Augustine pushed a commit to Sterling-Augustine/llvm-project that referenced this pull request Oct 3, 2024
The option provides the search prefix for executables, libraries and
data files.

The option is implemented in the common portion of the Driver and only
needs to be enabled in Flang. Test added is a copy of the relevant test
in Clang.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category flang:driver flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants