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

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon May 22 16:37:47 PDT 2017


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.getFileCharacteristic(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/20170522/509af5f2/attachment.html>


More information about the cfe-commits mailing list