summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-11-14 11:49:08 -0600
committerGitHub <noreply@github.com>2016-11-14 11:49:08 -0600
commitb7259deb35aae61d7d21875e3b3da55e3f4391cc (patch)
treedeb4de2b4964315e2ec62080a6a22d36208e56ae
parentb2081ebf345bee86ad516cbb9c5710580a40cd49 (diff)
parent37c05b71299ec00bd2679c3df22fb6ca0cd0e371 (diff)
Auto merge of #245 - emilio:min, r=fitzgen
codegen: Special-case i64::MIN since it produces a overflow on aster. Proper fix on aster soon, still worth to get this in I guess. r? @fitzgen
-rw-r--r--src/codegen/helpers.rs15
-rwxr-xr-xsrc/codegen/mod.rs7
-rw-r--r--tests/expectations/tests/enum_explicit_type.rs5
-rw-r--r--tests/expectations/tests/macro-expr-basic.rs1
-rw-r--r--tests/headers/enum_explicit_type.hpp6
-rw-r--r--tests/headers/macro-expr-basic.h2
6 files changed, 31 insertions, 5 deletions
diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs
index 016ba478..6e5a6f0e 100644
--- a/src/codegen/helpers.rs
+++ b/src/codegen/helpers.rs
@@ -117,4 +117,19 @@ pub mod ast_ty {
}
}
}
+
+ pub fn int_expr(val: i64) -> P<ast::Expr> {
+ use std::i64;
+ let expr = aster::AstBuilder::new().expr();
+
+ // This is not representable as an i64 if it's negative, so we
+ // special-case it.
+ //
+ // Fix in aster incoming.
+ if val == i64::MIN {
+ expr.neg().uint(1u64 << 63)
+ } else {
+ expr.int(val)
+ }
+ }
}
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index b4c2f3f7..a0b26ead 100755
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -101,7 +101,8 @@ impl CodegenResult {
/// counter internally so the next time we ask for the overload for this
/// name, we get the incremented value, and so on.
fn overload_number(&mut self, name: &str) -> u32 {
- let mut counter = self.overload_counters.entry(name.into()).or_insert(0);
+ let mut counter =
+ self.overload_counters.entry(name.into()).or_insert(0);
let number = *counter;
*counter += 1;
number
@@ -313,7 +314,7 @@ impl CodeGenerator for Var {
.pub_()
.const_(canonical_name)
.expr()
- .int(val)
+ .build(helpers::ast_ty::int_expr(val))
.build(ty);
result.push(const_item)
} else {
@@ -1285,7 +1286,7 @@ impl<'a> EnumBuilder<'a> {
let variant_name = ctx.rust_mangle(variant.name());
let expr = aster::AstBuilder::new().expr();
let expr = match variant.val() {
- EnumVariantValue::Signed(v) => expr.int(v),
+ EnumVariantValue::Signed(v) => helpers::ast_ty::int_expr(v),
EnumVariantValue::Unsigned(v) => expr.uint(v),
};
diff --git a/tests/expectations/tests/enum_explicit_type.rs b/tests/expectations/tests/enum_explicit_type.rs
index 352f4ea9..4e555d3a 100644
--- a/tests/expectations/tests/enum_explicit_type.rs
+++ b/tests/expectations/tests/enum_explicit_type.rs
@@ -16,6 +16,9 @@ pub enum Bigger { Much = 255, Larger = 256, }
#[repr(i64)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum MuchLong { MuchLow = -4294967296, }
+#[repr(i64)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub enum MuchLongLong { I64_MIN = -9223372036854775808, }
#[repr(u64)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub enum MuchLongLong { MuchHigh = 4294967296, }
+pub enum MuchULongLong { MuchHigh = 4294967296, }
diff --git a/tests/expectations/tests/macro-expr-basic.rs b/tests/expectations/tests/macro-expr-basic.rs
index 7a5c71e0..355294e7 100644
--- a/tests/expectations/tests/macro-expr-basic.rs
+++ b/tests/expectations/tests/macro-expr-basic.rs
@@ -7,6 +7,7 @@
pub const FOO: ::std::os::raw::c_uint = 1;
pub const BAR: ::std::os::raw::c_uint = 4;
pub const BAZ: ::std::os::raw::c_uint = 5;
+pub const MIN: ::std::os::raw::c_longlong = -9223372036854775808;
pub const BARR: ::std::os::raw::c_uint = 1;
pub const BAZZ: ::std::os::raw::c_uint = 7;
pub const I_RAN_OUT_OF_DUMB_NAMES: ::std::os::raw::c_uint = 7;
diff --git a/tests/headers/enum_explicit_type.hpp b/tests/headers/enum_explicit_type.hpp
index 4acb3f15..78eadd40 100644
--- a/tests/headers/enum_explicit_type.hpp
+++ b/tests/headers/enum_explicit_type.hpp
@@ -19,6 +19,10 @@ enum MuchLong: long {
MuchLow = -4294967296,
};
-enum MuchLongLong: unsigned long long {
+enum MuchLongLong: long long {
+ I64_MIN = 1ll << 63,
+};
+
+enum MuchULongLong: unsigned long long {
MuchHigh = 4294967296,
};
diff --git a/tests/headers/macro-expr-basic.h b/tests/headers/macro-expr-basic.h
index 55b11367..d2de7fdf 100644
--- a/tests/headers/macro-expr-basic.h
+++ b/tests/headers/macro-expr-basic.h
@@ -2,6 +2,8 @@
#define BAR 4
#define BAZ (FOO + BAR)
+#define MIN (1 << 63)
+
#define BARR (1 << 0)
#define BAZZ ((1 << 1) + BAZ)
#define I_RAN_OUT_OF_DUMB_NAMES (BARR | BAZZ)