aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Noronha <michaeltnoronha@gmail.com>2018-08-12 17:41:43 -0700
committerAndrew Kelley <superjoe30@gmail.com>2018-08-20 22:45:19 -0400
commit7e7e59d8811b9fd0ba7dde345f61597a49a3bd13 (patch)
tree6e66638f672ef95a125d80378d13a69fdcc14620 /src
parentdd4b13ac0326aeb6c2c197bfac49f9e931ccee37 (diff)
downloadzig-7e7e59d8811b9fd0ba7dde345f61597a49a3bd13.tar.gz
zig-7e7e59d8811b9fd0ba7dde345f61597a49a3bd13.zip
translate-c: Correctly translate enum init values, addressing #1360
Diffstat (limited to 'src')
-rw-r--r--src/translate_c.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/translate_c.cpp b/src/translate_c.cpp
index 735a671bcc..da37b907d6 100644
--- a/src/translate_c.cpp
+++ b/src/translate_c.cpp
@@ -458,9 +458,17 @@ static const char *decl_name(const Decl *decl) {
static AstNode *trans_create_node_apint(Context *c, const llvm::APSInt &aps_int) {
AstNode *node = trans_create_node(c, NodeTypeIntLiteral);
node->data.int_literal.bigint = allocate<BigInt>(1);
- bigint_init_data(node->data.int_literal.bigint, aps_int.getRawData(), aps_int.getNumWords(), aps_int.isNegative());
- return node;
+ llvm::APSInt copy = aps_int;
+ llvm::APSInt positive = (~copy)++;
+
+ if (!aps_int.isNegative()) {
+ bigint_init_data(node->data.int_literal.bigint, aps_int.getRawData(), aps_int.getNumWords(), aps_int.isNegative());
+ } else {
+ bigint_init_data(node->data.int_literal.bigint, positive.getRawData(), positive.getNumWords(), aps_int.isNegative());
+ }
+
+ return node;
}
static const Type *qual_type_canon(QualType qt) {