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: [email protected]
ReportedBy: [email protected]
CC: [email protected]
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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs