llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.65k stars 11.84k forks source link

Static analyser doesn't respect #pragma GCC diagnostic ignored "-Wnonnull" #28649

Open llvmbot opened 8 years ago

llvmbot commented 8 years ago
Bugzilla Link 28275
Version 3.4
OS Linux
Reporter LLVM Bugzilla Contributor

Extended Description

I have a method that should not be passed a null pointer under normal operation, so I have declared it like so (in C):

uint16_t CRC_xmodem(const uint8_t* data, const uint16_t length) attribute((nonnull));

but in unit testing I want to pass it a null pointer to ensure it accepts it gracefully. To avoid a compiler warning, I do this like so (in C++, using catch.hpp if that's relevant):

TEST_CASE("CRC_xmodem null pointer produces zero, "[crc]") {

pragma GCC diagnostic ignored "-Wnonnull"

CHECK( 0 == CRC_xmodem(NULL, 0) );

pragma GCC diagnostic pop

}

This is sufficient to suppress the compile-time warnings, but scan-build still produces a warning:-

snip/crc/crc_unittest.cpp:34:21: warning: Null pointer passed as an argument to a 'nonnull' parameter CHECK( 0 == CRC_xmodem(NULL, 0) ); ^ ~~~~

Currently I'm suppressing the warning using #ifndef __clang_analyzer__ but it would be tidier if the clang analyser respected the GCC pragma.

llvmbot commented 8 years ago

assigned to @tkremenek