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]

[PATCH]: Add strndup builtin attributes


This patch adds the strndup builtin, mainly to get the function
attributes setup properly.

Bootstrapped on x86_64-unknown-linux-gnu, no regressions.

Okay for mainline?

		Thanks,
		--Kaveh


2005-03-24  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* builtin-types.def (BT_FN_STRING_CONST_STRING_SIZE): New.
	* builtins.def (BUILT_IN_STRNDUP): New.
	
testsuite:
	* gcc.dg/nonnull-3.c: Also test __builtin_strndup.

diff -rup orig/egcc-CVS20050323/gcc/builtin-types.def egcc-CVS20050323/gcc/builtin-types.def
--- orig/egcc-CVS20050323/gcc/builtin-types.def	2004-07-09 19:04:31.000000000 -0400
+++ egcc-CVS20050323/gcc/builtin-types.def	2005-03-24 12:51:00.030239936 -0500
@@ -172,6 +172,8 @@ DEF_FUNCTION_TYPE_2 (BT_FN_SIZE_CONST_ST
 	             BT_SIZE, BT_CONST_STRING, BT_CONST_STRING)
 DEF_FUNCTION_TYPE_2 (BT_FN_STRING_CONST_STRING_INT,
 	             BT_STRING, BT_CONST_STRING, BT_INT)
+DEF_FUNCTION_TYPE_2 (BT_FN_STRING_CONST_STRING_SIZE,
+	             BT_STRING, BT_CONST_STRING, BT_SIZE)
 DEF_FUNCTION_TYPE_2 (BT_FN_INT_CONST_STRING_FILEPTR,
 		     BT_INT, BT_CONST_STRING, BT_FILEPTR)
 DEF_FUNCTION_TYPE_2 (BT_FN_INT_INT_FILEPTR,
diff -rup orig/egcc-CVS20050323/gcc/builtins.def egcc-CVS20050323/gcc/builtins.def
--- orig/egcc-CVS20050323/gcc/builtins.def	2005-03-14 22:13:36.000000000 -0500
+++ egcc-CVS20050323/gcc/builtins.def	2005-03-24 12:51:00.031239784 -0500
@@ -468,6 +468,7 @@ DEF_LIB_BUILTIN        (BUILT_IN_STRCMP,
 DEF_LIB_BUILTIN        (BUILT_IN_STRCPY, "strcpy", BT_FN_STRING_STRING_CONST_STRING, ATTR_NOTHROW_NONNULL)
 DEF_LIB_BUILTIN        (BUILT_IN_STRCSPN, "strcspn", BT_FN_SIZE_CONST_STRING_CONST_STRING, ATTR_PURE_NOTHROW_NONNULL)
 DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRDUP, "strdup", BT_FN_STRING_CONST_STRING, ATTR_MALLOC_NOTHROW_NONNULL)
+DEF_EXT_LIB_BUILTIN    (BUILT_IN_STRNDUP, "strndup", BT_FN_STRING_CONST_STRING_SIZE, ATTR_MALLOC_NOTHROW_NONNULL)
 DEF_LIB_BUILTIN        (BUILT_IN_STRLEN, "strlen", BT_FN_SIZE_CONST_STRING, ATTR_PURE_NOTHROW_NONNULL)
 DEF_LIB_BUILTIN        (BUILT_IN_STRNCAT, "strncat", BT_FN_STRING_STRING_CONST_STRING_SIZE, ATTR_NOTHROW_NONNULL)
 DEF_LIB_BUILTIN        (BUILT_IN_STRNCMP, "strncmp", BT_FN_INT_CONST_STRING_CONST_STRING_SIZE, ATTR_PURE_NOTHROW_NONNULL)
diff -rup orig/egcc-CVS20050323/gcc/testsuite/gcc.dg/nonnull-3.c egcc-CVS20050323/gcc/testsuite/gcc.dg/nonnull-3.c
--- orig/egcc-CVS20050323/gcc/testsuite/gcc.dg/nonnull-3.c	2003-05-04 18:18:17.000000000 -0400
+++ egcc-CVS20050323/gcc/testsuite/gcc.dg/nonnull-3.c	2005-03-24 12:51:30.604591928 -0500
@@ -51,6 +51,7 @@ foo (void *p, char *s)
   __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_strndup (NULL, 16);  /* { dg-warning "null" "null pointer check" } */
 
   __builtin_nan (NULL);  /* { dg-warning "null" "null pointer check" } */
   __builtin_nanf (NULL);  /* { 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]