Bug 33309 - gcc.c:6236: error: passing argument 1 of 'xputenv' discards qualifiers from pointer target type
Summary: gcc.c:6236: error: passing argument 1 of 'xputenv' discards qualifiers from p...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: bootstrap (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Francois-Xavier Coudert
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-05 01:05 UTC by John David Anglin
Modified: 2010-10-27 17:06 UTC (History)
4 users (show)

See Also:
Host: hppa64-hp-hpux11*
Target: hppa64-hp-hpux11*
Build: hppa64-hp-hpux11*
Known to work:
Known to fail: 4.3.0
Last reconfirmed: 2007-09-11 09:38:48


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John David Anglin 2007-09-05 01:05:29 UTC
/test/gnu/gcc/objdir/./prev-gcc/xgcc -B/test/gnu/gcc/objdir/./prev-gcc/
-B/opt/gnu64/gcc/gcc-4.3.0/hppa64-hp-hpux11.11/bin/   -g -O2 -DIN_GCC   -W -Wall
 -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition
 -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros
                             -Wno-overlength-strings -Werror -fno-common   -DHAV
E_CONFIG_H -I. -I. -I../../gcc/gcc -I../../gcc/gcc/. -I../../gcc/gcc/../include
-I../../gcc/gcc/../libcpp/include -I/opt/gnu64/gcc/gcc-4.3.0/include  -I../../gc
c/gcc/../libdecnumber -I../../gcc/gcc/../libdecnumber/dpd -I../libdecnumber    \
  -DSTANDARD_STARTFILE_PREFIX=\"../../../\" -DSTANDARD_EXEC_PREFIX=\"/opt/gnu64/
gcc/gcc-4.3.0/lib/gcc/\" -DSTANDARD_LIBEXEC_PREFIX=\"/opt/gnu64/gcc/gcc-4.3.0/li
bexec/gcc/\" -DDEFAULT_TARGET_VERSION=\"4.3.0\" -DDEFAULT_TARGET_MACHINE=\"hppa6
4-hp-hpux11.11\" -DSTANDARD_BINDIR_PREFIX=\"/opt/gnu64/gcc/gcc-4.3.0/bin/\" -DTO
OLDIR_BASE_PREFIX=\"../../../../\"  `test "X${SHLIB_LINK}" = "X" || test "yes" !
= "yes" || echo "-DENABLE_SHARED_LIBGCC"` \
  -c ../../gcc/gcc/gcc.c -o gcc.o)
cc1: warnings being treated as errors
../../gcc/gcc/gcc.c: In function 'main':
../../gcc/gcc/gcc.c:6236: error: passing argument 1 of 'xputenv' discards qualif
iers from pointer target type

Ugh.
Comment 1 John David Anglin 2007-09-05 01:50:32 UTC
I think I'll let Kaveh fix this one...

On hpux and in libiberty, putenv takes a const char * while on other os's
it takes a char *.  xputenv doesn't do anything that would affect the
constantness of its argument.

Thus, it doesn't seem reasonable to do something ugly to the definition of
INIT_ENVIRONMENT in pa64-hpux.h to resolve this regression.
Comment 2 Kaveh Ghazi 2007-09-05 06:17:08 UTC
(In reply to comment #1)
> I think I'll let Kaveh fix this one...

To what exactly do I owe this honor? :-)

AFAICT, this is a -Wwrite-strings error caused by a patch by FX:
http://gcc.gnu.org/ml/gcc-patches/2007-08/msg02280.html

A quick fix might be to do ASTRDUP on the INIT_ENVIRONMENT string.  It's okay to use stack space for putenv strings here because we're in main().  However I seem to recall a problem with alloca passed as a function argument in some ancient version of gcc.  So it'll need an intermediate tmp variable, or use xstrdup to avoid alloca.

Another option would be to constify xputenv and use CONST_CAST on the argument passed to putenv.

A third option would be to constify xputenv and fixinclude putenv on those platforms where it isn't const.
Comment 3 Francois-Xavier Coudert 2007-09-05 09:53:17 UTC
(In reply to comment #2)
> Another option would be to constify xputenv and use CONST_CAST on the argument
> passed to putenv.

Like this?

Index: gcc.c
===================================================================
--- gcc.c       (revision 128046)
+++ gcc.c       (working copy)
@@ -297,7 +297,7 @@ static void set_spec (const char *, cons
 static struct compiler *lookup_compiler (const char *, size_t, const char *);
 static char *build_search_list (const struct path_prefix *, const char *,
                                bool, bool);
-static void xputenv (char *);
+static void xputenv (const char *);
 static void putenv_from_prefixes (const struct path_prefix *, const char *,
                                  bool);
 static int access_check (const char *, int);
@@ -2602,11 +2602,11 @@ add_to_obstack (char *path, void *data)
 /* Add or change the value of an environment variable, outputting the
    change to standard error if in verbose mode.  */
 static void
-xputenv (char *string)
+xputenv (const char *string)
 {
   if (verbose_flag)
     notice ("%s\n", string);
-  putenv (string);
+  putenv (CONST_CAST (string));
 }

 /* Build a list of search directories from PATHS.
Comment 4 dave 2007-09-05 15:08:08 UTC
Subject: Re:  gcc.c:6236: error: passing argument 1 of 'xputenv' discards qualifiers from pointer target type

> ------- Comment #2 from ghazi at gcc dot gnu dot org  2007-09-05 06:17 -------
> (In reply to comment #1)
> > I think I'll let Kaveh fix this one...
> 
> To what exactly do I owe this honor? :-)

Insufficient research on my part ;(

Dave
Comment 5 Kaveh Ghazi 2007-09-05 16:04:16 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > Another option would be to constify xputenv and use CONST_CAST on the argument
> > passed to putenv.
> Like this?
> +  putenv (CONST_CAST (string));

Almost, CONST_CAST takes a type argument now:

CONST_CAST (char *, string)

Comment 6 dave 2007-09-07 01:50:32 UTC
Subject: Re:  gcc.c:6236: error: passing argument 1 of 'xputenv' discards qualifiers from pointer target type

> > > Another option would be to constify xputenv and use CONST_CAST on the argument
> > > passed to putenv.
> > Like this?
> > +  putenv (CONST_CAST (string));
> 
> Almost, CONST_CAST takes a type argument now:
> 
> CONST_CAST (char *, string)

The change with the above mod works for me on hpux.

Dave
Comment 7 Andreas Tobler 2007-09-10 20:42:01 UTC
What is the status here?
I tested the patch below on hppa64-hp-hpux11.11, i686-pc-linux-gnu and i686-apple-darwin8. It brings the pa target past the failure. The others completed bootstrap. I'm not able to test on the other targets I have access to since they are blocked by 32283.

Index: gcc.c
===================================================================
--- gcc.c	(revision 128287)
+++ gcc.c	(working copy)
@@ -297,7 +297,7 @@
 static struct compiler *lookup_compiler (const char *, size_t, const char *);
 static char *build_search_list (const struct path_prefix *, const char *,
 				bool, bool);
-static void xputenv (char *);
+static void xputenv (const char *);
 static void putenv_from_prefixes (const struct path_prefix *, const char *,
 				  bool);
 static int access_check (const char *, int);
@@ -2602,11 +2602,11 @@
 /* Add or change the value of an environment variable, outputting the
    change to standard error if in verbose mode.  */
 static void
-xputenv (char *string)
+xputenv (const char *string)
 {
   if (verbose_flag)
     notice ("%s\n", string);
-  putenv (string);
+  putenv (CONST_CAST (char *, string));
 }
 
 /* Build a list of search directories from PATHS.
Comment 8 dave 2007-09-10 21:30:04 UTC
Subject: Re:  gcc.c:6236: error: passing argument 1 of 'xputenv' discards qualifiers from pointer target type

> What is the status here?
> I tested the patch below on hppa64-hp-hpux11.11, i686-pc-linux-gnu and
> i686-apple-darwin8. It brings the pa target past the failure. The others
> completed bootstrap. I'm not able to test on the other targets I have access to
> since they are blocked by 32283.

Your change is the same as I've been using.  I guess someone needs
to do it.  Want to do it?  I'm heading home at the moment.

Dave
Comment 9 Andreas Tobler 2007-09-10 21:34:03 UTC
It is the same, I just wanted to summarize in patch form. If we have an approval then I can commit asap.
Kaveh?

I'm heading towards bed ;)
Comment 10 Kaveh Ghazi 2007-09-11 06:43:59 UTC
(In reply to comment #9)
> It is the same, I just wanted to summarize in patch form. If we have an
> approval then I can commit asap.
> Kaveh?

I can't approve it, but it looks correct to me.
Comment 11 Francois-Xavier Coudert 2007-09-11 09:38:48 UTC
(In reply to comment #9)
> It is the same, I just wanted to summarize in patch form. If we have an
> approval then I can commit asap.

Sorry for being so slow on that one, I only have limited net access. I have submitted the patch for approval (http://gcc.gnu.org/ml/gcc-patches/2007-09/msg00954.html) since Kaveh can't approve it.
Comment 12 Francois-Xavier Coudert 2007-09-13 10:10:22 UTC
Subject: Bug 33309

Author: fxcoudert
Date: Thu Sep 13 10:10:11 2007
New Revision: 128457

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128457
Log:
	PR driver/33309
	* gcc.c (xputenv): Make argument const, and use CONST_CAST.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gcc.c

Comment 13 Francois-Xavier Coudert 2007-09-13 10:10:43 UTC
Fixed.