From 357ece440765ea99109f6db56dfdfee5d0dd5843 Mon Sep 17 00:00:00 2001 From: Filipe Cabecinhas Date: Mon, 31 Aug 2015 18:00:30 +0000 Subject: [PATCH] [BitcodeReader] Ensure we can read constant vector selects with an i1 condition Summary: Constant vectors weren't allowed to have an i1 condition in the BitcodeReader. Make sure we have the same restrictions that are documented, not more. Reviewers: nlewycky, rafael, kschimpf Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D12440 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246459 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Reader/BitcodeReader.cpp | 9 +++++---- test/Bitcode/select.ll | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index c767b6c5c17..b9604af3bc8 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2475,11 +2475,12 @@ std::error_code BitcodeReader::parseConstants() { Type *SelectorTy = Type::getInt1Ty(Context); - // If CurTy is a vector of length n, then Record[0] must be a - // vector. Otherwise, it must be a single bit. + // The selector might be an i1 or an + // Get the type from the ValueList before getting a forward ref. if (VectorType *VTy = dyn_cast(CurTy)) - SelectorTy = VectorType::get(Type::getInt1Ty(Context), - VTy->getNumElements()); + if (Value *V = ValueList[Record[0]]) + if (SelectorTy != V->getType()) + SelectorTy = VectorType::get(SelectorTy, VTy->getNumElements()); V = ConstantExpr::getSelect(ValueList.getConstantFwdRef(Record[0], SelectorTy), diff --git a/test/Bitcode/select.ll b/test/Bitcode/select.ll index 3ad06796dcc..666d2960fb5 100644 --- a/test/Bitcode/select.ll +++ b/test/Bitcode/select.ll @@ -8,3 +8,11 @@ define <2 x i32> @main() { ; CHECK: define <2 x i32> @main() { ; CHECK: ret <2 x i32> ; CHECK: } + +define <2 x float> @f() { + ret <2 x float> select (i1 ptrtoint (<2 x float> ()* @f to i1), <2 x float> , <2 x float> zeroinitializer) +} + +; CHECK: define <2 x float> @f() { +; CHECK: ret <2 x float> select (i1 ptrtoint (<2 x float> ()* @f to i1), <2 x float> , <2 x float> zeroinitializer) +; CHECK: } -- 2.34.1