clang-analyzer-core.CallAndMessage and clang-analyzer-alpha.deadcode.UnreachableCode
| Bugzilla Link | 25777 |
| Version | unspecified |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
| CC | @devincoughlin |
Extended Description
This code:
void parseAggregate(std::string& key, std::vectorstd::string& values, const std::string& aggregate)
{
std::string::size_type pos = aggregate.find('=');
if(pos == std::string::npos)
throw FastException("Expected "key=value,value..." format.");
key = aggregate.substr(0, pos);
values.clear();
typedef boost::tokenizer<boost::char_separator
generates weird warnings like this:
/home/ppadlewski/fast-clang/Components/Stats/Aggregate.cc:18:26: warning: Called C++ object pointer is uninitialized [clang-analyzer-core.CallAndMessage]
for(const auto& token: tokenizer(aggregate.begin()+pos+1, aggregate.end(), boost::char_separator
I attach preprocesed file
Devin,
Here is the error I get:
error: Function call argument is a pointer to uninitialized value [clang-analyzer-core.CallAndMessage,-warnings-as-errors]
Should it be reporting [alpha.core.CallAndMessageUnInitRefArg] instead?
Andrew: It is the alpha.core.CallAndMessageUnInitRefArg checker producing this warning. I think it is working as designed. It is warning because you are passing a pointer to uninitialized memory to a function where the parameter is const.
Piotr: I fixed the false positive in your example in r255859.
Andrew: I'm having a hard time reproducing your false positive (either with or without the latest fix in r255859). Would you be willing to attach a preprocessed file (produced with 'clang -E') with the issue and also the exact command-line arguments to clang that you're using?
I just noticed that if you specify only the CallAndMessage check, it will not trip:
-checks=-*,clang-analyzer-core.CallAndMessage doesn't get it
-checks=-,clang-analyzer-core. doesn't get it
-checks=-,clang-analyzer gets it
I attached my preprocessor out, but its just gcc 4.8's cstdint
Full command:
clang-tidy -checks=-,clang-analyzer a.cpp -- -std=c++11
and I am checked out at:
llvm:
fdf52d35570d49dc00730511e32218aecd828926
clang: f47751e168163fcd3b756e3d7ad3c7de6e9a5fb1
clang-tools-extra: 3223c8e17635ad98e4063e2a27b1733f686c896f
*** Bug llvm/llvm-project#25628 has been marked as a duplicate of this bug. ***
Piotr: I fixed the false positive in your example in r255859.
Andrew: I'm having a hard time reproducing your false positive (either with or without the latest fix in r255859). Would you be willing to attach a preprocessed file (produced with 'clang -E') with the issue and also the exact command-line arguments to clang that you're using?
Here is a another example to produce:
" warning: Function call argument is a pointer to uninitialized value [clang-analyzer-core.CallAndMessage] A a(b); ^ note: 'b' initialized here std::uint8_t b[1]; ^ note: Function call argument is a pointer to uninitialized value A a(b); ^ "
struct A { const std::uint8_t* ptr; A( const std::uint8_t* a) : ptr(a) { }; };
int main() { std::uint8_t b[1]; A a{b}; }
Piotr, I don't see an attached file. Do you still have the preprocessed file?
Never mind! Reproduced without it.
Piotr, I don't see an attached file. Do you still have the preprocessed file?
Moving to the static analyzer component.
assigned to @devincoughlin