forked from OSchip/llvm-project
[CGAtomic] Mark atomic libcall functions `nounwind`
These functions won't ever unwind. This is useful for MemorySanitizer as it simplifies handling __atomic_load in particular. Differential Revision: https://reviews.llvm.org/D85573
This commit is contained in:
parent
d795f968d9
commit
909a851dbf
|
@ -307,7 +307,14 @@ static RValue emitAtomicLibcall(CodeGenFunction &CGF,
|
|||
const CGFunctionInfo &fnInfo =
|
||||
CGF.CGM.getTypes().arrangeBuiltinFunctionCall(resultType, args);
|
||||
llvm::FunctionType *fnTy = CGF.CGM.getTypes().GetFunctionType(fnInfo);
|
||||
llvm::FunctionCallee fn = CGF.CGM.CreateRuntimeFunction(fnTy, fnName);
|
||||
llvm::AttrBuilder fnAttrB;
|
||||
fnAttrB.addAttribute(llvm::Attribute::NoUnwind);
|
||||
fnAttrB.addAttribute(llvm::Attribute::WillReturn);
|
||||
llvm::AttributeList fnAttrs = llvm::AttributeList::get(
|
||||
CGF.getLLVMContext(), llvm::AttributeList::FunctionIndex, fnAttrB);
|
||||
|
||||
llvm::FunctionCallee fn =
|
||||
CGF.CGM.CreateRuntimeFunction(fnTy, fnName, fnAttrs);
|
||||
auto callee = CGCallee::forDirect(fn);
|
||||
return CGF.EmitCall(fnInfo, callee, ReturnValueSlot(), args);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,9 @@ void foo(int x)
|
|||
|
||||
}
|
||||
|
||||
// LIBCALL: declare void @__atomic_load(i32, i8*, i8*, i32) [[LC_ATTRS:#[0-9]+]]
|
||||
// LIBCALL: declare i1 @__atomic_compare_exchange(i32, i8*, i8*, i8*, i32, i32) [[LC_ATTRS:#[0-9]+]]
|
||||
|
||||
extern _Atomic _Bool b;
|
||||
|
||||
_Bool bar() {
|
||||
|
@ -53,6 +56,8 @@ void baz(int y) {
|
|||
x += y;
|
||||
}
|
||||
|
||||
// LIBCALL: declare void @__atomic_store(i32, i8*, i8*, i32) [[LC_ATTRS:#[0-9]+]]
|
||||
|
||||
_Atomic(int) compound_add(_Atomic(int) in) {
|
||||
// CHECK-LABEL: @compound_add
|
||||
// CHECK: [[OLD:%.*]] = atomicrmw add i32* {{.*}}, i32 5 seq_cst
|
||||
|
@ -107,3 +112,5 @@ _Atomic(int) compound_mul(_Atomic(int) in) {
|
|||
|
||||
return (in *= 5);
|
||||
}
|
||||
|
||||
// LIBCALL: [[LC_ATTRS]] = { nounwind willreturn }
|
||||
|
|
Loading…
Reference in New Issue