1 /* PR middle-end/85359 - duplicate -Wstringop-overflow for a strcmp call
2 with a nonstring pointer
4 { dg-options "-O2 -Wall" } */
6 typedef __SIZE_TYPE__
size_t;
7 typedef __builtin_va_list
va_list;
9 int printf (const char*, ...);
10 int puts (const char*);
11 int puts_unlocked (const char*);
12 int sprintf (char*, const char*, ...);
13 int snprintf (char*, size_t, const char*, ...);
14 int vsprintf (char*, const char*, va_list);
15 int vsnprintf (char*, size_t, const char*, va_list);
17 int strcmp (const char*, const char*);
18 int strncmp (const char*, const char*, size_t);
20 char* stpcpy (char*, const char*);
21 char* stpncpy (char*, const char*, size_t);
23 char* strcat (char*, const char*);
24 char* strncat (char*, const char*, size_t);
26 char* strcpy (char*, const char*);
27 char* strncpy (char*, const char*, size_t);
29 char* strchr (const char*, int);
30 char* strrchr (const char*, int);
31 char* strstr (const char*, const char*);
32 char* strdup (const char*);
33 size_t strlen (const char*);
34 size_t strnlen (const char*, size_t);
35 char* strndup (const char*, size_t);
37 #define NONSTRING __attribute__ ((nonstring))
39 extern char ns5
[5] NONSTRING
;
41 int strcmp_nonstring_1 (NONSTRING
const char *a
, const char *b
)
43 /* dg-warning matches one or more instances of the warning so it's
44 no good on its own. Use dg-regexp instead to verify that just
45 one instance of the warning is issued. See gcc.dg/pr64223-1
46 for a different approach. */
47 return strcmp (a
, b
); /* { dg-regexp "\[^\n\r\]+: warning: .strcmp. argument 1 declared attribute .nonstring. \\\[-Wstringop-overread\[^\n\r\]*" "strcmp" } */
50 int strcmp_nonstring_2 (const char *a
, NONSTRING
const char *b
)
52 return strcmp (a
, b
); /* { dg-regexp "\[^\n\r\]+: warning: .strcmp. argument 2 declared attribute .nonstring. \\\[-Wstringop-overread\[^\n\r\]*" "strcmp" } */
55 int strncmp_nonstring_1 (const char *s
)
57 return strncmp (s
, ns5
, sizeof ns5
+ 1); /* { dg-regexp "\[^\n\r\]+: warning: .strncmp. argument 2 declared attribute .nonstring. \[^\n\r\]+ \\\[-Wstringop-overread\[^\n\r\]*" "strncmp" } */
60 int strncmp_nonstring_2 (const char *s
)
62 return strncmp (ns5
, s
, sizeof ns5
+ 1); /* { dg-regexp "\[^\n\r\]+: warning: .strncmp. argument 1 declared attribute .nonstring. \[^\n\r\]+ \\\[-Wstringop-overread\[^\n\r\]*" "strncmp" } */
65 char* stpcpy_nonstring (char *d
, NONSTRING
const char *s
)
67 return stpcpy (d
, s
); /* { dg-regexp "\[^\n\r\]+: warning: .stpcpy. argument 2 declared attribute .nonstring. \\\[-Wstringop-overread\[^\n\r\]*" "stpcpy" } */
70 char* stpncpy_nonstring (char *d
)
72 return stpncpy (d
, ns5
, sizeof ns5
+ 1); /* { dg-regexp "\[^\n\r\]+: warning: .stpncpy. argument 2 declared attribute .nonstring. \[^\n\r\]+ \\\[-Wstringop-overread\[^\n\r\]*" "stpncpy" } */
75 char* strchr_nonstring (NONSTRING
const char *s
, int c
)
77 return strchr (s
, c
); /* { dg-regexp "\[^\n\r\]+: warning: .strchr. argument 1 declared attribute .nonstring. \\\[-Wstringop-overread\[^\n\r\]*" "strchr" } */
80 char* strrchr_nonstring (NONSTRING
const char *s
, int c
)
82 return strrchr (s
, c
); /* { dg-regexp "\[^\n\r\]+: warning: .strrchr. argument 1 declared attribute .nonstring. \\\[-Wstringop-overread\[^\n\r\]*" "strrchr" } */
85 char* strcpy_nonstring (char *d
, NONSTRING
const char *s
)
87 return strcpy (d
, s
); /* { dg-regexp "\[^\n\r\]+: warning: .strcpy. argument 2 declared attribute .nonstring. \\\[-Wstringop-overread\[^\n\r\]*" "strcpy" } */
90 char* strncpy_nonstring (char *d
)
92 return strncpy (d
, ns5
, sizeof ns5
+ 1); /* { dg-regexp "\[^\n\r\]+: warning: .strncpy. argument 2 declared attribute .nonstring. \[^\n\r\]+ \\\[-Wstringop-overread\[^\n\r\]*" "strncpy" } */
95 char* strstr_nonstring_1 (NONSTRING
const char *a
, const char *b
)
97 return strstr (a
, b
); /* { dg-regexp "\[^\n\r\]+: warning: .strstr. argument 1 declared attribute .nonstring. \\\[-Wstringop-overread\[^\n\r\]*" "strstr" } */
100 char* strstr_nonstring_2 (const char *a
, NONSTRING
const char *b
)
102 return strstr (a
, b
); /* { dg-regexp "\[^\n\r\]+: warning: .strstr. argument 2 declared attribute .nonstring. \\\[-Wstringop-overread\[^\n\r\]*" "strstr" } */
105 char* stdup_nonstring (NONSTRING
const char *s
)
107 return strdup (s
); /* { dg-regexp "\[^\n\r\]+: warning: .strdup. argument 1 declared attribute .nonstring. \\\[-Wstringop-overread\[^\n\r\]*" "strdup" } */
110 size_t strlen_nonstring (NONSTRING
const char *s
)
112 return strlen (s
); /* { dg-regexp "\[^\n\r\]+: warning: .strlen. argument 1 declared attribute .nonstring. \\\[-Wstringop-overread\[^\n\r\]*" "strlen" } */
115 int printf_nonstring (NONSTRING
const char *s
)
117 return printf (s
); /* { dg-regexp "\[^\n\r\]+: warning: .printf. argument 1 declared attribute .nonstring. \\\[-Wstringop-overread\[^\n\r\]*" "printf" } */
120 int sprintf_nonstring_2 (char *d
, NONSTRING
const char *s
)
122 return sprintf (d
, s
); /* { dg-regexp "\[^\n\r\]+: warning: .sprintf. argument 2 declared attribute .nonstring. \\\[-Wstringop-overread\[^\n\r\]*" "sprintf" } */