summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/refcounting.cxx
AgeCommit message (Collapse)Author
2023-09-17remove unnecessary dynamic_cast around SwXTextNoel Grandin
Unusually, we cannot use rtl::Reference to hold SwXText, because rtl::Reference assumes that its pointee is a subclass of OWeakObject, which SwXText is not (and we cannot make it so because the UNO bridge does not support virtual base classes). So we have to use css::uno::Reference<SwXText> and carve out an exception in loplugin:refcounting. Change-Id: If3a1307e30fdcd3b47aa665252be081fb5063400 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156982 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2023-01-20improve loplugin:refcountingNoel Grandin
to catch places where we are converting a weak reference to a strong reference, and then using a pointer to store the result Change-Id: I69b132907b574e5c6974fadf18bd9658107d3a0d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145877 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-08-29ref-count SdrObjectNoel Grandin
Which means we can get rid of the majestic hack of ScCaptionPtr Previously, SdrObject was manually managed, and the ownership passed around in very complicated fashion. Notes: (*) SvxShape has a strong reference to SdrObject, where previously it had a weak reference. It is now strong since otherwise the SdrObject will go away very eagerly. (*) SdrObject still has a weak reference to SvxShape (*) In the existing places that an SdrObject is being deleted, we now just clear the reference (*) instead of SwVirtFlyDrawObj removing itself from the page that contains inside it's destructor, make the call site do the removing from the page. (*) Needed to take the SolarMutex in UndoManagerHelper_Impl::impl_clear because this can be called from UNO (e.g. sfx2_complex JUnit test) and the SdrObjects need the SolarMutex when destructing. (*) handle a tricky situation with SwDrawVirtObj in the SwDrawModel destructor because the existing code wants mpDrawObj in SwAnchoredObject to be sometimes owning, sometimes not, which results in a cycle with the new code. Change-Id: I4d79df1660e386388e5d51030653755bca02a163 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138837 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-03-08loplugin:refcounting check for one more caseNoel
where we might be holding something newly created by pointer instead of by *::Reference Change-Id: Ife6f7acae4252bf56dcdeb95d72e43c523444f97 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112138 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-03-05loplugin:refcounting return objects properlyNoel
check that when we return ref-counted objects, we do so using rtl::Reference, so that the object actually has a non-zero ref count. Change-Id: Ib3ffae0d2502f6d117550c82fde5449729c27324 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111487 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-02-23loplugin:refcounting check for managing OWeakObject with raw pointerNoel
Change-Id: I7471725f1e658940b5e6993361c327be6ccf0d31 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111064 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-02-22Avoid loplugin:refounting in uninstantiated template codeStephan Bergmann
...causing e.g. false positive > In file included from shell/source/win32/spsupp/COMOpenDocuments_x64.cxx:11: > In file included from shell/source/win32/spsupp/COMOpenDocuments.cxx:16: > In file included from shell/inc/spsupp\COMOpenDocuments.hpp:21: > shell/inc/spsupp/COMRefCounted.hpp(35,13): error: cppu::OWeakObject subclass 'COMRefCounted<Interfaces...>' being deleted via delete, should be managed via rtl::Reference [loplugin:refcounting] > delete this; > ^~~~~~~~~~~ with clang-cl on Windows. (Ideally, this would be made up for with setting this plugins' shouldVisitTemplateInstantiations() to true, see the TODO added in compilerplugins/clang/test/refcounting.cxx, but that would cause lots of other findings, so is left out for now.) Change-Id: Ia52b13498a0c7169b37ecf4882ce84c3cc1d2cc4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111339 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2021-02-12loplugin:refcounting check for calling deleteNoel
Change-Id: I5b723d4d2376a28777e3ee7e9706e5f54fcb55e3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110809 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-02-11loplugin:refcounting generalise type checkingNoel
Change-Id: Ia013878ac9c2918d8eaf9aab16b291d8211e708f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110700 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-02-10loplugin:refcounting also check OWeakObject subclassesNoel
Change-Id: I2d89085a22d7424c6f8f7662307433ce50fc61d2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110666 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-04-25convert excel filter in calc from shared_ptr to rtl::ReferenceNoel Grandin
ref-counting traffic here accounts for 10% of the profile on some of my calc imports. Change-Id: I1b32e0e61d7bf5eb65780ec0e7fcb99f6576050a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92694 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-02-14make unusedmember use the shared plugin infrastructureNoel Grandin
Change-Id: Ie2f5ada6e27544ca1bceabe6fcfe524063d3201f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88588 Tested-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-12-14sc: rowcol: convert mark dataNoel Grandin
with this patch I can finally load a 3201 column document Change-Id: I880d485b3f628836e7aed92c276e660466a3b19c Reviewed-on: https://gerrit.libreoffice.org/85139 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-22Extend loplugin:external to warn about classesStephan Bergmann
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend loplugin:external to warn about enums". Cases where free functions were moved into an unnamed namespace along with a class, to not break ADL, are in: filter/source/svg/svgexport.cxx sc/source/filter/excel/xelink.cxx sc/source/filter/excel/xilink.cxx svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx All other free functions mentioning moved classes appear to be harmless and not give rise to (silent, even) ADL breakage. (One remaining TODO in compilerplugins/clang/external.cxx is that derived classes are not covered by computeAffectedTypes, even though they could also be affected by ADL-breakage--- but don't seem to be in any acutal case across the code base.) For friend declarations using elaborate type specifiers, like class C1 {}; class C2 { friend class C1; }; * If C2 (but not C1) is moved into an unnamed namespace, the friend declaration must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither qualified nor a template-id and the declaration is a function or an elaborated-type-specifier, the lookup to determine whether the entity has been previously declared shall not consider any scopes outside the innermost enclosing namespace.") * If C1 (but not C2) is moved into an unnamed namespace, the friend declaration must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882> "elaborated-type-specifier friend not looked up in unnamed namespace". Apart from that, to keep changes simple and mostly mechanical (which should help avoid regressions), out-of-line definitions of class members have been left in the enclosing (named) namespace. But explicit specializations of class templates had to be moved into the unnamed namespace to appease <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of template from unnamed namespace using unqualified-id in enclosing namespace". Also, accompanying declarations (of e.g. typedefs or static variables) that could arguably be moved into the unnamed namespace too have been left alone. And in some cases, mention of affected types in blacklists in other loplugins needed to be adapted. And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is not moved into an unnamed namespace (because it is declared in sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler doesn’t give this warning for types defined in the main .C file, as those are unlikely to have multiple definitions." (<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The warned-about classes also don't have multiple definitions in the given test, so disable the warning when including the .cxx. Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4 Reviewed-on: https://gerrit.libreoffice.org/83239 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-05-31tdf#114596 compilerplugins: add exception to [loplugin:refcounting]Xisco Fauli
Change-Id: I94a1d4fcacc7907df21b05fd773d3273e1a0d6a2 Reviewed-on: https://gerrit.libreoffice.org/73147 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-04-30implement std::hash for css::uno::Reference and rtl::ReferenceNoel Grandin
The declaration in BarChart.cxx is particularly suspicious, because it was using a < for the KeyEqual template parameter. Been there since: commit b2c3233e5f267b5d244d722a94424a3b224b3314 Date: Thu Dec 21 20:08:33 2017 +0900 chart2: suspend/resume setting rects dirty for 3D shapes comphelper::OInterfaceCompare is no longer necessary Change-Id: I8278c4a3d9113a18570ca237cd05d553ec8f3975 Reviewed-on: https://gerrit.libreoffice.org/71537 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-03-11move isDerivedFrom() from a clang plugin to shared code, for reuseLuboš Luňák
Change-Id: I7b9b41a7081281214a387cdf02080866e9b9dfe7 Reviewed-on: https://gerrit.libreoffice.org/68873 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-06compilerplugins: try to make these work with icecreamMichael Stahl
There are some problems here, this should fix one of them: the getFilename function returns "<stdin>" for spelling locations, because the input to clang is sort of preprocessed via -frewrite-includes if icecream is used and the file is built on a remote host (whereas it's apparently not preprocessed if the file is compiled locally by icecream). Using getPresumedLoc() uses the #line directives in the preprocessed input, which avoids the problem but is more expensive, so try to use it only when necessary. The getFileEntry(getMainFileID())->getName() pattern will also result in "<stdin>", but fortunately icecream passes -main-file-name, which oddly enough isn't used by the SourceManager's spelling locations, but is available separately via CodeGenOptions. This builds everything successfully with clang version 6.0.0: ICECC_PREFERRED_HOST=myremote make check gb_SUPPRESS_TESTS=t Change-Id: Ic121511683e5302d7b9d85186c8b9c4a5443fa1b Reviewed-on: https://gerrit.libreoffice.org/54993 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
2018-02-01these TODOs have been doneNoel Grandin
Change-Id: I5457f38f4668175a8f3e1b0f24a90963ee9d585f Reviewed-on: https://gerrit.libreoffice.org/49076 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-01-31tdf#114596 compilerplugins: add exception to [loplugin:refcounting]Michael Stahl
Change-Id: I994653dc4bf858bdea7ba60f40da0ee3c8d028e4
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-12-01Don't prevent ODatabaseDocument refcount from dropping to zeroStephan Bergmann
...preventing the dtor from ever being called. (DocumentEvents forwards its acquire/release calls to its m_pData->rParent, i.e., the ODatabaseDocument, for better or worse.) This caused ODatabaseDocument instances to be leaked during e.g. JunitTest_dbaccess_complex. Regression introduced with de2ac128da025502c533f8cede5862e054dd9c44 "loplugin:useuniqueptr in dbaccess". Change-Id: Ida073c7e576b88e0d1d1a90253445e946e6eac99 Reviewed-on: https://gerrit.libreoffice.org/45652 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2017-11-07Clean away temporarily added using declarationsStephan Bergmann
Change-Id: I26734c13515394162d88351a1cbe2b20abdac865
2017-09-11More clang::*Type vs. llvm::*Type ambiguitiesStephan Bergmann
Change-Id: I21133976793ab018c633dda077029666308526db
2017-06-30Actually print parent nameStephan Bergmann
Change-Id: Iba9bacc0ecaf5288f5c53f6fa73340504c646b4f
2017-06-30Avoid getQualifiedNameAsStringStephan Bergmann
Change-Id: I448bfd63f1a2fb9cac3366146b10ff6a465e6db7
2017-06-29improve refcounting lopluginNoel Grandin
to find ref-counted classes being managed via other smart pointer classes. Hopefully prevent needing fixes like 642ae256ea5b8083ba0b3c097ca8ea52304b9cdb "ChangedUIEventListener is refcounted, mustn't be helt by unique_ptr" Change-Id: I6b0c5f8f87ce3546a8a1104ce1000470c09459bd Reviewed-on: https://gerrit.libreoffice.org/39378 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-05-18Adapt pathname checks to mixed usage of \ and / on WindowsStephan Bergmann
Change-Id: I91bc89a9076c6642e06b238f65f2d31a1d20c6b5
2017-03-03Fix typosAndrea Gelmini
Change-Id: I4f16ba5fc32cbfd6a5b01e495f3ad905da193524 Reviewed-on: https://gerrit.libreoffice.org/34808 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-01-13inline InitGuardNoel Grandin
since it is only used in one place Change-Id: Ie541a255ddbe71105f6b58f02f372f4f45667d7a
2016-10-12typoStephan Bergmann
Change-Id: Iea55eee0e5e777e46bb02435f10bca03e554a15c
2016-10-12improve error message in refcounting pluginNoel Grandin
Change-Id: I02b483c1d696913b33112b9248747f9c3d28dc55
2016-09-09loplugin:refcounting: No more special-handling of SvXMLImportContextStephan Bergmann
...after 32ccb4ea863651c22bf33cc15012971d2a2d2810 "resolve the snafu with 2 separate refcounted bases" Change-Id: Iaf13deb0b83b6dfe1a2cf3863e07cf042c8e4f47
2016-08-26loplugin:refcounting: also cover temporaries being directly stack managedStephan Bergmann
Change-Id: Ib0f7c60df1d2fba0d4d9d3fa6faf3bb97867ebc0
2016-08-26Remove wrong check through template args from containsXInterfaceSubclassStephan Bergmann
...that was probably only there as a workaround for cases (equally wrongly) covered by the check for !hasAnyDependentBase in isDerivedFrom. And the latter appears to no longer be necessary, probably because the cases it happened to cover intentionally are now covered correctly through some other logic that got added to this plugin meanwhile. Change-Id: Ife6370b4f966198fc731813afe62d765450382e6
2016-06-29Further clean-upStephan Bergmann
Change-Id: I2b867a93fd8c5cf3c1e4f53863c441478d9201e1
2016-06-28More Clang 3.4 "(anonymous namespace)" fixesStephan Bergmann
Change-Id: I7cb43f915565dadd611b90ee30373e472f97efb5 Reviewed-on: https://gerrit.libreoffice.org/26748 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Stephan Bergmann <sbergman@redhat.com>
2016-06-28Adapt to Clang 3.4 (in preparation of a buildbot on CentOS 7)Stephan Bergmann
Change-Id: Ie2859f03b31c57deb7fd0deba3285f782e33b239
2016-05-31teach refcounting clang plugin about uno::ReferenceNoel Grandin
uno::Reference is only allowed to used with classes that have a ::static_type member. So convert all those places to rtl::Reference. Maybe we need some LIBO_INTERNAL_ONLY constructors on rtl::Reference and uno::Reference to make this a little smoother? Change-Id: Icdcb35d71ca40a87b1dc474096776412adbfc7e3 Reviewed-on: https://gerrit.libreoffice.org/25516 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
2016-03-01OSingletonRegistration is dead nowMatúš Kukan
Change-Id: I64a5ffa8790496bd39ba26e0c789db9eedc51071 Reviewed-on: https://gerrit.libreoffice.org/22788 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Matúš Kukan <matus@libreoffice.org>
2016-02-26These version checks are about the Clang the plugins are built /against/Stephan Bergmann
...not the (Clang) compiler they are being built /with/. (Also simplifies the checking #if code.) Change-Id: I416321be4ef4478785be40571f81500fd3b6feb8
2016-02-09Use rtl::Reference<CppType> instead of HardCppRef<UnoType,CppType>Stephan Bergmann
Change-Id: I089b5caca5e05726105f78aeb00db1869d0a17f4
2016-01-07Fix typosAndrea Gelmini
Change-Id: I90b04b8eda6fc3d530c9db72052720cbe9de0343 Reviewed-on: https://gerrit.libreoffice.org/21197 Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
2015-09-21tdf#94389 compilerplugins: clang 3.7.0Daniel Robertson
Fix errors that occur in build with clang 3.7.0 Change-Id: I0e8743f2b6a288d10b4e78e884ce34cfca4dd77c Reviewed-on: https://gerrit.libreoffice.org/18738 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Stephan Bergmann <sbergman@redhat.com>
2015-08-05improve refcounting loplugin to check SvRef-based classesNoel Grandin
Change-Id: I2b3c8eedabeaecd8dcae9fe69c951353a5686883 Reviewed-on: https://gerrit.libreoffice.org/17521 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
2015-08-04fix crash in refcounting pluginNoel Grandin
introduced by commit c15b4cf39a74176cee64795129d76f411d2c0a69 "Adapt to current Clang trunk towards 3.7" Change-Id: I00f58d3bc79e641df9bba4e9b1d5c8463b87dc42