public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jrseattle2002 at hotmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/45099]  New: Warning could be issued for use of register variables that will fail.
Date: Wed, 28 Jul 2010 06:07:00 -0000	[thread overview]
Message-ID: <bug-45099-19491@http.gcc.gnu.org/bugzilla/> (raw)

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


                 reply	other threads:[~2010-07-28  6:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-45099-19491@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).