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