Skip to content

Commit fffc1ce

Browse files
committed
Fix PR9614 for functions with the always_inline attribute. Try to keep
the common case (-O0, no always_inline) fast. llvm-svn: 143222
1 parent 409b694 commit fffc1ce

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -901,18 +901,15 @@ bool
901901
CodeGenModule::shouldEmitFunction(const FunctionDecl *F) {
902902
if (getFunctionLinkage(F) != llvm::Function::AvailableExternallyLinkage)
903903
return true;
904-
if (F->hasAttr<AlwaysInlineAttr>())
905-
return true;
906-
if (CodeGenOpts.OptimizationLevel == 0)
904+
if (CodeGenOpts.OptimizationLevel == 0 &&
905+
!F->hasAttr<AlwaysInlineAttr>())
907906
return false;
908907
// PR9614. Avoid cases where the source code is lying to us. An available
909908
// externally function should have an equivalent function somewhere else,
910909
// but a function that calls itself is clearly not equivalent to the real
911910
// implementation.
912911
// This happens in glibc's btowc and in some configure checks.
913-
if (isTriviallyRecursiveViaAsm(F))
914-
return false;
915-
return true;
912+
return !isTriviallyRecursiveViaAsm(F);
916913
}
917914

918915
void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD) {

clang/test/CodeGen/pr9614.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
22

3-
extern int foo_alias (void) __asm ("foo");
4-
inline int foo (void) {
3+
extern void foo_alias (void) __asm ("foo");
4+
inline void foo (void) {
55
return foo_alias ();
66
}
7-
int f(void) {
8-
return foo();
7+
extern void bar_alias (void) __asm ("bar");
8+
inline __attribute__ ((__always_inline__)) void bar (void) {
9+
return bar_alias ();
910
}
11+
void f(void) {
12+
foo();
13+
bar();
14+
}
15+
16+
// CHECK: define void @f()
17+
// CHECK-NEXT: entry:
18+
// CHECK-NEXT: call void @foo()
19+
// CHECK-NEXT: call void @bar()
20+
// CHECK-NEXT: ret void
1021

11-
// CHECK-NOT: define
12-
// CHECK: define i32 @f()
13-
// CHECK: call i32 @foo()
14-
// CHECK-NEXT: ret i32
15-
// CHECK-NOT: define
22+
// CHECK: declare void @foo()
23+
// CHECK: declare void @bar()

0 commit comments

Comments
 (0)