diff options
Diffstat (limited to 'unittests')
115 files changed, 673 insertions, 251 deletions
diff --git a/unittests/ADT/DAGDeltaAlgorithmTest.cpp b/unittests/ADT/DAGDeltaAlgorithmTest.cpp index 190df7f57470..030fadbc9a38 100644 --- a/unittests/ADT/DAGDeltaAlgorithmTest.cpp +++ b/unittests/ADT/DAGDeltaAlgorithmTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/DAGDeltaAlgorithm.h" +#include "gtest/gtest.h" #include <algorithm> #include <cstdarg> using namespace llvm; diff --git a/unittests/ADT/DeltaAlgorithmTest.cpp b/unittests/ADT/DeltaAlgorithmTest.cpp index bed57b1a1725..01dc1f36bd2f 100644 --- a/unittests/ADT/DeltaAlgorithmTest.cpp +++ b/unittests/ADT/DeltaAlgorithmTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/DeltaAlgorithm.h" +#include "gtest/gtest.h" #include <algorithm> #include <cstdarg> using namespace llvm; diff --git a/unittests/ADT/DenseMapTest.cpp b/unittests/ADT/DenseMapTest.cpp index 273f4da021c4..cb5ba6875eaa 100644 --- a/unittests/ADT/DenseMapTest.cpp +++ b/unittests/ADT/DenseMapTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/DenseMap.h" +#include "gtest/gtest.h" #include <map> #include <set> diff --git a/unittests/ADT/DepthFirstIteratorTest.cpp b/unittests/ADT/DepthFirstIteratorTest.cpp index 463d6928bd5c..4169cd48fcbd 100644 --- a/unittests/ADT/DepthFirstIteratorTest.cpp +++ b/unittests/ADT/DepthFirstIteratorTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "TestGraph.h" #include "llvm/ADT/DepthFirstIterator.h" +#include "TestGraph.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/ADT/FoldingSet.cpp b/unittests/ADT/FoldingSet.cpp index 696463881195..f5b1b71beb63 100644 --- a/unittests/ADT/FoldingSet.cpp +++ b/unittests/ADT/FoldingSet.cpp @@ -11,8 +11,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/FoldingSet.h" +#include "gtest/gtest.h" #include <string> using namespace llvm; diff --git a/unittests/ADT/HashingTest.cpp b/unittests/ADT/HashingTest.cpp index b28561bd0115..367f58dc7a6a 100644 --- a/unittests/ADT/HashingTest.cpp +++ b/unittests/ADT/HashingTest.cpp @@ -11,9 +11,9 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/Hashing.h" #include "llvm/Support/DataTypes.h" +#include "gtest/gtest.h" #include <deque> #include <list> #include <map> diff --git a/unittests/ADT/ImmutableMapTest.cpp b/unittests/ADT/ImmutableMapTest.cpp index 6a99884bfbb3..23ca168a7f7c 100644 --- a/unittests/ADT/ImmutableMapTest.cpp +++ b/unittests/ADT/ImmutableMapTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/ImmutableMap.h" +#include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/ADT/ImmutableSetTest.cpp b/unittests/ADT/ImmutableSetTest.cpp index a6eb405db720..35ac2c19b2f5 100644 --- a/unittests/ADT/ImmutableSetTest.cpp +++ b/unittests/ADT/ImmutableSetTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/ImmutableSet.h" +#include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/ADT/IteratorTest.cpp b/unittests/ADT/IteratorTest.cpp index 7f261824b499..c95ce8061847 100644 --- a/unittests/ADT/IteratorTest.cpp +++ b/unittests/ADT/IteratorTest.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/iterator.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/iterator.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/ADT/MapVectorTest.cpp b/unittests/ADT/MapVectorTest.cpp index f5b094fb627b..bd6602b030f6 100644 --- a/unittests/ADT/MapVectorTest.cpp +++ b/unittests/ADT/MapVectorTest.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/MapVector.h" #include "llvm/ADT/iterator_range.h" +#include "gtest/gtest.h" #include <utility> using namespace llvm; diff --git a/unittests/ADT/OptionalTest.cpp b/unittests/ADT/OptionalTest.cpp index 4c0c99393d21..46d4fe0780c3 100644 --- a/unittests/ADT/OptionalTest.cpp +++ b/unittests/ADT/OptionalTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/Optional.h" +#include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/ADT/PointerEmbeddedIntTest.cpp b/unittests/ADT/PointerEmbeddedIntTest.cpp index 9c27f8ee655f..695ea12e0b03 100644 --- a/unittests/ADT/PointerEmbeddedIntTest.cpp +++ b/unittests/ADT/PointerEmbeddedIntTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/PointerEmbeddedInt.h" +#include "gtest/gtest.h" using namespace llvm; namespace { diff --git a/unittests/ADT/PointerIntPairTest.cpp b/unittests/ADT/PointerIntPairTest.cpp index 13680c78b9bb..985fdba0247f 100644 --- a/unittests/ADT/PointerIntPairTest.cpp +++ b/unittests/ADT/PointerIntPairTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/PointerIntPair.h" +#include "gtest/gtest.h" #include <limits> using namespace llvm; diff --git a/unittests/ADT/PointerSumTypeTest.cpp b/unittests/ADT/PointerSumTypeTest.cpp index 75c88f7fee9f..a4faea624f1c 100644 --- a/unittests/ADT/PointerSumTypeTest.cpp +++ b/unittests/ADT/PointerSumTypeTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/PointerSumType.h" +#include "gtest/gtest.h" using namespace llvm; namespace { diff --git a/unittests/ADT/PointerUnionTest.cpp b/unittests/ADT/PointerUnionTest.cpp index a592784ae095..360c3714841b 100644 --- a/unittests/ADT/PointerUnionTest.cpp +++ b/unittests/ADT/PointerUnionTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/PointerUnion.h" +#include "gtest/gtest.h" using namespace llvm; namespace { diff --git a/unittests/ADT/PostOrderIteratorTest.cpp b/unittests/ADT/PostOrderIteratorTest.cpp index 17b8c4d842d3..20c938e89326 100644 --- a/unittests/ADT/PostOrderIteratorTest.cpp +++ b/unittests/ADT/PostOrderIteratorTest.cpp @@ -6,10 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/PostOrderIterator.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CFG.h" +#include "gtest/gtest.h" using namespace llvm; namespace { diff --git a/unittests/ADT/RangeAdapterTest.cpp b/unittests/ADT/RangeAdapterTest.cpp index 4c7bef53235b..edc1ced72ba9 100644 --- a/unittests/ADT/RangeAdapterTest.cpp +++ b/unittests/ADT/RangeAdapterTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/iterator_range.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/iterator_range.h" #include "gtest/gtest.h" #include <iterator> diff --git a/unittests/ADT/ReverseIterationTest.cpp b/unittests/ADT/ReverseIterationTest.cpp index a1fd3b26d4e3..1e2dedf083f7 100644 --- a/unittests/ADT/ReverseIterationTest.cpp +++ b/unittests/ADT/ReverseIterationTest.cpp @@ -11,8 +11,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/SmallPtrSet.h" +#include "gtest/gtest.h" #if LLVM_ENABLE_ABI_BREAKING_CHECKS using namespace llvm; diff --git a/unittests/ADT/SCCIteratorTest.cpp b/unittests/ADT/SCCIteratorTest.cpp index f596ea6d6b88..ca6d84ed2f32 100644 --- a/unittests/ADT/SCCIteratorTest.cpp +++ b/unittests/ADT/SCCIteratorTest.cpp @@ -8,8 +8,8 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/SCCIterator.h" -#include "gtest/gtest.h" #include "TestGraph.h" +#include "gtest/gtest.h" #include <limits.h> using namespace llvm; diff --git a/unittests/ADT/SmallPtrSetTest.cpp b/unittests/ADT/SmallPtrSetTest.cpp index fc14c684d67f..0070d1cbae1b 100644 --- a/unittests/ADT/SmallPtrSetTest.cpp +++ b/unittests/ADT/SmallPtrSetTest.cpp @@ -11,10 +11,10 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" -#include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/PointerIntPair.h" #include "llvm/Support/PointerLikeTypeTraits.h" +#include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/ADT/SmallVectorTest.cpp b/unittests/ADT/SmallVectorTest.cpp index ca6391024f27..5903ce8c08eb 100644 --- a/unittests/ADT/SmallVectorTest.cpp +++ b/unittests/ADT/SmallVectorTest.cpp @@ -11,8 +11,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/Support/Compiler.h" #include "gtest/gtest.h" #include <list> @@ -209,6 +209,22 @@ typedef ::testing::Types<SmallVector<Constructable, 0>, > SmallVectorTestTypes; TYPED_TEST_CASE(SmallVectorTest, SmallVectorTestTypes); +// Constructor test. +TYPED_TEST(SmallVectorTest, ConstructorNonIterTest) { + SCOPED_TRACE("ConstructorTest"); + this->theVector = SmallVector<Constructable, 2>(2, 2); + this->assertValuesInOrder(this->theVector, 2u, 2, 2); +} + +// Constructor test. +TYPED_TEST(SmallVectorTest, ConstructorIterTest) { + SCOPED_TRACE("ConstructorTest"); + int arr[] = {1, 2, 3}; + this->theVector = + SmallVector<Constructable, 4>(std::begin(arr), std::end(arr)); + this->assertValuesInOrder(this->theVector, 3u, 1, 2, 3); +} + // New vector test. TYPED_TEST(SmallVectorTest, EmptyVectorTest) { SCOPED_TRACE("EmptyVectorTest"); @@ -415,6 +431,33 @@ TYPED_TEST(SmallVectorTest, AppendRepeatedTest) { this->assertValuesInOrder(this->theVector, 3u, 1, 77, 77); } +// Append test +TYPED_TEST(SmallVectorTest, AppendNonIterTest) { + SCOPED_TRACE("AppendRepeatedTest"); + + this->theVector.push_back(Constructable(1)); + this->theVector.append(2, 7); + this->assertValuesInOrder(this->theVector, 3u, 1, 7, 7); +} + +TYPED_TEST(SmallVectorTest, AppendRepeatedNonForwardIterator) { + SCOPED_TRACE("AppendRepeatedTest"); + + struct output_iterator { + typedef std::output_iterator_tag iterator_category; + typedef int value_type; + typedef int difference_type; + typedef value_type *pointer; + typedef value_type &reference; + operator int() { return 2; } + operator Constructable() { return 7; } + }; + + this->theVector.push_back(Constructable(1)); + this->theVector.append(output_iterator(), output_iterator()); + this->assertValuesInOrder(this->theVector, 3u, 1, 7, 7); +} + // Assign test TYPED_TEST(SmallVectorTest, AssignTest) { SCOPED_TRACE("AssignTest"); @@ -434,6 +477,15 @@ TYPED_TEST(SmallVectorTest, AssignRangeTest) { this->assertValuesInOrder(this->theVector, 3u, 1, 2, 3); } +// Assign test +TYPED_TEST(SmallVectorTest, AssignNonIterTest) { + SCOPED_TRACE("AssignTest"); + + this->theVector.push_back(Constructable(1)); + this->theVector.assign(2, 7); + this->assertValuesInOrder(this->theVector, 2u, 7, 7); +} + // Move-assign test TYPED_TEST(SmallVectorTest, MoveAssignTest) { SCOPED_TRACE("MoveAssignTest"); @@ -532,6 +584,15 @@ TYPED_TEST(SmallVectorTest, InsertRepeatedTest) { this->assertValuesInOrder(this->theVector, 6u, 1, 16, 16, 2, 3, 4); } +TYPED_TEST(SmallVectorTest, InsertRepeatedNonIterTest) { + SCOPED_TRACE("InsertRepeatedTest"); + + this->makeSequence(this->theVector, 1, 4); + Constructable::reset(); + auto I = this->theVector.insert(this->theVector.begin() + 1, 2, 7); + EXPECT_EQ(this->theVector.begin() + 1, I); + this->assertValuesInOrder(this->theVector, 6u, 1, 7, 7, 2, 3, 4); +} TYPED_TEST(SmallVectorTest, InsertRepeatedAtEndTest) { SCOPED_TRACE("InsertRepeatedTest"); diff --git a/unittests/ADT/TripleTest.cpp b/unittests/ADT/TripleTest.cpp index 6d25526e5ad1..af4592ba0957 100644 --- a/unittests/ADT/TripleTest.cpp +++ b/unittests/ADT/TripleTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/Triple.h" +#include "gtest/gtest.h" using namespace llvm; @@ -1090,11 +1090,16 @@ TEST(TripleTest, NormalizeARM) { EXPECT_EQ("armv6eb--netbsd-eabihf", Triple::normalize("armv6eb-netbsd-eabihf")); EXPECT_EQ("armv7eb--netbsd-eabihf", Triple::normalize("armv7eb-netbsd-eabihf")); + EXPECT_EQ("armv7-suse-linux-gnueabihf", + Triple::normalize("armv7-suse-linux-gnueabi")); + Triple T; T = Triple("armv6--netbsd-eabi"); EXPECT_EQ(Triple::arm, T.getArch()); T = Triple("armv6eb--netbsd-eabi"); EXPECT_EQ(Triple::armeb, T.getArch()); + T = Triple("armv7-suse-linux-gnueabihf"); + EXPECT_EQ(Triple::GNUEABIHF, T.getEnvironment()); } TEST(TripleTest, ParseARMArch) { diff --git a/unittests/ADT/TwineTest.cpp b/unittests/ADT/TwineTest.cpp index 0b7e88dee500..950eda2b058a 100644 --- a/unittests/ADT/TwineTest.cpp +++ b/unittests/ADT/TwineTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/SmallString.h" #include "llvm/ADT/Twine.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Support/FormatAdapters.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/raw_ostream.h" diff --git a/unittests/ADT/VariadicFunctionTest.cpp b/unittests/ADT/VariadicFunctionTest.cpp index cde31205966c..43db64836cc1 100644 --- a/unittests/ADT/VariadicFunctionTest.cpp +++ b/unittests/ADT/VariadicFunctionTest.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" -#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/VariadicFunction.h" +#include "llvm/ADT/ArrayRef.h" +#include "gtest/gtest.h" using namespace llvm; namespace { diff --git a/unittests/Analysis/BranchProbabilityInfoTest.cpp b/unittests/Analysis/BranchProbabilityInfoTest.cpp index cbf8b50c7623..529af5c068da 100644 --- a/unittests/Analysis/BranchProbabilityInfoTest.cpp +++ b/unittests/Analysis/BranchProbabilityInfoTest.cpp @@ -13,8 +13,8 @@ #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Dominators.h" -#include "llvm/IR/Instructions.h" #include "llvm/IR/Function.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/Support/DataTypes.h" diff --git a/unittests/Analysis/CFGTest.cpp b/unittests/Analysis/CFGTest.cpp index c60044fa52df..d7f14c3e1c35 100644 --- a/unittests/Analysis/CFGTest.cpp +++ b/unittests/Analysis/CFGTest.cpp @@ -14,9 +14,9 @@ #include "llvm/IR/Function.h" #include "llvm/IR/InstIterator.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Module.h" #include "llvm/Pass.h" -#include "llvm/IR/LegacyPassManager.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/SourceMgr.h" #include "gtest/gtest.h" diff --git a/unittests/Analysis/CMakeLists.txt b/unittests/Analysis/CMakeLists.txt index 8082c54b9c66..ac8bca25d93a 100644 --- a/unittests/Analysis/CMakeLists.txt +++ b/unittests/Analysis/CMakeLists.txt @@ -12,6 +12,7 @@ add_llvm_unittest(AnalysisTests CallGraphTest.cpp CFGTest.cpp CGSCCPassManagerTest.cpp + GlobalsModRefTest.cpp LazyCallGraphTest.cpp LoopInfoTest.cpp MemoryBuiltinsTest.cpp diff --git a/unittests/Analysis/GlobalsModRefTest.cpp b/unittests/Analysis/GlobalsModRefTest.cpp new file mode 100644 index 000000000000..323edc2cc175 --- /dev/null +++ b/unittests/Analysis/GlobalsModRefTest.cpp @@ -0,0 +1,55 @@ +//===--- GlobalsModRefTest.cpp - Mixed TBAA unit tests --------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Analysis/GlobalsModRef.h" +#include "llvm/AsmParser/Parser.h" +#include "llvm/Support/SourceMgr.h" +#include "gtest/gtest.h" + +using namespace llvm; + +TEST(GlobalsModRef, OptNone) { + StringRef Assembly = R"( + define void @f1() optnone { + ret void + } + define void @f2() optnone readnone { + ret void + } + define void @f3() optnone readonly { + ret void + } + )"; + + LLVMContext Context; + SMDiagnostic Error; + auto M = parseAssemblyString(Assembly, Error, Context); + ASSERT_TRUE(M) << "Bad assembly?"; + + const auto &funcs = M->functions(); + auto I = funcs.begin(); + ASSERT_NE(I, funcs.end()); + const Function &F1 = *I; + ASSERT_NE(++I, funcs.end()); + const Function &F2 = *I; + ASSERT_NE(++I, funcs.end()); + const Function &F3 = *I; + EXPECT_EQ(++I, funcs.end()); + + Triple Trip(M->getTargetTriple()); + TargetLibraryInfoImpl TLII(Trip); + TargetLibraryInfo TLI(TLII); + llvm::CallGraph CG(*M); + + auto AAR = GlobalsAAResult::analyzeModule(*M, TLI, CG); + + EXPECT_EQ(FMRB_UnknownModRefBehavior, AAR.getModRefBehavior(&F1)); + EXPECT_EQ(FMRB_DoesNotAccessMemory, AAR.getModRefBehavior(&F2)); + EXPECT_EQ(FMRB_OnlyReadsMemory, AAR.getModRefBehavior(&F3)); +} diff --git a/unittests/Analysis/LazyCallGraphTest.cpp b/unittests/Analysis/LazyCallGraphTest.cpp index 6955beb37109..8c251cf043b8 100644 --- a/unittests/Analysis/LazyCallGraphTest.cpp +++ b/unittests/Analysis/LazyCallGraphTest.cpp @@ -9,8 +9,8 @@ #include "llvm/Analysis/LazyCallGraph.h" #include "llvm/AsmParser/Parser.h" -#include "llvm/IR/Instructions.h" #include "llvm/IR/Function.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/Support/ErrorHandling.h" diff --git a/unittests/Analysis/MemorySSA.cpp b/unittests/Analysis/MemorySSA.cpp index 08b0e830a9b2..affa0e71820c 100644 --- a/unittests/Analysis/MemorySSA.cpp +++ b/unittests/Analysis/MemorySSA.cpp @@ -6,9 +6,9 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// +#include "llvm/Analysis/MemorySSA.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/BasicAliasAnalysis.h" -#include "llvm/Analysis/MemorySSA.h" #include "llvm/Analysis/MemorySSAUpdater.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/DataLayout.h" @@ -244,6 +244,52 @@ TEST_F(MemorySSATest, CreateALoadUpdater) { MSSA.verifyMemorySSA(); } +TEST_F(MemorySSATest, SinkLoad) { + F = Function::Create( + FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), + GlobalValue::ExternalLinkage, "F", &M); + BasicBlock *Entry(BasicBlock::Create(C, "", F)); + BasicBlock *Left(BasicBlock::Create(C, "", F)); + BasicBlock *Right(BasicBlock::Create(C, "", F)); + BasicBlock *Merge(BasicBlock::Create(C, "", F)); + B.SetInsertPoint(Entry); + B.CreateCondBr(B.getTrue(), Left, Right); + B.SetInsertPoint(Left, Left->begin()); + Argument *PointerArg = &*F->arg_begin(); + B.SetInsertPoint(Left); + B.CreateBr(Merge); + B.SetInsertPoint(Right); + B.CreateBr(Merge); + + // Load in left block + B.SetInsertPoint(Left, Left->begin()); + LoadInst *LoadInst1 = B.CreateLoad(PointerArg); + // Store in merge block + B.SetInsertPoint(Merge, Merge->begin()); + B.CreateStore(B.getInt8(16), PointerArg); + + setupAnalyses(); + MemorySSA &MSSA = *Analyses->MSSA; + MemorySSAUpdater Updater(&MSSA); + + // Mimic sinking of a load: + // - clone load + // - insert in "exit" block + // - insert in mssa + // - remove from original block + + LoadInst *LoadInstClone = cast<LoadInst>(LoadInst1->clone()); + Merge->getInstList().insert(Merge->begin(), LoadInstClone); + MemoryAccess * NewLoadAccess = + Updater.createMemoryAccessInBB(LoadInstClone, nullptr, + LoadInstClone->getParent(), + MemorySSA::Beginning); + Updater.insertUse(cast<MemoryUse>(NewLoadAccess)); + MSSA.verifyMemorySSA(); + Updater.removeMemoryAccess(MSSA.getMemoryAccess(LoadInst1)); + MSSA.verifyMemorySSA(); +} + TEST_F(MemorySSATest, MoveAStore) { // We create a diamond where there is a in the entry, a store on one side, and // a load at the end. After building MemorySSA, we test updating by moving diff --git a/unittests/Analysis/ProfileSummaryInfoTest.cpp b/unittests/Analysis/ProfileSummaryInfoTest.cpp index c9e4fc029dc0..68a6d7bb4584 100644 --- a/unittests/Analysis/ProfileSummaryInfoTest.cpp +++ b/unittests/Analysis/ProfileSummaryInfoTest.cpp @@ -7,11 +7,11 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/Analysis/BlockFrequencyInfo.h" #include "llvm/Analysis/BlockFrequencyInfoImpl.h" #include "llvm/Analysis/BranchProbabilityInfo.h" #include "llvm/Analysis/LoopInfo.h" -#include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/AsmParser/Parser.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CallSite.h" diff --git a/unittests/Analysis/ScalarEvolutionTest.cpp b/unittests/Analysis/ScalarEvolutionTest.cpp index fcbbb46f7a7e..91f4c3535b74 100644 --- a/unittests/Analysis/ScalarEvolutionTest.cpp +++ b/unittests/Analysis/ScalarEvolutionTest.cpp @@ -10,7 +10,6 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/LoopInfo.h" -#include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/ScalarEvolutionExpander.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "llvm/Analysis/TargetLibraryInfo.h" diff --git a/unittests/Analysis/TBAATest.cpp b/unittests/Analysis/TBAATest.cpp index 3a1d2f43563e..f3f05d8fbd93 100644 --- a/unittests/Analysis/TBAATest.cpp +++ b/unittests/Analysis/TBAATest.cpp @@ -12,9 +12,9 @@ #include "llvm/IR/Constants.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/MDBuilder.h" #include "llvm/IR/Module.h" -#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Verifier.h" #include "llvm/Support/CommandLine.h" #include "gtest/gtest.h" diff --git a/unittests/Analysis/UnrollAnalyzer.cpp b/unittests/Analysis/UnrollAnalyzer.cpp index d6a7bd360b93..937e69f0c257 100644 --- a/unittests/Analysis/UnrollAnalyzer.cpp +++ b/unittests/Analysis/UnrollAnalyzer.cpp @@ -7,11 +7,11 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Analysis/LoopUnrollAnalyzer.h" #include "llvm/AsmParser/Parser.h" +#include "llvm/IR/Dominators.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/Support/SourceMgr.h" -#include "llvm/Analysis/LoopUnrollAnalyzer.h" -#include "llvm/IR/Dominators.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/BinaryFormat/CMakeLists.txt b/unittests/BinaryFormat/CMakeLists.txt new file mode 100644 index 000000000000..631936795b6c --- /dev/null +++ b/unittests/BinaryFormat/CMakeLists.txt @@ -0,0 +1,9 @@ +set(LLVM_LINK_COMPONENTS + BinaryFormat + ) + +add_llvm_unittest(BinaryFormatTests + DwarfTest.cpp + TestFileMagic.cpp + ) + diff --git a/unittests/Support/DwarfTest.cpp b/unittests/BinaryFormat/DwarfTest.cpp index 148ea2736e15..f24e029beef2 100644 --- a/unittests/Support/DwarfTest.cpp +++ b/unittests/BinaryFormat/DwarfTest.cpp @@ -1,4 +1,4 @@ -//===- unittest/Support/DwarfTest.cpp - Dwarf support tests ---------------===// +//===- unittest/BinaryFormat/DwarfTest.cpp - Dwarf support tests ----------===// // // The LLVM Compiler Infrastructure // @@ -7,7 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/Dwarf.h" +#include "llvm/BinaryFormat/Dwarf.h" +#include "llvm/ADT/StringRef.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/BinaryFormat/TestFileMagic.cpp b/unittests/BinaryFormat/TestFileMagic.cpp new file mode 100644 index 000000000000..fc2c1eef9fbf --- /dev/null +++ b/unittests/BinaryFormat/TestFileMagic.cpp @@ -0,0 +1,128 @@ +//===- llvm/unittest/BinaryFormat/TestFileMagic.cpp - File magic tests ----===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/Magic.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" + +#include "gtest/gtest.h" + +using namespace llvm; +namespace fs = llvm::sys::fs; + +#define ASSERT_NO_ERROR(x) \ + if (std::error_code ASSERT_NO_ERROR_ec = x) { \ + SmallString<128> MessageStorage; \ + raw_svector_ostream Message(MessageStorage); \ + Message << #x ": did not return errc::success.\n" \ + << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \ + << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \ + GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \ + } else { \ + } + +class MagicTest : public testing::Test { +protected: + /// Unique temporary directory in which all created filesystem entities must + /// be placed. It is removed at the end of each test (must be empty). + SmallString<128> TestDirectory; + + void SetUp() override { + ASSERT_NO_ERROR( + fs::createUniqueDirectory("file-system-test", TestDirectory)); + // We don't care about this specific file. + errs() << "Test Directory: " << TestDirectory << '\n'; + errs().flush(); + } + + void TearDown() override { ASSERT_NO_ERROR(fs::remove(TestDirectory.str())); } +}; + +const char archive[] = "!<arch>\x0A"; +const char bitcode[] = "\xde\xc0\x17\x0b"; +const char coff_object[] = "\x00\x00......"; +const char coff_bigobj[] = + "\x00\x00\xff\xff\x00\x02......" + "\xc7\xa1\xba\xd1\xee\xba\xa9\x4b\xaf\x20\xfa\xf6\x6a\xa4\xdc\xb8"; +const char coff_import_library[] = "\x00\x00\xff\xff...."; +const char elf_relocatable[] = {0x7f, 'E', 'L', 'F', 1, 2, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1}; +const char macho_universal_binary[] = "\xca\xfe\xba\xbe...\x00"; +const char macho_object[] = + "\xfe\xed\xfa\xce........\x00\x00\x00\x01............"; +const char macho_executable[] = + "\xfe\xed\xfa\xce........\x00\x00\x00\x02............"; +const char macho_fixed_virtual_memory_shared_lib[] = + "\xfe\xed\xfa\xce........\x00\x00\x00\x03............"; +const char macho_core[] = + "\xfe\xed\xfa\xce........\x00\x00\x00\x04............"; +const char macho_preload_executable[] = + "\xfe\xed\xfa\xce........\x00\x00\x00\x05............"; +const char macho_dynamically_linked_shared_lib[] = + "\xfe\xed\xfa\xce........\x00\x00\x00\x06............"; +const char macho_dynamic_linker[] = + "\xfe\xed\xfa\xce........\x00\x00\x00\x07............"; +const char macho_bundle[] = + "\xfe\xed\xfa\xce........\x00\x00\x00\x08............"; +const char macho_dsym_companion[] = + "\xfe\xed\xfa\xce........\x00\x00\x00\x0a............"; +const char macho_kext_bundle[] = + "\xfe\xed\xfa\xce........\x00\x00\x00\x0b............"; +const char windows_resource[] = "\x00\x00\x00\x00\x020\x00\x00\x00\xff"; +const char macho_dynamically_linked_shared_lib_stub[] = + "\xfe\xed\xfa\xce........\x00\x00\x00\x09............"; + +TEST_F(MagicTest, Magic) { + struct type { + const char *filename; + const char *magic_str; + size_t magic_str_len; + file_magic magic; + } types[] = { +#define DEFINE(magic) {#magic, magic, sizeof(magic), file_magic::magic} + DEFINE(archive), + DEFINE(bitcode), + DEFINE(coff_object), + {"coff_bigobj", coff_bigobj, sizeof(coff_bigobj), + file_magic::coff_object}, + DEFINE(coff_import_library), + DEFINE(elf_relocatable), + DEFINE(macho_universal_binary), + DEFINE(macho_object), + DEFINE(macho_executable), + DEFINE(macho_fixed_virtual_memory_shared_lib), + DEFINE(macho_core), + DEFINE(macho_preload_executable), + DEFINE(macho_dynamically_linked_shared_lib), + DEFINE(macho_dynamic_linker), + DEFINE(macho_bundle), + DEFINE(macho_dynamically_linked_shared_lib_stub), + DEFINE(macho_dsym_companion), + DEFINE(macho_kext_bundle), + DEFINE(windows_resource) +#undef DEFINE + }; + + // Create some files filled with magic. + for (type *i = types, *e = types + (sizeof(types) / sizeof(type)); i != e; + ++i) { + SmallString<128> file_pathname(TestDirectory); + llvm::sys::path::append(file_pathname, i->filename); + std::error_code EC; + raw_fd_ostream file(file_pathname, EC, sys::fs::F_None); + ASSERT_FALSE(file.has_error()); + StringRef magic(i->magic_str, i->magic_str_len); + file << magic; + file.close(); + EXPECT_EQ(i->magic, identify_magic(magic)); + ASSERT_NO_ERROR(fs::remove(Twine(file_pathname))); + } +} diff --git a/unittests/Bitcode/BitstreamReaderTest.cpp b/unittests/Bitcode/BitstreamReaderTest.cpp index 935ef4bcffc0..e7535f3e818e 100644 --- a/unittests/Bitcode/BitstreamReaderTest.cpp +++ b/unittests/Bitcode/BitstreamReaderTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/STLExtras.h" #include "llvm/Bitcode/BitstreamReader.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Bitcode/BitstreamWriter.h" #include "gtest/gtest.h" diff --git a/unittests/Bitcode/BitstreamWriterTest.cpp b/unittests/Bitcode/BitstreamWriterTest.cpp index f17cc157cde9..79143c8e7a63 100644 --- a/unittests/Bitcode/BitstreamWriterTest.cpp +++ b/unittests/Bitcode/BitstreamWriterTest.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Bitcode/BitstreamWriter.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" -#include "llvm/Bitcode/BitstreamWriter.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 8e40f141463b..daece1fe3221 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -18,6 +18,7 @@ add_subdirectory(Linker) add_subdirectory(MC) add_subdirectory(MI) add_subdirectory(Object) +add_subdirectory(BinaryFormat) add_subdirectory(ObjectYAML) add_subdirectory(Option) add_subdirectory(ProfileData) diff --git a/unittests/CodeGen/DIEHashTest.cpp b/unittests/CodeGen/DIEHashTest.cpp index dda08fcd6654..f60b0dd3b7ef 100644 --- a/unittests/CodeGen/DIEHashTest.cpp +++ b/unittests/CodeGen/DIEHashTest.cpp @@ -7,12 +7,12 @@ // //===----------------------------------------------------------------------===// -#include "llvm/CodeGen/DIE.h" #include "../lib/CodeGen/AsmPrinter/DIEHash.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/BinaryFormat/Dwarf.h" +#include "llvm/CodeGen/DIE.h" #include "llvm/CodeGen/DwarfStringPoolEntry.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/Dwarf.h" #include "llvm/Support/Format.h" #include "gtest/gtest.h" diff --git a/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp b/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp index 8f15fbf3941d..63365ab8fd4e 100644 --- a/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp +++ b/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/ilist_node.h" #include "llvm/CodeGen/MachineInstrBundleIterator.h" +#include "llvm/ADT/ilist_node.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp b/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp index 3d14eb736df2..18cab52a81b0 100644 --- a/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ b/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -13,6 +13,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Triple.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/Config/llvm-config.h" #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" @@ -21,7 +22,6 @@ #include "llvm/Object/ObjectFile.h" #include "llvm/ObjectYAML/DWARFEmitter.h" #include "llvm/ObjectYAML/DWARFYAML.h" -#include "llvm/Support/Dwarf.h" #include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/TargetSelect.h" diff --git a/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp b/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp index 028a03595de6..da7f43e721aa 100644 --- a/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp +++ b/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp @@ -10,7 +10,7 @@ #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallString.h" -#include "llvm/Support/Dwarf.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/Support/Host.h" #include "llvm/Support/LEB128.h" #include "gtest/gtest.h" diff --git a/unittests/DebugInfo/DWARF/DwarfGenerator.cpp b/unittests/DebugInfo/DWARF/DwarfGenerator.cpp index ac63bbaf0a11..c32cfa1de9ae 100644 --- a/unittests/DebugInfo/DWARF/DwarfGenerator.cpp +++ b/unittests/DebugInfo/DWARF/DwarfGenerator.cpp @@ -7,9 +7,10 @@ // //===----------------------------------------------------------------------===// -#include "../lib/CodeGen/AsmPrinter/DwarfStringPool.h" #include "DwarfGenerator.h" +#include "../lib/CodeGen/AsmPrinter/DwarfStringPool.h" #include "llvm/ADT/Triple.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/CodeGen/DIE.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" @@ -28,7 +29,6 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCTargetOptionsCommandFlags.h" #include "llvm/PassAnalysisSupport.h" -#include "llvm/Support/Dwarf.h" #include "llvm/Support/LEB128.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" diff --git a/unittests/ExecutionEngine/ExecutionEngineTest.cpp b/unittests/ExecutionEngine/ExecutionEngineTest.cpp index 7cad84130692..ec5fab6c4893 100644 --- a/unittests/ExecutionEngine/ExecutionEngineTest.cpp +++ b/unittests/ExecutionEngine/ExecutionEngineTest.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/STLExtras.h" #include "llvm/ExecutionEngine/Interpreter.h" #include "llvm/ExecutionEngine/RTDyldMemoryManager.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/LLVMContext.h" diff --git a/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp index cf63da3a22a5..155d10f5ccd3 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp @@ -12,8 +12,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm-c/Analysis.h" #include "MCJITTestAPICommon.h" +#include "llvm-c/Analysis.h" #include "llvm-c/Core.h" #include "llvm-c/ExecutionEngine.h" #include "llvm-c/Target.h" diff --git a/unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp index 65f969f24c6c..1226bba1c506 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp @@ -12,8 +12,8 @@ // modules, accessing global variables, etc. //===----------------------------------------------------------------------===// -#include "llvm/ExecutionEngine/MCJIT.h" #include "MCJITTestBase.h" +#include "llvm/ExecutionEngine/MCJIT.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp index 744bfdb4a01b..bc5cd689a19f 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp @@ -13,8 +13,8 @@ //===----------------------------------------------------------------------===// #include "llvm/ExecutionEngine/MCJIT.h" -#include "llvm/Support/DynamicLibrary.h" #include "MCJITTestBase.h" +#include "llvm/Support/DynamicLibrary.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp b/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp index ab04c14b0957..13693381c006 100644 --- a/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp +++ b/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "OrcTestCommon.h" #include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h" +#include "OrcTestCommon.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/ExecutionEngine/Orc/IndirectionUtilsTest.cpp b/unittests/ExecutionEngine/Orc/IndirectionUtilsTest.cpp index ab43c4af13f1..ed425449784c 100644 --- a/unittests/ExecutionEngine/Orc/IndirectionUtilsTest.cpp +++ b/unittests/ExecutionEngine/Orc/IndirectionUtilsTest.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h" #include "OrcTestCommon.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/ExecutionEngine/Orc/LazyEmittingLayerTest.cpp b/unittests/ExecutionEngine/Orc/LazyEmittingLayerTest.cpp index 3362f490a38a..213c460aa676 100644 --- a/unittests/ExecutionEngine/Orc/LazyEmittingLayerTest.cpp +++ b/unittests/ExecutionEngine/Orc/LazyEmittingLayerTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ExecutionEngine/RuntimeDyld.h" #include "llvm/ExecutionEngine/Orc/LazyEmittingLayer.h" +#include "llvm/ExecutionEngine/RuntimeDyld.h" #include "gtest/gtest.h" namespace { diff --git a/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp b/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp index 362c143c54ef..68db454637c5 100644 --- a/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp +++ b/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp @@ -7,13 +7,13 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" #include "llvm/ExecutionEngine/Orc/NullResolver.h" #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h" -#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h" #include "llvm/Object/ObjectFile.h" #include "gtest/gtest.h" diff --git a/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp b/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp index 305325b6c6ef..e8ba16a472b7 100644 --- a/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp +++ b/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp @@ -8,11 +8,11 @@ //===----------------------------------------------------------------------===// #include "OrcTestCommon.h" -#include "gtest/gtest.h" #include "llvm-c/Core.h" #include "llvm-c/OrcBindings.h" #include "llvm-c/Target.h" #include "llvm-c/TargetMachine.h" +#include "gtest/gtest.h" #include <stdio.h> #include <stdlib.h> diff --git a/unittests/ExecutionEngine/Orc/OrcTestCommon.h b/unittests/ExecutionEngine/Orc/OrcTestCommon.h index dff72c6b9d57..24320034a17a 100644 --- a/unittests/ExecutionEngine/Orc/OrcTestCommon.h +++ b/unittests/ExecutionEngine/Orc/OrcTestCommon.h @@ -15,14 +15,14 @@ #ifndef LLVM_UNITTESTS_EXECUTIONENGINE_ORC_ORCTESTCOMMON_H #define LLVM_UNITTESTS_EXECUTIONENGINE_ORC_ORCTESTCOMMON_H +#include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/IR/TypeBuilder.h" #include "llvm/Object/ObjectFile.h" -#include "llvm/ExecutionEngine/ExecutionEngine.h" -#include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/Support/TargetSelect.h" #include <memory> diff --git a/unittests/ExecutionEngine/Orc/QueueChannel.h b/unittests/ExecutionEngine/Orc/QueueChannel.h index 3d1058a83ebc..d8c16811af11 100644 --- a/unittests/ExecutionEngine/Orc/QueueChannel.h +++ b/unittests/ExecutionEngine/Orc/QueueChannel.h @@ -13,8 +13,8 @@ #include "llvm/ExecutionEngine/Orc/RawByteChannel.h" #include "llvm/Support/Error.h" -#include <queue> #include <condition_variable> +#include <queue> namespace llvm { diff --git a/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp b/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp index c13a75a5cbfe..8878451bdec2 100644 --- a/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp +++ b/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp @@ -7,13 +7,13 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h" #include "OrcTestCommon.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" -#include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" #include "llvm/ExecutionEngine/Orc/NullResolver.h" -#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h" +#include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/IR/Constants.h" #include "llvm/IR/LLVMContext.h" #include "gtest/gtest.h" diff --git a/unittests/IR/AsmWriterTest.cpp b/unittests/IR/AsmWriterTest.cpp index c7e7bb5c9f0f..55c2a70e21f5 100644 --- a/unittests/IR/AsmWriterTest.cpp +++ b/unittests/IR/AsmWriterTest.cpp @@ -6,8 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#include "llvm/IR/IRBuilder.h" #include "llvm/IR/Function.h" +#include "llvm/IR/IRBuilder.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/MDBuilder.h" #include "llvm/IR/Module.h" diff --git a/unittests/IR/ConstantRangeTest.cpp b/unittests/IR/ConstantRangeTest.cpp index c6c9bf6d6b50..0292f60fe332 100644 --- a/unittests/IR/ConstantRangeTest.cpp +++ b/unittests/IR/ConstantRangeTest.cpp @@ -187,6 +187,23 @@ TEST_F(ConstantRangeTest, Trunc) { EXPECT_EQ(TOne, ConstantRange(One.getLower().trunc(10), One.getUpper().trunc(10))); EXPECT_TRUE(TSome.isFullSet()); + EXPECT_TRUE(TWrap.isFullSet()); + + // trunc([2, 5), 3->2) = [2, 1) + ConstantRange TwoFive(APInt(3, 2), APInt(3, 5)); + EXPECT_EQ(TwoFive.truncate(2), ConstantRange(APInt(2, 2), APInt(2, 1))); + + // trunc([2, 6), 3->2) = full + ConstantRange TwoSix(APInt(3, 2), APInt(3, 6)); + EXPECT_TRUE(TwoSix.truncate(2).isFullSet()); + + // trunc([5, 7), 3->2) = [1, 3) + ConstantRange FiveSeven(APInt(3, 5), APInt(3, 7)); + EXPECT_EQ(FiveSeven.truncate(2), ConstantRange(APInt(2, 1), APInt(2, 3))); + + // trunc([7, 1), 3->2) = [3, 1) + ConstantRange SevenOne(APInt(3, 7), APInt(3, 1)); + EXPECT_EQ(SevenOne.truncate(2), ConstantRange(APInt(2, 3), APInt(2, 1))); } TEST_F(ConstantRangeTest, ZExt) { diff --git a/unittests/IR/ConstantsTest.cpp b/unittests/IR/ConstantsTest.cpp index 7a8a3045a0d4..ccffa50bf133 100644 --- a/unittests/IR/ConstantsTest.cpp +++ b/unittests/IR/ConstantsTest.cpp @@ -7,15 +7,15 @@ // //===----------------------------------------------------------------------===// -#include "llvm/AsmParser/Parser.h" #include "llvm/IR/Constants.h" +#include "llvm-c/Core.h" +#include "llvm/AsmParser/Parser.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/Support/SourceMgr.h" -#include "llvm-c/Core.h" #include "gtest/gtest.h" namespace llvm { diff --git a/unittests/IR/DebugTypeODRUniquingTest.cpp b/unittests/IR/DebugTypeODRUniquingTest.cpp index 7cf1cd22a2fb..7eb08e24b408 100644 --- a/unittests/IR/DebugTypeODRUniquingTest.cpp +++ b/unittests/IR/DebugTypeODRUniquingTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/IR/LLVMContext.h" #include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/LLVMContext.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/IR/DominatorTreeTest.cpp b/unittests/IR/DominatorTreeTest.cpp index d2062839a734..232f0cbd4ed9 100644 --- a/unittests/IR/DominatorTreeTest.cpp +++ b/unittests/IR/DominatorTreeTest.cpp @@ -257,3 +257,55 @@ TEST(DominatorTree, Unreachable) { DT->verifyDomTree(); }); } + +TEST(DominatorTree, NonUniqueEdges) { + StringRef ModuleString = + "define i32 @f(i32 %i, i32 *%p) {\n" + "bb0:\n" + " store i32 %i, i32 *%p\n" + " switch i32 %i, label %bb2 [\n" + " i32 0, label %bb1\n" + " i32 1, label %bb1\n" + " ]\n" + " bb1:\n" + " ret i32 1\n" + " bb2:\n" + " ret i32 4\n" + "}\n"; + + // Parse the module. + LLVMContext Context; + std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString); + + runWithDomTree( + *M, "f", + [&](Function &F, DominatorTree *DT, DominatorTreeBase<BasicBlock> *PDT) { + Function::iterator FI = F.begin(); + + BasicBlock *BB0 = &*FI++; + BasicBlock *BB1 = &*FI++; + BasicBlock *BB2 = &*FI++; + + const TerminatorInst *TI = BB0->getTerminator(); + assert(TI->getNumSuccessors() == 3 && "Switch has three successors"); + + BasicBlockEdge Edge_BB0_BB2(BB0, TI->getSuccessor(0)); + assert(Edge_BB0_BB2.getEnd() == BB2 && + "Default label is the 1st successor"); + + BasicBlockEdge Edge_BB0_BB1_a(BB0, TI->getSuccessor(1)); + assert(Edge_BB0_BB1_a.getEnd() == BB1 && "BB1 is the 2nd successor"); + + BasicBlockEdge Edge_BB0_BB1_b(BB0, TI->getSuccessor(2)); + assert(Edge_BB0_BB1_b.getEnd() == BB1 && "BB1 is the 3rd successor"); + + EXPECT_TRUE(DT->dominates(Edge_BB0_BB2, BB2)); + EXPECT_FALSE(DT->dominates(Edge_BB0_BB2, BB1)); + + EXPECT_FALSE(DT->dominates(Edge_BB0_BB1_a, BB1)); + EXPECT_FALSE(DT->dominates(Edge_BB0_BB1_b, BB1)); + + EXPECT_FALSE(DT->dominates(Edge_BB0_BB1_a, BB2)); + EXPECT_FALSE(DT->dominates(Edge_BB0_BB1_b, BB2)); + }); +} diff --git a/unittests/IR/IRBuilderTest.cpp b/unittests/IR/IRBuilderTest.cpp index 5686c3b2b3a7..186330f10573 100644 --- a/unittests/IR/IRBuilderTest.cpp +++ b/unittests/IR/IRBuilderTest.cpp @@ -9,8 +9,8 @@ #include "llvm/IR/IRBuilder.h" #include "llvm/IR/BasicBlock.h" -#include "llvm/IR/DataLayout.h" #include "llvm/IR/DIBuilder.h" +#include "llvm/IR/DataLayout.h" #include "llvm/IR/Function.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/LLVMContext.h" diff --git a/unittests/IR/MetadataTest.cpp b/unittests/IR/MetadataTest.cpp index 9f8fc4eaeb6f..bcf3babf7f68 100644 --- a/unittests/IR/MetadataTest.cpp +++ b/unittests/IR/MetadataTest.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/IR/Metadata.h" #include "llvm/ADT/STLExtras.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfo.h" @@ -14,7 +15,6 @@ #include "llvm/IR/Function.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/LLVMContext.h" -#include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/IR/ModuleSlotTracker.h" #include "llvm/IR/Type.h" diff --git a/unittests/IR/ModuleTest.cpp b/unittests/IR/ModuleTest.cpp index 9f52fedc4559..d93d036bb115 100644 --- a/unittests/IR/ModuleTest.cpp +++ b/unittests/IR/ModuleTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/IR/GlobalVariable.h" #include "llvm/IR/Module.h" +#include "llvm/IR/GlobalVariable.h" #include "llvm/Support/RandomNumberGenerator.h" #include "gtest/gtest.h" diff --git a/unittests/IR/PassManagerTest.cpp b/unittests/IR/PassManagerTest.cpp index b3a039a364fc..ad06cc4778fe 100644 --- a/unittests/IR/PassManagerTest.cpp +++ b/unittests/IR/PassManagerTest.cpp @@ -7,11 +7,11 @@ // //===----------------------------------------------------------------------===// +#include "llvm/IR/PassManager.h" #include "llvm/AsmParser/Parser.h" #include "llvm/IR/Function.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" -#include "llvm/IR/PassManager.h" #include "llvm/Support/SourceMgr.h" #include "gtest/gtest.h" diff --git a/unittests/IR/PatternMatch.cpp b/unittests/IR/PatternMatch.cpp index 2d1321def7e3..02ef87f5b13e 100644 --- a/unittests/IR/PatternMatch.cpp +++ b/unittests/IR/PatternMatch.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/IR/PatternMatch.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/BasicBlock.h" @@ -21,7 +22,6 @@ #include "llvm/IR/Module.h" #include "llvm/IR/NoFolder.h" #include "llvm/IR/Operator.h" -#include "llvm/IR/PatternMatch.h" #include "llvm/IR/Type.h" #include "gtest/gtest.h" diff --git a/unittests/IR/UserTest.cpp b/unittests/IR/UserTest.cpp index 7ba6840313b1..794dfc133bba 100644 --- a/unittests/IR/UserTest.cpp +++ b/unittests/IR/UserTest.cpp @@ -7,12 +7,12 @@ // //===----------------------------------------------------------------------===// +#include "llvm/IR/User.h" #include "llvm/AsmParser/Parser.h" #include "llvm/IR/Function.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" -#include "llvm/IR/User.h" #include "llvm/Support/SourceMgr.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/IR/ValueTest.cpp b/unittests/IR/ValueTest.cpp index 142444a809c6..0087cb2fa82c 100644 --- a/unittests/IR/ValueTest.cpp +++ b/unittests/IR/ValueTest.cpp @@ -7,12 +7,12 @@ // //===----------------------------------------------------------------------===// +#include "llvm/IR/Value.h" #include "llvm/AsmParser/Parser.h" #include "llvm/IR/Function.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/IR/ModuleSlotTracker.h" -#include "llvm/IR/Value.h" #include "llvm/Support/SourceMgr.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/IR/VerifierTest.cpp b/unittests/IR/VerifierTest.cpp index 188509aadf77..f1f453ed5d10 100644 --- a/unittests/IR/VerifierTest.cpp +++ b/unittests/IR/VerifierTest.cpp @@ -7,18 +7,18 @@ // //===----------------------------------------------------------------------===// +#include "llvm/IR/Verifier.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DIBuilder.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalAlias.h" #include "llvm/IR/GlobalVariable.h" -#include "llvm/IR/Instructions.h" #include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Module.h" -#include "llvm/IR/Verifier.h" #include "gtest/gtest.h" namespace llvm { diff --git a/unittests/Linker/LinkModulesTest.cpp b/unittests/Linker/LinkModulesTest.cpp index f31409c50121..67c12b838344 100644 --- a/unittests/Linker/LinkModulesTest.cpp +++ b/unittests/Linker/LinkModulesTest.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +#include "llvm-c/Core.h" +#include "llvm-c/Linker.h" #include "llvm/ADT/STLExtras.h" #include "llvm/AsmParser/Parser.h" #include "llvm/IR/BasicBlock.h" @@ -16,8 +18,6 @@ #include "llvm/IR/Module.h" #include "llvm/Linker/Linker.h" #include "llvm/Support/SourceMgr.h" -#include "llvm-c/Core.h" -#include "llvm-c/Linker.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/MC/DwarfLineTables.cpp b/unittests/MC/DwarfLineTables.cpp index d66c832df0ba..1b1a4d647ce0 100644 --- a/unittests/MC/DwarfLineTables.cpp +++ b/unittests/MC/DwarfLineTables.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/Dwarf.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCDwarf.h" diff --git a/unittests/MC/StringTableBuilderTest.cpp b/unittests/MC/StringTableBuilderTest.cpp index f68350d90ba5..b547f934b02c 100644 --- a/unittests/MC/StringTableBuilderTest.cpp +++ b/unittests/MC/StringTableBuilderTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/SmallString.h" #include "llvm/MC/StringTableBuilder.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Support/Endian.h" #include "gtest/gtest.h" #include <string> diff --git a/unittests/MI/LiveIntervalTest.cpp b/unittests/MI/LiveIntervalTest.cpp index 026fb42d345f..7118a43e6d88 100644 --- a/unittests/MI/LiveIntervalTest.cpp +++ b/unittests/MI/LiveIntervalTest.cpp @@ -1,4 +1,3 @@ -#include "gtest/gtest.h" #include "llvm/ADT/STLExtras.h" #include "llvm/CodeGen/LiveIntervalAnalysis.h" #include "llvm/CodeGen/MIRParser/MIRParser.h" @@ -6,6 +5,7 @@ #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/Passes.h" +#include "llvm/IR/LegacyPassManager.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/TargetRegistry.h" @@ -13,7 +13,7 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" #include "llvm/Target/TargetRegisterInfo.h" -#include "llvm/IR/LegacyPassManager.h" +#include "gtest/gtest.h" using namespace llvm; @@ -59,18 +59,15 @@ std::unique_ptr<Module> parseMIR(LLVMContext &Context, if (!MIR) return nullptr; - std::unique_ptr<Module> M = MIR->parseLLVMModule(); + std::unique_ptr<Module> M = MIR->parseIRModule(); if (!M) return nullptr; M->setDataLayout(TM.createDataLayout()); - Function *F = M->getFunction(FuncName); - if (!F) - return nullptr; - MachineModuleInfo *MMI = new MachineModuleInfo(&TM); - MMI->setMachineFunctionInitializer(MIR.get()); + if (MIR->parseMachineFunctions(*M, *MMI)) + return nullptr; PM.add(MMI); return M; @@ -154,6 +151,8 @@ body: | std::unique_ptr<MIRParser> MIR; std::unique_ptr<Module> M = parseMIR(Context, PM, MIR, *TM, MIRString, "func"); + if (!M) + report_fatal_error("Could not parse MIR code\n"); PM.add(new TestPass(T)); diff --git a/unittests/ProfileData/CoverageMappingTest.cpp b/unittests/ProfileData/CoverageMappingTest.cpp index 0783a23a67b0..0e6e993cf3da 100644 --- a/unittests/ProfileData/CoverageMappingTest.cpp +++ b/unittests/ProfileData/CoverageMappingTest.cpp @@ -584,6 +584,6 @@ INSTANTIATE_TEST_CASE_P(ParameterizedCovMapTest, CoverageMappingTest, ::testing::Values(std::pair<bool, bool>({false, false}), std::pair<bool, bool>({false, true}), std::pair<bool, bool>({true, false}), - std::pair<bool, bool>({true, true}))); + std::pair<bool, bool>({true, true})),); } // end anonymous namespace diff --git a/unittests/ProfileData/InstrProfTest.cpp b/unittests/ProfileData/InstrProfTest.cpp index 1b44463cd650..b15029a08137 100644 --- a/unittests/ProfileData/InstrProfTest.cpp +++ b/unittests/ProfileData/InstrProfTest.cpp @@ -1024,6 +1024,6 @@ TEST_F(SparseInstrProfTest, preserve_no_records) { } INSTANTIATE_TEST_CASE_P(MaybeSparse, MaybeSparseInstrProfTest, - ::testing::Bool()); + ::testing::Bool(),); } // end anonymous namespace diff --git a/unittests/ProfileData/SampleProfTest.cpp b/unittests/ProfileData/SampleProfTest.cpp index 96b2a01c7bd7..68b46cc5086d 100644 --- a/unittests/ProfileData/SampleProfTest.cpp +++ b/unittests/ProfileData/SampleProfTest.cpp @@ -7,13 +7,13 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ProfileData/SampleProf.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/ProfileData/ProfileCommon.h" -#include "llvm/ProfileData/SampleProf.h" #include "llvm/ProfileData/SampleProfReader.h" #include "llvm/ProfileData/SampleProfWriter.h" #include "llvm/Support/Casting.h" diff --git a/unittests/Support/ARMAttributeParser.cpp b/unittests/Support/ARMAttributeParser.cpp index c2df6537ff63..1df03db6d07f 100644 --- a/unittests/Support/ARMAttributeParser.cpp +++ b/unittests/Support/ARMAttributeParser.cpp @@ -1,5 +1,5 @@ -#include "llvm/Support/ARMBuildAttributes.h" #include "llvm/Support/ARMAttributeParser.h" +#include "llvm/Support/ARMBuildAttributes.h" #include "llvm/Support/LEB128.h" #include "gtest/gtest.h" #include <string> diff --git a/unittests/Support/BinaryStreamTest.cpp b/unittests/Support/BinaryStreamTest.cpp index 1ce74cbb722b..795c18902a9b 100644 --- a/unittests/Support/BinaryStreamTest.cpp +++ b/unittests/Support/BinaryStreamTest.cpp @@ -416,9 +416,7 @@ TEST_F(BinaryStreamTest, VarStreamArray) { struct StringExtractor { public: - typedef uint32_t &ContextType; - static Error extract(BinaryStreamRef Stream, uint32_t &Len, StringRef &Item, - uint32_t &Index) { + Error operator()(BinaryStreamRef Stream, uint32_t &Len, StringRef &Item) { if (Index == 0) Len = strlen("1. Test"); else if (Index == 1) @@ -435,11 +433,12 @@ TEST_F(BinaryStreamTest, VarStreamArray) { ++Index; return Error::success(); } + + uint32_t Index = 0; }; for (auto &Stream : Streams) { - uint32_t Context = 0; - VarStreamArray<StringRef, StringExtractor> Array(*Stream.Input, Context); + VarStreamArray<StringRef, StringExtractor> Array(*Stream.Input); auto Iter = Array.begin(); ASSERT_EQ("1. Test", *Iter++); ASSERT_EQ("2. Longer Test", *Iter++); diff --git a/unittests/Support/CMakeLists.txt b/unittests/Support/CMakeLists.txt index e7f2f515d76a..098dba83197b 100644 --- a/unittests/Support/CMakeLists.txt +++ b/unittests/Support/CMakeLists.txt @@ -19,7 +19,6 @@ add_llvm_unittest(SupportTests ConvertUTFTest.cpp DataExtractorTest.cpp DebugTest.cpp - DwarfTest.cpp EndianStreamTest.cpp EndianTest.cpp ErrorOrTest.cpp @@ -67,6 +66,11 @@ add_llvm_unittest(SupportTests xxhashTest.cpp ) +# Disable all warning for AlignOfTest.cpp, +# as it does things intentionally, and there is no reliable way of +# disabling all warnings for all the compilers by using pragmas. +set_source_files_properties(AlignOfTest.cpp PROPERTIES COMPILE_FLAGS -w) + # ManagedStatic.cpp uses <pthread>. target_link_libraries(SupportTests ${LLVM_PTHREAD_LIB}) diff --git a/unittests/Support/CommandLineTest.cpp b/unittests/Support/CommandLineTest.cpp index 33573c4e6960..7fdd42b4feca 100644 --- a/unittests/Support/CommandLineTest.cpp +++ b/unittests/Support/CommandLineTest.cpp @@ -7,10 +7,10 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/SmallString.h" +#include "llvm/Support/CommandLine.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Config/config.h" -#include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/StringSaver.h" diff --git a/unittests/Support/CompressionTest.cpp b/unittests/Support/CompressionTest.cpp index 18a6175460d3..505714bd2da5 100644 --- a/unittests/Support/CompressionTest.cpp +++ b/unittests/Support/CompressionTest.cpp @@ -12,10 +12,10 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Compression.h" -#include "llvm/Support/Error.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" #include "llvm/Config/config.h" +#include "llvm/Support/Error.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/Support/CrashRecoveryTest.cpp b/unittests/Support/CrashRecoveryTest.cpp index e9ffd1f8871f..3f13693632db 100644 --- a/unittests/Support/CrashRecoveryTest.cpp +++ b/unittests/Support/CrashRecoveryTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/CrashRecoveryContext.h" #include "gtest/gtest.h" #ifdef LLVM_ON_WIN32 diff --git a/unittests/Support/DataExtractorTest.cpp b/unittests/Support/DataExtractorTest.cpp index 81de983d2265..8b645524ec6c 100644 --- a/unittests/Support/DataExtractorTest.cpp +++ b/unittests/Support/DataExtractorTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/Support/DataExtractor.h" +#include "gtest/gtest.h" using namespace llvm; namespace { diff --git a/unittests/Support/DynamicLibrary/CMakeLists.txt b/unittests/Support/DynamicLibrary/CMakeLists.txt index f0e945e78b18..2fa4bf237d40 100644 --- a/unittests/Support/DynamicLibrary/CMakeLists.txt +++ b/unittests/Support/DynamicLibrary/CMakeLists.txt @@ -4,16 +4,21 @@ add_llvm_unittest(DynamicLibraryTests DynamicLibraryTest.cpp) export_executable_symbols(DynamicLibraryTests) -add_library(PipSqueak SHARED PipSqueak.cxx) +function(dynlib_add_module NAME) + add_library(${NAME} SHARED PipSqueak.cxx) -set_output_directory(PipSqueak - BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR} - LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR} - ) + set_output_directory(${NAME} + BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR} + LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR} + ) -set_target_properties(PipSqueak - PROPERTIES PREFIX "" - SUFFIX ".so" - ) + set_target_properties(${NAME} + PROPERTIES PREFIX "" + SUFFIX ".so" + ) -add_dependencies(DynamicLibraryTests PipSqueak) + add_dependencies(DynamicLibraryTests ${NAME}) +endfunction(dynlib_add_module) + +dynlib_add_module(PipSqueak) +dynlib_add_module(SecondLib) diff --git a/unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp b/unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp index 0674a91282a1..80a20990de18 100644 --- a/unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp +++ b/unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp @@ -7,34 +7,34 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Config/config.h" #include "llvm/Support/DynamicLibrary.h" +#include "llvm/Config/config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Path.h" #include "gtest/gtest.h" #include "PipSqueak.h" -#include <string> using namespace llvm; using namespace llvm::sys; extern "C" PIPSQUEAK_EXPORT const char *TestA() { return "ProcessCall"; } -std::string LibPath() { +std::string LibPath(const std::string Name = "PipSqueak") { const std::vector<testing::internal::string>& Argvs = testing::internal::GetArgvs(); const char *Argv0 = Argvs.size() > 0 ? Argvs[0].c_str() : "DynamicLibraryTests"; void *Ptr = (void*)(intptr_t)TestA; std::string Path = fs::getMainExecutable(Argv0, Ptr); llvm::SmallString<256> Buf(path::parent_path(Path)); - path::append(Buf, "PipSqueak.so"); + path::append(Buf, (Name+".so").c_str()); return Buf.str(); } #if defined(_WIN32) || (defined(HAVE_DLFCN_H) && defined(HAVE_DLOPEN)) typedef void (*SetStrings)(std::string &GStr, std::string &LStr); +typedef void (*TestOrder)(std::vector<std::string> &V); typedef const char *(*GetString)(); template <class T> static T FuncPtr(void *Ptr) { @@ -100,26 +100,59 @@ TEST(DynamicLibrary, Overload) { } TEST(DynamicLibrary, Shutdown) { - std::string A, B; + std::string A("PipSqueak"), B, C("SecondLib"); + std::vector<std::string> Order; { std::string Err; llvm_shutdown_obj Shutdown; DynamicLibrary DL = - DynamicLibrary::getPermanentLibrary(LibPath().c_str(), &Err); + DynamicLibrary::getPermanentLibrary(LibPath(A).c_str(), &Err); EXPECT_TRUE(DL.isValid()); EXPECT_TRUE(Err.empty()); - SetStrings SS = FuncPtr<SetStrings>( + SetStrings SS_0 = FuncPtr<SetStrings>( DynamicLibrary::SearchForAddressOfSymbol("SetStrings")); - EXPECT_TRUE(SS != nullptr); + EXPECT_TRUE(SS_0 != nullptr); + + SS_0(A, B); + EXPECT_EQ(B, "Local::Local(PipSqueak)"); + + TestOrder TO_0 = FuncPtr<TestOrder>( + DynamicLibrary::SearchForAddressOfSymbol("TestOrder")); + EXPECT_TRUE(TO_0 != nullptr); + + DynamicLibrary DL2 = + DynamicLibrary::getPermanentLibrary(LibPath(C).c_str(), &Err); + EXPECT_TRUE(DL2.isValid()); + EXPECT_TRUE(Err.empty()); - SS(A, B); - EXPECT_EQ(B, "Local::Local"); + // Should find latest version of symbols in SecondLib + SetStrings SS_1 = FuncPtr<SetStrings>( + DynamicLibrary::SearchForAddressOfSymbol("SetStrings")); + EXPECT_TRUE(SS_1 != nullptr); + EXPECT_TRUE(SS_0 != SS_1); + + TestOrder TO_1 = FuncPtr<TestOrder>( + DynamicLibrary::SearchForAddressOfSymbol("TestOrder")); + EXPECT_TRUE(TO_1 != nullptr); + EXPECT_TRUE(TO_0 != TO_1); + + B.clear(); + SS_1(C, B); + EXPECT_EQ(B, "Local::Local(SecondLib)"); + + TO_0(Order); + TO_1(Order); } EXPECT_EQ(A, "Global::~Global"); EXPECT_EQ(B, "Local::~Local"); EXPECT_TRUE(FuncPtr<SetStrings>(DynamicLibrary::SearchForAddressOfSymbol( "SetStrings")) == nullptr); + + // Test unload/destruction ordering + EXPECT_EQ(Order.size(), 2UL); + EXPECT_EQ(Order.front(), "SecondLib"); + EXPECT_EQ(Order.back(), "PipSqueak"); } #else diff --git a/unittests/Support/DynamicLibrary/PipSqueak.cxx b/unittests/Support/DynamicLibrary/PipSqueak.cxx index d1cf7c042b72..79cf59255a4f 100644 --- a/unittests/Support/DynamicLibrary/PipSqueak.cxx +++ b/unittests/Support/DynamicLibrary/PipSqueak.cxx @@ -9,38 +9,40 @@ #include "PipSqueak.h" -#if defined(_WIN32) && !defined(__GNUC__) -// Disable warnings from inclusion of xlocale & exception -#pragma warning(push) -#pragma warning(disable: 4530) -#pragma warning(disable: 4577) -#include <string> -#pragma warning(pop) -#else -#include <string> -#endif - struct Global { std::string *Str; - Global() : Str(nullptr) {} + std::vector<std::string> *Vec; + Global() : Str(nullptr), Vec(nullptr) {} ~Global() { - if (Str) + if (Str) { + if (Vec) + Vec->push_back(*Str); *Str = "Global::~Global"; + } } }; +static Global Glb; + struct Local { std::string &Str; - Local(std::string &S) : Str(S) { Str = "Local::Local"; } + Local(std::string &S) : Str(S) { + Str = "Local::Local"; + if (Glb.Str && !Glb.Str->empty()) + Str += std::string("(") + *Glb.Str + std::string(")"); + } ~Local() { Str = "Local::~Local"; } }; -static Global Glb; extern "C" PIPSQUEAK_EXPORT void SetStrings(std::string &GStr, std::string &LStr) { - static Local Lcl(LStr); Glb.Str = &GStr; + static Local Lcl(LStr); +} + +extern "C" PIPSQUEAK_EXPORT void TestOrder(std::vector<std::string> &V) { + Glb.Vec = &V; } extern "C" PIPSQUEAK_EXPORT const char *TestA() { return "LibCall"; } diff --git a/unittests/Support/DynamicLibrary/PipSqueak.h b/unittests/Support/DynamicLibrary/PipSqueak.h index e6a859d60716..3e4f79a9a6f4 100644 --- a/unittests/Support/DynamicLibrary/PipSqueak.h +++ b/unittests/Support/DynamicLibrary/PipSqueak.h @@ -10,6 +10,19 @@ #ifndef LLVM_PIPSQUEAK_H #define LLVM_PIPSQUEAK_H +#if defined(_WIN32) && !defined(__GNUC__) +// Disable warnings from inclusion of xlocale & exception +#pragma warning(push) +#pragma warning(disable: 4530) +#pragma warning(disable: 4577) +#include <string> +#include <vector> +#pragma warning(pop) +#else +#include <string> +#include <vector> +#endif + #ifdef _WIN32 #define PIPSQUEAK_EXPORT __declspec(dllexport) #else diff --git a/unittests/Support/EndianStreamTest.cpp b/unittests/Support/EndianStreamTest.cpp index ea6c308c560a..48c5c3bc8175 100644 --- a/unittests/Support/EndianStreamTest.cpp +++ b/unittests/Support/EndianStreamTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/SmallString.h" #include "llvm/Support/EndianStream.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Support/DataTypes.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/Support/FileOutputBufferTest.cpp b/unittests/Support/FileOutputBufferTest.cpp index 53a2ae0aadde..5f20634d66c2 100644 --- a/unittests/Support/FileOutputBufferTest.cpp +++ b/unittests/Support/FileOutputBufferTest.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/FileOutputBuffer.h" #include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/FileOutputBuffer.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" diff --git a/unittests/Support/FormatVariadicTest.cpp b/unittests/Support/FormatVariadicTest.cpp index b0c843870afc..99b90b17ae44 100644 --- a/unittests/Support/FormatVariadicTest.cpp +++ b/unittests/Support/FormatVariadicTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/FormatAdapters.h" #include "llvm/Support/FormatVariadic.h" +#include "llvm/Support/FormatAdapters.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/Support/LEB128Test.cpp b/unittests/Support/LEB128Test.cpp index 061936df1d19..09db6dfdc593 100644 --- a/unittests/Support/LEB128Test.cpp +++ b/unittests/Support/LEB128Test.cpp @@ -7,10 +7,10 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" -#include "llvm/Support/DataTypes.h" #include "llvm/Support/LEB128.h" +#include "llvm/Support/DataTypes.h" #include "llvm/Support/raw_ostream.h" +#include "gtest/gtest.h" #include <string> using namespace llvm; diff --git a/unittests/Support/MD5Test.cpp b/unittests/Support/MD5Test.cpp index fa9372fde33f..8b151827a7bd 100644 --- a/unittests/Support/MD5Test.cpp +++ b/unittests/Support/MD5Test.cpp @@ -11,9 +11,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/MD5.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallString.h" -#include "llvm/Support/MD5.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/Support/MathExtrasTest.cpp b/unittests/Support/MathExtrasTest.cpp index f46d94e9e577..e26653b8a656 100644 --- a/unittests/Support/MathExtrasTest.cpp +++ b/unittests/Support/MathExtrasTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/Support/MathExtras.h" +#include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/Support/MemoryBufferTest.cpp b/unittests/Support/MemoryBufferTest.cpp index 0efa22c157d9..294581aeb928 100644 --- a/unittests/Support/MemoryBufferTest.cpp +++ b/unittests/Support/MemoryBufferTest.cpp @@ -11,9 +11,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FileUtilities.h" -#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include "gtest/gtest.h" diff --git a/unittests/Support/MemoryTest.cpp b/unittests/Support/MemoryTest.cpp index f439cb2af9b1..140219ffd1d6 100644 --- a/unittests/Support/MemoryTest.cpp +++ b/unittests/Support/MemoryTest.cpp @@ -360,6 +360,6 @@ unsigned MemoryFlags[] = { INSTANTIATE_TEST_CASE_P(AllocationTests, MappedMemoryTest, - ::testing::ValuesIn(MemoryFlags)); + ::testing::ValuesIn(MemoryFlags),); } // anonymous namespace diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp index a4bdcb5c79a2..3e474f33ca6d 100644 --- a/unittests/Support/Path.cpp +++ b/unittests/Support/Path.cpp @@ -8,9 +8,10 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Path.h" -#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Triple.h" +#include "llvm/BinaryFormat/Magic.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" @@ -919,86 +920,6 @@ TEST_F(FileSystemTest, Remove) { ASSERT_FALSE(fs::exists(BaseDir)); } -const char archive[] = "!<arch>\x0A"; -const char bitcode[] = "\xde\xc0\x17\x0b"; -const char coff_object[] = "\x00\x00......"; -const char coff_bigobj[] = "\x00\x00\xff\xff\x00\x02......" - "\xc7\xa1\xba\xd1\xee\xba\xa9\x4b\xaf\x20\xfa\xf6\x6a\xa4\xdc\xb8"; -const char coff_import_library[] = "\x00\x00\xff\xff...."; -const char elf_relocatable[] = { 0x7f, 'E', 'L', 'F', 1, 2, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1 }; -const char macho_universal_binary[] = "\xca\xfe\xba\xbe...\x00"; -const char macho_object[] = - "\xfe\xed\xfa\xce........\x00\x00\x00\x01............"; -const char macho_executable[] = - "\xfe\xed\xfa\xce........\x00\x00\x00\x02............"; -const char macho_fixed_virtual_memory_shared_lib[] = - "\xfe\xed\xfa\xce........\x00\x00\x00\x03............"; -const char macho_core[] = - "\xfe\xed\xfa\xce........\x00\x00\x00\x04............"; -const char macho_preload_executable[] = - "\xfe\xed\xfa\xce........\x00\x00\x00\x05............"; -const char macho_dynamically_linked_shared_lib[] = - "\xfe\xed\xfa\xce........\x00\x00\x00\x06............"; -const char macho_dynamic_linker[] = - "\xfe\xed\xfa\xce........\x00\x00\x00\x07............"; -const char macho_bundle[] = - "\xfe\xed\xfa\xce........\x00\x00\x00\x08............"; -const char macho_dsym_companion[] = - "\xfe\xed\xfa\xce........\x00\x00\x00\x0a............"; -const char macho_kext_bundle[] = - "\xfe\xed\xfa\xce........\x00\x00\x00\x0b............"; -const char windows_resource[] = "\x00\x00\x00\x00\x020\x00\x00\x00\xff"; -const char macho_dynamically_linked_shared_lib_stub[] = - "\xfe\xed\xfa\xce........\x00\x00\x00\x09............"; - -TEST_F(FileSystemTest, Magic) { - struct type { - const char *filename; - const char *magic_str; - size_t magic_str_len; - fs::file_magic magic; - } types[] = { -#define DEFINE(magic) \ - { #magic, magic, sizeof(magic), fs::file_magic::magic } - DEFINE(archive), - DEFINE(bitcode), - DEFINE(coff_object), - { "coff_bigobj", coff_bigobj, sizeof(coff_bigobj), fs::file_magic::coff_object }, - DEFINE(coff_import_library), - DEFINE(elf_relocatable), - DEFINE(macho_universal_binary), - DEFINE(macho_object), - DEFINE(macho_executable), - DEFINE(macho_fixed_virtual_memory_shared_lib), - DEFINE(macho_core), - DEFINE(macho_preload_executable), - DEFINE(macho_dynamically_linked_shared_lib), - DEFINE(macho_dynamic_linker), - DEFINE(macho_bundle), - DEFINE(macho_dynamically_linked_shared_lib_stub), - DEFINE(macho_dsym_companion), - DEFINE(macho_kext_bundle), - DEFINE(windows_resource) -#undef DEFINE - }; - - // Create some files filled with magic. - for (type *i = types, *e = types + (sizeof(types) / sizeof(type)); i != e; - ++i) { - SmallString<128> file_pathname(TestDirectory); - path::append(file_pathname, i->filename); - std::error_code EC; - raw_fd_ostream file(file_pathname, EC, sys::fs::F_None); - ASSERT_FALSE(file.has_error()); - StringRef magic(i->magic_str, i->magic_str_len); - file << magic; - file.close(); - EXPECT_EQ(i->magic, fs::identify_magic(magic)); - ASSERT_NO_ERROR(fs::remove(Twine(file_pathname))); - } -} - #ifdef LLVM_ON_WIN32 TEST_F(FileSystemTest, CarriageReturn) { SmallString<128> FilePathname(TestDirectory); diff --git a/unittests/Support/ProgramTest.cpp b/unittests/Support/ProgramTest.cpp index 3926ceb92b3e..f658980073da 100644 --- a/unittests/Support/ProgramTest.cpp +++ b/unittests/Support/ProgramTest.cpp @@ -7,11 +7,11 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/Program.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/ConvertUTF.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" -#include "llvm/Support/Program.h" #include "gtest/gtest.h" #include <stdlib.h> #if defined(__APPLE__) diff --git a/unittests/Support/SpecialCaseListTest.cpp b/unittests/Support/SpecialCaseListTest.cpp index e86eecb527bb..130848845e45 100644 --- a/unittests/Support/SpecialCaseListTest.cpp +++ b/unittests/Support/SpecialCaseListTest.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/SpecialCaseList.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/SpecialCaseList.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/Support/SwapByteOrderTest.cpp b/unittests/Support/SwapByteOrderTest.cpp index 4f2537c4d5de..474eac6bbb38 100644 --- a/unittests/Support/SwapByteOrderTest.cpp +++ b/unittests/Support/SwapByteOrderTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/Support/SwapByteOrder.h" +#include "gtest/gtest.h" #include <cstdlib> #include <ctime> using namespace llvm; diff --git a/unittests/Support/TarWriterTest.cpp b/unittests/Support/TarWriterTest.cpp index 84005de56c12..927c8ed9be14 100644 --- a/unittests/Support/TarWriterTest.cpp +++ b/unittests/Support/TarWriterTest.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/TarWriter.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/TarWriter.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/Support/TargetParserTest.cpp b/unittests/Support/TargetParserTest.cpp index 76d1917d537a..b252641f1a13 100644 --- a/unittests/Support/TargetParserTest.cpp +++ b/unittests/Support/TargetParserTest.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/TargetParser.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/ARMBuildAttributes.h" -#include "llvm/Support/TargetParser.h" #include "gtest/gtest.h" #include <string> diff --git a/unittests/Support/TrigramIndexTest.cpp b/unittests/Support/TrigramIndexTest.cpp index fb0ad1749bbd..df42c1efd8a0 100644 --- a/unittests/Support/TrigramIndexTest.cpp +++ b/unittests/Support/TrigramIndexTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/STLExtras.h" #include "llvm/Support/TrigramIndex.h" +#include "llvm/ADT/STLExtras.h" #include "gtest/gtest.h" #include <string> diff --git a/unittests/Support/YAMLIOTest.cpp b/unittests/Support/YAMLIOTest.cpp index 5a0280c8ca5b..21c8430f9588 100644 --- a/unittests/Support/YAMLIOTest.cpp +++ b/unittests/Support/YAMLIOTest.cpp @@ -14,7 +14,6 @@ #include "llvm/Support/YAMLTraits.h" #include "gtest/gtest.h" - using llvm::yaml::Input; using llvm::yaml::Output; using llvm::yaml::IO; diff --git a/unittests/Support/YAMLParserTest.cpp b/unittests/Support/YAMLParserTest.cpp index 3f12a53fd9c5..d411a286830b 100644 --- a/unittests/Support/YAMLParserTest.cpp +++ b/unittests/Support/YAMLParserTest.cpp @@ -7,11 +7,11 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/YAMLParser.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Casting.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" -#include "llvm/Support/YAMLParser.h" #include "gtest/gtest.h" namespace llvm { diff --git a/unittests/Support/formatted_raw_ostream_test.cpp b/unittests/Support/formatted_raw_ostream_test.cpp index 9bb804691337..2b8f06523beb 100644 --- a/unittests/Support/formatted_raw_ostream_test.cpp +++ b/unittests/Support/formatted_raw_ostream_test.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/FormattedStream.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Support/FormattedStream.h" #include "llvm/Support/raw_ostream.h" #include "gtest/gtest.h" diff --git a/unittests/Support/raw_ostream_test.cpp b/unittests/Support/raw_ostream_test.cpp index 777e555949ee..a7a5ce8dd6d4 100644 --- a/unittests/Support/raw_ostream_test.cpp +++ b/unittests/Support/raw_ostream_test.cpp @@ -7,11 +7,11 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" +#include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/Support/raw_pwrite_stream_test.cpp b/unittests/Support/raw_pwrite_stream_test.cpp index 08b2f90d6054..249780a8c829 100644 --- a/unittests/Support/raw_pwrite_stream_test.cpp +++ b/unittests/Support/raw_pwrite_stream_test.cpp @@ -7,11 +7,11 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/raw_ostream.h" +#include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/Support/raw_sha1_ostream_test.cpp b/unittests/Support/raw_sha1_ostream_test.cpp index 1bb4e2eb1d58..e176f3f7a19b 100644 --- a/unittests/Support/raw_sha1_ostream_test.cpp +++ b/unittests/Support/raw_sha1_ostream_test.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_sha1_ostream.h" +#include "gtest/gtest.h" #include <string> diff --git a/unittests/Target/AArch64/InstSizes.cpp b/unittests/Target/AArch64/InstSizes.cpp index 22b47c6852ab..c1fe7f22dc5a 100644 --- a/unittests/Target/AArch64/InstSizes.cpp +++ b/unittests/Target/AArch64/InstSizes.cpp @@ -21,7 +21,8 @@ std::unique_ptr<TargetMachine> createTargetMachine() { std::string Error; const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error); - assert(TheTarget && "Target not registered"); + if (!TheTarget) + report_fatal_error("Target not registered"); return std::unique_ptr<TargetMachine>( TheTarget->createTargetMachine(TT, CPU, FS, TargetOptions(), None, @@ -58,20 +59,25 @@ void runChecks( std::unique_ptr<MemoryBuffer> MBuffer = MemoryBuffer::getMemBuffer(MIRString); std::unique_ptr<MIRParser> MParser = createMIRParser(std::move(MBuffer), Context); - assert(MParser && "Couldn't create MIR parser"); + if (!MParser) + report_fatal_error("Couldn't create MIR parser"); - std::unique_ptr<Module> M = MParser->parseLLVMModule(); - assert(M && "Couldn't parse module"); + std::unique_ptr<Module> M = MParser->parseIRModule(); + if (!M) + report_fatal_error("Couldn't parse module"); M->setTargetTriple(TM->getTargetTriple().getTriple()); M->setDataLayout(TM->createDataLayout()); - auto F = M->getFunction("sizes"); - assert(F && "Couldn't find intended function"); - MachineModuleInfo MMI(TM); - MMI.setMachineFunctionInitializer(MParser.get()); - auto &MF = MMI.getMachineFunction(*F); + bool Res = MParser->parseMachineFunctions(*M, MMI); + if (Res) + report_fatal_error("Couldn't parse MIR functions"); + + auto F = M->getFunction("sizes"); + if (!F) + report_fatal_error("Couldn't find intended function"); + auto &MF = MMI.getOrCreateMachineFunction(*F); Checks(*II, MF); } diff --git a/unittests/Transforms/Scalar/LoopPassManagerTest.cpp b/unittests/Transforms/Scalar/LoopPassManagerTest.cpp index 227060f0a46e..dfc351c648b1 100644 --- a/unittests/Transforms/Scalar/LoopPassManagerTest.cpp +++ b/unittests/Transforms/Scalar/LoopPassManagerTest.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Transforms/Scalar/LoopPassManager.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/ScalarEvolution.h" @@ -19,7 +20,6 @@ #include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" #include "llvm/Support/SourceMgr.h" -#include "llvm/Transforms/Scalar/LoopPassManager.h" #include "gmock/gmock.h" #include "gtest/gtest.h" diff --git a/unittests/Transforms/Utils/CMakeLists.txt b/unittests/Transforms/Utils/CMakeLists.txt index 0fc19ef09fb0..475c365dddc4 100644 --- a/unittests/Transforms/Utils/CMakeLists.txt +++ b/unittests/Transforms/Utils/CMakeLists.txt @@ -11,5 +11,6 @@ add_llvm_unittest(UtilsTests FunctionComparator.cpp IntegerDivision.cpp Local.cpp + OrderedInstructions.cpp ValueMapperTest.cpp ) diff --git a/unittests/Transforms/Utils/FunctionComparator.cpp b/unittests/Transforms/Utils/FunctionComparator.cpp index ff68cd6224d7..26e20cd9112c 100644 --- a/unittests/Transforms/Utils/FunctionComparator.cpp +++ b/unittests/Transforms/Utils/FunctionComparator.cpp @@ -10,8 +10,8 @@ #include "llvm/IR/BasicBlock.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instructions.h" -#include "llvm/IR/Module.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" #include "gtest/gtest.h" using namespace llvm; diff --git a/unittests/Transforms/Utils/OrderedInstructions.cpp b/unittests/Transforms/Utils/OrderedInstructions.cpp new file mode 100644 index 000000000000..1d6df1722945 --- /dev/null +++ b/unittests/Transforms/Utils/OrderedInstructions.cpp @@ -0,0 +1,65 @@ +//===- OrderedInstructions.cpp - Unit tests for OrderedInstructions ------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Transforms/Utils/OrderedInstructions.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Dominators.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" +#include "gtest/gtest.h" + +using namespace llvm; + +/// Check intra-basicblock and inter-basicblock dominance using +/// OrderedInstruction. +TEST(OrderedInstructionsTest, DominanceTest) { + LLVMContext Ctx; + Module M("test", Ctx); + IRBuilder<> B(Ctx); + FunctionType *FTy = + FunctionType::get(Type::getVoidTy(Ctx), {B.getInt8PtrTy()}, false); + Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + + // Create the function as follow and check for dominance relation. + // + // test(): + // bbx: + // loadx; + // loady; + // bby: + // loadz; + // return; + // + // More specifically, check for loadx -> (dominates) loady, + // loady -> loadx and loady -> loadz. + // + // Create BBX with 2 loads. + BasicBlock *BBX = BasicBlock::Create(Ctx, "bbx", F); + B.SetInsertPoint(BBX); + Argument *PointerArg = &*F->arg_begin(); + LoadInst *LoadInstX = B.CreateLoad(PointerArg); + LoadInst *LoadInstY = B.CreateLoad(PointerArg); + + // Create BBY with 1 load. + BasicBlock *BBY = BasicBlock::Create(Ctx, "bby", F); + B.SetInsertPoint(BBY); + LoadInst *LoadInstZ = B.CreateLoad(PointerArg); + B.CreateRet(LoadInstZ); + std::unique_ptr<DominatorTree> DT(new DominatorTree(*F)); + OrderedInstructions OI(&*DT); + + // Intra-BB dominance test. + EXPECT_TRUE(OI.dominates(LoadInstX, LoadInstY)); + EXPECT_FALSE(OI.dominates(LoadInstY, LoadInstX)); + + // Inter-BB dominance test. + EXPECT_TRUE(OI.dominates(LoadInstY, LoadInstZ)); +} diff --git a/unittests/Transforms/Utils/ValueMapperTest.cpp b/unittests/Transforms/Utils/ValueMapperTest.cpp index 34b62bb930d9..94ac76bb076c 100644 --- a/unittests/Transforms/Utils/ValueMapperTest.cpp +++ b/unittests/Transforms/Utils/ValueMapperTest.cpp @@ -7,12 +7,12 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Transforms/Utils/ValueMapper.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Metadata.h" -#include "llvm/Transforms/Utils/ValueMapper.h" #include "gtest/gtest.h" using namespace llvm; |