[libc-commits] [libc] Fix build issues with libc mem* benchmarks (PR #115982)

David Peixotto via libc-commits libc-commits at lists.llvm.org
Wed Nov 13 09:46:24 PST 2024


https://github.com/dmpots updated https://github.com/llvm/llvm-project/pull/115982

>From 52034186e56384b89e9e06c2bdfd09fde1067485 Mon Sep 17 00:00:00 2001
From: David Peixotto <peix at meta.com>
Date: Tue, 12 Nov 2024 19:17:26 -0800
Subject: [PATCH 1/2] Fix build issues with libc mem* benchmarks

Fix a few issues found when trying to build the benchmark:

Errors
1. Unable to find include "src/__support/macros/config.h" in
   LibcMemoryBenchmarkMain.cpp

Warnings
2. Unused variable warning `Index` in MemorySizeDistributions.cpp
3. Fix deprecation warning for const-ref version of `DoNotOptimize`.
   warning: 'DoNotOptimize<void *>' is deprecated: The const-ref version of this
             method can permit undesired compiler optimizations in benchmarks
---
 libc/benchmarks/CMakeLists.txt              | 1 +
 libc/benchmarks/LibcBenchmark.h             | 2 +-
 libc/benchmarks/MemorySizeDistributions.cpp | 2 --
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/libc/benchmarks/CMakeLists.txt b/libc/benchmarks/CMakeLists.txt
index 0cff6eb12c2475..52e3f942d16ea3 100644
--- a/libc/benchmarks/CMakeLists.txt
+++ b/libc/benchmarks/CMakeLists.txt
@@ -126,6 +126,7 @@ add_library(libc-memory-benchmark
 target_include_directories(libc-memory-benchmark
     PUBLIC
     ${CMAKE_CURRENT_SOURCE_DIR}
+    ${LIBC_SOURCE_DIR}
 )
 target_link_libraries(libc-memory-benchmark
     PUBLIC
diff --git a/libc/benchmarks/LibcBenchmark.h b/libc/benchmarks/LibcBenchmark.h
index 0a0b40f924e68e..6b1556721e416f 100644
--- a/libc/benchmarks/LibcBenchmark.h
+++ b/libc/benchmarks/LibcBenchmark.h
@@ -211,7 +211,7 @@ BenchmarkResult benchmark(const BenchmarkOptions &Options,
     // Measuring this Batch.
     const auto StartTime = Clock.now();
     for (const auto Parameter : Batch) {
-      const auto Production = foo(Parameter);
+      auto Production = foo(Parameter);
       benchmark::DoNotOptimize(Production);
     }
     const auto EndTime = Clock.now();
diff --git a/libc/benchmarks/MemorySizeDistributions.cpp b/libc/benchmarks/MemorySizeDistributions.cpp
index c3590297445dd1..58ba31b26f04bd 100644
--- a/libc/benchmarks/MemorySizeDistributions.cpp
+++ b/libc/benchmarks/MemorySizeDistributions.cpp
@@ -185,11 +185,9 @@ ArrayRef<MemorySizeDistribution> getMemcmpSizeDistributions() {
 MemorySizeDistribution
 getDistributionOrDie(ArrayRef<MemorySizeDistribution> Distributions,
                      StringRef Name) {
-  size_t Index = 0;
   for (const auto &MSD : Distributions) {
     if (MSD.Name == Name)
       return MSD;
-    ++Index;
   }
   std::string Message;
   raw_string_ostream Stream(Message);

>From 75c0e1fa557f2d26a8cbdee0798d6ab8c4b8cdb4 Mon Sep 17 00:00:00 2001
From: David Peixotto <peix at meta.com>
Date: Wed, 13 Nov 2024 09:46:09 -0800
Subject: [PATCH 2/2] Remove unnecessary braces

---
 libc/benchmarks/MemorySizeDistributions.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/benchmarks/MemorySizeDistributions.cpp b/libc/benchmarks/MemorySizeDistributions.cpp
index 58ba31b26f04bd..e29b3710f73673 100644
--- a/libc/benchmarks/MemorySizeDistributions.cpp
+++ b/libc/benchmarks/MemorySizeDistributions.cpp
@@ -185,10 +185,10 @@ ArrayRef<MemorySizeDistribution> getMemcmpSizeDistributions() {
 MemorySizeDistribution
 getDistributionOrDie(ArrayRef<MemorySizeDistribution> Distributions,
                      StringRef Name) {
-  for (const auto &MSD : Distributions) {
+  for (const auto &MSD : Distributions)
     if (MSD.Name == Name)
       return MSD;
-  }
+
   std::string Message;
   raw_string_ostream Stream(Message);
   Stream << "Unknown MemorySizeDistribution '" << Name



More information about the libc-commits mailing list