summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/pluginhandler.cxx
AgeCommit message (Collapse)Author
2019-03-12make (some) clang plugins share the same RecursiveASTVisitorLuboš Luňák
Each plugin currently uses its own recursive AST run, which adds up. This patch adds another shared plugin which internally contains all (suitable) plugins and dispatches to them from the same one recursive run. This patch converts ~25 plugins and for starmath's accessibility.cxx reduces clang build time from 5.43s to 5.14s (and it's 4.39s without any plugins). As there are almost 50 more plugins to go, this can theoretically result in 4.56s final time, although probably not all plugins can be that easily converted, if at all. This mostly requires very little change in many plugins (see e.g. BadStatics), some even work without any functionality change (e.g. CharRightShift). Traverse* calls require some changes but are often not that difficult. WalkUp* probably can't be supported, although some plugins can(?) possibly be adjusted to not rely on them. And of course some plugins can be left as they are, using their own recursive run. See description at the top of generator.cxx for description of how to convert a plugin. The sharedvisitor.cxx source is generated based on scanning relevant plugin sources using a clang-based scanner/generator. The generated source is intentionally included instead of getting always generated, as the generating currently takes some time, so it should get updated in git whenever a change in a plugin triggers a source change in it. Change-Id: Ia0d2e3a5a464659503dbb4ed6c20b6cc89b4de01 Reviewed-on: https://gerrit.libreoffice.org/68026 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
2019-03-11avoid a possible crash in loplugin's ignoreLocation()Luboš Luňák
For the built-in(?) __int128_t there's apparently no valid presumed location. Change-Id: I1b2f1a827bc914d2f288dd1e02718bf45a50dd1e Reviewed-on: https://gerrit.libreoffice.org/68870 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-07-25new loplugin:returnconstantNoel Grandin
look for methods that always return the same value Change-Id: I5f1c5b58a985ecf5f7765a2d4ebd464eae5ef76f Reviewed-on: https://gerrit.libreoffice.org/57973 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
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-03-27Let prefix arguments to hasPathnamePrefix end in slashStephan Bergmann
...for better precision Change-Id: I5f273b7c66ba931647805c415622b5ac767ff987
2018-03-23Revert "Allow compiler plugins for online"Stephan Bergmann
This reverts commit b39e627be45f847554f11fdac040b6f4da4054ba. The assumed (see comment at <https://gerrit.libreoffice.org/#/c/46769/4/compilerplugins/clang/ plugin.cxx@633>) performance bottleneck of isSamePathname -> getAbsolutePath does show up in Flamegraph inspections of LO builds. But changing (non-member function) isSamePathname to only call getAbsolutePath if (PluginHandlder member function) isLOOLMode is true would need some code reorg, and Online development doesn't seem to make too much actual use of the plugin, so conclusion on IRC was to revert. Change-Id: I0f04fdcc87087dac516630ed5e48361f5ea332ca Reviewed-on: https://gerrit.libreoffice.org/51774 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2018-02-12fix loplugin rewriter source range checkingNoel Grandin
after commit 94ab8e4360a2a7a932656e99f718244321d0f923 Date: Fri Feb 9 15:28:41 2018 +0200 improve loplugin rewriter double source modification detection Change-Id: Ibf0a64fe4cc3dd6bf5ae16672b3d748a842196e4
2018-02-10improve loplugin rewriter double source modification detectionNoel Grandin
because my new rewriter easily generates overlapping rewriting. Move the code from flatten and salcall up into the pluginhandler, and drop the simpler detection logic. Change-Id: I3da51ac510954a5d4276cee0924cc5dc1fc9a734 Reviewed-on: https://gerrit.libreoffice.org/49493 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-12-21Allow compiler plugins for onlinePranav Kant
Change-Id: I8e45936ef5675d531be71496e8894b90eaf2f6e2 Reviewed-on: https://gerrit.libreoffice.org/46769 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: pranavk <pranavk@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-12-08New --enable-compiler-plugins=debug modeStephan Bergmann
...to enable debug-only code in the plugins. Some situations in the plugin code should never happen, yet must not by default report errors or trigger assertions, as some newly written LO code could trigger them nevertheless (in which case the plugin code will likely need to be adapted, to cater for these presumed-impossible situations). Such code can now be included in the plugins behind an if(isDebugMode()) guard, and can explicitly be enabled with --enable-compiler-plugins=debug. I deliberately made this a runtime rather than a compile time option (using some #ifdef guards in the plugin code, say), as it IMO keeps the code more readable, and also allows overridding COMPILER_PLUGINS_DEBUG=... on the make command line. Change-Id: Iea4f0c2783ad968a0de097fa710b3be1a248de73 Reviewed-on: https://gerrit.libreoffice.org/46096 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2017-11-07Memoize ignoreLocation resultsStephan Bergmann
...which, according to callgrind, reduces instruction fetch count spent on compiling sw/source/core/layout/paintfrm.cxx (randomly selected because it is rather large) by 5% from 41,992,064,226 to 39,861,989,855 (function main() in clang-6.0). This is best done by forwarding ignoreLocation calls from Plugin to the PluginHandler signleton, but due to the tight mutual coupling between plugin.hxx and pluginhandler.hxx that unfortunately required some reorganization (and two outstanding TODO clean-ups of temporarily introduced using declarations in plugin.hxx). Change-Id: Ia4270517d194def7db7ed80cb6894e9c473e9499
2017-10-20Fully ignore inappropriately named loplugins in unit-test modeStephan Bergmann
...even if they implement PPCallbacks, so filtering them out in HandleTranslationUnit was ineffective. Change-Id: I9df8103a50739f3176e6d63accfd0334da7faa9a Reviewed-on: https://gerrit.libreoffice.org/43575 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Stephan Bergmann <sbergman@redhat.com>
2017-09-30Support loplugin in clang-clStephan Bergmann
This works at least with a recent Clang trunk (towards Clang 6.0). In order for the plugin.dll to find the LLVM/Clang symbols, it needs to be loaded into clang.exe not clang-cl.exe, so set CC/CXX to 'clang.exe --driver-mode=cl ...'. Buidling the plugin requires some linker flags that must go at the very end of the COMPILER_PLUGINS_CXX command line, after a /link switch, so introduce another COMPILER_PLUGINS_CXX_LINKFLAGS variable for that. Also, clang.lib is not installed as part of LLVM's 'cmake --build ... --target install' step, so is not available under CLANGDIR and needs to be taken from the build tree instead, so introduce another CLANGLIBDIR variable for that. autogen.input settings that work for me on Windows 8.1 with Microsoft Visual Studio 14.0 are: > CLANGDIR=C:/llvm/inst > CLANGLIBDIR=C:/llvm/build/lib > COMPILER_PLUGINS_CXX=C:/PROGRA~2/MICROS~3.0/VC/bin/amd64/cl.exe /IC:\PROGRA~2\MICROS~3.0\VC\INCLUDE /IC:\PROGRA~2\MICROS~3.0\VC\ATLMFC\INCLUDE /IC:\PROGRA~2\WI3CF2~1\10\include\100102~1.0\ucrt /IC:\PROGRA~2\WI3CF2~1\NETFXSDK\46D346~1.1\include\um /IC:\PROGRA~2\WI3CF2~1\8.1\include\shared /IC:\PROGRA~2\WI3CF2~1\8.1\include\um /IC:\PROGRA~2\WI3CF2~1\8.1\include\winrt > COMPILER_PLUGINS_CXX_LINKFLAGS=/LIBPATH:C:/PROGRA~2/MICROS~3.0/VC/LIB/amd64 /LIBPATH:C:/PROGRA~2/MICROS~3.0/VC/ATLMFC/LIB/amd64 /LIBPATH:C:/PROGRA~2/WI3CF2~1/10/lib/100102~1.0/ucrt/x64 /LIBPATH:C:/PROGRA~2/WI3CF2~1/NETFXSDK/46D346~1.1/lib/um/x64 /LIBPATH:C:/PROGRA~2/WI3CF2~1/8.1/lib/winv6.3/um/x64 (The last two are "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/ amd64/cl.exe" and translations of %INCLUDE% and %LIB% as set in the "VS2015 x64 Native Tools Command Prompt" shell. AC_CHECK_HEADER(clang/AST/RecursiveASTVisitor.h, ...) in configure.ac wouldn't like CXX to start with INCLUDE=... LIB=... environment variable settings, so it wouldn't work to instead pass %INCLUDE% and %LIB% to cl.exe that way. See <https://wiki.documentfoundation.org/Development/clang-cl> for general information about building with clang-cl on Windows.) There's still some room for improvement marked "TODO". (And some of the unused* plugins, which are not run by default anyway, use Unix-style functionality, so have been disabled for now.) Change-Id: I6c28bdeb801af39ce2bae03111f455e2338d66c9 Reviewed-on: https://gerrit.libreoffice.org/42931 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
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-06-20loplugin:unusedfields fix false positiveNoel Grandin
When the field in question is read from inside a constructor initializer. In the process, create some needed infrastructure in the plugin classes. Change-Id: I2f440efa6912801a236727c9fe3180404616958c Reviewed-on: https://gerrit.libreoffice.org/38960 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-06-19only unit-test one loplugin at a timeNoel Grandin
tell the plugin code when we are unit-testing it, so we can suppress all the warnings except for the plugin we are currently testing Change-Id: I240c8e37eba90c219e53c29531a3a43bc841a1c8
2017-04-25tools: svstream.hxx needs only errcode.hxx & not errinf.hxxChris Sherlock
Change-Id: Ia28e35ae5af4f601e9a586a3deffbcd61702b0ca Reviewed-on: https://gerrit.libreoffice.org/36896 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
2017-01-27Make plugin rewriting work on Windows tooStephan Bergmann
...in a somewhat hacked-up way for now (see the TODO comment) Change-Id: Ida89fb8257b876cfca05b3048ce15996091c5703
2016-12-18On Windows, #include <process.h> for getpidStephan Bergmann
Change-Id: Ibfb52800cdde99298431dab9da1cb8109658c425
2016-10-16clang::FileEntry::getName now returns StringRef on Clang masterStephan Bergmann
Change-Id: I94c9676e52a3c60ad70567396a8484e844176c6e
2016-04-26Enable Clang plugin warnings in Bison source codeStephan Bergmann
-Werror is generally suppressed in Bison-generated C/C++ code (as in all other generated code) to silence warnings from the Bison skeleton code. And the Clang plugins suppress warnings in generated WORKDIR code based on the presumed source location (i.e., taking #line directives into account). So introduce a new PLUGIN_WARNINGS_AS_ERRORS mode where warnings from Clang plugins are reported as errors even if -Werror is suppressed. That way, any warnings in the Bison skeleton code still do not lead to compilation errors, while (at least plugin- emitted) warnings in the genuine source code do. Unfortunately this cannot also be enabled for Flex source code, as at least Flex 2.5.39 generates poor code that does not properly prefix all skeleton code with appropriate #line directives, so that some skeleton code would be mistaken for genunie source code, and compilation would fail due to errors. Also, %glr-parser Bison input appears to generate no #line directives at all (at least with Bison 3.0.4), so all of connectivity/source/parse/sqlbison.y is considered generated code and plugin warnings are still suppressed throughout. Change-Id: Id746e81cbfa5f77628b0a34c7b82780948e7db08
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
2015-11-02tdf#94269: Replace "n" prefix for bool variables with "b"Benjamin Ni
Change-Id: I178545792c7354a362658ac7ef8b1d4cf0865797 Signed-off-by: Michael Stahl <mstahl@redhat.com>
2015-10-30compilerplugins: check that we're not building ccache preprocessedMichael Stahl
... input, which breaks because a) isInUnoIncludeFile() will not recognize the paths (which is actually fixable if it used getPresumedLoc() to get the path), and b) the isMacroBodyExpansion() check in salbool.cxx (which doesn't look fixable). So instead of printing lots of spurious warnings just abort. Change-Id: I77fd77b4986d2b099453309ecdf31be9cf93ceec Reviewed-on: https://gerrit.libreoffice.org/19693 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Stephan Bergmann <sbergman@redhat.com>
2015-09-29Avoid ambiguity with C++14 std::make_uniqueStephan Bergmann
Change-Id: I81b8bed175527bab02ffdd2fa17fa6a66c243d95
2014-08-11Adapt compilerplugins to Clang trunk towards 3.6Stephan Bergmann
Change-Id: I0b7be1616a3e4206982f9f925de141ed9d53b96e
2014-02-27Remove visual noise from compilerpluginsAlexander Wilms
Change-Id: Ibfed0b64bd60804fa377b5e25e5f197a7772d605 Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
2014-02-25...but Flags parameter was plain unsigned int prior to Clang 3.4Stephan Bergmann
Change-Id: Ife39abda6b5274ae196dcbf591d02fa3f36f6072
2014-02-25raw_fd_ostream Flags parameter no longer defaultedStephan Bergmann
...at least on trunk r202077. Change-Id: Ieb59cc7ac70e2a57ac13eefdfcbb6bfa42e25218
2014-02-20Don't attempt to actually do double code removalsStephan Bergmann
...that easily works around the problem that in a rewriter rewriting types of VarDecls like T x, y; it would try to replace T twice. Also, keep the list of removals globally with the (global) rewriter. Change-Id: I55b8d11986c2a29e09ff40132fd114a0cc48dc90
2014-02-17Run the non-rewriter plugins even when rewriters are specifiedStephan Bergmann
Change-Id: I8262091c52522c54f84c0fac5fd180871d4a3a9f
2014-01-31clang::DiagnosticsEnginge::getCustomDiagID now needs a literal FormatStringStephan Bergmann
...at least in trunk 200400 towards Clang 3.5. Change-Id: Ibe956a7f28c16510506bd354582b3fe5a72582e5
2014-01-27Prepare dual-mode compiler plugin featureStephan Bergmann
...which can act as either a rewriter or a non-rewriter that emits warnings. Also added COMPILER_PLUGIN_WARNINGS_ONLY=X to demote warnings from plugin X from errors to warnings, even under --enable-werror. Change-Id: I05361936240a890515c6bba2459565417c1746b7
2013-10-31solver doesn't solve anything...Michael Stahl
... it is an abbreviation of "Solar Version". Since nobody can remember that: remove OUTDIR OUTDIR_FOR_BUILD SOLARVER SOLARVERSION solarpath and any mention thereof. Change-Id: Idb3031c4f25a76ac05b22ec67e3ca3e1e8e512ad Reviewed-on: https://gerrit.libreoffice.org/6515 Tested-by: LibreOffice gerrit bot <gerrit@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com>
2013-09-22add mode lines to new files (and idls) since last runCaolán McNamara
Change-Id: Id1e74f18c90e69d1a781c8f02e30dc3c005ed4fd
2013-08-21prevent crash when rewriting sourceLuboš Luňák
Change-Id: I97519c2fb08efa2c694c9fb91a4cc402a6347c2c
2013-08-06error: cannot use dynamic_cast with -fno-rttiStephan Bergmann
...with recent Clang trunk towards 3.4 Change-Id: Ie0991c7bd560c30551aeaada426382a889b46391
2013-06-05Adapt UPDATE_FILES=<module> to headers being moved to include/Stephan Bergmann
Change-Id: I6af5236358a51a51514d646c809147db56b2464b
2013-04-04don't explicitly delete PPCallbacks-based compiler plugin actionsLuboš Luňák
If the class is based on PPCallbacks too, Clang internals will delete the instance. Change-Id: I6dd83d800e6cca17eb0b5de23c8994f11c087fd5
2013-03-28pass around CompilerInstance rather than ASTContextLuboš Luňák
It's possible to get the latter from the former, and the former is useful for other things too (access to the preprocessor, for example). Change-Id: I708d709129fd3a35bf7c63da4de09c2e696b382d
2013-03-28-Wextra for compiler pluginsLuboš Luňák
Change-Id: I246dcf1d2c099c510435d21f0dd47e3c098456f2
2013-02-09make it possible to limit what files will be modified by a compiler pluginLuboš Luňák
Change-Id: I4e3e8f5ca5e5b5b59b1bd067281f90940dd893b1
2013-02-09fix check whether a file is in a directoryLuboš Luňák
Make sure / is appended, otherwise /foo might match /foobar/file . Change-Id: I36469916b72b407c8f0c9c255099ee671039cf17
2013-02-02remove not needed #includeLuboš Luňák
Change-Id: I0fa791733407199db5be2cc9606ac9be1da64188
2013-02-02append [loplugin] automatically in report() rathen than manually everywhereLuboš Luňák
Change-Id: I2f98622f152ae0c7ac8d1113d6380f686ac7234c
2013-02-02always use the report() helperLuboš Luňák
Change-Id: I2966fdb5bd98b1ddf718079584acf90a3e3a3700
2013-02-02move documentation of plugins to the .cxx filesLuboš Luňák
It's mostly there already anyway, no need to duplicate it. Change-Id: I5b066f90725a064fb0746e1411900e835e3f66c3
2013-02-02avoid having to manuall modify sources when adding a new clang pluginLuboš Luňák
Now each one registers in its .cxx file. Change-Id: I811c0d4400c2bdccc1c287269378d7e8ad8743ce
2013-02-02move plugin handling to separate source filesLuboš Luňák
Change-Id: Ifa1af34121bda9ca3250d09a3b8a46ea226795ed