xref: /aosp_15_r20/external/compiler-rt/test/BlocksRuntime/large-struct.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //
2*7c3d14c8STreehugger Robot //                     The LLVM Compiler Infrastructure
3*7c3d14c8STreehugger Robot //
4*7c3d14c8STreehugger Robot // This file is distributed under the University of Illinois Open Source
5*7c3d14c8STreehugger Robot // License. See LICENSE.TXT for details.
6*7c3d14c8STreehugger Robot 
7*7c3d14c8STreehugger Robot //  -*- mode:C; c-basic-offset:4; tab-width:4; intent-tabs-mode:nil;  -*-
8*7c3d14c8STreehugger Robot // CONFIG
9*7c3d14c8STreehugger Robot 
10*7c3d14c8STreehugger Robot #import <stdio.h>
11*7c3d14c8STreehugger Robot #import <stdlib.h>
12*7c3d14c8STreehugger Robot #import <string.h>
13*7c3d14c8STreehugger Robot 
14*7c3d14c8STreehugger Robot typedef struct {
15*7c3d14c8STreehugger Robot     unsigned long ps[30];
16*7c3d14c8STreehugger Robot     int qs[30];
17*7c3d14c8STreehugger Robot } BobTheStruct;
18*7c3d14c8STreehugger Robot 
main(int argc,const char * argv[])19*7c3d14c8STreehugger Robot int main (int argc, const char * argv[]) {
20*7c3d14c8STreehugger Robot     BobTheStruct inny;
21*7c3d14c8STreehugger Robot     BobTheStruct outty;
22*7c3d14c8STreehugger Robot     BobTheStruct (^copyStruct)(BobTheStruct);
23*7c3d14c8STreehugger Robot     int i;
24*7c3d14c8STreehugger Robot 
25*7c3d14c8STreehugger Robot     memset(&inny, 0xA5, sizeof(inny));
26*7c3d14c8STreehugger Robot     memset(&outty, 0x2A, sizeof(outty));
27*7c3d14c8STreehugger Robot 
28*7c3d14c8STreehugger Robot     for(i=0; i<30; i++) {
29*7c3d14c8STreehugger Robot         inny.ps[i] = i * i * i;
30*7c3d14c8STreehugger Robot         inny.qs[i] = -i * i * i;
31*7c3d14c8STreehugger Robot     }
32*7c3d14c8STreehugger Robot 
33*7c3d14c8STreehugger Robot     copyStruct = ^(BobTheStruct aBigStruct){ return aBigStruct; };  // pass-by-value intrinsically copies the argument
34*7c3d14c8STreehugger Robot 
35*7c3d14c8STreehugger Robot     outty = copyStruct(inny);
36*7c3d14c8STreehugger Robot 
37*7c3d14c8STreehugger Robot     if ( &inny == &outty ) {
38*7c3d14c8STreehugger Robot         printf("%s: struct wasn't copied.", argv[0]);
39*7c3d14c8STreehugger Robot         exit(1);
40*7c3d14c8STreehugger Robot     }
41*7c3d14c8STreehugger Robot     for(i=0; i<30; i++) {
42*7c3d14c8STreehugger Robot         if ( (inny.ps[i] != outty.ps[i]) || (inny.qs[i] != outty.qs[i]) ) {
43*7c3d14c8STreehugger Robot             printf("%s: struct contents did not match.", argv[0]);
44*7c3d14c8STreehugger Robot             exit(1);
45*7c3d14c8STreehugger Robot         }
46*7c3d14c8STreehugger Robot     }
47*7c3d14c8STreehugger Robot 
48*7c3d14c8STreehugger Robot     printf("%s: success\n", argv[0]);
49*7c3d14c8STreehugger Robot 
50*7c3d14c8STreehugger Robot     return 0;
51*7c3d14c8STreehugger Robot }
52