T ( 3, "%1$c%2$c", '1', '2');
/* Verify that a warning is issued for exceeding INT_MAX bytes and
- not otherwise. */
- T (-1, "%*c", INT_MAX - 1, '1');
- T (-1, "%*c", INT_MAX, '1');
- T (-1, "X%*c", INT_MAX - 1, '1');
- T (-1, "X%*c", INT_MAX, '1'); /* { dg-warning "directive output of \[0-9\]+ bytes causes result to exceed .INT_MAX." } */
-
- 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." } */
-
- T (-1, "%*cX", INT_MAX - 2, '1');
- T (-1, "%*cX", INT_MAX - 1, '1');
- T (-1, "%*cX", INT_MAX, '1'); /* { dg-warning "output of \[0-9\]+ bytes causes result to exceed .INT_MAX." } */
+ 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 } } */
+ 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 } */
+
+ 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 } */
+
+ 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, '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 } */
}
/* Verify that no warning is issued for calls that write into a flexible
/* 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 - 1, "");
- T (-1, "%*s", INT_MAX, "");
- T (-1, "X%*s", INT_MAX, ""); /* { dg-warning "directive output of \[0-9\]+ bytes causes result to exceed .INT_MAX." } */
+ 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, "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 } */
/* Multiple directives. */
/* The two directives below combined convert to [INT_MAX, INT_MAX + 1].
Since the lower end of the range doesn't exceed INT_MAX no warning
- is expected. */
+ is expected in LP64. In ILP32 where the maximum object size is
+ INT_MAX - 1, the call is diagnosed. */
+ 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" } */
+ 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 } */
IR (imax - 5, imax - 3), IR (1, 2), SR (x, y),
IR ( 5, 6), IR (3, 4), SR (x, y));