test/Sema/typedef-redef.c failure

Hi,

Is anyone else seeing a failure in the Sema/typedef-redef.c test?
I'm getting this output:

$ clang -fsyntax-only test/Sema/typedef-redef.c
test/Sema/typedef-redef.c:4:23: error: redefinition of 'size_t'
typedef unsigned long size_t;
                      ^
In file included from test/Sema/typedef-redef.c:3:
/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/stddef.h:214:23: error: previous definition is here
typedef __SIZE_TYPE__ size_t;
                      ^
2 diagnostics generated.

Notice that it is including gcc's stddef.h instead of clang's. (btw __SIZE_TYPE__ is defined as 'long unsigned int').

Nuno

I'm not seeing this. Is /usr/lib/gcc/i686-oc-linue-gnu/4.1.2 included in the driver (clang.cpp) as a system header?

For example, do you have a line like:

     // Fedora 8
     AddPath("/usr/lib/gcc/i386-redhat-linux/4.1.2/include", System,
             false, false, false, Headers);

If you don't, stddef.h might not be included as a system header, although I'm not certain why clang would be able to find stddef.h.

No, I haven't patched the clang driver. I'm now using the CPATH environment variable. Anyway clang was supposed to use its own stddef.h...
Nuno

Uhm, so the reason why clang isn't using its own stddef.h is because GetMainExecutable() is returning 'clang' only. It then tries to access the /Headers directory and fails.
This issue has already been reported here for Debian systems, but I confirm this is also an issue with Gentoo stable (glibc 2.6.1).

Nuno

Uhm, so the reason why clang isn't using its own stddef.h is
because GetMainExecutable() is returning 'clang' only. It then
tries to access the /Headers directory and fails.
This issue has already been reported here for Debian systems,
but I confirm this is also an issue with Gentoo stable (glibc
2.6.1).

You can, in your mind, remove "Debian" and "Gentoo", and if it
pops up, also SUSE and Redhat and whatever, because it's a
generic linux problem.

Seo Sanghyeon already proposed a way to solve this:

"GetMainExecutable" is a tricky function to implement in
cross-platform way. The standard Linux method is to resolve
symlink /proc/self/exe. On Windows, you call GetModuleFileName.
See http://autopackage.org/docs/binreloc/ for extensive
discussion.

and I might even implement it, but I don't have much time for
this, so feel free to grab it and implement it faster. :slight_smile:

Holger Schurig wrote:

Seo Sanghyeon already proposed a way to solve this:

"GetMainExecutable" is a tricky function to implement in
cross-platform way. The standard Linux method is to resolve
symlink /proc/self/exe. On Windows, you call GetModuleFileName.
See http://autopackage.org/docs/binreloc/ for extensive
discussion.

I added support for the /proc/self/exe method a few months ago, but only for Cygwin. I didn't switch Linux to using it because I didn't want to break something that I assumed was working.

All that's really required is a #define change, but the attached patch also uses /proc/self/exe instead of /proc/$$/exe. (/me slaps forehead.)

Sam Bishop

fix-GetMainExecutable-on-Linux.patch (836 Bytes)

Thanks!
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20080623/064256.html