[clang] [llvm] [Clang][RISCV] Add hw-shadow-stack to functions without a FunctionDecl (PR #245909)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 25 00:10:39 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
@llvm/pr-subscribers-clang-codegen
Author: Kito Cheng (kito-cheng)
<details>
<summary>Changes</summary>
With -fcf-protection=return, functions that Clang makes itself had no
"hw-shadow-stack": IFUNC resolvers for target_clones and target_version,
global and TLS init functions, the C++ TLS wrapper, and OpenMP outlined
functions. They do not come from a function in the source, so they have
no FunctionDecl. RISCVTargetCodeGenInfo::setTargetAttributes returned
early in that case, before it added the attribute, and the TLS wrapper
does not call it at all. Functions that passes make, such as
asan.module_ctor, had none either.
Do it the same way as AArch64 branch protection:
- Add a HWShadowStack language option. RISCVTargetInfo::adjust sets it
from -fcf-protection=return, and BranchProtectionInfo carries it. So
every function gets "hw-shadow-stack" as a default attribute, and
setTargetAttributes adds it before the FunctionDecl check.
- Emit a "hw-shadow-stack" module flag. Function::createWithDefaultAttr
then adds the attribute to functions that passes make.
Fixes #<!-- -->240316.
Assisted-by: Claude
---
Patch is 21.98 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/245909.diff
11 Files Affected:
- (modified) clang/include/clang/Basic/LangOptions.def (+1)
- (modified) clang/include/clang/Basic/TargetInfo.h (+3-1)
- (modified) clang/lib/Basic/Targets/RISCV.cpp (+7)
- (modified) clang/lib/Basic/Targets/RISCV.h (+3)
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+3)
- (modified) clang/lib/CodeGen/TargetInfo.cpp (+3)
- (modified) clang/lib/CodeGen/Targets/RISCV.cpp (+9-5)
- (added) clang/test/CodeGen/RISCV/attr-hw-shadow-stack-synthesized.cpp (+259)
- (modified) clang/test/CodeGen/RISCV/attr-hw-shadow-stack.c (+2-1)
- (modified) llvm/lib/IR/Function.cpp (+1)
- (added) llvm/test/Instrumentation/AddressSanitizer/module-flags-riscv.ll (+26)
``````````diff
diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def
index 1fef2c5d881c77..f56c4f961c7698 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -474,6 +474,7 @@ ENUM_LANGOPT(SignReturnAddressHardening, SignReturnAddressHardeningKind, 1,
LANGOPT(BranchTargetEnforcement, 1, 0, NotCompatible, "Branch-target enforcement enabled")
LANGOPT(BranchProtectionPAuthLR, 1, 0, NotCompatible, "Use PC as a diversifier using PAuthLR NOP instructions.")
LANGOPT(GuardedControlStack, 1, 0, NotCompatible, "Guarded control stack enabled")
+LANGOPT(HWShadowStack, 1, 0, NotCompatible, "Hardware shadow stack enabled")
LANGOPT(SpeculativeLoadHardening, 1, 0, Benign, "Speculative load hardening enabled")
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index 7c5c35a5cfb7c5..abad7048870a98 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1484,6 +1484,7 @@ class TargetInfo : public TransferrableTargetInfo,
bool BranchTargetEnforcement;
bool BranchProtectionPAuthLR;
bool GuardedControlStack;
+ bool HWShadowStack;
const char *getSignReturnAddrStr() const {
switch (SignReturnAddr) {
@@ -1523,7 +1524,7 @@ class TargetInfo : public TransferrableTargetInfo,
SignReturnAddressHardening(
LangOptions::SignReturnAddressHardeningKind::None),
BranchTargetEnforcement(false), BranchProtectionPAuthLR(false),
- GuardedControlStack(false) {}
+ GuardedControlStack(false), HWShadowStack(false) {}
BranchProtectionInfo(const LangOptions &LangOpts) {
SignReturnAddr =
@@ -1539,6 +1540,7 @@ class TargetInfo : public TransferrableTargetInfo,
BranchTargetEnforcement = LangOpts.BranchTargetEnforcement;
BranchProtectionPAuthLR = LangOpts.BranchProtectionPAuthLR;
GuardedControlStack = LangOpts.GuardedControlStack;
+ HWShadowStack = LangOpts.HWShadowStack;
}
};
diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp
index e0adceb80fa0c1..87f67693668d6e 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -410,6 +410,13 @@ bool RISCVTargetInfo::hasFeature(StringRef Feature) const {
return ISAInfo->hasExtension(Feature);
}
+void RISCVTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts,
+ const TargetInfo *Aux) {
+ TargetInfo::adjust(Diags, Opts, Aux);
+ // -fcf-protection=return uses the Zicfiss shadow stack.
+ Opts.HWShadowStack = Opts.CFProtectionReturn;
+}
+
/// Perform initialization based on the user configured set of features.
bool RISCVTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
DiagnosticsEngine &Diags) {
diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 6997383c4d5898..8dd8dcdd82619f 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -108,6 +108,9 @@ class RISCVTargetInfo : public TargetInfo {
bool handleTargetFeatures(std::vector<std::string> &Features,
DiagnosticsEngine &Diags) override;
+ void adjust(DiagnosticsEngine &Diags, LangOptions &Opts,
+ const TargetInfo *Aux) override;
+
bool hasBitIntType() const override { return true; }
size_t getMaxBitIntWidth() const override {
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index f0ea493e172229..a3f1cb51cb24eb 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1681,6 +1681,9 @@ void CodeGenModule::Release() {
}
}
+ if (LangOpts.HWShadowStack)
+ getModule().addModuleFlag(llvm::Module::Min, "hw-shadow-stack", 1);
+
if (CodeGenOpts.FunctionReturnThunks)
getModule().addModuleFlag(llvm::Module::Override, "function_return_thunk_extern", 1);
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index 86f96b72170032..cde04a55777a06 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -262,6 +262,7 @@ void TargetCodeGenInfo::setBranchProtectionFnAttributes(
AddRemoveAttributeAsSet(BPI.BranchProtectionPAuthLR,
"branch-protection-pauth-lr");
AddRemoveAttributeAsSet(BPI.GuardedControlStack, "guarded-control-stack");
+ AddRemoveAttributeAsSet(BPI.HWShadowStack, "hw-shadow-stack");
}
void TargetCodeGenInfo::initBranchProtectionFnAttributes(
@@ -282,6 +283,8 @@ void TargetCodeGenInfo::initBranchProtectionFnAttributes(
FuncAttrs.addAttribute("branch-protection-pauth-lr");
if (BPI.GuardedControlStack)
FuncAttrs.addAttribute("guarded-control-stack");
+ if (BPI.HWShadowStack)
+ FuncAttrs.addAttribute("hw-shadow-stack");
}
void TargetCodeGenInfo::setPointerAuthFnAttributes(
diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp
index 96dad3d044c05f..8f8adff9994b95 100644
--- a/clang/lib/CodeGen/Targets/RISCV.cpp
+++ b/clang/lib/CodeGen/Targets/RISCV.cpp
@@ -1128,13 +1128,17 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &CGM) const override {
- const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
- if (!FD) return;
+ auto *Fn = dyn_cast<llvm::Function>(GV);
+ if (!Fn)
+ return;
- auto *Fn = cast<llvm::Function>(GV);
+ // Also covers functions without a FunctionDecl, such as IFUNC resolvers.
+ setBranchProtectionFnAttributes(
+ TargetInfo::BranchProtectionInfo(CGM.getLangOpts()), *Fn);
- if (CGM.getCodeGenOpts().CFProtectionReturn)
- Fn->addFnAttr("hw-shadow-stack");
+ const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
+ if (!FD)
+ return;
const auto *Attr = FD->getAttr<RISCVInterruptAttr>();
if (!Attr)
diff --git a/clang/test/CodeGen/RISCV/attr-hw-shadow-stack-synthesized.cpp b/clang/test/CodeGen/RISCV/attr-hw-shadow-stack-synthesized.cpp
new file mode 100644
index 00000000000000..8947fdf962876d
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/attr-hw-shadow-stack-synthesized.cpp
@@ -0,0 +1,259 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals all --include-generated-funcs --version 6
+// RUN: %clang_cc1 -triple riscv64-linux-gnu -target-feature +zimop -emit-llvm -o - %s -fcf-protection=return | FileCheck %s
+// RUN: %clang_cc1 -triple riscv64-linux-gnu -target-feature +zimop -emit-llvm -o - %s | FileCheck -check-prefix=NOSHADOWSTACK %s
+
+// Functions that Clang creates without a FunctionDecl need "hw-shadow-stack"
+// too.
+
+int g();
+
+__attribute__((target_clones("default", "arch=+zbb"))) int foo(int x) {
+ return x + 1;
+}
+int bar(int x) { return foo(x); }
+
+int x = g();
+thread_local int t = g();
+int use() { return t; }
+//.
+// CHECK: @x = global i32 0, align 4
+// CHECK: @t = thread_local global i32 0, align 4
+// CHECK: @__riscv_feature_bits = external dso_local global { i32, [2 x i64] }
+// CHECK: @__tls_guard = internal thread_local global i8 0, align 1
+// CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_attr_hw_shadow_stack_synthesized.cpp, ptr null }]
+// CHECK: @_Z3fooi.ifunc = weak_odr alias i32 (i32), ptr @_Z3fooi
+// CHECK: @_ZTH1t = alias void (), ptr @__tls_init
+// CHECK: @_Z3fooi = weak_odr ifunc i32 (i32), ptr @_Z3fooi.resolver
+//.
+// NOSHADOWSTACK: @x = global i32 0, align 4
+// NOSHADOWSTACK: @t = thread_local global i32 0, align 4
+// NOSHADOWSTACK: @__riscv_feature_bits = external dso_local global { i32, [2 x i64] }
+// NOSHADOWSTACK: @__tls_guard = internal thread_local global i8 0, align 1
+// NOSHADOWSTACK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_attr_hw_shadow_stack_synthesized.cpp, ptr null }]
+// NOSHADOWSTACK: @_Z3fooi.ifunc = weak_odr alias i32 (i32), ptr @_Z3fooi
+// NOSHADOWSTACK: @_ZTH1t = alias void (), ptr @__tls_init
+// NOSHADOWSTACK: @_Z3fooi = weak_odr ifunc i32 (i32), ptr @_Z3fooi.resolver
+//.
+// CHECK-LABEL: define dso_local noundef signext i32 @_Z3fooi.default(
+// CHECK-SAME: i32 noundef signext [[X:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT: [[X_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT: store i32 [[X]], ptr [[X_ADDR]], align 4
+// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP0]], 1
+// CHECK-NEXT: ret i32 [[ADD]]
+//
+//
+// CHECK-LABEL: define dso_local noundef signext i32 @_Z3fooi._zbb(
+// CHECK-SAME: i32 noundef signext [[X:%.*]]) #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT: [[X_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT: store i32 [[X]], ptr [[X_ADDR]], align 4
+// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP0]], 1
+// CHECK-NEXT: ret i32 [[ADD]]
+//
+//
+// CHECK-LABEL: define weak_odr ptr @_Z3fooi.resolver(
+// CHECK-SAME: ) #[[ATTR2:[0-9]+]] comdat {
+// CHECK-NEXT: [[RESOLVER_ENTRY:.*:]]
+// CHECK-NEXT: call void @__init_riscv_feature_bits(ptr null)
+// CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr getelementptr inbounds nuw (i8, ptr @__riscv_feature_bits, i64 8), align 8
+// CHECK-NEXT: [[TMP1:%.*]] = and i64 [[TMP0]], 268435456
+// CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 268435456
+// CHECK-NEXT: br i1 [[TMP2]], label %[[RESOLVER_RETURN:.*]], label %[[RESOLVER_ELSE:.*]]
+// CHECK: [[RESOLVER_RETURN]]:
+// CHECK-NEXT: ret ptr @_Z3fooi._zbb
+// CHECK: [[RESOLVER_ELSE]]:
+// CHECK-NEXT: ret ptr @_Z3fooi.default
+//
+//
+// CHECK-LABEL: define dso_local noundef signext i32 @_Z3bari(
+// CHECK-SAME: i32 noundef signext [[X:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT: [[X_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT: store i32 [[X]], ptr [[X_ADDR]], align 4
+// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// CHECK-NEXT: [[CALL:%.*]] = call noundef signext i32 @_Z3fooi(i32 noundef signext [[TMP0]])
+// CHECK-NEXT: ret i32 [[CALL]]
+//
+//
+// CHECK-LABEL: define internal void @__cxx_global_var_init(
+// CHECK-SAME: ) #[[ATTR3:[0-9]+]] section ".text.startup" {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT: [[CALL:%.*]] = call noundef signext i32 @_Z1gv()
+// CHECK-NEXT: store i32 [[CALL]], ptr @x, align 4
+// CHECK-NEXT: ret void
+//
+//
+// CHECK-LABEL: define internal void @__cxx_global_var_init.1(
+// CHECK-SAME: ) #[[ATTR3]] section ".text.startup" {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT: [[CALL:%.*]] = call noundef signext i32 @_Z1gv()
+// CHECK-NEXT: [[TMP0:%.*]] = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @t)
+// CHECK-NEXT: store i32 [[CALL]], ptr [[TMP0]], align 4
+// CHECK-NEXT: ret void
+//
+//
+// CHECK-LABEL: define dso_local noundef signext i32 @_Z3usev(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT: [[TMP0:%.*]] = call ptr @_ZTW1t()
+// CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4
+// CHECK-NEXT: ret i32 [[TMP1]]
+//
+//
+// CHECK-LABEL: define weak_odr hidden noundef ptr @_ZTW1t(
+// CHECK-SAME: ) #[[ATTR3]] comdat {
+// CHECK-NEXT: call void @_ZTH1t()
+// CHECK-NEXT: [[TMP1:%.*]] = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @t)
+// CHECK-NEXT: ret ptr [[TMP1]]
+//
+//
+// CHECK-LABEL: define internal void @_GLOBAL__sub_I_attr_hw_shadow_stack_synthesized.cpp(
+// CHECK-SAME: ) #[[ATTR3]] section ".text.startup" {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT: call void @__cxx_global_var_init()
+// CHECK-NEXT: ret void
+//
+//
+// CHECK-LABEL: define internal void @__tls_init(
+// CHECK-SAME: ) #[[ATTR3]] {
+// CHECK-NEXT: [[ENTRY:.*:]]
+// CHECK-NEXT: [[TMP0:%.*]] = load i8, ptr @__tls_guard, align 1
+// CHECK-NEXT: [[GUARD_UNINITIALIZED:%.*]] = icmp eq i8 [[TMP0]], 0
+// CHECK-NEXT: br i1 [[GUARD_UNINITIALIZED]], label %[[INIT:.*]], label %[[EXIT:.*]], !prof [[PROF6:![0-9]+]]
+// CHECK: [[INIT]]:
+// CHECK-NEXT: store i8 1, ptr @__tls_guard, align 1
+// CHECK-NEXT: call void @__cxx_global_var_init.1()
+// CHECK-NEXT: br label %[[EXIT]]
+// CHECK: [[EXIT]]:
+// CHECK-NEXT: ret void
+//
+//
+// NOSHADOWSTACK-LABEL: define dso_local noundef signext i32 @_Z3fooi.default(
+// NOSHADOWSTACK-SAME: i32 noundef signext [[X:%.*]]) #[[ATTR0:[0-9]+]] {
+// NOSHADOWSTACK-NEXT: [[ENTRY:.*:]]
+// NOSHADOWSTACK-NEXT: [[X_ADDR:%.*]] = alloca i32, align 4
+// NOSHADOWSTACK-NEXT: store i32 [[X]], ptr [[X_ADDR]], align 4
+// NOSHADOWSTACK-NEXT: [[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// NOSHADOWSTACK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP0]], 1
+// NOSHADOWSTACK-NEXT: ret i32 [[ADD]]
+//
+//
+// NOSHADOWSTACK-LABEL: define dso_local noundef signext i32 @_Z3fooi._zbb(
+// NOSHADOWSTACK-SAME: i32 noundef signext [[X:%.*]]) #[[ATTR1:[0-9]+]] {
+// NOSHADOWSTACK-NEXT: [[ENTRY:.*:]]
+// NOSHADOWSTACK-NEXT: [[X_ADDR:%.*]] = alloca i32, align 4
+// NOSHADOWSTACK-NEXT: store i32 [[X]], ptr [[X_ADDR]], align 4
+// NOSHADOWSTACK-NEXT: [[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// NOSHADOWSTACK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP0]], 1
+// NOSHADOWSTACK-NEXT: ret i32 [[ADD]]
+//
+//
+// NOSHADOWSTACK-LABEL: define weak_odr ptr @_Z3fooi.resolver(
+// NOSHADOWSTACK-SAME: ) #[[ATTR2:[0-9]+]] comdat {
+// NOSHADOWSTACK-NEXT: [[RESOLVER_ENTRY:.*:]]
+// NOSHADOWSTACK-NEXT: call void @__init_riscv_feature_bits(ptr null)
+// NOSHADOWSTACK-NEXT: [[TMP0:%.*]] = load i64, ptr getelementptr inbounds nuw (i8, ptr @__riscv_feature_bits, i64 8), align 8
+// NOSHADOWSTACK-NEXT: [[TMP1:%.*]] = and i64 [[TMP0]], 268435456
+// NOSHADOWSTACK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 268435456
+// NOSHADOWSTACK-NEXT: br i1 [[TMP2]], label %[[RESOLVER_RETURN:.*]], label %[[RESOLVER_ELSE:.*]]
+// NOSHADOWSTACK: [[RESOLVER_RETURN]]:
+// NOSHADOWSTACK-NEXT: ret ptr @_Z3fooi._zbb
+// NOSHADOWSTACK: [[RESOLVER_ELSE]]:
+// NOSHADOWSTACK-NEXT: ret ptr @_Z3fooi.default
+//
+//
+// NOSHADOWSTACK-LABEL: define dso_local noundef signext i32 @_Z3bari(
+// NOSHADOWSTACK-SAME: i32 noundef signext [[X:%.*]]) #[[ATTR0]] {
+// NOSHADOWSTACK-NEXT: [[ENTRY:.*:]]
+// NOSHADOWSTACK-NEXT: [[X_ADDR:%.*]] = alloca i32, align 4
+// NOSHADOWSTACK-NEXT: store i32 [[X]], ptr [[X_ADDR]], align 4
+// NOSHADOWSTACK-NEXT: [[TMP0:%.*]] = load i32, ptr [[X_ADDR]], align 4
+// NOSHADOWSTACK-NEXT: [[CALL:%.*]] = call noundef signext i32 @_Z3fooi(i32 noundef signext [[TMP0]])
+// NOSHADOWSTACK-NEXT: ret i32 [[CALL]]
+//
+//
+// NOSHADOWSTACK-LABEL: define internal void @__cxx_global_var_init(
+// NOSHADOWSTACK-SAME: ) #[[ATTR3:[0-9]+]] section ".text.startup" {
+// NOSHADOWSTACK-NEXT: [[ENTRY:.*:]]
+// NOSHADOWSTACK-NEXT: [[CALL:%.*]] = call noundef signext i32 @_Z1gv()
+// NOSHADOWSTACK-NEXT: store i32 [[CALL]], ptr @x, align 4
+// NOSHADOWSTACK-NEXT: ret void
+//
+//
+// NOSHADOWSTACK-LABEL: define internal void @__cxx_global_var_init.1(
+// NOSHADOWSTACK-SAME: ) #[[ATTR3]] section ".text.startup" {
+// NOSHADOWSTACK-NEXT: [[ENTRY:.*:]]
+// NOSHADOWSTACK-NEXT: [[CALL:%.*]] = call noundef signext i32 @_Z1gv()
+// NOSHADOWSTACK-NEXT: [[TMP0:%.*]] = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @t)
+// NOSHADOWSTACK-NEXT: store i32 [[CALL]], ptr [[TMP0]], align 4
+// NOSHADOWSTACK-NEXT: ret void
+//
+//
+// NOSHADOWSTACK-LABEL: define dso_local noundef signext i32 @_Z3usev(
+// NOSHADOWSTACK-SAME: ) #[[ATTR0]] {
+// NOSHADOWSTACK-NEXT: [[ENTRY:.*:]]
+// NOSHADOWSTACK-NEXT: [[TMP0:%.*]] = call ptr @_ZTW1t()
+// NOSHADOWSTACK-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4
+// NOSHADOWSTACK-NEXT: ret i32 [[TMP1]]
+//
+//
+// NOSHADOWSTACK-LABEL: define weak_odr hidden noundef ptr @_ZTW1t(
+// NOSHADOWSTACK-SAME: ) #[[ATTR3]] comdat {
+// NOSHADOWSTACK-NEXT: call void @_ZTH1t()
+// NOSHADOWSTACK-NEXT: [[TMP1:%.*]] = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @t)
+// NOSHADOWSTACK-NEXT: ret ptr [[TMP1]]
+//
+//
+// NOSHADOWSTACK-LABEL: define internal void @_GLOBAL__sub_I_attr_hw_shadow_stack_synthesized.cpp(
+// NOSHADOWSTACK-SAME: ) #[[ATTR3]] section ".text.startup" {
+// NOSHADOWSTACK-NEXT: [[ENTRY:.*:]]
+// NOSHADOWSTACK-NEXT: call void @__cxx_global_var_init()
+// NOSHADOWSTACK-NEXT: ret void
+//
+//
+// NOSHADOWSTACK-LABEL: define internal void @__tls_init(
+// NOSHADOWSTACK-SAME: ) #[[ATTR3]] {
+// NOSHADOWSTACK-NEXT: [[ENTRY:.*:]]
+// NOSHADOWSTACK-NEXT: [[TMP0:%.*]] = load i8, ptr @__tls_guard, align 1
+// NOSHADOWSTACK-NEXT: [[GUARD_UNINITIALIZED:%.*]] = icmp eq i8 [[TMP0]], 0
+// NOSHADOWSTACK-NEXT: br i1 [[GUARD_UNINITIALIZED]], label %[[INIT:.*]], label %[[EXIT:.*]], !prof [[PROF5:![0-9]+]]
+// NOSHADOWSTACK: [[INIT]]:
+// NOSHADOWSTACK-NEXT: store i8 1, ptr @__tls_guard, align 1
+// NOSHADOWSTACK-NEXT: call void @__cxx_global_var_init.1()
+// NOSHADOWSTACK-NEXT: br label %[[EXIT]]
+// NOSHADOWSTACK: [[EXIT]]:
+// NOSHADOWSTACK-NEXT: ret void
+//
+//.
+// CHECK: attributes #[[ATTR0]] = { mustprogress noinline nounwind optnone "hw-shadow-stack" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+zimop" }
+// CHECK: attributes #[[ATTR1]] = { mustprogress noinline nounwind optnone "hw-shadow-stack" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+zbb,+zimop" }
+// CHECK: attributes #[[ATTR2]] = { disable_sanitizer_instrumentation "hw-shadow-stack" }
+// CHECK: attributes #[[ATTR3]] = { noinline nounwind "hw-shadow-stack" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+zimop" }
+// CHECK: attributes #[[ATTR4:[0-9]+]] = { "hw-shadow-stack" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+zimop" }
+// CHECK: attributes #[[ATTR5:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
+//.
+// NOSHADOWSTACK: attributes #[[ATTR0]] = { mustprogress noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+zimop" }
+// NOSHADOWSTACK: attributes #[[ATTR1]] = { mustprogress noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+zbb,+zimop" }
+// NOSHADOWSTACK: attributes #[[ATTR2]] = { disable_sanitizer_instrumentation }
+// NOSHADOWSTACK: attributes #[[ATTR3]] = { noinline nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+zimop" }
+// NOSHADOWSTACK: attributes #[[ATTR4:[0-9]+]] = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+zimop" }
+// NOSHADOWSTACK: attributes #[[ATTR5:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
+//.
+// CHECK: [[META0:![0-9]+]] = !{i32 1, !"target-abi", !"lp64"}
+// CHECK: [[META1:![0-9]+]] = !{i32 6, !"riscv-isa", [[META2:![0-9]+]]}
+// CHECK: [[META2]] = !{!"rv64i2p1_zimop1p0"}
+// CHECK: [[META3:![0-9]+]] = !{i32 8, !"cf-protection-return", i32 1}
+// CHECK: [[META4:![0-9]+]] = !{i32 8, !"SmallDataLimit", i32 0}
+// CHECK: [[META5:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
+// CHECK: [[PROF6]] = !{!"branch_weights", i32 1, i32 1023}
+//.
+// NOSHADOWSTACK: [[META0:![0-9]+]] = !{i32 1, !"target-abi", !"lp64"}
+// NOSHADOWSTACK: [[META1:![0-9]+]] = !{i32 6, !"riscv-isa", [[META2:![0-9]+]]}
+// NOSHADOWSTACK: [[META2]] = !{!"rv64i2p1_zimop1p0"}
+// NOSHADOWSTACK: [[META3:![0-9]+]] = !{i32 8, !"SmallDataLimit", i32 0}
+// NOSHADOWSTACK: [[META4:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
+// NOSHADOWSTACK: [[PROF5]] = !{!"branch_weights", i32 1, i32 1023}
+//.
diff --git a/clang/test/CodeGen/RISCV/attr-hw-shadow-stack.c b/clang/test/CodeGen/RISCV/attr-hw-shadow-stack.c
index 8dfdc8c044cae1..93add521c162a6 100644
--- a/clang/test/CodeGen/RISCV/attr-hw-shadow-stack.c
+++ b/clang/test/CodeGen...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/245909
More information about the cfe-commits
mailing list