[LLVMbugs] [Bug 3989] C99 inline + extern decl merging problems

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Tue Jan 5 04:01:40 PST 2010


Richard Frith-Macdonald <richard at tiptree.demon.co.uk> changed:

           What    |Removed                     |Added
                 CC|                            |richard at tiptree.demon.co.uk
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |

--- Comment #10 from Richard Frith-Macdonald <richard at tiptree.demon.co.uk>  2010-01-05 06:01:38 ---
I'm not sure why this was marked as resolved/fixed ... perhaps it was fixed but
has been broken again.
I found this pre-existing report when thinking about reporting the same issue
with r92723 from subversion.  The problem is that clang appears to be
generating a reference to an external version of the function when no such
external version can be assumed to exist, resulting in unresolved references at
link time.

I wrote a test program containing a simple inline function x() called from

Now this function is not declared extern or static, and is used in the file.
As it's not declared 'extern' it can't depend on linking to an external
version, yet the .o file produced by clang lists it as undefined so that the
linker tries to resolve it.

See http://www.greenend.org.uk/rjk/2003/03/inline.html for a nice summary of
the rules about inline functions I found.

Here's a log of the results of compiling this code unit with gcc (which seems
to do the right thing) and with clang (followed by a listing of the test code):

[richard at centos libobjc2]$ gcc a.c -std=c99 -c
[richard at centos libobjc2]$ nm a.o | fgrep objc_read_int
[richard at centos libobjc2]$ nm a.o | fgrep x
00000000 T x
[richard at centos libobjc2]$ clang a.c -std=c99 -c
[richard at centos libobjc2]$ nm a.o | fgrep x
         U x
[richard at centos libobjc2]$ cat a.c

inline int
x ()
  return 1;

  return x();

[richard at centos libobjc2]$ 

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list