Menu

#3463 Bitfield not correctly assigned to pointer

closed-fixed
None
MCS51
5
2022-07-20
2022-07-20
volumit
No

Transfered the issue (think it is a bug) in a test case and run it as part of regression mcs51-large-stack-auto and others). Please can you check!
It fails unexpected on the commented positions (see source below).
Thank you!
SDCC : mcs51 4.2.2 #13448 (Linux)

/* Bitfield issue */
#include <testfwk.h>
#include <stdlib.h>
#include <stdint.h>

__data unsigned char * __data ptemp;
__data unsigned char temp;

struct {
  unsigned char b0 : 1;
  unsigned char b1 : 1;
  unsigned char b2 : 1;
  unsigned char b3 : 1;
  unsigned char b4_7 : 4;
} sb_bf;


void
test(void)
{
  ptemp=&temp;
  sb_bf.b4_7=2;
  ASSERT( sb_bf.b4_7==2 ); //PASS
  *ptemp=0xFF;
  ASSERT( *ptemp == 0xFF ); //PASS
  *ptemp=sb_bf.b4_7;
  ASSERT( *ptemp == 2 ); //FAIL
  ASSERT( *ptemp == 0x2F ); //PASS, but must fail
  *ptemp=(unsigned char) sb_bf.b4_7;
  ASSERT( *ptemp == 2 ); //FAIL
  ASSERT( *ptemp == 0x2F ); //PASS, but must fail
  temp=0xFF;
  ASSERT( temp == 0xFF ); //PASS
  temp=sb_bf.b4_7;
  ASSERT( temp == 2 ); //PASS
}

Discussion

  • Philipp Klaus Krause

    Thanks. I can reproduce the issue for mcs51, hc08 and mos6502.
    There is no issue for stm8 and z80.
    I suspect that this test basically triggers the equivalent of bug #3461, but for different ports.

     
  • Philipp Klaus Krause

    • assigned_to: Philipp Klaus Krause
     
  • Philipp Klaus Krause

    • status: open --> closed-fixed
     
  • Philipp Klaus Krause

    This issue affected mcs51, ds390, hc08, s08, mos6502.
    It is fixed in [r13584].

     

    Related

    Commit: [r13584]


Log in to post a comment.

MongoDB Logo MongoDB