This is the mail archive of the gcc-prs@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]

optimization/4130: gcc 3.0 -O2 and printf optimization



>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:


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