Skip to content

Commit f13e462

Browse files
committed
[clang] Don't force diagnosing when checking if -fcf-protection=branch is supported
This turns the target hook that checks if `-fcf-protection=branch` is supported into a pure check function that is suitable to be used in more places.
1 parent 2eda754 commit f13e462

File tree

5 files changed

+13
-22
lines changed

5 files changed

+13
-22
lines changed

clang/include/clang/Basic/TargetInfo.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,8 +1725,7 @@ class TargetInfo : public TransferrableTargetInfo,
17251725
}
17261726

17271727
/// Check if the target supports CFProtection branch.
1728-
virtual bool
1729-
checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const;
1728+
virtual bool checkCFProtectionBranchSupported() const;
17301729

17311730
/// Get the target default CFBranchLabelScheme scheme
17321731
virtual CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const;

clang/lib/Basic/TargetInfo.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,7 @@ void TargetInfo::resetDataLayout(StringRef DL, const char *ULP) {
192192
UserLabelPrefix = ULP;
193193
}
194194

195-
bool
196-
TargetInfo::checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const {
197-
Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch";
198-
return false;
199-
}
195+
bool TargetInfo::checkCFProtectionBranchSupported() const { return false; }
200196

201197
CFBranchLabelSchemeKind TargetInfo::getDefaultCFBranchLabelScheme() const {
202198
// if this hook is called, the target should override it

clang/lib/Basic/Targets/RISCV.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,8 @@ class RISCVTargetInfo : public TargetInfo {
135135
bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,
136136
bool &HasSizeMismatch) const override;
137137

138-
bool
139-
checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override {
140-
if (ISAInfo->hasExtension("zicfilp"))
141-
return true;
142-
return TargetInfo::checkCFProtectionBranchSupported(Diags);
138+
bool checkCFProtectionBranchSupported() const override {
139+
return ISAInfo->hasExtension("zicfilp");
143140
}
144141

145142
CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override {

clang/lib/Basic/Targets/X86.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,8 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
266266
return TargetInfo::checkCFProtectionReturnSupported(Diags);
267267
};
268268

269-
bool
270-
checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override {
271-
if (CPU == llvm::X86::CK_None || CPU >= llvm::X86::CK_PentiumPro)
272-
return true;
273-
return TargetInfo::checkCFProtectionBranchSupported(Diags);
269+
bool checkCFProtectionBranchSupported() const override {
270+
return CPU == llvm::X86::CK_None || CPU >= llvm::X86::CK_PentiumPro;
274271
};
275272

276273
virtual bool validateOperandSize(const llvm::StringMap<bool> &FeatureMap,

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,11 +1159,13 @@ void CodeGenModule::Release() {
11591159
1);
11601160
}
11611161

1162-
if (CodeGenOpts.CFProtectionBranch &&
1163-
Target.checkCFProtectionBranchSupported(getDiags())) {
1164-
// Indicate that we want to instrument branch control flow protection.
1165-
getModule().addModuleFlag(llvm::Module::Min, "cf-protection-branch",
1166-
1);
1162+
if (CodeGenOpts.CFProtectionBranch) {
1163+
if (Target.checkCFProtectionBranchSupported())
1164+
// Indicate that we want to instrument branch control flow protection.
1165+
getModule().addModuleFlag(llvm::Module::Min, "cf-protection-branch", 1);
1166+
else
1167+
getDiags().Report(diag::err_opt_not_valid_on_target)
1168+
<< "cf-protection=branch";
11671169
}
11681170

11691171
if (CodeGenOpts.FunctionReturnThunks)

0 commit comments

Comments
 (0)