Skip to content

Commit 408d010

Browse files
committedApr 1, 2015
[SimplifyLibCalls] Ignore nobuiltin/unavailable fortified libcalls.
We used to do this before refactorings around r225640. Some clang users checked for _chk libcall availability using: __has_builtin(__builtin___memcpy_chk) When compiling with -fno-builtin, this is always true. When passing -ffreestanding/-mkernel, which both imply -fno-builtin, we end up with fortified libcalls, which isn't acceptable in a freestanding environment which only provides their non-fortified counterparts. Until we change clang and/or teach external users to check for availability differently, disregard the "nobuiltin" attribute and TLI::has. Workaround for PR23093. llvm-svn: 233776
1 parent 50271aa commit 408d010

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed
 

‎llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -2322,8 +2322,18 @@ Value *FortifiedLibCallSimplifier::optimizeStrpNCpyChk(CallInst *CI,
23222322
}
23232323

23242324
Value *FortifiedLibCallSimplifier::optimizeCall(CallInst *CI) {
2325-
if (CI->isNoBuiltin())
2326-
return nullptr;
2325+
// FIXME: We shouldn't be changing "nobuiltin" or TLI unavailable calls here.
2326+
// Some clang users checked for _chk libcall availability using:
2327+
// __has_builtin(__builtin___memcpy_chk)
2328+
// When compiling with -fno-builtin, this is always true.
2329+
// When passing -ffreestanding/-mkernel, which both imply -fno-builtin, we
2330+
// end up with fortified libcalls, which isn't acceptable in a freestanding
2331+
// environment which only provides their non-fortified counterparts.
2332+
//
2333+
// Until we change clang and/or teach external users to check for availability
2334+
// differently, disregard the "nobuiltin" attribute and TLI::has.
2335+
//
2336+
// PR23093.
23272337

23282338
LibFunc::Func Func;
23292339
Function *Callee = CI->getCalledFunction();
@@ -2332,7 +2342,7 @@ Value *FortifiedLibCallSimplifier::optimizeCall(CallInst *CI) {
23322342
bool isCallingConvC = CI->getCallingConv() == llvm::CallingConv::C;
23332343

23342344
// First, check that this is a known library functions.
2335-
if (!TLI->getLibFunc(FuncName, Func) || !TLI->has(Func))
2345+
if (!TLI->getLibFunc(FuncName, Func))
23362346
return nullptr;
23372347

23382348
// We never change the calling convention.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: opt -S -disable-simplify-libcalls -codegenprepare < %s | FileCheck %s
2+
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
3+
4+
; This is a workaround for PR23093: when building with -mkernel/-fno-builtin,
5+
; we still generate fortified library calls.
6+
7+
; Check that we ignore two things:
8+
; - attribute nobuiltin
9+
; - TLI::has (always returns false thanks to -disable-simplify-libcalls)
10+
11+
; CHECK-NOT: _chk
12+
; CHECK: call void @llvm.memset.p0i8.i64(i8* %dst, i8 0, i64 %len, i32 1, i1 false)
13+
define void @test_nobuiltin(i8* %dst, i64 %len) {
14+
call i8* @__memset_chk(i8* %dst, i32 0, i64 %len, i64 -1) nobuiltin
15+
ret void
16+
}
17+
18+
declare i8* @__memset_chk(i8*, i32, i64, i64)

0 commit comments

Comments
 (0)