[PATCH] D146339: [StackProtector] attribute __stack_chk_fail as NoReturn
Nick Desaulniers via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 17 17:01:28 PDT 2023
nickdesaulniers updated this revision to Diff 506231.
nickdesaulniers added a comment.
- refactor
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146339/new/
https://reviews.llvm.org/D146339
Files:
llvm/lib/CodeGen/StackProtector.cpp
llvm/test/CodeGen/X86/2009-04-14-IllegalRegs.ll
llvm/test/CodeGen/X86/stack-protector-weight.ll
Index: llvm/test/CodeGen/X86/stack-protector-weight.ll
===================================================================
--- llvm/test/CodeGen/X86/stack-protector-weight.ll
+++ llvm/test/CodeGen/X86/stack-protector-weight.ll
@@ -10,7 +10,7 @@
; DARWIN-SELDAG: bb.[[SUCCESS]]{{[0-9a-zA-Z_.]+}}:
; DARWIN-IR: # Machine code for function test_branch_weights:
-; DARWIN-IR: successors: %bb.[[SUCCESS:[0-9]+]](0x7fffffff), %bb.[[FAILURE:[0-9]+]]
+; DARWIN-IR: successors: %bb.[[SUCCESS:[0-9]+]](0x7ffff800), %bb.[[FAILURE:[0-9]+]]
; DARWIN-IR: bb.[[SUCCESS]]{{[0-9a-zA-Z_.]+}}:
; DARWIN-IR: bb.[[FAILURE]]{{[0-9a-zA-Z_.]+}}:
; DARWIN-IR: CALL64pcrel32 @__stack_chk_fail
Index: llvm/test/CodeGen/X86/2009-04-14-IllegalRegs.ll
===================================================================
--- llvm/test/CodeGen/X86/2009-04-14-IllegalRegs.ll
+++ llvm/test/CodeGen/X86/2009-04-14-IllegalRegs.ll
@@ -53,7 +53,6 @@
; CHECK-NEXT: retl
; CHECK-NEXT: LBB0_3: ## %CallStackCheckFailBlk
; CHECK-NEXT: calll ___stack_chk_fail
-; CHECK-NEXT: ud2
entry:
%retval = alloca i32 ; <ptr> [#uses=2]
%xxx = alloca %struct.X ; <ptr> [#uses=6]
Index: llvm/lib/CodeGen/StackProtector.cpp
===================================================================
--- llvm/lib/CodeGen/StackProtector.cpp
+++ llvm/lib/CodeGen/StackProtector.cpp
@@ -15,6 +15,7 @@
#include "llvm/CodeGen/StackProtector.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/Analysis/MemoryLocation.h"
@@ -594,18 +595,19 @@
if (F->getSubprogram())
B.SetCurrentDebugLocation(
DILocation::get(Context, 0, 0, F->getSubprogram()));
+ FunctionCallee StackChkFail;
+ SmallVector<Value *> Args;
if (Trip.isOSOpenBSD()) {
- FunctionCallee StackChkFail = M->getOrInsertFunction(
- "__stack_smash_handler", Type::getVoidTy(Context),
- Type::getInt8PtrTy(Context));
-
- B.CreateCall(StackChkFail, B.CreateGlobalStringPtr(F->getName(), "SSH"));
+ StackChkFail = M->getOrInsertFunction("__stack_smash_handler",
+ Type::getVoidTy(Context),
+ Type::getInt8PtrTy(Context));
+ Args.push_back(B.CreateGlobalStringPtr(F->getName(), "SSH"));
} else {
- FunctionCallee StackChkFail =
+ StackChkFail =
M->getOrInsertFunction("__stack_chk_fail", Type::getVoidTy(Context));
-
- B.CreateCall(StackChkFail, {});
}
+ cast<Function>(StackChkFail.getCallee())->addFnAttr(Attribute::NoReturn);
+ B.CreateCall(StackChkFail, Args);
B.CreateUnreachable();
return FailBB;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146339.506231.patch
Type: text/x-patch
Size: 2701 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230318/5a8f40b3/attachment.bin>
More information about the llvm-commits
mailing list