Skip to content

Commit 10037b9

Browse files
committedSep 8, 2016
[Driver] Report invalid -mtune/-mcpu parameters when -arch=arm64
Differential Revision: https://reviews.llvm.org/D23643 llvm-svn: 280998
1 parent b6a11ac commit 10037b9

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed
 

Diff for: ‎clang/lib/Driver/Tools.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -1140,9 +1140,9 @@ void Clang::AddARMTargetArgs(const llvm::Triple &Triple, const ArgList &Args,
11401140
// ARM tools end.
11411141

11421142
/// getAArch64TargetCPU - Get the (LLVM) name of the AArch64 cpu we are
1143-
/// targeting.
1144-
static std::string getAArch64TargetCPU(const ArgList &Args) {
1145-
Arg *A;
1143+
/// targeting. Set \p A to the Arg corresponding to the -mcpu or -mtune
1144+
/// arguments if they are provided, or to nullptr otherwise.
1145+
static std::string getAArch64TargetCPU(const ArgList &Args, Arg *&A) {
11461146
std::string CPU;
11471147
// If we have -mtune or -mcpu, use that.
11481148
if ((A = Args.getLastArg(options::OPT_mtune_EQ))) {
@@ -1919,13 +1919,15 @@ static StringRef getWebAssemblyTargetCPU(const ArgList &Args) {
19191919

19201920
static std::string getCPUName(const ArgList &Args, const llvm::Triple &T,
19211921
bool FromAs = false) {
1922+
Arg *A;
1923+
19221924
switch (T.getArch()) {
19231925
default:
19241926
return "";
19251927

19261928
case llvm::Triple::aarch64:
19271929
case llvm::Triple::aarch64_be:
1928-
return getAArch64TargetCPU(Args);
1930+
return getAArch64TargetCPU(Args, A);
19291931

19301932
case llvm::Triple::arm:
19311933
case llvm::Triple::armeb:
@@ -2443,18 +2445,18 @@ static void getAArch64TargetFeatures(const Driver &D, const ArgList &Args,
24432445
else if ((A = Args.getLastArg(options::OPT_mcpu_EQ)))
24442446
success = getAArch64ArchFeaturesFromMcpu(D, A->getValue(), Args, Features);
24452447
else if (Args.hasArg(options::OPT_arch))
2446-
success = getAArch64ArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args), Args,
2447-
Features);
2448+
success = getAArch64ArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args, A),
2449+
Args, Features);
24482450

24492451
if (success && (A = Args.getLastArg(options::OPT_mtune_EQ)))
24502452
success =
24512453
getAArch64MicroArchFeaturesFromMtune(D, A->getValue(), Args, Features);
24522454
else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ)))
24532455
success =
24542456
getAArch64MicroArchFeaturesFromMcpu(D, A->getValue(), Args, Features);
2455-
else if (Args.hasArg(options::OPT_arch))
2456-
success = getAArch64MicroArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args),
2457-
Args, Features);
2457+
else if (success && Args.hasArg(options::OPT_arch))
2458+
success = getAArch64MicroArchFeaturesFromMcpu(
2459+
D, getAArch64TargetCPU(Args, A), Args, Features);
24582460

24592461
if (!success)
24602462
D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);

Diff for: ‎clang/test/Driver/arm-cortex-cpus.c

+3
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@
303303

304304
// ================== Check that a bogus CPU gives an error
305305
// RUN: %clang -target arm -mcpu=bogus -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-BOGUS-CPU %s
306+
// RUN: %clang -target armv8-apple-darwin -arch arm64 -mcpu=bogus -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-BOGUS-CPU %s
306307
// CHECK-BOGUS-CPU: error: {{.*}} does not support '-mcpu=bogus'
308+
// RUN: %clang -target armv8-apple-darwin -arch arm64 -mtune=bogus -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-BOGUS-TUNE %s
309+
// CHECK-BOGUS-TUNE: error: {{.*}} does not support '-mtune=bogus'
307310

308311
// ================== Check default Architecture on each ARM11 CPU
309312
// RUN: %clang -target arm-linux-gnueabi -mcpu=arm1136j-s -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CPUV6 %s

0 commit comments

Comments
 (0)
Please sign in to comment.