Disable dtor inlining for clang-tidy

LLVM r328258 turned on a feature called temporary dtor inlining by
default for all of C++ in clang-tidy. This feature appears to be
somewhat over-aggressive when objects are being passed by value. For
example, given:

void foo(std::unique_ptr<int> i);

void bar() {
  auto x = std::make_unique<int>();
  int *i = x.get();
  foo(std::move(x));
  *i = 99;
}

...clang-tidy will complain about `*i = 99;` being a definite
use-after-free. This is incorrect, however: `foo` could stash the
`unique_ptr` it's given in a global, or a class member, or ...

Until upstream fixes this bug, it's probably best to keep this disabled.

Bug: None
Test: Ran the analyzer across Android locally. Nothing broke; number of
complaints dropped significantly.

Change-Id: I742eedf598a72a533285d913d191bfbbf0ce1688
This commit is contained in:
George Burgess IV
2018-05-14 15:46:43 -07:00
parent f49d12ca24
commit 432899a25b

View File

@@ -1724,10 +1724,19 @@ ifneq (,$(filter 1 true,$(my_tidy_enabled)))
my_tidy_flags += -quiet -extra-arg-before=-fno-caret-diagnostics
endif
# We might be using the static analyzer through clang-tidy.
# https://bugs.llvm.org/show_bug.cgi?id=32914
ifneq ($(my_tidy_checks),)
# We might be using the static analyzer through clang-tidy.
# https://bugs.llvm.org/show_bug.cgi?id=32914
my_tidy_flags += -extra-arg-before=-D__clang_analyzer__
# A recent change in clang-tidy (r328258) enabled destructor inlining,
# which appears to cause a number of false positives. Until that's
# resolved, this turns off the effects of r328258.
# https://bugs.llvm.org/show_bug.cgi?id=37459
my_tidy_flags += -extra-arg-before=-Xclang
my_tidy_flags += -extra-arg-before=-analyzer-config
my_tidy_flags += -extra-arg-before=-Xclang
my_tidy_flags += -extra-arg-before=c++-temp-dtor-inlining=false
endif
endif
endif