From 7101465403dec23f8752d4b6359e998e89ca3b6b Mon Sep 17 00:00:00 2001 From: Joe Devietti Date: Mon, 9 Mar 2020 23:11:51 -0400 Subject: [PATCH 1/3] avoid gcc warning by appending ULL suffix to integer literals that are too big to fit in a signed 64-bit integer --- src/bindgen/ir/constant.rs | 3 ++- tests/expectations/both/constant_big.c | 8 ++++++++ tests/expectations/both/constant_big.compat.c | 8 ++++++++ tests/expectations/constant_big.c | 8 ++++++++ tests/expectations/constant_big.compat.c | 8 ++++++++ tests/expectations/constant_big.cpp | 8 ++++++++ tests/expectations/tag/constant_big.c | 8 ++++++++ tests/expectations/tag/constant_big.compat.c | 8 ++++++++ tests/rust/constant_big.rs | 2 ++ 9 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/expectations/both/constant_big.c create mode 100644 tests/expectations/both/constant_big.compat.c create mode 100644 tests/expectations/constant_big.c create mode 100644 tests/expectations/constant_big.compat.c create mode 100644 tests/expectations/constant_big.cpp create mode 100644 tests/expectations/tag/constant_big.c create mode 100644 tests/expectations/tag/constant_big.compat.c create mode 100644 tests/rust/constant_big.rs diff --git a/src/bindgen/ir/constant.rs b/src/bindgen/ir/constant.rs index 67d0bf79..0db637a5 100644 --- a/src/bindgen/ir/constant.rs +++ b/src/bindgen/ir/constant.rs @@ -163,7 +163,8 @@ impl Literal { other_code => format!(r"L'\U{:08X}'", other_code), })), syn::Lit::Int(ref value) => { - Ok(Literal::Expr(value.base10_digits().to_string())) + if value.base10_parse::().is_err() { Ok(Literal::Expr(format!("{}ULL",value.base10_digits()))) } + else { Ok(Literal::Expr(value.base10_digits().to_string())) } } syn::Lit::Float(ref value) => { Ok(Literal::Expr(value.base10_digits().to_string())) diff --git a/tests/expectations/both/constant_big.c b/tests/expectations/both/constant_big.c new file mode 100644 index 00000000..4829df14 --- /dev/null +++ b/tests/expectations/both/constant_big.c @@ -0,0 +1,8 @@ +#include +#include +#include +#include + +#define DOESNT_NEED_ULL_SUFFIX 8070450532247928832 + +#define NEEDS_ULL_SUFFIX 9223372036854775808ULL diff --git a/tests/expectations/both/constant_big.compat.c b/tests/expectations/both/constant_big.compat.c new file mode 100644 index 00000000..4829df14 --- /dev/null +++ b/tests/expectations/both/constant_big.compat.c @@ -0,0 +1,8 @@ +#include +#include +#include +#include + +#define DOESNT_NEED_ULL_SUFFIX 8070450532247928832 + +#define NEEDS_ULL_SUFFIX 9223372036854775808ULL diff --git a/tests/expectations/constant_big.c b/tests/expectations/constant_big.c new file mode 100644 index 00000000..4829df14 --- /dev/null +++ b/tests/expectations/constant_big.c @@ -0,0 +1,8 @@ +#include +#include +#include +#include + +#define DOESNT_NEED_ULL_SUFFIX 8070450532247928832 + +#define NEEDS_ULL_SUFFIX 9223372036854775808ULL diff --git a/tests/expectations/constant_big.compat.c b/tests/expectations/constant_big.compat.c new file mode 100644 index 00000000..4829df14 --- /dev/null +++ b/tests/expectations/constant_big.compat.c @@ -0,0 +1,8 @@ +#include +#include +#include +#include + +#define DOESNT_NEED_ULL_SUFFIX 8070450532247928832 + +#define NEEDS_ULL_SUFFIX 9223372036854775808ULL diff --git a/tests/expectations/constant_big.cpp b/tests/expectations/constant_big.cpp new file mode 100644 index 00000000..9f8d9794 --- /dev/null +++ b/tests/expectations/constant_big.cpp @@ -0,0 +1,8 @@ +#include +#include +#include +#include + +static const uint64_t DOESNT_NEED_ULL_SUFFIX = 8070450532247928832; + +static const uint64_t NEEDS_ULL_SUFFIX = 9223372036854775808ULL; diff --git a/tests/expectations/tag/constant_big.c b/tests/expectations/tag/constant_big.c new file mode 100644 index 00000000..4829df14 --- /dev/null +++ b/tests/expectations/tag/constant_big.c @@ -0,0 +1,8 @@ +#include +#include +#include +#include + +#define DOESNT_NEED_ULL_SUFFIX 8070450532247928832 + +#define NEEDS_ULL_SUFFIX 9223372036854775808ULL diff --git a/tests/expectations/tag/constant_big.compat.c b/tests/expectations/tag/constant_big.compat.c new file mode 100644 index 00000000..4829df14 --- /dev/null +++ b/tests/expectations/tag/constant_big.compat.c @@ -0,0 +1,8 @@ +#include +#include +#include +#include + +#define DOESNT_NEED_ULL_SUFFIX 8070450532247928832 + +#define NEEDS_ULL_SUFFIX 9223372036854775808ULL diff --git a/tests/rust/constant_big.rs b/tests/rust/constant_big.rs new file mode 100644 index 00000000..bf25be2c --- /dev/null +++ b/tests/rust/constant_big.rs @@ -0,0 +1,2 @@ +pub const NEEDS_ULL_SUFFIX: u64 = 0x8000_0000_0000_0000; +pub const DOESNT_NEED_ULL_SUFFIX: u64 = 0x7000_0000_0000_0000; From 8638652d1d72296888b540f1ae4a194991eba08b Mon Sep 17 00:00:00 2001 From: Joe Devietti Date: Mon, 9 Mar 2020 23:13:54 -0400 Subject: [PATCH 2/3] ran rustfmt --- src/bindgen/ir/constant.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bindgen/ir/constant.rs b/src/bindgen/ir/constant.rs index 0db637a5..9c7a1401 100644 --- a/src/bindgen/ir/constant.rs +++ b/src/bindgen/ir/constant.rs @@ -163,8 +163,11 @@ impl Literal { other_code => format!(r"L'\U{:08X}'", other_code), })), syn::Lit::Int(ref value) => { - if value.base10_parse::().is_err() { Ok(Literal::Expr(format!("{}ULL",value.base10_digits()))) } - else { Ok(Literal::Expr(value.base10_digits().to_string())) } + if value.base10_parse::().is_err() { + Ok(Literal::Expr(format!("{}ULL", value.base10_digits()))) + } else { + Ok(Literal::Expr(value.base10_digits().to_string())) + } } syn::Lit::Float(ref value) => { Ok(Literal::Expr(value.base10_digits().to_string())) From 6218281443ff9bb21c9502369497f7a7c24dd078 Mon Sep 17 00:00:00 2001 From: Joe Devietti Date: Wed, 11 Mar 2020 09:58:10 -0400 Subject: [PATCH 3/3] updated constant_big test case with large negative numbers --- tests/expectations/both/constant_big.c | 8 ++++++-- tests/expectations/both/constant_big.compat.c | 8 ++++++-- tests/expectations/constant_big.c | 8 ++++++-- tests/expectations/constant_big.compat.c | 8 ++++++-- tests/expectations/constant_big.cpp | 8 ++++++-- tests/expectations/tag/constant_big.c | 8 ++++++-- tests/expectations/tag/constant_big.compat.c | 8 ++++++-- tests/rust/constant_big.rs | 10 ++++++++-- 8 files changed, 50 insertions(+), 16 deletions(-) diff --git a/tests/expectations/both/constant_big.c b/tests/expectations/both/constant_big.c index 4829df14..469bf315 100644 --- a/tests/expectations/both/constant_big.c +++ b/tests/expectations/both/constant_big.c @@ -3,6 +3,10 @@ #include #include -#define DOESNT_NEED_ULL_SUFFIX 8070450532247928832 +#define SIGNED_DOESNT_NEED_ULL_SUFFIX -9223372036854775807 -#define NEEDS_ULL_SUFFIX 9223372036854775808ULL +#define SIGNED_NEEDS_ULL_SUFFIX -9223372036854775808ULL + +#define UNSIGNED_DOESNT_NEED_ULL_SUFFIX 8070450532247928832 + +#define UNSIGNED_NEEDS_ULL_SUFFIX 9223372036854775808ULL diff --git a/tests/expectations/both/constant_big.compat.c b/tests/expectations/both/constant_big.compat.c index 4829df14..469bf315 100644 --- a/tests/expectations/both/constant_big.compat.c +++ b/tests/expectations/both/constant_big.compat.c @@ -3,6 +3,10 @@ #include #include -#define DOESNT_NEED_ULL_SUFFIX 8070450532247928832 +#define SIGNED_DOESNT_NEED_ULL_SUFFIX -9223372036854775807 -#define NEEDS_ULL_SUFFIX 9223372036854775808ULL +#define SIGNED_NEEDS_ULL_SUFFIX -9223372036854775808ULL + +#define UNSIGNED_DOESNT_NEED_ULL_SUFFIX 8070450532247928832 + +#define UNSIGNED_NEEDS_ULL_SUFFIX 9223372036854775808ULL diff --git a/tests/expectations/constant_big.c b/tests/expectations/constant_big.c index 4829df14..469bf315 100644 --- a/tests/expectations/constant_big.c +++ b/tests/expectations/constant_big.c @@ -3,6 +3,10 @@ #include #include -#define DOESNT_NEED_ULL_SUFFIX 8070450532247928832 +#define SIGNED_DOESNT_NEED_ULL_SUFFIX -9223372036854775807 -#define NEEDS_ULL_SUFFIX 9223372036854775808ULL +#define SIGNED_NEEDS_ULL_SUFFIX -9223372036854775808ULL + +#define UNSIGNED_DOESNT_NEED_ULL_SUFFIX 8070450532247928832 + +#define UNSIGNED_NEEDS_ULL_SUFFIX 9223372036854775808ULL diff --git a/tests/expectations/constant_big.compat.c b/tests/expectations/constant_big.compat.c index 4829df14..469bf315 100644 --- a/tests/expectations/constant_big.compat.c +++ b/tests/expectations/constant_big.compat.c @@ -3,6 +3,10 @@ #include #include -#define DOESNT_NEED_ULL_SUFFIX 8070450532247928832 +#define SIGNED_DOESNT_NEED_ULL_SUFFIX -9223372036854775807 -#define NEEDS_ULL_SUFFIX 9223372036854775808ULL +#define SIGNED_NEEDS_ULL_SUFFIX -9223372036854775808ULL + +#define UNSIGNED_DOESNT_NEED_ULL_SUFFIX 8070450532247928832 + +#define UNSIGNED_NEEDS_ULL_SUFFIX 9223372036854775808ULL diff --git a/tests/expectations/constant_big.cpp b/tests/expectations/constant_big.cpp index 9f8d9794..e52f8f3e 100644 --- a/tests/expectations/constant_big.cpp +++ b/tests/expectations/constant_big.cpp @@ -3,6 +3,10 @@ #include #include -static const uint64_t DOESNT_NEED_ULL_SUFFIX = 8070450532247928832; +static const int64_t SIGNED_DOESNT_NEED_ULL_SUFFIX = -9223372036854775807; -static const uint64_t NEEDS_ULL_SUFFIX = 9223372036854775808ULL; +static const int64_t SIGNED_NEEDS_ULL_SUFFIX = -9223372036854775808ULL; + +static const uint64_t UNSIGNED_DOESNT_NEED_ULL_SUFFIX = 8070450532247928832; + +static const uint64_t UNSIGNED_NEEDS_ULL_SUFFIX = 9223372036854775808ULL; diff --git a/tests/expectations/tag/constant_big.c b/tests/expectations/tag/constant_big.c index 4829df14..469bf315 100644 --- a/tests/expectations/tag/constant_big.c +++ b/tests/expectations/tag/constant_big.c @@ -3,6 +3,10 @@ #include #include -#define DOESNT_NEED_ULL_SUFFIX 8070450532247928832 +#define SIGNED_DOESNT_NEED_ULL_SUFFIX -9223372036854775807 -#define NEEDS_ULL_SUFFIX 9223372036854775808ULL +#define SIGNED_NEEDS_ULL_SUFFIX -9223372036854775808ULL + +#define UNSIGNED_DOESNT_NEED_ULL_SUFFIX 8070450532247928832 + +#define UNSIGNED_NEEDS_ULL_SUFFIX 9223372036854775808ULL diff --git a/tests/expectations/tag/constant_big.compat.c b/tests/expectations/tag/constant_big.compat.c index 4829df14..469bf315 100644 --- a/tests/expectations/tag/constant_big.compat.c +++ b/tests/expectations/tag/constant_big.compat.c @@ -3,6 +3,10 @@ #include #include -#define DOESNT_NEED_ULL_SUFFIX 8070450532247928832 +#define SIGNED_DOESNT_NEED_ULL_SUFFIX -9223372036854775807 -#define NEEDS_ULL_SUFFIX 9223372036854775808ULL +#define SIGNED_NEEDS_ULL_SUFFIX -9223372036854775808ULL + +#define UNSIGNED_DOESNT_NEED_ULL_SUFFIX 8070450532247928832 + +#define UNSIGNED_NEEDS_ULL_SUFFIX 9223372036854775808ULL diff --git a/tests/rust/constant_big.rs b/tests/rust/constant_big.rs index bf25be2c..94eb834f 100644 --- a/tests/rust/constant_big.rs +++ b/tests/rust/constant_big.rs @@ -1,2 +1,8 @@ -pub const NEEDS_ULL_SUFFIX: u64 = 0x8000_0000_0000_0000; -pub const DOESNT_NEED_ULL_SUFFIX: u64 = 0x7000_0000_0000_0000; +pub const UNSIGNED_NEEDS_ULL_SUFFIX: u64 = 0x8000_0000_0000_0000; +pub const UNSIGNED_DOESNT_NEED_ULL_SUFFIX: u64 = 0x7000_0000_0000_0000; + +// i64::min_value() +pub const SIGNED_NEEDS_ULL_SUFFIX: i64 = -9223372036854775808; + +// i64::min_value() + 1 +pub const SIGNED_DOESNT_NEED_ULL_SUFFIX: i64 = -9223372036854775807;