[LLVMdev] Conditions that cause Clang refuse inlining a function
Reid Kleckner
rnk at google.com
Thu Sep 4 09:06:24 PDT 2014
On Thu, Sep 4, 2014 at 4:42 AM, David Sela <sela.david at gmail.com> wrote:
> Hi,
>
> I want to have some functions in my code inline so I use the *inline *
> keyword:
>
> *inline void foo() {}*
>
> On some functions the compiler inlines the function but it fails to do so
> on other functions and thus I get a linkage error:
>
> *error: undefined reference to 'foo'*
>
> What are the conditions that make the compiler refuse inline?
>
There are many reasons:
- recursion
- varargs
- code size
- general unprofitability
- compiling with -O0
It sounds like you're having trouble with C99 inline. Make sure to have a
single .c file that redeclares the inline function without 'inline' like so:
// foo.h
inline int foo() { return 42; }
// foo.c
int foo();
The redeclaration will force the compiler to emit a strong definition in
that TU, preventing linkage errors, so long as you only do it in one TU.
See here for more info:
http://www.greenend.org.uk/rjk/tech/inline.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140904/caa937e0/attachment.html>
More information about the llvm-dev
mailing list