Skip to content

Commit 3cae49e

Browse files
committed
[clang][RISCV] Accept -fcf-protection=branch when Zicfilp extension is on
-fcf-protection=branch turns on indirect branching protection on RISC-V targets with Zicfilp extension.
1 parent 81c3499 commit 3cae49e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

clang/lib/Basic/Targets/RISCV.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ class RISCVTargetInfo : public TargetInfo {
131131
bool supportsCpuInit() const override { return getTriple().isOSLinux(); }
132132
bool validateCpuSupports(StringRef Feature) const override;
133133
bool isValidFeatureName(StringRef Name) const override;
134+
135+
bool
136+
checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override {
137+
if (ISAInfo->hasExtension("zicfilp"))
138+
return true;
139+
return TargetInfo::checkCFProtectionBranchSupported(Diags);
140+
}
134141
};
135142
class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
136143
public:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: not %clang --target=riscv32 -fcf-protection=branch -c %s \
2+
// RUN: -o /dev/null 2>&1 \
3+
// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s
4+
5+
// RUN: not %clang --target=riscv32 -fcf-protection=branch -c %s \
6+
// RUN: -o /dev/null 2>&1 \
7+
// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s
8+
9+
// RUN: not %clang --target=riscv64 -fcf-protection=branch -c %s \
10+
// RUN: -o /dev/null 2>&1 \
11+
// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s
12+
13+
// RUN: not %clang --target=riscv64 -fcf-protection=branch -c %s \
14+
// RUN: -o /dev/null 2>&1 \
15+
// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s
16+
17+
// CHECK-BRANCH-PROT-INVALID: error: option 'cf-protection=branch' cannot be
18+
// CHECK-BRANCH-PROT-INVALID-SAME: specified on this target

0 commit comments

Comments
 (0)