Skip to content

Commit

Permalink
Quiet clang memory leak warning on "DoNotOptimize". (#1571)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
clalancette authored Mar 5, 2021
1 parent e11986b commit 13312dc
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rclcpp/test/benchmark/benchmark_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ BENCHMARK_F(NodePerformanceTest, create_node)(benchmark::State & state)
for (auto _ : state) {
// Using pointer to separate construction and destruction in timing
auto node = std::make_shared<rclcpp::Node>("node");
#ifndef __clang_analyzer__
benchmark::DoNotOptimize(node);
#endif
benchmark::ClobberMemory();

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

#ifndef __clang_analyzer__
benchmark::DoNotOptimize(node);
#endif
benchmark::ClobberMemory();

node.reset();
Expand Down

0 comments on commit 13312dc

Please sign in to comment.