1 /* PR tree-optimization/84468 - Inconsistent -Wstringop-truncation warnings
4 { dg-options "-O2 -Wstringop-truncation -ftrack-macro-expansion=0 -g" } */
6 #define strncpy __builtin_strncpy
13 void no_pred_succ_lit (struct A
*p
)
15 /* The following is folded early on, before the strncpy statement
16 has a basic block. Verify that the case is handled gracefully
17 (i.e., there's no assumption that the statement does have
19 strncpy (p
->a
, "1234", sizeof p
->a
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
22 /* Verify a strncpy call in a basic block with no predecessor or
24 void no_pred_succ (struct A
*p
, const struct A
*q
)
26 strncpy (p
->a
, q
->a
, sizeof p
->a
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
30 /* Verify a strncpy call in a basic block with no successor. */
31 void no_succ (struct A
*p
, const struct A
*q
)
34 strncpy (p
->a
, q
->a
, sizeof p
->a
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
37 /* Verify a strncpy call in a basic block with nul assignment in
39 void succ (struct A
*p
, const struct A
*q
)
41 /* Verify that the assignment suppresses the warning for the conditional
42 strcnpy call. The conditional should be folded to true since the
43 address of an array can never be null (see bug 84470). */
45 strncpy (p
->a
, q
->a
, sizeof p
->a
- 1); /* { dg-bogus "\\\[-Wstringop-truncation" } */
47 p
->a
[sizeof p
->a
- 1] = 0;
51 void succ_2 (struct A
*p
, const struct A
*q
, int i
)
53 /* Same as above but with a conditional that cannot be eliminated. */
55 strncpy (p
->a
, q
->a
, sizeof p
->a
- 1); /* { dg-bogus "\\\[-Wstringop-truncation" } */
57 p
->a
[sizeof p
->a
- 1] = 0;
61 /* Verify a strncpy call in a basic block with nul assignment in
62 the next successor block. */
63 int next_succ (struct A
*p
, const struct A
*q
, int i
, int j
)
65 /* Same as above but with a nested conditionals with else clauses. */
69 strncpy (p
->a
, q
->a
, sizeof p
->a
- 1); /* { dg-bogus "\\\[-Wstringop-truncation" } */
72 __builtin_strcpy (p
->a
, q
->a
);
74 p
->a
[sizeof p
->a
- 1] = 0;
79 int next_succ_1 (struct A
*p
, const struct A
*q
, int i
, int j
)
81 /* Same as above but with a nested conditionals with else clauses. */
85 strncpy (p
->a
, q
->a
, sizeof p
->a
- 1); /* { dg-bogus "\\\[-Wstringop-truncation" } */
87 strncpy (p
->a
, q
->a
, sizeof p
->a
- 2); /* { dg-bogus "\\\[-Wstringop-truncation" } */
90 p
->a
[sizeof p
->a
- 2] = 0;
95 int next_succ_2 (struct A
*p
, const struct A
*q
, int i
, int j
)
97 /* Same as above but with a nested conditionals with else clauses. */
101 strncpy (p
->a
, q
->a
, sizeof p
->a
- 1); /* { dg-bogus "\\\[-Wstringop-truncation" } */
103 strncpy (p
->a
, q
->a
, sizeof p
->a
- 2); /* { dg-bogus "\\\[-Wstringop-truncation" } */
106 __builtin_strcpy (p
->a
, q
->a
);
108 p
->a
[sizeof p
->a
- 2] = 0;
113 void cond_succ_warn (struct A
*p
, const struct A
*q
, int i
)
115 /* Verify that a conditional assignment doesn't suppress the warning. */
116 strncpy (p
->a
, q
->a
, sizeof p
->a
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
119 p
->a
[sizeof p
->a
- 1] = 0;
122 void cond_succ_nowarn (struct A
*p
, const struct A
*q
)
124 /* Verify that distinct but provably equivalent conditionals are
125 recognized and don't trigger the warning. */
127 strncpy (p
->a
, q
->a
, sizeof p
->a
- 1);
130 p
->a
[sizeof p
->a
- 1] = 0;