[LLVMdev] clang static analyzer annotations
rmann at latencyzero.com
Tue Jul 2 12:33:54 PDT 2013
Not sure if this is the right place to ask. Please let me know if there's a better place.
I ran the clang static analyzer via Xcode 4.6.3 on our project that uses a lot of third-party libraries. One of them is Google protobufs, and it has a set of non-exiting assertion macros that the analyzer (rightly) ignores when flagging some NULL dereferences.
The macros look like this:
#define GOOGLE_LOG(LEVEL) \
::google::protobuf::internal::LogFinisher() = \
::google::protobuf::LOGLEVEL_##LEVEL, __FILE__, __LINE__)
#define GOOGLE_LOG_IF(LEVEL, CONDITION) \
!(CONDITION) ? (void)0 : GOOGLE_LOG(LEVEL)
#define GOOGLE_CHECK(EXPRESSION) \
GOOGLE_LOG_IF(FATAL, !(EXPRESSION)) << "CHECK failed: " #EXPRESSION ": "
And the code might look like this:
const ::google::protobuf::FileDescriptor* file =
GOOGLE_CHECK(file != NULL);
Affine3f_descriptor_ = file->message_type(0);
Resulting in a warning from the analyzer on the last line that file could be NULL.
Is there a way to annotate these macros so that the analyzer doesn't flag the code? I realize that's not strictly correct, since the macros don't exit, but, for better or for worse, the code is checked, and the numerous warnings potentially hide other, more pernicious ones.
More information about the llvm-dev