From 30dc6ee97026f393813f0a31f2294ac1d0898c56 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Wed, 28 Sep 2016 16:13:12 +0000 Subject: [PATCH] PR middle-end/77683 - ICE on %lf directive in format_floating in gcc/testsuite/ChangeLog: PR middle-end/77683 * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Add test cases. gcc/ChangeLog: PR middle-end/77683 * gimple-ssa-sprintf.c (format_integer): Fail gracefully when length modifier is not expected. (format_floating): Ignore l length modifier and fail gracefuly when it isn't one of the other expected ones. From-SVN: r240583 --- gcc/ChangeLog | 8 ++++++ gcc/gimple-ssa-sprintf.c | 28 +++++++++++++++++-- gcc/testsuite/ChangeLog | 5 ++++ .../gcc.dg/tree-ssa/builtin-sprintf-warn-1.c | 6 ++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3a1e67645e4..13d0efa79d2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2016-09-28 Martin Sebor + + PR middle-end/77683 + * gimple-ssa-sprintf.c (format_integer): Fail gracefully when + length modifier is not expected. + (format_floating): Ignore l length modifier and fail gracefuly + when it isn't one of the other expected ones. + 2016-09-28 Martin Sebor PR bootstrap/77753 diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c index 2e15149cda0..f7382f10eef 100644 --- a/gcc/gimple-ssa-sprintf.c +++ b/gcc/gimple-ssa-sprintf.c @@ -869,7 +869,14 @@ format_integer (const conversion_spec &spec, tree arg) break; default: - gcc_unreachable (); + { + fmtresult res = fmtresult (); + res.range.min = HOST_WIDE_INT_MAX; + res.range.max = HOST_WIDE_INT_MAX; + res.bounded = false; + res.constant = false; + return res; + } } /* The type of the argument to the directive, either deduced from @@ -1147,6 +1154,7 @@ format_floating (const conversion_spec &spec, int width, int prec) switch (spec.modifier) { + case FMT_LEN_l: case FMT_LEN_none: type = double_type_node; break; @@ -1162,7 +1170,14 @@ format_floating (const conversion_spec &spec, int width, int prec) break; default: - gcc_unreachable (); + { + fmtresult res = fmtresult (); + res.range.min = HOST_WIDE_INT_MAX; + res.range.max = HOST_WIDE_INT_MAX; + res.bounded = false; + res.constant = false; + return res; + } } /* The minimum and maximum number of bytes produced by the directive. */ @@ -1248,7 +1263,14 @@ format_floating (const conversion_spec &spec, int width, int prec) } default: - gcc_unreachable (); + { + fmtresult res = fmtresult (); + res.range.min = HOST_WIDE_INT_MAX; + res.range.max = HOST_WIDE_INT_MAX; + res.bounded = false; + res.constant = false; + return res; + } } if (0 < width) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b942bd65b7f..0980c5483d0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-09-28 Martin Sebor + + PR middle-end/77683 + * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Add test cases. + 2016-09-28 Bernd Edlinger PR c++/77748 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c index e11c2798a2e..3a171893e81 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c @@ -866,6 +866,8 @@ void test_sprintf_chk_z_const (void) void test_sprintf_chk_e_const (void) { T (-1, "%E", 0.0); + T (-1, "%lE", 0.0); + T ( 0, "%E", 0.0); /* { dg-warning "into a region" } */ T ( 0, "%e", 0.0); /* { dg-warning "into a region" } */ T ( 1, "%E", 1.0); /* { dg-warning "into a region" } */ @@ -1076,6 +1078,8 @@ void test_sprintf_chk_int_nonconst (int a) void test_sprintf_chk_e_nonconst (double d) { T (-1, "%E", d); + T (-1, "%lE", d); + T ( 0, "%E", d); /* { dg-warning "writing between 12 and 14 bytes into a region of size 0" } */ T ( 0, "%e", d); /* { dg-warning "into a region" } */ T ( 1, "%E", d); /* { dg-warning "into a region" } */ @@ -1107,6 +1111,8 @@ void test_sprintf_chk_e_nonconst (double d) void test_sprintf_chk_f_nonconst (double d) { T (-1, "%F", d); + T (-1, "%lF", d); + T ( 0, "%F", d); /* { dg-warning "into a region" } */ T ( 0, "%f", d); /* { dg-warning "into a region" } */ T ( 1, "%F", d); /* { dg-warning "into a region" } */ -- 2.30.2