[LLVMbugs] [Bug 5104] New: printf returns 1 even when it fails if -simplify-libcalls is used

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Wed Sep 30 01:56:08 PDT 2009


           Summary: printf returns 1 even when it fails if -simplify-
                    libcalls is used
           Product: new-bugs
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: timo.lindfors at iki.fi
                CC: llvmbugs at cs.uiuc.edu

Created an attachment (id=3589)
 --> (http://llvm.org/bugs/attachment.cgi?id=3589)
testcase to reproduce the bug

Steps to reproduce:
1) (testcase also as attachment)
cat > printf-retval.c <<EOF 
#include <stdio.h>

int main(int argc, char *argv[]) {
    int ret;

    ret = printf("%c", 'A');
    fprintf(stderr, "printf returned %d\n", ret);
    return 0;
2) clang -O0 printf-retval.c && ./a.out
3) clang -O3 printf-retval.c && ./a.out

Expected results:
2 & 3) optimization does not change the return value of printf. It always
returns a negative value on failure. stdout is closed so it will fail.

Actual results:
2) printf returned -1
3) printf returned 1

More info:
1) It seems lib/Transforms/Scalar/SimplifyLibCalls.cpp converts printf to
putchar in this case and ignores the return value of putchar completely.
2) The attached patch llvm-simplifylibcalls-putchar-retval1.patch works for me
but probably needs to be polished by somebody more familiar with llvm

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list