[PATCH] PR c++/9367: Builtins for *scanf and *printf

Roger Sayle roger@www.eyesopen.com
Sat Mar 1 19:25:00 GMT 2003


This patch fixes high-priority PR c++/9367 which is an issue on both
3.3 and mainline.

The fundamental problem is that GCC has two mechanisms for
associating attributes with functions, one that's efficient
and works, and another that isn't and doesn't.  This patch
continues our migration to using built-ins rather than the
DEF_FN_ATTR macro in builtin-attrs.def.

The immediate advantage to PR c++/9367 is that we only associate
attributes to functions with matching prototypes.  It also avoids
the insert_default_attributes overhead on every identifier (that
isn't helping GCC's name lookup performance) with a single decl
creation at start-up.  Eventually, we may be able to avoid even
the built-in decl creation overhead using GCC's new PCH technology.

There still remain eight rare functions that use DEF_FN_ATTR.
I've left them as they are with this patch, hoping that this
patch is suitable for back-porting to gcc-3_3-branch, and I'll
fix them on mainline in follow-up patches.  As its is the *scanf
and *printf functions make for a large patch.  I also tried to
tidy up builtins.def a bit more, but there's more that can be
done.


The following patch has been tested on i686-pc-linux-gnu with a
full "make bootstrap", all languages except Ada and treelang, and
a complete "make -k check" with a single new regression.  We now
warn in gcc.dg/format/attr-5.c that we prototype an extern function
with an incompatible type to the corresponding built-in.  This is
a good thing.  The patch below contains a tweak to that test case
to check for the warning.  It also contains a new builtins*.C
testcase derived from PR c++/9367.


Ok for mainline?  If so, I'll leave it there a week and if all
looks well, I'll prepare a version for the 3.3 branch.



2003-03-01  Roger Sayle  <roger@eyesopen.com>

	PR c++/9367
	* builtin-types.def (DEF_FUNCTION_TYPE_VAR_3): New macro.
	(BT_FN_INT_CONST_STRING_VALIST_ARG,
	BT_FN_INT_STRING_CONST_STRING_VALIST_ARG,
	BT_FN_INT_CONST_STRING_CONST_STRING_VALIST_ARG,
	BT_FN_INT_STRING_SIZE_CONST_STRING_VALIST_ARG,
	BT_FN_INT_STRING_CONST_STRING_VAR,
	BT_FN_INT_CONST_STRING_CONST_STRING_VAR,
	BT_FN_INT_STRING_SIZE_CONST_STRING_VAR): New built-in types.
	* builtin-attrs.def (ATTR_NONNULL_1, ATTR_NONNULL_2,
	ATTR_NONNULL_3): Also include the nothrow attribute.
	(sprintf, scanf, sscanf, vprintf, vsprintf, snprintf,
	vsnprintf, vscanf, vsscanf): Don't define attributes here.
	* builtins.def (putchar, puts): Make full C89 built-ins.
	(snprintf, sprintf, scanf, sscanf, vprintf, vscanf,
	vsscanf, vsnprintf, vsprintf): New built-ins.
	* c-common.c (c_common_nodes_and_builtins): Handle new macro
	DEF_FUNCTION_TYPE_VAR_3.

	* java/builtins.c (builtin_type): Handle DEF_FUNCTION_TYPE_VAR_3.
	(initialize_builtins): Handle DEF_FUNCTION_TYPE_VAR_3.

	* doc/extend.texi: Document these new built-in functions.

	* gcc.dg/format/attr-5.c: Handle new conflicting types warning.
	* g++.old-deja/g++.other/builtins10.C: New test for PR 9367.


Index: builtin-types.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtin-types.def,v
retrieving revision 1.12
diff -c -3 -p -r1.12 builtin-types.def
*** builtin-types.def	7 Feb 2003 22:37:53 -0000	1.12
--- builtin-types.def	1 Mar 2003 16:24:12 -0000
*************** Software Foundation, 59 Temple Place - S
*** 40,45 ****
--- 40,46 ----
     DEF_FUNCTION_TYPE_VAR_0 (ENUM, RETURN)
     DEF_FUNCTION_TYPE_VAR_1 (ENUM, RETURN, ARG1)
     DEF_FUNCTION_TYPE_VAR_2 (ENUM, RETURN, ARG1, ARG2)
+    DEF_FUNCTION_TYPE_VAR_3 (ENUM, RETURN, ARG1, ARG2, ARG3)

       Similar, but for function types that take variable arguments.
       For example:
*************** DEF_FUNCTION_TYPE_2 (BT_FN_DOUBLE_DOUBLE
*** 155,160 ****
--- 156,163 ----
  		     BT_DOUBLE, BT_DOUBLE, BT_DOUBLE)
  DEF_FUNCTION_TYPE_2 (BT_FN_LONG_DOUBLE_LONG_DOUBLE_LONG_DOUBLE,
  		     BT_LONG_DOUBLE, BT_LONG_DOUBLE, BT_LONG_DOUBLE)
+ DEF_FUNCTION_TYPE_2 (BT_FN_INT_CONST_STRING_VALIST_ARG,
+ 		     BT_INT, BT_CONST_STRING, BT_VALIST_ARG)

  DEF_FUNCTION_TYPE_3 (BT_FN_STRING_STRING_CONST_STRING_SIZE,
  		     BT_STRING, BT_STRING, BT_CONST_STRING, BT_SIZE)
*************** DEF_FUNCTION_TYPE_3 (BT_FN_INT_CONST_PTR
*** 166,175 ****
  	             BT_INT, BT_CONST_PTR, BT_CONST_PTR, BT_SIZE)
  DEF_FUNCTION_TYPE_3 (BT_FN_PTR_PTR_INT_SIZE,
  	             BT_PTR, BT_PTR, BT_INT, BT_SIZE)
! DEF_FUNCTION_TYPE_3 (BT_FN_VOID_PTR_INT_INT, BT_VOID, BT_PTR, BT_INT, BT_INT)

  DEF_FUNCTION_TYPE_4 (BT_FN_SIZE_CONST_PTR_SIZE_SIZE_PTR,
  		     BT_SIZE, BT_CONST_PTR, BT_SIZE, BT_SIZE, BT_PTR)

  DEF_FUNCTION_TYPE_VAR_0 (BT_FN_VOID_VAR, BT_VOID)
  DEF_FUNCTION_TYPE_VAR_0 (BT_FN_INT_VAR, BT_INT)
--- 169,185 ----
  	             BT_INT, BT_CONST_PTR, BT_CONST_PTR, BT_SIZE)
  DEF_FUNCTION_TYPE_3 (BT_FN_PTR_PTR_INT_SIZE,
  	             BT_PTR, BT_PTR, BT_INT, BT_SIZE)
! DEF_FUNCTION_TYPE_3 (BT_FN_VOID_PTR_INT_INT,
! 		     BT_VOID, BT_PTR, BT_INT, BT_INT)
! DEF_FUNCTION_TYPE_3 (BT_FN_INT_STRING_CONST_STRING_VALIST_ARG,
! 		     BT_INT, BT_STRING, BT_CONST_STRING, BT_VALIST_ARG)
! DEF_FUNCTION_TYPE_3 (BT_FN_INT_CONST_STRING_CONST_STRING_VALIST_ARG,
! 		     BT_INT, BT_CONST_STRING, BT_CONST_STRING, BT_VALIST_ARG)

  DEF_FUNCTION_TYPE_4 (BT_FN_SIZE_CONST_PTR_SIZE_SIZE_PTR,
  		     BT_SIZE, BT_CONST_PTR, BT_SIZE, BT_SIZE, BT_PTR)
+ DEF_FUNCTION_TYPE_4 (BT_FN_INT_STRING_SIZE_CONST_STRING_VALIST_ARG,
+ 		BT_INT, BT_STRING, BT_SIZE, BT_CONST_STRING, BT_VALIST_ARG)

  DEF_FUNCTION_TYPE_VAR_0 (BT_FN_VOID_VAR, BT_VOID)
  DEF_FUNCTION_TYPE_VAR_0 (BT_FN_INT_VAR, BT_INT)
*************** DEF_FUNCTION_TYPE_VAR_1 (BT_FN_INT_CONST
*** 184,189 ****
--- 194,206 ----

  DEF_FUNCTION_TYPE_VAR_2 (BT_FN_INT_PTR_CONST_STRING_VAR,
  	                 BT_INT, BT_PTR, BT_CONST_STRING)
+ DEF_FUNCTION_TYPE_VAR_2 (BT_FN_INT_STRING_CONST_STRING_VAR,
+ 			 BT_INT, BT_STRING, BT_CONST_STRING)
+ DEF_FUNCTION_TYPE_VAR_2 (BT_FN_INT_CONST_STRING_CONST_STRING_VAR,
+ 			 BT_INT, BT_CONST_STRING, BT_CONST_STRING)
+
+ DEF_FUNCTION_TYPE_VAR_3 (BT_FN_INT_STRING_SIZE_CONST_STRING_VAR,
+ 			 BT_INT, BT_STRING, BT_SIZE, BT_CONST_STRING)

  DEF_POINTER_TYPE (BT_PTR_FN_VOID_VAR, BT_FN_VOID_VAR)
  DEF_FUNCTION_TYPE_3 (BT_FN_PTR_PTR_FN_VOID_VAR_PTR_SIZE,
Index: builtin-attrs.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtin-attrs.def,v
retrieving revision 1.4
diff -c -3 -p -r1.4 builtin-attrs.def
*** builtin-attrs.def	6 Jul 2002 00:16:41 -0000	1.4
--- builtin-attrs.def	1 Mar 2003 16:24:12 -0000
*************** DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHRO
*** 102,110 ****
  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, ATTR_NULL)
! DEF_ATTR_TREE_LIST (ATTR_NONNULL_2, ATTR_NONNULL, ATTR_LIST_2, ATTR_NULL)
! DEF_ATTR_TREE_LIST (ATTR_NONNULL_3, ATTR_NONNULL, ATTR_LIST_3, ATTR_NULL)

  /* Construct a tree for a format attribute.  */
  #define DEF_FORMAT_ATTRIBUTE(TYPE, FA, VALUES)				 \
--- 102,113 ----
  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, \
! 			ATTR_NOTHROW_LIST)
! DEF_ATTR_TREE_LIST (ATTR_NONNULL_2, ATTR_NONNULL, ATTR_LIST_2, \
! 			ATTR_NOTHROW_LIST)
! DEF_ATTR_TREE_LIST (ATTR_NONNULL_3, ATTR_NONNULL, ATTR_LIST_3, \
! 			ATTR_NOTHROW_LIST)

  /* Construct a tree for a format attribute.  */
  #define DEF_FORMAT_ATTRIBUTE(TYPE, FA, VALUES)				 \
*************** DEF_FORMAT_ARG_ATTRIBUTE(2)
*** 149,161 ****

  /* Functions from ISO/IEC 9899:1990.  */
  #define DEF_C89_ATTR(NAME, ATTRS) DEF_FN_ATTR_IDENT (NAME, ATTRS, flag_hosted)
- DEF_C89_ATTR (sprintf, ATTR_FORMAT_PRINTF_2_3)
- DEF_C89_ATTR (scanf, ATTR_FORMAT_SCANF_1_2)
  DEF_C89_ATTR (fscanf, ATTR_FORMAT_SCANF_2_3)
- DEF_C89_ATTR (sscanf, ATTR_FORMAT_SCANF_2_3)
- DEF_C89_ATTR (vprintf, ATTR_FORMAT_PRINTF_1_0)
  DEF_C89_ATTR (vfprintf, ATTR_FORMAT_PRINTF_2_0)
- DEF_C89_ATTR (vsprintf, ATTR_FORMAT_PRINTF_2_0)
  DEF_C89_ATTR (strftime, ATTR_FORMAT_STRFTIME_3_0)
  #undef DEF_C89_ATTR

--- 152,159 ----
*************** DEF_C89_ATTR (strftime, ATTR_FORMAT_STRF
*** 164,174 ****
    DEF_FN_ATTR_IDENT (NAME, ATTRS,					    \
  	       (flag_hosted						    \
  		&& (flag_isoc99 || flag_noniso_default_format_attributes)))
- DEF_C99_ATTR (snprintf, ATTR_FORMAT_PRINTF_3_4)
- DEF_C99_ATTR (vsnprintf, ATTR_FORMAT_PRINTF_3_0)
- DEF_C99_ATTR (vscanf, ATTR_FORMAT_SCANF_1_0)
  DEF_C99_ATTR (vfscanf, ATTR_FORMAT_SCANF_2_0)
- DEF_C99_ATTR (vsscanf, ATTR_FORMAT_SCANF_2_0)
  #undef DEF_C99_ATTR

  /* Functions not in any version of ISO C.  */
--- 162,168 ----
Index: builtins.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.def,v
retrieving revision 1.44
diff -c -3 -p -r1.44 builtins.def
*** builtins.def	26 Feb 2003 03:02:12 -0000	1.44
--- builtins.def	1 Mar 2003 16:24:12 -0000
*************** DEF_GCC_BUILTIN(BUILT_IN_PREFETCH,
*** 711,737 ****
  		BT_FN_VOID_CONST_PTR_VAR,
  		ATTR_NULL)

! /* Stdio builtins.  */
! DEF_FALLBACK_BUILTIN(BUILT_IN_PUTCHAR,
! 		    "__builtin_putchar",
! 		     BT_FN_INT_INT,
! 		     ATTR_NOTHROW_LIST)
! DEF_FALLBACK_BUILTIN(BUILT_IN_PUTS,
! 		     "__builtin_puts",
! 		     BT_FN_INT_CONST_STRING,
! 		     ATTR_NOTHROW_LIST)
  DEF_FRONT_END_LIB_BUILTIN(BUILT_IN_PRINTF,
  			  "__builtin_printf",
  			  BT_FN_INT_CONST_STRING_VAR,
  			  ATTR_FORMAT_PRINTF_1_2)
! DEF_FALLBACK_BUILTIN(BUILT_IN_FPUTC,
! 		     "__builtin_fputc",
! 		     BT_FN_INT_INT_PTR,
! 		     ATTR_NOTHROW_LIST)
  /* Declare the __builtin_ style with arguments and the regular style
     without them.  We rely on stdio.h to supply the arguments for the
     regular style declaration since we had to use void* instead of
     FILE* in the __builtin_ prototype supplied here.  */
  DEF_BUILTIN (BUILT_IN_FPUTS,
  	     "__builtin_fputs",
  	     BUILT_IN_NORMAL,
--- 711,779 ----
  		BT_FN_VOID_CONST_PTR_VAR,
  		ATTR_NULL)

! /* stdio.h builtins (without FILE *).  */
!
  DEF_FRONT_END_LIB_BUILTIN(BUILT_IN_PRINTF,
  			  "__builtin_printf",
  			  BT_FN_INT_CONST_STRING_VAR,
  			  ATTR_FORMAT_PRINTF_1_2)
! DEF_LIB_BUILTIN(BUILT_IN_PUTCHAR,
! 		"__builtin_putchar",
! 		BT_FN_INT_INT,
! 		ATTR_NOTHROW_LIST)
! DEF_LIB_BUILTIN(BUILT_IN_PUTS,
! 		"__builtin_puts",
! 		BT_FN_INT_CONST_STRING,
! 		ATTR_NOTHROW_LIST)
! DEF_C99_BUILTIN(BUILT_IN_SNPRINTF,
! 		"__builtin_snprintf",
! 		BT_FN_INT_STRING_SIZE_CONST_STRING_VAR,
! 		ATTR_FORMAT_PRINTF_3_4)
! DEF_LIB_BUILTIN(BUILT_IN_SPRINTF,
! 		"__builtin_sprintf",
! 		BT_FN_INT_STRING_CONST_STRING_VAR,
! 		ATTR_FORMAT_PRINTF_2_3)
! DEF_LIB_BUILTIN(BUILT_IN_SCANF,
! 		"__builtin_scanf",
! 		BT_FN_INT_CONST_STRING_VAR,
! 		ATTR_FORMAT_SCANF_1_2)
! DEF_LIB_BUILTIN(BUILT_IN_SSCANF,
! 		"__builtin_sscanf",
! 		BT_FN_INT_CONST_STRING_CONST_STRING_VAR,
! 		ATTR_FORMAT_SCANF_2_3)
! DEF_LIB_BUILTIN(BUILT_IN_VPRINTF,
! 		"__builtin_vprintf",
! 		BT_FN_INT_CONST_STRING_VALIST_ARG,
! 		ATTR_FORMAT_PRINTF_1_0)
! DEF_C99_BUILTIN(BUILT_IN_VSCANF,
! 		"__builtin_vscanf",
! 		BT_FN_INT_CONST_STRING_VALIST_ARG,
! 		ATTR_FORMAT_SCANF_1_0)
! DEF_C99_BUILTIN(BUILT_IN_VSSCANF,
! 		"__builtin_vsscanf",
! 		BT_FN_INT_CONST_STRING_CONST_STRING_VALIST_ARG,
! 		ATTR_FORMAT_SCANF_2_0)
! DEF_C99_BUILTIN(BUILT_IN_VSNPRINTF,
! 		"__builtin_vsnprintf",
! 		BT_FN_INT_STRING_SIZE_CONST_STRING_VALIST_ARG,
! 		ATTR_FORMAT_PRINTF_3_0)
! DEF_LIB_BUILTIN(BUILT_IN_VSPRINTF,
! 		"__builtin_vsprintf",
! 		BT_FN_INT_STRING_CONST_STRING_VALIST_ARG,
! 		ATTR_FORMAT_PRINTF_2_0)
!
!
! /* stdio.h builtins (with FILE *).  */
!
  /* Declare the __builtin_ style with arguments and the regular style
     without them.  We rely on stdio.h to supply the arguments for the
     regular style declaration since we had to use void* instead of
     FILE* in the __builtin_ prototype supplied here.  */
+
+ DEF_FALLBACK_BUILTIN(BUILT_IN_FPUTC,
+ 		     "__builtin_fputc",
+ 		     BT_FN_INT_INT_PTR,
+ 		     ATTR_NOTHROW_LIST)
  DEF_BUILTIN (BUILT_IN_FPUTS,
  	     "__builtin_fputs",
  	     BUILT_IN_NORMAL,
*************** DEF_FRONT_END_LIB_BUILTIN(BUILT_IN_FPRIN
*** 747,753 ****
  			 BT_FN_INT_PTR_CONST_STRING_VAR,
  			 ATTR_FORMAT_PRINTF_2_3)

! /* Stdio unlocked builtins.  */

  DEF_EXT_FALLBACK_BUILTIN(BUILT_IN_PUTCHAR_UNLOCKED,
  			 "__builtin_putchar_unlocked",
--- 789,795 ----
  			 BT_FN_INT_PTR_CONST_STRING_VAR,
  			 ATTR_FORMAT_PRINTF_2_3)

! /* stdio unlocked builtins (without FILE *).  */

  DEF_EXT_FALLBACK_BUILTIN(BUILT_IN_PUTCHAR_UNLOCKED,
  			 "__builtin_putchar_unlocked",
*************** DEF_EXT_FRONT_END_LIB_BUILTIN(BUILT_IN_P
*** 759,771 ****
  			      "__builtin_printf_unlocked",
  			      BT_FN_INT_CONST_STRING_VAR,
  			      ATTR_FORMAT_PRINTF_1_2)
! DEF_EXT_FALLBACK_BUILTIN(BUILT_IN_FPUTC_UNLOCKED,
! 			 "__builtin_fputc_unlocked",
! 			 BT_FN_INT_INT_PTR)
  /* Declare the __builtin_ style with arguments and the regular style
     without them.  We rely on stdio.h to supply the arguments for the
     regular style declaration since we had to use void* instead of
     FILE* in the __builtin_ prototype supplied here.  */
  DEF_BUILTIN (BUILT_IN_FPUTS_UNLOCKED,
  	     "__builtin_fputs_unlocked",
  	     BUILT_IN_NORMAL,
--- 801,817 ----
  			      "__builtin_printf_unlocked",
  			      BT_FN_INT_CONST_STRING_VAR,
  			      ATTR_FORMAT_PRINTF_1_2)
!
! /* stdio unlocked builtins (with FILE *).  */
!
  /* Declare the __builtin_ style with arguments and the regular style
     without them.  We rely on stdio.h to supply the arguments for the
     regular style declaration since we had to use void* instead of
     FILE* in the __builtin_ prototype supplied here.  */
+
+ DEF_EXT_FALLBACK_BUILTIN(BUILT_IN_FPUTC_UNLOCKED,
+ 			 "__builtin_fputc_unlocked",
+ 			 BT_FN_INT_INT_PTR)
  DEF_BUILTIN (BUILT_IN_FPUTS_UNLOCKED,
  	     "__builtin_fputs_unlocked",
  	     BUILT_IN_NORMAL,
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.401
diff -c -3 -p -r1.401 c-common.c
*** c-common.c	19 Feb 2003 02:07:02 -0000	1.401
--- c-common.c	1 Mar 2003 16:24:13 -0000
*************** c_common_nodes_and_builtins ()
*** 3203,3208 ****
--- 3203,3209 ----
  #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
  #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
  #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
+ #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
  #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
  #include "builtin-types.def"
  #undef DEF_PRIMITIVE_TYPE
*************** c_common_nodes_and_builtins ()
*** 3214,3219 ****
--- 3215,3221 ----
  #undef DEF_FUNCTION_TYPE_VAR_0
  #undef DEF_FUNCTION_TYPE_VAR_1
  #undef DEF_FUNCTION_TYPE_VAR_2
+ #undef DEF_FUNCTION_TYPE_VAR_3
  #undef DEF_POINTER_TYPE
      BT_LAST
    };
*************** c_common_nodes_and_builtins ()
*** 3533,3538 ****
--- 3535,3553 ----
  		  tree_cons (NULL_TREE,				\
  			     builtin_types[(int) ARG2],		\
  			     NULL_TREE)));
+
+ #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3)		\
+    builtin_types[(int) ENUM]						\
+     = build_function_type 						\
+       (builtin_types[(int) RETURN],					\
+        tree_cons (NULL_TREE,						\
+ 		  builtin_types[(int) ARG1],				\
+ 		  tree_cons (NULL_TREE,					\
+ 			     builtin_types[(int) ARG2],			\
+ 			     tree_cons (NULL_TREE,			\
+ 					builtin_types[(int) ARG3],	\
+ 					NULL_TREE))));
+
  #define DEF_POINTER_TYPE(ENUM, TYPE)			\
    builtin_types[(int) ENUM]				\
      = build_pointer_type (builtin_types[(int) TYPE]);
*************** c_common_nodes_and_builtins ()
*** 3544,3549 ****
--- 3559,3566 ----
  #undef DEF_FUNCTION_TYPE_4
  #undef DEF_FUNCTION_TYPE_VAR_0
  #undef DEF_FUNCTION_TYPE_VAR_1
+ #undef DEF_FUNCTION_TYPE_VAR_2
+ #undef DEF_FUNCTION_TYPE_VAR_3
  #undef DEF_POINTER_TYPE

    if (!c_attrs_initialized)
Index: java/builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/builtins.c,v
retrieving revision 1.16
diff -c -3 -p -r1.16 builtins.c
*** java/builtins.c	24 Jan 2003 22:07:01 -0000	1.16
--- java/builtins.c	1 Mar 2003 16:24:13 -0000
*************** enum builtin_type
*** 46,51 ****
--- 46,52 ----
  #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
  #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
  #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
+ #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
  #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
  #include "builtin-types.def"
  #undef DEF_PRIMITIVE_TYPE
*************** enum builtin_type
*** 57,62 ****
--- 58,64 ----
  #undef DEF_FUNCTION_TYPE_VAR_0
  #undef DEF_FUNCTION_TYPE_VAR_1
  #undef DEF_FUNCTION_TYPE_VAR_2
+ #undef DEF_FUNCTION_TYPE_VAR_3
  #undef DEF_POINTER_TYPE
    BT_LAST
  };
*************** initialize_builtins (void)
*** 297,307 ****
  #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4)	\
    builtin_types[(int) ENUM]						\
      = define_builtin_type (RETURN, ARG1, ARG2, ARG3, ARG4);
! #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN)				      \
    builtin_types[(int) ENUM] = NULL_TREE;
! #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1)			 \
     builtin_types[(int) ENUM] = NULL_TREE;
  #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2)	\
     builtin_types[(int) ENUM] = NULL_TREE;
  #define DEF_POINTER_TYPE(ENUM, TYPE)			\
    builtin_types[(int) ENUM] = NULL_TREE;
--- 299,311 ----
  #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4)	\
    builtin_types[(int) ENUM]						\
      = define_builtin_type (RETURN, ARG1, ARG2, ARG3, ARG4);
! #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN)			\
    builtin_types[(int) ENUM] = NULL_TREE;
! #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1)		\
     builtin_types[(int) ENUM] = NULL_TREE;
  #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2)	\
+    builtin_types[(int) ENUM] = NULL_TREE;
+ #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3)	\
     builtin_types[(int) ENUM] = NULL_TREE;
  #define DEF_POINTER_TYPE(ENUM, TYPE)			\
    builtin_types[(int) ENUM] = NULL_TREE;
Index: doc/extend.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/extend.texi,v
retrieving revision 1.123
diff -c -3 -p -r1.123 extend.texi
*** doc/extend.texi	26 Feb 2003 03:02:12 -0000	1.123
--- doc/extend.texi	1 Mar 2003 16:24:16 -0000
*************** v4si f (v4si a, v4si b, v4si c)
*** 4591,4606 ****
--- 4591,4612 ----
  @findex powl
  @findex printf
  @findex printf_unlocked
+ @findex putchar
+ @findex puts
  @findex rindex
  @findex round
  @findex roundf
  @findex roundl
+ @findex scanf
  @findex sin
  @findex sinf
  @findex sinl
+ @findex snprintf
+ @findex sprintf
  @findex sqrt
  @findex sqrtf
  @findex sqrtl
+ @findex sscanf
  @findex strcat
  @findex strchr
  @findex strcmp
*************** v4si f (v4si a, v4si b, v4si c)
*** 4617,4622 ****
--- 4623,4633 ----
  @findex trunc
  @findex truncf
  @findex truncl
+ @findex vprintf
+ @findex vscanf
+ @findex vsnprintf
+ @findex vsprintf
+ @findex vsscanf

  GCC provides a large number of built-in functions other than the ones
  mentioned above.  Some of these are for internal use in the processing
*************** mode.
*** 4648,4657 ****

  The ISO C99 functions @code{conj}, @code{conjf}, @code{conjl}, @code{creal},
  @code{crealf}, @code{creall}, @code{cimag}, @code{cimagf}, @code{cimagl},
! @code{_Exit},
! @code{llabs}, @code{imaxabs}, @code{round}, @code{roundf}, @code{roundl},
! @code{trunc}, @code{truncf}, @code{truncl}, @code{nearbyint},
! @code{nearbyintf} and @code{nearbyintl} are handled as built-in functions
  except in strict ISO C90 mode (@option{-ansi} or @option{-std=c89}).

  There are also built-in versions of the ISO C99 functions @code{atan2f},
--- 4659,4670 ----

  The ISO C99 functions @code{conj}, @code{conjf}, @code{conjl}, @code{creal},
  @code{crealf}, @code{creall}, @code{cimag}, @code{cimagf}, @code{cimagl},
! @code{_Exit}, @code{imaxabs}, @code{llabs},
! @code{nearbyint}, @code{nearbyintf}, @code{nearbyintl},
! @code{round}, @code{roundf}, @code{roundl}, @code{snprintf},
! @code{trunc}, @code{truncf}, @code{truncl},
! @code{vscanf}, @code{vsnprintf} and @code{vsscanf}
! are handled as built-in functions
  except in strict ISO C90 mode (@option{-ansi} or @option{-std=c89}).

  There are also built-in versions of the ISO C99 functions @code{atan2f},
*************** The ISO C90 functions @code{abort}, @cod
*** 4669,4678 ****
  @code{exp}, @code{fabs}, @code{floor}, @code{fmod},
  @code{fprintf}, @code{fputs}, @code{labs}, @code{log},
  @code{memcmp}, @code{memcpy}, @code{memset}, @code{pow}, @code{printf},
! @code{sin}, @code{sqrt}, @code{strcat}, @code{strchr}, @code{strcmp},
  @code{strcpy}, @code{strcspn}, @code{strlen}, @code{strncat}, @code{strncmp},
! @code{strncpy}, @code{strpbrk}, @code{strrchr}, @code{strspn}, and
! @code{strstr} are all recognized as built-in functions unless
  @option{-fno-builtin} is specified (or @option{-fno-builtin-@var{function}}
  is specified for an individual function).  All of these functions have
  corresponding versions prefixed with @code{__builtin_}.
--- 4682,4694 ----
  @code{exp}, @code{fabs}, @code{floor}, @code{fmod},
  @code{fprintf}, @code{fputs}, @code{labs}, @code{log},
  @code{memcmp}, @code{memcpy}, @code{memset}, @code{pow}, @code{printf},
! @code{putchar}, @code{puts}, @code{scanf}, @code{sin}, @code{snprintf},
! @code{sprintf}, code{sqrt}, @code{sscanf},
! @code{strcat}, @code{strchr}, @code{strcmp},
  @code{strcpy}, @code{strcspn}, @code{strlen}, @code{strncat}, @code{strncmp},
! @code{strncpy}, @code{strpbrk}, @code{strrchr}, @code{strspn}, @code{strstr},
! @code{vprintf} and @code{vsprintf}
! are all recognized as built-in functions unless
  @option{-fno-builtin} is specified (or @option{-fno-builtin-@var{function}}
  is specified for an individual function).  All of these functions have
  corresponding versions prefixed with @code{__builtin_}.


Index: gcc.dg/format/attr-5.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/format/attr-5.c,v
retrieving revision 1.1
diff -c -3 -p -r1.1 attr-5.c
*** gcc.dg/format/attr-5.c	2 Oct 2001 07:12:24 -0000	1.1
--- gcc.dg/format/attr-5.c	1 Mar 2003 15:55:38 -0000
*************** static int scanf(const char *restrict, .
*** 11,17 ****

  /* This sscanf declaration doesn't have variable arguments, so isn't
     compatible with a format attribute.  */
! extern int sscanf(const char *restrict, const char *restrict, int *);

  void
  foo (const char *s, int *p)
--- 11,17 ----

  /* This sscanf declaration doesn't have variable arguments, so isn't
     compatible with a format attribute.  */
! extern int sscanf(const char *restrict, const char *restrict, int *); /* { dg-warning "conflict" "conflict" } */

  void
  foo (const char *s, int *p)


// Build don't link:
// Test that built-in functions don't warn when prototyped without arguments.
// Origin: PR c++/9367
// Copyright (C) 2003 Free Software Foundation.

extern "C" int snprintf();


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833



More information about the Gcc-patches mailing list