[PATCH] D17627: Fix false positives for for-loop-analysis warning

Richard Trieu via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 25 21:25:53 PST 2016


rtrieu added a comment.

This seems rather strange.  Usually, a OpaqueValueExpr will hold an expression that is held elsewhere in the AST.  However, in this case, it appears that all the references to --i are all behind OpaqueValueExpr's, so they aren't processed.

  `-CStyleCastExpr 0x5675d30 <line:11:5, col:19> 'void' <ToVoid>
    `-PseudoObjectExpr 0x5675d00 <col:11, col:19> 'id':'id'
      |-ObjCSubscriptRefExpr 0x5675c90 <col:11, col:19> '<pseudo-object type>' lvalue Kind=ArraySubscript GetterForArray="(null)" SetterForArray="(null)
      | |-OpaqueValueExpr 0x5675c50 <col:11> 'MyArray *'
      | | `-ImplicitCastExpr 0x5675bf0 <col:11> 'MyArray *' <LValueToRValue>
      | |   `-DeclRefExpr 0x5675b80 <col:11> 'MyArray *' lvalue Var 0x56756d0 'test' 'MyArray *'
      | `-OpaqueValueExpr 0x5675c70 <col:16, col:18> 'unsigned int'
      |   `-UnaryOperator 0x5675bd0 <col:16, col:18> 'unsigned int' prefix '--'
      |     `-DeclRefExpr 0x5675ba8 <col:18> 'unsigned int' lvalue Var 0x56759e0 'i' 'unsigned int'
      |-OpaqueValueExpr 0x5675c50 <col:11> 'MyArray *'
      | `-ImplicitCastExpr 0x5675bf0 <col:11> 'MyArray *' <LValueToRValue>
      |   `-DeclRefExpr 0x5675b80 <co        `-CStyleCastExpr 0x5675d30 <line:11:5, col:19> 'void' <ToVoid>
    `-PseudoObjectExpr 0x5675d00 <col:11, col:19> 'id':'id'
      |-ObjCSubscriptRefExpr 0x5675c90 <col:11, col:19> '<pseudo-object type>' lvalue Kind=ArraySubscript GetterForArray="(null)" SetterForArray="(null)
      | |-OpaqueValueExpr 0x5675c50 <col:11> 'MyArray *'
      | | `-ImplicitCastExpr 0x5675bf0 <col:11> 'MyArray *' <LValueToRValue>
      | |   `-DeclRefExpr 0x5675b80 <col:11> 'MyArray *' lvalue Var 0x56756d0 'test' 'MyArray *'
      | `-OpaqueValueExpr 0x5675c70 <col:16, col:18> 'unsigned int'
      |   `-UnaryOperator 0x5675bd0 <col:16, col:18> 'unsigned int' prefix '--'
      |     `-DeclRefExpr 0x5675ba8 <col:18> 'unsigned int' lvalue Var 0x56759e0 'i' 'unsigned int'
      |-OpaqueValueExpr 0x5675c50 <col:11> 'MyArray *'
      | `-ImplicitCastExpr 0x5675bf0 <col:11> 'MyArray *' <LValueToRValue>
      |   `-DeclRefExpr 0x5675b80 <col:11> 'MyArray *' lvalue Var 0x56756d0 'test' 'MyArray *'
      |-OpaqueValueExpr 0x5675c70 <col:16, col:18> 'unsigned int'
      | `-UnaryOperator 0x5675bd0 <col:16, col:18> 'unsigned int' prefix '--'
      |   `-DeclRefExpr 0x5675ba8 <col:18> 'unsigned int' lvalue Var 0x56759e0 'i' 'unsigned int'
      `-ObjCMessageExpr 0x5675cc8 <col:11> 'id':'id' selector=objectAtIndexedSubscript:
        |-OpaqueValueExpr 0x5675c50 <col:11> 'MyArray *'
        | `-ImplicitCastExpr 0x5675bf0 <col:11> 'MyArray *' <LValueToRValue>
        |   `-DeclRefExpr 0x5675b80 <col:11> 'MyArray *' lvalue Var 0x56756d0 'test' 'MyArray *'
        `-OpaqueValueExpr 0x5675c70 <col:16, col:18> 'unsigned int'
          `-UnaryOperator 0x5675bd0 <col:16, col:18> 'unsigned int' prefix '--'
            `-DeclRefExpr 0x5675ba8 <col:18> 'unsigned int' lvalue Var 0x56759e0 'i' 'unsigned int'l:11> 'MyArray *' lvalue Var 0x56756d0 'test' 'MyArray *'
      |-OpaqueValueExpr 0x5675c70 <col:16, col:18> 'unsigned int'
      | `-UnaryOperator 0x5675bd0 <col:16, col:18> 'unsigned int' prefix '--'
      |   `-DeclRefExpr 0x5675ba8 <col:18> 'unsigned int' lvalue Var 0x56759e0 'i' 'unsigned int'
      `-ObjCMessageExpr 0x5675cc8 <col:11> 'id':'id' selector=objectAtIndexedSubscript:
        |-OpaqueValueExpr 0x5675c50 <col:11> 'MyArray *'
        | `-ImplicitCastExpr 0x5675bf0 <col:11> 'MyArray *' <LValueToRValue>
        |   `-DeclRefExpr 0x5675b80 <col:11> 'MyArray *' lvalue Var 0x56756d0 'test' 'MyArray *'
        `-OpaqueValueExpr 0x5675c70 <col:16, col:18> 'unsigned int'
          `-UnaryOperator 0x5675bd0 <col:16, col:18> 'unsigned int' prefix '--'
            `-DeclRefExpr 0x5675ba8 <col:18> 'unsigned int' lvalue Var 0x56759e0 'i' 'unsigned int'

Typically, we skip OpaqueValueExpr so that we don't process the same expression multiple times.  I don't know enough about Objective C to know whether this is the intended pattern or an oversight.  Instead of visiting all the sub-expressions of OpaqueValueExpr's, try to make a tighter visitor to avoid repeating work.  I think checking the sub-expressions of ObjCSubscriptRefExpr, and looking through the OpaqueValueExpr's there would be the best way for this.


http://reviews.llvm.org/D17627





More information about the cfe-commits mailing list