summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-01-08 19:02:23 +0000
committerChris Lattner <sabre@nondot.org>2010-01-08 19:02:23 +0000
commitb31189f26297fe30214da3e8d14a4575d5fdd262 (patch)
treec3b785a1cfdb4cc14fe11423eb881ea06614aa8f
parent54a57045ebcf8e31b1542098d1cd2bda9a718725 (diff)
downloadllvm-b31189f26297fe30214da3e8d14a4575d5fdd262.tar.gz
llvm-b31189f26297fe30214da3e8d14a4575d5fdd262.tar.bz2
llvm-b31189f26297fe30214da3e8d14a4575d5fdd262.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93018 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/ConstantFolding.cpp4
-rw-r--r--test/Transforms/ConstProp/loads.ll10
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index 194cabaf97..4ae8859a25 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/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/test/Transforms/ConstProp/loads.ll b/test/Transforms/ConstProp/loads.ll
index 9151d256b0..9fbba2b355 100644
--- a/test/Transforms/ConstProp/loads.ll
+++ b/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
+}