[Bug c/45099] New: Warning could be issued for use of register variables that will fail.

jrseattle2002 at hotmail dot com gcc-bugzilla@gcc.gnu.org
Wed Jul 28 06:07:00 GMT 2010


WinAVR needs register r10 (among others) for certain mathematical operations of
the "long long" data type, e.g. when calling "__muldi3".
The user may declare r10 to be assigned to a register variable.
When this combination occurs, code will not execute correctly.
This is specifically an issue when the register variable is NOT used in ISR
functions and the user expects r10 to be "call saved". WinAVR normally saves
these "call saved" registers in the function that uses them, but DOES NO DO
THAT IF THE REGISTER IS USED AS A REGISTER VARIABLE, even though it needs to
use that register. Such situations can be recognized and a warning issued. Even
better, the register could be saved in the first place using the rule "call
saved" registers need to be saved by the called function if used, even if the
register is used as a register variable.
Sample code:
register unsigned char GYOffset asm("r10"); 

typedef unsigned char byte;
typedef unsigned int uint;

void ComputeLargeNum(uint nDays, char *pStr)
{
        unsigned long long LargeNum = 13248524997010ULL + nDays * 4173424303;
        uint n = 0;
        while (LargeNum > 1000000000ULL) {
                ++n;
                LargeNum -= 1000000000ULL;
        }
}

void print(char *pStr)
{
}

int main(void)
{
        char buf[20];
        GYOffset = 1;
        ComputeLargeNum(10, buf);
        if (GYOffset != 1) {
                print("r10 corrupted\n");
        }
}


-- 
           Summary: Warning could be issued for use of register variables
                    that will fail.
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jrseattle2002 at hotmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45099



More information about the Gcc-bugs mailing list