diff options
author | Martin Sebor <msebor@redhat.com> | 2021-11-10 11:36:16 -0700 |
---|---|---|
committer | Martin Sebor <msebor@redhat.com> | 2021-11-10 11:39:35 -0700 |
commit | 7c8a416da86c175bcb5fa7b49abf3cf343bc068f (patch) | |
tree | 1c6f46d2c8651049486a6d167f020f41a3284ce2 | |
parent | 1c04af34c9c66d8ed9f6c12c97dd064238ddfa20 (diff) | |
download | gcc-7c8a416da86c175bcb5fa7b49abf3cf343bc068f.zip gcc-7c8a416da86c175bcb5fa7b49abf3cf343bc068f.tar.gz gcc-7c8a416da86c175bcb5fa7b49abf3cf343bc068f.tar.bz2 |
Adjust test to avoid target-specific failures [PR103161].
Resolves:
PR testsuite/103161 - Better ranges cause builtin-sprintf-warn-16.c failure
gcc/testsuite:
PR testsuite/103161
* gcc.dg/tree-ssa/builtin-sprintf-warn-16.c: Avoid relying on
argument evaluation order. Cast width and precision to signed
to avoid undefined behavior.
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-16.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-16.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-16.c index d6cbfe3..f975e16 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-16.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-16.c @@ -130,16 +130,18 @@ void test_width_var (void) { /* Create an unsigned range with a lower bound greater than 1 and - an upper bound in excess of INT_MAX and verify that the lower - bound isn't used as the minimum output (since the excessive - upper bound wraps around zero). It's possible to constrain - the upper bound on the output more, based on the upper bound - of the width here, but not worth the trouble. */ - extern unsigned w; + an upper bound in excess of INT_MAX and verify that after conversion + to signed int the lower bound isn't used as the minimum output (since + the excessive upper bound wraps around zero). Passing the precision + as unsigned, without the cast to signed int, is undedined. + It's possible to constrain the upper bound on the output more, based + on the upper bound of the width here, but not worth the trouble. */ + unsigned w = W (unsigned); if (w < 5 || (unsigned)-1 - 7 < w) w = 5; + int val = V (int); - T ("%*u", w, V (int)); /* { dg-warning "between 1 and 2147483648 " } */ + T ("%*u", (int)w, val); /* { dg-warning "between 1 and 2147483648 " } */ } { @@ -234,13 +236,17 @@ void test_precision_var (void) { /* Similar to the corresponding width case, create an unsigned range with a lower bound greater than 1 and an upper bound in excess of - INT_MAX and verify that the lower bound isn't used as the minimum - output (since the excessive upper bound wraps around zero). */ - extern unsigned p; + INT_MAX and verify that after conversion to int the lower bound isn't + used as the minimum output (since the excessive upper bound wraps + around zero). Passing the precision as unsigned, without a cast to + signed int, is undefined. */ + unsigned p = V (unsigned); if (p < 7 || (unsigned)-1 - 9 < p) p = 7; - T ("%.*u", p, V (int)); /* { dg-warning "up to 2147483647 " } */ + int val = V (int); + + T ("%.*u", (int)p, val); /* { dg-warning "up to 2147483647 " } */ } { |