Skip to content

Commit b822b69

Browse files
authored
[Driver] Add -mbranch-protection to ARM and AArch64 multilib flags (llvm#106391)
This adds the `-mbranch-protection` command line option to the set of flags used by the multilib selection for ARM and AArch64 targets.
1 parent 2eeeff8 commit b822b69

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clang/lib/Driver/ToolChain.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ static void getAArch64MultilibFlags(const Driver &D,
221221
assert(!ArchName.empty() && "at least one architecture should be found");
222222
MArch.insert(MArch.begin(), ("-march=" + ArchName).str());
223223
Result.push_back(llvm::join(MArch, "+"));
224+
225+
const Arg *BranchProtectionArg =
226+
Args.getLastArgNoClaim(options::OPT_mbranch_protection_EQ);
227+
if (BranchProtectionArg) {
228+
Result.push_back(BranchProtectionArg->getAsString(Args));
229+
}
224230
}
225231

226232
static void getARMMultilibFlags(const Driver &D,
@@ -268,6 +274,12 @@ static void getARMMultilibFlags(const Driver &D,
268274
case arm::FloatABI::Invalid:
269275
llvm_unreachable("Invalid float ABI");
270276
}
277+
278+
const Arg *BranchProtectionArg =
279+
Args.getLastArgNoClaim(options::OPT_mbranch_protection_EQ);
280+
if (BranchProtectionArg) {
281+
Result.push_back(BranchProtectionArg->getAsString(Args));
282+
}
271283
}
272284

273285
static void getRISCVMultilibFlags(const Driver &D, const llvm::Triple &Triple,

clang/test/Driver/print-multi-selection-flags.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
// CHECK-SVE2: --target=aarch64-unknown-none-elf
6060
// CHECK-SVE2: -march=armv{{.*}}-a{{.*}}+simd{{.*}}+sve{{.*}}+sve2{{.*}}
6161

62+
// RUN: %clang -print-multi-flags-experimental --target=arm-none-eabi -mbranch-protection=standard | FileCheck --check-prefix=CHECK-BRANCH-PROTECTION %s
63+
// RUN: %clang -print-multi-flags-experimental --target=aarch64-none-elf -mbranch-protection=standard | FileCheck --check-prefix=CHECK-BRANCH-PROTECTION %s
64+
// CHECK-BRANCH-PROTECTION: -mbranch-protection=standard
65+
6266
// RUN: %clang -print-multi-flags-experimental --target=riscv32-none-elf -march=rv32g | FileCheck --check-prefix=CHECK-RV32 %s
6367
// CHECK-RV32: --target=riscv32-unknown-none-elf
6468
// CHECK-RV32: -mabi=ilp32d

0 commit comments

Comments
 (0)