xref: /aosp_15_r20/external/compiler-rt/test/BlocksRuntime/structmember.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 /*
8*7c3d14c8STreehugger Robot  *  structmember.c
9*7c3d14c8STreehugger Robot  *  testObjects
10*7c3d14c8STreehugger Robot  *
11*7c3d14c8STreehugger Robot  *  Created by Blaine Garst on 9/30/08.
12*7c3d14c8STreehugger Robot  *  CONFIG
13*7c3d14c8STreehugger Robot  */
14*7c3d14c8STreehugger Robot #include <Block.h>
15*7c3d14c8STreehugger Robot #include <Block_private.h>
16*7c3d14c8STreehugger Robot #include <stdio.h>
17*7c3d14c8STreehugger Robot 
18*7c3d14c8STreehugger Robot // CONFIG
19*7c3d14c8STreehugger Robot 
main(int argc,char * argv[])20*7c3d14c8STreehugger Robot int main(int argc, char *argv[]) {
21*7c3d14c8STreehugger Robot     struct stuff {
22*7c3d14c8STreehugger Robot         long int a;
23*7c3d14c8STreehugger Robot         long int b;
24*7c3d14c8STreehugger Robot         long int c;
25*7c3d14c8STreehugger Robot     } localStuff = { 10, 20, 30 };
26*7c3d14c8STreehugger Robot     int d;
27*7c3d14c8STreehugger Robot 
28*7c3d14c8STreehugger Robot     void (^a)(void) = ^ { printf("d is %d", d); };
29*7c3d14c8STreehugger Robot     void (^b)(void) = ^ { printf("d is %d, localStuff.a is %lu", d, localStuff.a); };
30*7c3d14c8STreehugger Robot 
31*7c3d14c8STreehugger Robot     unsigned nominalsize = Block_size(b) - Block_size(a);
32*7c3d14c8STreehugger Robot #if __cplusplus__
33*7c3d14c8STreehugger Robot     // need copy+dispose helper for C++ structures
34*7c3d14c8STreehugger Robot     nominalsize += 2*sizeof(void*);
35*7c3d14c8STreehugger Robot #endif
36*7c3d14c8STreehugger Robot     if ((Block_size(b) - Block_size(a)) != nominalsize) {
37*7c3d14c8STreehugger Robot         printf("sizeof a is %ld, sizeof b is %ld, expected %d\n", Block_size(a), Block_size(b), nominalsize);
38*7c3d14c8STreehugger Robot         printf("dump of b is %s\n", _Block_dump(b));
39*7c3d14c8STreehugger Robot         return 1;
40*7c3d14c8STreehugger Robot     }
41*7c3d14c8STreehugger Robot     printf("%s: Success\n", argv[0]);
42*7c3d14c8STreehugger Robot     return 0;
43*7c3d14c8STreehugger Robot }
44*7c3d14c8STreehugger Robot 
45*7c3d14c8STreehugger Robot 
46