This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

BUG: erroneous read access to volatile mem ref


As mentioned earlier this week in gcc@gcc.gnu.org and gnuh8
mailing lists, there is a bug in code generation for a
very special case involving volatile mem refs and inline.

Consider the following real-life example:

////// start source

/* TCW is a fixed-address register that must be set
   to "0" from time to time; otherwise a watchog reset
   would be generated. A read access to this register
   leads to unpredictable results ("write-only")       */

extern volatile unsigned char TCW;

inline void Watchdog(void)
{
  TCW = 0;
}

void test1(void)
{
  TCW = 0;     /* this leads to correct code */
}

void test2(void)
{
  Watchdog();  /* ... but not this one!      */
}
////// end source


The code generated for h8300 is:

(...)

_test1__Fv:
  ; TCW = 0;
 sub.b r2l,r2l
 mov.b r2l,@_TCW  ; << correct!
 rts

(...)

_test2__Fv:
  ; Watchdog();
 sub.b r2l,r2l
 mov.b r2l,@_TCW  ; << correct!
 mov.b @_TCW,r3l  ; << erroreous read!
 rts

You would assume the outcome of both test cases to be identical.
Although in most cases this unneccessary read is not critical
(and therefore apparently has escaped everybody's attention), in
rare cases (as the one above) this is fatal.

This bug is only present in cc1plus.exe, but not in cc1.exe.

After all I could ascertain, this bug is not target dependent.
At least for i586-cygwin I could reproduce it.

A quick investigation on earlier versions turned out that
this issue has been present in egcs-20000103 snapshot already,
but not in versions before december 99. As I read somewhere,
a new inliner has been introduced around december; maybe this
new module is to blame?

Regards,
Ralf

           .....
           ô ô )
-----oOOo--(_)---oOOo------

Ralf Guetlein
Biotest Medizintechnik GmbH
Industriestrasse 19
D-63755 Alzenau
Germany
---------------------------
Tel. +49 6023 9487-42
Fax. +49 6023 9487-33
ralf.guetlein@biotest-mt.de
---------------------------




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]