From 561a3fe4af34038b8b4ab4293273b84fbfca13b3 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Wed, 3 May 2017 18:13:08 -0700 Subject: [PATCH] soong: add __clang_analyzer__ to clang-tidy We have code that acts slightly differently when the static analyzer is running, so that it can produce more accurate diagnostics (e.g. less false positives). It uses __clang_analyzer__ to detect the static analyzer. When the static analyzer is run via clang-tidy, __clang_analyzer__ doesn't get defined. Bug: None Test: WITH_TIDY=1 m. clang-tidy now acts as expected in code made for the static analyzer Change-Id: I460ff410640524633c0a60b71d34927d17e1ed98 --- cc/tidy.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cc/tidy.go b/cc/tidy.go index 9dcc946ac..c31f5aea6 100644 --- a/cc/tidy.go +++ b/cc/tidy.go @@ -77,6 +77,10 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags { flags.TidyFlags = append(flags.TidyFlags, headerFilter) } + // We might be using the static analyzer through clang tidy. + // https://bugs.llvm.org/show_bug.cgi?id=32914 + flags.TidyFlags = append(flags.TidyFlags, "-extra-arg-before=-D__clang_analyzer__") + tidyChecks := "-checks=" if checks := ctx.AConfig().TidyChecks(); len(checks) > 0 { tidyChecks += checks