- Timestamp:
- Oct 13, 2017 2:42:00 PM (7 years ago)
- Location:
- trunk/src/bldprogs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/Makefile.kmk
r62534 r69076 79 79 VBoxCompilerPlugInsGcc.o VBoxCompilerPlugInsCommon.o VBoxCompilerPlugIns.o gccplugin: gccplugin$(SUFF_DLL) 80 80 gccplugin$(SUFF_DLL): VBoxCompilerPlugInsGcc.cpp VBoxCompilerPlugInsCommon.cpp VBoxCompilerPlugIns.h 81 $(TOOL_GXX3_CXX) -shared -fPIC - g \81 $(TOOL_GXX3_CXX) -shared -fPIC -fno-rtti -g \ 82 82 -DIN_RING3 \ 83 83 $(if-expr "$(KBUILD_TYPE)" != "release",-DDEBUG,) \ -
trunk/src/bldprogs/VBoxCompilerPlugIns.h
r62537 r69076 38 38 typedef struct VFMTCHKSTATE 39 39 { 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; 44 44 #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; 47 51 #endif 48 52 } VFMTCHKSTATE; -
trunk/src/bldprogs/VBoxCompilerPlugInsGcc.cpp
r66779 r69076 5 5 6 6 /* 7 * Copyright (C) 2006-201 6Oracle Corporation7 * Copyright (C) 2006-2017 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 24 24 #include <iprt/stdarg.h> 25 25 26 #if RT_GNUC_PREREQ(5, 1) 27 # include "gcc-plugin.h" 28 # include "plugin-version.h" 29 #endif 26 30 #if __GNUC__ == 4 && __GNUC_MINOR__ == 5 27 31 # include "gmp.h" … … 32 36 #endif 33 37 #include "plugin.h" 34 #include "gimple.h"35 38 #include "basic-block.h" 36 39 #include "tree.h" 37 40 #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 38 46 #include "cp/cp-tree.h" 39 47 #if __GNUC__ == 4 && __GNUC_MINOR__ == 5 … … 57 65 #ifndef VAR_P 58 66 # 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]) 59 71 #endif 60 72 … … 89 101 } 90 102 #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()) 94 120 #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 98 125 #ifndef EXPR_LOC_OR_LOC 99 126 # define EXPR_LOC_OR_LOC(a,b) (b) … … 107 134 static bool MyPassGateCallback(void); 108 135 static unsigned int MyPassExecuteCallback(void); 136 static unsigned int MyPassExecuteCallbackWithFunction(struct function *pFun); 109 137 static tree AttributeHandler(tree *, tree, tree, int, bool *); 110 138 … … 120 148 }; 121 149 150 #if RT_GNUC_PREREQ(4, 9) 151 /** My pass. */ 152 static 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 165 class MyPass : public gimple_opt_pass 166 { 167 public: 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 122 186 /** My pass. */ 123 187 static struct gimple_opt_pass g_MyPass = … … 127 191 type : GIMPLE_PASS, 128 192 name : "*iprt-format-checks", /* asterisk = no dump */ 129 # if __GNUC__ != 4 || __GNUC_MINOR__ != 5193 # if __GNUC__ != 4 || __GNUC_MINOR__ != 5 130 194 optinfo_flags : 0, 131 # endif195 # endif 132 196 gate : MyPassGateCallback, 133 197 execute : MyPassExecuteCallback, … … 153 217 }; 154 218 219 #endif /* < 4.9.0 */ 220 155 221 156 222 /** Attribute specifications. */ … … 224 290 #endif 225 291 226 dprintf("%s ", tree_code_name[enmDeclCode]);292 dprintf("%s ", get_tree_code_name(enmDeclCode)); 227 293 dprintScope(hDecl); 228 294 dprintf("::%s", DECL_NAME(hDecl) ? IDENTIFIER_POINTER(DECL_NAME(hDecl)) : "<noname>"); 229 295 if (hType) 230 dprintf(" type %s", tree_code_name[enmTypeCode]);296 dprintf(" type %s", get_tree_code_name(enmTypeCode)); 231 297 dprintf(" @%s:%d", DECL_SOURCE_FILE(hDecl), DECL_SOURCE_LINE(hDecl)); 232 298 } … … 294 360 { 295 361 location_t hLoc = pState->hFmtLoc; 296 #if __GNUC__ != 4 || __GNUC_MINOR__ > 5362 #if RT_GNUC_PREREQ(4,6) 297 363 intptr_t offString = pszLoc - pState->pszFmt; 298 364 if ( offString >= 0 … … 302 368 expanded_location XLoc = expand_location_to_spelling_point(hLoc); 303 369 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); 306 372 # else 307 373 const char *pszLine = location_get_source_line(XLoc); … … 339 405 DECL_NO_INLINE(static, void) MyCheckFormatNonRecursive(PVFMTCHKSTATE pState, tree hFmtArg) 340 406 { 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))); 342 408 343 409 /* … … 348 414 hFmtArg = decl_constant_value(hFmtArg); 349 415 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))); 351 417 } 352 418 … … 365 431 */ 366 432 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))); 368 434 else 369 435 { … … 376 442 HOST_WIDE_INT off = 0; 377 443 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)) ) 380 446 { 381 off = MY_ INT_TO_SHWI(TREE_INT_CST(TREE_OPERAND(hFmtArg, 1)));447 off = MY_DOUBLE_INT_TO_SHWI(TREE_OPERAND(hFmtArg, 1)); 382 448 if (off < 0) 383 449 { … … 386 452 } 387 453 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); 389 455 } 390 456 … … 410 476 */ 411 477 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))); 413 479 else if (TYPE_MAIN_VARIANT(TREE_TYPE(TREE_TYPE(hFmtArg))) != char_type_node) 414 480 warning_at(pState->hFmtLoc, 0, "expected 'char' type string literal"); … … 425 491 { 426 492 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)) 429 495 warning_at(pState->hFmtLoc, 0, "Unexpected integer overflow in array size constant"); 430 496 else 431 497 { 432 HOST_WIDE_INT cbArray = MY_ INT_TO_SHWI(TREE_INT_CST(hArraySize));498 HOST_WIDE_INT cbArray = MY_DOUBLE_INT_TO_SHWI(hArraySize); 433 499 if ( cbArray <= 0 434 500 || cbArray != (int)cbArray) … … 517 583 518 584 585 #if !RT_GNUC_PREREQ(4, 9) 519 586 /** 520 587 * Execute my pass. … … 522 589 */ 523 590 static 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 */ 600 static unsigned int MyPassExecuteCallbackWithFunction(struct function *pFun) 524 601 { 525 602 dprintf("MyPassExecuteCallback:\n"); … … 529 606 */ 530 607 basic_block hBasicBlock; 531 FOR_EACH_BB (hBasicBlock)608 FOR_EACH_BB_FN(hBasicBlock, pFun) 532 609 { 533 610 dprintf(" hBasicBlock=%p\n", hBasicBlock); … … 539 616 for (gimple_stmt_iterator hStmtItr = gsi_start_bb(hBasicBlock); !gsi_end_p(hStmtItr); gsi_next(&hStmtItr)) 540 617 { 618 #if RT_GNUC_PREREQ(6, 0) 619 const gimple * const hStmt = gsi_stmt(hStmtItr); 620 #else 541 621 gimple const hStmt = gsi_stmt(hStmtItr); 622 #endif 623 542 624 enum gimple_code const enmCode = gimple_code(hStmt); 543 625 #ifdef DEBUG … … 548 630 tree const hOp = gimple_op(hStmt, iOp); 549 631 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)); 551 633 else 552 634 dprintf(" %02d: NULL_TREE\n", iOp); … … 560 642 tree const hFn = gimple_call_fn(hStmt); 561 643 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)); 563 645 #ifdef DEBUG 564 646 if (DECL_P(hFn)) … … 570 652 if (hFnDecl) 571 653 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), 573 655 DECL_NAME(hFnDecl) ? IDENTIFIER_POINTER(DECL_NAME(hFnDecl)) : "<unamed>", 574 656 TREE_TYPE(hFnDecl), DECL_SOURCE_FILE(hFnDecl), DECL_SOURCE_LINE(hFnDecl)); … … 576 658 if (hFnType == NULL_TREE) 577 659 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))); 579 661 else if (POINTER_TYPE_P(hFnType)) 580 662 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))); 582 664 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>"); 585 668 586 669 tree const hAttr = hFnType ? lookup_attribute("iprt_format", TYPE_ATTRIBUTES(hFnType)) : NULL_TREE; … … 593 676 tree const hAttrArgs = hAttr ? TREE_VALUE(hAttr) : TREE_VALUE(hAttrMaybe0); 594 677 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))); 597 680 State.pszFmt = NULL; 598 681 State.fMaybeNull = hAttr == NULL_TREE; … … 642 725 { 643 726 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))); 646 729 dprintf(" iFmt=%ld iArgs=%ld", iFmt, iArgs); 647 730 648 731 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)); 650 733 651 734 if (pfDontAddAttrib) … … 688 771 689 772 /* 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 690 782 register_callback(pPlugInInfo->base_name, PLUGIN_PASS_MANAGER_SETUP, NULL, (void *)&g_MyPassInfo); 783 #endif 691 784 692 785 /* Register plug-in info. */ … … 749 842 error_at(MY_LOC(hArg, pState), "%u extra arguments not consumed by format string", cArgs - iArg); 750 843 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); */ 753 846 error_at(MY_LOC(hArg, pState), "one extra argument not consumed by format string"); 754 847 } … … 776 869 tree hArg = gimple_call_arg(pState->hStmt, iArg); 777 870 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))]); 780 873 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)) ); 785 878 tree hTypeNm = TYPE_NAME(hType); 786 879 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)), 788 881 IDENTIFIER_POINTER(DECL_NAME(hTypeNm))); 789 882 }
Note:
See TracChangeset
for help on using the changeset viewer.