Use newest clang static analyzers.
* When WITH_STATIC_ANALYZER is set and non-zero, and clang compiler is used,
call new clang ccc-analyzer or c++-analyzer.
* Otherwise, if WITH_SYNTAX_CHECK is set and non-zero,
call compiler with -fsyntax-only.
* Replace "--sysroot=path" with "--sysroot path", to work with ccc-analyzer.
* ccc-analyzer executes the original compilation command to generate
object files before calling clang with --analyze to do static analysis.
* When clang is called with --analyze, macro __clang_analyzer__ is defined.
BUG: 13287788
(cherry picked from commit 765c1ea6d7272fae04d435b9bac79087a2f6aabf)
Change-Id: I6e51e51ff4ed3ce514f60d090494dcdf6e520b04
diff --git a/core/binary.mk b/core/binary.mk
index 7008492..d128c79 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -404,6 +404,12 @@
LOCAL_NO_STATIC_ANALYZER := true
endif
+# Clang does not recognize all gcc flags.
+# Use static analyzer only if clang is used.
+ifneq ($(my_clang),true)
+ LOCAL_NO_STATIC_ANALYZER := true
+endif
+
ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),)
my_syntax_arch := host
else
@@ -418,13 +424,16 @@
endif
my_cc := $(my_cc_wrapper) $(my_cc)
endif
+
ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
- my_cc := $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer $(my_syntax_arch) "$(my_cc)"
+ my_cc := CCC_CC=$(CLANG) CLANG=$(CLANG) \
+ $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer
else
ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
- my_cc := $(SYNTAX_TOOLS_PREFIX)/ccc-syntax $(my_syntax_arch) "$(my_cc)"
+ my_cc := $(my_cc) -fsyntax-only
endif
endif
+
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(my_cc)
ifeq ($(strip $(my_cxx)),)
@@ -435,13 +444,16 @@
endif
my_cxx := $(my_cxx_wrapper) $(my_cxx)
endif
+
ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
- my_cxx := $(SYNTAX_TOOLS_PREFIX)/cxx-analyzer $(my_syntax_arch) "$(my_cxx)"
+ my_cxx := CCC_CXX=$(CLANG_CXX) CLANG_CXX=$(CLANG_CXX) \
+ $(SYNTAX_TOOLS_PREFIX)/c++-analyzer
else
ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
- my_cxx := $(SYNTAX_TOOLS_PREFIX)/cxx-syntax $(my_syntax_arch) "$(my_cxx)"
+ my_cxx := $(my_cxx) -fsyntax-only
endif
endif
+
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LINKER := $(my_linker)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(my_cxx)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CLANG := $(my_clang)