summaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2016-01-06 20:01:02 +0000
committerdim <dim@FreeBSD.org>2016-01-06 20:01:02 +0000
commitff2ba393a56d9d99dcb76ceada542233db28af9a (patch)
treeea70b740d40cffe568a990c7aecd1acb5f83f786 /unittests
parent7c35321d839f2c4d0fc8510bfbd8954b07908b76 (diff)
downloadFreeBSD-src-ff2ba393a56d9d99dcb76ceada542233db28af9a.zip
FreeBSD-src-ff2ba393a56d9d99dcb76ceada542233db28af9a.tar.gz
Vendor import of llvm trunk r256945:
https://llvm.org/svn/llvm-project/llvm/trunk@256945
Diffstat (limited to 'unittests')
-rw-r--r--unittests/IR/IRBuilderTest.cpp10
-rw-r--r--unittests/IR/MetadataTest.cpp14
-rw-r--r--unittests/IR/TypesTest.cpp14
-rw-r--r--unittests/ProfileData/InstrProfTest.cpp74
-rw-r--r--unittests/Support/YAMLParserTest.cpp72
5 files changed, 177 insertions, 7 deletions
diff --git a/unittests/IR/IRBuilderTest.cpp b/unittests/IR/IRBuilderTest.cpp
index e0da018..82565cc 100644
--- a/unittests/IR/IRBuilderTest.cpp
+++ b/unittests/IR/IRBuilderTest.cpp
@@ -217,6 +217,11 @@ TEST_F(IRBuilderTest, FastMathFlags) {
FCall = Builder.CreateCall(Callee, None);
EXPECT_FALSE(FCall->hasNoNaNs());
+ Value *V =
+ Function::Create(CalleeTy, Function::ExternalLinkage, "", M.get());
+ FCall = Builder.CreateCall(V, None);
+ EXPECT_FALSE(FCall->hasNoNaNs());
+
FMF.clear();
FMF.setNoNaNs();
Builder.SetFastMathFlags(FMF);
@@ -226,6 +231,11 @@ TEST_F(IRBuilderTest, FastMathFlags) {
EXPECT_TRUE(Builder.getFastMathFlags().NoNaNs);
EXPECT_TRUE(FCall->hasNoNaNs());
+ FCall = Builder.CreateCall(V, None);
+ EXPECT_TRUE(Builder.getFastMathFlags().any());
+ EXPECT_TRUE(Builder.getFastMathFlags().NoNaNs);
+ EXPECT_TRUE(FCall->hasNoNaNs());
+
Builder.clearFastMathFlags();
// To test a copy, make sure that a '0' and a '1' change state.
diff --git a/unittests/IR/MetadataTest.cpp b/unittests/IR/MetadataTest.cpp
index 257ab72..a745b23 100644
--- a/unittests/IR/MetadataTest.cpp
+++ b/unittests/IR/MetadataTest.cpp
@@ -494,6 +494,20 @@ TEST_F(MDNodeTest, isTemporary) {
EXPECT_TRUE(T->isTemporary());
}
+#if defined(GTEST_HAS_DEATH_TEST) && !defined(NDEBUG)
+
+TEST_F(MDNodeTest, deathOnNoReplaceTemporaryRAUW) {
+ auto Temp = MDNode::getTemporary(Context, None);
+ Temp->setCanReplace(false);
+ EXPECT_DEATH(Temp->replaceAllUsesWith(nullptr),
+ "Attempted to replace Metadata marked for no replacement");
+ Temp->setCanReplace(true);
+ // Remove the references to Temp; required for teardown.
+ Temp->replaceAllUsesWith(nullptr);
+}
+
+#endif
+
TEST_F(MDNodeTest, getDistinctWithUnresolvedOperands) {
// temporary !{}
auto Temp = MDTuple::getTemporary(Context, None);
diff --git a/unittests/IR/TypesTest.cpp b/unittests/IR/TypesTest.cpp
index b4dbf8e..f006db5 100644
--- a/unittests/IR/TypesTest.cpp
+++ b/unittests/IR/TypesTest.cpp
@@ -27,12 +27,12 @@ TEST(TypesTest, StructType) {
EXPECT_FALSE(Struct->hasName());
}
-TEST(TypesTest, LayoutIdenticalEmptyStructs) {
- LLVMContext C;
-
- StructType *Foo = StructType::create(C, "Foo");
- StructType *Bar = StructType::create(C, "Bar");
- EXPECT_TRUE(Foo->isLayoutIdentical(Bar));
-}
+TEST(TypesTest, LayoutIdenticalEmptyStructs) {
+ LLVMContext C;
+
+ StructType *Foo = StructType::create(C, "Foo");
+ StructType *Bar = StructType::create(C, "Bar");
+ EXPECT_TRUE(Foo->isLayoutIdentical(Bar));
+}
} // end anonymous namespace
diff --git a/unittests/ProfileData/InstrProfTest.cpp b/unittests/ProfileData/InstrProfTest.cpp
index 8f4db87..1ccc3ca 100644
--- a/unittests/ProfileData/InstrProfTest.cpp
+++ b/unittests/ProfileData/InstrProfTest.cpp
@@ -9,6 +9,7 @@
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/ProfileData/InstrProfWriter.h"
+#include "llvm/Support/Compression.h"
#include "gtest/gtest.h"
#include <cstdarg>
@@ -583,4 +584,77 @@ TEST_F(InstrProfTest, instr_prof_symtab_test) {
ASSERT_EQ(StringRef("bar3"), R);
}
+TEST_F(InstrProfTest, instr_prof_symtab_compression_test) {
+ std::vector<std::string> FuncNames1;
+ std::vector<std::string> FuncNames2;
+ for (int I = 0; I < 10 * 1024; I++) {
+ std::string str;
+ raw_string_ostream OS(str);
+ OS << "func_" << I;
+ FuncNames1.push_back(OS.str());
+ str.clear();
+ OS << "fooooooooooooooo_" << I;
+ FuncNames1.push_back(OS.str());
+ str.clear();
+ OS << "BAR_" << I;
+ FuncNames2.push_back(OS.str());
+ str.clear();
+ OS << "BlahblahBlahblahBar_" << I;
+ FuncNames2.push_back(OS.str());
+ }
+
+ for (int Padding = 0; Padding < 10; Padding++) {
+ for (int DoCompression = 0; DoCompression < 2; DoCompression++) {
+ // Compressing:
+ std::string FuncNameStrings1;
+ collectPGOFuncNameStrings(FuncNames1,
+ (DoCompression != 0 && zlib::isAvailable()),
+ FuncNameStrings1);
+
+ // Compressing:
+ std::string FuncNameStrings2;
+ collectPGOFuncNameStrings(FuncNames2,
+ (DoCompression != 0 && zlib::isAvailable()),
+ FuncNameStrings2);
+
+ // Join with paddings:
+ std::string FuncNameStrings = FuncNameStrings1;
+ for (int P = 0; P < Padding; P++) {
+ FuncNameStrings.push_back('\0');
+ }
+ FuncNameStrings += FuncNameStrings2;
+
+ // Now decompress:
+ InstrProfSymtab Symtab;
+ Symtab.create(StringRef(FuncNameStrings));
+
+ // Now do the checks:
+ // First sampling some data points:
+ StringRef R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[0]));
+ ASSERT_EQ(StringRef("func_0"), R);
+ R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[1]));
+ ASSERT_EQ(StringRef("fooooooooooooooo_0"), R);
+ R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[998]));
+ ASSERT_EQ(StringRef("func_499"), R);
+ R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[999]));
+ ASSERT_EQ(StringRef("fooooooooooooooo_499"), R);
+ R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames2[100]));
+ ASSERT_EQ(StringRef("BAR_50"), R);
+ R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames2[101]));
+ ASSERT_EQ(StringRef("BlahblahBlahblahBar_50"), R);
+ for (int I = 0; I < 10 * 1024; I++) {
+ std::string N[4];
+ N[0] = FuncNames1[2 * I];
+ N[1] = FuncNames1[2 * I + 1];
+ N[2] = FuncNames2[2 * I];
+ N[3] = FuncNames2[2 * I + 1];
+ for (int J = 0; J < 4; J++) {
+ StringRef R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(N[J]));
+ ASSERT_EQ(StringRef(N[J]), R);
+ }
+ }
+ }
+ }
+}
+
} // end anonymous namespace
diff --git a/unittests/Support/YAMLParserTest.cpp b/unittests/Support/YAMLParserTest.cpp
index 69b354a..41ad649 100644
--- a/unittests/Support/YAMLParserTest.cpp
+++ b/unittests/Support/YAMLParserTest.cpp
@@ -260,4 +260,76 @@ TEST(YAMLParser, DiagnosticFilenameFromBufferID) {
EXPECT_EQ("buffername.yaml", GeneratedDiag.getFilename());
}
+TEST(YAMLParser, SameNodeIteratorOperatorNotEquals) {
+ SourceMgr SM;
+ yaml::Stream Stream("[\"1\", \"2\"]", SM);
+
+ yaml::SequenceNode *Node = dyn_cast<yaml::SequenceNode>(
+ Stream.begin()->getRoot());
+
+ auto Begin = Node->begin();
+ auto End = Node->end();
+
+ EXPECT_TRUE(Begin != End);
+ EXPECT_FALSE(Begin != Begin);
+ EXPECT_FALSE(End != End);
+}
+
+TEST(YAMLParser, SameNodeIteratorOperatorEquals) {
+ SourceMgr SM;
+ yaml::Stream Stream("[\"1\", \"2\"]", SM);
+
+ yaml::SequenceNode *Node = dyn_cast<yaml::SequenceNode>(
+ Stream.begin()->getRoot());
+
+ auto Begin = Node->begin();
+ auto End = Node->end();
+
+ EXPECT_FALSE(Begin == End);
+ EXPECT_TRUE(Begin == Begin);
+ EXPECT_TRUE(End == End);
+}
+
+TEST(YAMLParser, DifferentNodesIteratorOperatorNotEquals) {
+ SourceMgr SM;
+ yaml::Stream Stream("[\"1\", \"2\"]", SM);
+ yaml::Stream AnotherStream("[\"1\", \"2\"]", SM);
+
+ yaml::SequenceNode *Node = dyn_cast<yaml::SequenceNode>(
+ Stream.begin()->getRoot());
+ yaml::SequenceNode *AnotherNode = dyn_cast<yaml::SequenceNode>(
+ AnotherStream.begin()->getRoot());
+
+ auto Begin = Node->begin();
+ auto End = Node->end();
+
+ auto AnotherBegin = AnotherNode->begin();
+ auto AnotherEnd = AnotherNode->end();
+
+ EXPECT_TRUE(Begin != AnotherBegin);
+ EXPECT_TRUE(Begin != AnotherEnd);
+ EXPECT_FALSE(End != AnotherEnd);
+}
+
+TEST(YAMLParser, DifferentNodesIteratorOperatorEquals) {
+ SourceMgr SM;
+ yaml::Stream Stream("[\"1\", \"2\"]", SM);
+ yaml::Stream AnotherStream("[\"1\", \"2\"]", SM);
+
+ yaml::SequenceNode *Node = dyn_cast<yaml::SequenceNode>(
+ Stream.begin()->getRoot());
+ yaml::SequenceNode *AnotherNode = dyn_cast<yaml::SequenceNode>(
+ AnotherStream.begin()->getRoot());
+
+ auto Begin = Node->begin();
+ auto End = Node->end();
+
+ auto AnotherBegin = AnotherNode->begin();
+ auto AnotherEnd = AnotherNode->end();
+
+ EXPECT_FALSE(Begin == AnotherBegin);
+ EXPECT_FALSE(Begin == AnotherEnd);
+ EXPECT_TRUE(End == AnotherEnd);
+}
+
} // end namespace llvm
OpenPOWER on IntegriCloud