[PATCH] D134815: [Sema] print more readable identifier of anonymous struct of -Wconsumed

YingChi Long via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 28 10:09:28 PDT 2022


inclyc created this revision.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
inclyc published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Working in D133574 <https://reviews.llvm.org/D133574> we discovered -Wconsumed print '' with anonymous
class/struct. After this patch we give a line number, file name of
anonymous struct/class declaration.

Example:

  struct S {
    struct {
      __attribute__((callable_when(consumed))) void func();
    } s;
  };



  local/anoy-consume.cpp:3:20: warning: consumed analysis attribute is attached to member of class 'S::(unnamed struct at local/anoy-consume.cpp:2:3)' which isn't marked as consumable [-Wconsumed]
      __attribute__((callable_when(consumed))) void func();
                     ^
  1 warning generated.

Link: https://reviews.llvm.org/D133574#3817743
Link: https://godbolt.org/z/16vP3voTW


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134815

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaCXX/warn-consumed-parsing.cpp


Index: clang/test/SemaCXX/warn-consumed-parsing.cpp
===================================================================
--- clang/test/SemaCXX/warn-consumed-parsing.cpp
+++ clang/test/SemaCXX/warn-consumed-parsing.cpp
@@ -62,5 +62,10 @@
       Status {
 };
 
-
-
+class Anonymous {
+  struct /* anonymous */ {
+    void callableWhen()   CALLABLE_WHEN("unconsumed"); // expected-warning-re {{consumed analysis attribute is attached to member of class 'Anonymous::(unnamed struct at {{.*}})' which isn't marked as consumable}}
+    void consumes()       SET_TYPESTATE(consumed); // expected-warning-re {{consumed analysis attribute is attached to member of class 'Anonymous::(unnamed struct at {{.*}})' which isn't marked as consumable}}
+    bool testUnconsumed() TEST_TYPESTATE(consumed); // expected-warning-re {{consumed analysis attribute is attached to member of class 'Anonymous::(unnamed struct at {{.*}})' which isn't marked as consumable}}
+  } anonymous;
+};
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -1223,7 +1223,8 @@
 
   if (const CXXRecordDecl *RD = ThisType->getAsCXXRecordDecl()) {
     if (!RD->hasAttr<ConsumableAttr>()) {
-      S.Diag(AL.getLoc(), diag::warn_attr_on_unconsumable_class) << RD;
+      S.Diag(AL.getLoc(), diag::warn_attr_on_unconsumable_class)
+          << S.Context.getTagDeclType(RD);
 
       return false;
     }
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -212,6 +212,8 @@
   of FAM-like arrays.
 - Clang now correctly diagnoses a warning when defercencing a void pointer in C mode.
   This fixes `Issue 53631 <https://github.com/llvm/llvm-project/issues/53631>`_
+- Clang now prints more readable identifier for anonymous class/struct of
+  ``-Wconsumed``.
 
 Non-comprehensive list of changes in this release
 -------------------------------------------------


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134815.463600.patch
Type: text/x-patch
Size: 2070 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220928/3d29e304/attachment.bin>


More information about the cfe-commits mailing list