[LLVMbugs] [Bug 1148] NEW: Code quality issue with multiple inheritance
bugzilla-daemon at cs.uiuc.edu
bugzilla-daemon at cs.uiuc.edu
Tue Jan 30 21:02:18 PST 2007
http://llvm.org/bugs/show_bug.cgi?id=1148
Summary: Code quality issue with multiple inheritance
Product: tools
Version: 1.0
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: llvm-g++
AssignedTo: unassignedbugs at nondot.org
ReportedBy: sabre at nondot.org
Consider:
struct base { virtual ~base(); int X; };
struct A {
virtual ~A();
int B;
};
struct Derived : public A, public base {
int field;
};
int foo(base *B) {
return static_cast<Derived*>(B)->field;
}
The static_cast in foo is actually compiled to the equivalent of "B ? B-8 : 0", producing this llvm code:
define i32 @_Z3fooP4base(%struct.A* %B) {
entry:
%tmp = icmp eq %struct.A* %B, null ; <i1> [#uses=1]
br i1 %tmp, label %cond_next, label %cond_true
cond_true: ; preds = %entry
%B = bitcast %struct.A* %B to i8* ; <i8*> [#uses=1]
%ctg2 = getelementptr i8* %B, i32 -8 ; <i8*> [#uses=1]
%tmp = bitcast i8* %ctg2 to %struct.Derived* ; <%struct.Derived*> [#uses=1]
%tmp36 = getelementptr %struct.Derived* %tmp, i32 0, i32 2 ; <i32*> [#uses=1]
%tmp47 = load i32* %tmp36 ; <i32> [#uses=1]
ret i32 %tmp47
cond_next: ; preds = %entry
%tmp4 = load i32* inttoptr (i32 16 to i32*) ; <i32> [#uses=1]
ret i32 %tmp4
}
However, because the pointer is loaded, we know that B could not have been a null pointer. It's unclear
how to handle this in LLVM, loading from a constant address is legal. This has to be handled on the
tree level somehow.
-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