With a program compiled with e.g. -O2 -fexec-charset=IBM1047, the builtin
handlers for printf and fprintf get confused because they check for matching
stuff in the format string like "%s", "%s\n", "%c" and trailing "\n" using the
host's charset values.  So they don't match correctly when compiling strings in
the target charset and thus fail to do the appropriate transformations.  This
is merely a slight pessimization.

However what's worse is they'll do incorrect transformations if the user's
program happens to have matching strings.  E.g.

  printf ("hello world\012");

In the above, "\012" is ascii "\n" but it's something else in other charsets. 
However, GCC will still transform this call into puts with the "\012" stripped
off.  This yields "wrong code".


-- 
           Summary: [3.4/4.0/4.1/4.2] builtin printf/fprintf is confused by
                    -fexec-charset
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Keywords: wrong-code, missed-optimization
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ghazi at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25120

Reply via email to