Skip to content

Commit 47da2e8

Browse files
boomanaiden154felipepiovezan
authored andcommitted
[Benchmark] Fix warnings around usage of __COUNTER__ (llvm#184524)
Premerge CI is currently failing with the following after the update to clang v22: ``` /home/gha/llvm-project/clang-tools-extra/clangd/benchmarks/IndexBenchmark.cpp:92:1: error: '__COUNTER__' is a C2y extension [-Werror,-Wc2y-extensions] 92 | BENCHMARK(dexQueries); | ^ ``` Some original work was done around this in df1d786, which was then done in upstream Google benchmark in google/benchmark@d8db2f9. The original work done in the patch implementing this feature doesn't seem to account for as many cases as the upstream patch does. This patch reverts the diff in df1d786 and applies the applicable hunks from the upstream patch.
1 parent aeb2385 commit 47da2e8

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎third-party/benchmark/include/benchmark/benchmark.h‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,14 +1459,29 @@ class Fixture : public internal::Benchmark {
14591459
// ------------------------------------------------------
14601460
// Macro to register benchmarks
14611461

1462+
// clang-format off
1463+
#if defined(__clang__)
1464+
#define BENCHMARK_DISABLE_COUNTER_WARNING \
1465+
_Pragma("GCC diagnostic push") \
1466+
_Pragma("GCC diagnostic ignored \"-Wunknown-warning-option\"") \
1467+
_Pragma("GCC diagnostic ignored \"-Wc2y-extensions\"")
1468+
#define BENCHMARK_RESTORE_COUNTER_WARNING _Pragma("GCC diagnostic pop")
1469+
#else
1470+
#define BENCHMARK_DISABLE_COUNTER_WARNING
1471+
#define BENCHMARK_RESTORE_COUNTER_WARNING
1472+
#endif
1473+
// clang-format on
1474+
14621475
// Check that __COUNTER__ is defined and that __COUNTER__ increases by 1
14631476
// every time it is expanded. X + 1 == X + 0 is used in case X is defined to be
14641477
// empty. If X is empty the expression becomes (+1 == +0).
1478+
BENCHMARK_DISABLE_COUNTER_WARNING
14651479
#if defined(__COUNTER__) && (__COUNTER__ + 1 == __COUNTER__ + 0)
14661480
#define BENCHMARK_PRIVATE_UNIQUE_ID __COUNTER__
14671481
#else
14681482
#define BENCHMARK_PRIVATE_UNIQUE_ID __LINE__
14691483
#endif
1484+
BENCHMARK_RESTORE_COUNTER_WARNING
14701485

14711486
// Helpers for generating unique variable names
14721487
#ifdef BENCHMARK_HAS_CXX11
@@ -1485,8 +1500,9 @@ class Fixture : public internal::Benchmark {
14851500
BaseClass##_##Method##_Benchmark
14861501

14871502
#define BENCHMARK_PRIVATE_DECLARE(n) \
1503+
BENCHMARK_DISABLE_COUNTER_WARNING \
14881504
static ::benchmark::internal::Benchmark* BENCHMARK_PRIVATE_NAME(n) \
1489-
BENCHMARK_UNUSED
1505+
BENCHMARK_RESTORE_COUNTER_WARNING BENCHMARK_UNUSED
14901506

14911507
#ifdef BENCHMARK_HAS_CXX11
14921508
#define BENCHMARK(...) \

0 commit comments

Comments
 (0)