1; RUN: llc < %s 2 3 4declare i8* @llvm_gc_allocate(i32) 5declare void @llvm_gc_initialize(i32) 6 7declare void @llvm.gcroot(i8**, i8*) 8declare void @llvm.gcwrite(i8*, i8*, i8**) 9 10define i32 @main() gc "shadow-stack" { 11entry: 12 %A = alloca i8* 13 %B = alloca i8** 14 15 call void @llvm_gc_initialize(i32 1048576) ; Start with 1MB heap 16 17 ;; void *A; 18 call void @llvm.gcroot(i8** %A, i8* null) 19 20 ;; A = gcalloc(10); 21 %Aptr = call i8* @llvm_gc_allocate(i32 10) 22 store i8* %Aptr, i8** %A 23 24 ;; void **B; 25 %tmp.1 = bitcast i8*** %B to i8** 26 call void @llvm.gcroot(i8** %tmp.1, i8* null) 27 28 ;; B = gcalloc(4); 29 %B.upgrd.1 = call i8* @llvm_gc_allocate(i32 8) 30 %tmp.2 = bitcast i8* %B.upgrd.1 to i8** 31 store i8** %tmp.2, i8*** %B 32 33 ;; *B = A; 34 %B.1 = load i8*** %B 35 %A.1 = load i8** %A 36 call void @llvm.gcwrite(i8* %A.1, i8* %B.upgrd.1, i8** %B.1) 37 38 br label %AllocLoop 39 40AllocLoop: 41 %i = phi i32 [ 0, %entry ], [ %indvar.next, %AllocLoop ] 42 ;; Allocated mem: allocated memory is immediately dead. 43 call i8* @llvm_gc_allocate(i32 100) 44 45 %indvar.next = add i32 %i, 1 46 %exitcond = icmp eq i32 %indvar.next, 10000000 47 br i1 %exitcond, label %Exit, label %AllocLoop 48 49Exit: 50 ret i32 0 51} 52 53declare void @__main() 54