While experimenting with module, I found an annoying bug described at http://llvm.org/bugs/show_bug.cgi?id=16635
In short I have:
1. An precompiled header file that includes the stdio module, and defines an inline function which references 'stderr'.
2. A file that try to use that inline function.
When generating the header file, clang parses the inline function, generates a DeclRefExpr that contains a reference to stderr and set the stderr's Used flag to true, and serialize the DeclRefExpr.
As 'stderr' itself is already part of the stdio module, it is not serialized again, and so the 'Used' flag is not updated.
When compiling the file, clang unserialized the DeclRefExpr with the stderr Decl that come from the stdio module, but does not update the Decl's Used flag.
So at codegen time, clang asserts as it does not like generating code for ununsed Decl.
A simple fix would be to unconditionally mark the referenced Decl as unused when unserializing the DeclRefExpr (see attached patch), but I'm not familiar enough with the 'Used' flag usage to know if this is safe to do that.
Can someone familiar with the matter can tell me if this is the way to go ?
Used.patch (759 Bytes)