VirtualBox

Changeset 57003 in vbox for trunk/src/bldprogs


Ignore:
Timestamp:
Jul 19, 2015 12:35:01 AM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
101718
Message:

gccplugin: New attribute iprt_format_maybe_null for dealing with semaphore, critsect and lock validation naming.

Location:
trunk/src/bldprogs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bldprogs/VBoxCompilerPlugIns.h

    r57002 r57003  
    4141    long        iArgs;
    4242    const char *pszFmt;
     43    bool        fMaybeNull;
    4344#if defined(__GNUC__) && !defined(VBOX_COMPILER_PLUG_IN_AGNOSTIC)
    4445    gimple      hStmt;
  • trunk/src/bldprogs/VBoxCompilerPlugInsGcc.cpp

    r57002 r57003  
    106106
    107107
    108 /** Attribute specification. */
     108/** Attribute specifications. */
    109109static const struct attribute_spec g_AttribSpecs[] =
    110110{
     
    119119        .affects_type_identity  = false
    120120    },
    121     {   NULL, 0, 0, false, false, false, NULL, false }
     121    {
     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 */
    122132};
    123133
     
    292302     */
    293303    if (integer_zerop(hFmtArg))
    294         warning_at(MY_LOC(hFmtArg, pState), 0, "Format string should not be NULL");
     304    {
     305        if (pState->fMaybeNull)
     306            VFmtChkVerifyEndOfArgs(pState, 0);
     307        else
     308            error_at(MY_LOC(hFmtArg, pState), "Format string should not be NULL");
     309    }
    295310    /*
    296311     * Need address expression to get any further.
     
    412427{
    413428    /*
     429     * Catch wrong attribute use.
     430     */
     431    if (hFmtArg == NULL_TREE)
     432        error_at(pState->hFmtLoc, "IPRT format attribute is probably used incorrectly (hFmtArg is NULL)");
     433    /*
    414434     * NULL format strings may cause crashes.
    415435     */
    416     if (integer_zerop(hFmtArg))
    417         warning_at(MY_LOC(hFmtArg, pState), 0, "Format string should not be NULL");
     436    else if (integer_zerop(hFmtArg))
     437    {
     438        if (pState->fMaybeNull)
     439            VFmtChkVerifyEndOfArgs(pState, 0);
     440        else
     441            error_at(MY_LOC(hFmtArg, pState), "Format string should not be NULL");
     442    }
    418443    /*
    419444     * Check both branches of a ternary operator.
     
    479504                 * Check if the function type has the __iprt_format__ attribute.
    480505                 */
    481                 tree const hFn       = gimple_call_fn(hStmt);
    482                 tree const hFnType   = gimple_call_fntype(hStmt);
    483                 tree const hAttr     = lookup_attribute("iprt_format", TYPE_ATTRIBUTES(hFnType));
     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));
    484510#ifdef DEBUG
    485                 tree const hFnDecl   = gimple_call_fndecl(hStmt);
     511                tree const hFnDecl      = gimple_call_fndecl(hStmt);
    486512                dprintf("     hFn    =%p %s(%d); args=%d\n",
    487513                        hFn, tree_code_name[TREE_CODE(hFn)], TREE_CODE(hFn), gimple_call_num_args(hStmt));
     
    492518                    dprintf("     hFnType=%p %s(%d)\n", hFnType, tree_code_name[TREE_CODE(hFnType)], TREE_CODE(hFnType));
    493519#endif
    494                 if (hAttr)
     520                if (hAttr || hAttrMaybe0)
    495521                {
    496522                    /*
    497523                     * Yeah, it has the attribute!
    498524                     */
    499                     tree const hAttrArgs = TREE_VALUE(hAttr);
     525                    tree const hAttrArgs = hAttr ? TREE_VALUE(hAttr) : TREE_VALUE(hAttrMaybe0);
    500526                    VFMTCHKSTATE State;
    501                     State.iFmt    = TREE_INT_CST(TREE_VALUE(hAttrArgs)).to_shwi();
    502                     State.iArgs   = TREE_INT_CST(TREE_VALUE(TREE_CHAIN(hAttrArgs))).to_shwi();
    503                     State.hStmt   = hStmt;
    504                     State.hFmtLoc = gimple_location(hStmt);
    505                     State.pszFmt  = NULL;
    506                     dprintf("     %s() __iprt_format__(iFmt=%ld, iArgs=%ld)\n",
    507                             DECL_NAME(hFnDecl) ? IDENTIFIER_POINTER(DECL_NAME(hFnDecl)) : "<unamed>", State.iFmt, State.iArgs);
     527                    State.iFmt          = TREE_INT_CST(TREE_VALUE(hAttrArgs)).to_shwi();
     528                    State.iArgs         = TREE_INT_CST(TREE_VALUE(TREE_CHAIN(hAttrArgs))).to_shwi();
     529                    State.pszFmt        = NULL;
     530                    State.fMaybeNull    = hAttr == NULL_TREE;
     531                    State.hStmt         = hStmt;
     532                    State.hFmtLoc       = gimple_location(hStmt);
     533                    dprintf("     %s() __iprt_format%s__(iFmt=%ld, iArgs=%ld)\n",
     534                            DECL_NAME(hFnDecl) ? IDENTIFIER_POINTER(DECL_NAME(hFnDecl)) : "<unamed>",
     535                            State.fMaybeNull ? "_maybe_null" : "", State.iFmt, State.iArgs);
    508536
    509537                    MyCheckFormatRecursive(&State, gimple_call_arg(hStmt, State.iFmt - 1));
     
    565593
    566594    register_attribute(&g_AttribSpecs[0]);
     595    register_attribute(&g_AttribSpecs[1]);
    567596}
    568597
     
    633662void VFmtChkVerifyEndOfArgs(PVFMTCHKSTATE pState, unsigned iArg)
    634663{
    635     dprintf("VFmtChkVerifyFinalArg: iArg=%u iArgs=%ld cArgs=%u\n", iArg, pState->iArgs, gimple_call_num_args(pState->hStmt));
     664    dprintf("VFmtChkVerifyEndOfArgs: iArg=%u iArgs=%ld cArgs=%u\n", iArg, pState->iArgs, gimple_call_num_args(pState->hStmt));
    636665    if (pState->iArgs > 0)
    637666    {
     
    712741    if (pState->iArgs > 0)
    713742    {
    714         pState->iFmt  = pState->iArgs + iArg;
    715         pState->iArgs = pState->iFmt  + 1;
     743        pState->iFmt        = pState->iArgs + iArg;
     744        pState->iArgs       = pState->iFmt  + 1;
     745        pState->fMaybeNull  = false;
    716746        MyCheckFormatRecursive(pState, gimple_call_arg(pState->hStmt, pState->iFmt - 1));
    717747    }
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