Skip to content

Commit eaae6df

Browse files
gburgessivtstellar
authored andcommitted
[CodeGen] fix inline builtin-related breakage from D78162
In cases where we have multiple decls of an inline builtin, we may need to go hunting for the one with a definition when setting function attributes. An additional test-case was provided on ClangBuiltLinux/linux#979 (cherry picked from commit 9490808)
1 parent 3ab301b commit eaae6df

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,9 +1848,15 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
18481848
F->setSection(SA->getName());
18491849

18501850
// If we plan on emitting this inline builtin, we can't treat it as a builtin.
1851-
if (FD->isInlineBuiltinDeclaration() && shouldEmitFunction(FD)) {
1852-
F->addAttribute(llvm::AttributeList::FunctionIndex,
1853-
llvm::Attribute::NoBuiltin);
1851+
if (FD->isInlineBuiltinDeclaration()) {
1852+
const FunctionDecl *FDBody;
1853+
bool HasBody = FD->hasBody(FDBody);
1854+
(void)HasBody;
1855+
assert(HasBody && "Inline builtin declarations should always have an "
1856+
"available body!");
1857+
if (shouldEmitFunction(FDBody))
1858+
F->addAttribute(llvm::AttributeList::FunctionIndex,
1859+
llvm::Attribute::NoBuiltin);
18541860
}
18551861

18561862
if (FD->isReplaceableGlobalAllocationFunction()) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -triple i686-linux-gnu -std=c++11 -S -emit-llvm -o - %s | FileCheck %s
2+
//
3+
// Regression test for the issue reported at
4+
// https://reviews.llvm.org/D78162#1986104
5+
6+
typedef unsigned long size_t;
7+
8+
extern "C" __inline__ __attribute__((__gnu_inline__)) void *memcpy(void *a, const void *b, unsigned c) {
9+
return __builtin_memcpy(a, b, c);
10+
}
11+
void *memcpy(void *, const void *, unsigned);
12+
13+
// CHECK-LABEL: define void @_Z1av
14+
void a() { (void)memcpy; }
15+
16+
// CHECK-NOT: nobuiltin

0 commit comments

Comments
 (0)