llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

clang-analyzer-core.CallAndMessage and clang-analyzer-alpha.deadcode.UnreachableCode

Open llvmbot opened this issue 10 years ago • 11 comments

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> tokenizer; for(const auto& token: tokenizer(aggregate.begin()+pos+1, aggregate.end(), boost::char_separator(","))) values.push_back(token); }

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(","))) ^ /home/ppadlewski/fast-clang/Components/Stats/Aggregate.cc:13:8: note: Assuming 'pos' is not equal to 'npos' if(pos == std::string::npos) ^ /home/ppadlewski/fast-clang/Components/Stats/Aggregate.cc:13:5: note: Taking false branch if(pos == std::string::npos) ^ /home/ppadlewski/fast-clang/Components/Stats/Aggregate.cc:18:28: note: '__range' initialized to a garbage value for(const auto& token: tokenizer(aggregate.begin()+pos+1, aggregate.end(), boost::char_separator(","))) ^ /home/ppadlewski/fast-clang/Components/Stats/Aggregate.cc:18:26: note: Called C++ object pointer is uninitialized for(const auto& token: tokenizer(aggregate.begin()+pos+1, aggregate.end(), boost::char_separator(","))) ^ /home/ppadlewski/fast-clang/Components/Stats/Aggregate.cc:18:26: warning: This statement is never executed [clang-analyzer-alpha.deadcode.UnreachableCode] for(const auto& token: tokenizer(aggregate.begin()+pos+1, aggregate.end(), boost::char_separator(","))) ^ /home/ppadlewski/fast-clang/Components/Stats/Aggregate.cc:18:26: note: This statement is never executed for(const auto& token: tokenizer(aggregate.begin()+pos+1, aggregate.end(), boost::char_separator(",")))

I attach preprocesed file

llvmbot avatar Dec 08 '15 20:12 llvmbot

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?

llvmbot avatar Feb 09 '16 19:02 llvmbot

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.

devincoughlin avatar Feb 08 '16 09:02 devincoughlin

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

llvmbot avatar Dec 31 '15 20:12 llvmbot

preprocessor out

llvmbot avatar Dec 31 '15 20:12 llvmbot

*** Bug llvm/llvm-project#25628 has been marked as a duplicate of this bug. ***

devincoughlin avatar Dec 30 '15 21:12 devincoughlin

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?

devincoughlin avatar Dec 30 '15 03:12 devincoughlin

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}; }

llvmbot avatar Dec 17 '15 20:12 llvmbot

Piotr, I don't see an attached file. Do you still have the preprocessed file?

Never mind! Reproduced without it.

devincoughlin avatar Dec 15 '15 02:12 devincoughlin

Piotr, I don't see an attached file. Do you still have the preprocessed file?

devincoughlin avatar Dec 15 '15 01:12 devincoughlin

Moving to the static analyzer component.

devincoughlin avatar Dec 15 '15 01:12 devincoughlin

assigned to @devincoughlin

llvmbot avatar Dec 08 '15 20:12 llvmbot