support large integer constants (#490)

Avoid gcc warning by appending ULL suffix to integer literals that are too big to fit in a signed 64-bit integer.
This commit is contained in:
Emilio Cobos Álvarez
2020-03-11 15:34:33 +01:00
committed by GitHub
9 changed files with 97 additions and 1 deletions
+5 -1
View File
@@ -163,7 +163,11 @@ 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::<i64>().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()))
+12
View File
@@ -0,0 +1,12 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define SIGNED_DOESNT_NEED_ULL_SUFFIX -9223372036854775807
#define SIGNED_NEEDS_ULL_SUFFIX -9223372036854775808ULL
#define UNSIGNED_DOESNT_NEED_ULL_SUFFIX 8070450532247928832
#define UNSIGNED_NEEDS_ULL_SUFFIX 9223372036854775808ULL
@@ -0,0 +1,12 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define SIGNED_DOESNT_NEED_ULL_SUFFIX -9223372036854775807
#define SIGNED_NEEDS_ULL_SUFFIX -9223372036854775808ULL
#define UNSIGNED_DOESNT_NEED_ULL_SUFFIX 8070450532247928832
#define UNSIGNED_NEEDS_ULL_SUFFIX 9223372036854775808ULL
+12
View File
@@ -0,0 +1,12 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define SIGNED_DOESNT_NEED_ULL_SUFFIX -9223372036854775807
#define SIGNED_NEEDS_ULL_SUFFIX -9223372036854775808ULL
#define UNSIGNED_DOESNT_NEED_ULL_SUFFIX 8070450532247928832
#define UNSIGNED_NEEDS_ULL_SUFFIX 9223372036854775808ULL
+12
View File
@@ -0,0 +1,12 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define SIGNED_DOESNT_NEED_ULL_SUFFIX -9223372036854775807
#define SIGNED_NEEDS_ULL_SUFFIX -9223372036854775808ULL
#define UNSIGNED_DOESNT_NEED_ULL_SUFFIX 8070450532247928832
#define UNSIGNED_NEEDS_ULL_SUFFIX 9223372036854775808ULL
+12
View File
@@ -0,0 +1,12 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <new>
static const int64_t SIGNED_DOESNT_NEED_ULL_SUFFIX = -9223372036854775807;
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;
+12
View File
@@ -0,0 +1,12 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define SIGNED_DOESNT_NEED_ULL_SUFFIX -9223372036854775807
#define SIGNED_NEEDS_ULL_SUFFIX -9223372036854775808ULL
#define UNSIGNED_DOESNT_NEED_ULL_SUFFIX 8070450532247928832
#define UNSIGNED_NEEDS_ULL_SUFFIX 9223372036854775808ULL
@@ -0,0 +1,12 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define SIGNED_DOESNT_NEED_ULL_SUFFIX -9223372036854775807
#define SIGNED_NEEDS_ULL_SUFFIX -9223372036854775808ULL
#define UNSIGNED_DOESNT_NEED_ULL_SUFFIX 8070450532247928832
#define UNSIGNED_NEEDS_ULL_SUFFIX 9223372036854775808ULL
+8
View File
@@ -0,0 +1,8 @@
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;