[libcxx-commits] [libcxx] [libc++] Don't pass a path lvalue to DoNotOptimize in the filesystem benchmark (PR #225504)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 22 12:50:22 PDT 2026


https://github.com/ldionne created https://github.com/llvm/llvm-project/pull/225504

BM_PathIterateOnceBackwards passes *I directly to DoNotOptimize. However, libstdc++ returns a const lvalue reference to `path` from that operation, which selects GoogleBenchmark's deprecated const-ref overload.

Use the pattern used elsewhere in this file instead.

>From 48013e378b76d10f748fd2c1a8d204963fbd1b86 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 22 Sep 2026 12:31:23 -0700
Subject: [PATCH] [libc++] Don't pass a path lvalue to DoNotOptimize in the
 filesystem benchmark

BM_PathIterateOnceBackwards passes *I directly to DoNotOptimize. However,
libstdc++ returns a const lvalue reference to `path` from that operation,
which selects GoogleBenchmark's deprecated const-ref overload.

Use the pattern used elsewhere in this file instead.
---
 libcxx/test/benchmarks/filesystem.bench.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/test/benchmarks/filesystem.bench.cpp b/libcxx/test/benchmarks/filesystem.bench.cpp
index ad88c517b46657..e400c904340b77 100644
--- a/libcxx/test/benchmarks/filesystem.bench.cpp
+++ b/libcxx/test/benchmarks/filesystem.bench.cpp
@@ -131,9 +131,9 @@ TEST_ALIGN_BENCHMARK void BM_PathIterateOnceBackwards(benchmark::State& st, GenI
     auto I       = P.end();
     while (I != B) {
       --I;
-      benchmark::DoNotOptimize(*I);
+      benchmark::DoNotOptimize(I->native().data());
     }
-    benchmark::DoNotOptimize(*I);
+    benchmark::DoNotOptimize(I->native().data());
   }
 }
 BENCHMARK_CAPTURE(BM_PathIterateOnceBackwards, iterate_elements, getRandomStringInputs)



More information about the libcxx-commits mailing list