[Bug c++/30976] New: generating non-conforming "rep retn" with -match=athlon, k8 ; with -masm=intel fails

zsojka at seznam dot cz gcc-bugzilla@gcc.gnu.org
Tue Feb 27 00:19:00 GMT 2007


gcc versions tested (all have this problem on both architectures):
x86_64
3.4.6 4.1.1 4.1.2

i686
3.4.6 4.1.1

Reduced testcase: main.cpp
---------------
struct o {
  virtual void a() { }
};

int main(int,char**) {
  new o();
  return 0;
}
----------------
When a() is removed or set as non-virtual, problem disappears

Commandline to fail compilation:
i686:
g++ main.cpp -o main -O -fomit-frame-pointer -march=athlon -masm=intel

x86_64:
g++ main.cpp -o main -O -masm=intel

-march of athlon, athlon-4, k8 fails
without -masm the code is compiled, but its behavior is undefined (although
working)

---------------

In assembler output, the following line appears with AT&T syntax:
        rep ; ret
and is accepted. (two independendend instructions, although meaningless)
With Intel syntax, generated code:
        rep  ret
is not accepted. (meaningless prefix)

---------------
According to Intel IA-32 documentation:
"The behavior of the REP prefix is undefined when used with non-string
instructions."
AMD AMD64 documentation:
"The (rep/repe) prefixes should only be used with such (lods,stos,movs,...)
string instructions."

---------------

I could post exact error messages and outputs of gcc -v on all tested systems
if needed (I have already done so, but the output is very long to past here)

------------

Conlusion:
Generates code non-conforming to Intel and AMD documentation. Unlikely, code
would not work on future processors. With AT&T syntax, asm code is accepted.
With Intel syntax, it is rejected.
The pair 'rep ; retn' should never appear as it is undefined when executed by
CPU. (and it most likely gets generated nonintentionally)


-- 
           Summary: generating non-conforming "rep retn" with -match=athlon,
                    k8 ; with -masm=intel fails
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: zsojka at seznam dot cz
 GCC build triplet: x86_64-pc-linux-gnu i686-pc-linux-gnu


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



More information about the Gcc-bugs mailing list