-
Notifications
You must be signed in to change notification settings - Fork 120
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
Go Integer overflows translated from large C enum numbers #133
Comments
I understand the problem. At the same time, the statement
is kind of questionable, I'm afraid. According to C99, That being said, it would probably make sense to use e.g. gcc as reference. But this is not a trivial problem. As enums can be evaluated, they can overflow during evaluation, and if the expression is evaluated in Go (because it is not evaluated before translation), the enum value may have a different result. |
not so easy even in C/C++ codebases |
https://github.com/RadeonOpenCompute/rocm_smi_lib/blob/master/include/rocm_smi/rocm_smi.h#L130 Sometimes people do use this pattern in enums. There are workarounds for it. So if it's too much effort for a corner case, I'm all for closing this ticket. |
@hxy9243 definitely not closing, coz we may eventually find a workaround. The target of c-for-go is to be as practical as possible |
Sure. Right now I'm using hard-coded bash and sed to translate certain numbers in C header files. Would love a more elegant solution with c-for-go. |
In C, some legit enum definitions can generate problematic generations in Go. For example:
The
STATUS_FAILED
can be translated to unsigned integer in Go, which for a int32,STATUS_FAILED
should really be a-1
.The generated code with configuration
TRANSLATOR.ConstRules.enum: eval
.With the rule
expand
, it'll generate a similar problem:which throws Go compile error:
cannot use (_Ciconst_STATUS_FAILED) (untyped int constant 4294967295) as Status_t value in constant declaration (overflows)
.A viable solution might be:
This can happen in many libraries that uses large constant numbers like
0x10000000
or0xFFFF0000
.The text was updated successfully, but these errors were encountered: