[LLVMbugs] [Bug 11516] New: Wrong alignment for variable of a reference type (e.g. char &foo)
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Dec 8 19:21:22 PST 2011
http://llvm.org/bugs/show_bug.cgi?id=11516
Bug #: 11516
Summary: Wrong alignment for variable of a reference type (e.g.
char &foo)
Product: clang
Version: 3.0
Platform: PC
OS/Version: All
Status: NEW
Severity: normal
Priority: P
Component: C++
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: pickensd at synopsys.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
Look at the bitcode generated from the following function:
int eq(const char &c1, const char &c2) {
return c1 < c2;
}
You'll see that the dereference of c1 and c2 are incorrectly aligned to 4
instead of 1. This causes misaligned loads to be generated for some loop
transformations involving char pointers.
define i32 @_Z2eqRKcS0_(i8* %c1, i8* %c2) nounwind {
entry:
%c1.addr = alloca i8*, align 4
%c2.addr = alloca i8*, align 4
store i8* %c1, i8** %c1.addr, align 4
store i8* %c2, i8** %c2.addr, align 4
%0 = load i8** %c1.addr
%1 = load i8* %0, align 4 <-------------------WRONG!
%conv = zext i8 %1 to i32
%2 = load i8** %c2.addr
%3 = load i8* %2, align 4 <-------------------WRONG!
%conv1 = zext i8 %3 to i32
%cmp = icmp slt i32 %conv, %conv1
%conv2 = zext i1 %cmp to i32
ret i32 %conv2
}
Here is a proposed fix in module clang/lib/CodeGen/CGExpr.cpp, function
CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) :
Change this:
if (VD->getType()->isReferenceType())
V = Builder.CreateLoad(V);
To this:
if (VD->getType()->isReferenceType()) {
V = Builder.CreateLoad(V);
// Alignment is now that of referenced type!
QualType refee = VD->getType()->getPointeeType();
Alignment = getContext().getTypeAlignInChars(refee).getQuantity();
}
--
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