| #include <string.h> |
| |
| /* PR analyzer/95007. */ |
| |
| void test_1 (void) |
| { |
| char *s = "foo"; |
| s[0] = 'g'; /* { dg-warning "write to string literal" } */ |
| } |
| |
| /* PR c/83347. */ |
| |
| void test_2 (void) |
| { |
| memcpy ("abc", "def", 3); /* { dg-warning "write to string literal" } */ |
| } |
| |
| static char * __attribute__((noinline)) |
| called_by_test_3 (void) |
| { |
| return (char *)"foo"; |
| } |
| |
| void test_3 (void) |
| { |
| char *s = called_by_test_3 (); |
| s[1] = 'a'; /* { dg-warning "write to string literal" } */ |
| } |
| |
| static char * __attribute__((noinline)) |
| called_by_test_4 (int flag) |
| { |
| if (flag) |
| return (char *)"foo"; |
| else |
| return (char *)"bar"; |
| } |
| |
| void test_4 (void) |
| { |
| char *s = called_by_test_4 (0); |
| s[1] = 'z'; /* { dg-warning "write to string literal" } */ |
| } |
| |
| static char * __attribute__((noinline)) |
| called_by_test_5 (int flag) |
| { |
| if (flag) |
| return (char *)"foo"; |
| else |
| return (char *)"bar"; |
| } |
| |
| void test_5 (int flag) |
| { |
| char *s = called_by_test_5 (flag); |
| s[1] = 'z'; /* We miss this one, unless we disable state merging. */ |
| } |