[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
Fri Apr 27 07:37:57 PDT 2018


CarlosAlbertoEnciso created this revision.
CarlosAlbertoEnciso added reviewers: rsmith, erichkeane, probinson, dblaikie.
CarlosAlbertoEnciso added a project: clang.
Herald added a subscriber: aprantl.

The following submission under review

https://reviews.llvm.org/D44826

introduced an option to warn on unused 'using declarations'.

But it can't detect cases like

  namespace nsp {
    void foo();
    int var;
  }using var
  
  using foo;     <-- warning
  using var;     <-- MISSING warning  
  
  void bar() {
    using foo;     <-- warning
    using var;     <-- warning
  }
  
  void bar() {
    nsp::var = 1;
  }

One of the reviewers (dblaikie) mentioned the possible cause for that limitation.

  You mention a missed case in the description - where the target of a using decl is
  used and that causes the unused-using not to warn about the using decl? That
  seems like a big limitation. Does that mean the 'used' bit is being tracked in the
  wrong place, on the target of the using decl instead of on the using decl itself?

When a declaration is found to be ODR, only its associated 'Used' bit is set.

This patch, traverse its associated declarations and sets the 'Used' bit. The goal
is to create additional information to help in the reduction of the debug information
size, which is affected by extra generation of 'non-used' declarations.

Note:

To solve the debug information issue (size), there are 3 pieces of
work:

- Set the 'Used' bit recursively. This patch.
- Review the - Wunused-usings and -Wunused-local-typedefs implementation to take advantage of new 'Used' settings.
- Do not generate debug information for the unused using

Thanks for your view on this issue and on the general approach.


Repository:
  rC Clang

https://reviews.llvm.org/D46190

Files:
  include/clang/Sema/Sema.h
  include/clang/Sema/SemaInternal.h
  lib/AST/ASTDumper.cpp
  lib/AST/DeclBase.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaLambda.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Sema/SemaStmt.cpp
  lib/Sema/SemaStmtAsm.cpp
  test/Frontend/float16.cpp
  test/Misc/ast-dump-attr.cpp
  test/Misc/ast-dump-color.cpp
  test/PCH/cxx-templates.cpp
  test/SemaCXX/used_class_struct_union.cpp
  test/SemaCXX/used_enum.cpp
  test/SemaCXX/used_goto.cpp
  test/SemaCXX/used_pointer.cpp
  test/SemaCXX/used_template.cpp
  test/SemaCXX/used_typedef.cpp
  test/SemaCXX/used_using.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46190.144332.patch
Type: text/x-patch
Size: 67229 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180427/77fd743c/attachment-0001.bin>


More information about the cfe-commits mailing list