[RISC-V] Avoid unnecessary extensions when value is already extended
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / out-of-bounds-write-int-arr.c
blobc6c0435cf58392170406e94a82541cce30aa6f68
1 #include <stdint.h>
3 int32_t arr[10]; /* { dg-message "capacity: 40 bytes" } */
5 void int_arr_write_element_before_start_far(int32_t x)
7 arr[-100] = x; /* { dg-warning "buffer underwrite" "warning" } */
8 /* { dg-message "out-of-bounds write from byte -400 till byte -397 but 'arr' starts at byte 0" "final event" { target *-*-* } .-1 } */
9 /* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } .-2 } */
12 void int_arr_write_element_before_start_near(int32_t x)
14 arr[-2] = x; /* { dg-warning "buffer underwrite" "warning" } */
15 /* { dg-message "out-of-bounds write from byte -8 till byte -5 but 'arr' starts at byte 0" "final event" { target *-*-* } .-1 } */
16 /* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } .-2 } */
19 void int_arr_write_element_before_start_off_by_one(int32_t x)
21 arr[-1] = x; /* { dg-warning "buffer underwrite" "warning" } */
22 /* { dg-message "out-of-bounds write from byte -4 till byte -1 but 'arr' starts at byte 0" "final event" { target *-*-* } .-1 } */
23 /* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } .-2 } */
26 void int_arr_write_element_at_start(int32_t x)
28 arr[0] = x;
31 void int_arr_write_element_at_end(int32_t x)
33 arr[9] = x;
36 void int_arr_write_element_after_end_off_by_one(int32_t x)
38 arr[10] = x; /* { dg-warning "buffer overflow" "warning" } */
39 /* { dg-message "out-of-bounds write from byte 40 till byte 43 but 'arr' ends at byte 40" "final event" { target *-*-* } .-1 } */
40 /* { dg-message "write of 4 bytes to beyond the end of 'arr'" "num bad bytes note" { target *-*-* } .-2 } */
41 /* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } .-3 } */
44 void int_arr_write_element_after_end_near(int32_t x)
46 arr[11] = x; /* { dg-warning "buffer overflow" "warning" } */
47 /* { dg-message "out-of-bounds write from byte 44 till byte 47 but 'arr' ends at byte 40" "final event" { target *-*-* } .-1 } */
48 /* { dg-message "write of 4 bytes to beyond the end of 'arr'" "num bad bytes note" { target *-*-* } .-2 } */
49 /* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } .-3 } */
52 void int_arr_write_element_after_end_far(int32_t x)
54 arr[100] = x; /* { dg-warning "buffer overflow" "warning" } */
55 /* { dg-message "out-of-bounds write from byte 400 till byte 403 but 'arr' ends at byte 40" "final event" { target *-*-* } .-1 } */
56 /* { dg-message "write of 4 bytes to beyond the end of 'arr'" "num bad bytes note" { target *-*-* } .-2 } */
57 /* { dg-message "valid subscripts for 'arr' are '\\\[0\\\]' to '\\\[9\\\]'" "valid subscript note" { target *-*-* } .-3 } */