VirtualBox

Changeset 69076 in vbox for trunk


Ignore:
Timestamp:
Oct 13, 2017 2:42:00 PM (7 years ago)
Author:
vboxsync
Message:

bldprogs/gccplugin: Made it build with gcc 7.2.0 on ArchLinux.

Location:
trunk/src/bldprogs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bldprogs/Makefile.kmk

    r62534 r69076  
    7979VBoxCompilerPlugInsGcc.o VBoxCompilerPlugInsCommon.o VBoxCompilerPlugIns.o gccplugin: gccplugin$(SUFF_DLL)
    8080gccplugin$(SUFF_DLL): VBoxCompilerPlugInsGcc.cpp VBoxCompilerPlugInsCommon.cpp VBoxCompilerPlugIns.h
    81         $(TOOL_GXX3_CXX) -shared -fPIC -g \
     81        $(TOOL_GXX3_CXX) -shared -fPIC -fno-rtti -g \
    8282                -DIN_RING3 \
    8383                $(if-expr "$(KBUILD_TYPE)" != "release",-DDEBUG,) \
  • trunk/src/bldprogs/VBoxCompilerPlugIns.h

    r62537 r69076  
    3838typedef struct VFMTCHKSTATE
    3939{
    40     long        iFmt;
    41     long        iArgs;
    42     const char *pszFmt;
    43     bool        fMaybeNull;
     40    long            iFmt;
     41    long            iArgs;
     42    const char     *pszFmt;
     43    bool            fMaybeNull;
    4444#if defined(__GNUC__) && !defined(VBOX_COMPILER_PLUG_IN_AGNOSTIC)
    45     gimple      hStmt;
    46     location_t  hFmtLoc;
     45# if RT_GNUC_PREREQ(6, 0)
     46    gimple const   *hStmt;
     47# else
     48    gimple          hStmt;
     49# endif
     50    location_t      hFmtLoc;
    4751#endif
    4852} VFMTCHKSTATE;
  • trunk/src/bldprogs/VBoxCompilerPlugInsGcc.cpp

    r66779 r69076  
    55
    66/*
    7  * Copyright (C) 2006-2016 Oracle Corporation
     7 * Copyright (C) 2006-2017 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2424#include <iprt/stdarg.h>
    2525
     26#if RT_GNUC_PREREQ(5, 1)
     27# include "gcc-plugin.h"
     28# include "plugin-version.h"
     29#endif
    2630#if __GNUC__ == 4 && __GNUC_MINOR__ == 5
    2731# include "gmp.h"
     
    3236#endif
    3337#include "plugin.h"
    34 #include "gimple.h"
    3538#include "basic-block.h"
    3639#include "tree.h"
    3740#include "tree-pass.h"
     41#include "gimple.h"
     42#if RT_GNUC_PREREQ(4, 9)
     43# include "gimple-iterator.h"
     44# include "context.h" /* for g */
     45#endif
    3846#include "cp/cp-tree.h"
    3947#if __GNUC__ == 4 && __GNUC_MINOR__ == 5
     
    5765#ifndef VAR_P
    5866# define VAR_P(a_hNode) (TREE_CODE(a_hNode) == VAR_DECL)
     67#endif
     68/** Replacement for the 4.9.0 get_tree_code_name function. */
     69#if !RT_GNUC_PREREQ(4, 9)
     70# define get_tree_code_name(a_enmTreeCode) (tree_code_name[a_enmTreeCode])
    5971#endif
    6072
     
    89101}
    90102#endif
    91 #if __GNUC__ > 4 || __GNUC_MINOR__ > 5
    92 # define MY_INT_FITS_SHWI(hNode)    (hNode).fits_shwi()
    93 # define MY_INT_TO_SHWI(hNode)      (hNode).to_shwi()
     103
     104///* Integer to HOST_WIDE_INT conversion fun. */
     105//#if RT_GNUC_PREREQ(4, 6)
     106//# define MY_INT_FITS_SHWI(hNode)    (hNode).fits_shwi()
     107//# define MY_INT_TO_SHWI(hNode)      (hNode).to_shwi()
     108//#else
     109//# define MY_INT_FITS_SHWI(hNode)    double_int_fits_in_shwi_p(hNode)
     110//# define MY_INT_TO_SHWI(hNode)      double_int_to_shwi(hNode)
     111//#endif
     112
     113/* Integer to HOST_WIDE_INT conversion fun. */
     114#if RT_GNUC_PREREQ(5, 1)
     115# define MY_DOUBLE_INT_FITS_SHWI(hNode)     tree_fits_shwi_p(hNode)
     116# define MY_DOUBLE_INT_TO_SHWI(hNode)       tree_to_shwi(hNode)
     117#elif RT_GNUC_PREREQ(4, 6)
     118# define MY_DOUBLE_INT_FITS_SHWI(hNode)     (TREE_INT_CST(hNode).fits_shwi())
     119# define MY_DOUBLE_INT_TO_SHWI(hNode)       (TREE_INT_CST(hNode).to_shwi())
    94120#else
    95 # define MY_INT_FITS_SHWI(hNode)    double_int_fits_in_shwi_p(hNode)
    96 # define MY_INT_TO_SHWI(hNode)      double_int_to_shwi(hNode)
    97 #endif
     121# define MY_DOUBLE_INT_FITS_SHWI(hNode)     double_int_fits_in_shwi_p(TREE_INT_CST(hNode))
     122# define MY_DOUBLE_INT_TO_SHWI(hNode)       double_int_to_shwi(TREE_INT_CST(hNode))
     123#endif
     124
    98125#ifndef EXPR_LOC_OR_LOC
    99126# define EXPR_LOC_OR_LOC(a,b) (b)
     
    107134static bool             MyPassGateCallback(void);
    108135static unsigned int     MyPassExecuteCallback(void);
     136static unsigned int     MyPassExecuteCallbackWithFunction(struct function *pFun);
    109137static tree             AttributeHandler(tree *, tree, tree, int, bool *);
    110138
     
    120148};
    121149
     150#if RT_GNUC_PREREQ(4, 9)
     151/** My pass. */
     152static const pass_data g_MyPassData =
     153{
     154    type                    : GIMPLE_PASS,
     155    name                    : "*iprt-format-checks", /* asterisk = no dump */
     156    optinfo_flags           : 0,
     157    tv_id                   : TV_NONE,
     158    properties_required     : 0,
     159    properties_provided     : 0,
     160    properties_destroyed    : 0,
     161    todo_flags_start        : 0,
     162    todo_flags_finish       : 0,
     163};
     164
     165class MyPass : public gimple_opt_pass
     166{
     167public:
     168    MyPass(gcc::context *pCtx) : gimple_opt_pass(g_MyPassData, pCtx)
     169    { }
     170
     171    virtual bool gate(function *pFun)
     172    {
     173        NOREF(pFun);
     174        return MyPassGateCallback();
     175    }
     176
     177    virtual unsigned int execute(function *pFun)
     178    {
     179        NOREF(pFun);
     180        return MyPassExecuteCallbackWithFunction(pFun);
     181    }
     182};
     183
     184#else /* < 4.9.0 */
     185
    122186/** My pass. */
    123187static struct gimple_opt_pass g_MyPass =
     
    127191        type                    : GIMPLE_PASS,
    128192        name                    : "*iprt-format-checks", /* asterisk = no dump */
    129 #if __GNUC__ != 4 || __GNUC_MINOR__ != 5
     193# if __GNUC__ != 4 || __GNUC_MINOR__ != 5
    130194        optinfo_flags           : 0,
    131 #endif
     195# endif
    132196        gate                    : MyPassGateCallback,
    133197        execute                 : MyPassExecuteCallback,
     
    153217};
    154218
     219#endif /* < 4.9.0 */
     220
    155221
    156222/** Attribute specifications. */
     
    224290#endif
    225291
    226     dprintf("%s ", tree_code_name[enmDeclCode]);
     292    dprintf("%s ", get_tree_code_name(enmDeclCode));
    227293    dprintScope(hDecl);
    228294    dprintf("::%s", DECL_NAME(hDecl) ? IDENTIFIER_POINTER(DECL_NAME(hDecl)) : "<noname>");
    229295    if (hType)
    230         dprintf(" type %s", tree_code_name[enmTypeCode]);
     296        dprintf(" type %s", get_tree_code_name(enmTypeCode));
    231297    dprintf(" @%s:%d", DECL_SOURCE_FILE(hDecl),  DECL_SOURCE_LINE(hDecl));
    232298}
     
    294360{
    295361    location_t hLoc = pState->hFmtLoc;
    296 #if __GNUC__ != 4 || __GNUC_MINOR__ > 5
     362#if RT_GNUC_PREREQ(4,6)
    297363    intptr_t   offString = pszLoc - pState->pszFmt;
    298364    if (   offString >= 0
     
    302368        expanded_location   XLoc    = expand_location_to_spelling_point(hLoc);
    303369        int                 cchLine = 0;
    304 # if __GNUC__ >= 5 /** @todo figure this... */
    305         const char         *pszLine = location_get_source_line(XLoc, &cchLine);
     370# if RT_GNUC_PREREQ(5,0)
     371        const char         *pszLine = location_get_source_line(XLoc.file, XLoc.line, &cchLine);
    306372# else
    307373        const char         *pszLine = location_get_source_line(XLoc);
     
    339405DECL_NO_INLINE(static, void) MyCheckFormatNonRecursive(PVFMTCHKSTATE pState, tree hFmtArg)
    340406{
    341     dprintf("checker: hFmtArg=%p %s\n", hFmtArg, tree_code_name[TREE_CODE(hFmtArg)]);
     407    dprintf("checker: hFmtArg=%p %s\n", hFmtArg, get_tree_code_name(TREE_CODE(hFmtArg)));
    342408
    343409    /*
     
    348414        hFmtArg = decl_constant_value(hFmtArg);
    349415        STRIP_NOPS(hFmtArg); /* Used as argument and assigned call result. */
    350         dprintf("checker1: variable => hFmtArg=%p %s\n", hFmtArg, tree_code_name[TREE_CODE(hFmtArg)]);
     416        dprintf("checker1: variable => hFmtArg=%p %s\n", hFmtArg, get_tree_code_name(TREE_CODE(hFmtArg)));
    351417    }
    352418
     
    365431     */
    366432    else if (TREE_CODE(hFmtArg) != ADDR_EXPR)
    367         dprintf("checker1: Not address expression (%s)\n", tree_code_name[TREE_CODE(hFmtArg)]);
     433        dprintf("checker1: Not address expression (%s)\n", get_tree_code_name(TREE_CODE(hFmtArg)));
    368434    else
    369435    {
     
    376442        HOST_WIDE_INT off = 0;
    377443        if (   TREE_CODE(hFmtArg) == ARRAY_REF
    378             && MY_INT_FITS_SHWI(TREE_INT_CST(TREE_OPERAND(hFmtArg, 1)))
    379             && MY_INT_FITS_SHWI(TREE_INT_CST(TREE_OPERAND(hFmtArg, 1))) )
     444            && MY_DOUBLE_INT_FITS_SHWI(TREE_OPERAND(hFmtArg, 1))
     445            && MY_DOUBLE_INT_FITS_SHWI(TREE_OPERAND(hFmtArg, 1)) )
    380446        {
    381             off = MY_INT_TO_SHWI(TREE_INT_CST(TREE_OPERAND(hFmtArg, 1)));
     447            off = MY_DOUBLE_INT_TO_SHWI(TREE_OPERAND(hFmtArg, 1));
    382448            if (off < 0)
    383449            {
     
    386452            }
    387453            hFmtArg = TREE_OPERAND(hFmtArg, 0);
    388             dprintf("checker1: ARRAY_REF => hFmtArg=%p %s, off=%ld\n", hFmtArg, tree_code_name[TREE_CODE(hFmtArg)], off);
     454            dprintf("checker1: ARRAY_REF => hFmtArg=%p %s, off=%ld\n", hFmtArg, get_tree_code_name(TREE_CODE(hFmtArg)), off);
    389455        }
    390456
     
    410476         */
    411477        if (TREE_CODE(hFmtArg) != STRING_CST)
    412             dprintf("checker1: Not string literal (%s)\n", tree_code_name[TREE_CODE(hFmtArg)]);
     478            dprintf("checker1: Not string literal (%s)\n", get_tree_code_name(TREE_CODE(hFmtArg)));
    413479        else if (TYPE_MAIN_VARIANT(TREE_TYPE(TREE_TYPE(hFmtArg))) != char_type_node)
    414480            warning_at(pState->hFmtLoc, 0, "expected 'char' type string literal");
     
    425491            {
    426492                if (TREE_CODE(hArraySize) != INTEGER_CST)
    427                     warning_at(pState->hFmtLoc, 0, "Expected integer array size (not %s)", tree_code_name[TREE_CODE(hArraySize)]);
    428                 else if (!MY_INT_FITS_SHWI(TREE_INT_CST(hArraySize)))
     493                    warning_at(pState->hFmtLoc, 0, "Expected integer array size (not %s)", get_tree_code_name(TREE_CODE(hArraySize)));
     494                else if (!MY_DOUBLE_INT_FITS_SHWI(hArraySize))
    429495                    warning_at(pState->hFmtLoc, 0, "Unexpected integer overflow in array size constant");
    430496                else
    431497                {
    432                     HOST_WIDE_INT cbArray = MY_INT_TO_SHWI(TREE_INT_CST(hArraySize));
     498                    HOST_WIDE_INT cbArray = MY_DOUBLE_INT_TO_SHWI(hArraySize);
    433499                    if (   cbArray <= 0
    434500                        || cbArray != (int)cbArray)
     
    517583
    518584
     585#if !RT_GNUC_PREREQ(4, 9)
    519586/**
    520587 * Execute my pass.
     
    522589 */
    523590static unsigned int     MyPassExecuteCallback(void)
     591{
     592    return MyPassExecuteCallbackWithFunction(cfun);
     593}
     594#endif
     595
     596/**
     597 * Execute my pass.
     598 * @returns Flags indicates stuff todo, we return 0.
     599 */
     600static unsigned int     MyPassExecuteCallbackWithFunction(struct function *pFun)
    524601{
    525602    dprintf("MyPassExecuteCallback:\n");
     
    529606     */
    530607    basic_block hBasicBlock;
    531     FOR_EACH_BB(hBasicBlock)
     608    FOR_EACH_BB_FN(hBasicBlock, pFun)
    532609    {
    533610        dprintf(" hBasicBlock=%p\n", hBasicBlock);
     
    539616        for (gimple_stmt_iterator hStmtItr = gsi_start_bb(hBasicBlock); !gsi_end_p(hStmtItr); gsi_next(&hStmtItr))
    540617        {
     618#if RT_GNUC_PREREQ(6, 0)
     619            const gimple * const    hStmt   = gsi_stmt(hStmtItr);
     620#else
    541621            gimple const            hStmt   = gsi_stmt(hStmtItr);
     622#endif
     623
    542624            enum gimple_code const  enmCode = gimple_code(hStmt);
    543625#ifdef DEBUG
     
    548630                tree const hOp = gimple_op(hStmt, iOp);
    549631                if (hOp)
    550                     dprintf("     %02d: %p, code %s(%d)\n", iOp, hOp, tree_code_name[TREE_CODE(hOp)], TREE_CODE(hOp));
     632                    dprintf("     %02d: %p, code %s(%d)\n", iOp, hOp, get_tree_code_name(TREE_CODE(hOp)), TREE_CODE(hOp));
    551633                else
    552634                    dprintf("     %02d: NULL_TREE\n", iOp);
     
    560642                tree const hFn = gimple_call_fn(hStmt);
    561643                dprintf("     hFn    =%p %s(%d); args=%d\n",
    562                         hFn, tree_code_name[TREE_CODE(hFn)], TREE_CODE(hFn), gimple_call_num_args(hStmt));
     644                        hFn, get_tree_code_name(TREE_CODE(hFn)), TREE_CODE(hFn), gimple_call_num_args(hStmt));
    563645#ifdef DEBUG
    564646                if (DECL_P(hFn))
     
    570652                if (hFnDecl)
    571653                    dprintf("     hFnDecl=%p %s(%d) %s type=%p %s:%d\n",
    572                             hFnDecl, tree_code_name[TREE_CODE(hFnDecl)], TREE_CODE(hFnDecl),
     654                            hFnDecl, get_tree_code_name(TREE_CODE(hFnDecl)), TREE_CODE(hFnDecl),
    573655                            DECL_NAME(hFnDecl) ? IDENTIFIER_POINTER(DECL_NAME(hFnDecl)) : "<unamed>",
    574656                            TREE_TYPE(hFnDecl), DECL_SOURCE_FILE(hFnDecl), DECL_SOURCE_LINE(hFnDecl));
     
    576658                if (hFnType == NULL_TREE)
    577659                    error_at(gimple_location(hStmt), "Failed to resolve function type [fn=%s]\n",
    578                              tree_code_name[TREE_CODE(hFn)]);
     660                             get_tree_code_name(TREE_CODE(hFn)));
    579661                else if (POINTER_TYPE_P(hFnType))
    580662                    error_at(gimple_location(hStmt), "Got a POINTER_TYPE when expecting a function type [fn=%s]\n",
    581                              tree_code_name[TREE_CODE(hFn)]);
     663                             get_tree_code_name(TREE_CODE(hFn)));
    582664                if (hFnType)
    583                     dprintf("     hFnType=%p %s(%d) %s\n", hFnType, tree_code_name[TREE_CODE(hFnType)], TREE_CODE(hFnType),
    584                             TYPE_NAME(hFnType) ? IDENTIFIER_POINTER(TYPE_NAME(hFnType)) : "<unamed>");
     665                    dprintf("     hFnType=%p %s(%d) %s\n", hFnType, get_tree_code_name(TREE_CODE(hFnType)), TREE_CODE(hFnType),
     666                              TYPE_NAME(hFnType) && DECL_NAME(TYPE_NAME(hFnType))
     667                            ? IDENTIFIER_POINTER(DECL_NAME(TYPE_NAME(hFnType))) : "<unamed>");
    585668
    586669                tree const hAttr        = hFnType ? lookup_attribute("iprt_format", TYPE_ATTRIBUTES(hFnType))            : NULL_TREE;
     
    593676                    tree const hAttrArgs = hAttr ? TREE_VALUE(hAttr) : TREE_VALUE(hAttrMaybe0);
    594677                    VFMTCHKSTATE State;
    595                     State.iFmt          = MY_INT_TO_SHWI(TREE_INT_CST(TREE_VALUE(hAttrArgs)));
    596                     State.iArgs         = MY_INT_TO_SHWI(TREE_INT_CST(TREE_VALUE(TREE_CHAIN(hAttrArgs))));
     678                    State.iFmt          = MY_DOUBLE_INT_TO_SHWI(TREE_VALUE(hAttrArgs));
     679                    State.iArgs         = MY_DOUBLE_INT_TO_SHWI(TREE_VALUE(TREE_CHAIN(hAttrArgs)));
    597680                    State.pszFmt        = NULL;
    598681                    State.fMaybeNull    = hAttr == NULL_TREE;
     
    642725{
    643726    dprintf("AttributeHandler: name=%s fFlags=%#x", IDENTIFIER_POINTER(hAttrName), fFlags);
    644     long iFmt  = MY_INT_TO_SHWI(TREE_INT_CST(TREE_VALUE(hAttrArgs)));
    645     long iArgs = MY_INT_TO_SHWI(TREE_INT_CST(TREE_VALUE(TREE_CHAIN(hAttrArgs))));
     727    long iFmt  = MY_DOUBLE_INT_TO_SHWI(TREE_VALUE(hAttrArgs));
     728    long iArgs = MY_DOUBLE_INT_TO_SHWI(TREE_VALUE(TREE_CHAIN(hAttrArgs)));
    646729    dprintf(" iFmt=%ld iArgs=%ld", iFmt, iArgs);
    647730
    648731    tree hType = *phOnNode;
    649     dprintf(" hType=%p %s(%d)\n", hType, tree_code_name[TREE_CODE(hType)], TREE_CODE(hType));
     732    dprintf(" hType=%p %s(%d)\n", hType, get_tree_code_name(TREE_CODE(hType)), TREE_CODE(hType));
    650733
    651734    if (pfDontAddAttrib)
     
    688771
    689772    /* Register our pass. */
     773#if RT_GNUC_PREREQ(4, 9)
     774    /** The registration info for my pass. */
     775    struct register_pass_info MyPassInfo;
     776    MyPassInfo.pass                     = new MyPass(g);
     777    MyPassInfo.reference_pass_name      = "ssa";
     778    MyPassInfo.ref_pass_instance_number = 1;
     779    MyPassInfo.pos_op                   = PASS_POS_INSERT_BEFORE;
     780    register_callback(pPlugInInfo->base_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &MyPassInfo);
     781#else
    690782    register_callback(pPlugInInfo->base_name, PLUGIN_PASS_MANAGER_SETUP, NULL, (void *)&g_MyPassInfo);
     783#endif
    691784
    692785    /* Register plug-in info. */
     
    749842                error_at(MY_LOC(hArg, pState), "%u extra arguments not consumed by format string", cArgs - iArg);
    750843            else if (   TREE_CODE(hArg) != INTEGER_CST
    751                      || !MY_INT_FITS_SHWI(TREE_INT_CST(hArg))
    752                      || MY_INT_TO_SHWI(TREE_INT_CST(hArg)) != -99) /* ignore final dummy argument: ..., -99); */
     844                     || !MY_DOUBLE_INT_FITS_SHWI(hArg)
     845                     || MY_DOUBLE_INT_TO_SHWI(hArg) != -99) /* ignore final dummy argument: ..., -99); */
    753846                error_at(MY_LOC(hArg, pState), "one extra argument not consumed by format string");
    754847        }
     
    776869        tree hArg  = gimple_call_arg(pState->hStmt, iArg);
    777870        tree hType = TREE_TYPE(hArg);
    778         dprintf("arg%u: hArg=%p [%s] hType=%p [%s] cls=%s\n", iArg, hArg, tree_code_name[TREE_CODE(hArg)],
    779                 hType, tree_code_name[TREE_CODE(hType)], tree_code_class_strings[TREE_CODE_CLASS(TREE_CODE(hType))]);
     871        dprintf("arg%u: hArg=%p [%s] hType=%p [%s] cls=%s\n", iArg, hArg, get_tree_code_name(TREE_CODE(hArg)),
     872                hType, get_tree_code_name(TREE_CODE(hType)), tree_code_class_strings[TREE_CODE_CLASS(TREE_CODE(hType))]);
    780873        dprintf("      nm=%p\n", TYPE_NAME(hType));
    781         dprintf("      cb=%p %s value=%ld\n", TYPE_SIZE(hType), tree_code_name[TREE_CODE(TYPE_SIZE(hType))],
    782                 MY_INT_TO_SHWI(TREE_INT_CST(TYPE_SIZE(hType))) );
    783         dprintf("      unit=%p %s value=%ld\n", TYPE_SIZE_UNIT(hType), tree_code_name[TREE_CODE(TYPE_SIZE_UNIT(hType))],
    784                 MY_INT_TO_SHWI(TREE_INT_CST(TYPE_SIZE_UNIT(hType))) );
     874        dprintf("      cb=%p %s value=%ld\n", TYPE_SIZE(hType), get_tree_code_name(TREE_CODE(TYPE_SIZE(hType))),
     875                MY_DOUBLE_INT_TO_SHWI(TYPE_SIZE(hType)) );
     876        dprintf("      unit=%p %s value=%ld\n", TYPE_SIZE_UNIT(hType), get_tree_code_name(TREE_CODE(TYPE_SIZE_UNIT(hType))),
     877                MY_DOUBLE_INT_TO_SHWI(TYPE_SIZE_UNIT(hType)) );
    785878        tree hTypeNm = TYPE_NAME(hType);
    786879        if (hTypeNm)
    787             dprintf("      typenm=%p %s '%s'\n", hTypeNm, tree_code_name[TREE_CODE(hTypeNm)],
     880            dprintf("      typenm=%p %s '%s'\n", hTypeNm, get_tree_code_name(TREE_CODE(hTypeNm)),
    788881                    IDENTIFIER_POINTER(DECL_NAME(hTypeNm)));
    789882    }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette