File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo {
141
141
return true ;
142
142
}
143
143
144
+ bool
145
+ checkCFProtectionReturnSupported (DiagnosticsEngine &Diags) const override {
146
+ if (ISAInfo->hasExtension (" zicfiss" ))
147
+ return true ;
148
+ return TargetInfo::checkCFProtectionReturnSupported (Diags);
149
+ }
150
+
144
151
CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme () const override {
145
152
return CFBranchLabelSchemeKind::FuncSig;
146
153
}
Original file line number Diff line number Diff line change @@ -594,6 +594,11 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
594
594
const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
595
595
if (!FD) return ;
596
596
597
+ auto *Fn = cast<llvm::Function>(GV);
598
+
599
+ if (CGM.getCodeGenOpts ().CFProtectionReturn )
600
+ Fn->addFnAttr (" hw-shadow-stack" );
601
+
597
602
const auto *Attr = FD->getAttr <RISCVInterruptAttr>();
598
603
if (!Attr)
599
604
return ;
@@ -604,8 +609,6 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
604
609
case RISCVInterruptAttr::machine: Kind = " machine" ; break ;
605
610
}
606
611
607
- auto *Fn = cast<llvm::Function>(GV);
608
-
609
612
Fn->addFnAttr (" interrupt" , Kind);
610
613
}
611
614
};
Original file line number Diff line number Diff line change
1
+ // RUN: %clang_cc1 -triple riscv64 -target-feature +experimental-zicfiss -emit-llvm -o - %s -fcf-protection=return | FileCheck %s
2
+ // RUN: %clang_cc1 -triple riscv64 -target-feature +experimental-zicfiss -emit-llvm -o - %s | FileCheck -check-prefix=NOSHADOWSTACK %s
3
+ // RUN: %clang_cc1 -triple riscv32 -target-feature +experimental-zicfiss -emit-llvm -o - %s -fcf-protection=return | FileCheck %s
4
+ // RUN: %clang_cc1 -triple riscv32 -target-feature +experimental-zicfiss -emit-llvm -o - %s | FileCheck -check-prefix=NOSHADOWSTACK %s
5
+
6
+ int foo (int * a ) { return * a ; }
7
+
8
+ // CHECK: attributes {{.*}}"hw-shadow-stack"{{.*}}
9
+ // NOSHADOWSTACK-NOT: attributes {{.*}}"hw-shadow-stack"{{.*}}
You can’t perform that action at this time.
0 commit comments