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: ATTRIBUTE_NONNULL, ATTRIBUTE_NULL_PRINTF and dwarf2asm.h


Whilst reading the 3.3 changes file:
http://gcc.gnu.org/gcc-3.3/changes.html
I noticed the part about the nonnull attribute and it being decoupled
from the printf specifier stuff.

I recalled that some of the printf-style functions in gcc wanted to
also allow a NULL specifier and thus couldn't use ATTRIBUTE_PRINTF in
its old form.  Now we can. :-)

This patch adds new libiberty macros ATTRIBUTE_NONNULL and
ATTRIBUTE_NULL_PRINTF*.  It also adds ATTRIBUTE_NONNULL to the
original ATTRIBUTE_PRINTF so that its behavior is the same regardless
of whether one uses gcc < 3.2 or gcc >= 3.3.

Then I added ATTRIBUTE_NULL_PRINTF on some functions in dwarf2asm.h.

(If anyone knows of other places we could use this, let me know.)


Good news is that there were no new warnings (i.e. dwarf2 format bugs)
as a result of adding the attribute, and this will help ensure that it
remains the case.

Bootstrap now in stage3 on 3.3 and trunk on sparc-sun-solaris2.7.
Assuming no regressions, ok for both?

		Thanks,
		-Kaveh


2003-03-10  Kaveh R. Ghazi  <ghazi at caip dot rutgers dot edu>

include:
	* ansidecl.h (ATTRIBUTE_NONNULL, ATTRIBUTE_NULL_PRINTF,
	ATTRIBUTE_NULL_PRINTF_1, ATTRIBUTE_NULL_PRINTF_2,
	ATTRIBUTE_NULL_PRINTF_3, ATTRIBUTE_NULL_PRINTF_4,
	ATTRIBUTE_NULL_PRINTF_5): New.
	(ATTRIBUTE_PRINTF): Add ATTRIBUTE_NONNULL.

gcc:
	* dwarf2asm.h: Delete obsolete comment.
	(dw2_asm_output_data, dw2_asm_output_delta, dw2_asm_output_offset,
	dw2_asm_output_pcrel, dw2_asm_output_addr,
	dw2_asm_output_addr_rtx, dw2_asm_output_encoded_addr_rtx,
	dw2_asm_output_nstring, dw2_asm_output_data_uleb128,
	dw2_asm_output_data_sleb128, dw2_asm_output_delta_uleb128,
	dw2_asm_output_delta_sleb128): Add ATTRIBUTE_NULL_PRINTF.

diff -rup orig/egcc-CVS20030310/include/ansidecl.h egcc-CVS20030310/include/ansidecl.h
--- orig/egcc-CVS20030310/include/ansidecl.h	2002-10-24 19:36:25.000000000 -0400
+++ egcc-CVS20030310/include/ansidecl.h	2003-03-10 14:04:01.420589000 -0500
@@ -268,8 +268,17 @@ So instead we use the macro below and te
 #define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
 #endif /* ATTRIBUTE_NORETURN */
 
+/* Attribute nonnull was valid as of gcc 3.3.  */
+#ifndef ATTRIBUTE_NONNULL
+# if (GCC_VERSION >= 3003)
+#  define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
+# else
+#  define ATTRIBUTE_NONNULL(m)
+# endif /* GNUC >= 3.3 */
+#endif /* ATTRIBUTE_NONNULL */
+
 #ifndef ATTRIBUTE_PRINTF
-#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
+#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
 #define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
 #define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
 #define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
@@ -277,6 +286,20 @@ So instead we use the macro below and te
 #define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
 #endif /* ATTRIBUTE_PRINTF */
 
+/* NULL format specifiers were accepted as of gcc 3.3.  */
+#ifndef ATTRIBUTE_NULL_PRINTF
+# if (GCC_VERSION >= 3003)
+#  define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
+# else
+#  define ATTRIBUTE_NULL_PRINTF(m, n)
+# endif /* GNUC >= 3.3 */
+# define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2)
+# define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3)
+# define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4)
+# define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5)
+# define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6)
+#endif /* ATTRIBUTE_NULL_PRINTF */
+
 /* We use __extension__ in some places to suppress -pedantic warnings
    about GCC extensions.  This feature didn't work properly before
    gcc 2.8.  */
diff -rup orig/egcc-CVS20030310/gcc/dwarf2asm.h egcc-CVS20030310/gcc/dwarf2asm.h
--- orig/egcc-CVS20030310/gcc/dwarf2asm.h	2001-12-17 10:05:21.000000000 -0500
+++ egcc-CVS20030310/gcc/dwarf2asm.h	2003-03-10 13:23:28.760752000 -0500
@@ -19,60 +19,56 @@ Software Foundation, 59 Temple Place - S
 02111-1307, USA.  */
 
 
-/* ??? Format checking yields "null format string" warnings, which is
-   the way these routines are signaled that there is no associated
-   debug information.  So the attributes are commented out.  */
-
 extern void dw2_assemble_integer	PARAMS ((int, rtx));
 
 extern void dw2_asm_output_data		PARAMS ((int, unsigned HOST_WIDE_INT,
 						 const char *, ...))
-     /* ATTRIBUTE_PRINTF_3 */;
+     ATTRIBUTE_NULL_PRINTF_3;
 
 extern void dw2_asm_output_delta	PARAMS ((int, const char *,
 						 const char *,
 						 const char *, ...))
-     /* ATTRIBUTE_PRINTF_4 */;
+     ATTRIBUTE_NULL_PRINTF_4;
 
 extern void dw2_asm_output_offset	PARAMS ((int, const char *,
 						 const char *, ...))
-     /* ATTRIBUTE_PRINTF_3 */;
+     ATTRIBUTE_NULL_PRINTF_3;
 
 extern void dw2_asm_output_pcrel	PARAMS ((int, const char *,
 						 const char *, ...))
-     /* ATTRIBUTE_PRINTF_3 */;
+     ATTRIBUTE_NULL_PRINTF_3;
 
 extern void dw2_asm_output_addr		PARAMS ((int, const char *,
 						 const char *, ...))
-     /* ATTRIBUTE_PRINTF_3 */;
+     ATTRIBUTE_NULL_PRINTF_3;
 
 extern void dw2_asm_output_addr_rtx	PARAMS ((int, rtx,
 						 const char *, ...))
-     /* ATTRIBUTE_PRINTF_3 */;
+     ATTRIBUTE_NULL_PRINTF_3;
 
 extern void dw2_asm_output_encoded_addr_rtx PARAMS ((int, rtx,
 						     const char *, ...))
-     /* ATTRIBUTE_PRINTF_3 */;
+     ATTRIBUTE_NULL_PRINTF_3;
 
 extern void dw2_asm_output_nstring	PARAMS ((const char *, size_t,
 						 const char *, ...))
-     /* ATTRIBUTE_PRINTF_3 */;
+     ATTRIBUTE_NULL_PRINTF_3;
 
 extern void dw2_asm_output_data_uleb128	PARAMS ((unsigned HOST_WIDE_INT,
 						 const char *, ...))
-     /* ATTRIBUTE_PRINTF_2 */;
+     ATTRIBUTE_NULL_PRINTF_2;
 
 extern void dw2_asm_output_data_sleb128	PARAMS ((HOST_WIDE_INT,
 						 const char *, ...))
-     /* ATTRIBUTE_PRINTF_2 */;
+     ATTRIBUTE_NULL_PRINTF_2;
 
 extern void dw2_asm_output_delta_uleb128 PARAMS ((const char *, const char *,
 						  const char *, ...))
-     /* ATTRIBUTE_PRINTF_3 */;
+     ATTRIBUTE_NULL_PRINTF_3;
 
 extern void dw2_asm_output_delta_sleb128 PARAMS ((const char *, const char *,
 						  const char *, ...))
-     /* ATTRIBUTE_PRINTF_3 */;
+     ATTRIBUTE_NULL_PRINTF_3;
 
 extern int size_of_uleb128		PARAMS ((unsigned HOST_WIDE_INT));
 extern int size_of_sleb128		PARAMS ((HOST_WIDE_INT));


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