231 Commits

Author SHA1 Message Date
Luboš Luňák
75f41baab6 warn when rewriter should modify something involving a macro
Apparently Clang rewriter API doesn't properly bail out if the range
given is not inside one file, so check explicitly.

Change-Id: I27be6d396a131d385231e9c0dfa8c84d9fa15ccc
2013-08-21 15:08:16 +02:00
Luboš Luňák
21c795488c prevent crash when rewriting source
Change-Id: I97519c2fb08efa2c694c9fb91a4cc402a6347c2c
2013-08-21 15:08:16 +02:00
Luboš Luňák
4f60eb885a helper for getting location after current token
Given that locations often point to a (start of) token, even if it's
e.g. getLocEnd(), this should be very useful.

Change-Id: I266e4c0a234262e99158c8f495b631f54f8a5608
2013-08-21 15:08:16 +02:00
Luboš Luňák
0809d7d792 update/rework the Rewriter wrapper functions
Some improvements, like making it simple to actually remove a statement
or a token including its associated whitespace.

Change-Id: I02a5bd919f1fadae1dcd45a76f9d25df353ac518
2013-08-21 15:08:16 +02:00
Stephan Bergmann
653cdcf50c error: cannot use dynamic_cast with -fno-rtti
...with recent Clang trunk towards 3.4

Change-Id: Ie0991c7bd560c30551aeaada426382a889b46391
2013-08-06 17:59:09 +02:00
Luboš Luňák
c352f340c2 note about getDirectCallee() vs getCallee()
Change-Id: I0a4cfd0ddb0c03b0db95d003004195df29a3f6df
2013-08-05 15:10:40 +02:00
Luboš Luňák
015d932735 'generic' compiler plugin to modify calls to a specific function
Change-Id: I60756d9054dfa5c55aeae8ddc904ddf6d67d2088
2013-08-05 15:10:40 +02:00
Stephan Bergmann
06312f82e6 Adapt to PPCallbacks.h changes on Clang trunk towards 3.4
Change-Id: I5611ffd36f9c6d1560a6ada6118a1efaeb6dc522
2013-07-24 10:24:32 +02:00
Luboš Luňák
92dfa82d2d adjust for upstreaming of warn_unused attribute
The warn_unused attribute has been upstream to GCC and Clang, so use it if present.
Still warn about STL types if those do not use it yet (which is the status as of now).

Change-Id: I3c003e44c08d1d141e23bba38cf92e663a5ac353
2013-07-23 09:52:11 +02:00
Luboš Luňák
c17c8cc029 mention the explicit bool conversion from C++11 for pointer-to-bool check
Change-Id: I050019b30d2ec96bbd25916624f8cb88d72110e4
2013-07-16 15:41:40 +02:00
Luboš Luňák
22fa63a4fa compiler plugin warning about unwanted silent pointer-to-bool conversions
C/C++ silently converts pointers to booleans, which is presumably seen as
a good idea by lazy people, but it can occassionally silently break code
in strange ways, most notably by selecting a bool overload when no matching
overload for the pointer exists (OUStringBuffer::append() can break like that,
e.g. in ba37e4062f538db7e51d6a64ba544eeddbc567cf, other cases are
8e3bf1598fa95ac8d099e45ae4252e7654a6f590 or 28e4c0250e67a344b4d6088bdca2e680a4bffad0).

So far the plugin checks only conversions in function call arguments, there's
disabled code that could check more places, but I'm not aware so far of any place
where anything actually broke because of that, and it'd require fixups to be
explicit in some places (e.g. 'bool b = returns_pointer();' would require '!= NULL'
added), so for it'll be only the simple various and it can be made more strict if wanted.

Change-Id: I6a5d207daf925e6c2d1bf684060536795ecfcc35
2013-07-15 23:29:47 +02:00
Luboš Luňák
9d65113efe fix finding all parents for AST nodes
Ctor bodies can also have code inside of member variables initialization,
which is not considered to be inside function body.

Change-Id: Id68960093a51396b9486f1364b1a361526c3431d
2013-07-15 23:12:12 +02:00
Luboš Luňák
597178ceec simplify bodynotinblock plugin using parentStmt()
Change-Id: Ia2fe10af2ca555c7b88348e7ed571f1176586580
2013-06-20 07:21:32 +02:00
Luboš Luňák
81b58bb075 simplify postfixincrementfix plugin using parentStmt()
Change-Id: I93fa422afe7f3e1e10576dd64af9d57b2302f44e
2013-06-20 07:21:31 +02:00
Luboš Luňák
ade47d3d67 make it easy to get a parent of an AST node
Clang API doesn't provide this, but it's occasionally needed, and so far
the way has been inspecting the highest possible node in AST and walking down
and remembering, which is complicated, error-prone and annoying.

Change-Id: Id5b72cb5ebfc069e90efe6d673c0ef18ebcdab61
2013-06-20 07:21:31 +02:00
Stephan Bergmann
3d963884cb Adapt UPDATE_FILES=<module> to headers being moved to include/
Change-Id: I6af5236358a51a51514d646c809147db56b2464b
2013-06-05 23:32:16 +02:00
Luboš Luňák
0df04e0331 fix plugin build with clang < 3.3
Change-Id: If2eb7595ca7d25f6d491e332bb3060061d3b42a7
2013-06-02 16:33:25 +02:00
Luboš Luňák
6d114cda2c make compiler plugin warnings follow WaE
Change-Id: I72f1a11ce86d66e773e66116c725310df77fce39
2013-05-31 20:00:54 +02:00
Luboš Luňák
b0a650ff8a update for PPCallbacks API changes in Clang3.3
Change-Id: I8493afa8e2264a42fba090c9c72f36f36cb2d165
2013-05-31 20:00:54 +02:00
Luboš Luňák
a0d320096c mark all virtuals in the clang plugin as override
In order to help catch Clang API changes.

Change-Id: I5738f5dff405f7a2dd377c983fb32c1c7a2ff921
2013-05-31 20:00:53 +02:00
Noel Grandin
6a043e9c0a Use the new type-checking Reference constructor to reduce code noise
Also create a Clang compiler plugin to detect such cases.

Change-Id: I61ad1a1d6b1c017eeb51f226d2dde0e9bb7f1752
Reviewed-on: https://gerrit.libreoffice.org/4001
Tested-by: LibreOffice gerrit bot <gerrit@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>
2013-05-22 10:44:29 +00:00
Luboš Luňák
9cb21a3342 check for double modifications in compiler plugins
A different way to do 1c0669af2f1f58e6431b5e489ac48a883e242ba7.
Sometimes one piece of code can be represented several times in the AST,
e.g. with default function arguments.

Change-Id: Ic7799fa0bd918a638bdc8ebef69e6aa91d355bdc
2013-05-06 16:51:45 +02:00
Luboš Luňák
d870271c23 compiler plugin for RTL_CONSTASCII_USTRINGPARAM removal
Change-Id: Ibc487aa78d9eba3f936b4f4cc0298adfaef60d5c
2013-05-06 16:51:45 +02:00
Luboš Luňák
d01768c31a Revert "ignore already seen locations in compiler plugins"
This does not always work well, e.g. when building a return value
in a return statement from a temporary, there is CXXConstructExpr
containing CXXTemporaryObjectExpr, which both share the same location.
This reverts commit 1c0669af2f1f58e6431b5e489ac48a883e242ba7.
2013-05-06 16:49:36 +02:00
Luboš Luňák
a0da672521 ignore already seen locations in compiler plugins
Change-Id: Icba8dfa61aee7237af569b2414b1cf4ce93ca476
2013-05-06 16:49:36 +02:00
Luboš Luňák
6f16cfb5a6 Fix handling range in removeText().
Turns out removeText( SourceRange ) treats it as a token range, so it's
not always character-exact if used for removal of only several characters
from a token (e.g. an identifier).

Change-Id: I0223d52da90f9535d9ef1d48b0f56d69131536c8
2013-05-06 16:49:36 +02:00
Luboš Luňák
e6c20364e7 add const
Change-Id: I71236b9ca6300372ba00c85401cf19f6c0e7ac99
2013-05-02 18:19:59 +02:00
Tor Lillqvist
294ad90704 Update location of log-areas.dox
Change-Id: If54a3d7047f13ae9c9345c21737a89afee645403
2013-04-24 11:42:09 +03:00
Luboš Luňák
b8dd396976 base for unusedcode compiler plugin
Needs work to actually do something useful, but the basics are there.

Change-Id: I193922f2f5572760c8c20def0f9b830138f47fef
2013-04-22 17:56:47 +02:00
Luboš Luňák
5f8a2dc398 removeforwardstringdecl clang plugin has been used, move it
Change-Id: I3bccfa773448e17ac3c8ece6b99f85c6d399b0cf
2013-04-07 14:23:12 +02:00
Luboš Luňák
c3ffd741b2 compiler plugin to check incorrect #ifdef for config_XXX.h macros
http://lists.freedesktop.org/archives/libreoffice/2013-March/047769.html

Change-Id: Ibba9d3dcc87d6d6eee58ab3690a8f87339d00956
2013-04-04 13:05:02 +02:00
Luboš Luňák
996b6fc92b don't explicitly delete PPCallbacks-based compiler plugin actions
If the class is based on PPCallbacks too, Clang internals will delete
the instance.

Change-Id: I6dd83d800e6cca17eb0b5de23c8994f11c087fd5
2013-04-04 13:05:02 +02:00
Luboš Luňák
c63e6c38c9 adjust unused compiler plugins for ASTContext to CompilerInstance change too
Change-Id: I415ed25586408d7e7df9457f7c637a8c6d13d35d
2013-03-28 18:08:05 +01:00
Luboš Luňák
153a69cad2 pass around CompilerInstance rather than ASTContext
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 18:01:00 +01:00
Luboš Luňák
9ab15ecc4f -Wextra for compiler plugins
Change-Id: I246dcf1d2c099c510435d21f0dd47e3c098456f2
2013-03-28 18:01:00 +01:00
Stephan Bergmann
24387f1c58 A plugin to find suboptimal equalsIgnoreAsciiCaseAscii[L] calls
Change-Id: Id2572982ca899223b89016ee7482ccb960032805
2013-03-19 11:02:28 +01:00
Tor Lillqvist
616c6924f1 s/the the/the/
Change-Id: Iadacffaad832c6ff06757e8567e24f929f24a4c3
2013-02-22 09:58:19 +02:00
Marc-André Laverdière
847749e975 Fixed compilation error of Clang plugins on Ubuntu/Mint
Change-Id: Ib08c5075034e0e16c5541f05425ef15d2cc3a6f6
Reviewed-on: https://gerrit.libreoffice.org/2045
Reviewed-by: Luboš Luňák <l.lunak@suse.cz>
Tested-by: Luboš Luňák <l.lunak@suse.cz>
2013-02-11 10:09:17 +00:00
Luboš Luňák
857a392654 make it possible to limit what files will be modified by a compiler plugin
Change-Id: I4e3e8f5ca5e5b5b59b1bd067281f90940dd893b1
2013-02-09 18:48:31 +01:00
Luboš Luňák
8f1a01ad00 fix check whether a file is in a directory
Make sure / is appended, otherwise /foo might match /foobar/file .

Change-Id: I36469916b72b407c8f0c9c255099ee671039cf17
2013-02-09 18:48:31 +01:00
Luboš Luňák
4fd910a096 tutorial examples for writing new Clang plugin actions
http://wiki.documentfoundation.org/Clang_plugins

Change-Id: Ieb4fc186490e81ab961c094ca0a7fcdabc0f348f
2013-02-02 22:59:46 +01:00
Luboš Luňák
276953ef21 remove not needed #include
Change-Id: I0fa791733407199db5be2cc9606ac9be1da64188
2013-02-02 22:59:45 +01:00
Luboš Luňák
f5ee30c3ee append [loplugin] automatically in report() rathen than manually everywhere
Change-Id: I2f98622f152ae0c7ac8d1113d6380f686ac7234c
2013-02-02 22:59:45 +01:00
Luboš Luňák
b4392c575e always use the report() helper
Change-Id: I2966fdb5bd98b1ddf718079584acf90a3e3a3700
2013-02-02 22:59:45 +01:00
Luboš Luňák
108a95630d move clang plugin that's no longer needed
But still keep it in case it'd be needed again, or simply
as a starting reference.

Change-Id: If519e1320e1bd6dce7746b57172324b33504051e
2013-02-02 22:59:44 +01:00
Luboš Luňák
a1c61eb112 move documentation of plugins to the .cxx files
It's mostly there already anyway, no need to duplicate it.

Change-Id: I5b066f90725a064fb0746e1411900e835e3f66c3
2013-02-02 22:59:44 +01:00
Luboš Luňák
a7c3adb773 avoid having to manuall modify sources when adding a new clang plugin
Now each one registers in its .cxx file.

Change-Id: I811c0d4400c2bdccc1c287269378d7e8ad8743ce
2013-02-02 22:59:44 +01:00
Luboš Luňák
b8f932b6a5 move plugin handling to separate source files
Change-Id: Ifa1af34121bda9ca3250d09a3b8a46ea226795ed
2013-02-02 22:59:44 +01:00
Luboš Luňák
d9a5c6bdf0 fix detection whether to ignore a source file or not
When compiling using icecream, the whole input is one file fed from stdin,
so getBufferName() is "<stdin>", so get the filename from #line directives.

Change-Id: Ie87937b10b0c7e8ddfa57a405b80fd9bde68dd0a
2013-01-11 14:58:58 +01:00
Luboš Luňák
62532ad485 do not set our clang timestamp to the timestamp of the clang binary
If the clang binary comes from a package which had been built before
any of our clang related sources were changed the last time, the timestamp
would be older and so there would be no rebuild. So do the stamp handling
the usual way, clang upgrades will work fine, downgrades will not, but
that's the same problem like with downgrading a library and its headers.

To somewhat mitigate the problem (Clang plugin doesn't get cleaned by
'make clean'), include the full Clang version (which includes SVN revision)
in config_clang.h and make all Clang plugin code include that, so
at least configure re-run will trigger a rebuild if necessary.

Change-Id: I993197f79e92e36105092c92c33b2e1db343e975
2013-01-06 18:23:04 +01:00