[cfe-commits] r125640 - in /cfe/trunk:	include/clang/Basic/DiagnosticSemaKinds.td	include/clang/Sema/Sema.h lib/Sema/SemaChecking.cpp	lib/Sema/SemaExpr.cpp test/Analysis/out-of-bounds.c	test/Sema/array-bounds.c
    Ted Kremenek 
    kremenek at apple.com
       
    Thu Feb 17 09:13:29 PST 2011
    
    
  
On Feb 17, 2011, at 3:59 AM, Frits van Bommel wrote:
> Actually, all the examples Hans gave use compile-time constants as
> conditions. If you know the array bounds, you should also be able to
> figure out the values of those conditions. So it might be interesting
> to just look 'up' the AST for conditions that are statically known to
> be false, and suppress the warning in that case.
> 
> Of course, there are also more interesting cases like
> 
>  int A[10 + SomethingConstant];
>  if (SomethingConstant && someFunction())
>    A[10] = 0;
> 
> where the condition isn't necessarily a constant, but it being true
> (or false, if we're in an 'else') does imply something about a
> constant (in this case, that it's non-zero).
This is the purview of the static analyzer, which already can flag these kinds of buffer overflows.  The analysis it employs is path-sensitive, handles aliasing, etc.  The compiler warning we are talking about here is mainly to cover the dirt simple cases that should never appear in code.
    
    
More information about the cfe-commits
mailing list