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

George Karpenkov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 9 13:49:13 PST 2017

george.karpenkov added a comment.

> I'm curious if the crash would turn into an assertion failure during getRawSVal() after https://reviews.llvm.org/D38801 is committed.

I guess we would see?

> If this problem is fixed on the checker side (it probably should be - the checker , we can probably put stronger asserts onto types suitable for symbols.

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`.

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()) {
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.


More information about the cfe-commits mailing list