xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/cleanup-stack.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i386-unknown-unknown -O3 -emit-llvm %s -o %t
2*f4a2713aSLionel Sambuc // RUN: grep "ret i32 9" %t
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc struct s0 {
5*f4a2713aSLionel Sambuc   int *var;
6*f4a2713aSLionel Sambuc   int addend;
7*f4a2713aSLionel Sambuc };
8*f4a2713aSLionel Sambuc 
f0(struct s0 * p)9*f4a2713aSLionel Sambuc static void f0(struct s0 *p) {
10*f4a2713aSLionel Sambuc   *p->var += p->addend;
11*f4a2713aSLionel Sambuc }
12*f4a2713aSLionel Sambuc 
f1(void)13*f4a2713aSLionel Sambuc int f1(void) {
14*f4a2713aSLionel Sambuc   int var = 0;
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc   {
17*f4a2713aSLionel Sambuc     struct s0 x __attribute__((cleanup(f0))) = { &var, 2 };
18*f4a2713aSLionel Sambuc     struct s0 y __attribute__((cleanup(f0))) = { &var, 3 };
19*f4a2713aSLionel Sambuc     {
20*f4a2713aSLionel Sambuc       struct s0 y __attribute__((cleanup(f0))) = { &var, 4 };
21*f4a2713aSLionel Sambuc     }
22*f4a2713aSLionel Sambuc   }
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc   return var;
25*f4a2713aSLionel Sambuc }
26