#529 ignores code sometimes

closed-fixed
nobody
5
2013-05-25
2003-06-10
Anonymous
No

I found that when an *internal* variable (idata or data)
is declared as "extern" and later declared, the compiler
sometimes ignores a line. Both variables were of
type "unsigned long" and were divided. If you need
more, I can send the entire source code.

function Something() {
extern data long Variable1, Variable2;

a=Variable1/Variable2;

.
more code
}

data long Variable1, Variable2; // I like to put global
variables by the functions that most need them.
function SomethingElse() {
// Expressions using variable1 and variable 2 do get
compiled here
}

When Variable1 and Variable2 were moved to xdata, the
lines compiled. The compiler never gave a warning; it
acted like the lines were comment lines and ignored
them when Variable1 and Variable2 were in internal
memory.

robertr@hildalecity.com

Discussion

  • Logged In: NO

    I made a mistake in this bug reporting. The code that gets
    ignored is when I *assign* to an extern data variable that
    hasn't yet been defined in the code. It isn't when it is in the
    expression.

    void Function() {
    extern data unsigned int Variable1;

    Variable1=expression involving dividing long values; // This
    is where it gets ignored (eliminated as dead code?)

    }

    // More code

    data unsigned int Variable1; // It is defined here in code
    (outside of a function, but after the code shown above)

    As long as the variable does not have forward declaration, it
    works. Forward declaration also works as long as the variable
    is xdata instead of data or idata.

    robertr@hildalecity.com

     
  • Maarten Brock
    Maarten Brock
    2004-03-09

    Logged In: YES
    user_id=888171

    Isn't this all about the scope of a variable? Is it legal C to
    declare an external variable inside a function definition with
    the actual definition of the variable outside of the function
    block like this?

    void foo(void)
    {
    extern data unsigned int Variable1;
    long x = 1000000;
    long y = 1000;

    Variable1 = x / y;
    }

    data unsigned int Variable1;

    I do consider it a bug though that SDCC doesn't even throw a
    warning on this one.

     
  • Maarten Brock
    Maarten Brock
    2004-05-06

    Logged In: YES
    user_id=888171

    Ok, so I looked it up and it's legal. Then I tried to find the
    bug and fix it. Somewhere in the iCode generation the extern
    keyword was forgotten and the variable was treated local
    afterwards. And that resulted in the code being optimized
    away. The fix is in the patches area.

    Greetings,
    Maarten

     
  • Erik Petrich
    Erik Petrich
    2004-05-14

    • milestone: --> fixed
    • status: open --> closed-fixed
     
  • Erik Petrich
    Erik Petrich
    2004-05-14

    Logged In: YES
    user_id=635249

    Fixed; see ChangeLog 1.720 for the updated files.
    Thanks to Maarten for solving this bug.