[PATCH] Do not use "1" in linemarker for main file in -frewrite-includes

Lubos Lunak l.lunak at centrum.cz
Thu May 1 07:47:13 PDT 2014


On Sunday 13 of April 2014, Richard Smith wrote:
> The check for MainFileID and accompanying test LGTM.
>
> Can you explain what the check for PredefinesFileID is for?

 Without that check, the output can look e.g. like this:
=====
# 1 "<built-in>" 1 
# 1 "a.cpp" 
void f() {} 
=====

 Which is wrong. Only now that I look at it, what's wrong is rather that 
there's no closing "2" linemarker for <built-in>.

 So how about this attached patch (on top of the previous one that had the 
predefines check removed)?

> AFAICS, there's 
> no test for that part of the change, and I'm concerned that we could end up
> attributing lines in that FileID to some other file.

 The patch includes a test specifically for the predefines file, although that 
theoretically shouldn't be necessary, since there's no output from the 
predefines file anyway (OutputContentUpTo() skips it).

> On Fri, Apr 4, 2014 at 3:09 AM, Lubos Lunak <l.lunak at centrum.cz> wrote:
> >  The -frewrite-includes flag incorrectly uses at the beginning a
> > linemarker for the main file with the "1" flag which suggests that the
> > contents have been in fact included from another file. This for example
> > disables -Wunused-macros, which warns only for macros from the main file:
> >
> > $ cat a.cpp
> > #define FOO 1
> > $ clang++ -E -frewrite-includes a.cpp | clang++ -Wall -Wunused-macros -x
> > c++ -c -
> > $ clang++ -Wall -Wunused-macros -c a.cpp
> > a.cpp:1:9: warning: macro is not used [-Wunused-macros]
> > #define FOO 1
> >         ^
> > 1 warning generated.
> >
> >  The attached patch fixes the code to start the resulting file with the
> > correct linemarker.

-- 
 Lubos Lunak
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-do-not-use-1-for-line-marker-for-the-predefines-file.patch
Type: text/x-diff
Size: 2402 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140501/363d58ce/attachment.patch>


More information about the cfe-commits mailing list