<< Back to previous view

[PCC-476] issue with unsigned bitfields Created: 18/Aug/14  Updated: 21/Aug/14

Status: Resolved
Project: pcc
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Volkmar Klatt Assignee: Anders Magnusson
Resolution: Fixed Votes: 0
Environment: pcc 1.1.0.DEVEL 20140818 for i686-pc-linux-gnu

File Attachments: Text File tr_20140818_87.c    

 Description   
/* tr_20140818_87.c - test file for pcc - Volkmar Klatt
   issue with unsigned bitfields

   pcc 1.1.0.DEVEL 20140818 for i686-pc-linux-gnu

   usage:
   gcc tr_20140818_87.c -o z
   pcc tr_20140818_87.c -o zz
   ./z # a
   ./zz # b */
#include <stdio.h>

struct S {
   unsigned f : 22;
};

int main(void)
{
   struct S s = {1};

   if ((s.f = 1) > -1) /* always true */
      printf("a\n");
   else
      printf("b\n");

   return 0;
}




 Comments   
Comment by Volkmar Klatt [ 19/Aug/14 05:10 PM ]
another instance:

/* tr_20140819_89.c - test file for pcc - Volkmar Klatt
   The truncation from a negative int to an unsigned bitfield
   (--> intended overflow) is wrongly propagated
   when assigned to a signed integer

   pcc 1.1.0.DEVEL 20140819 for i686-pc-linux-gnu

   usage:
   gcc tr_20140819_89.c -o z
   pcc tr_20140819_89.c -o zz
   ./z # 65535
   ./zz # -1 */
#include <stdio.h>

struct S {
   unsigned f : 16;
};

int main(void)
{
   struct S s = {0};

   int i = (s.f = -1);
   printf("%i\n", i);

   return 0;
}


Comment by Anders Magnusson [ 19/Aug/14 06:28 PM ]
Do integer promotion on bitfield which size is less than number of bits in int.
Comment by Volkmar Klatt [ 21/Aug/14 09:19 PM ]
open again:

/* tr_20140821_92.c - test file for pcc - Volkmar Klatt
   bitfield issue
   The change from pcc-20140819 --> pcc-20140819
   has caused a regression
   pcc 1.1.0.DEVEL 20140820 for i686-pc-linux-gnu

   usage:
   gcc tr_20140821_92.c -o z
   pcc tr_20140821_92.c -o zz
   ./z # 1
   ./zz # 4294967295 */
#include <stdio.h>

union U {
   unsigned f : 1;
};


int main(void)
{
   static union U u = {3};

   printf("%u\n", u.f);
   return 0;
}


Generated at Fri Oct 31 05:06:21 CET 2014 using JIRA Enterprise Edition, Version: 3.13.1-#333.