https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103950
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |9.5 Summary|printf("\xff") incorrectly |[9/10/11/12 Regression] |optimized to putchar(-1) |printf("\xff") incorrectly | |optimized to putchar(-1) Known to work| |4.0.0 --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- The optimization was introduced in r0-69361 and so it is a regression from GCC 4.0.0 and before. I think the following will fix the issue: apinski@xeond:~/src/upstream-gcc/gcc/gcc$ git diff gimple-fold.c diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 77c551af942..6f158d301c5 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -3907,7 +3907,7 @@ gimple_fold_builtin_printf (gimple_stmt_iterator *gsi, tree fmt, /* Given printf("c"), (where c is any one character,) convert "c"[0] to an int and pass that to the replacement function. */ - newarg = build_int_cst (integer_type_node, str[0]); + newarg = build_int_cst (integer_type_node, (unsigned char)str[0]); if (fn_putchar) { gcall *repl = gimple_build_call (fn_putchar, 1, newarg);