https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80364

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-invalid-code
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot 
gnu.org

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
The get_int_range function is only meant to be used for printf arguments of
type int after promotion (width and precision specified by the asterisk, and
wint_t argument to %lc).  The test case in pr72858.c that triggers the
sanitizer error is invalid (with undefined behavior) because it passes in an
argument of type long.  A test case that passes in a __int128_t triggers an ICE
(below).  Arguments of non-integer types are ignored.  Let me correct the
handling to avoid these two problems.

$ cat a.c && gcc -O2 -S -Wall -Wextra -Wpedantic a.c
void f (__int128_t x)
{
  extern char d[3];
  __builtin_sprintf (d, "%*d", x, 1);
}

a.c: In function ‘f’:
a.c:4:27: warning: field width specifier ‘*’ expects argument of type ‘int’,
but argument 3 has type ‘__int128’ [-Wformat=]
   __builtin_sprintf (d, "%*d", x, 1);
                          ~^~
a.c:1:6: internal compiler error: in tree_to_shwi, at tree.c:7333
 void f (__int128_t x)
      ^
0x10b13cd tree_to_shwi(tree_node const*)
        /ssd/src/gcc/git-svn/gcc/tree.c:7333
0x16e8692 get_int_range
        /ssd/src/gcc/git-svn/gcc/gimple-ssa-sprintf.c:946
0x16e8865 get_int_range
        /ssd/src/gcc/git-svn/gcc/gimple-ssa-sprintf.c:995
0x16e7f3d set_width
        /ssd/src/gcc/git-svn/gcc/gimple-ssa-sprintf.c:677
0x16ed310 parse_directive
        /ssd/src/gcc/git-svn/gcc/gimple-ssa-sprintf.c:3129
0x16ed753 compute_format_length
        /ssd/src/gcc/git-svn/gcc/gimple-ssa-sprintf.c:3239
0x16ee60a handle_gimple_call
        /ssd/src/gcc/git-svn/gcc/gimple-ssa-sprintf.c:3671
0x16ee70d execute
        /ssd/src/gcc/git-svn/gcc/gimple-ssa-sprintf.c:3699
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Reply via email to