#1760 False unreachable code warning.

closed-rejected
3
2013-05-25
2011-02-19
No

For this small example sdcc gives unreachable code warnings:

unsigned char broken(void)
{
volatile unsigned char i = 1;
volatile signed int j = 0;
for(i=1; i<=j; i++)
return(1);
return(0);
}

There is no unreachable code here: We either execute return(0) or return(1), depending on the value of j, which could be anything.

Philipp

Discussion

  • Patryk

    Patryk - 2011-02-19

    j is initialized to 0 and not accessible outside broken(), not fixed address, no address passed outside, so despite 'volatile' modifier it's value can't change, and IMHO compiler can treat it as a constant and signal that return(1) won't be executed.

     
  • Philipp Klaus Krause

    Same problem for global j:

    volatile signed int j;

    unsigned char broken2(void)
    {
    volatile unsigned char i = 1;
    j = 0;
    for(i=1; i<=j; i++)
    return(1);
    return(0);
    }

     
  • Maarten Brock

    Maarten Brock - 2011-09-16

    But there is! It is the i++ that the compiler is warning about. Look at the line number in the warning. This is better visible if you split the for statement over several lines:

    for (
    i=1;
    i<=j;
    i++) // warning is for this line
    return(1);

     
  • Maarten Brock

    Maarten Brock - 2011-09-16
    • labels: --> Icode generator
    • milestone: --> non_bugs
    • assigned_to: nobody --> maartenbrock
    • status: open --> closed-rejected
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks