Changeset 57029 in vbox
- Timestamp:
- Jul 20, 2015 9:12:37 PM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 101747
- Location:
- trunk/src/bldprogs
- Files:
-
- 5 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/Makefile.kmk
r56977 r57029 79 79 -I$(shell gcc -print-file-name=plugin/include) \ 80 80 -I$(PATH_ROOT)/include \ 81 $(if-expr "$(KBUILD_HOST)" == "solaris", -I/usr/include/gmp -I$(PATH_ROOT)/src/bldprogs/solgcc/,) \ 81 82 -o $@ \ 82 83 VBoxCompilerPlugInsGcc.cpp \ -
trunk/src/bldprogs/VBoxCompilerPlugInsGcc.cpp
r57003 r57029 23 23 #include <iprt/stdarg.h> 24 24 25 #if __GNUC__ == 4 && __GNUC_MINOR__ == 5 26 # include "gmp.h" 27 extern "C" { 28 #endif 29 #if __GNUC__ == 4 && __GNUC_MINOR__ == 5 30 # include "coretypes.h" 31 #endif 25 32 #include "plugin.h" 33 #include "gimple.h" 26 34 #include "basic-block.h" 27 #include "gimple.h"28 35 #include "tree.h" 29 36 #include "tree-pass.h" 30 37 #include "cp/cp-tree.h" 38 #if __GNUC__ == 4 && __GNUC_MINOR__ == 5 39 } 40 #endif 31 41 32 42 #include "VBoxCompilerPlugIns.h" … … 54 64 #define MY_LOC(a_hPreferred, a_pState) EXPR_LOC_OR_LOC(a_hPreferred, (a_pState)->hFmtLoc) 55 65 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 72 static 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 /** @} */ 56 101 57 102 … … 70 115 static const struct plugin_info g_PlugInInfo = 71 116 { 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." 74 119 }; 75 120 … … 77 122 static struct gimple_opt_pass g_MyPass = 78 123 { 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, 95 142 } 96 143 }; … … 99 146 static const struct register_pass_info g_MyPassInfo = 100 147 { 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, 105 152 }; 106 153 … … 110 157 { 111 158 { 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 120 169 }, 121 170 { 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 } 132 182 }; 133 183 … … 204 254 } 205 255 206 #el se256 #elif __GNUC_MINOR__ > 5 207 257 /* 208 258 * Have to do the job ourselves, it seems. This is a bit hairy... … … 243 293 { 244 294 location_t hLoc = pState->hFmtLoc; 295 #if __GNUC__ != 4 || __GNUC_MINOR__ > 5 245 296 intptr_t offString = pszLoc - pState->pszFmt; 246 297 if ( offString >= 0 … … 250 301 expanded_location XLoc = expand_location_to_spelling_point(hLoc); 251 302 int cchLine = 0; 252 # if __GNUC__ >= 5 /** @todo figure this... */303 # if __GNUC__ >= 5 /** @todo figure this... */ 253 304 const char *pszLine = location_get_source_line(XLoc, &cchLine); 254 # else305 # else 255 306 const char *pszLine = location_get_source_line(XLoc); 256 307 if (pszLine) … … 261 312 cchLine = (int)(pszEol - pszLine); 262 313 } 263 # endif314 # endif 264 315 if (pszLine) 265 316 { … … 271 322 hLoc = MyGetLocationPlusColumnOffset(hLoc, uCol); 272 323 } 324 #endif 273 325 return hLoc; 274 326 } … … 323 375 HOST_WIDE_INT off = 0; 324 376 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))); 328 381 if (off < 0) 329 382 { … … 372 425 if (TREE_CODE(hArraySize) != INTEGER_CST) 373 426 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))) 375 428 warning_at(pState->hFmtLoc, 0, "Unexpected integer overflow in array size constant"); 376 429 else 377 430 { 378 HOST_WIDE_INT cbArray = TREE_INT_CST(hArraySize).to_shwi();431 HOST_WIDE_INT cbArray = MY_INT_TO_SHWI(TREE_INT_CST(hArraySize)); 379 432 if ( cbArray <= 0 380 433 || cbArray != (int)cbArray) … … 504 557 * Check if the function type has the __iprt_format__ attribute. 505 558 */ 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); 512 560 dprintf(" hFn =%p %s(%d); args=%d\n", 513 561 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); 514 568 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)]); 517 581 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; 520 587 if (hAttr || hAttrMaybe0) 521 588 { … … 525 592 tree const hAttrArgs = hAttr ? TREE_VALUE(hAttr) : TREE_VALUE(hAttrMaybe0); 526 593 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)))); 529 596 State.pszFmt = NULL; 530 597 State.fMaybeNull = hAttr == NULL_TREE; … … 568 635 { 569 636 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)))); 572 639 dprintf(" iFmt=%ld iArgs=%ld", iFmt, iArgs); 573 640 … … 675 742 error_at(MY_LOC(hArg, pState), "%u extra arguments not consumed by format string", cArgs - iArg); 676 743 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); */ 679 746 error_at(MY_LOC(hArg, pState), "one extra argument not consumed by format string"); 680 747 } … … 763 830 unsigned int VFmtChkGetFmtLocColumn(PVFMTCHKSTATE pState) 764 831 { 832 #ifdef LOCATION_COLUMN 765 833 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.