summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/codegen/mod.rs14
-rw-r--r--src/ir/ty.rs9
-rw-r--r--tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs7
-rw-r--r--tests/expectations/tests/issue-1040.rs7
-rw-r--r--tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h3
-rw-r--r--tests/headers/issue-1040.h1
6 files changed, 40 insertions, 1 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 38214054..ac28244c 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -478,7 +478,19 @@ impl CodeGenerator for Var {
});
}
VarType::Int(val) => {
- let val = helpers::ast_ty::int_expr(val);
+ let int_kind = self.ty()
+ .into_resolver()
+ .through_type_aliases()
+ .through_type_refs()
+ .resolve(ctx)
+ .expect_type()
+ .as_integer()
+ .unwrap();
+ let val = if int_kind.is_signed() {
+ helpers::ast_ty::int_expr(val)
+ } else {
+ helpers::ast_ty::uint_expr(val as _)
+ };
result.push(quote! {
pub const #canonical_ident : #ty = #val ;
});
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index 45555344..0db91385 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -194,6 +194,15 @@ impl Type {
}
}
+ /// Cast this type to an integer kind, or `None` if it is not an integer
+ /// type.
+ pub fn as_integer(&self) -> Option<IntKind> {
+ match self.kind {
+ TypeKind::Int(int_kind) => Some(int_kind),
+ _ => None,
+ }
+ }
+
/// Is this a `const` qualified type?
pub fn is_const(&self) -> bool {
self.is_const
diff --git a/tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs b/tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs
new file mode 100644
index 00000000..9613a7f2
--- /dev/null
+++ b/tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs
@@ -0,0 +1,7 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+pub const a: u32 = 18446744073709551611;
diff --git a/tests/expectations/tests/issue-1040.rs b/tests/expectations/tests/issue-1040.rs
new file mode 100644
index 00000000..3271d0e8
--- /dev/null
+++ b/tests/expectations/tests/issue-1040.rs
@@ -0,0 +1,7 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+pub const g_107: ::std::os::raw::c_ulonglong = 18446744073709551615;
diff --git a/tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h b/tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h
new file mode 100644
index 00000000..c9189952
--- /dev/null
+++ b/tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h
@@ -0,0 +1,3 @@
+typedef unsigned int uint32_t;
+
+uint32_t a = 18446744073709551611;
diff --git a/tests/headers/issue-1040.h b/tests/headers/issue-1040.h
new file mode 100644
index 00000000..1d61d40d
--- /dev/null
+++ b/tests/headers/issue-1040.h
@@ -0,0 +1 @@
+unsigned long long g_107 = 18446744073709551615UL;