| 1 |
/* This testcase checks that gcc_jit_global_set_initializer_rvalue() works |
| 2 |
with rvalues, especially with gcc_jit_context_new_*_constructor() for |
| 3 |
struct, unions and arrays. */ |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include <string.h> |
| 7 |
|
| 8 |
#include "libgccjit.h" |
| 9 |
#include "harness.h" |
| 10 |
|
| 11 |
void |
| 12 |
create_code (gcc_jit_context *ctxt, void *user_data) |
| 13 |
{ |
| 14 |
gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt, |
| 15 |
GCC_JIT_TYPE_INT); |
| 16 |
gcc_jit_type *short_type = gcc_jit_context_get_type (ctxt, |
| 17 |
GCC_JIT_TYPE_SHORT); |
| 18 |
gcc_jit_type *pint_type = gcc_jit_type_get_pointer (int_type); |
| 19 |
gcc_jit_type *double_type = gcc_jit_context_get_type (ctxt, |
| 20 |
GCC_JIT_TYPE_DOUBLE); |
| 21 |
gcc_jit_type *float_type = gcc_jit_context_get_type (ctxt, |
| 22 |
GCC_JIT_TYPE_FLOAT); |
| 23 |
gcc_jit_type *bool_type = gcc_jit_context_get_type (ctxt, |
| 24 |
GCC_JIT_TYPE_BOOL); |
| 25 |
gcc_jit_type *char_type = gcc_jit_context_get_type (ctxt, |
| 26 |
GCC_JIT_TYPE_CHAR); |
| 27 |
gcc_jit_type *cpchar_type = gcc_jit_context_get_type (ctxt, |
| 28 |
GCC_JIT_TYPE_CONST_CHAR_PTR); |
| 29 |
gcc_jit_type *size_type = gcc_jit_context_get_type (ctxt, |
| 30 |
GCC_JIT_TYPE_SIZE_T); |
| 31 |
|
| 32 |
/* Make a struct: struct fi { float f; int i;} */ |
| 33 |
gcc_jit_field *fi_f = gcc_jit_context_new_field (ctxt, |
| 34 |
0, |
| 35 |
float_type, |
| 36 |
"f"); |
| 37 |
gcc_jit_field *fi_i = gcc_jit_context_new_field (ctxt, |
| 38 |
0, |
| 39 |
int_type, |
| 40 |
"i"); |
| 41 |
gcc_jit_field *fields[] = {fi_f, fi_i}; |
| 42 |
|
| 43 |
gcc_jit_type *struct_fi_type = |
| 44 |
gcc_jit_struct_as_type ( |
| 45 |
gcc_jit_context_new_struct_type (ctxt, |
| 46 |
0, |
| 47 |
"fi", |
| 48 |
2, |
| 49 |
fields)); |
| 50 |
|
| 51 |
/* Make a struct: |
| 52 |
|
| 53 |
struct bar { |
| 54 |
int ii; |
| 55 |
struct fi fi; |
| 56 |
float ff; |
| 57 |
} |
| 58 |
*/ |
| 59 |
gcc_jit_field *bar_ff = gcc_jit_context_new_field (ctxt, |
| 60 |
0, |
| 61 |
float_type, |
| 62 |
"ff"); |
| 63 |
gcc_jit_field *bar_ii = gcc_jit_context_new_field (ctxt, |
| 64 |
0, |
| 65 |
int_type, |
| 66 |
"ii"); |
| 67 |
gcc_jit_field *bar_fi = gcc_jit_context_new_field (ctxt, |
| 68 |
0, |
| 69 |
struct_fi_type, |
| 70 |
"fi"); |
| 71 |
gcc_jit_field *fields2[] = {bar_ff, bar_fi, bar_ii}; |
| 72 |
|
| 73 |
gcc_jit_type *struct_bar_type = |
| 74 |
gcc_jit_struct_as_type ( |
| 75 |
gcc_jit_context_new_struct_type (ctxt, |
| 76 |
0, |
| 77 |
"bar", |
| 78 |
3, |
| 79 |
fields2)); |
| 80 |
|
| 81 |
/* Make an union: |
| 82 |
|
| 83 |
union ubar { |
| 84 |
float ff; |
| 85 |
int ii; |
| 86 |
}; |
| 87 |
*/ |
| 88 |
gcc_jit_field *ubar_ff = gcc_jit_context_new_field (ctxt, |
| 89 |
0, |
| 90 |
float_type, |
| 91 |
"ff"); |
| 92 |
gcc_jit_field *ubar_ii = gcc_jit_context_new_field (ctxt, |
| 93 |
0, |
| 94 |
int_type, |
| 95 |
"ii"); |
| 96 |
gcc_jit_field *fields3[] = {ubar_ff, ubar_ii}; |
| 97 |
|
| 98 |
gcc_jit_type *ubar = gcc_jit_context_new_union_type (ctxt, |
| 99 |
0, |
| 100 |
"ubar", |
| 101 |
2, |
| 102 |
fields3); |
| 103 |
|
| 104 |
{ /* struct bar bar = {.ff=1, .fi={.f=2, .i=3}, .ii=4}; |
| 105 |
I.e. nested ctors and with fields specified |
| 106 |
*/ |
| 107 |
gcc_jit_lvalue *bar = gcc_jit_context_new_global ( |
| 108 |
ctxt, NULL, |
| 109 |
GCC_JIT_GLOBAL_EXPORTED, |
| 110 |
struct_bar_type, |
| 111 |
"global_struct_bar_1234_1"); |
| 112 |
|
| 113 |
gcc_jit_rvalue *fval = gcc_jit_context_new_rvalue_from_int ( |
| 114 |
ctxt, float_type, 2); |
| 115 |
gcc_jit_rvalue *ival = gcc_jit_context_new_rvalue_from_int ( |
| 116 |
ctxt, int_type, 3); |
| 117 |
|
| 118 |
gcc_jit_rvalue *vals[] = { fval, ival}; |
| 119 |
gcc_jit_field *fields[] = {fi_f, fi_i}; |
| 120 |
|
| 121 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_struct_constructor |
| 122 |
(ctxt, 0, |
| 123 |
struct_fi_type, |
| 124 |
2, |
| 125 |
fields, |
| 126 |
vals); |
| 127 |
|
| 128 |
ival = gcc_jit_context_new_rvalue_from_int ( |
| 129 |
ctxt, int_type, 4); |
| 130 |
fval = gcc_jit_context_new_rvalue_from_int ( |
| 131 |
ctxt, float_type, 1); |
| 132 |
|
| 133 |
gcc_jit_rvalue *vals2[] = {fval, ctor, ival}; |
| 134 |
gcc_jit_field *fields2[] = {bar_ff, bar_fi, bar_ii}; |
| 135 |
|
| 136 |
gcc_jit_rvalue *ctor_bar = gcc_jit_context_new_struct_constructor |
| 137 |
(ctxt, 0, |
| 138 |
struct_bar_type, |
| 139 |
3, |
| 140 |
fields2, |
| 141 |
vals2); |
| 142 |
|
| 143 |
gcc_jit_global_set_initializer_rvalue (bar, ctor_bar); |
| 144 |
} |
| 145 |
{ /* struct bar bar = {1, {2, 3}, 4}; |
| 146 |
I.e. nested ctors and fields implicit in definition order (fields=NULL) |
| 147 |
*/ |
| 148 |
gcc_jit_lvalue *bar = gcc_jit_context_new_global ( |
| 149 |
ctxt, NULL, |
| 150 |
GCC_JIT_GLOBAL_EXPORTED, |
| 151 |
struct_bar_type, |
| 152 |
"global_struct_bar_1234_2"); |
| 153 |
|
| 154 |
gcc_jit_rvalue *fval = gcc_jit_context_new_rvalue_from_int ( |
| 155 |
ctxt, float_type, 2); |
| 156 |
gcc_jit_rvalue *ival = gcc_jit_context_new_rvalue_from_int ( |
| 157 |
ctxt, int_type, 3); |
| 158 |
|
| 159 |
gcc_jit_rvalue *vals[] = { fval, ival}; |
| 160 |
|
| 161 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_struct_constructor |
| 162 |
(ctxt, 0, |
| 163 |
struct_fi_type, |
| 164 |
2, |
| 165 |
0, |
| 166 |
vals); |
| 167 |
|
| 168 |
ival = gcc_jit_context_new_rvalue_from_int ( |
| 169 |
ctxt, int_type, 4); |
| 170 |
fval = gcc_jit_context_new_rvalue_from_int ( |
| 171 |
ctxt, float_type, 1); |
| 172 |
|
| 173 |
gcc_jit_rvalue *vals2[] = {fval, ctor, ival}; |
| 174 |
|
| 175 |
gcc_jit_rvalue *ctor_bar = gcc_jit_context_new_struct_constructor |
| 176 |
(ctxt, 0, |
| 177 |
struct_bar_type, |
| 178 |
3, |
| 179 |
0, |
| 180 |
vals2); |
| 181 |
|
| 182 |
gcc_jit_global_set_initializer_rvalue (bar, ctor_bar); |
| 183 |
} |
| 184 |
{ /* struct fi foo = {.f=2, .i=3}; */ |
| 185 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 186 |
ctxt, NULL, |
| 187 |
GCC_JIT_GLOBAL_EXPORTED, |
| 188 |
struct_fi_type, |
| 189 |
"global_struct_fi_23_1"); |
| 190 |
|
| 191 |
gcc_jit_rvalue *fval = gcc_jit_context_new_rvalue_from_int ( |
| 192 |
ctxt, float_type, 2); |
| 193 |
gcc_jit_rvalue *ival = gcc_jit_context_new_rvalue_from_int ( |
| 194 |
ctxt, int_type, 3); |
| 195 |
|
| 196 |
gcc_jit_rvalue *vals[] = { fval, ival}; |
| 197 |
gcc_jit_field *fields[] = {fi_f, fi_i}; |
| 198 |
|
| 199 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_struct_constructor |
| 200 |
(ctxt, 0, |
| 201 |
struct_fi_type, |
| 202 |
2, |
| 203 |
fields, |
| 204 |
vals); |
| 205 |
|
| 206 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 207 |
} |
| 208 |
{ /* struct fi foo = {2, 3}; */ |
| 209 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 210 |
ctxt, NULL, |
| 211 |
GCC_JIT_GLOBAL_EXPORTED, |
| 212 |
struct_fi_type, |
| 213 |
"global_struct_fi_23_2"); |
| 214 |
|
| 215 |
gcc_jit_rvalue *fval = gcc_jit_context_new_rvalue_from_int ( |
| 216 |
ctxt, float_type, 2); |
| 217 |
gcc_jit_rvalue *ival = gcc_jit_context_new_rvalue_from_int ( |
| 218 |
ctxt, int_type, 3); |
| 219 |
|
| 220 |
gcc_jit_rvalue *vals[] = { fval, ival}; |
| 221 |
|
| 222 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_struct_constructor |
| 223 |
(ctxt, 0, |
| 224 |
struct_fi_type, |
| 225 |
2, |
| 226 |
0, |
| 227 |
vals); |
| 228 |
|
| 229 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 230 |
} |
| 231 |
{ /* struct fi foo = {.i=0, .f=0}; (null init) */ |
| 232 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 233 |
ctxt, NULL, |
| 234 |
GCC_JIT_GLOBAL_EXPORTED, |
| 235 |
struct_fi_type, |
| 236 |
"global_struct_fi_00_1"); |
| 237 |
|
| 238 |
gcc_jit_rvalue *vals[] = { 0, 0}; |
| 239 |
gcc_jit_field *fields[] = {fi_f, fi_i}; |
| 240 |
|
| 241 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_struct_constructor |
| 242 |
(ctxt, 0, |
| 243 |
struct_fi_type, |
| 244 |
2, |
| 245 |
fields, |
| 246 |
vals); |
| 247 |
|
| 248 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 249 |
} |
| 250 |
{ /* struct fi foo = {0, 0}; (null fields, null elements in values) */ |
| 251 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 252 |
ctxt, NULL, |
| 253 |
GCC_JIT_GLOBAL_EXPORTED, |
| 254 |
struct_fi_type, |
| 255 |
"global_struct_fi_00_2"); |
| 256 |
|
| 257 |
gcc_jit_rvalue *vals[] = { 0, 0}; |
| 258 |
|
| 259 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_struct_constructor |
| 260 |
(ctxt, 0, |
| 261 |
struct_fi_type, |
| 262 |
2, |
| 263 |
0, |
| 264 |
vals); |
| 265 |
|
| 266 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 267 |
} |
| 268 |
{ /* struct fi foo = {.i = 0} (null init); |
| 269 |
|
| 270 |
Null init values. */ |
| 271 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 272 |
ctxt, NULL, |
| 273 |
GCC_JIT_GLOBAL_EXPORTED, |
| 274 |
struct_fi_type, |
| 275 |
"global_struct_fi_0_1"); |
| 276 |
|
| 277 |
gcc_jit_rvalue *vals[] = {0}; |
| 278 |
gcc_jit_field *fields[] = {fi_i}; |
| 279 |
|
| 280 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_struct_constructor |
| 281 |
(ctxt, 0, |
| 282 |
struct_fi_type, |
| 283 |
1, |
| 284 |
fields, |
| 285 |
vals); |
| 286 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 287 |
} |
| 288 |
{ /* struct fi foo = {0}; |
| 289 |
|
| 290 |
Null init values. */ |
| 291 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 292 |
ctxt, NULL, |
| 293 |
GCC_JIT_GLOBAL_EXPORTED, |
| 294 |
struct_fi_type, |
| 295 |
"global_struct_fi_0_2"); |
| 296 |
|
| 297 |
gcc_jit_rvalue *vals[] = {0}; |
| 298 |
|
| 299 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_struct_constructor |
| 300 |
(ctxt, 0, |
| 301 |
struct_fi_type, |
| 302 |
1, |
| 303 |
0, |
| 304 |
vals); |
| 305 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 306 |
} |
| 307 |
{ /* struct fi foo = {}; (null init) |
| 308 |
|
| 309 |
Null fields and values. */ |
| 310 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 311 |
ctxt, NULL, |
| 312 |
GCC_JIT_GLOBAL_EXPORTED, |
| 313 |
struct_fi_type, |
| 314 |
"global_struct_fi_6"); |
| 315 |
|
| 316 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_struct_constructor |
| 317 |
(ctxt, 0, |
| 318 |
struct_fi_type, |
| 319 |
0, |
| 320 |
0, |
| 321 |
0); |
| 322 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 323 |
} |
| 324 |
{ /* struct fi foo = {2 * 2, 3}; */ |
| 325 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 326 |
ctxt, NULL, |
| 327 |
GCC_JIT_GLOBAL_EXPORTED, |
| 328 |
struct_fi_type, |
| 329 |
"global_struct_fi_3"); |
| 330 |
|
| 331 |
gcc_jit_rvalue *fval = gcc_jit_context_new_rvalue_from_int ( |
| 332 |
ctxt, float_type, 2); |
| 333 |
gcc_jit_rvalue *fval2 = gcc_jit_context_new_rvalue_from_int ( |
| 334 |
ctxt, float_type, 2); |
| 335 |
gcc_jit_rvalue *ival = gcc_jit_context_new_rvalue_from_int ( |
| 336 |
ctxt, int_type, 3); |
| 337 |
gcc_jit_rvalue *rval_mul = gcc_jit_context_new_binary_op (ctxt, 0, |
| 338 |
GCC_JIT_BINARY_OP_MULT, |
| 339 |
float_type, |
| 340 |
fval, |
| 341 |
fval2); |
| 342 |
|
| 343 |
gcc_jit_rvalue *vals[] = { rval_mul, ival}; |
| 344 |
gcc_jit_field *fields[] = {fi_f, fi_i}; |
| 345 |
|
| 346 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_struct_constructor |
| 347 |
(ctxt, 0, |
| 348 |
struct_fi_type, |
| 349 |
2, |
| 350 |
fields, |
| 351 |
vals); |
| 352 |
|
| 353 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 354 |
} |
| 355 |
{ /* union ubar foo = {.ff = 3}; */ |
| 356 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 357 |
ctxt, NULL, |
| 358 |
GCC_JIT_GLOBAL_EXPORTED, |
| 359 |
ubar, |
| 360 |
"global_union_ufoo_ff3"); |
| 361 |
|
| 362 |
gcc_jit_rvalue *fval = gcc_jit_context_new_rvalue_from_int ( |
| 363 |
ctxt, float_type, 3); |
| 364 |
|
| 365 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_union_constructor ( |
| 366 |
ctxt, |
| 367 |
0, |
| 368 |
ubar, |
| 369 |
ubar_ff, |
| 370 |
fval); |
| 371 |
|
| 372 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 373 |
} |
| 374 |
{ /* union ubar foo = {.ii = 2}; */ |
| 375 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 376 |
ctxt, NULL, |
| 377 |
GCC_JIT_GLOBAL_EXPORTED, |
| 378 |
ubar, |
| 379 |
"global_union_ufoo_ii2"); |
| 380 |
|
| 381 |
gcc_jit_rvalue *ival = gcc_jit_context_new_rvalue_from_int ( |
| 382 |
ctxt, int_type, 2); |
| 383 |
|
| 384 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_union_constructor ( |
| 385 |
ctxt, |
| 386 |
0, |
| 387 |
ubar, |
| 388 |
ubar_ii, |
| 389 |
ival); |
| 390 |
|
| 391 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 392 |
} |
| 393 |
{ /* union ubar foo = {1.1f}; should init first field */ |
| 394 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 395 |
ctxt, NULL, |
| 396 |
GCC_JIT_GLOBAL_EXPORTED, |
| 397 |
ubar, |
| 398 |
"global_union_ufoo_ff1c1"); |
| 399 |
|
| 400 |
gcc_jit_rvalue *fval = gcc_jit_context_new_rvalue_from_double ( |
| 401 |
ctxt, float_type, 1.1); |
| 402 |
|
| 403 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_union_constructor ( |
| 404 |
ctxt, |
| 405 |
0, |
| 406 |
ubar, |
| 407 |
0, |
| 408 |
fval); |
| 409 |
|
| 410 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 411 |
} |
| 412 |
{ /* union ubar foo = (union ubar){}; */ |
| 413 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 414 |
ctxt, NULL, |
| 415 |
GCC_JIT_GLOBAL_EXPORTED, |
| 416 |
ubar, |
| 417 |
"global_union_ufoo_0"); |
| 418 |
|
| 419 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_union_constructor ( |
| 420 |
ctxt, |
| 421 |
0, |
| 422 |
ubar, |
| 423 |
0, |
| 424 |
0); |
| 425 |
|
| 426 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 427 |
} |
| 428 |
{ /* int foo = 3; */ |
| 429 |
gcc_jit_rvalue *rval = gcc_jit_context_new_rvalue_from_int ( |
| 430 |
ctxt, int_type, 3); |
| 431 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 432 |
ctxt, NULL, |
| 433 |
GCC_JIT_GLOBAL_EXPORTED, |
| 434 |
int_type, |
| 435 |
"global_int1_3"); |
| 436 |
gcc_jit_global_set_initializer_rvalue (foo, |
| 437 |
rval); |
| 438 |
} |
| 439 |
{ /* const volatile int foo = 3; */ |
| 440 |
gcc_jit_rvalue *rval = gcc_jit_context_new_rvalue_from_int ( |
| 441 |
ctxt, int_type, 3); |
| 442 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 443 |
ctxt, NULL, |
| 444 |
GCC_JIT_GLOBAL_EXPORTED, |
| 445 |
gcc_jit_type_get_const (gcc_jit_type_get_volatile (int_type)), |
| 446 |
"global_cvint1_3"); |
| 447 |
gcc_jit_global_set_initializer_rvalue (foo, |
| 448 |
rval); |
| 449 |
} |
| 450 |
{ /* Try the above, but with opposite order of global and literal calls */ |
| 451 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 452 |
ctxt, NULL, |
| 453 |
GCC_JIT_GLOBAL_EXPORTED, |
| 454 |
int_type, |
| 455 |
"global_int2_3"); |
| 456 |
gcc_jit_rvalue *rval = gcc_jit_context_new_rvalue_from_int ( |
| 457 |
ctxt, int_type, 3); |
| 458 |
gcc_jit_global_set_initializer_rvalue (foo, |
| 459 |
rval); |
| 460 |
} |
| 461 |
{ /* int foo = 3 * (3 + 3) */ |
| 462 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 463 |
ctxt, NULL, |
| 464 |
GCC_JIT_GLOBAL_EXPORTED, |
| 465 |
int_type, |
| 466 |
"global_int3_18"); |
| 467 |
gcc_jit_rvalue *rval3_0 = gcc_jit_context_new_rvalue_from_int ( |
| 468 |
ctxt, int_type, 3); |
| 469 |
gcc_jit_rvalue *rval3_1 = gcc_jit_context_new_rvalue_from_int ( |
| 470 |
ctxt, int_type, 3); |
| 471 |
gcc_jit_rvalue *rval3_2 = gcc_jit_context_new_rvalue_from_int ( |
| 472 |
ctxt, int_type, 3); |
| 473 |
gcc_jit_rvalue *rval_plus = gcc_jit_context_new_binary_op (ctxt, 0, |
| 474 |
GCC_JIT_BINARY_OP_PLUS, |
| 475 |
int_type, |
| 476 |
rval3_0, |
| 477 |
rval3_1); |
| 478 |
gcc_jit_rvalue *rval_mul = gcc_jit_context_new_binary_op (ctxt, 0, |
| 479 |
GCC_JIT_BINARY_OP_MULT, |
| 480 |
int_type, |
| 481 |
rval_plus, |
| 482 |
rval3_2); |
| 483 |
|
| 484 |
gcc_jit_global_set_initializer_rvalue (foo, |
| 485 |
rval_mul); |
| 486 |
} |
| 487 |
{ /* int foo = ~(-(((((2 | 8) & 15) ^ 0) << 3 >> 2 - 1) / 2)); */ |
| 488 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 489 |
ctxt, NULL, |
| 490 |
GCC_JIT_GLOBAL_EXPORTED, |
| 491 |
int_type, |
| 492 |
"global_int_alotofoperators"); |
| 493 |
gcc_jit_rvalue *rval_0 = gcc_jit_context_new_rvalue_from_int ( |
| 494 |
ctxt, int_type, 2); |
| 495 |
gcc_jit_rvalue *rval_1 = gcc_jit_context_new_rvalue_from_int ( |
| 496 |
ctxt, int_type, 8); |
| 497 |
gcc_jit_rvalue *rval_2 = gcc_jit_context_new_rvalue_from_int ( |
| 498 |
ctxt, int_type, 15); |
| 499 |
gcc_jit_rvalue *rval_3 = gcc_jit_context_new_rvalue_from_int ( |
| 500 |
ctxt, int_type, 0); |
| 501 |
gcc_jit_rvalue *rval_4 = gcc_jit_context_new_rvalue_from_int ( |
| 502 |
ctxt, int_type, 3); |
| 503 |
gcc_jit_rvalue *rval_5 = gcc_jit_context_new_rvalue_from_int ( |
| 504 |
ctxt, int_type, 2); |
| 505 |
gcc_jit_rvalue *rval_6 = gcc_jit_context_new_rvalue_from_int ( |
| 506 |
ctxt, int_type, 1); |
| 507 |
gcc_jit_rvalue *rval_7 = gcc_jit_context_new_rvalue_from_int ( |
| 508 |
ctxt, int_type, 2); |
| 509 |
|
| 510 |
gcc_jit_rvalue *rval_or = gcc_jit_context_new_binary_op (ctxt, 0, |
| 511 |
GCC_JIT_BINARY_OP_BITWISE_OR, |
| 512 |
int_type, |
| 513 |
rval_0, |
| 514 |
rval_1); |
| 515 |
gcc_jit_rvalue *rval_and = gcc_jit_context_new_binary_op (ctxt, 0, |
| 516 |
GCC_JIT_BINARY_OP_BITWISE_AND, |
| 517 |
int_type, |
| 518 |
rval_or, |
| 519 |
rval_2); |
| 520 |
gcc_jit_rvalue *rval_xor = gcc_jit_context_new_binary_op (ctxt, 0, |
| 521 |
GCC_JIT_BINARY_OP_BITWISE_XOR, |
| 522 |
int_type, |
| 523 |
rval_and, |
| 524 |
rval_3); |
| 525 |
gcc_jit_rvalue *rval_lsh = gcc_jit_context_new_binary_op (ctxt, 0, |
| 526 |
GCC_JIT_BINARY_OP_LSHIFT, |
| 527 |
int_type, |
| 528 |
rval_xor, |
| 529 |
rval_4); |
| 530 |
gcc_jit_rvalue *rval_rsh = gcc_jit_context_new_binary_op (ctxt, 0, |
| 531 |
GCC_JIT_BINARY_OP_RSHIFT, |
| 532 |
int_type, |
| 533 |
rval_lsh, |
| 534 |
rval_5); |
| 535 |
gcc_jit_rvalue *rval_min = gcc_jit_context_new_binary_op (ctxt, 0, |
| 536 |
GCC_JIT_BINARY_OP_MINUS, |
| 537 |
int_type, |
| 538 |
rval_rsh, |
| 539 |
rval_6); |
| 540 |
gcc_jit_rvalue *rval_div = gcc_jit_context_new_binary_op (ctxt, 0, |
| 541 |
GCC_JIT_BINARY_OP_DIVIDE, |
| 542 |
int_type, |
| 543 |
rval_min, |
| 544 |
rval_7); |
| 545 |
gcc_jit_rvalue *rval_umin = gcc_jit_context_new_unary_op (ctxt, 0, |
| 546 |
GCC_JIT_UNARY_OP_MINUS, |
| 547 |
int_type, |
| 548 |
rval_div); |
| 549 |
gcc_jit_rvalue *rval_neg = gcc_jit_context_new_unary_op (ctxt, 0, |
| 550 |
GCC_JIT_UNARY_OP_BITWISE_NEGATE, |
| 551 |
int_type, |
| 552 |
rval_umin); |
| 553 |
|
| 554 |
gcc_jit_global_set_initializer_rvalue (foo, |
| 555 |
rval_neg); |
| 556 |
} |
| 557 |
{ /* int foo = 3; int *pfoo = &foo; */ |
| 558 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 559 |
ctxt, NULL, |
| 560 |
GCC_JIT_GLOBAL_EXPORTED, |
| 561 |
int_type, |
| 562 |
"global_int4_3"); |
| 563 |
gcc_jit_rvalue *rval = gcc_jit_context_new_rvalue_from_int ( |
| 564 |
ctxt, int_type, 3); |
| 565 |
gcc_jit_global_set_initializer_rvalue (foo, |
| 566 |
rval); |
| 567 |
|
| 568 |
gcc_jit_lvalue *pfoo = gcc_jit_context_new_global ( |
| 569 |
ctxt, NULL, |
| 570 |
GCC_JIT_GLOBAL_EXPORTED, |
| 571 |
pint_type, |
| 572 |
"global_pint5"); |
| 573 |
gcc_jit_global_set_initializer_rvalue (pfoo, |
| 574 |
gcc_jit_lvalue_get_address (foo, 0)); |
| 575 |
} |
| 576 |
{ /* static int foo; int *pfoo = &foo; */ |
| 577 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 578 |
ctxt, NULL, |
| 579 |
GCC_JIT_GLOBAL_INTERNAL, |
| 580 |
int_type, |
| 581 |
"global_int5_3"); |
| 582 |
|
| 583 |
gcc_jit_lvalue *pfoo = gcc_jit_context_new_global ( |
| 584 |
ctxt, NULL, |
| 585 |
GCC_JIT_GLOBAL_EXPORTED, |
| 586 |
pint_type, |
| 587 |
"global_pint6"); |
| 588 |
gcc_jit_global_set_initializer_rvalue (pfoo, |
| 589 |
gcc_jit_lvalue_get_address (foo, 0)); |
| 590 |
|
| 591 |
gcc_jit_function *fn = |
| 592 |
gcc_jit_context_new_function (ctxt, |
| 593 |
0, |
| 594 |
GCC_JIT_FUNCTION_EXPORTED, |
| 595 |
gcc_jit_type_get_pointer(int_type), |
| 596 |
"fn_pint_0", |
| 597 |
0, |
| 598 |
0, |
| 599 |
0); |
| 600 |
|
| 601 |
gcc_jit_block *block = gcc_jit_function_new_block (fn, "start"); |
| 602 |
|
| 603 |
gcc_jit_block_end_with_return (block, |
| 604 |
0, |
| 605 |
gcc_jit_lvalue_get_address (foo, 0)); |
| 606 |
} |
| 607 |
{ /* int foo = 3; int *pfoo = &foo + 1; */ |
| 608 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 609 |
ctxt, NULL, |
| 610 |
GCC_JIT_GLOBAL_EXPORTED, |
| 611 |
int_type, |
| 612 |
"global_int6_3"); |
| 613 |
gcc_jit_rvalue *rval = gcc_jit_context_new_rvalue_from_int ( |
| 614 |
ctxt, int_type, 3); |
| 615 |
gcc_jit_global_set_initializer_rvalue (foo, |
| 616 |
rval); |
| 617 |
|
| 618 |
gcc_jit_lvalue *pfoo = gcc_jit_context_new_global ( |
| 619 |
ctxt, NULL, |
| 620 |
GCC_JIT_GLOBAL_EXPORTED, |
| 621 |
pint_type, |
| 622 |
"global_pint7"); |
| 623 |
gcc_jit_global_set_initializer_rvalue (pfoo, |
| 624 |
gcc_jit_lvalue_get_address ( |
| 625 |
gcc_jit_context_new_array_access( |
| 626 |
ctxt, |
| 627 |
0, |
| 628 |
gcc_jit_lvalue_get_address(foo, 0), |
| 629 |
gcc_jit_context_one(ctxt, int_type)), |
| 630 |
0)); |
| 631 |
} |
| 632 |
{ /* double foo = 3; */ |
| 633 |
gcc_jit_lvalue *double1 = gcc_jit_context_new_global ( |
| 634 |
ctxt, NULL, |
| 635 |
GCC_JIT_GLOBAL_EXPORTED, |
| 636 |
double_type, |
| 637 |
"global_double1_3"); |
| 638 |
gcc_jit_rvalue *rval = gcc_jit_context_new_rvalue_from_int ( |
| 639 |
ctxt, double_type, 3); |
| 640 |
gcc_jit_global_set_initializer_rvalue (double1, |
| 641 |
rval); |
| 642 |
} |
| 643 |
{ /* double foo = 3 * 3 + 3 */ |
| 644 |
gcc_jit_lvalue *double1 = gcc_jit_context_new_global ( |
| 645 |
ctxt, NULL, |
| 646 |
GCC_JIT_GLOBAL_EXPORTED, |
| 647 |
double_type, |
| 648 |
"global_double2_12"); |
| 649 |
gcc_jit_rvalue *rval = gcc_jit_context_new_rvalue_from_int ( |
| 650 |
ctxt, double_type, 3); |
| 651 |
gcc_jit_rvalue *rval_mul = gcc_jit_context_new_binary_op (ctxt, 0, |
| 652 |
GCC_JIT_BINARY_OP_MULT, |
| 653 |
double_type, |
| 654 |
rval, |
| 655 |
rval); |
| 656 |
gcc_jit_rvalue *rval_plus = gcc_jit_context_new_binary_op (ctxt, 0, |
| 657 |
GCC_JIT_BINARY_OP_PLUS, |
| 658 |
double_type, |
| 659 |
rval_mul, |
| 660 |
rval); |
| 661 |
gcc_jit_global_set_initializer_rvalue (double1, |
| 662 |
rval_plus); |
| 663 |
} |
| 664 |
{ /* bool foo = 3 + 3 <= 6; */ |
| 665 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 666 |
ctxt, NULL, |
| 667 |
GCC_JIT_GLOBAL_EXPORTED, |
| 668 |
bool_type, |
| 669 |
"global_bool1_1"); |
| 670 |
gcc_jit_rvalue *rval3_0 = gcc_jit_context_new_rvalue_from_int ( |
| 671 |
ctxt, int_type, 3); |
| 672 |
gcc_jit_rvalue *rval3_1 = gcc_jit_context_new_rvalue_from_int ( |
| 673 |
ctxt, int_type, 3); |
| 674 |
gcc_jit_rvalue *rval6 = gcc_jit_context_new_rvalue_from_int ( |
| 675 |
ctxt, int_type, 6); |
| 676 |
gcc_jit_rvalue *rval_plus = gcc_jit_context_new_binary_op (ctxt, |
| 677 |
0, |
| 678 |
GCC_JIT_BINARY_OP_PLUS, |
| 679 |
int_type, |
| 680 |
rval3_0, |
| 681 |
rval3_1); |
| 682 |
gcc_jit_rvalue *rval_le = gcc_jit_context_new_comparison (ctxt, |
| 683 |
0, |
| 684 |
GCC_JIT_COMPARISON_LE, |
| 685 |
rval_plus, |
| 686 |
rval6); |
| 687 |
|
| 688 |
gcc_jit_global_set_initializer_rvalue (foo, |
| 689 |
rval_le); |
| 690 |
} |
| 691 |
gcc_jit_lvalue *global_intarr_1234; |
| 692 |
{ /* int foo[] = {1,2,3,4}; */ |
| 693 |
|
| 694 |
gcc_jit_type *arr_type = gcc_jit_context_new_array_type (ctxt, |
| 695 |
0, |
| 696 |
int_type, |
| 697 |
4); |
| 698 |
gcc_jit_rvalue *rval_1 = gcc_jit_context_new_rvalue_from_int ( |
| 699 |
ctxt, int_type, 1); |
| 700 |
gcc_jit_rvalue *rval_2 = gcc_jit_context_new_rvalue_from_int ( |
| 701 |
ctxt, int_type, 2); |
| 702 |
gcc_jit_rvalue *rval_3 = gcc_jit_context_new_rvalue_from_int ( |
| 703 |
ctxt, int_type, 3); |
| 704 |
gcc_jit_rvalue *rval_4 = gcc_jit_context_new_rvalue_from_int ( |
| 705 |
ctxt, int_type, 4); |
| 706 |
|
| 707 |
gcc_jit_rvalue *values[] = {rval_1, rval_2, rval_3, rval_4}; |
| 708 |
|
| 709 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_array_constructor (ctxt, |
| 710 |
0, |
| 711 |
arr_type, |
| 712 |
4, |
| 713 |
values); |
| 714 |
global_intarr_1234 = gcc_jit_context_new_global ( |
| 715 |
ctxt, NULL, |
| 716 |
GCC_JIT_GLOBAL_EXPORTED, |
| 717 |
arr_type, |
| 718 |
"global_intarr_1234"); |
| 719 |
gcc_jit_global_set_initializer_rvalue (global_intarr_1234, ctor); |
| 720 |
} |
| 721 |
{ /* float foo[4] = {1,2}; */ |
| 722 |
|
| 723 |
gcc_jit_type *arr_type = gcc_jit_context_new_array_type (ctxt, |
| 724 |
0, |
| 725 |
float_type, |
| 726 |
4); |
| 727 |
gcc_jit_rvalue *rval_1 = gcc_jit_context_new_rvalue_from_int ( |
| 728 |
ctxt, float_type, 1); |
| 729 |
gcc_jit_rvalue *rval_2 = gcc_jit_context_new_rvalue_from_int ( |
| 730 |
ctxt, float_type, 2); |
| 731 |
|
| 732 |
gcc_jit_rvalue *values[] = {rval_1, rval_2}; |
| 733 |
|
| 734 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_array_constructor (ctxt, |
| 735 |
0, |
| 736 |
arr_type, |
| 737 |
2, |
| 738 |
values); |
| 739 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 740 |
ctxt, NULL, |
| 741 |
GCC_JIT_GLOBAL_EXPORTED, |
| 742 |
arr_type, |
| 743 |
"global_floatarr_12"); |
| 744 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 745 |
} |
| 746 |
{ /* float foo[4] = {1,2}; |
| 747 |
With different array objects of same size and type. */ |
| 748 |
|
| 749 |
gcc_jit_type *arr_type = gcc_jit_context_new_array_type (ctxt, |
| 750 |
0, |
| 751 |
float_type, |
| 752 |
4); |
| 753 |
gcc_jit_type *arr_type1 = gcc_jit_context_new_array_type (ctxt, |
| 754 |
0, |
| 755 |
float_type, |
| 756 |
4); |
| 757 |
gcc_jit_rvalue *rval_1 = gcc_jit_context_new_rvalue_from_int ( |
| 758 |
ctxt, float_type, 1); |
| 759 |
gcc_jit_rvalue *rval_2 = gcc_jit_context_new_rvalue_from_int ( |
| 760 |
ctxt, float_type, 2); |
| 761 |
|
| 762 |
gcc_jit_rvalue *values[] = {rval_1, rval_2}; |
| 763 |
|
| 764 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_array_constructor (ctxt, |
| 765 |
0, |
| 766 |
arr_type1, |
| 767 |
2, |
| 768 |
values); |
| 769 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 770 |
ctxt, NULL, |
| 771 |
GCC_JIT_GLOBAL_EXPORTED, |
| 772 |
arr_type, |
| 773 |
"global_floatarr_12_2"); |
| 774 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 775 |
} |
| 776 |
{ /* float foo[4] = {1,2,0}; (null init) */ |
| 777 |
|
| 778 |
gcc_jit_type *arr_type = gcc_jit_context_new_array_type (ctxt, |
| 779 |
0, |
| 780 |
float_type, |
| 781 |
4); |
| 782 |
gcc_jit_rvalue *rval_1 = gcc_jit_context_new_rvalue_from_int ( |
| 783 |
ctxt, float_type, 1); |
| 784 |
gcc_jit_rvalue *rval_2 = gcc_jit_context_new_rvalue_from_int ( |
| 785 |
ctxt, float_type, 2); |
| 786 |
|
| 787 |
gcc_jit_rvalue *values[] = {rval_1, rval_2, 0}; |
| 788 |
|
| 789 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_array_constructor (ctxt, |
| 790 |
0, |
| 791 |
arr_type, |
| 792 |
2, |
| 793 |
values); |
| 794 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 795 |
ctxt, NULL, |
| 796 |
GCC_JIT_GLOBAL_EXPORTED, |
| 797 |
arr_type, |
| 798 |
"global_floatarr_120"); |
| 799 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 800 |
} |
| 801 |
{ /* float foo[4] = {}; (null init) */ |
| 802 |
|
| 803 |
gcc_jit_type *arr_type = gcc_jit_context_new_array_type (ctxt, |
| 804 |
0, |
| 805 |
float_type, |
| 806 |
4); |
| 807 |
|
| 808 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_array_constructor (ctxt, |
| 809 |
0, |
| 810 |
arr_type, |
| 811 |
0, |
| 812 |
0); |
| 813 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 814 |
ctxt, NULL, |
| 815 |
GCC_JIT_GLOBAL_EXPORTED, |
| 816 |
arr_type, |
| 817 |
"global_floatarr_0000"); |
| 818 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 819 |
} |
| 820 |
{ /* float foo[4] = {NULL , NULL, 3, NULL, 5, 6}; (null init) */ |
| 821 |
|
| 822 |
gcc_jit_type *arr_type = gcc_jit_context_new_array_type (ctxt, |
| 823 |
0, |
| 824 |
float_type, |
| 825 |
8); |
| 826 |
gcc_jit_rvalue *rval3 = gcc_jit_context_new_rvalue_from_int ( |
| 827 |
ctxt, float_type, 3); |
| 828 |
gcc_jit_rvalue *rval5 = gcc_jit_context_new_rvalue_from_int ( |
| 829 |
ctxt, float_type, 5); |
| 830 |
gcc_jit_rvalue *rval6 = gcc_jit_context_new_rvalue_from_int ( |
| 831 |
ctxt, float_type, 6); |
| 832 |
|
| 833 |
gcc_jit_rvalue *values[] = {0, 0, rval3, 0, rval5, rval6, 0 }; |
| 834 |
|
| 835 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_array_constructor (ctxt, |
| 836 |
0, |
| 837 |
arr_type, |
| 838 |
7, |
| 839 |
values); |
| 840 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 841 |
ctxt, NULL, |
| 842 |
GCC_JIT_GLOBAL_EXPORTED, |
| 843 |
arr_type, |
| 844 |
"global_floatarr_00305600"); |
| 845 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 846 |
} |
| 847 |
{ /* int *foo[4] = {0, &global_intarr_1234[1], 0}; */ |
| 848 |
|
| 849 |
gcc_jit_type *arr_type = gcc_jit_context_new_array_type (ctxt, |
| 850 |
0, |
| 851 |
pint_type, |
| 852 |
4); |
| 853 |
gcc_jit_rvalue *rval_1 = gcc_jit_context_new_rvalue_from_int ( |
| 854 |
ctxt, int_type, 1); |
| 855 |
gcc_jit_lvalue *arr_access = gcc_jit_context_new_array_access ( |
| 856 |
ctxt, |
| 857 |
0, |
| 858 |
gcc_jit_lvalue_as_rvalue (global_intarr_1234), |
| 859 |
rval_1); |
| 860 |
gcc_jit_rvalue *rval_2 = gcc_jit_lvalue_get_address (arr_access, 0); |
| 861 |
gcc_jit_rvalue *rval_3 = gcc_jit_context_null (ctxt, pint_type); |
| 862 |
|
| 863 |
gcc_jit_rvalue *values[] = {0, rval_2, rval_3}; |
| 864 |
|
| 865 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_array_constructor (ctxt, |
| 866 |
0, |
| 867 |
arr_type, |
| 868 |
2, |
| 869 |
values); |
| 870 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 871 |
ctxt, NULL, |
| 872 |
GCC_JIT_GLOBAL_EXPORTED, |
| 873 |
arr_type, |
| 874 |
"global_pintarr_x2xx"); |
| 875 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 876 |
} |
| 877 |
{ /* char foo[4] = {'q','w','e',0}; */ |
| 878 |
|
| 879 |
gcc_jit_type *arr_type = gcc_jit_context_new_array_type (ctxt, |
| 880 |
0, |
| 881 |
char_type, |
| 882 |
4); |
| 883 |
|
| 884 |
|
| 885 |
gcc_jit_rvalue *rvals[] = { |
| 886 |
gcc_jit_context_new_rvalue_from_int ( ctxt, char_type, 'q'), |
| 887 |
gcc_jit_context_new_rvalue_from_int ( ctxt, char_type, 'w'), |
| 888 |
gcc_jit_context_new_rvalue_from_int ( ctxt, char_type, 'e'), |
| 889 |
gcc_jit_context_new_rvalue_from_int ( ctxt, char_type, 0) |
| 890 |
}; |
| 891 |
|
| 892 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_array_constructor (ctxt, |
| 893 |
0, |
| 894 |
arr_type, |
| 895 |
4, |
| 896 |
rvals); |
| 897 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 898 |
ctxt, NULL, |
| 899 |
GCC_JIT_GLOBAL_EXPORTED, |
| 900 |
arr_type, |
| 901 |
"global_chararr_qwe"); |
| 902 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 903 |
} |
| 904 |
{ /* int foo[2][2] = {{1,2},{3,4}}; */ |
| 905 |
|
| 906 |
gcc_jit_type *row_type = gcc_jit_context_new_array_type (ctxt, |
| 907 |
0, |
| 908 |
int_type, |
| 909 |
2); |
| 910 |
|
| 911 |
gcc_jit_type *arr_type = gcc_jit_context_new_array_type (ctxt, |
| 912 |
0, |
| 913 |
row_type, |
| 914 |
2); |
| 915 |
gcc_jit_rvalue *rvals_row0[] = { |
| 916 |
gcc_jit_context_new_rvalue_from_int ( ctxt, int_type, 1), |
| 917 |
gcc_jit_context_new_rvalue_from_int ( ctxt, int_type, 2) |
| 918 |
}; |
| 919 |
gcc_jit_rvalue *rvals_row1[] = { |
| 920 |
gcc_jit_context_new_rvalue_from_int ( ctxt, int_type, 3), |
| 921 |
gcc_jit_context_new_rvalue_from_int ( ctxt, int_type, 4) |
| 922 |
}; |
| 923 |
|
| 924 |
gcc_jit_rvalue *ctor_row0 = |
| 925 |
gcc_jit_context_new_array_constructor (ctxt, |
| 926 |
0, |
| 927 |
row_type, |
| 928 |
2, |
| 929 |
rvals_row0); |
| 930 |
gcc_jit_rvalue *ctor_row1 = |
| 931 |
gcc_jit_context_new_array_constructor (ctxt, |
| 932 |
0, |
| 933 |
row_type, |
| 934 |
2, |
| 935 |
rvals_row1); |
| 936 |
gcc_jit_rvalue *ctors_row[] = {ctor_row0, ctor_row1}; |
| 937 |
|
| 938 |
gcc_jit_rvalue *ctor_arr = |
| 939 |
gcc_jit_context_new_array_constructor (ctxt, |
| 940 |
0, |
| 941 |
arr_type, |
| 942 |
2, |
| 943 |
ctors_row); |
| 944 |
|
| 945 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 946 |
ctxt, NULL, |
| 947 |
GCC_JIT_GLOBAL_EXPORTED, |
| 948 |
arr_type, |
| 949 |
"global_int2x2matrix_1234"); |
| 950 |
|
| 951 |
gcc_jit_global_set_initializer_rvalue (foo, ctor_arr); |
| 952 |
} |
| 953 |
{ /* const char *foo[4] = {"qwe", "asd"}; */ |
| 954 |
|
| 955 |
gcc_jit_type *arr_type = gcc_jit_context_new_array_type (ctxt, |
| 956 |
0, |
| 957 |
cpchar_type, |
| 958 |
4); |
| 959 |
|
| 960 |
|
| 961 |
gcc_jit_rvalue *rvals[] = { |
| 962 |
gcc_jit_context_new_string_literal (ctxt, "qwe"), |
| 963 |
gcc_jit_context_new_string_literal (ctxt, "asd") |
| 964 |
}; |
| 965 |
|
| 966 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_array_constructor (ctxt, |
| 967 |
0, |
| 968 |
arr_type, |
| 969 |
2, |
| 970 |
rvals); |
| 971 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 972 |
ctxt, NULL, |
| 973 |
GCC_JIT_GLOBAL_EXPORTED, |
| 974 |
arr_type, |
| 975 |
"global_cpchararr_qwe_asd"); |
| 976 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 977 |
} |
| 978 |
{ /* const int foo = 3; |
| 979 |
int bar = foo; |
| 980 |
*/ |
| 981 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 982 |
ctxt, NULL, |
| 983 |
GCC_JIT_GLOBAL_EXPORTED, |
| 984 |
gcc_jit_type_get_const (int_type), |
| 985 |
"global_const_int_3"); |
| 986 |
gcc_jit_rvalue *rval3 = gcc_jit_context_new_rvalue_from_int ( |
| 987 |
ctxt, int_type, 3); |
| 988 |
gcc_jit_global_set_initializer_rvalue (foo, |
| 989 |
rval3); |
| 990 |
gcc_jit_lvalue *bar = gcc_jit_context_new_global ( |
| 991 |
ctxt, NULL, |
| 992 |
GCC_JIT_GLOBAL_EXPORTED, |
| 993 |
int_type, |
| 994 |
"global_lvalueinit_int_3"); |
| 995 |
gcc_jit_global_set_initializer_rvalue (bar, |
| 996 |
gcc_jit_lvalue_as_rvalue (foo)); |
| 997 |
} |
| 998 |
{ /* int foo = 3 * 2; |
| 999 |
int arr[] = {1,2,3,4}; |
| 1000 |
int *bar = &arr[2] + 1 |
| 1001 |
|
| 1002 |
Example in the docs. |
| 1003 |
*/ |
| 1004 |
|
| 1005 |
gcc_jit_type *arr_type = gcc_jit_context_new_array_type (ctxt, |
| 1006 |
0, |
| 1007 |
int_type, |
| 1008 |
4); |
| 1009 |
gcc_jit_rvalue *rval_1 = gcc_jit_context_new_rvalue_from_int ( |
| 1010 |
ctxt, int_type, 1); |
| 1011 |
gcc_jit_rvalue *rval_2 = gcc_jit_context_new_rvalue_from_int ( |
| 1012 |
ctxt, int_type, 2); |
| 1013 |
gcc_jit_rvalue *rval_3 = gcc_jit_context_new_rvalue_from_int ( |
| 1014 |
ctxt, int_type, 3); |
| 1015 |
gcc_jit_rvalue *rval_4 = gcc_jit_context_new_rvalue_from_int ( |
| 1016 |
ctxt, int_type, 4); |
| 1017 |
|
| 1018 |
gcc_jit_rvalue *values[] = {rval_1, rval_2, rval_3, rval_4}; |
| 1019 |
|
| 1020 |
gcc_jit_rvalue *ctor = gcc_jit_context_new_array_constructor (ctxt, |
| 1021 |
0, |
| 1022 |
arr_type, |
| 1023 |
4, |
| 1024 |
values); |
| 1025 |
gcc_jit_lvalue *global_intarr_1234 = |
| 1026 |
gcc_jit_context_new_global (ctxt, NULL, |
| 1027 |
GCC_JIT_GLOBAL_EXPORTED, |
| 1028 |
arr_type, |
| 1029 |
"global_intarr_1234_2"); |
| 1030 |
|
| 1031 |
gcc_jit_global_set_initializer_rvalue (global_intarr_1234, ctor); |
| 1032 |
|
| 1033 |
gcc_jit_lvalue *bar = |
| 1034 |
gcc_jit_context_new_global (ctxt, NULL, |
| 1035 |
GCC_JIT_GLOBAL_EXPORTED, |
| 1036 |
int_type, |
| 1037 |
"global_int_6"); |
| 1038 |
gcc_jit_global_set_initializer_rvalue |
| 1039 |
(bar, |
| 1040 |
gcc_jit_context_new_binary_op |
| 1041 |
(ctxt, 0, GCC_JIT_BINARY_OP_MULT, |
| 1042 |
int_type, |
| 1043 |
gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 3), |
| 1044 |
gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 2))); |
| 1045 |
|
| 1046 |
gcc_jit_lvalue *pfoo = |
| 1047 |
gcc_jit_context_new_global (ctxt, NULL, |
| 1048 |
GCC_JIT_GLOBAL_EXPORTED, |
| 1049 |
gcc_jit_type_get_pointer (int_type), |
| 1050 |
"global_pint_4"); |
| 1051 |
/* int *bar = &arr[2] + 1; |
| 1052 |
|
| 1053 |
In practice we could just do &foo[3] |
| 1054 |
but just prove folding this works. */ |
| 1055 |
gcc_jit_global_set_initializer_rvalue ( |
| 1056 |
pfoo, |
| 1057 |
gcc_jit_lvalue_get_address ( |
| 1058 |
gcc_jit_context_new_array_access ( |
| 1059 |
ctxt, 0, |
| 1060 |
gcc_jit_lvalue_get_address ( |
| 1061 |
gcc_jit_context_new_array_access ( |
| 1062 |
ctxt, 0, |
| 1063 |
gcc_jit_lvalue_as_rvalue (global_intarr_1234), |
| 1064 |
gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 2)), |
| 1065 |
0), |
| 1066 |
gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 1)), |
| 1067 |
0)); |
| 1068 |
} |
| 1069 |
{ /* static int bar = 11; |
| 1070 |
int foo () { return bar; } */ |
| 1071 |
|
| 1072 |
gcc_jit_lvalue *bar = gcc_jit_context_new_global ( |
| 1073 |
ctxt, NULL, |
| 1074 |
GCC_JIT_GLOBAL_INTERNAL, |
| 1075 |
int_type, |
| 1076 |
"global_static_int_11"); |
| 1077 |
gcc_jit_rvalue *rval1 = gcc_jit_context_new_rvalue_from_int ( |
| 1078 |
ctxt, int_type, 11); |
| 1079 |
gcc_jit_global_set_initializer_rvalue (bar, |
| 1080 |
rval1); |
| 1081 |
|
| 1082 |
gcc_jit_function *fn11 = |
| 1083 |
gcc_jit_context_new_function (ctxt, |
| 1084 |
0, |
| 1085 |
GCC_JIT_FUNCTION_EXPORTED, |
| 1086 |
int_type, |
| 1087 |
"fn_int_11", |
| 1088 |
0, |
| 1089 |
0, |
| 1090 |
0); |
| 1091 |
gcc_jit_block *block = gcc_jit_function_new_block (fn11, "start"); |
| 1092 |
|
| 1093 |
gcc_jit_block_end_with_return (block, |
| 1094 |
0, |
| 1095 |
gcc_jit_lvalue_as_rvalue(bar)); |
| 1096 |
} |
| 1097 |
{ /* static const int cbar = 11; |
| 1098 |
int cfoo () { return cbar; } */ |
| 1099 |
|
| 1100 |
gcc_jit_lvalue *bar = gcc_jit_context_new_global ( |
| 1101 |
ctxt, NULL, |
| 1102 |
GCC_JIT_GLOBAL_INTERNAL, |
| 1103 |
gcc_jit_type_get_const (int_type), |
| 1104 |
"global_static_cint_11"); |
| 1105 |
gcc_jit_rvalue *rval1 = gcc_jit_context_new_rvalue_from_int ( |
| 1106 |
ctxt, int_type, 11); |
| 1107 |
gcc_jit_global_set_initializer_rvalue (bar, |
| 1108 |
rval1); |
| 1109 |
|
| 1110 |
gcc_jit_function *fn11 = |
| 1111 |
gcc_jit_context_new_function (ctxt, |
| 1112 |
0, |
| 1113 |
GCC_JIT_FUNCTION_EXPORTED, |
| 1114 |
int_type, |
| 1115 |
"fn_cint_11", |
| 1116 |
0, |
| 1117 |
0, |
| 1118 |
0); |
| 1119 |
gcc_jit_block *block = gcc_jit_function_new_block (fn11, "start"); |
| 1120 |
|
| 1121 |
gcc_jit_block_end_with_return (block, |
| 1122 |
0, |
| 1123 |
gcc_jit_lvalue_as_rvalue(bar)); |
| 1124 |
} |
| 1125 |
{ /* static const int cbar = 12; |
| 1126 |
const int* cfoo () { return &cbar; } */ |
| 1127 |
|
| 1128 |
gcc_jit_lvalue *bar = gcc_jit_context_new_global ( |
| 1129 |
ctxt, NULL, |
| 1130 |
GCC_JIT_GLOBAL_INTERNAL, |
| 1131 |
gcc_jit_type_get_const (int_type), |
| 1132 |
"global_static_cint_12"); |
| 1133 |
gcc_jit_rvalue *rval1 = gcc_jit_context_new_rvalue_from_int ( |
| 1134 |
ctxt, int_type, 12); |
| 1135 |
gcc_jit_global_set_initializer_rvalue (bar, |
| 1136 |
rval1); |
| 1137 |
|
| 1138 |
gcc_jit_function *fn11 = |
| 1139 |
gcc_jit_context_new_function (ctxt, |
| 1140 |
0, |
| 1141 |
GCC_JIT_FUNCTION_EXPORTED, |
| 1142 |
gcc_jit_type_get_pointer(int_type), |
| 1143 |
"fn_cint_12", |
| 1144 |
0, |
| 1145 |
0, |
| 1146 |
0); |
| 1147 |
|
| 1148 |
gcc_jit_block *block = gcc_jit_function_new_block (fn11, "start"); |
| 1149 |
|
| 1150 |
gcc_jit_block_end_with_return (block, |
| 1151 |
0, |
| 1152 |
gcc_jit_lvalue_get_address (bar, 0)); |
| 1153 |
} |
| 1154 |
{ /* const int foo = 3; |
| 1155 |
short bar = (short)foo; |
| 1156 |
|
| 1157 |
Assure casts fold |
| 1158 |
*/ |
| 1159 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 1160 |
ctxt, NULL, |
| 1161 |
GCC_JIT_GLOBAL_EXPORTED, |
| 1162 |
gcc_jit_type_get_const (int_type), |
| 1163 |
"global_const_int_4"); |
| 1164 |
gcc_jit_rvalue *rval3 = gcc_jit_context_new_rvalue_from_int ( |
| 1165 |
ctxt, int_type, 3); |
| 1166 |
gcc_jit_global_set_initializer_rvalue (foo, |
| 1167 |
rval3); |
| 1168 |
gcc_jit_lvalue *bar = gcc_jit_context_new_global ( |
| 1169 |
ctxt, NULL, |
| 1170 |
GCC_JIT_GLOBAL_EXPORTED, |
| 1171 |
short_type, |
| 1172 |
"global_lvalueinit_short_3"); |
| 1173 |
gcc_jit_global_set_initializer_rvalue ( |
| 1174 |
bar, |
| 1175 |
gcc_jit_context_new_cast( ctxt, 0, |
| 1176 |
gcc_jit_lvalue_as_rvalue (foo), |
| 1177 |
short_type)); |
| 1178 |
} |
| 1179 |
{ /* const int foo = 3; |
| 1180 |
const int const *bar = &foo; */ |
| 1181 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 1182 |
ctxt, NULL, |
| 1183 |
GCC_JIT_GLOBAL_EXPORTED, |
| 1184 |
gcc_jit_type_get_const (int_type), |
| 1185 |
"global_const_int_6"); |
| 1186 |
gcc_jit_rvalue *rval3 = gcc_jit_context_new_rvalue_from_int ( |
| 1187 |
ctxt, int_type, 3); |
| 1188 |
gcc_jit_global_set_initializer_rvalue (foo, |
| 1189 |
rval3); |
| 1190 |
gcc_jit_lvalue *bar = gcc_jit_context_new_global ( |
| 1191 |
ctxt, NULL, |
| 1192 |
GCC_JIT_GLOBAL_EXPORTED, |
| 1193 |
gcc_jit_type_get_const ( |
| 1194 |
gcc_jit_type_get_pointer ( |
| 1195 |
gcc_jit_type_get_const ( |
| 1196 |
int_type))), |
| 1197 |
"global_lvalueinit_cpcint_3"); |
| 1198 |
gcc_jit_global_set_initializer_rvalue ( |
| 1199 |
bar, |
| 1200 |
gcc_jit_lvalue_get_address (foo, 0)); |
| 1201 |
} |
| 1202 |
{ /* const int __attribute__ ((aligned (64))) foo = 3; |
| 1203 |
int bar = foo; |
| 1204 |
|
| 1205 |
Assure alignement does not make the constant "miss" |
| 1206 |
or something strange. |
| 1207 |
*/ |
| 1208 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 1209 |
ctxt, NULL, |
| 1210 |
GCC_JIT_GLOBAL_EXPORTED, |
| 1211 |
gcc_jit_type_get_const (gcc_jit_type_get_aligned (int_type, 64)), |
| 1212 |
"global_const_int_7"); |
| 1213 |
gcc_jit_rvalue *rval = gcc_jit_context_new_rvalue_from_int ( |
| 1214 |
ctxt, int_type, 4); |
| 1215 |
gcc_jit_global_set_initializer_rvalue (foo, |
| 1216 |
rval); |
| 1217 |
gcc_jit_lvalue *bar = gcc_jit_context_new_global ( |
| 1218 |
ctxt, NULL, |
| 1219 |
GCC_JIT_GLOBAL_EXPORTED, |
| 1220 |
int_type, |
| 1221 |
"global_lvalueinit_int_4"); |
| 1222 |
gcc_jit_global_set_initializer_rvalue (bar, |
| 1223 |
gcc_jit_lvalue_as_rvalue (foo)); |
| 1224 |
} |
| 1225 |
{ |
| 1226 |
/* union upintsize { size_t s; int *p } u = {.s = 0xEEEFBEEF}; */ |
| 1227 |
gcc_jit_field *f1 = gcc_jit_context_new_field (ctxt, |
| 1228 |
0, |
| 1229 |
size_type, |
| 1230 |
"s"); |
| 1231 |
gcc_jit_field *f2 = gcc_jit_context_new_field (ctxt, |
| 1232 |
0, |
| 1233 |
pint_type, |
| 1234 |
"p"); |
| 1235 |
gcc_jit_field *fields1[] = {f1, f2}; |
| 1236 |
|
| 1237 |
gcc_jit_type *ubar = gcc_jit_context_new_union_type (ctxt, |
| 1238 |
0, |
| 1239 |
"upintsize", |
| 1240 |
2, |
| 1241 |
fields1); |
| 1242 |
gcc_jit_lvalue *foo = gcc_jit_context_new_global ( |
| 1243 |
ctxt, NULL, |
| 1244 |
GCC_JIT_GLOBAL_EXPORTED, |
| 1245 |
gcc_jit_type_get_const (ubar), |
| 1246 |
"global_const_upintsize_1"); |
| 1247 |
|
| 1248 |
gcc_jit_rvalue *val = gcc_jit_context_new_rvalue_from_long ( |
| 1249 |
ctxt, size_type, 0xEEEFBEEF); |
| 1250 |
|
| 1251 |
gcc_jit_rvalue *ctor = |
| 1252 |
gcc_jit_context_new_union_constructor (ctxt, |
| 1253 |
0, |
| 1254 |
ubar, |
| 1255 |
f1, |
| 1256 |
val); |
| 1257 |
|
| 1258 |
gcc_jit_global_set_initializer_rvalue (foo, ctor); |
| 1259 |
} |
| 1260 |
{/* |
| 1261 |
struct B; |
| 1262 |
struct A { B* b; }; |
| 1263 |
struct B { A* a; }; |
| 1264 |
extern struct B b; |
| 1265 |
struct A a = {.b = b}; |
| 1266 |
struct B b = {.a = a}; |
| 1267 |
|
| 1268 |
See that opaque structs and circular pointers works. |
| 1269 |
*/ |
| 1270 |
|
| 1271 |
gcc_jit_struct *struct_B = |
| 1272 |
gcc_jit_context_new_opaque_struct(ctxt, |
| 1273 |
0, "B"); |
| 1274 |
|
| 1275 |
gcc_jit_field *fields_A[] = |
| 1276 |
{ |
| 1277 |
gcc_jit_context_new_field (ctxt, 0, |
| 1278 |
gcc_jit_type_get_pointer ( |
| 1279 |
gcc_jit_struct_as_type (struct_B)), |
| 1280 |
"b") |
| 1281 |
}; |
| 1282 |
|
| 1283 |
gcc_jit_struct *struct_A = |
| 1284 |
gcc_jit_context_new_struct_type(ctxt, 0, "A", 1, fields_A); |
| 1285 |
|
| 1286 |
gcc_jit_field *fields_B[] = |
| 1287 |
{ |
| 1288 |
gcc_jit_context_new_field (ctxt, 0, |
| 1289 |
gcc_jit_type_get_pointer ( |
| 1290 |
gcc_jit_struct_as_type (struct_A)), |
| 1291 |
"a") |
| 1292 |
}; |
| 1293 |
|
| 1294 |
gcc_jit_struct_set_fields (struct_B, 0, 1, fields_B); |
| 1295 |
|
| 1296 |
gcc_jit_lvalue *a = |
| 1297 |
gcc_jit_context_new_global (ctxt, 0, GCC_JIT_GLOBAL_EXPORTED, |
| 1298 |
gcc_jit_struct_as_type (struct_A), |
| 1299 |
"a_glb"); |
| 1300 |
gcc_jit_lvalue *b = |
| 1301 |
gcc_jit_context_new_global (ctxt, 0, GCC_JIT_GLOBAL_EXPORTED, |
| 1302 |
gcc_jit_struct_as_type (struct_B), |
| 1303 |
"b_glb"); |
| 1304 |
gcc_jit_rvalue *b_addr = gcc_jit_lvalue_get_address( b, 0); |
| 1305 |
gcc_jit_rvalue *a_ctor = |
| 1306 |
gcc_jit_context_new_struct_constructor (ctxt, 0, |
| 1307 |
gcc_jit_struct_as_type (struct_A), |
| 1308 |
1, 0, |
| 1309 |
&b_addr); |
| 1310 |
gcc_jit_rvalue *a_addr = gcc_jit_lvalue_get_address( a, 0); |
| 1311 |
gcc_jit_rvalue *b_ctor = |
| 1312 |
gcc_jit_context_new_struct_constructor (ctxt, 0, |
| 1313 |
gcc_jit_struct_as_type (struct_B), |
| 1314 |
1, 0, |
| 1315 |
&a_addr); |
| 1316 |
|
| 1317 |
gcc_jit_global_set_initializer_rvalue(a, a_ctor); |
| 1318 |
gcc_jit_global_set_initializer_rvalue(b, b_ctor); |
| 1319 |
} |
| 1320 |
} |
| 1321 |
|
| 1322 |
struct fi { |
| 1323 |
float f; |
| 1324 |
int i; |
| 1325 |
}; |
| 1326 |
|
| 1327 |
struct bar1 { |
| 1328 |
float ff; |
| 1329 |
struct fi fi; |
| 1330 |
int ii; |
| 1331 |
}; |
| 1332 |
|
| 1333 |
union ubar1 { |
| 1334 |
float ff; |
| 1335 |
int ii; |
| 1336 |
}; |
| 1337 |
|
| 1338 |
union upintsize { |
| 1339 |
size_t s; |
| 1340 |
int *p; |
| 1341 |
}; |
| 1342 |
|
| 1343 |
struct B_glb; |
| 1344 |
struct A_glb { |
| 1345 |
struct B_glb *b; |
| 1346 |
}; |
| 1347 |
struct B_glb { |
| 1348 |
struct A_glb *a; |
| 1349 |
}; |
| 1350 |
|
| 1351 |
int test_aligned64_works_in_linker_1 __attribute__ ((aligned (64))) = 0; |
| 1352 |
int test_aligned64_works_in_linker_2 __attribute__ ((aligned (64))) = 0; |
| 1353 |
|
| 1354 |
void |
| 1355 |
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) |
| 1356 |
{ |
| 1357 |
CHECK_NON_NULL (result); |
| 1358 |
|
| 1359 |
{ |
| 1360 |
struct bar1 *bar = |
| 1361 |
gcc_jit_result_get_global (result, "global_struct_bar_1234_1"); |
| 1362 |
|
| 1363 |
CHECK_VALUE (bar->ff, 1); |
| 1364 |
CHECK_VALUE (bar->fi.f, 2); |
| 1365 |
CHECK_VALUE (bar->fi.i, 3); |
| 1366 |
CHECK_VALUE (bar->ii, 4); |
| 1367 |
} |
| 1368 |
{ |
| 1369 |
struct bar1 *bar = |
| 1370 |
gcc_jit_result_get_global (result, "global_struct_bar_1234_2"); |
| 1371 |
|
| 1372 |
CHECK_VALUE (bar->ff, 1); |
| 1373 |
CHECK_VALUE (bar->fi.f, 2); |
| 1374 |
CHECK_VALUE (bar->fi.i, 3); |
| 1375 |
CHECK_VALUE (bar->ii, 4); |
| 1376 |
} |
| 1377 |
{ |
| 1378 |
struct fi *fi = gcc_jit_result_get_global (result, "global_struct_fi_23_1"); |
| 1379 |
|
| 1380 |
CHECK_VALUE (fi->f, 2); |
| 1381 |
CHECK_VALUE (fi->i, 3); |
| 1382 |
} |
| 1383 |
{ |
| 1384 |
struct fi *fi = gcc_jit_result_get_global (result, "global_struct_fi_23_2"); |
| 1385 |
|
| 1386 |
CHECK_VALUE (fi->f, 2); |
| 1387 |
CHECK_VALUE (fi->i, 3); |
| 1388 |
} |
| 1389 |
{ |
| 1390 |
struct fi *fi = gcc_jit_result_get_global (result, "global_struct_fi_00_1"); |
| 1391 |
|
| 1392 |
CHECK_VALUE (fi->f, 0); |
| 1393 |
CHECK_VALUE (fi->i, 0); |
| 1394 |
} |
| 1395 |
{ |
| 1396 |
struct fi *fi = gcc_jit_result_get_global (result, "global_struct_fi_00_2"); |
| 1397 |
|
| 1398 |
CHECK_VALUE (fi->f, 0); |
| 1399 |
CHECK_VALUE (fi->i, 0); |
| 1400 |
} |
| 1401 |
{ |
| 1402 |
struct fi *fi = gcc_jit_result_get_global (result, "global_struct_fi_0_1"); |
| 1403 |
|
| 1404 |
CHECK_VALUE (fi->f, 0); |
| 1405 |
CHECK_VALUE (fi->i, 0); |
| 1406 |
} |
| 1407 |
{ |
| 1408 |
struct fi *fi = gcc_jit_result_get_global (result, "global_struct_fi_0_2"); |
| 1409 |
|
| 1410 |
CHECK_VALUE (fi->f, 0); |
| 1411 |
CHECK_VALUE (fi->i, 0); |
| 1412 |
} |
| 1413 |
{ |
| 1414 |
struct fi *fi = gcc_jit_result_get_global (result, "global_struct_fi_6"); |
| 1415 |
|
| 1416 |
CHECK_VALUE (fi->f, 0); |
| 1417 |
CHECK_VALUE (fi->i, 0); |
| 1418 |
} |
| 1419 |
{ |
| 1420 |
struct fi *fi = gcc_jit_result_get_global (result, "global_struct_fi_3"); |
| 1421 |
|
| 1422 |
CHECK_VALUE (fi->f, 2 * 2); |
| 1423 |
CHECK_VALUE (fi->i, 3); |
| 1424 |
} |
| 1425 |
{ |
| 1426 |
union ubar1 *foo = gcc_jit_result_get_global (result, |
| 1427 |
"global_union_ufoo_ff3"); |
| 1428 |
CHECK_VALUE (foo->ff, 3); |
| 1429 |
} |
| 1430 |
{ |
| 1431 |
union ubar1 *foo = gcc_jit_result_get_global (result, |
| 1432 |
"global_union_ufoo_ii2"); |
| 1433 |
CHECK_VALUE (foo->ii, 2); |
| 1434 |
} |
| 1435 |
{ |
| 1436 |
union ubar1 *foo = gcc_jit_result_get_global (result, |
| 1437 |
"global_union_ufoo_ff1c1"); |
| 1438 |
CHECK_VALUE (foo->ff, 1.1f); |
| 1439 |
} |
| 1440 |
{ |
| 1441 |
union ubar1 *foo = gcc_jit_result_get_global (result, |
| 1442 |
"global_union_ufoo_0"); |
| 1443 |
CHECK_VALUE (foo->ii, 0); |
| 1444 |
} |
| 1445 |
{ |
| 1446 |
int *foo = gcc_jit_result_get_global (result, "global_int1_3"); |
| 1447 |
|
| 1448 |
CHECK_VALUE (*foo, 3); |
| 1449 |
} |
| 1450 |
{ |
| 1451 |
int *foo = gcc_jit_result_get_global (result, "global_cvint1_3"); |
| 1452 |
|
| 1453 |
CHECK_VALUE (*foo, 3); |
| 1454 |
} |
| 1455 |
{ |
| 1456 |
int *foo = gcc_jit_result_get_global (result, "global_int2_3"); |
| 1457 |
|
| 1458 |
CHECK_VALUE (*foo, 3); |
| 1459 |
} |
| 1460 |
{ |
| 1461 |
int *foo = gcc_jit_result_get_global (result, "global_int3_18"); |
| 1462 |
|
| 1463 |
CHECK_VALUE (*foo, 18); |
| 1464 |
} |
| 1465 |
{ |
| 1466 |
int *foo = gcc_jit_result_get_global (result, "global_int_alotofoperators"); |
| 1467 |
|
| 1468 |
CHECK_VALUE (*foo, ~(-((((((2 | 8) & 15) ^ 0) << 3 >> 2) - 1) / 2))); |
| 1469 |
} |
| 1470 |
{ |
| 1471 |
int *foo = gcc_jit_result_get_global (result, "global_int4_3"); |
| 1472 |
int **pfoo = gcc_jit_result_get_global (result, "global_pint5"); |
| 1473 |
|
| 1474 |
CHECK_VALUE (*foo, 3); |
| 1475 |
CHECK_VALUE (foo, *pfoo); |
| 1476 |
CHECK_VALUE (**pfoo, 3); |
| 1477 |
} |
| 1478 |
{ |
| 1479 |
int * (*foo) (void) = gcc_jit_result_get_code (result, "fn_pint_0"); |
| 1480 |
int **pfoo = gcc_jit_result_get_global (result, "global_pint6"); |
| 1481 |
|
| 1482 |
CHECK_VALUE (*foo (), 0); |
| 1483 |
CHECK_VALUE (foo (), *pfoo); |
| 1484 |
CHECK_VALUE (**pfoo, 0); |
| 1485 |
} |
| 1486 |
{ |
| 1487 |
int *foo = gcc_jit_result_get_global (result, "global_int6_3"); |
| 1488 |
int **pfoo = gcc_jit_result_get_global (result, "global_pint7"); |
| 1489 |
|
| 1490 |
CHECK_VALUE (*foo, 3); |
| 1491 |
CHECK_VALUE (foo + 1, *pfoo); |
| 1492 |
CHECK_VALUE (*(*pfoo - 1), 3); |
| 1493 |
} |
| 1494 |
{ |
| 1495 |
double *foo = gcc_jit_result_get_global (result, "global_double1_3"); |
| 1496 |
|
| 1497 |
CHECK_VALUE (*foo, 3); |
| 1498 |
} |
| 1499 |
{ |
| 1500 |
double *foo = gcc_jit_result_get_global (result, "global_double2_12"); |
| 1501 |
|
| 1502 |
CHECK_VALUE (*foo, 12); |
| 1503 |
} |
| 1504 |
{ |
| 1505 |
_Bool *foo = gcc_jit_result_get_global (result, "global_bool1_1"); |
| 1506 |
|
| 1507 |
CHECK_VALUE (*foo, 1); |
| 1508 |
} |
| 1509 |
{ |
| 1510 |
int *foo = gcc_jit_result_get_global (result, "global_intarr_1234"); |
| 1511 |
|
| 1512 |
CHECK_VALUE (foo[0], 1); |
| 1513 |
CHECK_VALUE (foo[1], 2); |
| 1514 |
CHECK_VALUE (foo[2], 3); |
| 1515 |
CHECK_VALUE (foo[3], 4); |
| 1516 |
} |
| 1517 |
{ |
| 1518 |
float *foo = gcc_jit_result_get_global (result, "global_floatarr_12"); |
| 1519 |
|
| 1520 |
CHECK_VALUE (foo[0], 1); |
| 1521 |
CHECK_VALUE (foo[1], 2); |
| 1522 |
CHECK_VALUE (foo[2], 0); |
| 1523 |
CHECK_VALUE (foo[3], 0); |
| 1524 |
} |
| 1525 |
{ |
| 1526 |
float *foo = gcc_jit_result_get_global (result, "global_floatarr_12_2"); |
| 1527 |
|
| 1528 |
CHECK_VALUE (foo[0], 1); |
| 1529 |
CHECK_VALUE (foo[1], 2); |
| 1530 |
CHECK_VALUE (foo[2], 0); |
| 1531 |
CHECK_VALUE (foo[3], 0); |
| 1532 |
} |
| 1533 |
{ |
| 1534 |
float *foo = gcc_jit_result_get_global (result, "global_floatarr_120"); |
| 1535 |
|
| 1536 |
CHECK_VALUE (foo[0], 1); |
| 1537 |
CHECK_VALUE (foo[1], 2); |
| 1538 |
CHECK_VALUE (foo[2], 0); |
| 1539 |
CHECK_VALUE (foo[3], 0); |
| 1540 |
} |
| 1541 |
{ |
| 1542 |
float *foo = gcc_jit_result_get_global (result, "global_floatarr_0000"); |
| 1543 |
|
| 1544 |
CHECK_VALUE (foo[0], 0); |
| 1545 |
CHECK_VALUE (foo[1], 0); |
| 1546 |
CHECK_VALUE (foo[2], 0); |
| 1547 |
CHECK_VALUE (foo[3], 0); |
| 1548 |
} |
| 1549 |
{ |
| 1550 |
float *foo = gcc_jit_result_get_global (result, "global_floatarr_00305600"); |
| 1551 |
|
| 1552 |
float key[] = {0,0,3,0,5,6,0,0}; |
| 1553 |
|
| 1554 |
CHECK_VALUE (memcmp (foo, key, sizeof key), 0); |
| 1555 |
} |
| 1556 |
{ |
| 1557 |
int **foo = gcc_jit_result_get_global (result, "global_pintarr_x2xx"); |
| 1558 |
|
| 1559 |
CHECK_VALUE (foo[0], 0); |
| 1560 |
CHECK_VALUE (*foo[1], 2); |
| 1561 |
} |
| 1562 |
{ |
| 1563 |
char *foo = gcc_jit_result_get_global (result, "global_chararr_qwe"); |
| 1564 |
const char *key = "qwe"; |
| 1565 |
CHECK_VALUE (strcmp (foo, key), 0); |
| 1566 |
} |
| 1567 |
{ |
| 1568 |
int *foo = gcc_jit_result_get_global (result, "global_int2x2matrix_1234"); |
| 1569 |
|
| 1570 |
for (int i = 0; i < 4; i++) |
| 1571 |
CHECK_VALUE (foo[i], i + 1); |
| 1572 |
} |
| 1573 |
{ |
| 1574 |
const char **foo = |
| 1575 |
gcc_jit_result_get_global (result, "global_cpchararr_qwe_asd"); |
| 1576 |
|
| 1577 |
CHECK_VALUE (strcmp (foo[0], "qwe"), 0); |
| 1578 |
CHECK_VALUE (strcmp (foo[1], "asd"), 0); |
| 1579 |
} |
| 1580 |
{ |
| 1581 |
int *foo = gcc_jit_result_get_global (result, "global_lvalueinit_int_3"); |
| 1582 |
|
| 1583 |
CHECK_VALUE (*foo, 3); |
| 1584 |
} |
| 1585 |
{ |
| 1586 |
int **pint = |
| 1587 |
gcc_jit_result_get_global (result, "global_pint_4"); |
| 1588 |
int *foo = |
| 1589 |
gcc_jit_result_get_global (result, "global_int_6"); |
| 1590 |
CHECK_VALUE (**pint, 4); |
| 1591 |
CHECK_VALUE (*foo, 6); |
| 1592 |
} |
| 1593 |
{ |
| 1594 |
int (*fn)(void) = gcc_jit_result_get_code (result, "fn_int_11"); |
| 1595 |
CHECK_VALUE (fn (), 11); |
| 1596 |
} |
| 1597 |
{ |
| 1598 |
int (*fn)(void) = gcc_jit_result_get_code (result, "fn_cint_11"); |
| 1599 |
CHECK_VALUE (fn (), 11); |
| 1600 |
} |
| 1601 |
{ |
| 1602 |
int *(*fn)(void) = gcc_jit_result_get_code (result, "fn_cint_12"); |
| 1603 |
CHECK_VALUE (*fn (), 12); |
| 1604 |
} |
| 1605 |
{ |
| 1606 |
short *foo = |
| 1607 |
gcc_jit_result_get_code (result, "global_lvalueinit_short_3"); |
| 1608 |
CHECK_VALUE (*foo, 3); |
| 1609 |
} |
| 1610 |
{ |
| 1611 |
int **foo = |
| 1612 |
gcc_jit_result_get_code (result, "global_lvalueinit_cpcint_3"); |
| 1613 |
CHECK_VALUE (**foo, 3); |
| 1614 |
} |
| 1615 |
{ |
| 1616 |
int *foo = |
| 1617 |
gcc_jit_result_get_code (result, "global_lvalueinit_int_4"); |
| 1618 |
CHECK_VALUE (*foo, 4); |
| 1619 |
|
| 1620 |
int *bar = |
| 1621 |
gcc_jit_result_get_code (result, "global_const_int_7"); |
| 1622 |
CHECK_VALUE (*bar, 4); |
| 1623 |
/* The linker does not have to support up to 64 alignment, so test that |
| 1624 |
it does before testing that it works in libgccjit. */ |
| 1625 |
if ((size_t) &test_aligned64_works_in_linker_1 % 64 == 0 && |
| 1626 |
(size_t) &test_aligned64_works_in_linker_2 % 64 == 0) |
| 1627 |
CHECK_VALUE ((size_t) bar % 64, 0); /* __attribute__ ((aligned (64))) */ |
| 1628 |
} |
| 1629 |
{ |
| 1630 |
union upintsize *foo = |
| 1631 |
gcc_jit_result_get_code (result, "global_const_upintsize_1"); |
| 1632 |
CHECK_VALUE (foo->p, (void*)0xEEEFBEEF); |
| 1633 |
} |
| 1634 |
{ |
| 1635 |
struct A_glb *a = |
| 1636 |
gcc_jit_result_get_code (result, "a_glb"); |
| 1637 |
struct B_glb *b = |
| 1638 |
gcc_jit_result_get_code (result, "b_glb"); |
| 1639 |
|
| 1640 |
CHECK_VALUE (a->b, b); |
| 1641 |
CHECK_VALUE (b->a, a); |
| 1642 |
} |
| 1643 |
} |