summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/singlevalfields.cxx
AgeCommit message (Collapse)Author
2022-06-14better solution for ignoreLocation for tree-wide pluginsNoel Grandin
Change-Id: I7336003e038781d4ef50380fa49f66b5ff19379f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135589 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-03-28Adapt loplugin:singlevalfields to AtomicExprStephan Bergmann
> AtomicExpr 0xcb01120 'std::__detail::__platform_wait_t':'int' > |-ImplicitCastExpr 0xcb01108 'std::__detail::__platform_wait_t *' <LValueToRValue> > | `-MemberExpr 0xcb01048 'std::__detail::__platform_wait_t *' lvalue ->_M_addr 0xcafd9c8 > | `-CXXThisExpr 0xcb01038 '__waiter_base<_Tp> *' implicit this > |-IntegerLiteral 0xcb01098 'int' 5 > `-IntegerLiteral 0xcb01078 'int' 1 > AtomicExpr 0xd1e2d08 'std::__detail::__platform_wait_t':'int' > |-ImplicitCastExpr 0xd1e2cf0 'std::__detail::__platform_wait_t *' <LValueToRValue> > | `-MemberExpr 0xd1e2cc0 'std::__detail::__platform_wait_t *' lvalue ->_M_addr 0xcb02bf8 > | `-CXXThisExpr 0xd1e2cb0 'struct std::__detail::__waiter_base<struct std::__detail::__waiter_pool> *' implicit this > |-IntegerLiteral 0xcb01098 'int' 5 > `-IntegerLiteral 0xcb01078 'int' 1 > error: 'error' diagnostics seen but not expected: > File ~/gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/12.0.1/../../../../include/c++/12.0.1/bits/atomic_wait.h Line 312: oh dear, what can the matter be? [loplugin:singlevalfields] > File ~/gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/12.0.1/../../../../include/c++/12.0.1/bits/atomic_wait.h Line 312: oh dear, what can the matter be? [loplugin:singlevalfields] Change-Id: I71c43b482aaa0992b7ce131d27e262b8e3b4087f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132160 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2022-03-25loplugins ignoreLocation() is unreliable with PCHNoel Grandin
Change-Id: Ic12cacb6e058a8725ea6d722399e3afe6ea458c6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132115 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-02-17Bump compiler plugins Clang baseline to 12.0.1Stephan Bergmann
...as discussed in the mail thread starting at <https://lists.freedesktop.org/archives/libreoffice/2020-November/086234.html> "Bump --enable-compiler-plugins Clang baseline?" (and now picked up again at <https://lists.freedesktop.org/archives/libreoffice/2022-February/088459.html> "Re: Bump --enable-compiler-plugins Clang baseline?"), and clean up compilerplugins/clang/ accordingly Change-Id: I5e81c6fdcc363aeefd6227606225b526fdf7ac16 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129989 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2021-09-18make FORCE_COMPILE_ALL more flexible than all or nothingLuboš Luňák
Rename it to FORCE_COMPILE and it takes the --enable-symbols specification of what to include, for example FORCE_COMPILE="all -sw/ -Library_sc". Change-Id: I92afd8e0abc75d3566285c197d6640c26c03db36 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122248 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
2021-06-14Adapt compilerplugins to LLVM 13 APSInt::toString changeStephan Bergmann
<https://github.com/llvm/llvm-project/commit/61cdaf66fe22be2b5942ddee4f46a998b4f3ee29> "[ADT] Remove APInt/APSInt toString() std::string variants". TODO: While most uses of compat::toString should be harmless performance-wise, as they are either in error reporting code or in plugins that are not run by default, some calls like the one in compilerplugins/clang/staticconstfield.cxx might benefit from moving them away from using std::string. Change-Id: Icfac7d6d4a0a4a4edeb5c8bdcdbc13b73e20a5e5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117152 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-12-08loplugin:singlevalfields update to python3Noel
Change-Id: I1257b7b865caa356c85eeeb45a19a537fc434ac5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107368 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-08-03Revert "Adapt to changed clang::ASTContext::getParents behavior on Clang 11 ↵Stephan Bergmann
trunk" This reverts commit 09aa5a9be8b9b3c88cf25b85e0eda28c5ef19aa4, now that <https://github.com/llvm/llvm-project/commit/ 551092bc3dfb86f1e11a55f3bee0c8ee1be6fdd6> "Revert AST Matchers default to AsIs mode" reverted the Clang commit that prompted this compilerplugins change. Change-Id: I75c8b4cb2894cd67a791db460f2886a783856c73 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100026 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-05-25Adapt to changed clang::ASTContext::getParents behavior on Clang 11 trunkStephan Bergmann
...since <https://github.com/llvm/llvm-project/commit/ d0da5d2bbe8305d06dc01a98706fd73e11e24a9f> "Change default traversal in AST Matchers to ignore invisible nodes". This caused failures > [CPT] compilerplugins/clang/test/constparams.cxx > ParmVarDecl 0x11d76c730 <compilerplugins/clang/test/constparams.cxx:15:12, col:18> col:18 used f1 'int *' > DeclRefExpr 0x11d76c948 'int *' lvalue ParmVar 0x11d76c730 'f1' 'int *' > ParmVarDecl 0x11d76cc80 <compilerplugins/clang/test/constparams.cxx:21:12, col:18> col:18 used f2 'int *' > DeclRefExpr 0x11d76ce60 'int *' lvalue ParmVar 0x11d76cc80 'f2' 'int *' > error: 'error' diagnostics expected but not seen: > File compilerplugins/clang/test/constparams.cxx Line 15: this parameter can be const Class1::Class1 [loplugin:constparams] > error: 'error' diagnostics seen but not expected: > File compilerplugins/clang/test/constparams.cxx Line 15: no parent? [loplugin:constparams] > File compilerplugins/clang/test/constparams.cxx Line 21: no parent? [loplugin:constparams] > 3 errors generated. [...] > [CPT] compilerplugins/clang/test/unusedenumconstants.cxx > error: 'error' diagnostics expected but not seen: > File compilerplugins/clang/test/unusedenumconstants.cxx Line 30: read Bottom [loplugin:unusedenumconstants] > error: 'error' diagnostics seen but not expected: > File compilerplugins/clang/test/unusedenumconstants.cxx Line 30: write Bottom [loplugin:unusedenumconstants] > 2 errors generated. [...] > [CPT] compilerplugins/clang/test/unusedfields.cxx > error: 'error' diagnostics expected but not seen: > File compilerplugins/clang/test/unusedfields.cxx Line 156 (directive at compilerplugins/clang/test/unusedfields.cxx:164): write m_f5 [loplugin:unusedfields] > File compilerplugins/clang/test/unusedfields.cxx Line 210 (directive at compilerplugins/clang/test/unusedfields.cxx:211): read m_f1 [loplugin:unusedfields] > 2 errors generated. For compilerplugins/clang/test/constparams.cxx at least it would have worked to fix that locally with > diff --git a/compilerplugins/clang/constparams.cxx b/compilerplugins/clang/constparams.cxx > index 95c8184009d7..70f056fa5a69 100644 > --- a/compilerplugins/clang/constparams.cxx > +++ b/compilerplugins/clang/constparams.cxx > @@ -274,7 +274,7 @@ bool ConstParams::checkIfCanBeConst(const Stmt* stmt, const ParmVarDecl* parmVar > { > for ( auto cxxCtorInitializer : cxxConstructorDecl->inits()) > { > - if ( cxxCtorInitializer->getInit() == stmt) > + if ( cxxCtorInitializer->getInit()->IgnoreImpCasts() == stmt) > { > if (cxxCtorInitializer->isAnyMemberInitializer()) > { (somewhat unintuitively, given the Clang change is apparently about ignoring more implicit nodes), but overall it appears better---at least for now---to use a getParents variant that keeps the old traversal behavior. For that, instead of using the clang::ASTContext::ParentMapCtx, we create our own loplugin::Plugin::parentMapContext_. There appear to be no uses of ASTContext::getParent across the Clang codebase itself, outside of ASTMatcher code, so it looks unlikely that creating our own ParentMapContext instance would degrade performance by no longer sharing cached data between Clang's internals and our plugin. (And given that ASTContext::getParents is deprecated with the note "New callers should use ParentMapContext::getParents() directly", this may well be the correct way in the long run, anyway.) Change-Id: I46c7912f2737e7c224fd45ab41441f69e2f10bd4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94795 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-01-29Adapt to "[ADT] Make StringRef's std::string conversion operator explicit"Stephan Bergmann
...<https://github.com/llvm/llvm-project/commit/ 777180a32b61070a10dd330b4f038bf24e916af1>. This is just a quick fix to get copmilerplugins buiding again with latest LLVM/Clang trunk. Ideally, we should get rid of as many of those (potentially expensive) conversions from llvm::StringRef to std::string as possible. Change-Id: I18e185e0022a06fd8e3b983a3c4f80e1f3b96746 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87682 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-01-27Adapt to Clang 11 move of DynTypedNodeListStephan Bergmann
...in <https://github.com/llvm/llvm-project/commit/ 8a81daaa8b58aeaa192a47c4ce7f94b4d59ce082> "[AST] Split parent map traversal logic into ParentMapContext.h", causing failures like > compilerplugins/clang/constmethod.cxx: In member function ‘bool {anonymous}::ConstMethod::checkIfCanBeConst(const clang::Stmt*, const clang::CXXMethodDecl*)’: > compilerplugins/clang/constmethod.cxx:191:70: error: invalid use of incomplete type ‘class clang::DynTypedNodeList’ > 191 | auto parentsRange = compiler.getASTContext().getParents(*stmt); > | ^ > In file included from compilerplugins/clang/plugin.hxx:15, > from compilerplugins/clang/constmethod.cxx:16: > include/clang/AST/ASTContext.h:97:7: note: forward declaration of ‘class clang::DynTypedNodeList’ > 97 | class DynTypedNodeList; > | ^~~~~~~~~~~~~~~~ Change-Id: Ib82d04608fa306a715af481422017c24053a01c6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87533 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-10-08better name for a function in compilerpluginsLuboš Luňák
The function is not just about a spelling location. Change-Id: I96e9e9ef7e27a9763397b4b86473c1c30d0e3eeb Reviewed-on: https://gerrit.libreoffice.org/80381 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
2019-10-07do not use compiler.getSourceManager().getFilename()Luboš Luňák
This is a continuation of ff002524c12471668e63837a804b6006f9136a34. When compiling with icecream, its -frewrite-includes merges all #include's into one .cxx file and marks them with with line markers. But SourceManager::getFilename() doesn't take those into account and so it reports all of those as <stdin>. So use getFileNameOfSpellingLoc(), which explicitly handles this case. And we should probably never ever use SourceManager::getFilename(). Change-Id: Ia194c2e041578e1e199aee2df2f885922ef7e31a Reviewed-on: https://gerrit.libreoffice.org/80326 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
2018-12-07loplugin:singlevalfields extend to all static varsNoel Grandin
Change-Id: Ic238bb5291539fd1b7e98cb4afc9b25f37e7d528 Reviewed-on: https://gerrit.libreoffice.org/64710 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-12-05loplugin:singlevalfields add checking for static class fieldsNoel Grandin
which required a completely different set of code Also add checking for in-class initialiser on struct/class fields Change-Id: I31e1586975aaafe23996619e2f59678c5fbc390f Reviewed-on: https://gerrit.libreoffice.org/64593 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-11-27add EvaluateAsInt compat function for latest clangNoel Grandin
the old EvaluateAsInt method has been dropped as from current clang Change-Id: Ie30d1547ad8de777badff4b380d2fc9fb261e8fe Reviewed-on: https://gerrit.libreoffice.org/64107 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-11-23Bump compiler plugins Clang baseline to 5.0.2Stephan Bergmann
...as discussed at <https://lists.freedesktop.org/archives/libreoffice/2018-November/081435.html> "minutes of ESC call ..." Change-Id: Ia053da171d59747984546f38e19da808825b4f79 Reviewed-on: https://gerrit.libreoffice.org/63832 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2018-11-14"oh dear, what can the matter be?"Stephan Bergmann
Lets assume that e3290499009492e39e5ddd870d314bb5df494199 "loplugin singlevalfields improvement" enabled loplugin:singlevalfields by accident. (It fails miserably for me.) Change-Id: Id308a17469babae195fa8261d937036b0cc39ff0
2018-11-13loplugin singlevalfields improvementNoel Grandin
checking for casting to void* turns out to mask useful stuff, so remove that and just deal with a few extra false+ Change-Id: Id9700d7ceda90ba8fdb38aa870f13a7ca3acb668 Reviewed-on: https://gerrit.libreoffice.org/63145 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-10-26loplugin:singlevalfields improvementNoel Grandin
look for any kind of types, not just POD types, helps to find smart pointer fields that are only assigned nullptr Change-Id: I2d887e98db012f03b646e1023985bcc196285abc Reviewed-on: https://gerrit.libreoffice.org/62382 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-10-22loplugin:singlevalfields look for fields that can be boolNoel Grandin
Change-Id: Ief773b661a8378a10db56943b32127c7a2c86d11 Reviewed-on: https://gerrit.libreoffice.org/62037 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-10-17loplugin:singlevalfieldsNoel Grandin
tighten up the handling of binary operators Change-Id: I262ec57bf7142fa094d240738150a94d83fd15ee Reviewed-on: https://gerrit.libreoffice.org/61777 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-08-10Avoid -Werror=deprecated-declarations with recent Clang trunkStephan Bergmann
...which first added alternative names to and then deprecated getLocBegin/End Change-Id: Iaefb8ce259057abfa6cd20f0b63c0ef2949a96b2 Reviewed-on: https://gerrit.libreoffice.org/58820 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2018-04-23loplugin:singlevalfields improve unaryoperatorNoel Grandin
when we see a unaryoperator, unless it's one of a small set, we can know (mostly) that the field will not be written. there is still a small risk of false+ with code taking references via conditional expressions. Change-Id: I96fa808067576a50e5eaf425338e225b4e0bdd4e Reviewed-on: https://gerrit.libreoffice.org/53263 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-04-10put the loplugin output files in the workdirNoel Grandin
so that the next time I accidentally leave one turned on, and commit it, the buildbots will clean up naturally the next time they run 'make clean' Change-Id: Ia09dea9c272c322c7e2773c5458cb54aceb50dd1
2018-02-02loplugin:singlevalfieldsNoel Grandin
Change-Id: I346f236e28cb0bd064a7d757b187e5e64544700f Reviewed-on: https://gerrit.libreoffice.org/49086 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-01-03loplugin:singlevalfields improve copy constructor checkNoel Grandin
Change-Id: Id1e7fbecd9e9f816553d2e678c3f1b7890fc4db8 Reviewed-on: https://gerrit.libreoffice.org/47293 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-12-19Bump --enable-compiler-plugins to Clang 3.8.0Stephan Bergmann
<https://lists.freedesktop.org/archives/libreoffice/2017-December/079107.html> "Clang baseline bump" Change-Id: I18fca8794ea34118fc6308458064d0c28cf5caf7 Reviewed-on: https://gerrit.libreoffice.org/46557 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2017-11-30some global loplugin improvementsNoel Grandin
for some reason we're hitting more template AST nodes now? Anyhow, updated singlevalfields and unusedenumconstants to cope. For unusedfields, ignore field access inside Clone() methods, since it's like a constructor. Similarly for unusedmethods. Change-Id: Icb2f76fb2f06ae5df21f9d75312e42a2800befb9 Reviewed-on: https://gerrit.libreoffice.org/45470 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-11-07Clean away temporarily added using declarationsStephan Bergmann
Change-Id: I26734c13515394162d88351a1cbe2b20abdac865
2017-10-27rename loplugin::Plugin::parentStmtNoel Grandin
to getParentStmt and rename parentFunctionDecl to getParentFunctionDecl, so I don't keep using accidentally naming my variables the same as the functions. Change-Id: I66f9452458c8b439e5132191ac5219fb6d420708
2017-06-20reformat some loplugin codeNoel Grandin
to match our more normal conventions. Also drop the 'using std' and some other cruft Change-Id: I02ef81c5427188bc03a20b157a57a900a9d7bf0d
2017-04-06loplugin:singlevalfieldsNoel Grandin
Change-Id: Ia681765aa1da5c80a3dbe91b7376af841a9c9ec1 Reviewed-on: https://gerrit.libreoffice.org/36145 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-03-28fixes for some lopluginsNoel Grandin
ran the ones in store/ just for fun, but didn't find anything useful Change-Id: I2bb251e8d99b5d88e11b2ca74e99672d75f0a1fd
2016-09-27clang plugins: do "dotdot" normalisationNoel Grandin
which fixes some false positives Change-Id: I555349180b5ca819f29695789f1545ba2177bd09 Reviewed-on: https://gerrit.libreoffice.org/29320 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2016-09-15loplugin:singlevalfields in l10ntools..saxNoel Grandin
and ignore URE headers in the plugin Change-Id: I939df744c1173cf0f67d515f6c3fb4ac4cb25588
2016-09-12handle nullptr in various clang pluginsNoel Grandin
since we are using it so widely now, instead of NULL Change-Id: I990ff1334f657663e8791ab064d69e56636fe6e7
2016-07-25loplugins: more consistent naming of output filesNoel Grandin
Change-Id: Ia26f697cb16078f235c94e4cff449a60c1bbd74e
2016-06-28Adapt to Clang 3.4 (in preparation of a buildbot on CentOS 7)Stephan Bergmann
Change-Id: Ie2859f03b31c57deb7fd0deba3285f782e33b239
2016-06-28loplugin: move parentFunctionDecl() into common codeNoel Grandin
Change-Id: Ia10a76a98a63c6ea3b516d9146281f672b213ab3
2016-06-28loplugin:singlevalfields in variousNoel Grandin
Change-Id: Ia0d8f463a4dba9ec63aa0159441e3e607dd3bf5e Reviewed-on: https://gerrit.libreoffice.org/26738 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
2016-06-27check for field being returned by non-const refNoel Grandin
Change-Id: I660c98dcbfa6052628ff667886981d075f34b2b7
2016-06-26dont ignore destructorsNoel Grandin
generate more false+ than it helps to find interesting stuff Change-Id: I752f08a28e629bce00264108399b2a4c8afd388f
2016-06-24teach singlevalfields loplugin about function pointersNoel Grandin
Change-Id: I81f77e2b3f94c208866fa8d124b0b00ea5387563
2016-06-23loplugin singlevalfields, need to check default constructor code tooNoel Grandin
Change-Id: Idcc8de6f1d403a57c59e84774bd7a97e2f3fc224
2016-06-23-Werror=unused-functionStephan Bergmann
Change-Id: Ib579e8896a751383d31c1dbf7e6ebf5c0774a976
2016-06-23-Werror=unused-but-set-variableStephan Bergmann
Change-Id: I0b3586bb3acca4075b26790a8dfe3f97d6921feb
2016-06-23new loplugin: singlevalfieldsNoel Grandin
look for fields that only have a single constant value assigned to them Change-Id: Iafcd37fdb8a8119bbc00f92981a1a01badf9c5a2