VirtualBox

Changeset 57029 in vbox


Ignore:
Timestamp:
Jul 20, 2015 9:12:37 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
101747
Message:

gccplugin: solaris / gcc 4.5.2 port.

Location:
trunk/src/bldprogs
Files:
5 added
2 edited

Legend:

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

    r56977 r57029  
    7979                -I$(shell gcc -print-file-name=plugin/include) \
    8080                -I$(PATH_ROOT)/include \
     81                $(if-expr "$(KBUILD_HOST)" == "solaris", -I/usr/include/gmp -I$(PATH_ROOT)/src/bldprogs/solgcc/,) \
    8182                -o $@ \
    8283                VBoxCompilerPlugInsGcc.cpp \
  • trunk/src/bldprogs/VBoxCompilerPlugInsGcc.cpp

    r57003 r57029  
    2323#include <iprt/stdarg.h>
    2424
     25#if __GNUC__ == 4 && __GNUC_MINOR__ == 5
     26# include "gmp.h"
     27extern "C" {
     28#endif
     29#if __GNUC__ == 4 && __GNUC_MINOR__ == 5
     30# include "coretypes.h"
     31#endif
    2532#include "plugin.h"
     33#include "gimple.h"
    2634#include "basic-block.h"
    27 #include "gimple.h"
    2835#include "tree.h"
    2936#include "tree-pass.h"
    3037#include "cp/cp-tree.h"
     38#if __GNUC__ == 4 && __GNUC_MINOR__ == 5
     39}
     40#endif
    3141
    3242#include "VBoxCompilerPlugIns.h"
     
    5464#define MY_LOC(a_hPreferred, a_pState) EXPR_LOC_OR_LOC(a_hPreferred, (a_pState)->hFmtLoc)
    5565
     66/** @name Compatibility glue
     67 * @{ */
     68#if __GNUC__ == 4 && __GNUC_MINOR__ == 5
     69# define linemap_location_from_macro_expansion_p(a, b) false
     70#endif
     71#if __GNUC__ == 4 && __GNUC_MINOR__ == 5
     72static tree gimple_call_fntype(gimple hStmt)
     73{
     74    tree hDecl = gimple_call_fndecl(hStmt);
     75    if (hDecl)
     76        return TREE_TYPE(hDecl);
     77    hDecl = gimple_call_fn(hStmt);
     78    if (TREE_CODE(hDecl) == OBJ_TYPE_REF)
     79        hDecl = OBJ_TYPE_REF_EXPR(hDecl);
     80    if (DECL_P(hDecl))
     81    {
     82        tree hType = TREE_TYPE(hDecl);
     83        if (POINTER_TYPE_P(hType))
     84            hType = TREE_TYPE(hType);
     85        return hType;
     86    }
     87    return NULL_TREE; /* caller bitches about this*/
     88}
     89#endif
     90#if __GNUC__ > 4 || __GNUC_MINOR__ > 5
     91# define MY_INT_FITS_SHWI(hNode)    (hNode).fits_shwi()
     92# define MY_INT_TO_SHWI(hNode)      (hNode).to_shwi()
     93#else
     94# define MY_INT_FITS_SHWI(hNode)    double_int_fits_in_shwi_p(hNode)
     95# define MY_INT_TO_SHWI(hNode)      double_int_to_shwi(hNode)
     96#endif
     97#ifndef EXPR_LOC_OR_LOC
     98# define EXPR_LOC_OR_LOC(a,b) (b)
     99#endif
     100/** @} */
    56101
    57102
     
    70115static const struct plugin_info g_PlugInInfo =
    71116{
    72     .version = "0.0.0-ALPHA",
    73     .help    = "Implements the __iprt_format__ attribute for checking format strings and arguments."
     117    version: "0.0.0-ALPHA",
     118    help   : "Implements the __iprt_format__ attribute for checking format strings and arguments."
    74119};
    75120
     
    77122static struct gimple_opt_pass g_MyPass =
    78123{
    79     .pass =
    80     {
    81         .type                   = GIMPLE_PASS,
    82         .name                   = "*iprt-format-checks", /* asterisk = no dump */
    83         .optinfo_flags          = 0,
    84         .gate                   = MyPassGateCallback,
    85         .execute                = MyPassExecuteCallback,
    86         .sub                    = NULL,
    87         .next                   = NULL,
    88         .static_pass_number     = 0,
    89         .tv_id                  = TV_NONE,
    90         .properties_required    = 0,
    91         .properties_provided    = 0,
    92         .properties_destroyed   = 0,
    93         .todo_flags_start       = 0,
    94         .todo_flags_finish      = 0,
     124    pass:
     125    {
     126        type                    : GIMPLE_PASS,
     127        name                    : "*iprt-format-checks", /* asterisk = no dump */
     128#if __GNUC__ != 4 || __GNUC_MINOR__ != 5
     129        optinfo_flags           : 0,
     130#endif
     131        gate                    : MyPassGateCallback,
     132        execute                 : MyPassExecuteCallback,
     133        sub                     : NULL,
     134        next                    : NULL,
     135        static_pass_number      : 0,
     136        tv_id                   : TV_NONE,
     137        properties_required     : 0,
     138        properties_provided     : 0,
     139        properties_destroyed    : 0,
     140        todo_flags_start        : 0,
     141        todo_flags_finish       : 0,
    95142    }
    96143};
     
    99146static const struct register_pass_info  g_MyPassInfo =
    100147{
    101     .pass                       = &g_MyPass.pass,
    102     .reference_pass_name        = "ssa",
    103     .ref_pass_instance_number   = 1,
    104     .pos_op                     = PASS_POS_INSERT_BEFORE,
     148    pass                        : &g_MyPass.pass,
     149    reference_pass_name         : "ssa",
     150    ref_pass_instance_number    : 1,
     151    pos_op                      : PASS_POS_INSERT_BEFORE,
    105152};
    106153
     
    110157{
    111158    {
    112         .name                   = "iprt_format",
    113         .min_length             = 2,
    114         .max_length             = 2,
    115         .decl_required          = false,
    116         .type_required          = true,
    117         .function_type_required = true,
    118         .handler                = AttributeHandler,
    119         .affects_type_identity  = false
     159        name                    : "iprt_format",
     160        min_length              : 2,
     161        max_length              : 2,
     162        decl_required           : false,
     163        type_required           : true,
     164        function_type_required  : true,
     165        handler                 : AttributeHandler,
     166#if __GNUC__ != 4 || __GNUC_MINOR__ != 5
     167        affects_type_identity   : false
     168#endif
    120169    },
    121170    {
    122         .name                   = "iprt_format_maybe_null",
    123         .min_length             = 2,
    124         .max_length             = 2,
    125         .decl_required          = false,
    126         .type_required          = true,
    127         .function_type_required = true,
    128         .handler                = AttributeHandler,
    129         .affects_type_identity  = false
    130     },
    131     {   NULL, 0, 0, false, false, false, NULL, false } /* just in case */
     171        name                    : "iprt_format_maybe_null",
     172        min_length              : 2,
     173        max_length              : 2,
     174        decl_required           : false,
     175        type_required           : true,
     176        function_type_required  : true,
     177        handler                 : AttributeHandler,
     178#if __GNUC__ != 4 || __GNUC_MINOR__ != 5
     179        affects_type_identity   : false
     180#endif
     181    }
    132182};
    133183
     
    204254        }
    205255
    206 #else
     256#elif __GNUC_MINOR__ > 5
    207257        /*
    208258         * Have to do the job ourselves, it seems.  This is a bit hairy...
     
    243293{
    244294    location_t hLoc = pState->hFmtLoc;
     295#if __GNUC__ != 4 || __GNUC_MINOR__ > 5
    245296    intptr_t   offString = pszLoc - pState->pszFmt;
    246297    if (   offString >= 0
     
    250301        expanded_location   XLoc    = expand_location_to_spelling_point(hLoc);
    251302        int                 cchLine = 0;
    252 #if __GNUC__ >= 5 /** @todo figure this... */
     303# if __GNUC__ >= 5 /** @todo figure this... */
    253304        const char         *pszLine = location_get_source_line(XLoc, &cchLine);
    254 #else
     305# else
    255306        const char         *pszLine = location_get_source_line(XLoc);
    256307        if (pszLine)
     
    261312            cchLine = (int)(pszEol - pszLine);
    262313        }
    263 #endif
     314# endif
    264315        if (pszLine)
    265316        {
     
    271322        hLoc = MyGetLocationPlusColumnOffset(hLoc, uCol);
    272323    }
     324#endif
    273325    return hLoc;
    274326}
     
    323375        HOST_WIDE_INT off = 0;
    324376        if (   TREE_CODE(hFmtArg) == ARRAY_REF
    325             && TREE_INT_CST(TREE_OPERAND(hFmtArg, 1)).fits_shwi() )
    326         {
    327             off = TREE_INT_CST(TREE_OPERAND(hFmtArg, 1)).to_shwi();
     377            && MY_INT_FITS_SHWI(TREE_INT_CST(TREE_OPERAND(hFmtArg, 1)))
     378            && MY_INT_FITS_SHWI(TREE_INT_CST(TREE_OPERAND(hFmtArg, 1))) )
     379        {
     380            off = MY_INT_TO_SHWI(TREE_INT_CST(TREE_OPERAND(hFmtArg, 1)));
    328381            if (off < 0)
    329382            {
     
    372425                if (TREE_CODE(hArraySize) != INTEGER_CST)
    373426                    warning_at(pState->hFmtLoc, 0, "Expected integer array size (not %s)", tree_code_name[TREE_CODE(hArraySize)]);
    374                 else if (!TREE_INT_CST(hArraySize).fits_shwi())
     427                else if (!MY_INT_FITS_SHWI(TREE_INT_CST(hArraySize)))
    375428                    warning_at(pState->hFmtLoc, 0, "Unexpected integer overflow in array size constant");
    376429                else
    377430                {
    378                     HOST_WIDE_INT cbArray = TREE_INT_CST(hArraySize).to_shwi();
     431                    HOST_WIDE_INT cbArray = MY_INT_TO_SHWI(TREE_INT_CST(hArraySize));
    379432                    if (   cbArray <= 0
    380433                        || cbArray != (int)cbArray)
     
    504557                 * Check if the function type has the __iprt_format__ attribute.
    505558                 */
    506                 tree const hFn          = gimple_call_fn(hStmt);
    507                 tree const hFnType      = gimple_call_fntype(hStmt);
    508                 tree const hAttr        = lookup_attribute("iprt_format", TYPE_ATTRIBUTES(hFnType));
    509                 tree const hAttrMaybe0  = lookup_attribute("iprt_format_maybe_null", TYPE_ATTRIBUTES(hFnType));
    510 #ifdef DEBUG
    511                 tree const hFnDecl      = gimple_call_fndecl(hStmt);
     559                tree const hFn = gimple_call_fn(hStmt);
    512560                dprintf("     hFn    =%p %s(%d); args=%d\n",
    513561                        hFn, tree_code_name[TREE_CODE(hFn)], TREE_CODE(hFn), gimple_call_num_args(hStmt));
     562#ifdef DEBUG
     563                if (DECL_P(hFn))
     564                    dprintf("     hFn is decl: %s %s:%d\n",
     565                            DECL_NAME(hFn) ? IDENTIFIER_POINTER(DECL_NAME(hFn)) : "<unamed>",
     566                            DECL_SOURCE_FILE(hFn), DECL_SOURCE_LINE(hFn));
     567                tree const hFnDecl = gimple_call_fndecl(hStmt);
    514568                if (hFnDecl)
    515                     dprintf("     hFnDecl=%p %s(%d) type=%p %s:%d\n", hFnDecl, tree_code_name[TREE_CODE(hFnDecl)],
    516                             TREE_CODE(hFnDecl), TREE_TYPE(hFnDecl), DECL_SOURCE_FILE(hFnDecl), DECL_SOURCE_LINE(hFnDecl));
     569                    dprintf("     hFnDecl=%p %s(%d) %s type=%p %s:%d\n", hFnDecl, tree_code_name[TREE_CODE(hFnDecl)],
     570                            TREE_CODE(hFnDecl), TREE_TYPE(hFnDecl),
     571                            DECL_NAME(hFnDecl) ? IDENTIFIER_POINTER(DECL_NAME(hFnDecl)) : "<unamed>",
     572                            DECL_SOURCE_FILE(hFnDecl), DECL_SOURCE_LINE(hFnDecl));
     573#endif
     574                tree const hFnType = gimple_call_fntype(hStmt);
     575                if (hFnType == NULL_TREE)
     576                    error_at(gimple_location(hStmt), "Failed to resolve function type [fn=%s]\n",
     577                             tree_code_name[TREE_CODE(hFn)]);
     578                else if (POINTER_TYPE_P(hFnType))
     579                    error_at(gimple_location(hStmt), "Got a POINTER_TYPE when expecting a function type [fn=%s]\n",
     580                             tree_code_name[TREE_CODE(hFn)]);
    517581                if (hFnType)
    518                     dprintf("     hFnType=%p %s(%d)\n", hFnType, tree_code_name[TREE_CODE(hFnType)], TREE_CODE(hFnType));
    519 #endif
     582                    dprintf("     hFnType=%p %s(%d) %s\n", hFnType, tree_code_name[TREE_CODE(hFnType)], TREE_CODE(hFnType),
     583                            TYPE_NAME(hFnType) ? IDENTIFIER_POINTER(TYPE_NAME(hFnType)) : "<unamed>");
     584
     585                tree const hAttr        = hFnType ? lookup_attribute("iprt_format", TYPE_ATTRIBUTES(hFnType))            : NULL_TREE;
     586                tree const hAttrMaybe0  = hFnType ? lookup_attribute("iprt_format_maybe_null", TYPE_ATTRIBUTES(hFnType)) : NULL_TREE;
    520587                if (hAttr || hAttrMaybe0)
    521588                {
     
    525592                    tree const hAttrArgs = hAttr ? TREE_VALUE(hAttr) : TREE_VALUE(hAttrMaybe0);
    526593                    VFMTCHKSTATE State;
    527                     State.iFmt          = TREE_INT_CST(TREE_VALUE(hAttrArgs)).to_shwi();
    528                     State.iArgs         = TREE_INT_CST(TREE_VALUE(TREE_CHAIN(hAttrArgs))).to_shwi();
     594                    State.iFmt          = MY_INT_TO_SHWI(TREE_INT_CST(TREE_VALUE(hAttrArgs)));
     595                    State.iArgs         = MY_INT_TO_SHWI(TREE_INT_CST(TREE_VALUE(TREE_CHAIN(hAttrArgs))));
    529596                    State.pszFmt        = NULL;
    530597                    State.fMaybeNull    = hAttr == NULL_TREE;
     
    568635{
    569636    dprintf("AttributeHandler: name=%s fFlags=%#x", IDENTIFIER_POINTER(hAttrName), fFlags);
    570     long iFmt  = TREE_INT_CST(TREE_VALUE(hAttrArgs)).to_shwi();
    571     long iArgs = TREE_INT_CST(TREE_VALUE(TREE_CHAIN(hAttrArgs))).to_shwi();
     637    long iFmt  = MY_INT_TO_SHWI(TREE_INT_CST(TREE_VALUE(hAttrArgs)));
     638    long iArgs = MY_INT_TO_SHWI(TREE_INT_CST(TREE_VALUE(TREE_CHAIN(hAttrArgs))));
    572639    dprintf(" iFmt=%ld iArgs=%ld", iFmt, iArgs);
    573640
     
    675742                error_at(MY_LOC(hArg, pState), "%u extra arguments not consumed by format string", cArgs - iArg);
    676743            else if (   TREE_CODE(hArg) != INTEGER_CST
    677                      || !TREE_INT_CST(hArg).fits_shwi()
    678                      || TREE_INT_CST(hArg).to_shwi() != -99) /* ignore final dummy argument: ..., -99); */
     744                     || !MY_INT_FITS_SHWI(TREE_INT_CST(hArg))
     745                     || MY_INT_TO_SHWI(TREE_INT_CST(hArg)) != -99) /* ignore final dummy argument: ..., -99); */
    679746                error_at(MY_LOC(hArg, pState), "one extra argument not consumed by format string");
    680747        }
     
    763830unsigned int VFmtChkGetFmtLocColumn(PVFMTCHKSTATE pState)
    764831{
     832#ifdef LOCATION_COLUMN
    765833    return LOCATION_COLUMN(pState->hFmtLoc);
    766 }
    767 
     834#else
     835    return 1;
     836#endif
     837}
     838
Note: See TracChangeset for help on using the changeset viewer.

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