[LLVMbugs] [Bug 14101] New: Feature Request: warn on over-generalised functions

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Oct 16 13:48:09 PDT 2012


             Bug #: 14101
           Summary: Feature Request: warn on over-generalised functions
           Product: clang
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: paul.holden at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


I was tidying up our codebase today, and realised that the refactoring that I
was performing might make a useful static analyser warning.

The functions I was looking at were overgeneralised - everywhere they were
called in the codebase specified the same arguments. For example, we had
something like this:

Object * Clone(Object * object, Matrix * transform, Colour * color, float *
mass) {
  Object * copy = object->clone();
  if (transform) { copy->SetPos(*transform); }
  if (color)     { copy->SetColor(*color); }
  if (mass)      { copy->SetMass(*mass); }
  return copy;

Everywhere Clone was called, we always passed NULL for color and mass. (I
suspect they used to do something useful, but the code has changed over time).
So I removed the arguments, simplified the body of Clone() and tidied up all
the call sites.

After manually tidying up a bunch of functions like this, I realised that it
might make a useful static analysis warning. Something like:

'Clone' is always called with NULL for argument 2 ('color').
'Clone' is always called with NULL for argument 3 ('mass').

I can see false-positives being an issue. e.g. one obvious example springs to

'memset' is always called with 0 for argument 2 ('value').

But in general I think this would be a useful scenario to check for - it
certainly feels similar to 'function X is never called' or 'conditional
expression is constant' classes of warnings.

Is this something that would be viable for the static analyser to check for? 


Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list