[cfe-dev] Module and auto include file mapping

Jean-Daniel Dupas devlists at shadowlab.org
Tue Aug 6 14:37:17 PDT 2013


Hello,

While I was playing with the new clang module functionality, I encountered an issue with the 'convert #include in import' feature.

Apparently, when including a file using an absolute path, clang does not try at all to map it to possibly existing included module. It results in some inconsistencies when compiling with and without module enabled.

Take for instance this source file:

------------ include.c

#include "/usr/include/stdio.h"

#include <stdio.h>

-------------------------

Obviously, as the stdio.h file contains include guards, this file compile fine without modules.
But if I enable modules, clang does not figures both includes points to the same files, and so the same module, and it try to import the module, while the stdio.h was already included.
And it result in a rather ugly mess:

$ clang -fsyntax-only -fmodules include.c

usr/include/stdio.h:96:8: error: redefinition of '__sbuf'
struct __sbuf {
       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/stdio.h:86:8: note: previous definition is here
struct __sbuf {
       ^
In file included from include.c:2:
/usr/include/stdio.h:130:16: error: redefinition of '__sFILE'
typedef struct __sFILE {
               ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/stdio.h:120:16: note: previous definition is here
typedef struct __sFILE {
               ^

… and so on, on many lines.

Of course, I don't expect someone write this kind of include, but this is what Xcode and clang synthesize when using prefix headers.
Xcode convert the header path to an absolute path, and pass it to clang using the "-include" parameter.
Then clang interpret the '-include' argument as an #include directive, and try to import the file using the absolute path.

Is this a clang bug, or is it an expected behaviors for the modules ? If this is a bug, I'd be glad to have a look at what is wrong, and propose patches.

-- Jean-Daniel




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130806/39f97428/attachment.html>


More information about the cfe-dev mailing list