~mcf/cproc#51:
Bit-field sign extension in assignment expression result

--------------------------------------
TEST:
bug-c45bd91c-b146-4581-adc8-4beec4c70609.c
RESULT:
FAIL
SRC:
void printf();
struct {
  signed a : 6;
} b;
int c;
unsigned char d;
char e;
int main() {
  e = -1;
  d = e;
  c = b.a = d;
  printf("%d\n", c);
}

CC-OUTPUT:
QBE_PATH:
/nix/store/hkn01j1ncivcsvynhb285g9i9vqkqbhb-single-exec/test.qbe
ASSEMBLY_PATH:
/nix/store/hkn01j1ncivcsvynhb285g9i9vqkqbhb-single-exec/test.s
TEST-OUTPUT-DIFF:
--- output.expected     2019-04-25 09:55:31.819073470 +0000
+++ output.actual       2019-04-25 09:55:31.904073452 +0000
@@ -1 +1 @@
--1
+255
EXIT-CODE:
0
Status
RESOLVED FIXED
Submitter
~ach
Assigned to
No-one
Submitted
8 months ago
Updated
8 months ago
Labels
bug

~mcf REPORTED FIXED 8 months ago

Fixed in 1ef0706e1f.

~mcf 8 months ago

Forgot to mention that this requires a QBE constant folding fix as well: https://git.sr.ht/~mcf/qbe/commit/055e7a7cf74defaee32a5e3e17cb91ec70da144c

I think there may also be a related issue for unsigned bit-fields. QBE is preserves the bits that should be cleared when shifting left in the upper 32 bits of the constant, which then reappear after the right shift.

Register here or Log in to comment, or comment via email.