Skip to content

Instantly share code, notes, and snippets.

@imasahiro
Last active September 29, 2015 04:37
Show Gist options
  • Save imasahiro/1547164 to your computer and use it in GitHub Desktop.
Save imasahiro/1547164 to your computer and use it in GitHub Desktop.
llvm bug?
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const* argv[])
{
while(1) {
void *a = alloca(1024);
fprintf(stderr, "%p\n", a);
}
return 0;
}
; ModuleID = 'alloca.cpp'
%struct.x = type { i32 }
define void @f(%struct.x* nocapture %x) nounwind uwtable noinline ssp {
ret void
}
define i32 @main(i32 %argc, i8** nocapture %argv) nounwind uwtable ssp {
br label %1
; <label>:1 ; preds = %1, %0
%i.01 = phi i32 [ 0, %0 ], [ %2, %1 ]
%x = alloca %struct.x, align 4
call void @f(%struct.x* %x)
%2 = add nsw i32 %i.01, 1
%exitcond = icmp eq i32 %2, 6000000
br i1 %exitcond, label %3, label %1
; <label>:3 ; preds = %1
ret i32 0
}
; ModuleID = 'alloca.cpp'
%struct.x = type { i32 }
define void @f(%struct.x* nocapture %x) nounwind uwtable noinline ssp {
entry:
ret void
}
define i32 @main(i32 %argc, i8** nocapture %argv) nounwind uwtable ssp {
entry:
%x = alloca %struct.x, align 4
br label %for.body
for.body: ; preds = %for.body, %entry
%i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
call void @f(%struct.x* %x)
%inc = add nsw i32 %i.01, 1
%exitcond = icmp eq i32 %inc, 600000
br i1 %exitcond, label %for.end, label %for.body
for.end: ; preds = %for.body
ret i32 0
}
$ gdb -arg lli alloca.ll
(gdb) r
Starting program: /usr/local/bin/lli alloca.ll
Reading symbols for shared libraries ++........................ done
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00007fff5f3ffff8
0x000000010232502e in ?? ()
(gdb) bt
#0 0x000000010232502e in ?? ()
#1 0x000000010000ecb4 in llvm::JIT::runFunction (this=0x102402fd0, F=0x102401c00, ArgValues=@0x7fff5fbff0a0) at /Users/masa/src/llvm/lib/ExecutionEngine/JIT/JIT.cpp:428
#2 0x00000001001a0954 in llvm::ExecutionEngine::runFunctionAsMain (this=0x102402fd0, Fn=0x102401c00, argv=@0x100d37318, envp=0x7fff5fbff4b8) at /Users/masa/src/llvm/lib/ExecutionEngine/ExecutionEngine.cpp:398
#3 0x00000001000029c5 in main (argc=2, argv=0x7fff5fbff4a0, envp=0x7fff5fbff4b8) at /Users/masa/src/llvm/tools/lli/lli.cpp:286
(gdb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment