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 int a;
158c1441f8SAlexey Samsonov int b;
168c1441f8SAlexey Samsonov } MiniStruct;
178c1441f8SAlexey Samsonov
main(int argc,const char * argv[])188c1441f8SAlexey Samsonov int main (int argc, const char * argv[]) {
198c1441f8SAlexey Samsonov MiniStruct inny;
208c1441f8SAlexey Samsonov MiniStruct outty;
218c1441f8SAlexey Samsonov MiniStruct (^copyStruct)(MiniStruct);
228c1441f8SAlexey Samsonov
238c1441f8SAlexey Samsonov memset(&inny, 0xA5, sizeof(inny));
248c1441f8SAlexey Samsonov memset(&outty, 0x2A, sizeof(outty));
258c1441f8SAlexey Samsonov
268c1441f8SAlexey Samsonov inny.a = 12;
278c1441f8SAlexey Samsonov inny.b = 42;
288c1441f8SAlexey Samsonov
298c1441f8SAlexey Samsonov copyStruct = ^(MiniStruct aTinyStruct){ return aTinyStruct; }; // pass-by-value intrinsically copies the argument
308c1441f8SAlexey Samsonov
318c1441f8SAlexey Samsonov outty = copyStruct(inny);
328c1441f8SAlexey Samsonov
338c1441f8SAlexey Samsonov if ( &inny == &outty ) {
348c1441f8SAlexey Samsonov printf("%s: struct wasn't copied.", argv[0]);
358c1441f8SAlexey Samsonov exit(1);
368c1441f8SAlexey Samsonov }
378c1441f8SAlexey Samsonov if ( (inny.a != outty.a) || (inny.b != outty.b) ) {
388c1441f8SAlexey Samsonov printf("%s: struct contents did not match.", argv[0]);
398c1441f8SAlexey Samsonov exit(1);
408c1441f8SAlexey Samsonov }
418c1441f8SAlexey Samsonov
428c1441f8SAlexey Samsonov printf("%s: success\n", argv[0]);
438c1441f8SAlexey Samsonov return 0;
448c1441f8SAlexey Samsonov }
45