156 Commits

Author SHA1 Message Date
Matúš Kukan
37facd4f70 Store compilerplugin warning about classes derived from a specific class.
Useful in case someone wants to find all classes deriving from "foo" and "bar".

Change-Id: I7b12882881712d37976eb8c96fad6e9c9ac01370
2014-02-14 11:11:53 +01:00
Stephan Bergmann
d19598b56c Adapt ImplicitBoolConversion to 32-bit builds (where sal_Int32 is long)
Change-Id: I64480e6026e7e39fe89f90c7d269f6bb1d02968d
2014-02-13 10:49:13 +01:00
Noel Grandin
15535e32dd convert SvStream::operator>> methods to ReadXXX methods
First, I updated the clang rewriter to do the conversion.
Then I lightly hand-tweaked the output for the few places where
the rewriter messed up, mostly when dealing with calls on "this".

Change-Id: I40a6a977959cd97415c678eafc8507de8aa3b1a9
Reviewed-on: https://gerrit.libreoffice.org/7879
Reviewed-by: Michael Stahl <mstahl@redhat.com>
Tested-by: Michael Stahl <mstahl@redhat.com>
2014-02-12 15:31:40 +00:00
Andrzej Hunt
b8ca3737fb DiagnosticsEngine::getCustomDiagID isn't const, so don't pass in const engine.
Change-Id: I7e4494b7f1cb62ab27851e34ab4dc6be8e04e1fa
Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
2014-01-31 16:42:08 +01:00
Jesús Corrius
82300f367d sbergman's typo
Change-Id: I36dc29659d0d6965c28e5fe0bb03759476de4781
2014-01-31 12:55:13 +01:00
Stephan Bergmann
11235e8649 clang::DiagnosticsEnginge::getCustomDiagID now needs a literal FormatString
...at least in trunk 200400 towards Clang 3.5.

Change-Id: Ibe956a7f28c16510506bd354582b3fe5a72582e5
2014-01-31 09:50:21 +01:00
Stephan Bergmann
b21e3d16aa Clang API function terminology got changed
...at least in trunk 200400 towards Clang 3.5.

Change-Id: I6e295e3a4cf721fbda9df8e7c5bed3993ee78216
2014-01-31 09:44:46 +01:00
Noel Grandin
a1aa702861 literaltobool conversion plugin, reduce spurious warnings with clang 3.3
It appears that clang 3.3 also generates spurious warnings, so
adjust the ifdef

Change-Id: Idb57f7eafd55effd4c7c8b1f96c03c2ea6ddaba3
2014-01-30 15:41:27 +02:00
Stephan Bergmann
81760e2702 implicitboolconversion: also warn about redundant explicit casts
Change-Id: Ib89b4c12d2cdca873a9fe9a509d7a123977652a7
2014-01-29 15:42:37 +01:00
Stephan Bergmann
c03a2a0b1b Further fix for old Clang versions
...maybe this needs adaption for 3.3 or 3.4 too, known to work with trunk
towards 3.5.

Change-Id: I9f05ae44e4a49ae51df69d5a3c1df5eb371a1c87
2014-01-29 11:15:44 +01:00
Stephan Bergmann
d433d8245b Fix for old Clang versions
Change-Id: Ib902535c03a9f1b93a2c4ff3dd61d29e316bfd49
2014-01-29 09:58:10 +01:00
Stephan Bergmann
3de97578e4 Clang plugin to warn about implicit conversion of literals to bool
...which warns about apparent errors like

  n == KIND_FOO || KIND_BAR

that should have read

  n == KIND_FOO || n == KIND_BAR

It also warns about trivial (mis-)uses of 0/1 and sal_False/True like

  while (1) { ... }

instead of

  while (true) { ... }

which it can automatically rewrite.

It does not warn if the relevant code is inside a macro in a .h (i.e., C)
include file, nor when a string literal is used in the assert macro like

  assert(!"this cannot happen");

Change-Id: If8c305a25e5da15e78f6139b5b0c0e868f06d4f3
2014-01-28 20:26:31 +01:00
Stephan Bergmann
1f078fcadd Prepare dual-mode compiler plugin feature
...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
2014-01-27 13:12:33 +01:00
Stephan Bergmann
cd20baf40a implicitboolconversion: warn about mixing bool with integer
...in &=, |=, ^=, as does MSVC, too.

Change-Id: I57ecc9d784dd483e04ae561c62595b1d0380517f
2014-01-26 12:28:09 +01:00
Stephan Bergmann
8128644312 implicitboolconversion: also warn about mixing bool/sal_Bool in &=, |=, ^=
...as MSVC would warn about those anyway.

Change-Id: If22dfd35bc01aff1a1bef68702c616e711db42fb
2014-01-22 15:00:54 +01:00
Stephan Bergmann
cb710f3a1e implicitboolconversion: also warn about mixing bool/sal_Bool in == etc.
...as MSVC would warn about those anyway (at least about cases that do not
compare against literal sal_True/sal_False, but warning even about those helped
clean up lots of redundant

  if (foo == true)

instead of just

  if (foo)

etc. across the code base).

Change-Id: Iad4b335c35c5411070f04f87f974db7942c288d4
2014-01-22 11:39:22 +01:00
Stephan Bergmann
4865115d1b Improve Clang 3.2 hasCLanguageLinkageType workaround
Change-Id: If5c104adc05aa362d15cedf6f8953bda478897bc
2014-01-22 11:03:30 +01:00
Stephan Bergmann
3c2a6ad96b Make implicitboolconversion.cxx compile with Clang 3.2
Change-Id: I011e74fd044d0b76cccc60adea362805917c584a
2014-01-20 14:32:35 +01:00
Stephan Bergmann
e908f69ec0 Clang plugin that flags implicit conversions from bool
...as they are often enough errors, like a typo in brace placement in

  if (foo == (FOO || bar == BAR) && baz)

or a literal true passed as an argument to a function that rather expects an
integer bit mask, etc.  The plugin is smart enough to detect interaction with
logically boolean return/parameter types of C functions that use [unsigned] int
instead, and knows the relevant boolean typedefs (sal_Bool, gboolean, etc.).

Change-Id: I5f0e4344fe86589bec35a71018c7effdedf85e3e
2014-01-17 18:45:16 +01:00
Stephan Bergmann
0d824b5cc1 compilerplugins: ignore WORKDIR code
...which is typically external or generated code and causes warnings that
we cannot easily fix.

Change-Id: If86ecd96c069ec23c6b3d7f5c32bf962397393e5
2014-01-10 17:11:42 +01:00
Noel Grandin
de84529b55 Clang plugin to re-write SvStream operator<< to non-overloaded methods
Use a clang rewriter to rewrite SvStream::operator<< to methods
like WriteUInt32.
Note that the rewriter is not perfect, and hand-tweaking the output
is necessary.

Change-Id: I0291c8192ca74d6334ed3cf8cb713212b2f0c67d
Reviewed-on: https://gerrit.libreoffice.org/7307
Reviewed-by: Michael Stahl <mstahl@redhat.com>
Tested-by: Michael Stahl <mstahl@redhat.com>
2014-01-10 13:26:15 +00:00
Michael Stahl
5d8f48c81e solver doesn't solve anything...
... 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-10-31 15:42:24 +00:00
Caolán McNamara
3656a57e88 add mode lines to new files (and idls) since last run
Change-Id: Id1e74f18c90e69d1a781c8f02e30dc3c005ed4fd
2013-09-22 12:21:34 +01:00
Luboš Luňák
b0b087cd18 move valueof compiler plugin
The mass-conversion has been already done, so it's most probably
not needed anymore.

Change-Id: I3f161b8ea122e4dd185746ea29509b0d7768d6c7
2013-08-27 18:11:21 +02:00
Luboš Luňák
64b993e046 finish deprecation of O(U)String::valueOf()
Compiler plugin to replace with matching number(), boolean() or OUString ctor,
ran it, few manual tweaks, mark as really deprecated.

Change-Id: I4a79bdbcf4c460d21e73b635d2bd3725c22876b2
2013-08-21 15:10:35 +02:00
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