Home | History | Annotate | Download | only in X86
      1 ; RUN: llc < %s | FileCheck %s
      2 target triple = "x86_64-apple-macosx10.4.0"
      3 
      4 ; __stack_chk_guard must be loaded for twice, once for setting up the canary,
      5 ; another time for performing the check. It is because if we reuse the same
      6 ; stack guard value, it may get spilled to the stack, then the for loop may
      7 ; corrupt it.
      8 ;
      9 ; bool Bar(int*);
     10 ; bool Foo(int n) {
     11 ;   int a[10];
     12 ;   for (int i = 0; i < n; i++) {
     13 ;     a[i] = 0;
     14 ;   }
     15 ;   return Bar(a);
     16 ; }
     17 ;
     18 ; CHECK: movq ___stack_chk_guard
     19 ; CHECK: movq ___stack_chk_guard
     20 define zeroext i1 @_Z3Fooi(i32 %n) sspstrong {
     21 entry:
     22   %n.addr = alloca i32, align 4
     23   %a = alloca [10 x i32], align 16
     24   %i = alloca i32, align 4
     25   store i32 %n, i32* %n.addr, align 4
     26   store i32 0, i32* %i, align 4
     27   br label %for.cond
     28 
     29 for.cond:                                         ; preds = %for.inc, %entry
     30   %tmp = load i32, i32* %i, align 4
     31   %tmp1 = load i32, i32* %n.addr, align 4
     32   %cmp = icmp slt i32 %tmp, %tmp1
     33   br i1 %cmp, label %for.body, label %for.end
     34 
     35 for.body:                                         ; preds = %for.cond
     36   %tmp2 = load i32, i32* %i, align 4
     37   %idxprom = sext i32 %tmp2 to i64
     38   %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %a, i64 0, i64 %idxprom
     39   store i32 0, i32* %arrayidx, align 4
     40   br label %for.inc
     41 
     42 for.inc:                                          ; preds = %for.body
     43   %tmp3 = load i32, i32* %i, align 4
     44   %inc = add nsw i32 %tmp3, 1
     45   store i32 %inc, i32* %i, align 4
     46   br label %for.cond
     47 
     48 for.end:                                          ; preds = %for.cond
     49   %arraydecay = getelementptr inbounds [10 x i32], [10 x i32]* %a, i32 0, i32 0
     50   %call = call zeroext i1 @_Z3BarPi(i32* %arraydecay)
     51   ret i1 %call
     52 }
     53 
     54 declare zeroext i1 @_Z3BarPi(i32*)
     55