File: Wstringop-overflow-79.c

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (70 lines) | stat: -rw-r--r-- 2,884 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Verify that a separate note is issued for each offset into the same
   object after a -Wstringop-overflow.  Since all arguments are known
   the test doesn't need optimization.  Wstringop-overflow-79.c verifies
   they're also issued at -O2.
   { dg-do compile }
   { dg-options "-O0 -Wno-array-bounds" } */

extern char a[8];                 // dg-message at offset \\\[3, 6] into destination object 'a'" "note 1" }
                                  // dg-message at offset \\\[5, 8] into destination object 'a'" "note 2" { target *-*-* } .-1 }

void test_2_notes (int i)
{
  char *p = i ? a + 3 : a + 5;
  __builtin_memset (p, 0, 7);     // { dg-warning "-Wstringop-overflow" }
}


extern char b[8];                 // dg-message at offset \\\[3, 6] into destination object 'b'" "note 1" }
                                  // dg-message at offset \\\[4, 7] into destination object 'b'" "note 2" { target *-*-* } .-1 }
                                  // dg-message at offset \\\[5, 8] into destination object 'b'" "note 3" { target *-*-* } .-2 }

void test_3_notes (int i)
{
  char *p = i < 0 ? b + 3 : 0 < i ? b + 5 : b + 4;
  __builtin_memset (p, 0, 7);     // { dg-warning "-Wstringop-overflow" }
}


extern char c[8];                 // dg-message at offset \\\[3, 6] into destination object 'c'" "note 1" }
                                  // dg-message at offset \\\[4, 7] into destination object 'c'" "note 2" { target *-*-* } .-1 }
                                  // dg-message at offset \\\[5, 8] into destination object 'c'" "note 3" { target *-*-* } .-2 }
                                  // dg-message at offset \\\[6, 8] into destination object 'c'" "note 3" { target *-*-* } .-2 }

void test_4_notes (int i)
{
  char *p;
  if (i < -1)
    p = c + 3;
  else if (i < 0)
    p = c + 4;
  else if (0 < i)
    p = c + 6;
  else
    p = c + 5;

  __builtin_memset (p, 0, 7);     // { dg-warning "-Wstringop-overflow" }
}


extern char d[8];                 // dg-message at offset \\\[3, 6] into destination object 'd'" "note 1" }
                                  // dg-message at offset \\\[4, 7] into destination object 'd'" "note 2" { target *-*-* } .-1 }
                                  // dg-message at offset \\\[5, 8] into destination object 'd'" "note 3" { target *-*-* } .-2 }
                                  // dg-message at offset \\\[6, 8] into destination object 'd'" "note 3" { target *-*-* } .-3 }
                                  // dg-message at offset \\\[7, 8] into destination object 'd'" "note 3" { target *-*-* } .-4 }

void test_5_notes (int i)
{
  char *p;
  switch (i)
    {
    case -9: p = d + 3; break;
    case -5: p = d + 4; break;
    case  0: p = d + 5; break;
    case  3: p = d + 6; break;
    case  4: p = d + 7; break;
    default: return;
    }

  __builtin_memset (p, 0, 7);     // { dg-warning "-Wstringop-overflow" }
}