Issue Details (XML | Word | Printable)

Key: PCC-464
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 overflow of a signed bitfield

Created: 10/Aug/14 03:35 PM   Updated: 14/Aug/14 10:27 AM
Component/s: None
Affects Version/s: None
Fix Version/s: None

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

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


 Description  « Hide
/* tr_20140809_65.c - test file for pcc - Volkmar Klatt
   issue with overflow of a signed bitfield

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

   usage:
   gcc tr_20140809_65.c -o z # or other compiler
   pcc tr_20140809_65.c -o zz
   ./z --> -1
   ./zz --> 1 */
#include <stdio.h>

struct S {
   signed f : 1; /* [-1, 0] */
};

int main (void)
{
    struct S s = {0};
    int i = (s.f = 1); /* overflow to -1 */

    printf("%i\n", i);
    return 0;
}




 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Anders Magnusson added a comment - 14/Aug/14 10:27 AM
Rightmost bit as a signed bitfield gave wrong sign on the result. Fixed now, thanks.