Changeset 57003 in vbox for trunk/src/bldprogs
- Timestamp:
- Jul 19, 2015 12:35:01 AM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 101718
- Location:
- trunk/src/bldprogs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/VBoxCompilerPlugIns.h
r57002 r57003 41 41 long iArgs; 42 42 const char *pszFmt; 43 bool fMaybeNull; 43 44 #if defined(__GNUC__) && !defined(VBOX_COMPILER_PLUG_IN_AGNOSTIC) 44 45 gimple hStmt; -
trunk/src/bldprogs/VBoxCompilerPlugInsGcc.cpp
r57002 r57003 106 106 107 107 108 /** Attribute specification . */108 /** Attribute specifications. */ 109 109 static const struct attribute_spec g_AttribSpecs[] = 110 110 { … … 119 119 .affects_type_identity = false 120 120 }, 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 */ 122 132 }; 123 133 … … 292 302 */ 293 303 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 } 295 310 /* 296 311 * Need address expression to get any further. … … 412 427 { 413 428 /* 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 /* 414 434 * NULL format strings may cause crashes. 415 435 */ 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 } 418 443 /* 419 444 * Check both branches of a ternary operator. … … 479 504 * Check if the function type has the __iprt_format__ attribute. 480 505 */ 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)); 484 510 #ifdef DEBUG 485 tree const hFnDecl = gimple_call_fndecl(hStmt);511 tree const hFnDecl = gimple_call_fndecl(hStmt); 486 512 dprintf(" hFn =%p %s(%d); args=%d\n", 487 513 hFn, tree_code_name[TREE_CODE(hFn)], TREE_CODE(hFn), gimple_call_num_args(hStmt)); … … 492 518 dprintf(" hFnType=%p %s(%d)\n", hFnType, tree_code_name[TREE_CODE(hFnType)], TREE_CODE(hFnType)); 493 519 #endif 494 if (hAttr )520 if (hAttr || hAttrMaybe0) 495 521 { 496 522 /* 497 523 * Yeah, it has the attribute! 498 524 */ 499 tree const hAttrArgs = TREE_VALUE(hAttr);525 tree const hAttrArgs = hAttr ? TREE_VALUE(hAttr) : TREE_VALUE(hAttrMaybe0); 500 526 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); 508 536 509 537 MyCheckFormatRecursive(&State, gimple_call_arg(hStmt, State.iFmt - 1)); … … 565 593 566 594 register_attribute(&g_AttribSpecs[0]); 595 register_attribute(&g_AttribSpecs[1]); 567 596 } 568 597 … … 633 662 void VFmtChkVerifyEndOfArgs(PVFMTCHKSTATE pState, unsigned iArg) 634 663 { 635 dprintf("VFmtChkVerify FinalArg: 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)); 636 665 if (pState->iArgs > 0) 637 666 { … … 712 741 if (pState->iArgs > 0) 713 742 { 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; 716 746 MyCheckFormatRecursive(pState, gimple_call_arg(pState->hStmt, pState->iFmt - 1)); 717 747 }
Note:
See TracChangeset
for help on using the changeset viewer.