-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Kiran Chandramohan (kiranchandramohan) ChangesThe 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:
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
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
a0cd82b
to
322ff81
Compare
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.
322ff81
to
3af5907
Compare
There was a problem hiding this 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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
flang/test/Driver/B-opt.f90
Outdated
! Check -B driver option. | ||
! | ||
! Target triple prefix is not detected for -B. | ||
! RUN: %flang %s -### -o %t.o -target i386-unknown-linux \ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this 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.
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.
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.