Many analyses are missing in tools/clang/lib/Analysis/<br><br><div class="gmail_quote">2011/10/7 Don Quixote de la Mancha <span dir="ltr"><<a href="mailto:quixote@dulcineatech.com">quixote@dulcineatech.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I've been looking around for an analysis I could add to clang, but I<br>
used Xcode 4.1's clang to test this, which only has CLang 2.1. Could<br>
someone please check whether the current SVN catches this? I would<br>
check myself but I am having some trouble getting the current SVN to<br>
build. It's not the source code but some arcane problems with the<br>
configure shell scripts. If I can't figure out my configure problem<br>
soon I will ask about it here.<br>
<br>
If the current SVN does not catch this, I'd like to do the work to add<br>
the analysis myself. I've been following the list for a couple weeks<br>
and understand now what would be expected of my code for it to be<br>
accepted. I will open a Bugzilla bug to track my progress.<br>
<br>
You NEVER EVER want to do the following:<br>
<br>
if ( condition )<br>
assert( must_be_true );<br>
<br>
following_line();<br>
<br>
If NDEBUG is defined as for a release or profile build, you'll get the<br>
following in your preprocessed code, which will be very hard to debug:<br>
<br>
if ( condition )<br>
following_line();<br>
<br>
If you really must insist on putting an assert as the only line within<br>
an if statement, you MUST place it in a Basic Block:<br>
<br>
if ( condition ){<br>
assert( must_be_true );<br>
}<br>
<br>
Even better is to make the if statement part of the assert:<br>
<br>
assert( condition && must_be_true );<br>
<br>
Back in the day I wrote a new library to replace my client's old one.<br>
To test that my new library got the same results as his old one, he<br>
asked me to link his executable with both his old and my new library,<br>
and to compare the results of all the calls to each library. I don't<br>
recall why anymore but I actually made the mistake, then spent all day<br>
long tracking down my bug, as the executables and both libraries were<br>
very complex.<br>
<br>
I'm running Mac OS X Snow Leopard 10.6.8 on a MacBook Pro, Model<br>
Identifier MacBookPro1,1 (32-bit Core Duo, NOT 64-bit Core 2 Duo).<br>
<br>
$ clang --version<br>
Apple clang version 2.1 (tags/Apple/clang-163.7.1) (based on LLVM 3.0svn)<br>
Target: i386-apple-darwin10.8.0<br>
Thread model: posix<br>
<br>
$ gcc --version<br>
i686-apple-darwin10-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc.<br>
build 5658) (LLVM build 2335.15.00)<br>
<br>
$ gcc --pedantic -Wall -c assert_within_if.c<br>
<br>
This compile succeeds without any warnings.<br>
<br>
$ clang --analyze assert_within_if.c<br>
<br>
CLang doesn't print anything to the terminal. assert_within_if.plist<br>
doesn't contain any diagnostics.<br>
<br>
====== Cut Here ======<br>
/* assert_within_if.c */<br>
#include <stdlib.h><br>
#include <assert.h><br>
<br>
int assert_within_if( int flag, int *pointer );<br>
<br>
int assert_within_if( int flag, int *pointer )<br>
{<br>
int result = 0;<br>
<br>
if ( flag )<br>
assert( NULL != pointer );<br>
<br>
result = *pointer;<br>
<br>
return result;<br>
}<br>
<br>
====== Cut Here =====<br>
<br>
Ever Faithful,<br>
<br>
Don Quixote<br>
<font color="#888888">--<br>
Don Quixote de la Mancha<br>
Dulcinea Technologies Corporation<br>
Software of Elegance and Beauty<br>
<a href="http://www.dulcineatech.com" target="_blank">http://www.dulcineatech.com</a><br>
<a href="mailto:quixote@dulcineatech.com">quixote@dulcineatech.com</a><br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</font></blockquote></div><br>