Skip to content

Commit 13312dc

Browse files
authored
Quiet clang memory leak warning on "DoNotOptimize". (ros2#1571)
When building rclcpp under clang static analysis, it complains that the "DoNotOptimize" function from Google benchmark can cause a memory leak. I can't see how this is possible, so I can only assume that the inline assembly that is used to implement "DoNotOptimize" is causing a false positive. Just quite the warning here when building under clang static analysis. Signed-off-by: Chris Lalancette <[email protected]>
1 parent e11986b commit 13312dc

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

rclcpp/test/benchmark/benchmark_node.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ BENCHMARK_F(NodePerformanceTest, create_node)(benchmark::State & state)
4646
for (auto _ : state) {
4747
// Using pointer to separate construction and destruction in timing
4848
auto node = std::make_shared<rclcpp::Node>("node");
49+
#ifndef __clang_analyzer__
4950
benchmark::DoNotOptimize(node);
51+
#endif
5052
benchmark::ClobberMemory();
5153

5254
// Ensure destruction of node is not counted toward timing
@@ -69,7 +71,9 @@ BENCHMARK_F(NodePerformanceTest, destroy_node)(benchmark::State & state)
6971
auto node = std::make_shared<rclcpp::Node>("node");
7072
state.ResumeTiming();
7173

74+
#ifndef __clang_analyzer__
7275
benchmark::DoNotOptimize(node);
76+
#endif
7377
benchmark::ClobberMemory();
7478

7579
node.reset();

0 commit comments

Comments
 (0)