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 {
141141 return true ;
142142 }
143143
144+ bool
145+ checkCFProtectionReturnSupported (DiagnosticsEngine &Diags) const override {
146+ if (ISAInfo->hasExtension (" zicfiss" ))
147+ return true ;
148+ return TargetInfo::checkCFProtectionReturnSupported (Diags);
149+ }
150+
144151 CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme () const override {
145152 return CFBranchLabelSchemeKind::FuncSig;
146153 }
Original file line number Diff line number Diff line change @@ -594,6 +594,11 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
594594 const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
595595 if (!FD) return ;
596596
597+ auto *Fn = cast<llvm::Function>(GV);
598+
599+ if (CGM.getCodeGenOpts ().CFProtectionReturn )
600+ Fn->addFnAttr (" hw-shadow-stack" );
601+
597602 const auto *Attr = FD->getAttr <RISCVInterruptAttr>();
598603 if (!Attr)
599604 return ;
@@ -604,8 +609,6 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
604609 case RISCVInterruptAttr::machine: Kind = " machine" ; break ;
605610 }
606611
607- auto *Fn = cast<llvm::Function>(GV);
608-
609612 Fn->addFnAttr (" interrupt" , Kind);
610613 }
611614};
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