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: PR bootstrap/19818: fix libcpp warnings (take 2)


See the previous discussion on why you can't make GCed stuff 'const'.

You did not answer to Zack's comments then:


> > these data structures are not truly
> > write-once; any pointers contained in them will be changed by saving
> > a PCH.
>
> Sure; however, that happens behind the back of the code that uses this
> data structure.  The 'const' is correctly placed to catch bugs in that
> code, which is what I care about.

I suppose if nobody felt the need to make "source" const, I could just as well add a cast to remove the const when source is set. But I think that this issue ought to be revisited sooner or later.

Ok to commit the attached patch, bootstrapped and regtested powepc-apple-darwin7.7.0?

Paolo
include:
2005-02-08  Paolo Bonzini  <bonzini@gnu.org>

	PR bootstrap/19818
	* ansidecl.h (PARAMS): Guard from redefinition.

libcpp:
2005-02-08  Paolo Bonzini  <bonzini@gnu.org>

	PR bootstrap/19818
	* configure.ac: Check for declaration of basename and getopt.
	* config.in: Regenerate.
	* configure: Regenerate.
	* internal.h (ustrcspn): New.
	* macro.c (create_iso_definition): Fix allocation of memory.
	(padding_token): Add cast to remove const-ness.
	* pch.c (cpp_read_state): Use ustrcspn.

Index: include/ansidecl.h
===================================================================
RCS file: /cvs/gcc/gcc/include/ansidecl.h,v
retrieving revision 1.19
diff -u -p -r1.19 ansidecl.h
--- include/ansidecl.h	5 Sep 2004 02:49:55 -0000	1.19
+++ include/ansidecl.h	10 Feb 2005 08:50:28 -0000
@@ -149,7 +149,12 @@ So instead we use the macro below and te
 #define PTRCONST	void *const
 #define LONG_DOUBLE	long double
 
+/* PARAMS is often defined elsewhere (e.g. by libintl.h), so wrap it in
+   a #ifndef.  */
+#ifndef PARAMS
 #define PARAMS(ARGS)		ARGS
+#endif
+
 #define VPARAMS(ARGS)		ARGS
 #define VA_START(VA_LIST, VAR)	va_start(VA_LIST, VAR)
 
Index: libcpp/configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/configure.ac,v
retrieving revision 1.10
diff -u -p -r1.10 configure.ac
--- libcpp/configure.ac	24 Nov 2004 14:00:37 -0000	1.10
+++ libcpp/configure.ac	10 Feb 2005 08:50:29 -0000
@@ -46,7 +46,7 @@ AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(long)
 AC_CHECK_FUNCS(putc_unlocked fputc_unlocked fputs_unlocked \
         fwrite_unlocked fprintf_unlocked)
-AC_CHECK_DECLS([abort, errno, putc_unlocked, fputc_unlocked,
+AC_CHECK_DECLS([abort, basename, errno, getopt, putc_unlocked, fputc_unlocked,
         fputs_unlocked, fwrite_unlocked, fprintf_unlocked])
 
 # Checks for library functions.
Index: libcpp/internal.h
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/internal.h,v
retrieving revision 1.11
diff -u -p -r1.11 internal.h
--- libcpp/internal.h	2 Jan 2005 01:32:21 -0000	1.11
+++ libcpp/internal.h	10 Feb 2005 08:50:29 -0000
@@ -585,6 +585,9 @@ static inline unsigned char *uxstrdup (c
 static inline unsigned char *ustrchr (const unsigned char *, int);
 static inline int ufputs (const unsigned char *, FILE *);
 
+/* Use a const char for the second parameter since it is usually a literal.  */
+static inline int ustrcspn (const unsigned char *, const char *);
+
 static inline int
 ustrcmp (const unsigned char *s1, const unsigned char *s2)
 {
@@ -597,6 +600,12 @@ ustrncmp (const unsigned char *s1, const
   return strncmp ((const char *)s1, (const char *)s2, n);
 }
 
+static inline int
+ustrcspn (const unsigned char *s1, const char *s2)
+{
+  return strcspn ((const char *)s1, s2);
+}
+
 static inline size_t
 ustrlen (const unsigned char *s1)
 {
Index: libcpp/macro.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/macro.c,v
retrieving revision 1.6
diff -u -p -r1.6 macro.c
--- libcpp/macro.c	2 Jan 2005 01:32:21 -0000	1.6
+++ libcpp/macro.c	10 Feb 2005 08:50:29 -0000
@@ -910,7 +910,10 @@ padding_token (cpp_reader *pfile, const 
   cpp_token *result = _cpp_temp_token (pfile);
 
   result->type = CPP_PADDING;
-  result->val.source = source;
+
+  /* Data in GCed data structures cannot be made const so far, so we
+     need a cast here.  */
+  result->val.source = (cpp_token *) source;
   result->flags = 0;
   return result;
 }
@@ -1416,10 +1419,11 @@ create_iso_definition (cpp_reader *pfile
       /* Success.  Commit or allocate the parameter array.  */
       if (pfile->hash_table->alloc_subobject)
 	{
-	  cpp_token *tokns = pfile->hash_table->alloc_subobject
-	    (sizeof (cpp_token) * macro->paramc);
-	  memcpy (tokns, macro->params, sizeof (cpp_token) * macro->paramc);
-	  macro->params = tokns;
+	  cpp_hashnode **params = pfile->hash_table->alloc_subobject
+	    (sizeof (cpp_hashnode *) * macro->paramc);
+	  memcpy (params, macro->params,
+		  sizeof (cpp_hashnode *) * macro->paramc);
+	  macro->params = params;
 	}
       else
 	BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->params[macro->paramc];
Index: libcpp/pch.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/pch.c,v
retrieving revision 1.4
diff -u -p -r1.4 pch.c
--- libcpp/pch.c	8 Oct 2004 12:50:12 -0000	1.4
+++ libcpp/pch.c	10 Feb 2005 08:50:29 -0000
@@ -653,7 +653,7 @@ cpp_read_state (cpp_reader *r, const cha
       size_t namelen;
       uchar *defn;
 
-      namelen = strcspn (data->defns[i], "( \n");
+      namelen = ustrcspn (data->defns[i], "( \n");
       h = cpp_lookup (r, data->defns[i], namelen);
       defn = data->defns[i] + namelen;
 

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