Reapply r215966, r215965, r215964, r215963, r215960, r215959, r215958, and r215957

This reverts commit r215981, which reverted the above commits because
MSVC std::equal asserts on nullptr iterators, and thes commits
introduced an `ArrayRef::equals()` on empty ArrayRefs.

ArrayRef was changed not to use std::equal in r215986.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215987 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2014-08-19 16:39:58 +00:00
parent 8c20a93bac
commit 7116af637c
8 changed files with 433 additions and 497 deletions

View File

@@ -274,5 +274,30 @@ TEST(ConstantsTest, ReplaceWithConstantTest) {
#undef CHECK
TEST(ConstantsTest, ConstantArrayReplaceWithConstant) {
LLVMContext Context;
std::unique_ptr<Module> M(new Module("MyModule", Context));
Type *IntTy = Type::getInt8Ty(Context);
ArrayType *ArrayTy = ArrayType::get(IntTy, 2);
Constant *A01Vals[2] = {ConstantInt::get(IntTy, 0),
ConstantInt::get(IntTy, 1)};
Constant *A01 = ConstantArray::get(ArrayTy, A01Vals);
Constant *Global = new GlobalVariable(*M, IntTy, false,
GlobalValue::ExternalLinkage, nullptr);
Constant *GlobalInt = ConstantExpr::getPtrToInt(Global, IntTy);
Constant *A0GVals[2] = {ConstantInt::get(IntTy, 0), GlobalInt};
Constant *A0G = ConstantArray::get(ArrayTy, A0GVals);
ASSERT_NE(A01, A0G);
GlobalVariable *RefArray =
new GlobalVariable(*M, ArrayTy, false, GlobalValue::ExternalLinkage, A0G);
ASSERT_EQ(A0G, RefArray->getInitializer());
GlobalInt->replaceAllUsesWith(ConstantInt::get(IntTy, 1));
ASSERT_EQ(A01, RefArray->getInitializer());
}
} // end anonymous namespace
} // end namespace llvm