-
Notifications
You must be signed in to change notification settings - Fork 206
/
cconv_more.t
697 lines (623 loc) · 21 KB
/
cconv_more.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
-- This is an attempt to be more systematic about checking Terra's
-- calling convention support, particularly against C.
--
-- The test covers:
--
-- * Pass no arguments and return void.
--
-- * Pass/return an empty struct.
--
-- * For T in {uint8, int16, int32, int64, float, double,
-- uint8[2], int16[2], int32[2], int64[2], float[2], double[2]}:
-- 1. Pass 1..N arguments of type T, and return T.
-- 2. Pass (and return) a single struct argument with 1..N fields of type T.
-- 3. Pass two struct arguments, as above, and return same struct.
--
-- * As above, but with arguments/fields picked from a rotating set of types.
--
-- * Note: arrays (uint8[2], etc.) passed as individual arguments (not struct
-- fields) are wrapped in a single-field struct because otherwise C arrays
-- are passed by reference. While Terra is capable of passing such types by
-- value, C is not, so there is no way to do a comparison.
--
-- A couple notable features (especially compared to cconv.t):
--
-- * The tests verify that structs are passed by value, ensuring
-- modifications within the callee do not affect the caller.
--
-- * As compared to cconv.t, this test verifies that Terra can call both
-- itself and C. The latter is particularly important for ensuring we match
-- the ABI of the system C compiler.
--
-- * As a bonus, the use of C enables comparisons between Clang's and
-- Terra's output. A command to generate the LLVM IR is shown (commented)
-- at the bottom of the file.
local MAX_N = 12 -- Needs to be <= 23 to avoid overflowing uint8.
local MAX_ARRAY_N = 4
local ffi = require("ffi")
if ffi.arch == "x64" then
MAX_N = 9 -- https://github.com/terralang/terra/issues/576
elseif ffi.arch == "arm64" and ffi.os == "OSX" then
MAX_N = 9 -- https://github.com/terralang/terra/issues/627
end
local ctypes = {
[uint8] = "uint8_t",
[int16] = "int16_t",
[int32] = "int32_t",
[int64] = "int64_t",
[float] = "float",
[double] = "double",
}
local function lookup_scalar(typ)
if typ:isarray() then
return lookup_scalar(typ.type) .. "_" .. tostring(typ.N)
end
return ctypes[typ]
end
local function lookup_scalar_base(typ)
if typ:isarray() then
return lookup_scalar_base(typ.type)
end
return ctypes[typ]
end
local function lookup_field(typ)
if not typ then return end
if typ:isarray() then
local prefix, suffix = lookup_field(typ.type)
return prefix, suffix .. "[" .. typ.N .. "]"
end
return ctypes[typ], ""
end
local function get_type_in_rotation(types, i)
return types[((i - 1) % #types) + 1]
end
local function generate_array_wrapper(typ, N)
local name = lookup_scalar(typ) .. "_"
local parts = terralib.newlist({"typedef struct " .. name .. N .. " {"})
local prefix, suffix = lookup_field(typ[N])
parts:insert(prefix .. " x" .. suffix .. ";")
parts:insert("} " .. name .. N .. ";")
return parts:concat(" ")
end
local function generate_uniform_struct(name, typ, N)
local parts = terralib.newlist({"typedef struct " .. name .. N .. " {"})
local prefix, suffix = lookup_field(typ)
for i = 1, N do
parts:insert(prefix .. " f" .. i .. suffix .. ";")
end
parts:insert("} " .. name .. N .. ";")
return parts:concat(" ")
end
local function generate_nonuniform_struct(name, types, N)
local parts = terralib.newlist({"typedef struct " .. name .. N .. " {"})
for i = 1, N do
local typ = get_type_in_rotation(types, i)
local prefix, suffix = lookup_field(typ)
parts:insert(prefix .. " f" .. i .. suffix .. ";")
end
parts:insert("} " .. name .. N .. ";")
return parts:concat(" ")
end
local noinline = "__attribute__ ((noinline)) "
local function generate_void_function(name)
return noinline .. "void " .. name .. "() {}"
end
local function generate_scalar_exprs(argname, typ, exprlist)
if typ:isarray() then
for j = 0, typ.N-1 do
exprlist:insert(argname .. ".x[" .. j .. "]")
end
else
exprlist:insert(argname)
end
end
local function generate_uniform_scalar_function(name, typ, N)
local arglist = terralib.newlist()
for i = 1, N do
arglist:insert(lookup_scalar(typ) .. " x" .. i)
end
local exprlist = terralib.newlist()
for i = 1, N do
generate_scalar_exprs("x" .. i, typ, exprlist)
end
return noinline .. lookup_scalar_base(typ) .. " " .. name .. N .. "(" .. arglist:concat(", ") .. ") { return " .. exprlist:concat(" + ") .. "; }"
end
local function generate_nonuniform_scalar_function(name, types, N)
local arglist = terralib.newlist()
for i = 1, N do
local typ = get_type_in_rotation(types, i)
arglist:insert(lookup_scalar(typ) .. " x" .. i)
end
local exprlist = terralib.newlist()
for i = 1, N do
local typ = get_type_in_rotation(types, i)
generate_scalar_exprs("x" .. i, typ, exprlist)
end
return noinline .. "double " .. name .. N .. "(" .. arglist:concat(", ") .. ") { return " .. exprlist:concat(" + ") .. "; }"
end
local function generate_aggregate_one_field_stat(field, inc, typ, statlist)
if typ:isarray() then
for j = 0, typ.N-1 do
statlist:insert(field .. "[" .. j .. "] += " .. inc .. ";")
end
else
statlist:insert(field .. " += " .. inc .. ";")
end
end
local function generate_uniform_aggregate_one_arg_function(name, aggname, typ, N)
local statlist = terralib.newlist()
for i = 1, N do
generate_aggregate_one_field_stat("x.f" .. i, i, typ, statlist)
end
return noinline .. aggname .. N .. " " .. name .. N .. "(" .. aggname .. N .. " x) { " .. statlist:concat(" ") .. " return x; }"
end
local function generate_nonuniform_aggregate_one_arg_function(name, aggname, types, N)
local statlist = terralib.newlist()
for i = 1, N do
local typ = get_type_in_rotation(types, i)
generate_aggregate_one_field_stat("x.f" .. i, i, typ, statlist)
end
return noinline .. aggname .. N .. " " .. name .. N .. "(" .. aggname .. N .. " x) { " .. statlist:concat(" ") .. " return x; }"
end
local function generate_aggregate_two_field_stat(field1, field2, typ, statlist)
if typ:isarray() then
for j = 0, typ.N-1 do
statlist:insert(field1 .. "[" .. j .. "] += " .. field2 .. "[" .. j .. "];")
end
else
statlist:insert(field1 .. " += " .. field2 .. ";")
end
end
local function generate_uniform_aggregate_two_arg_function(name, aggname, typ, N)
local statlist = terralib.newlist()
for i = 1, N do
generate_aggregate_two_field_stat("x.f" .. i, "y.f" .. i, typ, statlist)
end
return noinline .. aggname .. N .. " " .. name .. N .. "(" .. aggname .. N .. " x, " .. aggname .. N .. " y) { " .. statlist:concat(" ") .. " return x; }"
end
local function generate_nonuniform_aggregate_two_arg_function(name, aggname, types, N)
local statlist = terralib.newlist()
for i = 1, N do
local typ = get_type_in_rotation(types, i)
generate_aggregate_two_field_stat("x.f" .. i, "y.f" .. i, typ, statlist)
end
return noinline .. aggname .. N .. " " .. name .. N .. "(" .. aggname .. N .. " x, " .. aggname .. N .. " y) { " .. statlist:concat(" ") .. " return x; }"
end
local base_types = {uint8, int16, int32, int64, float, double}
local uniform_names = terralib.newlist({"p", "q", "r", "s", "t", "u",
"pp", "qq", "rr", "ss", "tt", "uu"})
local types = {uint8, int16, int32, int64, float, double,
uint8[2], int16[2], int32[2], int64[2], float[2], double[2]}
local nonuniform_names = terralib.newlist({"v", "w", "x", "y", "z"})
local type_rotations = {
{uint8, int16, int32, int64, double},
{float, float, uint8, uint8, int16, int32, int64},
{uint8, int16[2], int64, float[3], double[2]},
{float, float[2]},
{double, double[4]},
}
local all_names = terralib.newlist()
all_names:insertall(uniform_names)
all_names:insertall(nonuniform_names)
local uniform_scalar_names = terralib.newlist({"b", "c", "d", "e", "f", "g",
"bb", "cc", "dd", "ee", "ff", "gg"})
local nonuniform_scalar_names = terralib.newlist({"h", "i", "j", "k", "kk"})
local all_scalar_names = terralib.newlist()
all_scalar_names:insertall(uniform_scalar_names)
all_scalar_names:insertall(nonuniform_scalar_names)
local c
do
local definitions = terralib.newlist({"#include <stdint.h>", ""})
definitions:insert(generate_uniform_struct("p", nil, 0))
definitions:insert("")
for i, typ in ipairs(base_types) do
for N = 1, MAX_ARRAY_N do
definitions:insert(generate_array_wrapper(typ, N))
end
definitions:insert("")
end
for i, typ in ipairs(types) do
local name = uniform_names[i]
for N = 1, MAX_N do
definitions:insert(generate_uniform_struct(name, typ, N))
end
definitions:insert("")
end
for i, type_rotation in ipairs(type_rotations) do
local name = nonuniform_names[i]
for N = 1, MAX_N do
definitions:insert(generate_nonuniform_struct(name, type_rotation, N))
end
definitions:insert("")
end
definitions:insert(generate_void_function("ca0"))
definitions:insert("")
for i, typ in ipairs(types) do
local name = uniform_scalar_names[i]
for N = 1, MAX_N do
definitions:insert(generate_uniform_scalar_function("c" .. name, typ, N))
end
definitions:insert("")
end
for i, type_rotation in ipairs(type_rotations) do
local name = nonuniform_scalar_names[i]
for N = 1, MAX_N do
definitions:insert(
generate_nonuniform_scalar_function("c" .. name, type_rotation, N))
end
definitions:insert("")
end
definitions:insert(generate_uniform_aggregate_one_arg_function("cp", "p", nil, 0))
definitions:insert("")
for i, typ in ipairs(types) do
local name = uniform_names[i]
for N = 1, MAX_N do
definitions:insert(
generate_uniform_aggregate_one_arg_function("c" .. name, name, typ, N))
end
definitions:insert("")
end
for i, type_rotation in ipairs(type_rotations) do
local name = nonuniform_names[i]
for N = 1, MAX_N do
definitions:insert(
generate_nonuniform_aggregate_one_arg_function("c" .. name, name, type_rotation, N))
end
definitions:insert("")
end
for i, typ in ipairs(types) do
local name = uniform_names[i]
for N = 1, MAX_N do
definitions:insert(
generate_uniform_aggregate_two_arg_function("c2" .. name, name, typ, N))
end
definitions:insert("")
end
for i, type_rotation in ipairs(type_rotations) do
local name = nonuniform_names[i]
for N = 1, MAX_N do
definitions:insert(
generate_nonuniform_aggregate_two_arg_function("c2" .. name, name, type_rotation, N))
end
definitions:insert("")
end
c = terralib.includecstring(definitions:concat("\n"))
end
local function generate_void_terra(mod, name)
local terra f() end
f:setname(name)
f:setinlined(false)
mod[name] = f
end
local function lookup_scalar_terra(typ)
if typ:isarray() then
return c[lookup_scalar(typ)]
end
return typ
end
local function generate_scalar_exprs_terra(arg, typ, exprlist)
if typ:isarray() then
for j = 0, typ.N-1 do
exprlist:insert(`arg.x[j])
end
else
exprlist:insert(arg)
end
end
local function generate_uniform_scalar_terra(mod, name, typ, N)
local argtype = lookup_scalar_terra(typ)
local args = terralib.newlist()
for i = 1, N do
args:insert(terralib.newsymbol(argtype, "x" .. i))
end
local exprlist = terralib.newlist()
for _, arg in ipairs(args) do
generate_scalar_exprs_terra(arg, typ, exprlist)
end
local terra f([args])
return [exprlist:reduce(function(x, y) return `x + y end)]
end
f:setname(name .. N)
f:setinlined(false)
mod[name .. N] = f
end
local function generate_nonuniform_scalar_terra(mod, name, types, N)
local args = terralib.newlist()
for i = 1, N do
local typ = get_type_in_rotation(types, i)
local argtype = lookup_scalar_terra(typ)
args:insert(terralib.newsymbol(argtype, "x" .. i))
end
local exprlist = terralib.newlist()
for i, arg in ipairs(args) do
local typ = get_type_in_rotation(types, i)
generate_scalar_exprs_terra(arg, typ, exprlist)
end
local terra f([args])
return [exprlist:reduce(function(x, y) return `x + y end)]
end
f:setname(name .. N)
f:setinlined(false)
mod[name .. N] = f
end
local function generate_aggregate_one_field_stats_terra(field, typ, inc, statlist)
if typ:isarray() then
for j = 0, typ.N-1 do
statlist:insert(quote [field][j] = [field][j] + inc end)
end
else
statlist:insert(quote [field] = [field] + inc end)
end
end
local function generate_aggregate_one_arg_terra(mod, name, aggtyp, N)
local terra f(x : aggtyp)
escape
local statlist = terralib.newlist()
for i = 1, N do
local field = `x.["f" .. i]
local ftype = field:gettype()
generate_aggregate_one_field_stats_terra(field, ftype, i, statlist)
end
emit quote [statlist] end
end
return x
end
f:setname(name .. N)
f:setinlined(false)
mod[name .. N] = f
end
local function generate_aggregate_two_field_stats_terra(field1, field2, typ, statlist)
if typ:isarray() then
for j = 0, typ.N-1 do
statlist:insert(quote [field1][j] = [field1][j] + [field2][j] end)
end
else
statlist:insert(quote [field1] = [field1] + [field2] end)
end
end
local function generate_aggregate_two_arg_terra(mod, name, aggtyp, N)
local terra f(x : aggtyp, y : aggtyp)
escape
local statlist = terralib.newlist()
for i = 1, N do
local fname = "f" .. i
local field1 = `x.["f" .. i]
local field2 = `y.["f" .. i]
local ftype = field1:gettype()
generate_aggregate_two_field_stats_terra(field1, field2, ftype, statlist)
end
emit quote [statlist] end
end
return x
end
f:setname(name .. N)
f:setinlined(false)
mod[name .. N] = f
end
local t = {}
generate_void_terra(t, "ta0")
for i, typ in ipairs(types) do
local name = uniform_scalar_names[i]
for N = 1, MAX_N do
generate_uniform_scalar_terra(t, "t" .. name, typ, N)
end
end
for i, type_rotation in ipairs(type_rotations) do
local name = nonuniform_scalar_names[i]
for N = 1, MAX_N do
generate_nonuniform_scalar_terra(t, "t" .. name, type_rotation, N)
end
end
generate_aggregate_one_arg_terra(t, "tp", c["p0"], 0)
for _, name in ipairs(all_names) do
for N = 1, MAX_N do
generate_aggregate_one_arg_terra(t, "t" .. name, c[name .. N], N)
end
end
for _, name in ipairs(all_names) do
for N = 1, MAX_N do
generate_aggregate_two_arg_terra(t, "t2" .. name, c[name .. N], N)
end
end
-- Generate a unique exit condition for each test site.
local exit_condition = 1
local function generate_teq(arg, value)
exit_condition = exit_condition + 1
return quote
if arg ~= value then
return exit_condition -- failure
end
end
end
local teq = macro(generate_teq)
local function generate_field_init(field, typ, init, statlist)
if typ:isarray() then
for j = 0, typ.N-1 do
statlist:insert(quote field[j] = init end)
end
else
statlist:insert(quote field = init end)
end
end
local init_fields = macro(
function(arg, value, num_fields)
local statlist = terralib.newlist()
for i = 1, num_fields:asvalue() do
local field = `arg.["f" .. i]
local ftype = field:gettype()
generate_field_init(field, ftype, `value*i, statlist)
end
return quote [statlist] end
end)
local function generate_field_check(field, typ, expected, statlist)
if typ:isarray() then
for j = 0, typ.N-1 do
statlist:insert(generate_teq(`field[j], expected))
end
else
statlist:insert(generate_teq(field, expected))
end
end
local check_fields = macro(
function(arg, value, num_fields)
local statlist = terralib.newlist()
for i = 1, num_fields:asvalue() do
local field = `arg.["f" .. i]
local ftype = field:gettype()
generate_field_check(field, ftype, `value*i, statlist)
end
return quote [statlist] end
end)
-- Check functions with zero arguments/fields.
terra check_zero()
c.ca0()
t.ta0()
var x0 : c.p0
var cx0 = c.cp0(x0)
var tx0 = t.tp0(x0)
end
check_zero()
local function generate_scalar_args(typ, i, arglist)
if typ:isarray() then
local expected_result = 0
local values = terralib.newlist()
for j = 0, typ.N-1 do
values:insert(i)
expected_result = expected_result + i
end
local arrtyp = lookup_scalar_terra(typ)
arglist:insert(`arrtyp { x = arrayof(typ.type, values) })
return expected_result
end
arglist:insert(i)
return i
end
local function safe_limit(typ)
if typ:isarray() then
return safe_limit(typ.type)
end
-- Overapproximate range of float/double. This is ok because we'll
-- never get close to this limit.
return 2ULL ^ (sizeof(typ)*8) - 1
end
local function min(a, b, c, d)
if a < b then return a, c end
return b, d
end
-- Check functions of scalar arguments.
for i, typ in ipairs(types) do
local name = uniform_scalar_names[i]
for N = 1, MAX_N do
local cfunc = c["c" .. name .. N]
local tfunc = t["t" .. name .. N]
local arglist = terralib.newlist()
local expected_result = 0
for i = 1, N do
expected_result = expected_result + generate_scalar_args(typ, i, arglist)
end
local limit = safe_limit(typ)
local test_name = "N=" .. tostring(N) .. ", " .. tostring(tfunc:gettype())
if expected_result < limit then
print("running scalar test for " .. test_name)
local terra check()
teq(cfunc(arglist), expected_result)
teq(tfunc(arglist), expected_result)
return 0
end
local ok = check()
if ok ~= 0 then
print(terralib.saveobj(nil, "llvmir", {check=check}, nil, nil, false))
error("scalar test failed for " .. test_name .. ": error code " .. tostring(ok))
end
else
print("skipping scalar test for " .. test_name .. ": " .. expected_result .. " is too large for " .. tostring(typ) .. " " .. tostring(limit))
end
end
end
for i, type_rotation in ipairs(type_rotations) do
local name = nonuniform_scalar_names[i]
for N = 1, MAX_N do
local cfunc = c["c" .. name .. N]
local tfunc = t["t" .. name .. N]
local arglist = terralib.newlist()
local expected_result = 0
local limit, limit_type = math.huge
for i = 1, N do
local typ = get_type_in_rotation(type_rotation, i)
expected_result = expected_result + generate_scalar_args(typ, i, arglist)
limit, limit_type = min(limit, safe_limit(typ), limit_type, typ)
end
local test_name = "N=" .. tostring(N) .. ", " .. tostring(tfunc:gettype())
if expected_result < limit then
print("running scalar test for " .. test_name)
local terra check()
teq(cfunc(arglist), expected_result)
teq(tfunc(arglist), expected_result)
return 0
end
local ok = check()
if ok ~= 0 then
print(terralib.saveobj(nil, "llvmir", {check=check}, nil, nil, false))
error("scalar test failed for " .. test_name .. ": error code " .. tostring(ok))
end
else
print("skipping scalar test for " .. test_name .. ": " .. expected_result .. " is too large for " .. tostring(limit_type) .. " " .. tostring(limit))
end
end
end
-- Check functions of one aggregate argument.
for _, name in ipairs(all_names) do
for N = 1, MAX_N do
local aggtype = c[name .. N]
local cfunc = c["c" .. name .. N]
local tfunc = t["t" .. name .. N]
local test_name = "N=" .. tostring(N) .. ", " .. tostring(tfunc:gettype()) .. " where " .. tostring(aggtype) .. "=" .. tostring(aggtype:getentries():map(function(f) return tostring(f.field) .. "=" .. tostring(f.type) end))
print("running aggregate test for " .. test_name)
assert(11 * N < 255, "value is too large to fit in uint8, not safe to test")
local terra check()
var x : aggtype
init_fields(x, 10, N)
var cx = cfunc(x)
check_fields(x, 10, N)
check_fields(cx, 11, N)
var tx = tfunc(x)
check_fields(x, 10, N)
check_fields(tx, 11, N)
return 0
end
local ok = check()
if ok ~= 0 then
print(terralib.saveobj(nil, "llvmir", {check=check}, nil, nil, false))
error("aggregate test failed for " .. test_name .. ": error code " .. tostring(ok))
end
end
end
-- Check functions of two aggregate arguments.
for _, name in ipairs(all_names) do
for N = 1, MAX_N do
local aggtype = c[name .. N]
local cfunc = c["c2" .. name .. N]
local tfunc = t["t2" .. name .. N]
local test_name = "N=" .. tostring(N) .. ", " .. tostring(tfunc:gettype()) .. " where " .. tostring(aggtype) .. "=" .. tostring(aggtype:getentries():map(function(f) return tostring(f.field) .. "=" .. tostring(f.type) end))
print("running aggregate test for " .. test_name)
assert(11 * N < 255, "value is too large to fit in uint8, not safe to test")
local terra check()
var x : aggtype
init_fields(x, 10, N)
var y : aggtype
init_fields(y, 1, N)
var cx = cfunc(x, y)
check_fields(x, 10, N)
check_fields(cx, 11, N)
var tx = tfunc(x, y)
check_fields(x, 10, N)
check_fields(tx, 11, N)
return 0
end
local ok = check()
if ok ~= 0 then
print(terralib.saveobj(nil, "llvmir", {check=check}, nil, nil, false))
error("aggregate test failed for " .. test_name .. ": error code " .. tostring(ok))
end
end
end