18c1441f8SAlexey Samsonov //
2*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
4*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
58c1441f8SAlexey Samsonov
68c1441f8SAlexey Samsonov // -*- mode:C; c-basic-offset:4; tab-width:4; intent-tabs-mode:nil; -*-
78c1441f8SAlexey Samsonov // CONFIG
88c1441f8SAlexey Samsonov
98c1441f8SAlexey Samsonov #import <stdio.h>
108c1441f8SAlexey Samsonov #import <stdlib.h>
118c1441f8SAlexey Samsonov #import <string.h>
128c1441f8SAlexey Samsonov
138c1441f8SAlexey Samsonov typedef struct {
148c1441f8SAlexey Samsonov unsigned long ps[30];
158c1441f8SAlexey Samsonov int qs[30];
168c1441f8SAlexey Samsonov } BobTheStruct;
178c1441f8SAlexey Samsonov
main(int argc,const char * argv[])188c1441f8SAlexey Samsonov int main (int argc, const char * argv[]) {
198c1441f8SAlexey Samsonov BobTheStruct inny;
208c1441f8SAlexey Samsonov BobTheStruct outty;
218c1441f8SAlexey Samsonov BobTheStruct (^copyStruct)(BobTheStruct);
228c1441f8SAlexey Samsonov int i;
238c1441f8SAlexey Samsonov
248c1441f8SAlexey Samsonov memset(&inny, 0xA5, sizeof(inny));
258c1441f8SAlexey Samsonov memset(&outty, 0x2A, sizeof(outty));
268c1441f8SAlexey Samsonov
278c1441f8SAlexey Samsonov for(i=0; i<30; i++) {
288c1441f8SAlexey Samsonov inny.ps[i] = i * i * i;
298c1441f8SAlexey Samsonov inny.qs[i] = -i * i * i;
308c1441f8SAlexey Samsonov }
318c1441f8SAlexey Samsonov
328c1441f8SAlexey Samsonov copyStruct = ^(BobTheStruct aBigStruct){ return aBigStruct; }; // pass-by-value intrinsically copies the argument
338c1441f8SAlexey Samsonov
348c1441f8SAlexey Samsonov outty = copyStruct(inny);
358c1441f8SAlexey Samsonov
368c1441f8SAlexey Samsonov if ( &inny == &outty ) {
378c1441f8SAlexey Samsonov printf("%s: struct wasn't copied.", argv[0]);
388c1441f8SAlexey Samsonov exit(1);
398c1441f8SAlexey Samsonov }
408c1441f8SAlexey Samsonov for(i=0; i<30; i++) {
418c1441f8SAlexey Samsonov if ( (inny.ps[i] != outty.ps[i]) || (inny.qs[i] != outty.qs[i]) ) {
428c1441f8SAlexey Samsonov printf("%s: struct contents did not match.", argv[0]);
438c1441f8SAlexey Samsonov exit(1);
448c1441f8SAlexey Samsonov }
458c1441f8SAlexey Samsonov }
468c1441f8SAlexey Samsonov
478c1441f8SAlexey Samsonov printf("%s: success\n", argv[0]);
488c1441f8SAlexey Samsonov
498c1441f8SAlexey Samsonov return 0;
508c1441f8SAlexey Samsonov }
51