Fix incorrect integer promotion for bit-fields - #218
Fix incorrect integer promotion for bit-fields#218michael-schwarz with Copilot wants to merge 9 commits into
Conversation
Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
|
@copilot Fix failing regressions. |
Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
Fixed in a777519. The merge from |
|
@copilot: Address Simmo's comments above. |
…dth) and bitfieldWidthOfLval Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com> Agent-Logs-Url: https://github.com/goblint/cil/sessions/b375cb35-22a8-482e-9239-4b1def60eb18
Both addressed in 6c76a45: Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
… option=None) Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com> Agent-Logs-Url: https://github.com/goblint/cil/sessions/b375cb35-22a8-482e-9239-4b1def60eb18
|
@copilot Address Simmo's comments. |
… test to use int bit-fields Agent-Logs-Url: https://github.com/goblint/cil/sessions/d38e0dc5-d41f-423a-9017-8ba98e3d6a2f Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
sim642
left a comment
There was a problem hiding this comment.
I thought this was in a quite good state now but looking at it again I'm more confused than before.
|
I have now manually cleaned up the mess: The key insights are:
We thus have: struct X {
long x : 7; /* signed long 7-bit: range fits in int -> promote to int */
} sx;
int main() {
int r1 = _Generic(sx.x + 0, int : 1, default : -1);
// r1 == 1
// sx.x + 0 caused arithmetic promotion of sx.x to int
/* Unary + also triggers integer promotion */
int r2 = _Generic(+sx.x, int : 1, default : -1);
// r2 == 1
// uplus caused arithmetic promotion of sx.x to int
/* Direct bit-field access does not itself trigger integer promotion. */
int r6 = _Generic(sx.x, int : 1, default : -1);
// r 6 == -1
// sx.x causes no promotion
} |
Fixes integer promotion for
int/unsigned intbit-fields per ISO 6.3.1.1, which specifies that a bit-field whose values fit withinintshall be promoted toint.Changes Made
_Generic, unary ops (+,-,~), switch statements,doBinOp, and variadic argument default promotionsintegralPromotionwith optional?width:intargument replacing the separateintegralPromotionBitfieldfunction —integralPromotion tgives regular promotion;integralPromotion ~width:w tgives bit-field-aware promotion restricted toint/unsigned intbit-fields per the standardbitfieldWidthOfLval : lval -> int option(replacing the formerbitfieldWidthOfExp) andintegralPromotionEhelper for expression-aware promotionNone(non-bitfield) path ofintegralPromotionpreserves the exact original behaviour: only_Booland narrow types (char,short, …) are promoted;int,unsigned int,long, etc. are returned unchangedSome w(bitfield) path applies width-based promotion only toIInt | IUIntas required by ISO 6.3.1.1 ("A bit-field of type bool, int, signed int, or unsigned int"); other bit-field types fall back to regular promotionbitfield4.cusingint : 7/unsigned int : 7bit-fields (the only types eligible for width-based promotion per the standard), registered intestcil.plastestrunc11/bitfield4Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.