[LLVMbugs] [Bug 13694] New: wrong optimizations with -ffreestanding

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Aug 24 23:24:40 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13694

             Bug #: 13694
           Summary: wrong optimizations with -ffreestanding
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: agentprog at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


functions using at least malloc() get wrongly optimized (at least malloc()
noted) in freestanding environment such as musl libc.

steps to reproduce:

1) create a test file:

#include <stdlib.h>

void *f() {
    char *p;

    p = malloc(100);

    if (p[0])
        p[0] = 0;

    return p;
}

int main(int argc, char **argv) {
    char *p = f();

    return 0;
}

2) compile with:

clang -O3 -ffreestanding -S t.c

3) look at t.s and get the 'if' is optimized out.

additional note:
if i use an malloc() stub for this like that:

void *foo(size_t n) {
    static char buf[200];
    return buf + 10;
}

void *f() {
    char *p;

    p = foo(100);

    if (p[0])
        p[0] = 0;

    return p;
}

'if' statement is not optimized out.

expected result: not to optimize 'if' statement out when -ffreestanding is in
use.

this bug causes calloc() implementation in musl libc skip zero fill memory
allocated by musl's malloc().

this was performed with clang from trunk (rev. 162541) with optimization levels
-O3, -Os and -O2 on linux x86.

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