* parse-datetime.y reports integer overflow when compiled with gcc 5.5.0
@ 2021-01-08 14:37 Sergey Poznyakoff
2021-01-08 21:49 ` Bruno Haible
0 siblings, 1 reply; 3+ messages in thread
From: Sergey Poznyakoff @ 2021-01-08 14:37 UTC (permalink / raw)
To: bug-gnulib
Hello,
With recent gnulib (v0.1-4336-gbdae9a5), attempting to compile
parse-datetime.c fails with:
$ make -k parse-datetime.o V=1
gcc -DHAVE_CONFIG_H -I. -I.. -Wall -ggdb -MT parse-datetime.o -MD -MP -MF .deps/parse-datetime.Tpo -c -o parse-datetime.o parse-datetime.c
In file included from parse-datetime.y:39:0:
parse-datetime.y: In function 'to_tm_year':
intprops.h:578:17: warning: integer overflow in expression [-Woverflow]
|| (tmax) + (b) < (a)))
^
intprops.h:524:4: note: in expansion of macro '_GL_INT_SUBTRACT_RANGE_OVERFLOW'
(overflow (a, b, tmin, tmax) \
^
intprops.h:491:10: note: in expansion of macro '_GL_INT_OP_CALC'
? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
^
intprops.h:389:4: note: in expansion of macro '_GL_INT_OP_WRAPV'
_GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW)
^
parse-datetime.y:1274:9: note: in expansion of macro 'INT_SUBTRACT_WRAPV'
: INT_SUBTRACT_WRAPV (year, TM_YEAR_BASE, tm_year))
^
parse-datetime.y: In function 'yylex':
intprops.h:578:17: warning: integer overflow in expression [-Woverflow]
|| (tmax) + (b) < (a)))
^
intprops.h:524:4: note: in expansion of macro '_GL_INT_SUBTRACT_RANGE_OVERFLOW'
(overflow (a, b, tmin, tmax) \
^
intprops.h:500:11: note: in expansion of macro '_GL_INT_OP_CALC'
? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
^
intprops.h:495:7: note: in expansion of macro '_GL_INT_OP_WRAPV_LONGISH'
: _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow))
^
intprops.h:389:4: note: in expansion of macro '_GL_INT_OP_WRAPV'
_GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW)
^
parse-datetime.y:1469:23: note: in expansion of macro 'INT_SUBTRACT_WRAPV'
if (INT_SUBTRACT_WRAPV (s, 1, &s))
^
Bisecting shows that the bug was introduced by commit 55168f5fa7b3b95fbaa2be525b15f6ecd5500c02
Regards,
Sergey
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: parse-datetime.y reports integer overflow when compiled with gcc 5.5.0
2021-01-08 14:37 parse-datetime.y reports integer overflow when compiled with gcc 5.5.0 Sergey Poznyakoff
@ 2021-01-08 21:49 ` Bruno Haible
2021-01-08 22:00 ` Paul Eggert
0 siblings, 1 reply; 3+ messages in thread
From: Bruno Haible @ 2021-01-08 21:49 UTC (permalink / raw)
To: bug-gnulib
Sergey Poznyakoff wrote:
> With recent gnulib (v0.1-4336-gbdae9a5), attempting to compile
> parse-datetime.c fails with:
>
> $ make -k parse-datetime.o V=1
> gcc -DHAVE_CONFIG_H -I. -I.. -Wall -ggdb -MT parse-datetime.o -MD -MP -MF .deps/parse-datetime.Tpo -c -o parse-datetime.o parse-datetime.c
> In file included from parse-datetime.y:39:0:
> parse-datetime.y: In function 'to_tm_year':
> intprops.h:578:17: warning: integer overflow in expression [-Woverflow]
> || (tmax) + (b) < (a)))
> ^
> intprops.h:524:4: note: in expansion of macro '_GL_INT_SUBTRACT_RANGE_OVERFLOW'
> (overflow (a, b, tmin, tmax) \
> ^
> intprops.h:491:10: note: in expansion of macro '_GL_INT_OP_CALC'
> ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
> ^
> intprops.h:389:4: note: in expansion of macro '_GL_INT_OP_WRAPV'
> _GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW)
> ^
> parse-datetime.y:1274:9: note: in expansion of macro 'INT_SUBTRACT_WRAPV'
> : INT_SUBTRACT_WRAPV (year, TM_YEAR_BASE, tm_year))
> ^
> parse-datetime.y: In function 'yylex':
> intprops.h:578:17: warning: integer overflow in expression [-Woverflow]
> || (tmax) + (b) < (a)))
> ^
> intprops.h:524:4: note: in expansion of macro '_GL_INT_SUBTRACT_RANGE_OVERFLOW'
> (overflow (a, b, tmin, tmax) \
> ^
> intprops.h:500:11: note: in expansion of macro '_GL_INT_OP_CALC'
> ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
> ^
> intprops.h:495:7: note: in expansion of macro '_GL_INT_OP_WRAPV_LONGISH'
> : _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow))
> ^
> intprops.h:389:4: note: in expansion of macro '_GL_INT_OP_WRAPV'
> _GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW)
> ^
> parse-datetime.y:1469:23: note: in expansion of macro 'INT_SUBTRACT_WRAPV'
> if (INT_SUBTRACT_WRAPV (s, 1, &s))
> ^
The compilation doesn't fail; it merely shows warning.
When I modify intprops.h to behave the same for all GCC versions as for GCC 5.x,
I see:
* The warning is there for all GCC versions < 10, but is fixed in GCC 10.2.0.
* GCC 9.3.0 has more details:
In file included from parse-datetime.y:39:
parse-datetime.y: In function 'to_tm_year':
intprops.h:576:17: warning: integer overflow in expression of type 'int' results in '-2147481749' [-Woverflow]
576 | || (tmax) + (b) < (a)))
| ^
intprops.h:522:4: note: in expansion of macro '_GL_INT_SUBTRACT_RANGE_OVERFLOW'
522 | (overflow (a, b, tmin, tmax) \
| ^~~~~~~~
intprops.h:489:10: note: in expansion of macro '_GL_INT_OP_CALC'
489 | ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
| ^~~~~~~~~~~~~~~
intprops.h:389:4: note: in expansion of macro '_GL_INT_OP_WRAPV'
389 | _GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW)
| ^~~~~~~~~~~~~~~~
parse-datetime.y:1274:9: note: in expansion of macro 'INT_SUBTRACT_WRAPV'
1274 | : INT_SUBTRACT_WRAPV (year, TM_YEAR_BASE, tm_year))
| ^~~~~~~~~~~~~~~~~~
parse-datetime.y: In function 'yylex':
intprops.h:576:17: warning: integer overflow in expression of type 'long int' results in '-9223372036854775808' [-Woverflow]
576 | || (tmax) + (b) < (a)))
| ^
intprops.h:522:4: note: in expansion of macro '_GL_INT_SUBTRACT_RANGE_OVERFLOW'
522 | (overflow (a, b, tmin, tmax) \
| ^~~~~~~~
intprops.h:498:11: note: in expansion of macro '_GL_INT_OP_CALC'
498 | ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
| ^~~~~~~~~~~~~~~
intprops.h:493:7: note: in expansion of macro '_GL_INT_OP_WRAPV_LONGISH'
493 | : _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow))
| ^~~~~~~~~~~~~~~~~~~~~~~~
intprops.h:389:4: note: in expansion of macro '_GL_INT_OP_WRAPV'
389 | _GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW)
| ^~~~~~~~~~~~~~~~
parse-datetime.y:1469:23: note: in expansion of macro 'INT_SUBTRACT_WRAPV'
1469 | if (INT_SUBTRACT_WRAPV (s, 1, &s))
| ^~~~~~~~~~~~~~~~~~
So, the problem is a signed-integer overflow of constants in a dead
(unreachable) code branch.
Bruno
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: parse-datetime.y reports integer overflow when compiled with gcc 5.5.0
2021-01-08 21:49 ` Bruno Haible
@ 2021-01-08 22:00 ` Paul Eggert
0 siblings, 0 replies; 3+ messages in thread
From: Paul Eggert @ 2021-01-08 22:00 UTC (permalink / raw)
To: Bruno Haible; +Cc: bug-gnulib
On 1/8/21 1:49 PM, Bruno Haible wrote:
> So, the problem is a signed-integer overflow of constants in a dead
> (unreachable) code branch.
Yes, I get many warnings like that in Oracle Developer Studio too, with
some of the Gnulib tests. Either ignore the warnings, or don't use
-Woverflow, or (as we did with GCC) get your compiler fixed.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-08 22:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-08 14:37 parse-datetime.y reports integer overflow when compiled with gcc 5.5.0 Sergey Poznyakoff
2021-01-08 21:49 ` Bruno Haible
2021-01-08 22:00 ` Paul Eggert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).