This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch to add "nonnull" attribute to various builtins


 > From: Geoff Keating <geoffk@geoffk.org>
 > 
 > "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> writes:
 > 
 > > This patch adds the "nonnull" attribute to most builtin functions
 > > taking pointer parameters.  I'm not a language guru, but I believe
 > > none of these should be expected to accept NULL pointers.
 > > 
 > > Tested on sparc-sun-solaris2.7, no regressions and the new test
 > > passes.
 > > 
 > > Ok for mainline?
 > 
 > No, historically bzero(), bcopy(), and bcmp() do nothing at all if
 > their argument is zero-size, so it's legitimate to pass them NULL pointers.
 > (This is not true of memcpy etc.).


Here's an updated patch.  Changes from last time are:

1.  Renamed ATTRs to explicitely mention NOTHROW to avoid confusion.
2.  Don't add "nonnull" to bcopy et al.  Instead add a comment.
3.  Update testcase to reflect #2.

Retested on solaris2.7, no regressions.  Ok?

		Thanks,
		--Kaveh



2003-05-04  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

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.

diff -rup orig/egcc-CVS20030504/gcc/builtin-attrs.def egcc-CVS20030504/gcc/builtin-attrs.def
--- orig/egcc-CVS20030504/gcc/builtin-attrs.def	2003-03-02 00:55:15.000000000 -0500
+++ egcc-CVS20030504/gcc/builtin-attrs.def	2003-05-04 02:38:42.696843187 -0400
@@ -102,19 +102,37 @@ DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHRO
 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 -rup orig/egcc-CVS20030504/gcc/builtins.def egcc-CVS20030504/gcc/builtins.def
--- orig/egcc-CVS20030504/gcc/builtins.def	2003-05-04 01:26:35.000000000 -0400
+++ egcc-CVS20030504/gcc/builtins.def	2003-05-04 02:42:17.187646426 -0400
@@ -85,9 +85,9 @@ Software Foundation, 59 Temple Place - S
    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_FPRIN
 
 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_P
 
 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 -rup orig/egcc-CVS20030504/gcc/testsuite/gcc.dg/nonnull-3.c egcc-CVS20030504/gcc/testsuite/gcc.dg/nonnull-3.c
--- orig/egcc-CVS20030504/gcc/testsuite/gcc.dg/nonnull-3.c	2003-05-04 01:47:12.480711019 -0400
+++ egcc-CVS20030504/gcc/testsuite/gcc.dg/nonnull-3.c	2003-05-04 01:52:50.441675197 -0400
@@ -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 <ghazi@caip.rutgers.edu> */
+/* { dg-do compile } */
+/* { dg-options "-Wnonnull" } */
+
+#include <stddef.h>
+
+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" } */
+
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]