diff options
author | Chris Lattner <sabre@nondot.org> | 2010-01-08 19:02:23 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-01-08 19:02:23 +0000 |
commit | a69f89c17a85d504d31a187111e5f0a0677c1921 (patch) | |
tree | 268c32254e475fcd3cc93dd8ac7c3bfa81c1425f /llvm | |
parent | b92304b42f7f7b9b294d9e7dd7ab96002dff5b97 (diff) | |
download | bcm5719-llvm-a69f89c17a85d504d31a187111e5f0a0677c1921.tar.gz bcm5719-llvm-a69f89c17a85d504d31a187111e5f0a0677c1921.zip |
fix PR5978 by peeling the loop so that we avoid shifting the
result int by 8 for the first byte. While normally harmless,
if the result is smaller than a byte, this shift is invalid.
llvm-svn: 93018
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 4 | ||||
-rw-r--r-- | llvm/test/Transforms/ConstProp/loads.ll | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 194cabaf978..4ae8859a257 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -398,8 +398,8 @@ static Constant *FoldReinterpretLoadFromConstPtr(Constant *C, BytesLoaded, TD)) return 0; - APInt ResultVal(IntType->getBitWidth(), 0); - for (unsigned i = 0; i != BytesLoaded; ++i) { + APInt ResultVal = APInt(IntType->getBitWidth(), RawBytes[BytesLoaded-1]); + for (unsigned i = 1; i != BytesLoaded; ++i) { ResultVal <<= 8; ResultVal |= APInt(IntType->getBitWidth(), RawBytes[BytesLoaded-1-i]); } diff --git a/llvm/test/Transforms/ConstProp/loads.ll b/llvm/test/Transforms/ConstProp/loads.ll index 9151d256b02..9fbba2b3552 100644 --- a/llvm/test/Transforms/ConstProp/loads.ll +++ b/llvm/test/Transforms/ConstProp/loads.ll @@ -110,3 +110,13 @@ define i16 @test12() { ; CHECK: @test12 ; CHECK: ret i16 98 } + + +; PR5978 +@g5 = constant i8 4 +define i1 @test13() { + %A = load i1* bitcast (i8* @g5 to i1*) + ret i1 %A +; CHECK: @test13 +; CHECK: ret i1 false +} |