Project

General

Profile

Bug #2265

cppcheck CUDA + allocator.h compareBoolExpressionWithInt false positive

Added by Aleksei Iupinov about 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
analysis tools
Target version:
Affected version - extra info:
68c489a5f472a4eec032370792737f9614a2dee5
Affected version:
Difficulty:
simple
Close

Description

Cppcheck made me waste an hour on this stupid false positive. Perhaps we should consider deprecating it. At least I'm gonna document this in case this saves someone a minute.

Steps to reproduce with CUDA build:
Create a file src/gromacs/gpu_utils/dummy.cpp with contents:

#include "gromacs/utility/allocator.h" 

Run cmake and make cppcheck: no warnings.
Rename the file to dummy.cu.
Run cmake and make cppcheck:
src/gromacs/utility/allocator.h:206:compareBoolExpressionWithInt: warning: Comparison of a boolean expression with an integer other than 0 or 1.

The line(s) in question:

205       std::size_t
206       max_size() const { return (static_cast<std::size_t>(0) - static_cast<std::size_t>(1)) / sizeof(T); }

In my case, I solved it by breaking the include chain which led from CUDA code to allocator.h, but that is clearly not a general answer.

Associated revisions

Revision 0ccfa6aa (diff)
Added by Mark Abraham about 2 years ago

Tell cppcheck that .cpp and .cu files are c++

This will avoid known strange behavior with .cu files.

Fixes #2265

Change-Id: I06850509afa11a531fe9b7063368614c81f4a7d1

History

#1 Updated by Mark Abraham about 2 years ago

f64eebb35b453b9e86d7c2fe78cb86bf37c05ee2 improved support for cppcheck on .cu files, but didn't actually tell cppcheck to consider them C++ files. This is useful, because cppcheck will also check C files, and it wasn't until cppcheck 1.79 that C++ constructs in C files was an error for cppcheck.

#2 Updated by Gerrit Code Review Bot about 2 years ago

Gerrit received a related patchset '1' for Issue #2265.
Uploader: Mark Abraham ()
Change-Id: gromacs~master~I06850509afa11a531fe9b7063368614c81f4a7d1
Gerrit URL: https://gerrit.gromacs.org/7010

#3 Updated by Mark Abraham about 2 years ago

Got some of my clues from http://trac.cppcheck.net/ticket/7770 and the cppcheck release notes

#4 Updated by Mark Abraham about 2 years ago

  • Status changed from New to Fix uploaded

#5 Updated by Mark Abraham about 2 years ago

  • Target version set to 2018

#6 Updated by Aleksei Iupinov about 2 years ago

Nice!

#7 Updated by Mark Abraham about 2 years ago

  • Status changed from Fix uploaded to Resolved

#8 Updated by Aleksei Iupinov almost 2 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF