From 48eda2c5d6d2a5c95775a1a3a8a22428bb6869c6 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Fri, 4 Dec 2009 22:35:50 +0000 Subject: [PATCH] Be a little more clever about inline member functions that are marked inline in the inline class declaration but not in the actual definition: class A { inline void f(); } void A::f() { } This is not the most ideal solution, since it doesn't work 100% with regular functions (as my FIXME comment states). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90607 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Decl.cpp | 14 +++++++++++++- test/CodeGenCXX/inline-functions.cpp | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/CodeGenCXX/inline-functions.cpp diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 572d76ff72..51a4731bfc 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -838,8 +838,20 @@ unsigned FunctionDecl::getMinRequiredArguments() const { } bool FunctionDecl::isInlined() const { - if (isInlineSpecified() || (isa(this) && !isOutOfLine())) + // FIXME: This is not enough. Consider: + // + // inline void f(); + // void f() { } + // + // f is inlined, but does not have inline specified. + // To fix this we should add an 'inline' flag to FunctionDecl. + if (isInlineSpecified()) return true; + + if (isa(this)) { + if (!isOutOfLine() || getCanonicalDecl()->isInlineSpecified()) + return true; + } switch (getTemplateSpecializationKind()) { case TSK_Undeclared: diff --git a/test/CodeGenCXX/inline-functions.cpp b/test/CodeGenCXX/inline-functions.cpp new file mode 100644 index 0000000000..9af4c6e5be --- /dev/null +++ b/test/CodeGenCXX/inline-functions.cpp @@ -0,0 +1,23 @@ +// RUN: clang-cc %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s +// CHECK: ; ModuleID + +struct A { + inline void f(); +}; + +// CHECK-NOT: define void @_ZN1A1fEv +void A::f() { } + +template struct B { }; + +template<> struct B { + inline void f(); +}; + +// CHECK-NOT: _ZN1BIcE1fEv +void B::f() { } + +// We need a final CHECK line here. + +// CHECK: define void @_Z1fv +void f() { } -- 2.40.0