[PATCH] D20054: Fix spurious warnings about unused private field
ogoffart created this revision. ogoffart added reviewers: cfe-commits, djasper. If the address of a field is taken as a pointer to member, we should not warn that the field is not used. Normaly, yse of fields are done from MemberExpr, but in case of pointer to member, it is in a DeclRefExpr http://reviews.llvm.org/D20054 Files: lib/Sema/SemaExpr.cpp test/SemaCXX/warn-unused-private-field.cpp Index: test/SemaCXX/warn-unused-private-field.cpp === --- test/SemaCXX/warn-unused-private-field.cpp +++ test/SemaCXX/warn-unused-private-field.cpp @@ -128,6 +128,7 @@ int *use = &by_reference_; int test[2]; test[as_array_index_] = 42; +int EverythingUsed::*ptr = &EverythingUsed::by_pointer_to_member_; } template @@ -142,6 +143,7 @@ int by_template_function_; int as_array_index_; int by_initializer_; + int by_pointer_to_member_; }; class HasFeatureTest { Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -1736,10 +1736,12 @@ !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, E->getLocStart())) recordUseOfEvaluatedWeak(E); - // Just in case we're building an illegal pointer-to-member. - FieldDecl *FD = dyn_cast(D); - if (FD && FD->isBitField()) -E->setObjectKind(OK_BitField); + if (FieldDecl *FD = dyn_cast(D)) { +UnusedPrivateFields.remove(FD); +// Just in case we're building an illegal pointer-to-member. +if (FD->isBitField()) + E->setObjectKind(OK_BitField); + } return E; } Index: test/SemaCXX/warn-unused-private-field.cpp === --- test/SemaCXX/warn-unused-private-field.cpp +++ test/SemaCXX/warn-unused-private-field.cpp @@ -128,6 +128,7 @@ int *use = &by_reference_; int test[2]; test[as_array_index_] = 42; +int EverythingUsed::*ptr = &EverythingUsed::by_pointer_to_member_; } template @@ -142,6 +143,7 @@ int by_template_function_; int as_array_index_; int by_initializer_; + int by_pointer_to_member_; }; class HasFeatureTest { Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -1736,10 +1736,12 @@ !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, E->getLocStart())) recordUseOfEvaluatedWeak(E); - // Just in case we're building an illegal pointer-to-member. - FieldDecl *FD = dyn_cast(D); - if (FD && FD->isBitField()) -E->setObjectKind(OK_BitField); + if (FieldDecl *FD = dyn_cast(D)) { +UnusedPrivateFields.remove(FD); +// Just in case we're building an illegal pointer-to-member. +if (FD->isBitField()) + E->setObjectKind(OK_BitField); + } return E; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D20054: Fix spurious warnings about unused private field
djasper accepted this revision. djasper added a comment. This revision is now accepted and ready to land. Looks good. http://reviews.llvm.org/D20054 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D20054: Fix spurious warnings about unused private field
This revision was automatically updated to reflect the committed changes. Closed by commit rL268895: Fix spurious warnings about unused private field (authored by ogoffart). Changed prior to commit: http://reviews.llvm.org/D20054?vs=56514&id=56530#toc Repository: rL LLVM http://reviews.llvm.org/D20054 Files: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/SemaCXX/warn-unused-private-field.cpp Index: cfe/trunk/test/SemaCXX/warn-unused-private-field.cpp === --- cfe/trunk/test/SemaCXX/warn-unused-private-field.cpp +++ cfe/trunk/test/SemaCXX/warn-unused-private-field.cpp @@ -128,6 +128,7 @@ int *use = &by_reference_; int test[2]; test[as_array_index_] = 42; +int EverythingUsed::*ptr = &EverythingUsed::by_pointer_to_member_; } template @@ -142,6 +143,7 @@ int by_template_function_; int as_array_index_; int by_initializer_; + int by_pointer_to_member_; }; class HasFeatureTest { Index: cfe/trunk/lib/Sema/SemaExpr.cpp === --- cfe/trunk/lib/Sema/SemaExpr.cpp +++ cfe/trunk/lib/Sema/SemaExpr.cpp @@ -1736,10 +1736,12 @@ !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, E->getLocStart())) recordUseOfEvaluatedWeak(E); - // Just in case we're building an illegal pointer-to-member. - FieldDecl *FD = dyn_cast(D); - if (FD && FD->isBitField()) -E->setObjectKind(OK_BitField); + if (FieldDecl *FD = dyn_cast(D)) { +UnusedPrivateFields.remove(FD); +// Just in case we're building an illegal pointer-to-member. +if (FD->isBitField()) + E->setObjectKind(OK_BitField); + } return E; } Index: cfe/trunk/test/SemaCXX/warn-unused-private-field.cpp === --- cfe/trunk/test/SemaCXX/warn-unused-private-field.cpp +++ cfe/trunk/test/SemaCXX/warn-unused-private-field.cpp @@ -128,6 +128,7 @@ int *use = &by_reference_; int test[2]; test[as_array_index_] = 42; +int EverythingUsed::*ptr = &EverythingUsed::by_pointer_to_member_; } template @@ -142,6 +143,7 @@ int by_template_function_; int as_array_index_; int by_initializer_; + int by_pointer_to_member_; }; class HasFeatureTest { Index: cfe/trunk/lib/Sema/SemaExpr.cpp === --- cfe/trunk/lib/Sema/SemaExpr.cpp +++ cfe/trunk/lib/Sema/SemaExpr.cpp @@ -1736,10 +1736,12 @@ !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, E->getLocStart())) recordUseOfEvaluatedWeak(E); - // Just in case we're building an illegal pointer-to-member. - FieldDecl *FD = dyn_cast(D); - if (FD && FD->isBitField()) -E->setObjectKind(OK_BitField); + if (FieldDecl *FD = dyn_cast(D)) { +UnusedPrivateFields.remove(FD); +// Just in case we're building an illegal pointer-to-member. +if (FD->isBitField()) + E->setObjectKind(OK_BitField); + } return E; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits