Menu

#1658 Cast lost in assignment to bitfield

closed-fixed
7
2011-08-27
2010-07-18
No

In assignments to bitfields sdcc sometimes loses casts. This is true for both implicit and explicit casts.

The attached file has been compiled using sdcc -mz80 --std-c99 boolbit.c.

Philipp

Discussion

  • Philipp Klaus Krause

     
  • Philipp Klaus Krause

    I use sdcc 2.9.7 #5879.

     
  • Maarten Brock

    Maarten Brock - 2010-09-24

    I don't think that f() is broken since you're not storing a 0 or a 1. See C99:

    6.7.2.1 Structure and union specifiers
    9 A bit-field is interpreted as a signed or unsigned integer type consisting of the specified
    number of bits. If the value 0 or 1 is stored into a nonzero-width bit-field of type
    _Bool, the value of the bit-field shall compare equal to the value stored.

    Still g() with the explicit cast must be considered broken.

     
  • Philipp Klaus Krause

    Well, the bitfield still has type _Bool. Thus when the assignment operator is used to store something into it, IMO it should be casted to _Bool first, and the result stored into the bitfield. C99, verse 1303: "In simple assignment (=), the value of the right operand is converted to the type of the assignment expression and replaces the value stored in the object designated by the left operand."

    Philipp

     
  • Philipp Klaus Krause

    • priority: 5 --> 7
     
  • Philipp Klaus Krause

    Increasing priority, since bad code is silently generated.

    Philipp

     
  • Philipp Klaus Krause

    • assigned_to: nobody --> spth
     
  • Philipp Klaus Krause

    Fixed in sdcc revision #6768.

    Philipp

     
  • Philipp Klaus Krause

    • labels: --> Icode generator
    • status: open --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB