r303582 - Give files from #line the characteristics of the current file

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Tue May 23 09:17:11 PDT 2017


Thanks, I added that test case in r303642. I was struggling to identify the
behavior change.

On Mon, May 22, 2017 at 4:37 PM, Richard Smith <richard at metafoo.co.uk>
wrote:

> On 22 May 2017 at 15:22, Reid Kleckner via cfe-commits <
> cfe-commits at lists.llvm.org> wrote:
>
>> On Mon, May 22, 2017 at 3:17 PM, Richard Smith <richard at metafoo.co.uk>
>> wrote:
>>
>>>    // If the StrTok is "eod", then it wasn't present.  Otherwise, it
>>>> must be a
>>>>    // string followed by eod.
>>>> -  if (StrTok.is(tok::eod))
>>>> -    ; // ok
>>>> -  else if (StrTok.isNot(tok::string_literal)) {
>>>> +  if (StrTok.is(tok::eod)) {
>>>> +    // Treat this like "#line NN", which doesn't change file
>>>> characteristics.
>>>> +    FileKind = SourceMgr.getFileCharacteristi
>>>> c(DigitTok.getLocation());
>>>>
>>>
>>> This change for "# <number>" handling makes sense (and I've checked and
>>> it matches GCC), but it looks like we don't have test coverage for either
>>> the old or new behavior. Can I interest you in adding some? :)
>>>
>>
>> We do have coverage for it, see test/Preprocessor/line-directive.c:
>> """
>> # 192 "glomp.h" 3 // System header.
>> typedef int y;  // ok
>> typedef int y;  // ok
>>
>> typedef int q;  // q is in system header.
>>
>> #line 42 "blonk.h"  // doesn't change system headerness.
>>
>> typedef int z;  // ok
>> typedef int z;  // ok
>>
>> # 97     // doesn't change system headerness.
>>
>> typedef int z1;  // ok
>> typedef int z1;  // ok
>> """
>>
>> We were just getting similar behavior because of the code I removed that
>> sends us to the #line directive handling when the filename isn't present.
>>
>
> Ah, I see. It looks like, prior to your change, we got self-inconsistent
> results. "# <number>" worked properly when compiling (and we do have
> coverage for that, per the above test), but not when preprocessing (for
> which we don't have test coverage). So for instance, this input:
>
> # 1 "foo" 3
> # 2
> x
>
> preprocesses as
>
> # 1 "foo" 3
> # 2 "foo"
> x
>
> before your change and as
>
> # 1 "foo" 3
> # 2 "foo" 3
> x
>
> after your change.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170523/bf77428e/attachment.html>


More information about the cfe-commits mailing list