public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: optimization/4130: gcc 3.0 -O2 and printf optimization
@ 2002-04-03  0:20 rth
  0 siblings, 0 replies; 5+ messages in thread
From: rth @ 2002-04-03  0:20 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, rjk

Synopsis: gcc 3.0 -O2 and printf optimization

State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Wed Apr  3 00:20:49 2002
State-Changed-Why:
    According to Uli Drepper, whom I consider an authority in this area:
    
       The handling of byte sequences which are not valid in the current locale
       is unspecified.  Either result is valid.  There is the different result
       but people writing incorrect code should not get into to way of
       optimizing code.  And there always is the opportunity to compile with -O0.
    
    Although -fno-builtin-printf is certainly more palletable
    than -O0.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=4130


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: optimization/4130: gcc 3.0 -O2 and printf optimization
@ 2002-04-03 10:46 Richard Henderson
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2002-04-03 10:46 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR optimization/4130; it has been noted by GNATS.

From: Richard Henderson <rth@redhat.com>
To: Richard Kettlewell <rjk@greenend.org.uk>
Cc: gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Subject: Re: optimization/4130: gcc 3.0 -O2 and printf optimization
Date: Wed, 3 Apr 2002 10:37:24 -0800

 ----- Forwarded message from Ulrich Drepper <drepper@redhat.com> -----
 
 > My copy of the draft standard says:
 > 
 >     An encoding error occurs if the character sequence presented to
 >     the underlying mbrtowc function does not form a valid
 >     (generalized) multibyte character, or if the code value passed to
 >     the underlying wcrtomb does not correspond to a valid
 >     (generalized) multibyte character. The wide-character input/output
 >     functions and the byte input/output functions store the value of
 >     the macro EILSEQ in errno if and only if an encoding error occurs.
 > 
 > And:
 > 
 >     The printf function returns the number of characters transmitted,
 >     or a negative value if an output or encoding error occurred.
 
 This has nothing to do with the problem.  It applies to the strings
 which are passed in for "%s" etc.  The fprintf() definition says that
 the format string is a multibyte character string.  If this is violated
 (e.g., if there is an invalid character) the result in unspecified.
 
 Any format string (and the arguments to puts, fputs, etc) have to be
 scrutinized by the compiler.  The compiler has to know what encoding the
 file uses.  If it finds an invalid multibyte character it must report
 this.  If the compilation succeeds the result can be expected to be
 valid.
 
 Now one can argue that gcc should actually do these tests (what is not
 the case) but it's unrelated to the problem at hand.
 
 ----- End forwarded message -----


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: optimization/4130: gcc 3.0 -O2 and printf optimization
@ 2002-04-03 10:26 Richard Henderson
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2002-04-03 10:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR optimization/4130; it has been noted by GNATS.

From: Richard Henderson <rth@redhat.com>
To: Richard Kettlewell <rjk@greenend.org.uk>
Cc: gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Subject: Re: optimization/4130: gcc 3.0 -O2 and printf optimization
Date: Wed, 3 Apr 2002 10:23:13 -0800

 ----- Forwarded message from "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> -----
 
 In addition, the builtin printf optimization (really all stdio
 builtins) are not performed if the return value is examined.  This is
 specifically to address the particular problem of how these functions
 all differently handle return values and errno.  So if you're actually
 going to examine errno, you should do it as I've done below.  (Code
 rewritten from the example provided in the PR):
 
  > #include <stdio.h>
  > #include <errno.h>
  > int main(void)
  > {
  >   if (printf ("foo\xC0\n") < 0)
  >     perror("printf");
  >   return 0;
  > }
 
 or something similar.  In this case, the optimization to `puts' is not
 done.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: optimization/4130: gcc 3.0 -O2 and printf optimization
@ 2002-04-03  2:36 Richard Kettlewell
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Kettlewell @ 2002-04-03  2:36 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR optimization/4130; it has been noted by GNATS.

From: Richard Kettlewell <rjk@greenend.org.uk>
To: rth@gcc.gnu.org,
    gcc-bugs@gcc.gnu.org,
    gcc-prs@gcc.gnu.org,
    nobody@gcc.gnu.org,
    gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: optimization/4130: gcc 3.0 -O2 and printf optimization
Date: Wed, 3 Apr 2002 11:25:54 +0100

 rth@gcc.gnu.org writes:
 > Synopsis: gcc 3.0 -O2 and printf optimization
 > 
 > State-Changed-From-To: open->closed
 > State-Changed-By: rth
 > State-Changed-When: Wed Apr  3 00:20:49 2002
 > State-Changed-Why:
 >     According to Uli Drepper, whom I consider an authority in this area:
 >     
 >        The handling of byte sequences which are not valid in the current locale
 >        is unspecified.  Either result is valid.  There is the different result
 >        but people writing incorrect code should not get into to way of
 >        optimizing code.  And there always is the opportunity to compile with -O0.
 >     
 >     Although -fno-builtin-printf is certainly more palletable
 >     than -O0.
 > 
 > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=4130
 
 My copy of the draft standard says:
 
     An encoding error occurs if the character sequence presented to
     the underlying mbrtowc function does not form a valid
     (generalized) multibyte character, or if the code value passed to
     the underlying wcrtomb does not correspond to a valid
     (generalized) multibyte character. The wide-character input/output
     functions and the byte input/output functions store the value of
     the macro EILSEQ in errno if and only if an encoding error occurs.
 
 And:
 
     The printf function returns the number of characters transmitted,
     or a negative value if an output or encoding error occurred.
 
 Granted this may have changed between the draft and the standard, but
 it looks quite adequately specified to me.
 
 ttfn/rjk
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* optimization/4130: gcc 3.0 -O2 and printf optimization
@ 2001-08-26  3:36 Richard Kettlewell
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Kettlewell @ 2001-08-26  3:36 UTC (permalink / raw)
  To: gcc-gnats

>Number:         4130
>Category:       optimization
>Synopsis:       gcc 3.0 -O2 and printf optimization
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sun Aug 26 03:36:03 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Richard Kettlewell
>Release:        3.0
>Organization:
>Environment:
System: Linux lyonesse 2.2.19 #1 Mon Apr 16 14:07:32 BST 2001 i686 unknown
Architecture: i686


host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /home/richard/junk/gcc-3.0/gcc-3.0/configure --prefix=/usr/local/gcc-3.0 --enable-version-specific-runtime-libs

lyonesse$ dpkg -l libc6|tail -1
ii  libc6          2.2.4-1        GNU C Library: Shared libraries and Timezone

>Description:

gcc will optimize some printf() calls into puts() calls.  However it
does not take into account the fact that (at least on this
platformq) printf() and puts() behave differently when the argument
string contains invalid multibyte character sequences: printf() sets
errno to EILSEQ, but puts() does not.

>How-To-Repeat:

Here is my test program:

    #include <stdio.h>
    #include <errno.h>

    int main(void) {
      errno = 0;
      printf("foo\xC0\n");
      if(errno)
	perror("printf");
      return 0;
    }

Here is how I compiled it:

    lyonesse$ /usr/local/gcc-3.0/bin/gcc -O0 -o t0 t.c
    lyonesse$ /usr/local/gcc-3.0/bin/gcc -O2 -o t2 t.c

Here is what the output looks like (with \xC0 replaced with a <C0>).

    lyonesse$ ./t0
    foo<C0>
    printf: Invalid or incomplete multibyte or wide character
    lyonesse$ ./t2
    foo<C0>

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-04-03 18:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-03  0:20 optimization/4130: gcc 3.0 -O2 and printf optimization rth
  -- strict thread matches above, loose matches on Subject: below --
2002-04-03 10:46 Richard Henderson
2002-04-03 10:26 Richard Henderson
2002-04-03  2:36 Richard Kettlewell
2001-08-26  3:36 Richard Kettlewell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).