[PATCH] Avoid lexer crash with -frewrite-includes

Alp Toker alp at nuanti.com
Thu Nov 28 00:30:44 PST 2013

#include "rewrite-includes-bom.h"#endif /* expanded by -frewrite-includes */

On 27/11/2013 18:24, Lubos Lunak wrote:
>   As discussed in " [PATCH] PR14795 : -frewrite-includes sometimes results in
> incorrect line number", the following leads to a crash:

I don't see a crash mentioned in PR14795. Wrong bug?

> $ echo -ne '#if 0\n#endif' >a.cpp
> $ clang++ -frewrite-includes -E a.cpp
>   The attached patch adds a trivial fix avoiding the problem. I'm not quite
> sure why the problem happens, but presumably it has something to do with the
> lexing not being driven by the preprocessor instance (so maybe that one gets
> deleted when reaching EOF?).

Raw lexers don't have a PP, so the check was obviously missing and this 
is a good crash fix.

Be aware however that with this change, you'll get invalid expansions like:

#include "rewrite-includes-bom.h"#endif /* expanded by -frewrite-includes */

Unless this is expected behaviour, you'll need to add special handling 
for end-of-directive in the include rewriter.


> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

the browser experts

More information about the cfe-commits mailing list