From 003620645c6adf8fb4380846fe11124fc05a2e87 Mon Sep 17 00:00:00 2001 From: "Kaveh R. Ghazi" Date: Sun, 4 May 2003 22:18:17 +0000 Subject: [PATCH] builtin-attrs.def (ATTR_NOTHROW_NONNULL_1, [...]): Renamed from ATTR_NONNULL_1, ATTR_NONNULL_2 and ATTR_NONNULL_3. gcc: * builtin-attrs.def (ATTR_NOTHROW_NONNULL_1, ATTR_NOTHROW_NONNULL_2, ATTR_NOTHROW_NONNULL_3): Renamed from ATTR_NONNULL_1, ATTR_NONNULL_2 and ATTR_NONNULL_3. (ATTR_NOTHROW_NONNULL_1_2, ATTR_NOTHROW_NONNULL_1_4, ATTR_CONST_NOTHROW_NONNULL_1, ATTR_PURE_NOTHROW_NONNULL_1, ATTR_PURE_NOTHROW_NONNULL_1_2, ATTR_MALLOC_NOTHROW_NONNULL_1): New. * builtins.def (DEF_EXT_FALLBACK_BUILTIN): Accept ATTRS argument. (BUILT_IN_BZERO, BUILT_IN_BCOPY, BUILT_IN_BCMP): Update comment (BUILT_IN_INDEX, BUILT_IN_RINDEX, BUILT_IN_MEMCPY, BUILT_IN_MEMMOVE, BUILT_IN_MEMCMP, BUILT_IN_MEMSET, BUILT_IN_MEMPCPY, BUILT_IN_STRCAT, BUILT_IN_STRNCAT, BUILT_IN_STPCPY, BUILT_IN_STRCPY, BUILT_IN_STRNCPY, BUILT_IN_STRCMP, BUILT_IN_STRNCMP, BUILT_IN_STRLEN, BUILT_IN_STRSTR, BUILT_IN_STRPBRK, BUILT_IN_STRSPN, BUILT_IN_STRCSPN, BUILT_IN_STRCHR, BUILT_IN_STRRCHR, BUILT_IN_NAN, BUILT_IN_NANF, BUILT_IN_NANL, BUILT_IN_NANS, BUILT_IN_NANSF, BUILT_IN_NANSL, BUILT_IN_PUTS, BUILT_IN_FPUTC, BUILT_IN_FPUTS, BUILT_IN_FWRITE, BUILT_IN_PUTS_UNLOCKED, BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS_UNLOCKED, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_STRDUP): Add "nonnull" attribute. testsuite: * gcc.dg/nonnull-3.c: New test. From-SVN: r66468 --- gcc/ChangeLog | 27 ++++++++++ gcc/builtin-attrs.def | 28 +++++++++-- gcc/builtins.def | 85 +++++++++++++++++--------------- gcc/testsuite/ChangeLog | 4 ++ gcc/testsuite/gcc.dg/nonnull-3.c | 75 ++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+), 46 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/nonnull-3.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 669001dfdbba..13f2a54edc1a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,30 @@ +2003-05-04 Kaveh R. Ghazi + + * builtin-attrs.def (ATTR_NOTHROW_NONNULL_1, + ATTR_NOTHROW_NONNULL_2, ATTR_NOTHROW_NONNULL_3): Renamed from + ATTR_NONNULL_1, ATTR_NONNULL_2 and ATTR_NONNULL_3. + + (ATTR_NOTHROW_NONNULL_1_2, ATTR_NOTHROW_NONNULL_1_4, + ATTR_CONST_NOTHROW_NONNULL_1, ATTR_PURE_NOTHROW_NONNULL_1, + ATTR_PURE_NOTHROW_NONNULL_1_2, ATTR_MALLOC_NOTHROW_NONNULL_1): + New. + + * builtins.def (DEF_EXT_FALLBACK_BUILTIN): Accept ATTRS argument. + (BUILT_IN_BZERO, BUILT_IN_BCOPY, BUILT_IN_BCMP): Update comment + + (BUILT_IN_INDEX, BUILT_IN_RINDEX, BUILT_IN_MEMCPY, + BUILT_IN_MEMMOVE, BUILT_IN_MEMCMP, BUILT_IN_MEMSET, + BUILT_IN_MEMPCPY, BUILT_IN_STRCAT, BUILT_IN_STRNCAT, + BUILT_IN_STPCPY, BUILT_IN_STRCPY, BUILT_IN_STRNCPY, + BUILT_IN_STRCMP, BUILT_IN_STRNCMP, BUILT_IN_STRLEN, + BUILT_IN_STRSTR, BUILT_IN_STRPBRK, BUILT_IN_STRSPN, + BUILT_IN_STRCSPN, BUILT_IN_STRCHR, BUILT_IN_STRRCHR, BUILT_IN_NAN, + BUILT_IN_NANF, BUILT_IN_NANL, BUILT_IN_NANS, BUILT_IN_NANSF, + BUILT_IN_NANSL, BUILT_IN_PUTS, BUILT_IN_FPUTC, BUILT_IN_FPUTS, + BUILT_IN_FWRITE, BUILT_IN_PUTS_UNLOCKED, BUILT_IN_FPUTC_UNLOCKED, + BUILT_IN_FPUTS_UNLOCKED, BUILT_IN_FWRITE_UNLOCKED, + BUILT_IN_STRDUP): Add "nonnull" attribute. + 2003-05-04 Richard Kenner * expr.c (store_field): Don't clobber TEMP in shift: it might be diff --git a/gcc/builtin-attrs.def b/gcc/builtin-attrs.def index 7bdbd6280865..ea05f49f4f8f 100644 --- a/gcc/builtin-attrs.def +++ b/gcc/builtin-attrs.def @@ -102,19 +102,37 @@ DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LIST, ATTR_NORETURN, \ DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_LIST, ATTR_MALLOC, \ ATTR_NULL, ATTR_NOTHROW_LIST) -DEF_ATTR_TREE_LIST (ATTR_NONNULL_1, ATTR_NONNULL, ATTR_LIST_1, \ +DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_1, ATTR_NONNULL, ATTR_LIST_1, \ ATTR_NOTHROW_LIST) -DEF_ATTR_TREE_LIST (ATTR_NONNULL_2, ATTR_NONNULL, ATTR_LIST_2, \ +DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_2, ATTR_NONNULL, ATTR_LIST_2, \ ATTR_NOTHROW_LIST) -DEF_ATTR_TREE_LIST (ATTR_NONNULL_3, ATTR_NONNULL, ATTR_LIST_3, \ +DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_3, ATTR_NONNULL, ATTR_LIST_3, \ ATTR_NOTHROW_LIST) +/* Nothrow functions whose first and second parameters are nonnull pointers. */ +DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_1_2, ATTR_NONNULL, ATTR_LIST_2, \ + ATTR_NOTHROW_NONNULL_1) +/* Nothrow functions whose first and fourth parameters are nonnull pointers. */ +DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_1_4, ATTR_NONNULL, ATTR_LIST_4, \ + ATTR_NOTHROW_NONNULL_1) +/* Nothrow const functions whose first parameter is a nonnull pointer. */ +DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_NONNULL_1, ATTR_CONST, ATTR_NULL, \ + ATTR_NOTHROW_NONNULL_1) +/* Nothrow pure functions whose first parameter is a nonnull pointer. */ +DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NONNULL_1, ATTR_PURE, ATTR_NULL, \ + ATTR_NOTHROW_NONNULL_1) +/* Nothrow pure functions whose first and second parameters are nonnull pointers. */ +DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NONNULL_1_2, ATTR_PURE, ATTR_NULL, \ + ATTR_NOTHROW_NONNULL_1_2) +/* Nothrow malloc functions whose first parameter is a nonnull pointer. */ +DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_NONNULL_1, ATTR_MALLOC, ATTR_NULL, \ + ATTR_NOTHROW_NONNULL_1) /* Construct a tree for a format attribute. */ #define DEF_FORMAT_ATTRIBUTE(TYPE, FA, VALUES) \ DEF_ATTR_TREE_LIST (CONCAT4 (ATTR_,TYPE,_,VALUES), ATTR_NULL, \ CONCAT2 (ATTR_,TYPE), CONCAT2 (ATTR_LIST_,VALUES)) \ DEF_ATTR_TREE_LIST (CONCAT4 (ATTR_FORMAT_,TYPE,_,VALUES), ATTR_FORMAT, \ - CONCAT4 (ATTR_,TYPE,_,VALUES), CONCAT2 (ATTR_NONNULL_,FA)) + CONCAT4 (ATTR_,TYPE,_,VALUES), CONCAT2 (ATTR_NOTHROW_NONNULL_,FA)) DEF_FORMAT_ATTRIBUTE(PRINTF,1,1_0) DEF_FORMAT_ATTRIBUTE(PRINTF,1,1_2) DEF_FORMAT_ATTRIBUTE(PRINTF,2,2_0) @@ -132,7 +150,7 @@ DEF_FORMAT_ATTRIBUTE(STRFMON,3,3_4) /* Construct a tree for a format_arg attribute. */ #define DEF_FORMAT_ARG_ATTRIBUTE(FA) \ DEF_ATTR_TREE_LIST (CONCAT2 (ATTR_FORMAT_ARG_,FA), ATTR_FORMAT_ARG, \ - CONCAT2 (ATTR_LIST_,FA), CONCAT2 (ATTR_NONNULL_,FA)) + CONCAT2 (ATTR_LIST_,FA), CONCAT2 (ATTR_NOTHROW_NONNULL_,FA)) DEF_FORMAT_ARG_ATTRIBUTE(1) DEF_FORMAT_ARG_ATTRIBUTE(2) #undef DEF_FORMAT_ARG_ATTRIBUTE diff --git a/gcc/builtins.def b/gcc/builtins.def index a74673196a63..a45641cf0ae5 100644 --- a/gcc/builtins.def +++ b/gcc/builtins.def @@ -85,9 +85,9 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA we ignore the version of these builtins that does not begin with __builtin. */ #undef DEF_EXT_FALLBACK_BUILTIN -#define DEF_EXT_FALLBACK_BUILTIN(ENUM, NAME, TYPE) \ +#define DEF_EXT_FALLBACK_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, TYPE, \ - false, true, true, ATTR_NOTHROW_LIST, true) + false, true, true, ATTRS, true) /* A library builtin (like __builtin_strchr) is a builtin equivalent of an ANSI/ISO standard library function. In addition to the @@ -287,8 +287,11 @@ DEF_C99_BUILTIN(BUILT_IN_CIMAGL, ATTR_CONST_NOTHROW_LIST) /* The system prototypes for `bzero', 'bcopy' and `bcmp' functions - have many variations, so don't specify parameters to avoid conflicts. - The expand_* functions check the argument types anyway. */ + have many variations, so don't specify parameters to avoid + conflicts. The expand_* functions check the argument types anyway. + In addition, these functions have traditionally accepted NULL + pointers when the length parameter is zero, so don't apply + attribute "nonnull". */ DEF_BUILTIN (BUILT_IN_BZERO, "__builtin_bzero", BUILT_IN_NORMAL, @@ -377,89 +380,89 @@ DEF_GCC_BUILTIN(BUILT_IN_PARITYLL, DEF_EXT_LIB_BUILTIN(BUILT_IN_INDEX, "__builtin_index", BT_FN_STRING_CONST_STRING_INT, - ATTR_PURE_NOTHROW_LIST) + ATTR_PURE_NOTHROW_NONNULL_1) DEF_EXT_LIB_BUILTIN(BUILT_IN_RINDEX, "__builtin_rindex", BT_FN_STRING_CONST_STRING_INT, - ATTR_PURE_NOTHROW_LIST) + ATTR_PURE_NOTHROW_NONNULL_1) DEF_LIB_BUILTIN(BUILT_IN_MEMCPY, "__builtin_memcpy", BT_FN_PTR_PTR_CONST_PTR_SIZE, - ATTR_NOTHROW_LIST) + ATTR_NOTHROW_NONNULL_1_2) DEF_LIB_BUILTIN(BUILT_IN_MEMMOVE, "__builtin_memmove", BT_FN_PTR_PTR_CONST_PTR_SIZE, - ATTR_NOTHROW_LIST) + ATTR_NOTHROW_NONNULL_1_2) DEF_LIB_BUILTIN(BUILT_IN_MEMCMP, "__builtin_memcmp", BT_FN_INT_CONST_PTR_CONST_PTR_SIZE, - ATTR_PURE_NOTHROW_LIST) + ATTR_PURE_NOTHROW_NONNULL_1_2) DEF_LIB_BUILTIN(BUILT_IN_MEMSET, "__builtin_memset", BT_FN_PTR_PTR_INT_SIZE, - ATTR_NOTHROW_LIST) + ATTR_NOTHROW_NONNULL_1) DEF_EXT_LIB_BUILTIN(BUILT_IN_MEMPCPY, "__builtin_mempcpy", BT_FN_PTR_PTR_CONST_PTR_SIZE, - ATTR_NOTHROW_LIST) + ATTR_NOTHROW_NONNULL_1_2) DEF_LIB_BUILTIN(BUILT_IN_STRCAT, "__builtin_strcat", BT_FN_STRING_STRING_CONST_STRING, - ATTR_NOTHROW_LIST) + ATTR_NOTHROW_NONNULL_1_2) DEF_LIB_BUILTIN(BUILT_IN_STRNCAT, "__builtin_strncat", BT_FN_STRING_STRING_CONST_STRING_SIZE, - ATTR_NOTHROW_LIST) + ATTR_NOTHROW_NONNULL_1_2) DEF_EXT_LIB_BUILTIN(BUILT_IN_STPCPY, "__builtin_stpcpy", BT_FN_STRING_STRING_CONST_STRING, - ATTR_NOTHROW_LIST) + ATTR_NOTHROW_NONNULL_1_2) DEF_LIB_BUILTIN(BUILT_IN_STRCPY, "__builtin_strcpy", BT_FN_STRING_STRING_CONST_STRING, - ATTR_NOTHROW_LIST) + ATTR_NOTHROW_NONNULL_1_2) DEF_LIB_BUILTIN(BUILT_IN_STRNCPY, "__builtin_strncpy", BT_FN_STRING_STRING_CONST_STRING_SIZE, - ATTR_NOTHROW_LIST) + ATTR_NOTHROW_NONNULL_1_2) DEF_LIB_BUILTIN(BUILT_IN_STRCMP, "__builtin_strcmp", BT_FN_INT_CONST_STRING_CONST_STRING, - ATTR_PURE_NOTHROW_LIST) + ATTR_PURE_NOTHROW_NONNULL_1_2) DEF_LIB_BUILTIN(BUILT_IN_STRNCMP, "__builtin_strncmp", BT_FN_INT_CONST_STRING_CONST_STRING_SIZE, - ATTR_PURE_NOTHROW_LIST) + ATTR_PURE_NOTHROW_NONNULL_1_2) DEF_LIB_BUILTIN(BUILT_IN_STRLEN, "__builtin_strlen", BT_FN_SIZE_CONST_STRING, - ATTR_PURE_NOTHROW_LIST) + ATTR_PURE_NOTHROW_NONNULL_1) DEF_LIB_BUILTIN(BUILT_IN_STRSTR, "__builtin_strstr", BT_FN_STRING_CONST_STRING_CONST_STRING, - ATTR_PURE_NOTHROW_LIST) + ATTR_PURE_NOTHROW_NONNULL_1_2) DEF_LIB_BUILTIN(BUILT_IN_STRPBRK, "__builtin_strpbrk", BT_FN_STRING_CONST_STRING_CONST_STRING, - ATTR_PURE_NOTHROW_LIST) + ATTR_PURE_NOTHROW_NONNULL_1_2) DEF_LIB_BUILTIN(BUILT_IN_STRSPN, "__builtin_strspn", BT_FN_SIZE_CONST_STRING_CONST_STRING, - ATTR_PURE_NOTHROW_LIST) + ATTR_PURE_NOTHROW_NONNULL_1_2) DEF_LIB_BUILTIN(BUILT_IN_STRCSPN, "__builtin_strcspn", BT_FN_SIZE_CONST_STRING_CONST_STRING, - ATTR_PURE_NOTHROW_LIST) + ATTR_PURE_NOTHROW_NONNULL_1_2) DEF_LIB_BUILTIN(BUILT_IN_STRCHR, "__builtin_strchr", BT_FN_STRING_CONST_STRING_INT, - ATTR_PURE_NOTHROW_LIST) + ATTR_PURE_NOTHROW_NONNULL_1) DEF_LIB_BUILTIN(BUILT_IN_STRRCHR, "__builtin_strrchr", BT_FN_STRING_CONST_STRING_INT, - ATTR_PURE_NOTHROW_LIST) + ATTR_PURE_NOTHROW_NONNULL_1) DEF_LIB_BUILTIN(BUILT_IN_SQRT, "__builtin_sqrt", @@ -647,28 +650,28 @@ DEF_GCC_BUILTIN(BUILT_IN_HUGE_VALL, DEF_LIB_BUILTIN(BUILT_IN_NAN, "__builtin_nan", BT_FN_DOUBLE_CONST_STRING, - ATTR_CONST_NOTHROW_LIST) + ATTR_CONST_NOTHROW_NONNULL_1) DEF_LIB_BUILTIN(BUILT_IN_NANF, "__builtin_nanf", BT_FN_FLOAT_CONST_STRING, - ATTR_CONST_NOTHROW_LIST) + ATTR_CONST_NOTHROW_NONNULL_1) DEF_LIB_BUILTIN(BUILT_IN_NANL, "__builtin_nanl", BT_FN_LONG_DOUBLE_CONST_STRING, - ATTR_CONST_NOTHROW_LIST) + ATTR_CONST_NOTHROW_NONNULL_1) DEF_LIB_BUILTIN(BUILT_IN_NANS, "__builtin_nans", BT_FN_DOUBLE_CONST_STRING, - ATTR_CONST_NOTHROW_LIST) + ATTR_CONST_NOTHROW_NONNULL_1) DEF_LIB_BUILTIN(BUILT_IN_NANSF, "__builtin_nansf", BT_FN_FLOAT_CONST_STRING, - ATTR_CONST_NOTHROW_LIST) + ATTR_CONST_NOTHROW_NONNULL_1) DEF_LIB_BUILTIN(BUILT_IN_NANSL, "__builtin_nansl", BT_FN_LONG_DOUBLE_CONST_STRING, - ATTR_CONST_NOTHROW_LIST) + ATTR_CONST_NOTHROW_NONNULL_1) DEF_GCC_BUILTIN(BUILT_IN_SAVEREGS, "__builtin_saveregs", @@ -744,7 +747,7 @@ DEF_LIB_BUILTIN(BUILT_IN_PUTCHAR, DEF_LIB_BUILTIN(BUILT_IN_PUTS, "__builtin_puts", BT_FN_INT_CONST_STRING, - ATTR_NOTHROW_LIST) + ATTR_NOTHROW_NONNULL_1) DEF_C99_BUILTIN(BUILT_IN_SNPRINTF, "__builtin_snprintf", BT_FN_INT_STRING_SIZE_CONST_STRING_VAR, @@ -793,17 +796,17 @@ DEF_LIB_BUILTIN(BUILT_IN_VSPRINTF, DEF_FALLBACK_BUILTIN(BUILT_IN_FPUTC, "__builtin_fputc", BT_FN_INT_INT_PTR, - ATTR_NOTHROW_LIST) + ATTR_NOTHROW_NONNULL_2) DEF_BUILTIN (BUILT_IN_FPUTS, "__builtin_fputs", BUILT_IN_NORMAL, BT_FN_INT_CONST_STRING_PTR, BT_FN_INT_VAR, - true, true, false, ATTR_NOTHROW_LIST, true) + true, true, false, ATTR_NOTHROW_NONNULL_1_2, true) DEF_FALLBACK_BUILTIN(BUILT_IN_FWRITE, "__builtin_fwrite", BT_FN_SIZE_CONST_PTR_SIZE_SIZE_PTR, - ATTR_NOTHROW_LIST) + ATTR_NOTHROW_NONNULL_1_4) DEF_FRONT_END_LIB_BUILTIN(BUILT_IN_FPRINTF, "__builtin_fprintf", BT_FN_INT_PTR_CONST_STRING_VAR, @@ -813,10 +816,10 @@ DEF_FRONT_END_LIB_BUILTIN(BUILT_IN_FPRINTF, DEF_EXT_FALLBACK_BUILTIN(BUILT_IN_PUTCHAR_UNLOCKED, "__builtin_putchar_unlocked", - BT_FN_INT_INT) + BT_FN_INT_INT, ATTR_NOTHROW_LIST) DEF_EXT_FALLBACK_BUILTIN(BUILT_IN_PUTS_UNLOCKED, "__builtin_puts_unlocked", - BT_FN_INT_CONST_STRING) + BT_FN_INT_CONST_STRING, ATTR_NOTHROW_NONNULL_1) DEF_EXT_FRONT_END_LIB_BUILTIN(BUILT_IN_PRINTF_UNLOCKED, "__builtin_printf_unlocked", BT_FN_INT_CONST_STRING_VAR, @@ -831,16 +834,16 @@ DEF_EXT_FRONT_END_LIB_BUILTIN(BUILT_IN_PRINTF_UNLOCKED, DEF_EXT_FALLBACK_BUILTIN(BUILT_IN_FPUTC_UNLOCKED, "__builtin_fputc_unlocked", - BT_FN_INT_INT_PTR) + BT_FN_INT_INT_PTR, ATTR_NOTHROW_NONNULL_2) DEF_BUILTIN (BUILT_IN_FPUTS_UNLOCKED, "__builtin_fputs_unlocked", BUILT_IN_NORMAL, BT_FN_INT_CONST_STRING_PTR, BT_FN_INT_VAR, - true, true, true, ATTR_NOTHROW_LIST, true) + true, true, true, ATTR_NOTHROW_NONNULL_1_2, true) DEF_EXT_FALLBACK_BUILTIN(BUILT_IN_FWRITE_UNLOCKED, "__builtin_fwrite_unlocked", - BT_FN_SIZE_CONST_PTR_SIZE_SIZE_PTR) + BT_FN_SIZE_CONST_PTR_SIZE_SIZE_PTR, ATTR_NOTHROW_NONNULL_1_4) DEF_EXT_FRONT_END_LIB_BUILTIN(BUILT_IN_FPRINTF_UNLOCKED, "__builtin_fprintf_unlocked", BT_FN_INT_PTR_CONST_STRING_VAR, @@ -961,5 +964,5 @@ DEF_LIB_BUILTIN(BUILT_IN_CALLOC, DEF_EXT_LIB_BUILTIN(BUILT_IN_STRDUP, "__builtin_strdup", BT_FN_STRING_CONST_STRING, - ATTR_MALLOC_NOTHROW_LIST) + ATTR_MALLOC_NOTHROW_NONNULL_1) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 56fb9fcd3786..5f20c5e795e7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2003-05-04 Kaveh R. Ghazi + + * gcc.dg/nonnull-3.c: New test. + 2003-05-04 Neil Booth * gcc.dg/cpp/Wtrigraphs.c: Update. diff --git a/gcc/testsuite/gcc.dg/nonnull-3.c b/gcc/testsuite/gcc.dg/nonnull-3.c new file mode 100644 index 000000000000..3b53eaf7b957 --- /dev/null +++ b/gcc/testsuite/gcc.dg/nonnull-3.c @@ -0,0 +1,75 @@ +/* Test for the "nonnull" function attribute on builtins. Use the + "__builtin_" style below so we don't need prototypes. */ +/* Origin: Kaveh R. Ghazi */ +/* { dg-do compile } */ +/* { dg-options "-Wnonnull" } */ + +#include + +void +foo (void *p, char *s) +{ + __builtin_bzero (NULL, 0); + __builtin_bcopy (NULL, p, 0); + __builtin_bcopy (p, NULL, 0); + __builtin_bcmp (NULL, p, 0); + __builtin_bcmp (p, NULL, 0); + __builtin_index (NULL, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_rindex (NULL, 16); /* { dg-warning "null" "null pointer check" } */ + + __builtin_memcpy (p, NULL, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_memcpy (NULL, p, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_memmove (p, NULL, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_memmove (NULL, p, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_memcmp (p, NULL, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_memcmp (NULL, p, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_memset (NULL, 0, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_mempcpy (p, NULL, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_mempcpy (NULL, p, 16); /* { dg-warning "null" "null pointer check" } */ + + __builtin_strcat (NULL, s); /* { dg-warning "null" "null pointer check" } */ + __builtin_strcat (s, NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_strncat (NULL, s, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_strncat (s, NULL, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_stpcpy (NULL, s); /* { dg-warning "null" "null pointer check" } */ + __builtin_stpcpy (s, NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_strcpy (NULL, s); /* { dg-warning "null" "null pointer check" } */ + __builtin_strcpy (s, NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_strncpy (NULL, s, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_strncpy (s, NULL, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_strcmp (NULL, s); /* { dg-warning "null" "null pointer check" } */ + __builtin_strcmp (s, NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_strncmp (NULL, s, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_strncmp (s, NULL, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_strlen (NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_strstr (NULL, s); /* { dg-warning "null" "null pointer check" } */ + __builtin_strstr (s, NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_strpbrk (NULL, s); /* { dg-warning "null" "null pointer check" } */ + __builtin_strpbrk (s, NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_strspn (NULL, s); /* { dg-warning "null" "null pointer check" } */ + __builtin_strspn (s, NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_strchr (NULL, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_strrchr (NULL, 16); /* { dg-warning "null" "null pointer check" } */ + __builtin_strdup (NULL); /* { dg-warning "null" "null pointer check" } */ + + __builtin_nan (NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_nanf (NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_nanl (NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_nans (NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_nansf (NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_nansl (NULL); /* { dg-warning "null" "null pointer check" } */ + + __builtin_puts (NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_fputc (*s, NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_fputs (s, NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_fputs (NULL, p); /* { dg-warning "null" "null pointer check" } */ + __builtin_fwrite (s, 16, 16, NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_fwrite (NULL, 16, 16, p); /* { dg-warning "null" "null pointer check" } */ + __builtin_puts_unlocked (NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_fputc_unlocked (*s, NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_fputs_unlocked (s, NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_fputs_unlocked (NULL, p); /* { dg-warning "null" "null pointer check" } */ + __builtin_fwrite_unlocked (s, 16, 16, NULL); /* { dg-warning "null" "null pointer check" } */ + __builtin_fwrite_unlocked (NULL, 16, 16, p); /* { dg-warning "null" "null pointer check" } */ + +}