[PATCH] D13099: [Analyzer] Don’t invalidate CXXThis when conservatively evaluating const methods (PR 21606)

Sean Eveson via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 23 07:25:58 PDT 2015

seaneveson created this revision.
seaneveson added a subscriber: cfe-commits.

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

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?


Sean Eveson
SN Systems - Sony Computer Entertainment Group



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13099.35496.patch
Type: text/x-patch
Size: 2600 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150923/0b137f26/attachment.bin>

More information about the cfe-commits mailing list