Hello,
as stated in the TODO file bitfields are buggy.
For example the following does not work:
struct{short x:12; char y:1;}s; s.y=1;

The attached patch improves bitfield handling.
With it the previous example gets fixed.

There are still corner cases which are still failing, like:
struct{int x:31; char y:2;}s; s.y=1;
in which the char overflows the 32-bit type.

Feel free to apply it to tcc.

Regards,
  Vicente.
This patch improves bitfield handling, but the following still fails:

  int main(){
    struct {
      int  x:31; // long long int x:63;
      char y: 2;
    } s;
    s.y = 1;
    return s.y != 1;
  }

--- a/tccgen.c
+++ b/tccgen.c
@@ -4811,6 +4811,11 @@ ST_FUNC void unary(void)
             gen_op('+');
             /* change type to field type, and set to lvalue */
             vtop->type = s->type;
+            if (vtop->type.t & VT_BITFIELD) {
+              int dbt = vtop->type.t & VT_BTYPE;
+              if(dbt==VT_BOOL || dbt==VT_BYTE || dbt==VT_SHORT)
+                vtop->type.t = (vtop->type.t & ~VT_BTYPE) | VT_INT;
+            }
             vtop->type.t |= qualifiers;
             /* an array is never an lvalue */
             if (!(vtop->type.t & VT_ARRAY)) {
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to