[LLVMdev] interesting possible compiler bug

reed kotler rkotler at mips.com
Mon Oct 1 18:34:43 PDT 2012

This code is essentially from an LTP test ( http://ltp.sourceforge.net/ 
<http://ltp.sourceforge.net/> ).

#include <stdlib.h>

int main() {
   void  *curr;

   do {
     curr = malloc(1);
   } while (curr);

   return 0;


If you compile it with no optimization, it will keep the malloc calls.

If you compile it with -O2, it will create an infinite loop, i.e. 
assuming that malloc always returns a non zero result and the result is 
not used.

~/llvmpb/install/bin/clang loop.c -O2 -S

     .file    "loop.c"
     .globl    main
     .align    16, 0x90
     .type    main, at function
main:                                   # @main
# BB#0:                                 # %entry
     .align    16, 0x90
.LBB0_1:                                # %do.body
                                         # =>This Inner Loop Header: Depth=1
     jmp    .LBB0_1
     .size    main, .Ltmp0-main

     .section    ".note.GNU-stack","", at progbits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121001/98dfdbb2/attachment.html>

More information about the llvm-dev mailing list