[clang] cd18efb - [Driver] Make -G TargetSpecific
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 8 09:02:18 PDT 2023
Author: Fangrui Song
Date: 2023-06-08T09:02:12-07:00
New Revision: cd18efb61d759405956dbd30e4b5f2720d8e1783
URL: https://github.com/llvm/llvm-project/commit/cd18efb61d759405956dbd30e4b5f2720d8e1783
DIFF: https://github.com/llvm/llvm-project/commit/cd18efb61d759405956dbd30e4b5f2720d8e1783.diff
LOG: [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.
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/AIX.cpp
clang/test/Driver/aix-err-options.c
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 7934afa52af84..30e75fd02d52c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -723,7 +723,7 @@ def E : Flag<["-"], "E">, Flags<[NoXarchOption,CC1Option, FlangOption, FC1Option
HelpText<"Only run the preprocessor">;
def F : JoinedOrSeparate<["-"], "F">, Flags<[RenderJoined,CC1Option]>,
HelpText<"Add directory to framework include search path">;
-def G : JoinedOrSeparate<["-"], "G">, Flags<[NoXarchOption]>, Group<m_Group>,
+def G : JoinedOrSeparate<["-"], "G">, Flags<[NoXarchOption,TargetSpecific]>, Group<m_Group>,
MetaVarName<"<size>">, HelpText<"Put objects of at most <size> bytes "
"into small data section (MIPS / Hexagon)">;
def G_EQ : Joined<["-"], "G=">, Flags<[NoXarchOption]>, Group<m_Group>, Alias<G>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index fee14ba6faabe..243aebb3bc23f 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4739,13 +4739,8 @@ void Driver::BuildJobs(Compilation &C) const {
}
const llvm::Triple &RawTriple = C.getDefaultToolChain().getTriple();
- if (RawTriple.isOSAIX()) {
- if (Arg *A = C.getArgs().getLastArg(options::OPT_G))
- Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << RawTriple.str();
- if (LTOMode == LTOK_Thin)
- Diag(diag::err_drv_clang_unsupported) << "thinLTO on AIX";
- }
+ if (RawTriple.isOSAIX() && LTOMode == LTOK_Thin)
+ Diag(diag::err_drv_clang_unsupported) << "thinLTO on AIX";
// Collect the list of architectures.
llvm::StringSet<> ArchNames;
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index ad7f3edeb9384..a0b036eea64ba 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -112,6 +112,11 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (!(IsArch32Bit || IsArch64Bit))
llvm_unreachable("Unsupported bit width value.");
+ if (Arg *A = C.getArgs().getLastArg(options::OPT_G)) {
+ D.Diag(diag::err_drv_unsupported_opt_for_target)
+ << A->getSpelling() << D.getTargetTriple();
+ }
+
// Force static linking when "-static" is present.
if (Args.hasArg(options::OPT_static))
CmdArgs.push_back("-bnso");
diff --git a/clang/test/Driver/aix-err-options.c b/clang/test/Driver/aix-err-options.c
index 935ae78dab080..45d36136e1297 100644
--- a/clang/test/Driver/aix-err-options.c
+++ b/clang/test/Driver/aix-err-options.c
@@ -4,12 +4,9 @@
// RUN: FileCheck --check-prefix=CHECK32 %s
// RUN: %clang --target=powerpc-ibm-aix-xcoff -### -c -G 0 2>&1 %s | \
// RUN: FileCheck --check-prefix=CHECK32 %s
-// RUN: %clang --target=powerpc-ibm-aix-xcoff -### -c \
-// RUN: %S/Inputs/aix_ppc_tree/dummy0.s -G 0 2>&1 | \
-// RUN: FileCheck --check-prefix=CHECK32 %s
-// RUN: %clang --target=powerpc-ibm-aix-xcoff -### -o dummy.so \
-// RUN: %S/Inputs/aix_ppc_tree/dummy0.o -G 0 2>&1 | \
-// RUN: FileCheck --check-prefix=CHECK32 %s
+// RUN: touch %t.s %t.o
+// RUN: %clang --target=powerpc-ibm-aix-xcoff -### -c %t.s -G 0 2>&1 | FileCheck --check-prefix=CHECK32 %s
+// RUN: %clang --target=powerpc-ibm-aix-xcoff -### -o dummy.so %t.o -G 0 2>&1 | FileCheck --check-prefix=CHECK32 %s
// RUN: %clang --target=powerpc64-ibm-aix-xcoff -### -E -G 0 2>&1 %s | \
// RUN: FileCheck --check-prefix=CHECK64 %s
@@ -17,12 +14,8 @@
// RUN: FileCheck --check-prefix=CHECK64 %s
// RUN: %clang --target=powerpc64-ibm-aix-xcoff -### -c -G 0 2>&1 %s | \
// RUN: FileCheck --check-prefix=CHECK64 %s
-// RUN: %clang --target=powerpc64-ibm-aix-xcoff -### -c \
-// RUN: %S/Inputs/aix_ppc_tree/dummy0.s -G 0 2>&1 | \
-// RUN: FileCheck --check-prefix=CHECK64 %s
-// RUN: %clang --target=powerpc64-ibm-aix-xcoff -### -o dummy.so \
-// RUN: %S/Inputs/aix_ppc_tree/dummy0.o -G 0 2>&1 | \
-// RUN: FileCheck --check-prefix=CHECK64 %s
+// RUN: %clang --target=powerpc64-ibm-aix-xcoff -### -c %t.s -G 0 2>&1 | FileCheck --check-prefix=CHECK64 %s
+// RUN: %clang --target=powerpc64-ibm-aix-xcoff -### -o dummy.so %t.o -G 0 2>&1 | FileCheck --check-prefix=CHECK64 %s
// CHECK32: error: unsupported option '-G' for target 'powerpc-ibm-aix-xcoff'
// CHECK64: error: unsupported option '-G' for target 'powerpc64-ibm-aix-xcoff'
More information about the cfe-commits
mailing list