[PATCH] D46190: For an ODR declaration, set the 'Used' bit on its associated declarations.

Carlos Alberto Enciso via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 30 04:05:29 PDT 2018


CarlosAlbertoEnciso added a comment.

My initial approach was based on the following test case:

  void Bar() {
    typedef int I_Ref;
    I_Ref var_bar;
  }
  
  void Foo() {
    typedef int I_Used;
    I_Used var_foo;
    var_foo = 2;
  }
  
  void Test() {
    Foo();
  }

and the generated AST looks like:

  |-FunctionDecl Bar 'void ()'
  |   |-DeclStmt
  |   | `-TypedefDecl referenced I_Ref 'int'
  |   |-DeclStmt
  |     `-VarDecl var_bar 'I_Ref':'int'
  
  |-FunctionDecl used Foo 'void ()'
  |   |-DeclStmt
  |   | `-TypedefDecl referenced I_Used 'int'
  |   |-DeclStmt
  |   | `-VarDecl used var_foo 'I_Used':'int'

The typedef 'I_Ref' is marked as 'referenced' due to its association with 'var_bar'.
The typedef 'I_Used' is marked as 'referenced' despite that its association with 'var_foo' which is 'used'
Both 'typedefs' are marked as 'referenced'.

With the intended patch, the AST looks like:

  |-FunctionDecl Bar 'void ()'
  |   |-DeclStmt
  |   | `-TypedefDecl referenced I_Ref 'int'
  |   `-DeclStmt
  |     `-VarDecl var_bar 'I_Ref':'int'
  
  |-FunctionDecl used Foo 'void ()'
  |   |-DeclStmt
  |   | `-TypedefDecl used I_Used 'int'
  |   |-DeclStmt
  |   | `-VarDecl used var_foo 'I_Used':'int'

The typedef 'I_Ref' is marked as 'referenced'.
The typedef 'I_Used' is marked as 'used'.


Repository:
  rC Clang

https://reviews.llvm.org/D46190





More information about the cfe-commits mailing list