summaryrefslogtreecommitdiff
path: root/llvm/unittests/tools
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2020-02-12 23:30:22 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2020-02-12 23:33:23 +0300
commit687bbf85de4ae463c0794dff545734e194941162 (patch)
treee3244e678515cc14ea70c2c2f620b1adb1de12ed /llvm/unittests/tools
parente26c24b849211f35a988d001753e0cd15e4a9d7b (diff)
downloadllvm-687bbf85de4ae463c0794dff545734e194941162.tar.gz
[llvm-exegesis] CombinationGenerator: don't store function_ref
function_ref is non-owning, so if we get it as a parameter in constructor, our reference goes out-of-scope as soon as constructor returns. Instead, let's just take it as a parameter to the actual `generate()` call
Diffstat (limited to 'llvm/unittests/tools')
-rw-r--r--llvm/unittests/tools/llvm-exegesis/SnippetGeneratorTest.cpp88
1 files changed, 40 insertions, 48 deletions
diff --git a/llvm/unittests/tools/llvm-exegesis/SnippetGeneratorTest.cpp b/llvm/unittests/tools/llvm-exegesis/SnippetGeneratorTest.cpp
index 9feff27f40dd..760caa8ce325 100644
--- a/llvm/unittests/tools/llvm-exegesis/SnippetGeneratorTest.cpp
+++ b/llvm/unittests/tools/llvm-exegesis/SnippetGeneratorTest.cpp
@@ -20,13 +20,12 @@ TEST(CombinationGenerator, Square) {
const std::vector<std::vector<int>> Choices{{0, 1}, {2, 3}};
std::vector<std::vector<int>> Variants;
- CombinationGenerator<int, std::vector<int>, 4> G(
- Choices, [&](ArrayRef<int> State) -> bool {
- Variants.emplace_back(State);
- return false; // keep going
- });
+ CombinationGenerator<int, std::vector<int>, 4> G(Choices);
const size_t NumVariants = G.numCombinations();
- G.generate();
+ G.generate([&](ArrayRef<int> State) -> bool {
+ Variants.emplace_back(State);
+ return false; // keep going
+ });
const std::vector<std::vector<int>> ExpectedVariants{
{0, 2},
@@ -42,13 +41,12 @@ TEST(CombinationGenerator, MiddleColumn) {
const std::vector<std::vector<int>> Choices{{0}, {1, 2}, {3}};
std::vector<std::vector<int>> Variants;
- CombinationGenerator<int, std::vector<int>, 4> G(
- Choices, [&](ArrayRef<int> State) -> bool {
- Variants.emplace_back(State);
- return false; // keep going
- });
+ CombinationGenerator<int, std::vector<int>, 4> G(Choices);
const size_t NumVariants = G.numCombinations();
- G.generate();
+ G.generate([&](ArrayRef<int> State) -> bool {
+ Variants.emplace_back(State);
+ return false; // keep going
+ });
const std::vector<std::vector<int>> ExpectedVariants{
{0, 1, 3},
@@ -62,13 +60,12 @@ TEST(CombinationGenerator, SideColumns) {
const std::vector<std::vector<int>> Choices{{0, 1}, {2}, {3, 4}};
std::vector<std::vector<int>> Variants;
- CombinationGenerator<int, std::vector<int>, 4> G(
- Choices, [&](ArrayRef<int> State) -> bool {
- Variants.emplace_back(State);
- return false; // keep going
- });
+ CombinationGenerator<int, std::vector<int>, 4> G(Choices);
const size_t NumVariants = G.numCombinations();
- G.generate();
+ G.generate([&](ArrayRef<int> State) -> bool {
+ Variants.emplace_back(State);
+ return false; // keep going
+ });
const std::vector<std::vector<int>> ExpectedVariants{
{0, 2, 3},
@@ -84,13 +81,12 @@ TEST(CombinationGenerator, LeftColumn) {
const std::vector<std::vector<int>> Choices{{0, 1}, {2}};
std::vector<std::vector<int>> Variants;
- CombinationGenerator<int, std::vector<int>, 4> G(
- Choices, [&](ArrayRef<int> State) -> bool {
- Variants.emplace_back(State);
- return false; // keep going
- });
+ CombinationGenerator<int, std::vector<int>, 4> G(Choices);
const size_t NumVariants = G.numCombinations();
- G.generate();
+ G.generate([&](ArrayRef<int> State) -> bool {
+ Variants.emplace_back(State);
+ return false; // keep going
+ });
const std::vector<std::vector<int>> ExpectedVariants{
{0, 2},
@@ -104,13 +100,12 @@ TEST(CombinationGenerator, RightColumn) {
const std::vector<std::vector<int>> Choices{{0}, {1, 2}};
std::vector<std::vector<int>> Variants;
- CombinationGenerator<int, std::vector<int>, 4> G(
- Choices, [&](ArrayRef<int> State) -> bool {
- Variants.emplace_back(State);
- return false; // keep going
- });
+ CombinationGenerator<int, std::vector<int>, 4> G(Choices);
const size_t NumVariants = G.numCombinations();
- G.generate();
+ G.generate([&](ArrayRef<int> State) -> bool {
+ Variants.emplace_back(State);
+ return false; // keep going
+ });
const std::vector<std::vector<int>> ExpectedVariants{
{0, 1},
@@ -124,13 +119,12 @@ TEST(CombinationGenerator, Column) {
const std::vector<std::vector<int>> Choices{{0, 1}};
std::vector<std::vector<int>> Variants;
- CombinationGenerator<int, std::vector<int>, 4> G(
- Choices, [&](ArrayRef<int> State) -> bool {
- Variants.emplace_back(State);
- return false; // keep going
- });
+ CombinationGenerator<int, std::vector<int>, 4> G(Choices);
const size_t NumVariants = G.numCombinations();
- G.generate();
+ G.generate([&](ArrayRef<int> State) -> bool {
+ Variants.emplace_back(State);
+ return false; // keep going
+ });
const std::vector<std::vector<int>> ExpectedVariants{
{0},
@@ -144,13 +138,12 @@ TEST(CombinationGenerator, Row) {
const std::vector<std::vector<int>> Choices{{0}, {1}};
std::vector<std::vector<int>> Variants;
- CombinationGenerator<int, std::vector<int>, 4> G(
- Choices, [&](ArrayRef<int> State) -> bool {
- Variants.emplace_back(State);
- return false; // keep going
- });
+ CombinationGenerator<int, std::vector<int>, 4> G(Choices);
const size_t NumVariants = G.numCombinations();
- G.generate();
+ G.generate([&](ArrayRef<int> State) -> bool {
+ Variants.emplace_back(State);
+ return false; // keep going
+ });
const std::vector<std::vector<int>> ExpectedVariants{
{0, 1},
@@ -163,13 +156,12 @@ TEST(CombinationGenerator, Singleton) {
const std::vector<std::vector<int>> Choices{{0}};
std::vector<std::vector<int>> Variants;
- CombinationGenerator<int, std::vector<int>, 4> G(
- Choices, [&](ArrayRef<int> State) -> bool {
- Variants.emplace_back(State);
- return false; // keep going
- });
+ CombinationGenerator<int, std::vector<int>, 4> G(Choices);
const size_t NumVariants = G.numCombinations();
- G.generate();
+ G.generate([&](ArrayRef<int> State) -> bool {
+ Variants.emplace_back(State);
+ return false; // keep going
+ });
const std::vector<std::vector<int>> ExpectedVariants{
{0},