[PATCH] D67740: [Consumed] Refactor and improve diagnostics

Nicholas Allegra via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 18 16:31:19 PDT 2019


comex created this revision.
comex added a reviewer: dblaikie.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As suggested by FIXME comments, fix commented-out diagnostic in Sema and remove the equivalent check within the consumed analysis.

The diagnostic in question is the warning for using `param_typestate` and `return_typestate` with a type that is not consumable.

There were several FIXME comments about the same issue; the most detailed was before the commented-out check:

  // FIXME: This check is currently being done in the analysis.  It can be
  //        enabled here only after the parser propagates attributes at
  //        template specialization definition, not declaration.

I was confused what this meant.  After investigating, I think it actually refers to the fact that attributes are parsed only once for a template, and are not re-parsed when the template is instantiated.  If I'm right, the issue actually has nothing to do with template specializations or with definitions versus declarations.  I could be missing something, though, so please let me know if there's a case I'm not thinking of.  I did add some template specializations as test cases (for both class and function templates).

This patch addresses the issue by moving the diagnostic to a function which is called from both parsing and template instantiation, similar to what's already done with some other attributes.

The analysis version of the check didn't always work, and only applied to `return_typestate` rather than `param_typestate` (even though both had commented-out Sema checks); therefore, the fixed code may produce warnings that didn't appear before.

Also, add a new diagnostic for when the `set_typestate` or `test_typestate` attribute is applied to a constructor or static method; previously Clang would ignore it or crash, respectively.


Repository:
  rC Clang

https://reviews.llvm.org/D67740

Files:
  include/clang/Analysis/Analyses/Consumed.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Analysis/Consumed.cpp
  lib/Sema/AnalysisBasedWarnings.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/SemaCXX/warn-consumed-parsing.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67740.220770.patch
Type: text/x-patch
Size: 14315 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190918/e6002ec8/attachment-0001.bin>


More information about the cfe-commits mailing list