[llvm-branch-commits] [compiler-rt] 70de7e0 - [compiler-rt] FuzzedDataProvider: Add PickValueInArray for std::array

2020-12-30 Thread Max Moroz via llvm-branch-commits

Author: Max Moroz
Date: 2020-12-30T10:25:26-08:00
New Revision: 70de7e0d9a95b7fcd7c105b06bd90fdf4e01f563

URL: 
https://github.com/llvm/llvm-project/commit/70de7e0d9a95b7fcd7c105b06bd90fdf4e01f563
DIFF: 
https://github.com/llvm/llvm-project/commit/70de7e0d9a95b7fcd7c105b06bd90fdf4e01f563.diff

LOG: [compiler-rt] FuzzedDataProvider: Add PickValueInArray for std::array

This makes `PickValueInArray` work for `std::array` (C++11). I've also 
tested the C++17 `std::array` (with compiler-deduced template parameters)

```
Author:
MarcoFalke 
```

Reviewed By: Dor1s

Differential Revision: https://reviews.llvm.org/D93412

Added: 


Modified: 
compiler-rt/include/fuzzer/FuzzedDataProvider.h
compiler-rt/lib/fuzzer/tests/FuzzedDataProviderUnittest.cpp

Removed: 




diff  --git a/compiler-rt/include/fuzzer/FuzzedDataProvider.h 
b/compiler-rt/include/fuzzer/FuzzedDataProvider.h
index 83bcd0134a7d..744a9d78cec0 100644
--- a/compiler-rt/include/fuzzer/FuzzedDataProvider.h
+++ b/compiler-rt/include/fuzzer/FuzzedDataProvider.h
@@ -14,6 +14,7 @@
 #define LLVM_FUZZER_FUZZED_DATA_PROVIDER_H_
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -71,6 +72,8 @@ class FuzzedDataProvider {
 
   // Returns a value from the given array.
   template  T PickValueInArray(const T 
(&array)[size]);
+  template 
+  T PickValueInArray(const std::array &array);
   template  T PickValueInArray(std::initializer_list 
list);
 
   // Writes data to the given destination and returns number of bytes written.
@@ -301,6 +304,12 @@ T FuzzedDataProvider::PickValueInArray(const T 
(&array)[size]) {
   return array[ConsumeIntegralInRange(0, size - 1)];
 }
 
+template 
+T FuzzedDataProvider::PickValueInArray(const std::array &array) {
+  static_assert(size > 0, "The array must be non empty.");
+  return array[ConsumeIntegralInRange(0, size - 1)];
+}
+
 template 
 T FuzzedDataProvider::PickValueInArray(std::initializer_list list) {
   // TODO(Dor1s): switch to static_assert once C++14 is allowed.

diff  --git a/compiler-rt/lib/fuzzer/tests/FuzzedDataProviderUnittest.cpp 
b/compiler-rt/lib/fuzzer/tests/FuzzedDataProviderUnittest.cpp
index 99d9d8ecbe9b..ea6774e5a5cd 100644
--- a/compiler-rt/lib/fuzzer/tests/FuzzedDataProviderUnittest.cpp
+++ b/compiler-rt/lib/fuzzer/tests/FuzzedDataProviderUnittest.cpp
@@ -283,6 +283,20 @@ TEST(FuzzedDataProvider, ConsumeBool) {
   EXPECT_EQ(false, DataProv.ConsumeBool());
 }
 
+TEST(FuzzedDataProvider, PickValueInStdArray) {
+  FuzzedDataProvider DataProv(Data, sizeof(Data));
+  const std::array Array = {1, 2, 3, 4, 5};
+  EXPECT_EQ(5, DataProv.PickValueInArray(Array));
+  EXPECT_EQ(2, DataProv.PickValueInArray(Array));
+  EXPECT_EQ(2, DataProv.PickValueInArray(Array));
+  EXPECT_EQ(3, DataProv.PickValueInArray(Array));
+  EXPECT_EQ(3, DataProv.PickValueInArray(Array));
+  EXPECT_EQ(3, DataProv.PickValueInArray(Array));
+  EXPECT_EQ(1, DataProv.PickValueInArray(Array));
+  EXPECT_EQ(3, DataProv.PickValueInArray(Array));
+  EXPECT_EQ(2, DataProv.PickValueInArray(Array));
+}
+
 TEST(FuzzedDataProvider, PickValueInArray) {
   FuzzedDataProvider DataProv(Data, sizeof(Data));
   const int Array[] = {1, 2, 3, 4, 5};



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 8ded83f - [llvm-cov] Add support for -skip-functions to lcov

2020-01-22 Thread Max Moroz via llvm-branch-commits

Author: Keith Smiley
Date: 2020-01-22T12:49:00-08:00
New Revision: 8ded83ff7e048bb45e56889f1bf00e36c63e1982

URL: 
https://github.com/llvm/llvm-project/commit/8ded83ff7e048bb45e56889f1bf00e36c63e1982
DIFF: 
https://github.com/llvm/llvm-project/commit/8ded83ff7e048bb45e56889f1bf00e36c63e1982.diff

LOG: [llvm-cov] Add support for -skip-functions to lcov

Summary:
This flag was added for the json format to exclude functions from the
output. This mirrors that behavior in lcov (where it was previously
accepted but ignored). This makes the output file smaller which can be
beneficial depending on how you consume it, especially if you don't use
this data anyways.

Patch by Keith Smiley (@keith).

Reviewers: kastiglione, Dor1s, vsk, allevato

Reviewed By: Dor1s, allevato

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73160

Added: 
llvm/test/tools/llvm-cov/export_functions-lcov.test

Modified: 
llvm/tools/llvm-cov/CoverageExporterLcov.cpp

Removed: 




diff  --git a/llvm/test/tools/llvm-cov/export_functions-lcov.test 
b/llvm/test/tools/llvm-cov/export_functions-lcov.test
new file mode 100644
index ..86331d823623
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/export_functions-lcov.test
@@ -0,0 +1,8 @@
+# Test that llvm-cov export produces function data by default and that it can 
be
+# turned off with a flag.
+
+RUN: llvm-cov export -format lcov %S/Inputs/report.covmapping -instr-profile 
%S/Inputs/report.profdata 2>&1 | FileCheck %s
+RUN: llvm-cov export -format lcov %S/Inputs/report.covmapping -instr-profile 
%S/Inputs/report.profdata -skip-functions 2>&1 | FileCheck 
-check-prefix=SKIP-FUNCTIONS %s
+
+CHECK: FN:
+SKIP-FUNCTIONS-NOT: FN:

diff  --git a/llvm/tools/llvm-cov/CoverageExporterLcov.cpp 
b/llvm/tools/llvm-cov/CoverageExporterLcov.cpp
index d9b0c3b0d7a8..a6b3c6607030 100644
--- a/llvm/tools/llvm-cov/CoverageExporterLcov.cpp
+++ b/llvm/tools/llvm-cov/CoverageExporterLcov.cpp
@@ -78,10 +78,11 @@ void renderLineSummary(raw_ostream &OS, const 
FileCoverageSummary &Summary) {
 
 void renderFile(raw_ostream &OS, const coverage::CoverageMapping &Coverage,
 const std::string &Filename,
-const FileCoverageSummary &FileReport, bool ExportSummaryOnly) 
{
+const FileCoverageSummary &FileReport, bool ExportSummaryOnly,
+bool SkipFunctions) {
   OS << "SF:" << Filename << '\n';
 
-  if (!ExportSummaryOnly) {
+  if (!ExportSummaryOnly && !SkipFunctions) {
 renderFunctions(OS, Coverage.getCoveredFunctions(Filename));
   }
   renderFunctionSummary(OS, FileReport);
@@ -99,9 +100,10 @@ void renderFile(raw_ostream &OS, const 
coverage::CoverageMapping &Coverage,
 void renderFiles(raw_ostream &OS, const coverage::CoverageMapping &Coverage,
  ArrayRef SourceFiles,
  ArrayRef FileReports,
- bool ExportSummaryOnly) {
+ bool ExportSummaryOnly, bool SkipFunctions) {
   for (unsigned I = 0, E = SourceFiles.size(); I < E; ++I)
-renderFile(OS, Coverage, SourceFiles[I], FileReports[I], 
ExportSummaryOnly);
+renderFile(OS, Coverage, SourceFiles[I], FileReports[I], ExportSummaryOnly,
+   SkipFunctions);
 }
 
 } // end anonymous namespace
@@ -119,6 +121,6 @@ void CoverageExporterLcov::renderRoot(ArrayRef 
SourceFiles) {
   FileCoverageSummary Totals = FileCoverageSummary("Totals");
   auto FileReports = CoverageReport::prepareFileReports(Coverage, Totals,
 SourceFiles, Options);
-  renderFiles(OS, Coverage, SourceFiles, FileReports,
-  Options.ExportSummaryOnly);
+  renderFiles(OS, Coverage, SourceFiles, FileReports, 
Options.ExportSummaryOnly,
+  Options.SkipFunctions);
 }



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits