[LLVMbugs] [Bug 602] NEW: [llvm-g++] Bad getelementptr instruction when accessing virtual base class

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Thu Jul 21 14:13:58 PDT 2005


http://llvm.cs.uiuc.edu/bugs/show_bug.cgi?id=602

           Summary: [llvm-g++] Bad getelementptr instruction when accessing
                    virtual base class
           Product: tools
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: llvm-g++
        AssignedTo: sabre at nondot.org
        ReportedBy: sabre at nondot.org


In this C++ testcase:

---
void foo(int*);
struct FOO { int X; };
struct BAR : virtual FOO {};
int testfn() {
  BAR B;
  foo(&B.X);
}
---

The C++ FE expands 'testfn' to this:

int %_Z6testfnv() {
entry:
        %B = alloca %struct.BAR         ; <%struct.BAR*> [#uses=2]
        call void %_ZN3BARC1Ev( %struct.BAR* %B )
        %tmp.0 = cast %struct.BAR* %B to %struct.FOO*           ; <%struct.FOO*> [#uses=1]
***   %tmp.1 = getelementptr %struct.FOO* %tmp.0, int 1               ; <%struct.FOO*> [#uses=1]
        %tmp.2 = getelementptr %struct.FOO* %tmp.1, int 0, uint 0               ; <int*> [#uses=1]
        call void %_Z3fooPi( int* %tmp.2 )
        ret int undef
}

The marked GEP instruction is illegal: it produces the right offset, but will confuse the optimizer.  It is 
doing pointer arithmetic that is effectively equivalent to this (which is also illegal):

struct X { int A, B; };

int *foo(X *x) { return &x.A+1; }  // Illegal way to get &x.B

-Chris



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.




More information about the llvm-bugs mailing list