[PATCH] D39862: [analyzer] do not crash when trying to convert an APSInt to an unexpected type

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 9 23:29:28 PST 2017

NoQ added a comment.

In https://reviews.llvm.org/D39862#921075, @george.karpenkov wrote:

> Of course I'm new, but I disagree with this statement: in order to have a robust API, the function should not crash, unless the caller violates an explicit precondition.
>  `getSVal` is just a function for getting a symbolic value for a particular statement, it seems totally valid to query it for an expression which type is `void`.

Not for an expression - this overload retrieves a value stored in the memory region. I think that we should inform the checker's author when he tries to interpret the value in memory as a void value, because i believe that in pretty much all cases he has a better type to provide.

Comment at: lib/StaticAnalyzer/Core/ProgramState.cpp:265
+  // to the type of T, which is not always the case (e.g. for void).
+  if (!T.isNull() && (T->isIntegralOrEnumerationType() || Loc::isLocType(T))) {
     if (SymbolRef sym = V.getAsSymbol()) {
george.karpenkov wrote:
> NoQ wrote:
> > If a type is an integral or enumeration type or a Loc type, then it is definitely not null.
> But the check itself will crash if the type is null.
Whoops right sry.



More information about the cfe-commits mailing list