Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in folding load of static initializer data #1394

Closed
sunfishcode opened this issue Nov 28, 2006 · 1 comment
Closed

bug in folding load of static initializer data #1394

sunfishcode opened this issue Nov 28, 2006 · 1 comment
Labels
bugzilla Issues migrated from bugzilla llvm:codegen miscompilation

Comments

@sunfishcode
Copy link
Member

Bugzilla Link 1022
Resolution FIXED
Resolved on Feb 22, 2010 12:50
Version trunk
OS Linux

Extended Description

There's a bug in folding loads of static initializers. If there are bytes with
the high bit set, adjacent bytes are getting set to all ones when the compiler
is running on a host with signed char. Here's a patch that fixes it:

Index: SelectionDAGISel.cpp

RCS file: /var/cvs/llvm/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp,v
retrieving revision 1.319
diff -u -r1.319 SelectionDAGISel.cpp
--- SelectionDAGISel.cpp
+++ SelectionDAGISel.cpp
@@ -3179,7 +3179,7 @@
if (TLI.isLittleEndian())
Offset = Offset + MSB - 1;
for (unsigned i = 0; i != MSB; ++i) {

  • Val = (Val << 8) | Str[Offset];
  • Val = (Val << 8) | (unsigned char) Str[Offset];
    Offset += TLI.isLittleEndian() ? -1 : 1;
    }
    return DAG.getConstant(Val, VT);

And here's a testcase that reproduces the problem.

target datalayout = "e-p:32:32"
target endian = little
target pointersize = 32
target triple = "i686-pc-linux-gnu"
%fmt = constant [4 x sbyte] c"%x\0A\00"
%bytes = constant [4 x sbyte] c"\AA\BB\CC\DD"

implementation

int %main() {
%y = alloca uint
%c = cast uint* %y to sbyte*
%z = getelementptr [4 x sbyte]* %bytes, int 0, int 0
call void %llvm.memcpy.i32( sbyte* %c, sbyte* %z, uint 4, uint 1 )
%r = load uint* %y
%t = cast [4 x sbyte]* %fmt to sbyte*
%tmp = call int (sbyte*, ...)* %printf( sbyte* %t, uint %r )
ret int 0
}

declare void %llvm.memcpy.i32(sbyte*, sbyte*, uint, uint)

declare int %printf(sbyte*, ...)

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 29, 2006

Patch applied. Thanks!

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla llvm:codegen miscompilation
Projects
None yet
Development

No branches or pull requests

2 participants