summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/doubleconvert.cxx
blob: 2dbff56ca30bcd1e2f93993a067e99cf5bf9a841 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef LO_CLANG_SHARED_PLUGINS

#include "check.hxx"
#include "compat.hxx"
#include "plugin.hxx"

/**
 * Look for places where we are converting from type A through a conversion operator and back to type A,
 * which is redundant. At the moment only look for Color, to aid my ColorData->Color conversion
 */
namespace
{
class DoubleConvert final : public loplugin::FilteringPlugin<DoubleConvert>
{
public:
    explicit DoubleConvert(loplugin::InstantiationData const& data)
        : FilteringPlugin(data)
    {
    }
    void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }

    bool VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr const*);
};

/**
 The AST looks like:

 CXXOperatorCallExpr 0x8e5b840 'class Color' lvalue
|-ImplicitCastExpr 0x8e5b828 'class Color &(*)(class Color &&) noexcept' <FunctionToPointerDecay>
| `-DeclRefExpr 0x8e5b800 'class Color &(class Color &&) noexcept' lvalue CXXMethod 0x8e59a08 'operator=' 'class Color &(class Color &&) noexcept'
|-DeclRefExpr 0x8e5b678 'class Color' lvalue Var 0x8e5b5d0 'col2' 'class Color'
`-MaterializeTemporaryExpr 0x8e5b7e8 'class Color' xvalue
  `-CXXConstructExpr 0x8e5b7b0 'class Color' 'void (ColorData)'
    `-ImplicitCastExpr 0x8e5b798 'ColorData':'unsigned int' <IntegralCast>
      `-CXXFunctionalCastExpr 0x8e5b770 'sal_Int32':'int' functional cast to sal_Int32 <NoOp>
        `-ImplicitCastExpr 0x8e5b758 'sal_Int32':'int' <UserDefinedConversion>
          `-CXXMemberCallExpr 0x8e5b730 'sal_Int32':'int'
            `-MemberExpr 0x8e5b6f8 '<bound member function type>' .operator int 0x8e51048
              `-ImplicitCastExpr 0x8e5b6e0 'const class Color' lvalue <NoOp>
                `-DeclRefExpr 0x8e5b6b0 'class Color' lvalue Var 0x8e5b518 'col1' 'class Color'
*/
bool DoubleConvert::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr const* materializetemp)
{
    if (ignoreLocation(materializetemp))
        return true;
    auto cxxConstruct
        = dyn_cast<CXXConstructExpr>(compat::getSubExpr(materializetemp)->IgnoreParenCasts());
    if (!cxxConstruct)
        return true;
    if (cxxConstruct->getNumArgs() == 0)
        return true;
    auto cxxMemberCallExpr
        = dyn_cast<CXXMemberCallExpr>(cxxConstruct->getArg(0)->IgnoreParenCasts());
    if (!cxxMemberCallExpr)
        return true;
    if (!isa<CXXConversionDecl>(cxxMemberCallExpr->getMethodDecl()))
        return true;
    if (materializetemp->getType().getCanonicalType().getTypePtr()
        != cxxMemberCallExpr->getImplicitObjectArgument()
               ->getType()
               .getCanonicalType()
               .getTypePtr())
        return true;
    if (!loplugin::TypeCheck(materializetemp->getType().getCanonicalType())
             .Class("Color")
             .GlobalNamespace())
        return true;

    report(DiagnosticsEngine::Warning, "redundant double conversion", materializetemp->getExprLoc())
        << materializetemp->getSourceRange();
    return true;
}

static loplugin::Plugin::Registration<DoubleConvert> doubleconvert("doubleconvert");
}

#endif // LO_CLANG_SHARED_PLUGINS

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
:44 +0200'>2014-09-17Remove obsolete -malign-natural on Mac OS X from SDK, tooStephan Bergmann ...causes "clang: error: unknown argument: '-malign-natural' [-Wunused-command-line-argument-hard-error-in-future]; clang: note: this will be a hard error (cannot be downgraded to a warning) in the future" at least with "Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)", and last mention of -malign-natural in solenv/gbuild was removed with 4ea84822b1b638a61495af5006041bea8db8a3eb "OSX: drop -malign-natural flag for non-clang compilers." Change-Id: I0db1de484e45ba3eddf113392da71f20d099e9b5 2014-09-16Fix OO_SDK_URE_HOME for new Mac OS X layoutStephan Bergmann Change-Id: I438b9ca643819cfd3e636e8157c6ef491beb1903 2014-01-30SDK: Split PLATFORMID at build time rather than runtimeStephan Bergmann ...where $(shell printf ...) in settings.mk likely doesn't work on Windows. Change-Id: I64a51203d1bf131160768f9a9069f428228aa6b1 2014-01-20Fix Mac OS X 64 bit SDK settings.mkStephan Bergmann ...to simply use Xcode clang++ (which implicitly uses libc++). Change-Id: I02578f971e4abddfe74211046674bdcd23d7b279 2014-01-20SDK settings.mk: Don't guess PLATFORM/PROCTYPEStephan Bergmann ...rather, pass them from the build to the SDK installation via dk.mk. (The SDK installation is already platform-specific anyway, see the binary executables in its bin/ directory, so there is no point in not fixing this at build time. In the future, the shipped settings.mk could of course be stripped to just the parts relevant for a given platform, of course.) Along the way, fixes some apparent "ppc" vs. "powerpc" typos in settings.mk. This is a prerequisite to create a working settings.mk for macosx_x86_64, but does not yet do that. Change-Id: Ib8e0c03ad6dfd610aae58a61e32bdc61c785584f 2013-12-18fdo#72598: odk: remove SunStudio supportMichael Stahl No idea if the GCC stuff that's in there actually works. Change-Id: Idd1b93edd88609f3c09d14134d00a15fa9c0b0b7 2013-12-11ure: remove references to SunStudio C52 filenamesMichael Stahl Change-Id: If11655aa56239b9241db43a058244360a8abe1ec 2013-07-18Resolves: #i122767# disallow pre-standard C++ for-scopeHerbert Dürr (cherry picked from commit 197b1ac3007b870e6c51ae9c767ad4f2a340e799) Conflicts: odk/settings/settings.mk solenv/gbuild/platform/windows.mk solenv/inc/set_wntx64.mk solenv/inc/wntmsci11.mk Change-Id: I266a0d7672839b4568e76b7223aae15d82cd9a63 2013-04-19Adapt SDK to usage of msvcrtd for Windows --enable-dbgutilStephan Bergmann * Re-use existing settings/dk.mk to tunnel ENABLE_DEBUG into the SDK. Turns out this was explicitly included in ~all examples Makefiles, but only after settings.mk where it is now used, so include it in settings.mk now and dropped it from all the exmaples Makefiles. * The old settings.mk was apparently confused with using /MT ("link with LIBCMT.LIB") on cl command line and /MD ("link with MSVCRT.LIB") on link command line (where it was ignored), and you apparently can't pass both together to cl, so I settled on /MD (resp. /MDd) now and dropped /MT (resp. /MTd). No idea if that is exactly right, however. * Introduced client-facing LIBO_SDK_LDFLAGS_STDLIBS that covers kernel32.lib and msvcrt.lib vs. msvcrtd.lib on Windows. Adapted examples Makefiles and /ure/source/uretest/Makefile accordingly. Some examples Makefiles additionally use msvcprt.lib, no idea whether that still needs to be addressed. Change-Id: Ia8d9d177e415abfbaf6f9fa6239f0ef9998868be 2013-04-18Properly set PS to a single backslash for WindowsStephan Bergmann I guess all those $(subst \\,\,...) in odk/examples/.../Makefile are only workarounds for a broken PS setting and could go, too. Change-Id: I2e44108f23803e1f49157a91be11af5ad860673c 2013-04-10API CHANGE: odk: remove "store" and "reg" librariesMichael Stahl These libraries were never part of the stable URE interface, and thus including their headers and import libs in the SDK was a mistake. Apparently at least on MacOSX and some Linux distros it was not possible to link against the libraries anyway. Change-Id: I3c43c86ff5d7bc316ed7af0be4ef313f7869ac23 2013-04-10odk: settings.mk: add variable PURPENVHELPERLIBMichael Stahl This library is part of the stable URE interface. Change-Id: Id131bdd333ecff2ae788830ca4b5b57b4a4a9c24 2013-04-04remove -dylib_file mappings that are not needed anymoreChristian Lohmaier XCode 2.5 (i.e. Mac OSX 10.4 & 10.5) couldn't find the libraries without explicit mapping, but as baseline is now 10.6, this wrapping is no longer necessary Change-Id: I225fc47b9ea4b1fb2b13ba575605cbdebc014fd8 Reviewed-on: https://gerrit.libreoffice.org/3192 Tested-by: LibreOffice gerrit bot <gerrit@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com> 2013-04-03Remove Mac OS X for PowerPC supportTor Lillqvist Change-Id: I10b15141e6a5f93365e1cfa6fbc0c7cc3ea49b15 2013-02-28Unused UDK_MAJOR/MINOR/MICRO macros (and udkversion.mk), also removed from SDKStephan Bergmann Change-Id: I466424c5b71de4d6bb126499895539813283502a 2013-02-20rhbz#742780: Let make OPT_FLAGS=... override SDK optimization/debugging flagsStephan Bergmann Change-Id: I639fa16f74342b108a395d7d0335d116f96677f1 2012-12-17Remove --with-stlport from LO 4.0Stephan Bergmann The STLport was only built for the benefit of old extensions on platforms that once used it themselves (Linux x86, Solaris x86 and SPARC, Windows). We deliberately break such old extensions for LO 4.0 by no longer shipping that backwards-compatiblity cludge. Keeps STLport listed in readlicense_oo/ because of o3tl/inc/o3tl/compat_functionality.hxx. Also removes GXX_INCLUDE_PATH, as that was only used by STLport (if at all?). Removes a spurious #define MOVEFILE_REPLACE_EXISTING 0x01 from l10ntools/inc/helpmerge.hxx that was once added with 854812584862d0609b695682d2bfea2667d75c00 "INTEGRATION: CWS extensionl10nfix01 (1.11.6); FILE MERGED: 2008/06/26 13:56:03 ihi 1.11.6.1: #i90987# windows rename -> MoveFileEx" but now starts to cause trouble on Windows. Also disables warning C4005 about redefinition of WB_LEFT/RIGHT macros (defined in both tools/wintypes.hxx and the Windows API) in a number of places that include windows.h -- however the old STLport caused those warnings to not show. Change-Id: Ie138a219fbbc86fb5aaa7ea0b88cf349935d9829 2012-11-22Use xcrun when available to run install_name_toolTor Lillqvist This hopefully should help in situations like Jonathan Aquilina's, where /usr/bin/install_name_tool does not correspond to the tool-chain used (but is from an earlier version of Xcode). Change-Id: I5b4ca9e5e163fb4a84967577d2146cdbe8344f03 2012-11-12re-base on ALv2 code. Includes:Michael Meeks Patches contributed by Pedro Giffuni: Avoid some uses of non portable #!/bin/bash in shell scripts. http://svn.apache.org/viewvc?view=revision&revision=1235297 Reduce the dependencies on non standard GNU copy. http://svn.apache.org/viewvc?view=revision&revision=1238684 Correct /usr/bin/env path. http://svn.apache.org/viewvc?view=revision&revision=1235619 Complex Toolbar Controls Extension from the SDK Patches contributed by Ariel Constenla-Haile http://svn.apache.org/viewvc?view=revision&revision=1190390 i118615 - make epm more verbose http://svn.apache.org/viewvc?view=revision&revision=1204288 Patches contributed by Mathias Bauer (and others) gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 Patches contributed by Juergen Schmidt: jsc341: i117327: take care if no dependency node in current description exists, create one http://svn.apache.org/viewvc?view=revision&revision=1172101 jsc341: i117327: add extra extension dependency check http://svn.apache.org/viewvc?view=revision&revision=1172098 make initial branding changes http://svn.apache.org/viewvc?view=revision&revision=1231878 Patches contributed by Ingo Schmidt native373: #i117733# no linux jre installation on 64 bit systems http://svn.apache.org/viewvc?view=revision&revision=1167536 native373: ##164464# improve debian support http://svn.apache.org/viewvc?view=revision&revision=1167537 Patch contribtued by Armin Le-Grand: Changed various aspects concerning usages of old vendor names http://svn.apache.org/viewvc?view=revision&revision=1293313 fix for neon webdav, remove coinmp bits, improve odk script, cleanup & remove OS/2 conditionals, system ucpp fixes, remove OS/2 conditionals, restore our license filenames. 2012-08-30Fix -Wl,-z,origin -Wl,-rpath,... quotingStephan Bergmann Change-Id: I65eac6ab34d2d54eeaa2bc14838711f700d0d535 2012-08-29fdo#54015: At least FreeBSD ld requires -z origin when RPATH contains $ORIGINJung-uk Kim Signed-off-by: Stephan Bergmann <sbergman@redhat.com>: * bulk replacement of "-Wl,-z,origin,-rpath,..." with "-Wl,-z,origin -Wl,rpath,..." * additional hunk for directory/c-sdk/config/FreeBSD.mk in moz/seamonkey-source-1.1.14.patch did not apply and has been dropped Change-Id: Ie60c696f041108e819ce8f799cff6f58e63a5ad7 2012-07-10solaris: update settings.mk to use gccPierre-Eric Pelloux-Prayer Change-Id: Ife7a4806776f55babfab11ceac25a3d2d66fe5af