summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/unusedfields.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-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-11-11Drop ScGlobal::GetEmptyOUString() and EMPTY_OUSTRINGMike Kaganski
OUString default ctor already uses a static instance (through rtl_uString_new), no need to have another module-specific static. Commit d8037ae18a297229d1b79f8f76331abfd548350d had removed its sw counterpart some time ago. Change-Id: I140fe13bc1f6b0cbe188e83e602fdebe995e467a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125061 Tested-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.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-05-18loplugin:unusedfieldsNoel Grandin
Change-Id: Ib574403a7f7f8b11c6263c9c19ec6b65c8374ddd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115753 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-08-04remove some debug codeNoel Grandin
Change-Id: I6aff84ce7b9d4fed27d8442d1366bcf14bc44f86 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100084 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-05-25Code duplicationStephan Bergmann
Change-Id: I1af2948e0332044ef88bc7dbd837e8c7afe7af19 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94785 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-03-10Deref of DynTypedNode* must not outlive owning DynTypedNodeListStephan Bergmann
Change-Id: I8ac4a2f1e442446384b88f38bdef21644409f8a2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90303 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-03-09improve loplugin:unusedfieldsNoel Grandin
noticed something that wasn't being picked up, wrote some tests, and found an unhandled case in Plugin::getParentFunctionDecl Change-Id: I52b4ea273be6614e197392dfc4d6053bbc1704de Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90141 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-02-03loplugin:unusedfieldsNoel Grandin
tweak plugin with the name of another clone method Change-Id: I47193d31f53f48297c9e773da375c7255ddde282 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87852 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-01-31loplugin:unusedfields improve checking for fields guarded by existence checkNoel Grandin
which resulted in only a couple of real finds, mostly false+ Change-Id: I26058a29c27bff50e9526bedd54fb04589c2934d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87765 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
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>
2019-09-06Fixing "...."Andrea Gelmini
Change-Id: Id005a7531d546dd43de13b49bcb3e93081c5ad8d Reviewed-on: https://gerrit.libreoffice.org/78679 Tested-by: Jenkins Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2019-06-14loplugin:unusedfields improvementsNoel Grandin
tighten up the only calling write-only methods part of the analysis Change-Id: I5bc6fdf0ce51940653317e8a48c5241705c90d4c Reviewed-on: https://gerrit.libreoffice.org/74022 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-02-27loplugin:unusedfields fix read/write when dealing with r<<= and >>=Noel Grandin
Change-Id: I103bcc2f21741d0a52a0bdf053fdbddf5a3e9ea0 Reviewed-on: https://gerrit.libreoffice.org/68387 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-02-21loplugin:unusedfields improve write-only when dealing with operatorsNoel Grandin
Change-Id: I3a060d94de7c3d77a54e7f7f87bef88458ab5161 Reviewed-on: https://gerrit.libreoffice.org/68132 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-12-13loplugin:unusedfields improve write-only logicNoel Grandin
when dealing with modifications to container classes (e.g. std::vector) Change-Id: Ic30043631007355ee9a3d9e3f9b6488b435182d6 Reviewed-on: https://gerrit.libreoffice.org/65050 Tested-by: Jenkins Reviewed-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-10-22loplugin:unusedfields improvemementsNoel Grandin
treat fields touched in operator== as not being important, which finds some more stuff (but also adds some false+) Change-Id: I3f5d504d7dec7945a917afbcd58c92df74f03645 Reviewed-on: https://gerrit.libreoffice.org/62020 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-09-18loplugin:unusedfields improve search for unused collection fieldsNoel Grandin
look for collection-like fields that are never added to, and are therefore effectively unused Change-Id: Id52c5500ea5e3d2436fb5915aebb86278bf2d925 Reviewed-on: https://gerrit.libreoffice.org/60661 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-09-13new loplugin:constfieldsNoel Grandin
look for fields which are only assigned to in the constructor, so they can be made const Change-Id: I0b76817c2181227b04f6a29d6a808f5e31999765 Reviewed-on: https://gerrit.libreoffice.org/60393 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-08-14filter out some of the AST in the pluginsNoel Grandin
by checking if the current namespace decl is in our code, so we have to scan less stuff, which results in a 10% perf improvement for me Change-Id: Idf0e30d57b6d0dcd13daa9ed679c28b9d233d387 Reviewed-on: https://gerrit.libreoffice.org/58942 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-07-20loplugin:unusedfields - look for fields that can be const, in comphelperNoel Grandin
idea from tml. Extend the unusedfields plugin to find fields that are only assigned in the constructor. Change-Id: I258d3581afbe651d53ce730c9ba27a4598cd9248 Reviewed-on: https://gerrit.libreoffice.org/57733 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-07-02loplugin:unusedfields improve checking for write-only fieldsNoel Grandin
we trade off a little accuracy for finding more possible write-only fields. Change-Id: I9f7edba99481fe4ded0a9d8e45e911b0ee99d269 Reviewed-on: https://gerrit.libreoffice.org/56715 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-05-19improve unusedfields loplugin to find constructor-only fieldsNoel Grandin
ie. fields that are only touched in the constructor Change-Id: Ia714cbfed9710e47e69ca9f0eb0eac4f7e8b8a86 Reviewed-on: https://gerrit.libreoffice.org/54412 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-04-10darn, unusedfields loplugin was left enabledNoel Grandin
Change-Id: I343262e0c61e9ecde5395f13732c212197e7fd03
2018-04-10loplugin:unusedfield improvementsNoel Grandin
improve the read-only check to ignore reads from fields that are guarded by a boolean check, something like: if (field) field.foo(); this produces some false positives at the moment because I'm not correctly handling the else block, but also some useful new dead code. Change-Id: Id21fa1a56c171d09d979769b978b6eef14e8b695 Reviewed-on: https://gerrit.libreoffice.org/52664 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-01-09Don't build off-by-default loplugin:unusedfields on Windows for nowStephan Bergmann
...due to missing sys/file.h Change-Id: I7cfd64c5355d9fdbb85320f876c277a408be9352 Reviewed-on: https://gerrit.libreoffice.org/47675 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2018-01-04loplugin:unusedfieldsNoel Grandin
fix the ReturnStmt check Change-Id: I95076076bd1313d23798c4615ea12910c86ed9a8 Reviewed-on: https://gerrit.libreoffice.org/47309 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
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-09loplugin:unusedfieldsNoel Grandin
Change-Id: Ie8a2c6462ddc708140e725847199c8234ab6b592 Reviewed-on: https://gerrit.libreoffice.org/44528 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-09-29More clang::*Type vs. llvm::*Type ambiguitiesStephan Bergmann
Change-Id: I52373c32818234e376d855684635f9bf1012ed5e
2017-09-29loplugin:unusedfields improve finding calleeNoel Grandin
which makes absolutely no difference to the results, but anyhow, would be a shame to waste the work Change-Id: I4576528f30986a5ce522c76fdf21873f0ce23f0a
2017-09-21loplugin:unusedfields, fix var taking refNoel Grandin
Change-Id: I0ea1f0c7488c140fca9f64de326c6ac588ece925
2017-09-18improve unusedfields lopluginNoel Grandin
(*) IsPassedByNonConst was completely wrong, not even sure why it worked before. (*) treat a field passed to operator>>= as being written to, but not read Change-Id: Id3a5f2f35222986fe5edba3f5a58215a1815d401
2017-07-27simplify unusedfields pluginNoel Grandin
using some wrappers around callee and caller AST nodes Change-Id: I599a04a18caa3ada70bcb266e228208b7a81f1a1
2017-07-24improve unusedfields loplugin readonly analysisNoel Grandin
(*) better analysis of init-list-expressions (*) fix analysis of calls to members, turns out there is no parameter offset after all (*) check for passing arrays to functions, need to check if the parameter is T* or T const * (*) check for assigning field to a T& variable Change-Id: Ie6f07f970310c3854e74619fe4fd02a299bf6879
2017-07-22Typo: "disposeAndClear", not "clearAndDispose"Julien Nabet
Change-Id: I9f7f30fce9324f7ccb79e9a8ef0c13e091d7c3a3 Reviewed-on: https://gerrit.libreoffice.org/40304 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-07-19enhance unusedfields plugin to find readonly fieldsNoel Grandin
Change-Id: I4da97443fc7eb14fd94959a026ab45a9256c055f Reviewed-on: https://gerrit.libreoffice.org/40158 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-07-14remove some dead code from unusedfields pluginNoel Grandin
Change-Id: I268b32270a17c0c3fcf8236c3e0eebac9a57cb5d