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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -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=">,
Expand Down
10 changes: 5 additions & 5 deletions clang/test/Driver/B-opt.c
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
// Check -B driver option.

/// Target triple prefix is not detected for -B.
// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
// RUN: %clang %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: %clang %s -### -o %t.o -target i386-unknown-linux \
// RUN: %clang %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"
//
// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
// RUN: %clang %s -### -o %t.o --target=i386-unknown-linux \
// RUN: -B %S/Inputs/B_opt_tree/dir3/prefix- -fuse-ld=ld 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-B-OPT-PREFIX %s
// CHECK-B-OPT-PREFIX: "{{.*}}/Inputs/B_opt_tree/dir3{{/|\\\\}}prefix-ld"
//
// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
// RUN: %clang %s -### -o %t.o --target=i386-unknown-linux \
// 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"
//
// RUN: %clang -B %S/Inputs/does_not_exist -print-search-dirs \
// RUN: -target aarch64-linux-gnu \
// RUN: --target=aarch64-linux-gnu \
// RUN: | FileCheck --check-prefix=CHECK-B-OPT-INVALID %s
// CHECK-B-OPT-INVALID-NOT: /..//bin
23 changes: 23 additions & 0 deletions flang/test/Driver/B-opt.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
! 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"
!
! RUN: %flang %s -### -o %t.o --target=i386-unknown-linux \
! RUN: -B %S/Inputs/B_opt_tree/dir3/prefix- -fuse-ld=ld 2>&1 \
! RUN: | FileCheck --check-prefix=CHECK-B-OPT-PREFIX %s
! CHECK-B-OPT-PREFIX: "{{.*}}/Inputs/B_opt_tree/dir3{{/|\\\\}}prefix-ld"
!
! RUN: %flang %s -### -o %t.o --target=i386-unknown-linux \
! 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).

Empty file.
Empty file.
Empty file.
Empty file.
Loading