2009-09-09 00:09:15 +00:00
|
|
|
; RUN: llc < %s
|
2004-11-06 21:11:04 +00:00
|
|
|
|
2004-05-23 21:24:50 +00:00
|
|
|
|
2007-12-09 15:03:01 +00:00
|
|
|
declare i8* @llvm_gc_allocate(i32)
|
|
|
|
declare void @llvm_gc_initialize(i32)
|
2004-05-23 21:24:50 +00:00
|
|
|
|
2007-12-09 15:03:01 +00:00
|
|
|
declare void @llvm.gcroot(i8**, i8*)
|
|
|
|
declare void @llvm.gcwrite(i8*, i8*, i8**)
|
2004-05-23 21:24:50 +00:00
|
|
|
|
2007-12-10 03:18:06 +00:00
|
|
|
define i32 @main() gc "shadow-stack" {
|
2004-05-23 21:24:50 +00:00
|
|
|
entry:
|
2007-12-09 15:03:01 +00:00
|
|
|
%A = alloca i8*
|
|
|
|
%B = alloca i8**
|
2004-05-23 21:24:50 +00:00
|
|
|
|
2007-12-09 15:03:01 +00:00
|
|
|
call void @llvm_gc_initialize(i32 1048576) ; Start with 1MB heap
|
2004-05-23 21:24:50 +00:00
|
|
|
|
|
|
|
;; void *A;
|
2007-12-09 15:03:01 +00:00
|
|
|
call void @llvm.gcroot(i8** %A, i8* null)
|
2004-05-23 21:24:50 +00:00
|
|
|
|
|
|
|
;; A = gcalloc(10);
|
2007-12-09 15:03:01 +00:00
|
|
|
%Aptr = call i8* @llvm_gc_allocate(i32 10)
|
|
|
|
store i8* %Aptr, i8** %A
|
2004-05-23 21:24:50 +00:00
|
|
|
|
|
|
|
;; void **B;
|
2007-12-09 15:03:01 +00:00
|
|
|
%tmp.1 = bitcast i8*** %B to i8**
|
|
|
|
call void @llvm.gcroot(i8** %tmp.1, i8* null)
|
2004-05-23 21:24:50 +00:00
|
|
|
|
|
|
|
;; B = gcalloc(4);
|
2007-12-09 15:03:01 +00:00
|
|
|
%B.upgrd.1 = call i8* @llvm_gc_allocate(i32 8)
|
|
|
|
%tmp.2 = bitcast i8* %B.upgrd.1 to i8**
|
|
|
|
store i8** %tmp.2, i8*** %B
|
2004-05-23 21:24:50 +00:00
|
|
|
|
|
|
|
;; *B = A;
|
2007-12-09 15:03:01 +00:00
|
|
|
%B.1 = load i8*** %B
|
|
|
|
%A.1 = load i8** %A
|
|
|
|
call void @llvm.gcwrite(i8* %A.1, i8* %B.upgrd.1, i8** %B.1)
|
2004-05-23 21:24:50 +00:00
|
|
|
|
|
|
|
br label %AllocLoop
|
|
|
|
|
|
|
|
AllocLoop:
|
2007-12-09 15:03:01 +00:00
|
|
|
%i = phi i32 [ 0, %entry ], [ %indvar.next, %AllocLoop ]
|
2004-05-23 21:24:50 +00:00
|
|
|
;; Allocated mem: allocated memory is immediately dead.
|
2007-12-09 15:03:01 +00:00
|
|
|
call i8* @llvm_gc_allocate(i32 100)
|
2004-05-23 21:24:50 +00:00
|
|
|
|
2007-12-09 15:03:01 +00:00
|
|
|
%indvar.next = add i32 %i, 1
|
|
|
|
%exitcond = icmp eq i32 %indvar.next, 10000000
|
|
|
|
br i1 %exitcond, label %Exit, label %AllocLoop
|
2004-05-23 21:24:50 +00:00
|
|
|
|
|
|
|
Exit:
|
2007-12-09 15:03:01 +00:00
|
|
|
ret i32 0
|
2004-05-23 21:24:50 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 15:03:01 +00:00
|
|
|
declare void @__main()
|