From 5106ff7e6095a281de4c4eead6a3a69a7c59f882 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Wed, 2 Dec 2020 17:29:59 -0700 Subject: [PATCH] Adjust tests even more to avoid ILP32 failures after r11-5622 (PR middle-end/97373) gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Adjust expected warnings to correctly reflect the maximum object size. * gcc.dg/tree-ssa/builtin-sprintf-warn-11.c: Same. * gcc.dg/tree-ssa/builtin-sprintf-warn-18.c: Same. --- .../gcc.dg/tree-ssa/builtin-sprintf-warn-1.c | 30 ++++++++----------- .../gcc.dg/tree-ssa/builtin-sprintf-warn-11.c | 18 +++++------ .../gcc.dg/tree-ssa/builtin-sprintf-warn-18.c | 8 ++--- 3 files changed, 25 insertions(+), 31 deletions(-) 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 3d238c4c3ed..0cc03ff2de8 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 @@ -112,24 +112,21 @@ void test_sprintf_c_const (void) T ( 3, "%1$c%2$c", '1', '2'); /* Verify that a warning is issued for exceeding INT_MAX bytes and - not otherwise. In ILP32 where the maximum object size is INT_MAX - 1 - bytes, the calls are diagnosed due to the overflow. */ - T (-1, "%*c", INT_MAX - 2, '1'); - T (-1, "%*c", INT_MAX - 1, '1'); /* { dg-warning "writing a terminating nul past the end" "ilp32" { target ilp32 } } */ - T (-1, "%*c", INT_MAX, '1'); /* { dg-warning "writing 2147483647 bytes into a region of size 2147483646" "il32" { target ilp32 } } */ - T (-1, "X%*c", INT_MAX - 3, '1'); - T (-1, "X%*c", INT_MAX - 1, '1'); /* { dg-warning "writing 2147483646 bytes into a region of size 2147483645" "ilp32" { target ilp32 } } */ + not otherwise. In ILP32 the maximum object size is INT_MAX - 1 + bytes so the calls are diagnosed due to the overflow. */ + T (-1, "%*c", INT_MAX - 1, '1'); + T (-1, "%*c", INT_MAX, '1'); /* { dg-warning "writing a terminating nul past the end " "ilp32" { target ilp32 } } */ + T (-1, "X%*c", INT_MAX - 1, '1'); /* { dg-warning "writing a terminating nul past the end " "ilp32" { target ilp32 } } */ T (-1, "X%*c", INT_MAX, '1'); /* { dg-warning "directive output of \[0-9\]+ bytes causes result to exceed .INT_MAX." "lp64" { target lp64 } } */ - /* { dg-warning "directive writing 2147483647 bytes into a region of size 2147483645." "lp32" { target ilp32 } .-1 } */ + /* { dg-warning "directive writing 2147483647 bytes into a region of size 2147483646" "ilp32" { target ilp32 } .-1 } */ T (-1, "%*c%*c", INT_MAX - 1, '1', INT_MAX - 1, '2'); /* { dg-warning "directive output of \[0-9\]+ bytes causes result to exceed .INT_MAX." "lp64" { target lp64 } } */ - /* { dg-warning "directive writing 2147483646 bytes into a region of size 0" "ilp32" { target ilp32 } .-1 } */ + /* { dg-warning "directive writing 2147483646 bytes into a region of size 1" "ilp32" { target ilp32 } .-1 } */ - T (-1, "%*cX", INT_MAX - 3, '1'); - T (-1, "%*cX", INT_MAX - 2, '1'); /* { dg-warning "writing a terminating nul past the end of the destination" "ilp32" { target ilp32} } */ - T (-1, "%*cX", INT_MAX - 1, '1'); /* { dg-warning "'X' directive writing 1 byte into a region of size 0" "ilp32" { target ilp32 } } */ + T (-1, "%*cX", INT_MAX - 2, '1'); + T (-1, "%*cX", INT_MAX - 1, '1'); /* { dg-warning "writing a terminating nul past the end of the destination" "ilp32" { target ilp32 } } */ T (-1, "%*cX", INT_MAX, '1'); /* { dg-warning "output of \[0-9\]+ bytes causes result to exceed .INT_MAX." "lp64" { target lp64 } } */ - /* { dg-warning "directive writing 2147483647 bytes into a region of size 2147483646" "ilp32" { target ilp32 } .-1 } */ + /* { dg-warning "directive writing 1 byte into a region of size 0" "ilp32" { target ilp32 } .-1 } */ } /* Verify that no warning is issued for calls that write into a flexible @@ -294,11 +291,10 @@ void test_sprintf_chk_s_const (void) /* Verify that output in excess of INT_MAX bytes is diagnosed even when the size of the destination object is unknown. */ - T (-1, "%*s", INT_MAX - 2, ""); - T (-1, "%*s", INT_MAX - 1, ""); /* { dg-warning "writing a terminating nul past the end of the destination" "ilp32" { target ilp32 } } */ - T (-1, "%*s", INT_MAX, ""); /* { dg-warning "directive writing 2147483647 bytes into a region of size 2147483646" "ilp32" { target ilp32 } } */ + T (-1, "%*s", INT_MAX - 1, ""); + T (-1, "%*s", INT_MAX, ""); /* { dg-warning "writing a terminating nul past the end" "ilp32" { target ilp32 } } */ T (-1, "X%*s", INT_MAX, ""); /* { dg-warning "directive output of \[0-9\]+ bytes causes result to exceed .INT_MAX." "lp64" { target lp64 } } */ - /* { dg-warning "directive writing 2147483647 bytes into a region of size 2147483645" "ilp32" { target ilp32 } .-1 } */ + /* { dg-warning "directive writing 2147483647 bytes into a region of size 2147483646" "ilp32" { target ilp32 } .-1 } */ /* Multiple directives. */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-11.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-11.c index 22f286dc818..134967d54ca 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-11.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-11.c @@ -197,23 +197,21 @@ void test_narrow_string_with_width_and_precision (void) IR (imax / 9, imax / 8), IR (imax / 7, imax / 6), SR (x, y), IR (imax / 5, imax / 4), IR (imax / 3, imax / 2), SR (x, y)); - /* The two directives below combined convert to [INT_MAX, INT_MAX + 1]. + /* The two directives below combined convert to [INT_MAX -1, INT_MAX + 1]. Since the lower end of the range doesn't exceed INT_MAX no warning - is expected in LP64. In ILP32 where the maximum object size is - INT_MAX - 1, the call is diagnosed. */ + is expected. */ T (-1, "%*.*s%*.*s", IR (imax - 6, imax - 3), IR (1, 2), SR (x, y), - IR ( 4, 6), IR (3, 4), SR (x, y)); - T (-1, "%*.*s%*.*s", - IR (imax - 5, imax - 3), IR (1, 2), SR (x, y), IR ( 5, 6), IR (3, 4), SR (x, y)); - /* { dg-warning "directive writing between 5 and 6 bytes into a region of size between 2 and 4" "ilp32" { target ilp32 } .-3 } */ /* The three directives below (the two %s plus the space in between) combined convert to [INT_MAX + 1, INT_MAX + 2]. Since the lower - end of the range exceeds INT_MAX a warning is expected. */ - T (-1, "%*.*s %*.*s", /* { dg-warning "INT_MAX" "lp64" { target lp64 } } */ - /* { dg-warning "directive writing between 5 and 6 bytes into a region of size between 1 and 3" "ilp32" { target ilp32 } .-1 } */ + end of the range exceeds INT_MAX a warning is expected. In ILP32, + the output overflows the maximum object size. */ + T (-1, "%*.*s %*.*s", + /* { dg-warning "INT_MAX" "LP64" { target lp64 } .-1 } + { dg-warning "directive writing between 5 and 6 bytes into a region of size between 2 and 4" "ILP32" { target ilp32 } .-2 } + */ IR (imax - 5, imax - 3), IR (1, 2), SR (x, y), IR ( 5, 6), IR (3, 4), SR (x, y)); diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-18.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-18.c index d30775dc62d..2c410b1414c 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-18.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-18.c @@ -117,10 +117,10 @@ void test_width_and_precision_out_of_range (char *d) { /* The range here happens to be a property of the compiler, not one of the target. */ - T ("%9223372036854775808i", 0); /* { dg-warning "width out of range" "first" } */ - /* { dg-warning "directive writing \\d+ bytes into a region of size \\d+" "second" { target *-*-* } .-1 } */ - T ("%.9223372036854775808i", 0); /* { dg-warning "precision out of range" "first" } */ - /* { dg-warning "directive writing \\d+ bytes into a region of size \\d+" "second" { target *-*-* } .-1 } */ + T ("%9223372036854775808i", 0); /* { dg-warning "width out of range|exceeds 'INT_MAX'" "first" } */ + /* { dg-warning "directive writing \\d+ bytes into a region of size \\d+" "" { target ilp32 } .-1 } */ + T ("%.9223372036854775808i", 0); /* { dg-warning "precision out of range|exceeds 'INT_MAX'" "first" } */ + /* { dg-warning "directive writing \\d+ bytes into a region of size \\d+" "ilp32" { target ilp32 } .-1 } */ /* The following is diagnosed by -Wformat (disabled here). */ /* T ("%9223372036854775808$i", 0); */ -- 2.30.2