[analyzer] Should we invalidate the `this` pointer?

Hi all,

I recently encountered a assertion failure as shown below.

Assertion !InitValWithAdjustments.getAs() || Loc::isLocType(Result->getType()) || Result->getType()->isMemberPointerType()’ failed`

The code that will trigger this assertion failed.

This assertion is pretty fundamental. Invalidation, if done correctly, should not have triggered it - after all, invalidation could occur for any other reason, not necessarily because of loop widening.

Invalidation of this-region contents (that is, not of the CXXThisObjectRegion of the current stack frame, but of the actual this-region which is a pointee of the CXXThisObjectRegion) sounds reasonable if the region is modified within the loop - which is going to often be the case.

Hi Artem,

Thank you for your explanation1 You are right, invalidation of the region
contents of the class object is correct and common. However this pointer i
s no-lvalue and it’s a prvalue expression in c++17. IMHO, invalidation of CXXThisObjectRegion is incorrect and violates the C++ standard.

Given the code below:

Yeah, this looks pretty broken. One does not simply overwrite his this-pointer using valid C++. Feel free to fix :slight_smile: