[cfe-commits] r168843 - in /cfe/trunk: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp test/Analysis/misc-ps-region-store.cpp

Ted Kremenek kremenek at apple.com
Wed Nov 28 22:20:50 PST 2012


On Nov 28, 2012, at 5:03 PM, Eli Friedman <eli.friedman at gmail.com> wrote:

> On Wed, Nov 28, 2012 at 4:50 PM, Ted Kremenek <kremenek at apple.com> wrote:
>> Author: kremenek
>> Date: Wed Nov 28 18:50:20 2012
>> New Revision: 168843
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=168843&view=rev
>> Log:
>> Correctly handle IntegralToBool casts in C++ in the static analyzer.  Fixes <rdar://problem/12759044>.
>> 
>> Modified:
>>    cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
>>    cfe/trunk/test/Analysis/misc-ps-region-store.cpp
>> 
>> Modified: cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp?rev=168843&r1=168842&r2=168843&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (original)
>> +++ cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp Wed Nov 28 18:50:20 2012
>> @@ -101,6 +101,12 @@
>>   if (!isa<nonloc::ConcreteInt>(val))
>>     return UnknownVal();
>> 
>> +  // Handle casts to a boolean type.
>> +  if (castTy->isBooleanType()) {
>> +    bool b = cast<nonloc::ConcreteInt>(val).getValue().getBoolValue();
>> +    return makeTruthVal(b, castTy);
>> +  }
> 
> General observation: in Sema and CodeGen, we try to avoid figuring out
> what a cast means based on the destination type of a cast; using
> CastKinds generally makes code both more clear and avoids this sort of
> bug.

I had the same thought as well when I made this change.  In order to better do this we will need to rework the casting logic here to incorporate the CastKind, but I'm starting to think that this is the right approach.



More information about the cfe-commits mailing list