[cfe-dev] Working on my first patch for the static analyzer, few questions.

Richard Trieu rtrieu at google.com
Fri Dec 5 19:26:37 PST 2014


On Wed, Dec 3, 2014 at 5:30 PM, Emily Bellows <emily.a.bellows at gmail.com>
wrote:

> Hi everyone,
>
> I’ve been writing one of the potential checkers from the clang-analyzer
> website. It detects calls to member functions before all base classes are
> initialized in a constructor initializer list, which the standard says is
> undefined behavior (C++11 12.6.2.p13.)
>
> My checker finds these cases fine, it runs perfectly on the examples given
> from the standard, and I ran it on the LLVM codebase and it even found
> three instances of this (calls to allocHungoffUses in
> lib/IR/Instructions.cpp if you’re curious, lines 89, 196, and 3579.)
>
> Questions,
>
> 1. Does this seem like it might be better as a compiler warning?


This warning does seem well suited for including within the compiler.
Clang already detects other uninitialized uses in field initializers.  The
code for the Clang warnings is in UninitializedFieldVisitor in
lib/Sema/SemaDeclCXX.cpp


> Right now the checker only uses checkASTDecl, and so is not path
> sensitive. It could be made path sensitive in the future to detect code
> indirectly using ’this’, however.
>
> 2. Does the ReportBug method look sensible? Given the check is not path
> sensitive, I couldn’t quite figure out what the PathDiagnosticLocation
> class is supposed to represent, or whether or not I’m using it correctly
> because most of the constructors take an ExplodedNode. The error messages
> my checker gives out looks reasonable to me, so it works, but I’m not sure
> if it’s idiomatic usage of the reporting API.
>
> Example error:
>
> /Users/emilybellows/Workspace/llvm/lib/IR/Instructions.cpp:89:17: warning:
> Method called before all bases were initialized
>                 allocHungoffUses(PN.getNumOperands()),
> PN.getNumOperands()),
>                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> 3. Who is the code owner of this part of clang for when I end up
> submitting the patch. Is the owner Chris Lattner by default? And does this
> patch look ready to submit to cfe-commits?
>
> I welcome any other comments too, this is my first time working with
> either LLVM or Clang, and my first time contributing code to an open source
> project.
>
> Thanks,
> Emily
>
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141205/b6f48ebd/attachment.html>


More information about the cfe-dev mailing list