Fix warning with -Wsign-compare -Wsystem-headers
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / pr79691.c
blobbf889318c063da46347e9c72e197d7f9caa1a849
1 /* PR tree-optimization/79691 - -Wformat-truncation suppressed by
2 (and only by) -Og
4 { dg-do compile }
5 { dg-options "-Og -Wall -fdump-tree-optimized" } */
7 char d[2];
9 /* Verify -Wformat-overflow works. */
10 void f1 (void)
12 __builtin_sprintf (d, "%i", 123); /* { dg-warning "directive writing 3 bytes" } */
15 /* Verify -Wformat-truncation works. */
16 void f2 (void)
18 __builtin_snprintf (d, sizeof d, "%i", 1234); /* { dg-warning "output truncated writing 4 bytes" } */
21 /* Verify -fprintf-return-value works. */
22 int f3 (void)
24 return __builtin_snprintf (0, 0, "%i", 12345);
27 /* Verify -fprintf-return-value results used for constant propagation. */
28 int f4 (int i)
30 int n1 = __builtin_snprintf (0, 0, "%i", 1234);
31 int n2 = __builtin_snprintf (0, 0, "%i", 12345);
32 return n1 + n2;
35 /* { dg-final { scan-tree-dump-times "sprintf" 1 "optimized" } }
36 { dg-final { scan-tree-dump-times "snprintf" 1 "optimized" } }
37 { dg-final { scan-tree-dump " = 9;" "optimized" } } */