| author | |
| committer | |
| log | 7e7e59d8811b9fd0ba7dde345f61597a49a3bd13 |
| tree | 6e66638f672ef95a125d80378d13a69fdcc14620 |
| parent | dd4b13ac0326aeb6c2c197bfac49f9e931ccee37 |
2 files changed, 36 insertions(+), 2 deletions(-)
src/translate_c.cpp+10-2| ... | ... | @@ -458,9 +458,17 @@ static const char *decl_name(const Decl *decl) { |
| 458 | 458 | static AstNode *trans_create_node_apint(Context *c, const llvm::APSInt &aps_int) { |
| 459 | 459 | AstNode *node = trans_create_node(c, NodeTypeIntLiteral); |
| 460 | 460 | node->data.int_literal.bigint = allocate<BigInt>(1); |
| 461 | bigint_init_data(node->data.int_literal.bigint, aps_int.getRawData(), aps_int.getNumWords(), aps_int.isNegative()); | |
| 462 | return node; | |
| 463 | 461 | |
| 462 | llvm::APSInt copy = aps_int; | |
| 463 | llvm::APSInt positive = (~copy)++; | |
| 464 | ||
| 465 | if (!aps_int.isNegative()) { | |
| 466 | bigint_init_data(node->data.int_literal.bigint, aps_int.getRawData(), aps_int.getNumWords(), aps_int.isNegative()); | |
| 467 | } else { | |
| 468 | bigint_init_data(node->data.int_literal.bigint, positive.getRawData(), positive.getNumWords(), aps_int.isNegative()); | |
| 469 | } | |
| 470 | ||
| 471 | return node; | |
| 464 | 472 | } |
| 465 | 473 | |
| 466 | 474 | static const Type *qual_type_canon(QualType qt) { |
test/translate_c.zig+26| ... | ... | @@ -1358,4 +1358,30 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1358 | 1358 | \\ } |
| 1359 | 1359 | \\} |
| 1360 | 1360 | ); |
| 1361 | ||
| 1362 | cases.add("correctly translate enum init values", | |
| 1363 | \\enum EnumWithInits { | |
| 1364 | \\ VAL1 = 0, | |
| 1365 | \\ VAL2 = 1, | |
| 1366 | \\ VAL3 = 2, | |
| 1367 | \\ VAL4 = 3, | |
| 1368 | \\ VAL5 = -1, | |
| 1369 | \\ VAL6 = -2, | |
| 1370 | \\ VAL7 = -3, | |
| 1371 | \\ VAL8 = -4, | |
| 1372 | \\ VAL9 = VAL2 + VAL8, | |
| 1373 | \\}; | |
| 1374 | , | |
| 1375 | \\pub const enum_EnumWithInits = extern enum { | |
| 1376 | \\ VAL1 = 0, | |
| 1377 | \\ VAL2 = 1, | |
| 1378 | \\ VAL3 = 2, | |
| 1379 | \\ VAL4 = 3, | |
| 1380 | \\ VAL5 = -1, | |
| 1381 | \\ VAL6 = -2, | |
| 1382 | \\ VAL7 = -3, | |
| 1383 | \\ VAL8 = -4, | |
| 1384 | \\ VAL9 = -3, | |
| 1385 | \\}; | |
| 1386 | ); | |
| 1361 | 1387 | } |