Open dfarley1 opened 2 years ago
It seems working on my side.
However, I noted you had a typo: ANALYZER_ASSSERT
-> ANALYZER_ASSERT
It should fix your issue. Let me know.
Ha, sorry the typo is an artifact of me copy/pasting/sanitizing for this issue, I've double checked that things are correctly spelled in the actual code.
I could not reproduce your issue.
cat > def.h << EOF
#ifdef __clang_analyzer__
#include <assert.h>
#define ANALYZER_ASSERT(x) assert(x)
#else
#define ANALYZER_ASSERT(x) do {} while (0)
#endif
EOF
cat > api.c << EOF
#include "def.h"
int foo(int x) {
ANALYZER_ASSERT(x == 2);
return x / (x - 2);
}
EOF
CodeChecker log -b "gcc -Wall -Wextra -c api.c -o /dev/null" -o db.json
CodeChecker analyze db.json -o reports --verbose debug
After this we should expect a div by zero error because the ANALYZER_ASSERT(x == 2)
introduced the assumption that x
must be equal to 2
, thus x - 2
is zero causing the div by zero. Consequently, The analyzer correctly expanded the conditional #ifdef __clang_analyzer_
and selected the assert(cond)
version of the macro.
I'll close this issue unless you can give a clean end-to-end reproducer.
I'm working on adding CodeChecker support for our codebase and the docs mention that you should use
assert()
to guide clangsa around false positives. Our codebase doesn't currently useassert()
so I went to add it as a macro guarded by__clang_analyzer__
so that it doesn't affect our normal builds:I have some code in
api.c
that looks likeWhich produces this error:
We know that
cycle_length_sec()
can technically, but never practically, return 0, so I added our assert right above the line:But the warning keeps appearing, and clangsa doesn't seem to acknowledge the macro in its list of
Macro expansions
like it does forROUNDDOWN
. However, if I move theifdef
block intoapi.c
then the warning is suppressed as I'd expect:So for some reason it seems like
__clang_analyzer__
is defined inapi.c
but not indef.h
, even though the latter is directly#include
d from the former??I tried running the analyzer with debug logging turned on and I do see
-D__clang_analyzer__
in the CTU portion of the analysis:But I do not see it in the analysis run itself:
Is this something I need to go bug LLVM about or is there something going on with how CodeChecker invokes it?
CodeChecker version v6.19.1