Issue Details (XML | Word | Printable)

Key: PCC-476
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Anders Magnusson
Reporter: Volkmar Klatt
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
pcc

issue with unsigned bitfields

Created: 18/Aug/14 07:31 PM   Updated: 21/Aug/14 09:19 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

File Attachments: 1. Text File tr_20140818_87.c (0.5 kB)

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


 Description  « Hide
/* 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;
}




 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Volkmar Klatt added a comment - 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;
}



Anders Magnusson added a comment - 19/Aug/14 06:28 PM
Do integer promotion on bitfield which size is less than number of bits in int.

Volkmar Klatt added a comment - 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;
}