Dear All,
I would like to propose a patch that prevents the invalidation of ‘this’ when a method is const; fixing the test case given below, taken from PR 21606 (https://llvm.org/bugs/show_bug.cgi?id=21606).
struct s1 { void g(const int *i) const; }; struct s2 { void f(int *i) { m_i = i; m_s.g(m_i); // Diagnostic goes away if you remove this line. if (m_i) *i = 42; } int *m_i; s1 m_s; }; int main() { s2().f(0); }
Mutable members of the object are a special case and are still invalidated; if a mutable member is invalidated the entire object will be invalidated because invalidateRegions invalidates the base region.
Whilst the patch fixes the test case from PR 21606, the same false-positive occurs when the method ‘s1::g’ isn’t const; i.e. when ‘s2::f’ is called, subsequently calling ‘s1::g’, the memory region for the instance of s1 is (correctly) invalidated. However, the containing memory region (the instance of s2) is also invalidated, which I think is overly conservative.
Why is the base region (in this case: S2) invalidated? Would it be acceptable to change invalidation to modify the given region and not the base region when
- invalidating only the mutable members for a const method call?
- invalidating an object as a result of conservative ‘method call’ evaluations?
Regards,
Sean Eveson
SN Systems - Sony Computer Entertainment Group