[cfe-dev] Module and auto include file mapping

Richard Smith richard at metafoo.co.uk
Tue Aug 6 15:41:03 PDT 2013


On Tue, Aug 6, 2013 at 2:37 PM, Jean-Daniel Dupas <devlists at shadowlab.org>wrote:

> 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.
>

This is sort of expected. We look for the module.map file in the base of
the include path where the header was found (the path given to -I or
-isystem). If you give an absolute path, then there is no such path.


> 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
>
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130806/1caa5de7/attachment.html>


More information about the cfe-dev mailing list