tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] __LINE__ and #line undelying type


From: Vincent Lefevre
Subject: Re: [Tinycc-devel] __LINE__ and #line undelying type
Date: Fri, 16 Apr 2021 16:44:35 +0200
User-agent: Mutt/2.0.6+148 (869c6cc4) vl-132933 (2021-04-10)

On 2021-04-16 14:52:50 +0100, Edmund Grimley Evans wrote:
> Riddle me this:
> 
> $ gcc --version | head -n 1
> gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
> $ printf '#line 60129542143\n__LINE__' | gcc -E - | grep -v ^#
> 4294967295
> $ printf '#line 60129542144\n__LINE__' | gcc -E - | grep -v ^#
> <stdin>:1:7: warning: line number out of range
> 0
> $ gdb
> (gdb) p/x 60129542143
> $1 = 0xdffffffff
> (gdb)

Well, providing a #line value larger than the maximum allowed by
the C standard is undefined behavior, and a diagnostic is not
required because this is not a constraint here. But here, this
is probably a bug in GCC.

$ printf '#line 4294967296\n__LINE__' | gcc -E - | grep -v "^#"
<stdin>:1:7: warning: line number out of range
0
$ printf '#line 8589934591\n__LINE__' | gcc -E - | grep -v "^#"
4294967295
$ printf '#line 8589934592\n__LINE__' | gcc -E - | grep -v "^#"
<stdin>:1:7: warning: line number out of range
0

I suspect that some bound test may be wrong. For instance, it
correctly detects the issue when converted to int, it gives a
nonnegative value, but not for negative values (and the output
seems to be done with an unsigned int).

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]