diff options
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ADT/STLExtrasTest.cpp | 20 | ||||
-rw-r--r-- | unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp | 119 | ||||
-rw-r--r-- | unittests/CodeGen/LowLevelTypeTest.cpp | 78 | ||||
-rw-r--r-- | unittests/CodeGen/MachineInstrTest.cpp | 4 | ||||
-rw-r--r-- | unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp | 6 | ||||
-rw-r--r-- | unittests/IR/IRBuilderTest.cpp | 51 | ||||
-rw-r--r-- | unittests/Support/DynamicLibrary/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittests/Support/FileOutputBufferTest.cpp | 22 | ||||
-rw-r--r-- | unittests/Support/SpecialCaseListTest.cpp | 24 | ||||
-rw-r--r-- | unittests/tools/llvm-cfi-verify/CMakeLists.txt | 1 | ||||
-rw-r--r-- | unittests/tools/llvm-cfi-verify/FileAnalysis.cpp | 54 | ||||
-rw-r--r-- | unittests/tools/llvm-cfi-verify/GraphBuilder.cpp | 1 |
12 files changed, 256 insertions, 126 deletions
diff --git a/unittests/ADT/STLExtrasTest.cpp b/unittests/ADT/STLExtrasTest.cpp index 2e6eb6f413f6..68cd9f5d2c8b 100644 --- a/unittests/ADT/STLExtrasTest.cpp +++ b/unittests/ADT/STLExtrasTest.cpp @@ -252,12 +252,20 @@ TEST(STLExtrasTest, CountAdaptor) { EXPECT_EQ(3, count(v, 1)); EXPECT_EQ(2, count(v, 2)); EXPECT_EQ(1, count(v, 3)); - EXPECT_EQ(1, count(v, 4)); -} - -TEST(STLExtrasTest, ToVector) { - std::vector<char> v = {'a', 'b', 'c'}; - auto Enumerated = to_vector<4>(enumerate(v)); + EXPECT_EQ(1, count(v, 4));
+}
+
+TEST(STLExtrasTest, for_each) {
+ std::vector<int> v{ 0, 1, 2, 3, 4 };
+ int count = 0;
+
+ llvm::for_each(v, [&count](int) { ++count; });
+ EXPECT_EQ(5, count);
+}
+
+TEST(STLExtrasTest, ToVector) {
+ std::vector<char> v = {'a', 'b', 'c'};
+ auto Enumerated = to_vector<4>(enumerate(v));
ASSERT_EQ(3u, Enumerated.size()); for (size_t I = 0; I < v.size(); ++I) { EXPECT_EQ(I, Enumerated[I].index()); diff --git a/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp b/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp index 0e881759656d..550201ebdd16 100644 --- a/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp +++ b/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp @@ -49,66 +49,91 @@ TEST(LegalizerInfoTest, ScalarRISC) { using namespace TargetOpcode; LegalizerInfo L; // Typical RISCy set of operations based on AArch64. - L.setAction({G_ADD, LLT::scalar(8)}, LegalizerInfo::WidenScalar); - L.setAction({G_ADD, LLT::scalar(16)}, LegalizerInfo::WidenScalar); - L.setAction({G_ADD, LLT::scalar(32)}, LegalizerInfo::Legal); - L.setAction({G_ADD, LLT::scalar(64)}, LegalizerInfo::Legal); + for (unsigned Op : {G_ADD, G_SUB}) { + for (unsigned Size : {32, 64}) + L.setAction({Op, 0, LLT::scalar(Size)}, LegalizerInfo::Legal); + L.setLegalizeScalarToDifferentSizeStrategy( + Op, 0, LegalizerInfo::widenToLargerTypesAndNarrowToLargest); + } + L.computeTables(); - // Check we infer the correct types and actually do what we're told. - ASSERT_EQ(L.getAction({G_ADD, LLT::scalar(8)}), - std::make_pair(LegalizerInfo::WidenScalar, LLT::scalar(32))); - ASSERT_EQ(L.getAction({G_ADD, LLT::scalar(16)}), - std::make_pair(LegalizerInfo::WidenScalar, LLT::scalar(32))); - ASSERT_EQ(L.getAction({G_ADD, LLT::scalar(32)}), - std::make_pair(LegalizerInfo::Legal, LLT::scalar(32))); - ASSERT_EQ(L.getAction({G_ADD, LLT::scalar(64)}), - std::make_pair(LegalizerInfo::Legal, LLT::scalar(64))); - - // Make sure the default for over-sized types applies. - ASSERT_EQ(L.getAction({G_ADD, LLT::scalar(128)}), - std::make_pair(LegalizerInfo::NarrowScalar, LLT::scalar(64))); + for (unsigned opcode : {G_ADD, G_SUB}) { + // Check we infer the correct types and actually do what we're told. + ASSERT_EQ(L.getAction({opcode, LLT::scalar(8)}), + std::make_pair(LegalizerInfo::WidenScalar, LLT::scalar(32))); + ASSERT_EQ(L.getAction({opcode, LLT::scalar(16)}), + std::make_pair(LegalizerInfo::WidenScalar, LLT::scalar(32))); + ASSERT_EQ(L.getAction({opcode, LLT::scalar(32)}), + std::make_pair(LegalizerInfo::Legal, LLT::scalar(32))); + ASSERT_EQ(L.getAction({opcode, LLT::scalar(64)}), + std::make_pair(LegalizerInfo::Legal, LLT::scalar(64))); + + // Make sure the default for over-sized types applies. + ASSERT_EQ(L.getAction({opcode, LLT::scalar(128)}), + std::make_pair(LegalizerInfo::NarrowScalar, LLT::scalar(64))); + // Make sure we also handle unusual sizes + ASSERT_EQ(L.getAction({opcode, LLT::scalar(1)}), + std::make_pair(LegalizerInfo::WidenScalar, LLT::scalar(32))); + ASSERT_EQ(L.getAction({opcode, LLT::scalar(31)}), + std::make_pair(LegalizerInfo::WidenScalar, LLT::scalar(32))); + ASSERT_EQ(L.getAction({opcode, LLT::scalar(33)}), + std::make_pair(LegalizerInfo::WidenScalar, LLT::scalar(64))); + ASSERT_EQ(L.getAction({opcode, LLT::scalar(63)}), + std::make_pair(LegalizerInfo::WidenScalar, LLT::scalar(64))); + ASSERT_EQ(L.getAction({opcode, LLT::scalar(65)}), + std::make_pair(LegalizerInfo::NarrowScalar, LLT::scalar(64))); + } } TEST(LegalizerInfoTest, VectorRISC) { using namespace TargetOpcode; LegalizerInfo L; // Typical RISCy set of operations based on ARM. - L.setScalarInVectorAction(G_ADD, LLT::scalar(8), LegalizerInfo::Legal); - L.setScalarInVectorAction(G_ADD, LLT::scalar(16), LegalizerInfo::Legal); - L.setScalarInVectorAction(G_ADD, LLT::scalar(32), LegalizerInfo::Legal); - L.setAction({G_ADD, LLT::vector(8, 8)}, LegalizerInfo::Legal); L.setAction({G_ADD, LLT::vector(16, 8)}, LegalizerInfo::Legal); L.setAction({G_ADD, LLT::vector(4, 16)}, LegalizerInfo::Legal); L.setAction({G_ADD, LLT::vector(8, 16)}, LegalizerInfo::Legal); L.setAction({G_ADD, LLT::vector(2, 32)}, LegalizerInfo::Legal); L.setAction({G_ADD, LLT::vector(4, 32)}, LegalizerInfo::Legal); + + L.setLegalizeVectorElementToDifferentSizeStrategy( + G_ADD, 0, LegalizerInfo::widenToLargerTypesUnsupportedOtherwise); + + L.setAction({G_ADD, 0, LLT::scalar(32)}, LegalizerInfo::Legal); + L.computeTables(); // Check we infer the correct types and actually do what we're told for some // simple cases. - ASSERT_EQ(L.getAction({G_ADD, LLT::vector(2, 8)}), - std::make_pair(LegalizerInfo::MoreElements, LLT::vector(8, 8))); ASSERT_EQ(L.getAction({G_ADD, LLT::vector(8, 8)}), std::make_pair(LegalizerInfo::Legal, LLT::vector(8, 8))); - ASSERT_EQ( - L.getAction({G_ADD, LLT::vector(8, 32)}), - std::make_pair(LegalizerInfo::FewerElements, LLT::vector(4, 32))); + ASSERT_EQ(L.getAction({G_ADD, LLT::vector(8, 7)}), + std::make_pair(LegalizerInfo::WidenScalar, LLT::vector(8, 8))); + ASSERT_EQ(L.getAction({G_ADD, LLT::vector(2, 8)}), + std::make_pair(LegalizerInfo::MoreElements, LLT::vector(8, 8))); + ASSERT_EQ(L.getAction({G_ADD, LLT::vector(8, 32)}), + std::make_pair(LegalizerInfo::FewerElements, LLT::vector(4, 32))); + // Check a few non-power-of-2 sizes: + ASSERT_EQ(L.getAction({G_ADD, LLT::vector(3, 3)}), + std::make_pair(LegalizerInfo::WidenScalar, LLT::vector(3, 8))); + ASSERT_EQ(L.getAction({G_ADD, LLT::vector(3, 8)}), + std::make_pair(LegalizerInfo::MoreElements, LLT::vector(8, 8))); } TEST(LegalizerInfoTest, MultipleTypes) { using namespace TargetOpcode; LegalizerInfo L; LLT p0 = LLT::pointer(0, 64); - LLT s32 = LLT::scalar(32); LLT s64 = LLT::scalar(64); // Typical RISCy set of operations based on AArch64. L.setAction({G_PTRTOINT, 0, s64}, LegalizerInfo::Legal); L.setAction({G_PTRTOINT, 1, p0}, LegalizerInfo::Legal); - L.setAction({G_PTRTOINT, 0, s32}, LegalizerInfo::WidenScalar); + L.setLegalizeScalarToDifferentSizeStrategy( + G_PTRTOINT, 0, LegalizerInfo::widenToLargerTypesAndNarrowToLargest); + L.computeTables(); // Check we infer the correct types and actually do what we're told. @@ -116,16 +141,21 @@ TEST(LegalizerInfoTest, MultipleTypes) { std::make_pair(LegalizerInfo::Legal, s64)); ASSERT_EQ(L.getAction({G_PTRTOINT, 1, p0}), std::make_pair(LegalizerInfo::Legal, p0)); + // Make sure we also handle unusual sizes + ASSERT_EQ(L.getAction({G_PTRTOINT, 0, LLT::scalar(65)}), + std::make_pair(LegalizerInfo::NarrowScalar, s64)); + ASSERT_EQ(L.getAction({G_PTRTOINT, 1, LLT::pointer(0, 32)}), + std::make_pair(LegalizerInfo::Unsupported, LLT::pointer(0, 32))); } TEST(LegalizerInfoTest, MultipleSteps) { using namespace TargetOpcode; LegalizerInfo L; - LLT s16 = LLT::scalar(16); LLT s32 = LLT::scalar(32); LLT s64 = LLT::scalar(64); - L.setAction({G_UREM, 0, s16}, LegalizerInfo::WidenScalar); + L.setLegalizeScalarToDifferentSizeStrategy( + G_UREM, 0, LegalizerInfo::widenToLargerTypesUnsupportedOtherwise); L.setAction({G_UREM, 0, s32}, LegalizerInfo::Lower); L.setAction({G_UREM, 0, s64}, LegalizerInfo::Lower); @@ -136,4 +166,33 @@ TEST(LegalizerInfoTest, MultipleSteps) { ASSERT_EQ(L.getAction({G_UREM, LLT::scalar(32)}), std::make_pair(LegalizerInfo::Lower, LLT::scalar(32))); } + +TEST(LegalizerInfoTest, SizeChangeStrategy) { + using namespace TargetOpcode; + LegalizerInfo L; + for (unsigned Size : {1, 8, 16, 32}) + L.setAction({G_UREM, 0, LLT::scalar(Size)}, LegalizerInfo::Legal); + + L.setLegalizeScalarToDifferentSizeStrategy( + G_UREM, 0, LegalizerInfo::widenToLargerTypesUnsupportedOtherwise); + L.computeTables(); + + // Check we infer the correct types and actually do what we're told. + for (unsigned Size : {1, 8, 16, 32}) { + ASSERT_EQ(L.getAction({G_UREM, LLT::scalar(Size)}), + std::make_pair(LegalizerInfo::Legal, LLT::scalar(Size))); + } + ASSERT_EQ(L.getAction({G_UREM, LLT::scalar(2)}), + std::make_pair(LegalizerInfo::WidenScalar, LLT::scalar(8))); + ASSERT_EQ(L.getAction({G_UREM, LLT::scalar(7)}), + std::make_pair(LegalizerInfo::WidenScalar, LLT::scalar(8))); + ASSERT_EQ(L.getAction({G_UREM, LLT::scalar(9)}), + std::make_pair(LegalizerInfo::WidenScalar, LLT::scalar(16))); + ASSERT_EQ(L.getAction({G_UREM, LLT::scalar(17)}), + std::make_pair(LegalizerInfo::WidenScalar, LLT::scalar(32))); + ASSERT_EQ(L.getAction({G_UREM, LLT::scalar(31)}), + std::make_pair(LegalizerInfo::WidenScalar, LLT::scalar(32))); + ASSERT_EQ(L.getAction({G_UREM, LLT::scalar(33)}), + std::make_pair(LegalizerInfo::Unsupported, LLT::scalar(33))); +} } diff --git a/unittests/CodeGen/LowLevelTypeTest.cpp b/unittests/CodeGen/LowLevelTypeTest.cpp index 115554642907..a4765d998562 100644 --- a/unittests/CodeGen/LowLevelTypeTest.cpp +++ b/unittests/CodeGen/LowLevelTypeTest.cpp @@ -36,36 +36,22 @@ TEST(LowLevelTypeTest, Scalar) { for (unsigned S : {1U, 17U, 32U, 64U, 0xfffffU}) { const LLT Ty = LLT::scalar(S); - const LLT HalfTy = (S % 2) == 0 ? Ty.halfScalarSize() : Ty; - const LLT DoubleTy = Ty.doubleScalarSize(); // Test kind. - for (const LLT TestTy : {Ty, HalfTy, DoubleTy}) { - ASSERT_TRUE(TestTy.isValid()); - ASSERT_TRUE(TestTy.isScalar()); + ASSERT_TRUE(Ty.isValid()); + ASSERT_TRUE(Ty.isScalar()); - ASSERT_FALSE(TestTy.isPointer()); - ASSERT_FALSE(TestTy.isVector()); - } + ASSERT_FALSE(Ty.isPointer()); + ASSERT_FALSE(Ty.isVector()); // Test sizes. EXPECT_EQ(S, Ty.getSizeInBits()); EXPECT_EQ(S, Ty.getScalarSizeInBits()); - EXPECT_EQ(S*2, DoubleTy.getSizeInBits()); - EXPECT_EQ(S*2, DoubleTy.getScalarSizeInBits()); - - if ((S % 2) == 0) { - EXPECT_EQ(S/2, HalfTy.getSizeInBits()); - EXPECT_EQ(S/2, HalfTy.getScalarSizeInBits()); - } - // Test equality operators. EXPECT_TRUE(Ty == Ty); EXPECT_FALSE(Ty != Ty); - EXPECT_NE(Ty, DoubleTy); - // Test Type->LLT conversion. Type *IRTy = IntegerType::get(C, S); EXPECT_EQ(Ty, getLLTForType(*IRTy, DL)); @@ -90,62 +76,18 @@ TEST(LowLevelTypeTest, Vector) { // Test getElementType(). EXPECT_EQ(STy, VTy.getElementType()); - const LLT HalfSzTy = ((S % 2) == 0) ? VTy.halfScalarSize() : VTy; - const LLT DoubleSzTy = VTy.doubleScalarSize(); - - // halfElements requires an even number of elements. - const LLT HalfEltIfEvenTy = ((Elts % 2) == 0) ? VTy.halfElements() : VTy; - const LLT DoubleEltTy = VTy.doubleElements(); - // Test kind. - for (const LLT TestTy : {VTy, HalfSzTy, DoubleSzTy, DoubleEltTy}) { - ASSERT_TRUE(TestTy.isValid()); - ASSERT_TRUE(TestTy.isVector()); - - ASSERT_FALSE(TestTy.isScalar()); - ASSERT_FALSE(TestTy.isPointer()); - } - - // Test halving elements to a scalar. - { - ASSERT_TRUE(HalfEltIfEvenTy.isValid()); - ASSERT_FALSE(HalfEltIfEvenTy.isPointer()); - if (Elts > 2) { - ASSERT_TRUE(HalfEltIfEvenTy.isVector()); - } else { - ASSERT_FALSE(HalfEltIfEvenTy.isVector()); - EXPECT_EQ(STy, HalfEltIfEvenTy); - } - } + ASSERT_TRUE(VTy.isValid()); + ASSERT_TRUE(VTy.isVector()); + ASSERT_FALSE(VTy.isScalar()); + ASSERT_FALSE(VTy.isPointer()); // Test sizes. EXPECT_EQ(S * Elts, VTy.getSizeInBits()); EXPECT_EQ(S, VTy.getScalarSizeInBits()); EXPECT_EQ(Elts, VTy.getNumElements()); - if ((S % 2) == 0) { - EXPECT_EQ((S / 2) * Elts, HalfSzTy.getSizeInBits()); - EXPECT_EQ(S / 2, HalfSzTy.getScalarSizeInBits()); - EXPECT_EQ(Elts, HalfSzTy.getNumElements()); - } - - EXPECT_EQ((S * 2) * Elts, DoubleSzTy.getSizeInBits()); - EXPECT_EQ(S * 2, DoubleSzTy.getScalarSizeInBits()); - EXPECT_EQ(Elts, DoubleSzTy.getNumElements()); - - if ((Elts % 2) == 0) { - EXPECT_EQ(S * (Elts / 2), HalfEltIfEvenTy.getSizeInBits()); - EXPECT_EQ(S, HalfEltIfEvenTy.getScalarSizeInBits()); - if (Elts > 2) { - EXPECT_EQ(Elts / 2, HalfEltIfEvenTy.getNumElements()); - } - } - - EXPECT_EQ(S * (Elts * 2), DoubleEltTy.getSizeInBits()); - EXPECT_EQ(S, DoubleEltTy.getScalarSizeInBits()); - EXPECT_EQ(Elts * 2, DoubleEltTy.getNumElements()); - // Test equality operators. EXPECT_TRUE(VTy == VTy); EXPECT_FALSE(VTy != VTy); @@ -153,10 +95,6 @@ TEST(LowLevelTypeTest, Vector) { // Test inequality operators on.. // ..different kind. EXPECT_NE(VTy, STy); - // ..different #elts. - EXPECT_NE(VTy, DoubleEltTy); - // ..different scalar size. - EXPECT_NE(VTy, DoubleSzTy); // Test Type->LLT conversion. Type *IRSTy = IntegerType::get(C, S); diff --git a/unittests/CodeGen/MachineInstrTest.cpp b/unittests/CodeGen/MachineInstrTest.cpp index 89041e2ab22b..808890e175da 100644 --- a/unittests/CodeGen/MachineInstrTest.cpp +++ b/unittests/CodeGen/MachineInstrTest.cpp @@ -10,10 +10,10 @@ #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineModuleInfo.h" +#include "llvm/CodeGen/TargetFrameLowering.h" +#include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" -#include "llvm/Target/TargetFrameLowering.h" -#include "llvm/Target/TargetInstrInfo.h" #include "llvm/Target/TargetLowering.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" diff --git a/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp b/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp index f283ac0961cc..14550b9082b4 100644 --- a/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp +++ b/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp @@ -99,7 +99,7 @@ DWARFFormValue createDataXFormValue(dwarf::Form Form, RawTypeT Value) { DWARFFormValue Result(Form); DWARFDataExtractor Data(StringRef(Raw, sizeof(RawTypeT)), sys::IsLittleEndianHost, sizeof(void *)); - Result.extractValue(Data, &Offset, nullptr); + Result.extractValue(Data, &Offset, {0, 0, dwarf::DwarfFormat::DWARF32}); return Result; } @@ -110,7 +110,7 @@ DWARFFormValue createULEBFormValue(uint64_t Value) { uint32_t Offset = 0; DWARFFormValue Result(DW_FORM_udata); DWARFDataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void *)); - Result.extractValue(Data, &Offset, nullptr); + Result.extractValue(Data, &Offset, {0, 0, dwarf::DwarfFormat::DWARF32}); return Result; } @@ -121,7 +121,7 @@ DWARFFormValue createSLEBFormValue(int64_t Value) { uint32_t Offset = 0; DWARFFormValue Result(DW_FORM_sdata); DWARFDataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void *)); - Result.extractValue(Data, &Offset, nullptr); + Result.extractValue(Data, &Offset, {0, 0, dwarf::DwarfFormat::DWARF32}); return Result; } diff --git a/unittests/IR/IRBuilderTest.cpp b/unittests/IR/IRBuilderTest.cpp index d361107cc0d2..bb74756d81a9 100644 --- a/unittests/IR/IRBuilderTest.cpp +++ b/unittests/IR/IRBuilderTest.cpp @@ -144,17 +144,40 @@ TEST_F(IRBuilderTest, FastMathFlags) { FastMathFlags FMF; Builder.setFastMathFlags(FMF); + // By default, no flags are set. F = Builder.CreateFAdd(F, F); EXPECT_FALSE(Builder.getFastMathFlags().any()); + ASSERT_TRUE(isa<Instruction>(F)); + FAdd = cast<Instruction>(F); + EXPECT_FALSE(FAdd->hasNoNaNs()); + EXPECT_FALSE(FAdd->hasNoInfs()); + EXPECT_FALSE(FAdd->hasNoSignedZeros()); + EXPECT_FALSE(FAdd->hasAllowReciprocal()); + EXPECT_FALSE(FAdd->hasAllowContract()); + EXPECT_FALSE(FAdd->hasAllowReassoc()); + EXPECT_FALSE(FAdd->hasApproxFunc()); - FMF.setUnsafeAlgebra(); + // Set all flags in the instruction. + FAdd->setFast(true); + EXPECT_TRUE(FAdd->hasNoNaNs()); + EXPECT_TRUE(FAdd->hasNoInfs()); + EXPECT_TRUE(FAdd->hasNoSignedZeros()); + EXPECT_TRUE(FAdd->hasAllowReciprocal()); + EXPECT_TRUE(FAdd->hasAllowContract()); + EXPECT_TRUE(FAdd->hasAllowReassoc()); + EXPECT_TRUE(FAdd->hasApproxFunc()); + + // All flags are set in the builder. + FMF.setFast(); Builder.setFastMathFlags(FMF); F = Builder.CreateFAdd(F, F); EXPECT_TRUE(Builder.getFastMathFlags().any()); + EXPECT_TRUE(Builder.getFastMathFlags().all()); ASSERT_TRUE(isa<Instruction>(F)); FAdd = cast<Instruction>(F); EXPECT_TRUE(FAdd->hasNoNaNs()); + EXPECT_TRUE(FAdd->isFast()); // Now, try it with CreateBinOp F = Builder.CreateBinOp(Instruction::FAdd, F, F); @@ -162,21 +185,23 @@ TEST_F(IRBuilderTest, FastMathFlags) { ASSERT_TRUE(isa<Instruction>(F)); FAdd = cast<Instruction>(F); EXPECT_TRUE(FAdd->hasNoNaNs()); + EXPECT_TRUE(FAdd->isFast()); F = Builder.CreateFDiv(F, F); - EXPECT_TRUE(Builder.getFastMathFlags().any()); - EXPECT_TRUE(Builder.getFastMathFlags().UnsafeAlgebra); + EXPECT_TRUE(Builder.getFastMathFlags().all()); ASSERT_TRUE(isa<Instruction>(F)); FDiv = cast<Instruction>(F); EXPECT_TRUE(FDiv->hasAllowReciprocal()); + // Clear all FMF in the builder. Builder.clearFastMathFlags(); F = Builder.CreateFDiv(F, F); ASSERT_TRUE(isa<Instruction>(F)); FDiv = cast<Instruction>(F); EXPECT_FALSE(FDiv->hasAllowReciprocal()); - + + // Try individual flags. FMF.clear(); FMF.setAllowReciprocal(); Builder.setFastMathFlags(FMF); @@ -225,7 +250,25 @@ TEST_F(IRBuilderTest, FastMathFlags) { FAdd = cast<Instruction>(FC); EXPECT_TRUE(FAdd->hasAllowContract()); + FMF.setApproxFunc(); + Builder.clearFastMathFlags(); + Builder.setFastMathFlags(FMF); + // Now 'aml' and 'contract' are set. + F = Builder.CreateFMul(F, F); + FAdd = cast<Instruction>(F); + EXPECT_TRUE(FAdd->hasApproxFunc()); + EXPECT_TRUE(FAdd->hasAllowContract()); + EXPECT_FALSE(FAdd->hasAllowReassoc()); + + FMF.setAllowReassoc(); Builder.clearFastMathFlags(); + Builder.setFastMathFlags(FMF); + // Now 'aml' and 'contract' and 'reassoc' are set. + F = Builder.CreateFMul(F, F); + FAdd = cast<Instruction>(F); + EXPECT_TRUE(FAdd->hasApproxFunc()); + EXPECT_TRUE(FAdd->hasAllowContract()); + EXPECT_TRUE(FAdd->hasAllowReassoc()); // Test a call with FMF. auto CalleeTy = FunctionType::get(Type::getFloatTy(Ctx), diff --git a/unittests/Support/DynamicLibrary/CMakeLists.txt b/unittests/Support/DynamicLibrary/CMakeLists.txt index b5844381362e..9355979221aa 100644 --- a/unittests/Support/DynamicLibrary/CMakeLists.txt +++ b/unittests/Support/DynamicLibrary/CMakeLists.txt @@ -1,6 +1,7 @@ set(LLVM_LINK_COMPONENTS Support) add_library(DynamicLibraryLib STATIC ExportedFuncs.cxx) +set_target_properties(DynamicLibraryLib PROPERTIES FOLDER "Tests") add_llvm_unittest(DynamicLibraryTests DynamicLibraryTest.cpp) target_link_libraries(DynamicLibraryTests DynamicLibraryLib) @@ -8,6 +9,7 @@ export_executable_symbols(DynamicLibraryTests) function(dynlib_add_module NAME) add_library(${NAME} SHARED PipSqueak.cxx) + set_target_properties(${NAME} PROPERTIES FOLDER "Tests") set_output_directory(${NAME} BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR} diff --git a/unittests/Support/FileOutputBufferTest.cpp b/unittests/Support/FileOutputBufferTest.cpp index 640af46844b1..e7f1fd765bde 100644 --- a/unittests/Support/FileOutputBufferTest.cpp +++ b/unittests/Support/FileOutputBufferTest.cpp @@ -42,16 +42,16 @@ TEST(FileOutputBuffer, Test) { SmallString<128> File1(TestDirectory); File1.append("/file1"); { - ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr = + Expected<std::unique_ptr<FileOutputBuffer>> BufferOrErr = FileOutputBuffer::create(File1, 8192); - ASSERT_NO_ERROR(BufferOrErr.getError()); + ASSERT_NO_ERROR(errorToErrorCode(BufferOrErr.takeError())); std::unique_ptr<FileOutputBuffer> &Buffer = *BufferOrErr; // Start buffer with special header. memcpy(Buffer->getBufferStart(), "AABBCCDDEEFFGGHHIIJJ", 20); // Write to end of buffer to verify it is writable. memcpy(Buffer->getBufferEnd() - 20, "AABBCCDDEEFFGGHHIIJJ", 20); // Commit buffer. - ASSERT_NO_ERROR(Buffer->commit()); + ASSERT_NO_ERROR(errorToErrorCode(Buffer->commit())); } // Verify file is correct size. @@ -64,9 +64,9 @@ TEST(FileOutputBuffer, Test) { SmallString<128> File2(TestDirectory); File2.append("/file2"); { - ErrorOr<std::unique_ptr<FileOutputBuffer>> Buffer2OrErr = + Expected<std::unique_ptr<FileOutputBuffer>> Buffer2OrErr = FileOutputBuffer::create(File2, 8192); - ASSERT_NO_ERROR(Buffer2OrErr.getError()); + ASSERT_NO_ERROR(errorToErrorCode(Buffer2OrErr.takeError())); std::unique_ptr<FileOutputBuffer> &Buffer2 = *Buffer2OrErr; // Fill buffer with special header. memcpy(Buffer2->getBufferStart(), "AABBCCDDEEFFGGHHIIJJ", 20); @@ -81,15 +81,15 @@ TEST(FileOutputBuffer, Test) { SmallString<128> File3(TestDirectory); File3.append("/file3"); { - ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr = + Expected<std::unique_ptr<FileOutputBuffer>> BufferOrErr = FileOutputBuffer::create(File3, 8192000); - ASSERT_NO_ERROR(BufferOrErr.getError()); + ASSERT_NO_ERROR(errorToErrorCode(BufferOrErr.takeError())); std::unique_ptr<FileOutputBuffer> &Buffer = *BufferOrErr; // Start buffer with special header. memcpy(Buffer->getBufferStart(), "AABBCCDDEEFFGGHHIIJJ", 20); // Write to end of buffer to verify it is writable. memcpy(Buffer->getBufferEnd() - 20, "AABBCCDDEEFFGGHHIIJJ", 20); - ASSERT_NO_ERROR(Buffer->commit()); + ASSERT_NO_ERROR(errorToErrorCode(Buffer->commit())); } // Verify file is correct size. @@ -102,14 +102,14 @@ TEST(FileOutputBuffer, Test) { SmallString<128> File4(TestDirectory); File4.append("/file4"); { - ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr = + Expected<std::unique_ptr<FileOutputBuffer>> BufferOrErr = FileOutputBuffer::create(File4, 8192, FileOutputBuffer::F_executable); - ASSERT_NO_ERROR(BufferOrErr.getError()); + ASSERT_NO_ERROR(errorToErrorCode(BufferOrErr.takeError())); std::unique_ptr<FileOutputBuffer> &Buffer = *BufferOrErr; // Start buffer with special header. memcpy(Buffer->getBufferStart(), "AABBCCDDEEFFGGHHIIJJ", 20); // Commit buffer. - ASSERT_NO_ERROR(Buffer->commit()); + ASSERT_NO_ERROR(errorToErrorCode(Buffer->commit())); } // Verify file exists and is executable. fs::file_status Status; diff --git a/unittests/Support/SpecialCaseListTest.cpp b/unittests/Support/SpecialCaseListTest.cpp index 9e1223b54976..060703e102fc 100644 --- a/unittests/Support/SpecialCaseListTest.cpp +++ b/unittests/Support/SpecialCaseListTest.cpp @@ -58,6 +58,30 @@ TEST_F(SpecialCaseListTest, Basic) { EXPECT_FALSE(SCL->inSection("", "src", "hi")); EXPECT_FALSE(SCL->inSection("", "fun", "hello")); EXPECT_FALSE(SCL->inSection("", "src", "hello", "category")); + + EXPECT_EQ(3u, SCL->inSectionBlame("", "src", "hello")); + EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "bye")); + EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "hi", "category")); + EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "zzzz", "category")); + EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hi")); + EXPECT_EQ(0u, SCL->inSectionBlame("", "fun", "hello")); + EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hello", "category")); +} + +TEST_F(SpecialCaseListTest, CorrectErrorLineNumberWithBlankLine) { + std::string Error; + EXPECT_EQ(nullptr, makeSpecialCaseList("# This is a comment.\n" + "\n" + "[not valid\n", + Error)); + EXPECT_TRUE( + ((StringRef)Error).startswith("malformed section header on line 3:")); + + EXPECT_EQ(nullptr, makeSpecialCaseList("\n\n\n" + "[not valid\n", + Error)); + EXPECT_TRUE( + ((StringRef)Error).startswith("malformed section header on line 4:")); } TEST_F(SpecialCaseListTest, SectionRegexErrorHandling) { diff --git a/unittests/tools/llvm-cfi-verify/CMakeLists.txt b/unittests/tools/llvm-cfi-verify/CMakeLists.txt index ad3266c27776..adb7a55327ae 100644 --- a/unittests/tools/llvm-cfi-verify/CMakeLists.txt +++ b/unittests/tools/llvm-cfi-verify/CMakeLists.txt @@ -8,6 +8,7 @@ set(LLVM_LINK_COMPONENTS MCParser Object Support + Symbolize ) add_llvm_unittest(CFIVerifyTests diff --git a/unittests/tools/llvm-cfi-verify/FileAnalysis.cpp b/unittests/tools/llvm-cfi-verify/FileAnalysis.cpp index 0df468e8995c..00346ab5a14e 100644 --- a/unittests/tools/llvm-cfi-verify/FileAnalysis.cpp +++ b/unittests/tools/llvm-cfi-verify/FileAnalysis.cpp @@ -64,6 +64,7 @@ public: class BasicFileAnalysisTest : public ::testing::Test { protected: virtual void SetUp() { + IgnoreDWARFFlag = true; SuccessfullyInitialised = true; if (auto Err = Analysis.initialiseDisassemblyMembers()) { handleAllErrors(std::move(Err), [&](const UnsupportedDisassembly &E) { @@ -650,7 +651,60 @@ TEST_F(BasicFileAnalysisTest, CFIProtectionComplexExample) { 0x0f, 0x0b, // 22: ud2 }, 0xDEADBEEF); + uint64_t PrevSearchLengthForUndef = SearchLengthForUndef; + SearchLengthForUndef = 5; EXPECT_FALSE(Analysis.isIndirectInstructionCFIProtected(0xDEADBEEF + 9)); + SearchLengthForUndef = PrevSearchLengthForUndef; +} + +TEST_F(BasicFileAnalysisTest, UndefSearchLengthOneTest) { + Analysis.parseSectionContents( + { + 0x77, 0x0d, // 0x688118: ja 0x688127 [+12] + 0x48, 0x89, 0xdf, // 0x68811a: mov %rbx, %rdi + 0xff, 0xd0, // 0x68811d: callq *%rax + 0x48, 0x89, 0xdf, // 0x68811f: mov %rbx, %rdi + 0xe8, 0x09, 0x00, 0x00, 0x00, // 0x688122: callq 0x688130 + 0x0f, 0x0b, // 0x688127: ud2 + }, + 0x688118); + uint64_t PrevSearchLengthForUndef = SearchLengthForUndef; + SearchLengthForUndef = 1; + EXPECT_TRUE(Analysis.isIndirectInstructionCFIProtected(0x68811d)); + SearchLengthForUndef = PrevSearchLengthForUndef; +} + +TEST_F(BasicFileAnalysisTest, UndefSearchLengthOneTestFarAway) { + Analysis.parseSectionContents( + { + 0x74, 0x73, // 0x7759eb: je 0x775a60 + 0xe9, 0x1c, 0x04, 0x00, 0x00, 0x00, // 0x7759ed: jmpq 0x775e0e + }, + 0x7759eb); + + Analysis.parseSectionContents( + { + 0x0f, 0x85, 0xb2, 0x03, 0x00, 0x00, // 0x775a56: jne 0x775e0e + 0x48, 0x83, 0xc3, 0xf4, // 0x775a5c: add $0xfffffffffffffff4,%rbx + 0x48, 0x8b, 0x7c, 0x24, 0x10, // 0x775a60: mov 0x10(%rsp),%rdi + 0x48, 0x89, 0xde, // 0x775a65: mov %rbx,%rsi + 0xff, 0xd1, // 0x775a68: callq *%rcx + }, + 0x775a56); + + Analysis.parseSectionContents( + { + 0x0f, 0x0b, // 0x775e0e: ud2 + }, + 0x775e0e); + uint64_t PrevSearchLengthForUndef = SearchLengthForUndef; + SearchLengthForUndef = 1; + EXPECT_FALSE(Analysis.isIndirectInstructionCFIProtected(0x775a68)); + SearchLengthForUndef = 2; + EXPECT_TRUE(Analysis.isIndirectInstructionCFIProtected(0x775a68)); + SearchLengthForUndef = 3; + EXPECT_TRUE(Analysis.isIndirectInstructionCFIProtected(0x775a68)); + SearchLengthForUndef = PrevSearchLengthForUndef; } } // anonymous namespace diff --git a/unittests/tools/llvm-cfi-verify/GraphBuilder.cpp b/unittests/tools/llvm-cfi-verify/GraphBuilder.cpp index b200677dd09b..a7d09b547814 100644 --- a/unittests/tools/llvm-cfi-verify/GraphBuilder.cpp +++ b/unittests/tools/llvm-cfi-verify/GraphBuilder.cpp @@ -126,6 +126,7 @@ public: class BasicGraphBuilderTest : public ::testing::Test { protected: virtual void SetUp() { + IgnoreDWARFFlag = true; SuccessfullyInitialised = true; if (auto Err = Analysis.initialiseDisassemblyMembers()) { handleAllErrors(std::move(Err), [&](const UnsupportedDisassembly &E) { |