-
Notifications
You must be signed in to change notification settings - Fork 729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Constants like UINT_MAX
not recognized
#1636
Comments
Sorry for the delay here. We could probably define a few standard macros in BindgenContext::parsed_macros, if we wanted to fix this. |
I just hit the same problem on macOS with Minimal input: #include <limits.h>
const unsigned long VAR = ULONG_MAX; Command:
Output:
|
One potential solution would be to expose getIntWidth and equivalents for other types ( |
Just ran into this issue, consider this C header: #define TEST0 0x7fffffffffffffff
#define TEST1 0x8000000000000000
#define TEST2 0xefffffffffffffff
#define TEST3 0xfffffffffffffff0
#define TEST4 0xffffffffffffffff leads to this seemingly random output: pub const TEST0: u64 = 9223372036854775807;
pub const TEST1: i64 = -9223372036854775808;
pub const TEST2: i64 = -1152921504606846977;
pub const TEST3: i32 = -16;
pub const TEST4: i32 = -1; I've tried to show the bounds of where the strangeness occurs, (becoming signed, and then 32 bit as the value gets larger) |
This has been fixed by using the |
Input C/C++ Header
Bindgen Invocation
Both
bindgen defines.h
and a minimalbuilder().header("defines.h").generate()?.write_to_file(…)
create the observed behavior.Actual Results
The
__bindgen.i
output frombindgen --dump-preprocessed-output ./defines.h
contains a linewhich shows that to Clang, UINT_MAX is, with limits.h in place, valid.
Expected Results
B should be recognized as a compiler constant and expanded.
I did not manage to follow Clang's reasoning to the end, but when I looked through the
( kind = macro_definition
debug output, not only did theB
macro show up as invalid, but there was also asection, following which I found
UINT_MAX
defined as(__INT_MAX__ *2U +1U)
, where there is no macro for__INT_MAX__
visible in the debug output -- so that's probably a compiler built-in constant. One way to resolve that might be to inject the compiler constants into the constant expression evaluation process that makes values out of nested defines. (Which otherwise work: a#define TWICE_A (A * 2)
expands to 84 in bindgen).The text was updated successfully, but these errors were encountered: