Skip to content

Commit cd18efb

Browse files
committed
[Driver] Make -G TargetSpecific
so that we report `unsupported option '-G' for target ...` on unsupported targets (most targets). This error is tested by one target in aix-err-options.c. Follow-up to D89897 and D90063.
1 parent 361bc85 commit cd18efb

File tree

4 files changed

+13
-20
lines changed

4 files changed

+13
-20
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ def E : Flag<["-"], "E">, Flags<[NoXarchOption,CC1Option, FlangOption, FC1Option
723723
HelpText<"Only run the preprocessor">;
724724
def F : JoinedOrSeparate<["-"], "F">, Flags<[RenderJoined,CC1Option]>,
725725
HelpText<"Add directory to framework include search path">;
726-
def G : JoinedOrSeparate<["-"], "G">, Flags<[NoXarchOption]>, Group<m_Group>,
726+
def G : JoinedOrSeparate<["-"], "G">, Flags<[NoXarchOption,TargetSpecific]>, Group<m_Group>,
727727
MetaVarName<"<size>">, HelpText<"Put objects of at most <size> bytes "
728728
"into small data section (MIPS / Hexagon)">;
729729
def G_EQ : Joined<["-"], "G=">, Flags<[NoXarchOption]>, Group<m_Group>, Alias<G>;

clang/lib/Driver/Driver.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4739,13 +4739,8 @@ void Driver::BuildJobs(Compilation &C) const {
47394739
}
47404740

47414741
const llvm::Triple &RawTriple = C.getDefaultToolChain().getTriple();
4742-
if (RawTriple.isOSAIX()) {
4743-
if (Arg *A = C.getArgs().getLastArg(options::OPT_G))
4744-
Diag(diag::err_drv_unsupported_opt_for_target)
4745-
<< A->getSpelling() << RawTriple.str();
4746-
if (LTOMode == LTOK_Thin)
4747-
Diag(diag::err_drv_clang_unsupported) << "thinLTO on AIX";
4748-
}
4742+
if (RawTriple.isOSAIX() && LTOMode == LTOK_Thin)
4743+
Diag(diag::err_drv_clang_unsupported) << "thinLTO on AIX";
47494744

47504745
// Collect the list of architectures.
47514746
llvm::StringSet<> ArchNames;

clang/lib/Driver/ToolChains/AIX.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
112112
if (!(IsArch32Bit || IsArch64Bit))
113113
llvm_unreachable("Unsupported bit width value.");
114114

115+
if (Arg *A = C.getArgs().getLastArg(options::OPT_G)) {
116+
D.Diag(diag::err_drv_unsupported_opt_for_target)
117+
<< A->getSpelling() << D.getTargetTriple();
118+
}
119+
115120
// Force static linking when "-static" is present.
116121
if (Args.hasArg(options::OPT_static))
117122
CmdArgs.push_back("-bnso");

clang/test/Driver/aix-err-options.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,18 @@
44
// RUN: FileCheck --check-prefix=CHECK32 %s
55
// RUN: %clang --target=powerpc-ibm-aix-xcoff -### -c -G 0 2>&1 %s | \
66
// RUN: FileCheck --check-prefix=CHECK32 %s
7-
// RUN: %clang --target=powerpc-ibm-aix-xcoff -### -c \
8-
// RUN: %S/Inputs/aix_ppc_tree/dummy0.s -G 0 2>&1 | \
9-
// RUN: FileCheck --check-prefix=CHECK32 %s
10-
// RUN: %clang --target=powerpc-ibm-aix-xcoff -### -o dummy.so \
11-
// RUN: %S/Inputs/aix_ppc_tree/dummy0.o -G 0 2>&1 | \
12-
// RUN: FileCheck --check-prefix=CHECK32 %s
7+
// RUN: touch %t.s %t.o
8+
// RUN: %clang --target=powerpc-ibm-aix-xcoff -### -c %t.s -G 0 2>&1 | FileCheck --check-prefix=CHECK32 %s
9+
// RUN: %clang --target=powerpc-ibm-aix-xcoff -### -o dummy.so %t.o -G 0 2>&1 | FileCheck --check-prefix=CHECK32 %s
1310

1411
// RUN: %clang --target=powerpc64-ibm-aix-xcoff -### -E -G 0 2>&1 %s | \
1512
// RUN: FileCheck --check-prefix=CHECK64 %s
1613
// RUN: %clang --target=powerpc64-ibm-aix-xcoff -### -S -emit-llvm -G 0 2>&1 %s | \
1714
// RUN: FileCheck --check-prefix=CHECK64 %s
1815
// RUN: %clang --target=powerpc64-ibm-aix-xcoff -### -c -G 0 2>&1 %s | \
1916
// RUN: FileCheck --check-prefix=CHECK64 %s
20-
// RUN: %clang --target=powerpc64-ibm-aix-xcoff -### -c \
21-
// RUN: %S/Inputs/aix_ppc_tree/dummy0.s -G 0 2>&1 | \
22-
// RUN: FileCheck --check-prefix=CHECK64 %s
23-
// RUN: %clang --target=powerpc64-ibm-aix-xcoff -### -o dummy.so \
24-
// RUN: %S/Inputs/aix_ppc_tree/dummy0.o -G 0 2>&1 | \
25-
// RUN: FileCheck --check-prefix=CHECK64 %s
17+
// RUN: %clang --target=powerpc64-ibm-aix-xcoff -### -c %t.s -G 0 2>&1 | FileCheck --check-prefix=CHECK64 %s
18+
// RUN: %clang --target=powerpc64-ibm-aix-xcoff -### -o dummy.so %t.o -G 0 2>&1 | FileCheck --check-prefix=CHECK64 %s
2619

2720
// CHECK32: error: unsupported option '-G' for target 'powerpc-ibm-aix-xcoff'
2821
// CHECK64: error: unsupported option '-G' for target 'powerpc64-ibm-aix-xcoff'

0 commit comments

Comments
 (0)