#111 PIC16: fix constant strings

closed-accepted
Borut Ražem
None
5
2008-09-07
2008-07-30
Mauro Giachero
No

Constant strings can contain '\0', so their "emission" cannot rely on it being present only as string termination. This patch implements a more proper way to manage string length.
Fixes regression test failures on nullstring.c.
Applies cleanly to revision 5199.
[Thank you for applying my previous patches!]
Mauro

Discussion

  • Mauro Giachero
    Mauro Giachero
    2008-07-30

    Patch to fix constant strings containing '\0'

     
    Attachments
  • Borut Ražem
    Borut Ražem
    2008-07-30

    Logged In: YES
    user_id=568035
    Originator: NO

    Patch applied in svn revision #5202.

    Mario, the assertion failures are fixed, but the warnings "warning 147: excess elements in array of chars initializer after 'string3'" are still there. Any idea why?

    Thanks for the great work. I hope you'll continue to improve sdcc.

    Borut

     
  • Borut Ražem
    Borut Ražem
    2008-07-30

    • assigned_to: nobody --> borutr
    • status: open --> pending-accepted
     
  • Mauro Giachero
    Mauro Giachero
    2008-07-30

    Logged In: YES
    user_id=2160854
    Originator: YES

    I admit I haven't investigated them a lot, but I assumed that these are due to lines like
    char string3[5] = "a\0b\0c"
    where string3 has 5 bytes allocated, but "a\0b\0c" is 6 bytes long due to the string terminator. After looking at the asm, I assumed that the policy is to use only the first 5 bytes and discard the extra bytes provided. So the warning is correctly pointing out that a part of the provided literal initialization string is discarded.

    Mauro

     
  • Mauro Giachero
    Mauro Giachero
    2008-07-30

    • status: pending-accepted --> open-accepted
     
  • Maarten Brock
    Maarten Brock
    2008-07-30

    Logged In: YES
    user_id=888171
    Originator: NO

    In this case I think it is disputable whether the literal string is 5 or 6 bytes long. It is allowed to provide 5 chars for the full initialization. If the literal string would be longer the warning should appear though.

    Maarten

     
  • Borut Ražem
    Borut Ražem
    2008-07-30

    Logged In: YES
    user_id=568035
    Originator: NO

    It is strange that the warning is submitted only for pic targets. The behavior IMO should be the same for all targets. Or I'm wrong?

    Borut

     
  • Maarten Brock
    Maarten Brock
    2008-07-30

    Logged In: YES
    user_id=888171
    Originator: NO

    It is probably generated in glue() which is different for picxx and the others.

     
  • Borut Ražem
    Borut Ražem
    2008-09-07

    • status: open-accepted --> closed-accepted
     
  • Borut Ražem
    Borut Ražem
    2008-09-07

    Logged In: YES
    user_id=568035
    Originator: NO

    Fixed throw of "excess elements" warning for char arrays in svn revision #5231.

    Borut