Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 370887

Summary: CPPVariableReadWriteFlags.getReadWriteFlags returns incorrect result for method call
Product: [Tools] CDT Reporter: Sergey Prigogin <eclipse.sprigogin>
Component: cdt-coreAssignee: Sergey Prigogin <eclipse.sprigogin>
Status: RESOLVED FIXED QA Contact: Doug Schaefer <cdtdoug>
Severity: normal    
Priority: P3 CC: cdtdoug, malaperle
Version: 8.0Flags: eclipse.sprigogin: iplog-
mschorn.eclipse: review+
Target Milestone: 8.1.0   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed fix eclipse.sprigogin: iplog-, mschorn.eclipse: review+

Description Sergey Prigogin CLA 2012-02-07 15:58:34 EST
In the following code

class A {
public:
  void m();
};

void test() {
  A a;
  a.m();
}

CPPVariableReadWriteFlags.getReadWriteFlags returns READ for 'a' in a.m(). It should return WRITE since the method m is not declared const.
Comment 1 Sergey Prigogin CLA 2012-02-07 20:59:59 EST
Created VariableReadWriteFlagsTest, which uncovered two more problems:

1.
int a = 1;  READ | WRITE instead of expected WRITE

2.
struct A { int x; };

void test() {
  A a;
  a.x = 1;  READ instead of expected WRITE
};
Comment 2 Sergey Prigogin CLA 2012-02-07 23:48:00 EST
Created attachment 210705 [details]
Proposed fix

Markus,
Could you please review the attached fix for the function call issue. Thanks.
Comment 3 Markus Schorn CLA 2012-02-08 02:57:16 EST
Comment on attachment 210705 [details]
Proposed fix

Looks good to me.
Comment 4 Markus Schorn CLA 2012-02-08 03:21:08 EST
(In reply to comment #3)
> Comment on attachment 210705 [details]
> Proposed fix
> Looks good to me.

It just came to my mind that you may have to check the indirection of using the variable. The indirection is passed around as an argument and is modified when one of the operators [], *, & is encountered. Currently it is not adjusted when the operator -> is found.

void test() {
  A* ap;
  A  a;
  (*ap).m();  // read access to ap
  ap->m();    // read access to ap
  (&a)->m();  // read/write access to a
}
Comment 5 Sergey Prigogin CLA 2012-02-08 20:31:07 EST
Fixed in master.
Comment 6 CDT Genie CLA 2012-02-29 13:24:39 EST
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 370887 - CPPVariableReadWriteFlags.getReadWriteFlags returns
    incorrect results.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=61e9d699ba21775a06748d2fbf3183d064411c37
Comment 7 CDT Genie CLA 2012-02-29 13:24:41 EST
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 370887 - CPPVariableReadWriteFlags.getReadWriteFlags returns
    incorrect results.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=61e9d699ba21775a06748d2fbf3183d064411c37
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 370887 - CPPVariableReadWriteFlags.getReadWriteFlags returns
    incorrect results.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=61e9d699ba21775a06748d2fbf3183d064411c37