[LLVMbugs] [Bug 4739] New: GlobalAlias of ConstantExpr emits incorrect code
bugzilla-daemon at cs.uiuc.edu
bugzilla-daemon at cs.uiuc.edu
Tue Aug 18 13:09:18 PDT 2009
http://llvm.org/bugs/show_bug.cgi?id=4739
Summary: GlobalAlias of ConstantExpr emits incorrect code
Product: new-bugs
Version: unspecified
Platform: PC
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: new bugs
AssignedTo: unassignedbugs at nondot.org
ReportedBy: csdavec at swan.ac.uk
CC: llvmbugs at cs.uiuc.edu
A global alias may be defined as a GEP pointing to an element in the middle of
a structure, in which case the generated assembly is incorrect. Consider this
simple example:
%0 = type { i32, i32 }
@structure = internal global %0 { i32 0, i32 1 }
@element1 = alias getelementptr( %0* @structure, i32 0, i32 1)
@.str = private constant [12 x i8] c"Value: %d\0A\00"
declare i32 @printf(i8*, ...)
define i32 @main() {
entry:
%tmp1 = load i32* getelementptr( %0* @structure, i32 0, i32 1)
call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([12 x i8]* @.str,
i32 0, i32 0), i32 %tmp1); <i32> [#uses=0]
%tmp2 = load i32* @element1
call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([12 x i8]* @.str,
i32 0, i32 0), i32 %tmp2); <i32> [#uses=0]
ret i32 0
}
Running this prints:
Value: 1
Value: 0
This is because the @element1 alias is being resolved at to the global
referenced in the GEP, not to the result of the GEP. Looking at the generated
assembly, this is obvious:
.globl element1
.set element1, structure
This ought to be:
.globl element1
.set element1, structure+4
Making this change in the asm gives:
Value: 1
Value: 1
This is the correct output.
If there is some other way of emitting a symbol in the middle of an LLVM
structure so I can work around this bug, please let me know.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list