Gcc
GNU Compiler Collection ïŒäžè¬çã«GCCãšç¥ãããïŒã¯ãGNUãããžã§ã¯ãã®äžéšãšããŠéçºãããããŸããŸãªããã°ã©ãã³ã°èšèªçšã®ã³ã³ãã€ã©ã®ã³ã¬ã¯ã·ã§ã³ã§ãã GCCã¯ãGNU GPLããã³GNU LGPL Free Software Foundationã«ãã£ãŠé åžãããŠããããªãŒãœãããŠã§ã¢ã§ãããGNUããŒã«ãã§ãŒã³ã®éèŠãªã³ã³ããŒãã³ãã§ãã ãããžã§ã¯ãã¯Cããã³C ++ã§èšè¿°ãããŠããŸãã
GCCã³ã³ãã€ã©ã«ã¯ãã³ã³ãã€ã«æ®µéã§å€ãã®ãšã©ãŒãèå¥ããã®ã«åœ¹ç«ã€åªããçµã¿èŸŒã¿èšºææ©èœââããããŸãã åœç¶ãGCCã¯GCCã䜿çšããŠæ§ç¯ãããŠãããããç¬èªã®ã³ãŒãã§ãšã©ãŒãæ€åºã§ããŸãã ããã«ãGCCãœãŒã¹ã³ãŒãã¯Coverityã¢ãã©ã€ã¶ãŒã䜿çšããŠæ€èšŒãããŸãã ãšã«ãããGCCã¯å€ãã®ã¢ãã©ã€ã¶ãŒããã®ä»ã®ããŒã«ã䜿çšããŠæ奜家ã«ãã£ãŠãã¹ãããããšæããŸãã ããã«ãããGCCãã°æ€çŽ¢ãPVS-Studioã³ãŒãã¢ãã©ã€ã¶ãŒã®å€§ããªãã¹ãã«ãªããŸãã
åæã®ããã«ããã©ã³ã¯ããŒãžã§ã³ã¯gitãªããžããªããååŸãããŸããïŒïŒgitïŒcommit 00a7fcca6a4657b6cf203824beda1e89f751354b svn + sshïŒ//gcc.gnu.org/svn/gcc/trunk@238976
ã泚æ ãã®èšäºã¯ãªãªãŒã¹ã«äŒŽã£ãŠé 延ããããããããã€ãã®ãšã©ãŒã¯ãã§ã«ä¿®æ£ãããŠããŸãã ããããããã¯åé¡ã§ã¯ãããŸãããæ°ãããšã©ãŒã絶ããçŸããå€ããšã©ãŒã¯æ¶ããŸãã äž»ãªãã®-ãã®èšäºã¯ãéçåæãããã°ã©ããŒããšã©ãŒã衚瀺ããåŸã«ç¹å®ããã®ã«åœ¹ç«ã€ããšã瀺ããŠããŸãã
è°è«ãäºæ³ãã
ã¯ããã«è¿°ã¹ãããã«ãGCCã¯é«å質ã®ã³ãŒããåãããããžã§ã¯ãã ãšèããŠããŸãã å€ãã®äººãè°è«ããããšæãã§ãããã äŸãšããŠããã·ã¢èªã®ãŠã£ãããã£ã¢ããåŒçšããŸãã
Theo de RaadtãOtto Moerbeekãªã©ã®äžéšã®OpenBSDéçºè ã¯ãGCCããæ±ãã«ããããã°ããããé ããäžæ£ãªã³ãŒããçæããããšèšã£ãŠæ¹å€ããŠããŸãã
ç§ã¯ãã®ãããªå£°æã¯æ ¹æ ããªããšèããŠããŸãã ã¯ããããããGCCã³ãŒãã«ã¯èªã¿ã«ããããå€ãã®ãã¯ããå«ãŸããŠããŸãã ããããç§ã¯åœŒã®ãã®ãŒã«é¢ãã声æã«åæããããšã¯ã§ããŸããã GCCã«ãã°ãããå Žåãã©ãã§ãæ©èœããŸããã ã³ã³ãã€ã«ããŠæ£åžžã«åäœããããã°ã©ã ã®æ°ãèŠããŠããã ãã§ãã GCCã®äœæè ã¯ãåªããããæèãæã£ãŠå·šå€§ã§è€éãªä»äºãããŠããŸãã 圌ãã«æè¬ããŸãã ãã®ãããªé«å質ã®ãããžã§ã¯ãã§PVS-Studioã®åäœããã¹ãã§ããããšãå¬ããæããŸãã
Clangã³ã³ãã€ã©ã³ãŒãã¯ãŸã ãŸã ã¯ãŒã«ã ãšèšã人ã®ããã«ãPVS-Studioã§ãšã©ãŒãæ€åºãããããšãæãåºãããŠãã ããïŒ 1ã2 ã
PVS-Studio
Linuxã¢ãã©ã€ã¶ãŒã®PVS-Studioã®ã¢ã«ãã¡çã§GCCã³ãŒãããã§ãã¯ããŸããã 2016幎9æäžæ¬ã«ãé¢å¿ã®ããããã°ã©ããŒã«ã¢ãã©ã€ã¶ãŒã®ããŒã¿çã®çºè¡ãéå§ããäºå®ã§ãã ãããžã§ã¯ãã§PVS-Studio for Linuxã®ããŒã¿çãè©Šãããšãã§ããæåã®äººã«ãªãæ¹æ³ã«ã€ããŠã¯ãèšäºã PVS-StudioãLinuxã«å¯Ÿããæã宣èšãã ããåç §ããŠãã ããã
2016幎9æãããã£ãšåŸã«ãã®èšäºãèªãã§PVS-Studio for Linuxãè©ŠããŠã¿ããå Žåã¯ã補åããŒãžhttp://www.viva64.com/en/pvs-studio/ã«æåŸ ããŸãã
æ€èšŒçµæ
æãèå³æ·±ãã»ã¯ã·ã§ã³ã«ãã©ãçããŸãããç§ãã¡ã®åžžé£èªè ã¯æ¥œãã¿ã«ããŠããŸãã ã¢ãã©ã€ã¶ãŒããšã©ãŒãŸãã¯éåžžã«çãããç¬éãèŠã€ããã³ãŒãã®ã»ã¯ã·ã§ã³ãæ€èšããŠãã ããã
æ®å¿µãªãããã³ã³ãã€ã©éçºè ã«å®å šãªã¬ããŒããæäŸããããšã¯ã§ããŸããã ã¢ãã©ã€ã¶ãŒãLinuxã®äžçã«å®å šã«å¯Ÿå¿ããæºåãæŽã£ãŠããªããšããäºå®ã«é¢é£ãããŽãïŒèª€æ€ç¥ïŒããŸã å€ãããŸãã 䜿çšãããå žåçãªæ§é ã«é¢ãã誀ã£ãèŠåã®æ°ãæžããäœæ¥ãè¡ãå¿ èŠããããŸãã ç°¡åãªäŸã§èª¬æããŸãã å€ãã®èšºæã§ã¯ããã¯ãã®ã¢ãµãŒãã«é¢é£ããåŒãèªãå¿ èŠã¯ãããŸããã ãããã®ãã¯ãã¯éåžžã«åµé çã§ãããã¢ãã©ã€ã¶ãŒã«æ³šæãæããªãããã«æããå¿ èŠããããŸãã ããããå®éã«ã¯ã assertãã¯ãã¯éåžžã«ç°ãªãæ¹æ³ã§å®çŸ©ãããŠããããã¹ãŠã®äžè¬çãªãªãã·ã§ã³ã§ã¢ãã©ã€ã¶ãŒããã¬ãŒãã³ã°ããå¿ èŠããããŸãã
ãã®ãããGCCéçºè ã«ã¯ãå°ãªããšãããŒã¿çã®ã¢ãã©ã€ã¶ãŒã®ãªãªãŒã¹ãåŸ ã€ãããé¡ãããŸãã æªå®æã®ããŒãžã§ã³ã§çæãããã¬ããŒãã§å°è±¡ãæãªããããããŸããã
ã¯ã©ã·ãã¯ïŒã³ããŒããŒã¹ãïŒ
V501蚺æããã°ã©ã ã§æ€åºãããæãå€å žçã§äžè¬çãªééãããå§ããŸãã ååãšããŠããã®ãããªãšã©ãŒã¯ã³ããŒããŒã¹ãäžã®äžæ³šæã®ããã«è¡šç€ºãããããåã«æ°ããã³ãŒããå ¥åãããšãã«å ¥åãã¹ãèš±å¯ãããŸãã
static bool dw_val_equal_p (dw_val_node *a, dw_val_node *b) { .... case dw_val_class_vms_delta: return (!strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1) && !strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1)); .... }
PVS-Studioã¢ãã©ã€ã¶ãŒã®èŠåïŒ V501ã&&ãæŒç®åã®å·Šãšå³ã«åãå¯æ¬¡åŒãïŒStrcmpïŒa-> v.val_vms_delta.lbl1ãb-> v.val_vms_delta.lbl1ïŒãããããŸãã dwarf2out.c 1428
ãšã©ãŒãããã«åé¡ã«ãªãããšã確èªãã泚ææ·±ã調ã¹ãå¿ èŠããããŸãã ãã®ãããã³ãŒãã¬ãã¥ãŒãšãªãã¡ã¯ã¿ãªã³ã°äžã«ãšã©ãŒãæ€åºãããŸããã§ããã
strcmpé¢æ°ã¯ãåãè¡ã2åæ¯èŒããŸãã 2床ç®ã«ã¯ãã¯ã©ã¹lbl1ã®ã¡ã³ããŒã§ã¯ãªãlbl2ãæ¯èŒããå¿ èŠããã£ãããã«æããŸãã æ£ããã³ãŒãã¯æ¬¡ã®ããã«ãªããŸãã
return (!strcmp (a->v.val_vms_delta.lbl1, b->v.val_vms_delta.lbl1) && !strcmp (a->v.val_vms_delta.lbl2, b->v.val_vms_delta.lbl2));
ãã®èšäºã®ã³ãŒãã¯ãX軞äžã®ã¹ããŒã¹ãã»ãšãã©ãšããªãããã«ãããã«ãã©ãŒããããããŠããŸãããå®éã«ã¯æ¬¡ã®ããã«ãªããŸãã
ãããŒãã«ãã³ãŒãã¢ã©ã€ã¡ã³ãã䜿çšããã°ãããããééããåé¿ã§ããã§ãããã ããšãã°ã次ã®ããã«ã³ãŒãããã©ãŒããããããšããšã©ãŒããããããããªããŸãã
ãã®ã¢ãããŒãã«ã€ããŠã¯ãé»åæžç±ã ããã°ã©ãã³ã°ããªãã¡ã¯ã¿ãªã³ã°ããã®ä»ãã¹ãŠã®äž»ãªåé¡ ãã§è©³ããæ€èšããŸããïŒN13ç« ãåãã¿ã€ãã®ã³ãŒãããããŒãã«ãã«æããããåç §ïŒã ã³ãŒãã®å質ãæ°ã«ãã人ã«ã¯ãããã§æäŸãããŠãããªã³ã¯ãç¥ã£ãŠããããšããå§ãããŸãã
Copy-Pasteãåå ã§çºçãããšæãããå¥ã®ãšã©ãŒãèŠãŠã¿ãŸãããã
const char *host_detect_local_cpu (int argc, const char **argv) { unsigned int has_avx512vl = 0; unsigned int has_avx512ifma = 0; .... has_avx512dq = ebx & bit_AVX512DQ; has_avx512bw = ebx & bit_AVX512BW; has_avx512vl = ebx & bit_AVX512VL; // <= has_avx512vl = ebx & bit_AVX512IFMA; // <= .... }
PVS-Studioã¢ãã©ã€ã¶ãŒã®èŠåïŒ V519 'has_avx512vl'å€æ°ã«ã¯å€ãé£ç¶ããŠ2åå²ãåœãŠãããŸãã ããããããã¯ééãã§ãã è¡ã確èªããŠãã ããïŒ500ã501ãdriver-i386.c 501
has_avx512vlå€æ°ã«ã¯ãããŸããŸãªå€ãé£ç¶ããŠ2åæžã蟌ãŸããŸãã æå³ããããŸãã ã³ãŒãã調ã¹ãŠã has_avx512ifmaå€æ°ãçºèŠããŸãã ã ã»ãšãã©ã®å ŽåãåŒebxïŒbit_AVX512IFMAã§åæåããå¿ èŠããããŸãã æ£ããã³ãŒãã¯æ¬¡ã®ããã«ãªããŸãã
has_avx512vl = ebx & bit_AVX512VL; has_avx512ifma = ebx & bit_AVX512IFMA;
ã¿ã€ããã¹
ããªãã®ãã€ã³ããã«ãã¹ã®ãã¹ããç¶ããŸãã ã³ãŒããèŠãŠãäžãèŠããã«ãšã©ãŒãèŠã€ããŠãã ããã
static bool ubsan_use_new_style_p (location_t loc) { if (loc == UNKNOWN_LOCATION) return false; expanded_location xloc = expand_location (loc); if (xloc.file == NULL || strncmp (xloc.file, "\1", 2) == 0 || xloc.file == '\0' || xloc.file[0] == '\xff' || xloc.file[1] == '\xff') return false; return true; }
PVS-Studioã¢ãã©ã€ã¶ãŒã®èŠåïŒ V528 ãcharãã¿ã€ããžã®ãã€ã³ã¿ãŒãã\ 0ãå€ãšæ¯èŒãããã®ã¯å¥åŠã§ãã ãããã以äžãæå³ããŸãïŒ* xloc.file == '\ 0'ã ubsan.c 1472
ããã§ãããã°ã©ããŒã¯ãåŒxloc.file == '\ 0'ã®ãã€ã³ã¿ãŒãéåç §ããã®ã誀ã£ãŠå¿ããŠããŸããã ãã®çµæããã€ã³ã¿ãŒã¯åçŽã«0ãšæ¯èŒãããŸãã NULLã䜿çšããŸã ã 以åã¯ãã®ãããªãã§ãã¯ããã§ã«å®è¡ãããŠãããããããã¯å¹æããããŸããïŒ xloc.file == NULL ã
ããã°ã©ããã¿ãŒããã«ãŒããã\ 0ããšæžãçããŠãããšäŸ¿å©ã§ãã ããã«ãããã³ãŒããééã£ãŠããããšãšãã®ä¿®æ£æ¹æ³ããã°ããç解ã§ããŸãã ãã®ããšã«ã€ããŠã¯ãæ¬ã§ãæžããŸããïŒN9ç« ïŒãªãã©ã«ã\ 0ãã䜿çšããŠã¿ãŒããã«ãŒãã瀺ããŸãïŒã
æ£ããã³ãŒãã¯æ¬¡ã®ãšããã§ãã
if (xloc.file == NULL || strncmp (xloc.file, "\1", 2) == 0 || xloc.file[0] == '\0' || xloc.file[0] == '\xff' || xloc.file[1] == '\xff') return false;
ãã ããã³ãŒããããå°ãæ¹åããŸãããã 次ã®ããã«åŒããã©ãŒãããããããšããå§ãããŸãã
if ( xloc.file == NULL || strncmp (xloc.file, "\1", 2) == 0 || xloc.file[0] == '\0' || xloc.file[0] == '\xff' || xloc.file[1] == '\xff') return false;
泚æïŒä»ãããªããåãééããããå Žåãããã«æ°ä»ãå¯èœæ§ã¯ãããã«é«ããªããŸãïŒ
if ( xloc.file == NULL || strncmp (xloc.file, "\1", 2) == 0 || xloc.file == '\0' || xloc.file[0] == '\xff' || xloc.file[1] == '\xff') return false;
æœåšçãªNULLãã€ã³ã¿ãŒã®éåç §
ãã®ã»ã¯ã·ã§ã³ã¯ãã10äžçªç®ã®äŸããã¯ããæªãçç±ããšãåŒã°ããŸãã ç§ã¯ãã¯ããæ¬åœã«å«ãã§ãåžžã«ãã¯ãã®äœ¿çšãæ§ããããå§ããŠããŸãã ãã¯ãã¯ãã³ãŒãã®èªã¿åããå°é£ã«ãããšã©ãŒãåŒãèµ·ãããéçã¢ãã©ã€ã¶ãŒã®äœæ¥ãè€éã«ããŸãã GCCã³ãŒããšã®çãäŒè©±ãããèè ã¯ãã¯ããéåžžã«å¥œãã§ããããã«æããŸããã ç§ã¯ãã®ãã¯ããŸãã¯ãã®ãã¯ããäœã§æããã«ãããŠããã®ããç 究ããããã«èŠãã¿ãŸããããããããããå€ãã®èå³æ·±ããšã©ãŒãèŠéããçç±ã§ãã ç§ã¯æã ãæ ãè ã§ãã ãã ãããã¯ãã«é¢é£ããããã€ãã®ãšã©ãŒãåŒãç¶ã瀺ããŸãã
odr_type get_odr_type (tree type, bool insert) { .... odr_types[val->id] = 0; gcc_assert (val->derived_types.length() == 0); if (odr_types_ptr) val->id = odr_types.length (); .... }
PVS-Studioã¢ãã©ã€ã¶ãŒã®èŠåïŒ V595 nullptrã«å¯ŸããŠæ€èšŒãããåã«ããodr_types_ptrããã€ã³ã¿ãŒã䜿çšãããŸããã è¡ã確èªããŠãã ããïŒ2135ã2139ãipa-devirt.c 2135
ããã«ééãããããŸããïŒ ç§ã¯ããã¯æããŸããããã¢ãã©ã€ã¶ãŒã®ã¡ãã»ãŒãžã¯æçãããããããŸããã åé¡ã¯ã odr_typesã¯å€æ°åã§ã¯ãªãã次ã®ããã«å®£èšããããã¯ãã§ãããšããããšã§ãã
#define odr_types (*odr_types_ptr)
ãã¯ããéããŠãé¢ä¿ã®ãªããã®ããã¹ãŠåé€ãããšã次ã®ã³ãŒããååŸãããŸãã
(*odr_types_ptr)[val->id] = 0; if (odr_types_ptr)
æåã«ããã€ã³ã¿ãŒã¯éåç §ããããã§ãã¯ãããŸãã ãããå®éã«ãã©ãã«ã«ã€ãªãããã©ãããèšãã®ã¯é£ããã§ãããã ããã¯ãã¹ãŠããã€ã³ã¿ãŒãå®éã«nullptrã§ãããšãã«ç¶æ³ãçºçããå¯èœæ§ããããã©ããã«äŸåããŸãã ãã®ç¶æ³ãäžå¯èœãªå Žåã¯ãäœåãªãã§ãã¯ãåé€ããå¿ èŠããããŸããããã¯ãã³ãŒããšã³ãŒãã¢ãã©ã€ã¶ãŒããµããŒããã人ã ã誀解ãããŸãã ãã€ã³ã¿ãŒããã«ã«ãªãå¯èœæ§ãããå Žåãããã¯æ·±å»ãªééãã§ãããããã«æ³šæãšä¿®æ£ãå¿ èŠã§ãã
å¥ã®åæ§ã®ã±ãŒã¹ãèããŠã¿ãŸãããïŒ
static inline bool sd_iterator_cond (sd_iterator_def *it_ptr, dep_t *dep_ptr) { .... it_ptr->linkp = &DEPS_LIST_FIRST (list); if (list) continue; .... }
PVS-Studioã¢ãã©ã€ã¶ãŒã®èŠåïŒ V595 nullptrã«å¯ŸããŠæ€èšŒãããåã«ããªã¹ãããã€ã³ã¿ãŒã䜿çšãããŸããã è¡ã確èªããŠãã ããïŒ1627ã1629ãsched-int.h 1627
ãšã©ãŒã衚瀺ããã«ã¯ããã¯ãããã€ã¹ãå床衚瀺ããå¿ èŠããããŸãã
#define DEPS_LIST_FIRST(L) ((L)->first)
ãã¯ããéãã以äžãååŸããŸãã
it_ptr->linkp = &((list)->first); if (list) continue;
ãããŠä»ãå€ãã®äººãå«ã¶ã§ãããïŒããããŠããããŠïŒ ééãã¯ãããŸããã ã¯ã©ã¹ã®ã¡ã³ããŒãžã®ãã€ã³ã¿ãååŸããã ãã§ãã ããã§ã¯ãnullãã€ã³ã¿ãŒã®éåç §ã¯ãããŸããã ã¯ããããããã³ãŒãã¯æ£ç¢ºã§ã¯ãããŸããããããã«ã¯ãšã©ãŒã¯ãããŸããïŒã
ããã»ã©åçŽã§ã¯ãããŸããã ããã§æªå®çŸ©ã®åäœãçºçããŸãã ãããŠããã®ãããªã³ãŒããå®éã«æ©èœãããšããäºå®ã¯å¹žéã§ãã å®éããã®ããã«æžãããšã¯ã§ããŸããã ããšãã°ãæé©åã³ã³ãã€ã©ã¯ã list->ãæåã«èŠãŠã ifïŒãªã¹ãïŒãã§ãã¯ãåé€ã§ããŸãã ->æŒç®åãå®è¡ããããããã€ã³ã¿ãŒãnullptrã§ã¯ãªãããšãæå³ããŸãã ãã®å Žåããã€ã³ã¿ãŒã確èªããå¿ èŠã¯ãããŸããã
ãã®ãããã¯ã«é¢ããèšäºå šäœãæžããŸããïŒã nullãã€ã³ã¿ãŒãéåç §ãããšæªå®çŸ©ã®åäœãçºçããŸããã åæ§ã®ã±ãŒã¹ãããã§æ€èšãããŠããŸãã è°è«ããåã«ããã®èšäºã泚ææ·±ãèªãã§ãã ããã
ãã ããèæ ®ãããç¶æ³ã¯éåžžã«è€éã§æçœã§ã¯ãããŸããã ç§ã¯ãŸã ééã£ãŠããå¯èœæ§ããããééãããªãããšãèªããŸãã ãããããããŸã§ã®ãšãã誰ãç§ã«ããã蚌æããããšãã§ããŸããã§ããã GCCéçºè ããã®èšäºã«æ³šæãæããšãGCCéçºè ããã®ã³ã¡ã³ããèãã®ã¯é¢çœãã§ãããã 圌ãã¯ãã³ã³ãã€ã©ãã©ã®ããã«æ©èœãããããããŠãã®ãããªã³ãŒãããšã©ãŒãšããŠè§£éãããã¹ããã©ãããæ£ç¢ºã«ç¥ãå¿ èŠããããŸãã
ç Žå£ãããé åã䜿çšãã
static void dump_hsa_symbol (FILE *f, hsa_symbol *symbol) { const char *name; if (symbol->m_name) name = symbol->m_name; else { char buf[64]; sprintf (buf, "__%s_%i", hsa_seg_name (symbol->m_segment), symbol->m_name_number); name = buf; } fprintf (f, "align(%u) %s_%s %s", hsa_byte_alignment (symbol->m_align), hsa_seg_name(symbol->m_segment), hsa_type_name(symbol->m_type & ~BRIG_TYPE_ARRAY_MASK), name); .... }
PVS-Studioã¢ãã©ã€ã¶ãŒã®èŠåïŒ V507ã®ããŒã«ã«é åãbufããžã®ãã€ã³ã¿ãŒã¯ããã®é åã®ã¹ã³ãŒãå€ã«ä¿åãããŸãã ãã®ãããªãã€ã³ã¿ãŒã¯ç¡å¹ã«ãªããŸãã hsa-dump.c 704
äžæãããã¡bufã«æååã圢æãããŸãã ãã®äžæãããã¡ã®ã¢ãã¬ã¹ã¯å€æ°åã«ä¿åãããåŸã§é¢æ°ã®æ¬äœã§äœ¿çšãããŸãã ãšã©ãŒã¯ãå€æ°nameã«ãããã¡ãŒãæžã蟌ãã åŸããã®ãããã¡ãŒèªäœãç Žæ£ãããããšã§ãã
ç Žå£ããããããã¡ãžã®ãã€ã³ã¿ã¯äœ¿çšã§ããŸããã æ£åŒã«ã¯ãäžå®ã®åäœãæ±ã£ãŠããŸãã å®éã«ã¯ããã®ã³ãŒãã¯éåžžã«ããŸãæ©èœããŸãã ããã°ã©ã ã®æ£ããåäœã¯ãæªå®çŸ©ã®åäœãæ瀺ããããã®ãªãã·ã§ã³ã®1ã€ã§ãã
ãããã«ããŠãããã®ã³ãŒãã«ã¯ãšã©ãŒãå«ãŸããŠãããããä¿®æ£ããå¿ èŠããããŸãã ã³ãŒãã¯ãã³ã³ãã€ã©ãä»ã®å€æ°ãŸãã¯é åã®åŸç¶ã®æ ŒçŽã«äžæãããã¡ã䜿çšããå¿ èŠããªããšèãããããããªããšããçç±ã§æ©èœããå ŽåããããŸãã ãããŠãã¹ã¿ãã¯äžã«äœæãããé åã¯ç Žå£ããããšèŠãªãããŸãããå®éã«ã¯èª°ãããã«è§Šããããšãã§ãããé¢æ°ã¯ãã®ä»äºãæ£ããè¡ããŸãã ããã¯ãã€ã§ãçµããããããšãã§ãã幞éã§ããã10幎éåããŠããã³ãŒãã¯ãçªç¶ãã³ã³ãã€ã©ã®æ°ããããŒãžã§ã³ã«åãæ¿ãããšãé©ãã»ã©ã®åäœãéå§ããŸãã
ãšã©ãŒãä¿®æ£ããã«ã¯ã ååãã€ã³ã¿ãšåãã¹ã³ãŒãã§bufé åã宣èšããã ãã§ãïŒ
static void dump_hsa_symbol (FILE *f, hsa_symbol *symbol) { const char *name; char buf[64]; .... }
æ¡ä»¶ã«é¢ä¿ãªãåãã¢ã¯ã·ã§ã³ãå®è¡ãã
ã¢ãã©ã€ã¶ãŒã¯ããšã©ãŒãšããŠæ確ã«ç¹å®ã§ããªãã³ãŒãã®ã»ã¯ã·ã§ã³ãæ€åºããŸããã ãã ãããã§ãã¯ãå®è¡ãããã®çµæã«é¢ä¿ãªãåãã¢ã¯ã·ã§ã³ãå®è¡ããããšã¯éåžžã«çãããã§ãã ãã¡ãããããããããã¯æªæ¥ã«åœ±é¿ãäžããŠããããããŸã§ã®ãšãããã¹ãŠãæ£ããã§ãããã³ãŒãã®ãã®ã»ã¯ã·ã§ã³ã確èªãã䟡å€ãããããšã¯æããã§ãã
bool thread_through_all_blocks (bool may_peel_loop_headers) { .... /* Case 1, threading from outside to inside the loop after we'd already threaded through the header. */ if ((*path)[0]->e->dest->loop_father != path->last ()->e->src->loop_father) { delete_jump_thread_path (path); e->aux = NULL; ei_next (&ei); } else { delete_jump_thread_path (path); e->aux = NULL; ei_next (&ei); } .... }
PVS-Studioã¢ãã©ã€ã¶ãŒã®èŠåïŒ V523 ãthenãã¹ããŒãã¡ã³ãã¯ãelseãã¹ããŒãã¡ã³ããšåçã§ãã tree-ssa-threadupdate.c 2596
ãã®ã³ãŒãã«èª€ããããå Žåãæ®å¿µãªãããä¿®æ£æ¹æ³ãããããŸããã ããã¯ãä¿®æ£ãè¡ãããã«ãããžã§ã¯ãã«ç²Ÿéããå¿ èŠãããå Žåã§ãã
ãã©ãŒã ã®éå°ãªè¡šçŸïŒA == 1 || AïŒ= 2ïŒ
static const char * alter_output_for_subst_insn (rtx insn, int alt) { const char *insn_out, *sp ; char *old_out, *new_out, *cp; int i, j, new_len; insn_out = XTMPL (insn, 3); if (alt < 2 || *insn_out == '*' || *insn_out != '@') return insn_out; .... }
PVS-Studioã¢ãã©ã€ã¶ãŒã®èŠåïŒ V590ãã®åŒã®æ€æ»ãæ€èšããŠãã ããã è¡šçŸãéå°ã§ãããã誀æ€ãå«ãŸããŠããŸãã gensupport.c 1640
æ¡ä»¶ã«èå³ããããŸãïŒïŒalt <2 || * insn_out == '*' || * insn_outïŒ= '@'ïŒ
ççž®ã§ããŸãïŒïŒalt <2 || * insn_outïŒ= '@'ïŒ
æŒç®åïŒ=ã==ã«çœ®ãæããå¿ èŠããããšæã蟌ãã§ããŸãã 次ã«ãã³ãŒãã¯ããæå³ã®ããå€èŠ³ã«ãªããŸãã
if (alt < 2 || *insn_out == '*' || *insn_out == '@')
ééã£ããã€ã³ã¿ãŒããŒãã«ãã
ãªãœãŒã¹ã解æŸããæ©èœãæ€èšããŠãã ããã
void free_original_copy_tables (void) { gcc_assert (original_copy_bb_pool); delete bb_copy; bb_copy = NULL; delete bb_original; bb_copy = NULL; delete loop_copy; loop_copy = NULL; delete original_copy_bb_pool; original_copy_bb_pool = NULL; }
PVS-Studioã¢ãã©ã€ã¶ãŒã®èŠåïŒ V519ãbb_copyãå€æ°ã«ã¯é£ç¶ããŠ2åå€ãå²ãåœãŠãããŸãã ããããããã¯ééãã§ãã è¡ã確èªããŠãã ããïŒ1076ã1078ãcfg.c 1078
次ã®4è¡ã®ã³ãŒãã«æ³šæããŠãã ããã
delete bb_copy; bb_copy = NULL; delete bb_original; bb_copy = NULL;
bb_copyãã€ã³ã¿ãŒã誀ã£ãŠ2åç¡å¹ã«ãããŸãã æ£ãããªãã·ã§ã³ïŒ
delete bb_copy; bb_copy = NULL; delete bb_original; bb_original = NULL;
äœããã§ãã¯ããªããšã¢ãµãŒããã
gcc_assertãã¯ãã®åŒæ°ã§ãã誀ã£ãæ¡ä»¶ã¯ãããã°ã©ã ã®æ£ç¢ºæ§ã«ã¯åœ±é¿ããŸãããããšã©ãŒãçºçããå Žåã®æ€çŽ¢ãè€éã«ããŸãã ã³ãŒããèæ ®ããŠãã ããïŒ
static void output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip) { unsigned long die_offset = get_ref_die_offset (val1->v.val_die_ref.die); .... gcc_assert (die_offset > 0 && die_offset <= (loc->dw_loc_opc == DW_OP_call2) ? 0xffff : 0xffffffff); .... }
PVS-Studioã¢ãã©ã€ã¶ãŒã®èŠåïŒ V502ãããããïŒïŒããªãã¬ãŒã¿ãŒã¯äºæ³ãšã¯ç°ãªãæ¹æ³ã§åäœããŸãã ãïŒïŒãæŒç®åã®åªå é äœã¯ãã<=ãæŒç®åãããäœããªã£ãŠããŸãã dwarf2out.c 2053
äžé æŒç®åïŒã®åªå é äœïŒæ¯èŒæŒç®å<=ã®åªå é äœãããäœãã ããã¯ã次ã®åœ¢åŒã®æ¡ä»¶ãæ±ã£ãŠããããšãæå³ããŸãã
die_offset > 0 && ((die_offset <= (loc->dw_loc_opc == DW_OP_call2)) ? 0xffff : 0xffffffff);
ãããã£ãŠã &&æŒç®åã®ç¬¬2ãªãã©ã³ãã¯ãå€0xffffãŸãã¯0xffffffffãåãããšãã§ããŸãã ãããã¯äž¡æ¹ãšãçã§ãããããåŒã¯æ¬¡ã®ããã«ç°¡ç¥åã§ããŸãã
(die_offset > 0)
ããã¯æããã«ããã°ã©ããæå³ãããã®ã§ã¯ãããŸããã ãããä¿®æ£ããã«ã¯ãæ¬åŒ§ãããã€ãè¿œå ããŸãã
gcc_assert (die_offset > 0 && die_offset <= ((loc->dw_loc_opc == DW_OP_call2) ? 0xffff : 0xffffffff));
æŒç®åïŒïŒéåžžã«æœè¡æ§ããããè€éãªåŒã§ã¯äœ¿çšããªãæ¹ãè¯ãã§ãã ééããã®ã¯ãšãŠãç°¡åã§ãã ããŸããŸãªãªãŒãã³ãœãŒã¹ãããžã§ã¯ãã§PVS-Studioã¢ãã©ã€ã¶ãŒã«ãã£ãŠæ€åºããããã®ãããªãšã©ãŒã®äŸãå€æ°åéããŸããã æŒç®åã«ã€ããŠã®è©³çŽ°ã¯ïŒïŒãã§ã«åè¿°ããæ¬ã«æžããŸããïŒN4ç« ïŒæŒç®åãæããŸããïŒïŒãããŠæ¬åŒ§ã§å²ã¿ãŸãïŒã
圌ãã¯ãè²»çšããå¿ããŠããããã§ã
alg_hash_entryæ§é äœã¯ ã次ã®ããã«å®£èšãããŸãã
struct alg_hash_entry { unsigned HOST_WIDE_INT t; machine_mode mode; enum alg_code alg; struct mult_cost cost; bool speed; };
synth_multé¢æ°ã§ãããã°ã©ããŒã¯ããããå¿ èŠãªãªããžã§ã¯ãã§ãããã©ããã確èªããããšã«ããŸããã ãããè¡ãã«ã¯ãæ§é ãã£ãŒã«ããæ¯èŒããå¿ èŠããããŸãã ãã ãããã®å Žæã«ã¯ééããããããã§ãã
static void synth_mult (....) { .... struct alg_hash_entry *entry_ptr; .... if (entry_ptr->t == t && entry_ptr->mode == mode && entry_ptr->mode == mode && entry_ptr->speed == speed && entry_ptr->alg != alg_unknown) { .... }
PVS-Studioã¢ãã©ã€ã¶ãŒã®èŠåïŒ V501ã&&ãæŒç®åã®å·ŠåŽãšå³åŽã«ã¯ãåããµãè¡šçŸãentry_ptr-> mode == modeãããããŸãã expmed.c 2573
ã¢ãŒãã¯é£ç¶ããŠ2åãã§ãã¯ãããŸããã ã³ã¹ããã§ãã¯ã¯ãããŸããã ãããããæ¯èŒã®1ã€ãåé€ããã ããã ã³ã¹ããæ¯èŒããå¿ èŠããããŸã ã ç§ãå€æããã®ã¯é£ããã§ãããã³ãŒãã¯æããã«ä¿®æ£ãã䟡å€ããããŸãã
å²ãåœãŠã®éè€
ç§ã®æèŠã§ã¯ãã³ãŒãã®æ¬¡ã®ã»ã¯ã·ã§ã³ã¯å±éºã§ã¯ãªããéè€ããå²ãåœãŠãç°¡åã«åé€ã§ããããã§ãã
ã±ãŒã¹N1
type_p find_structure (const char *name, enum typekind kind) { .... structures = s; // <= s->kind = kind; s->ustag = name; structures = s; // <= return s; }
PVS-Studioã¢ãã©ã€ã¶ãŒã®èŠåïŒ V519ãæ§é ãå€æ°ã«ã¯ãé£ç¶ããŠ2åå€ãå²ãåœãŠãããŸãã ããããããã¯ééãã§ãã è¡ã確èªããŠãã ããïŒ842ã845ãgengtype.c 845
ã±ãŒã¹N2
static rtx ix86_expand_sse_pcmpistr (....) { unsigned int i, nargs; .... case V8DI_FTYPE_V8DI_V8DI_V8DI_INT_UQI: case V16SI_FTYPE_V16SI_V16SI_V16SI_INT_UHI: case V2DF_FTYPE_V2DF_V2DF_V2DI_INT_UQI: case V4SF_FTYPE_V4SF_V4SF_V4SI_INT_UQI: case V8SF_FTYPE_V8SF_V8SF_V8SI_INT_UQI: case V8SI_FTYPE_V8SI_V8SI_V8SI_INT_UQI: case V4DF_FTYPE_V4DF_V4DF_V4DI_INT_UQI: case V4DI_FTYPE_V4DI_V4DI_V4DI_INT_UQI: case V4SI_FTYPE_V4SI_V4SI_V4SI_INT_UQI: case V2DI_FTYPE_V2DI_V2DI_V2DI_INT_UQI: nargs = 5; // <= nargs = 5; // <= mask_pos = 1; nargs_constant = 1; break; .... }
PVS-Studioã¢ãã©ã€ã¶ãŒã®èŠåïŒ V519ãnargsãå€æ°ã«ã¯ãé£ç¶ããŠ2åå€ãå²ãåœãŠãããŸãã ããããããã¯ééãã§ãã ãã§ãã¯è¡ïŒ39951ã39952ãi386.c 39952
ã±ãŒã¹N3
åŸè ã®ã±ãŒã¹ã¯ãä»ã®ã±ãŒã¹ãããå¥åŠã§ãã ããããäœããã®ééãããããŸãã å€æ°steptypeã®å€ã¯2åãŸãã¯3åå²ãåœãŠãããŸãã ããã¯çãããã§ãã
static void cand_value_at (....) { aff_tree step, delta, nit; struct iv *iv = cand->iv; tree type = TREE_TYPE (iv->base); tree steptype = type; // <= if (POINTER_TYPE_P (type)) steptype = sizetype; // <= steptype = unsigned_type_for (type); // <= .... }
PVS-Studioã¢ãã©ã€ã¶ãŒã®èŠåïŒ V519ãsteptypeãå€æ°ã«ã¯ãé£ç¶ããŠ2åå€ãå²ãåœãŠãããŸãã ããããããã¯ééãã§ãã è¡ã確èªããŠãã ããïŒ5173ã5174ãtree-ssa-loop-ivopts.c 5174
ãããã«
ãã®èšäºãæžããŠããããã§ãã ãGCCã¯åãèŠåãåºãã®ã§ãPVS-Studioã¯å¿ èŠãããŸããããªã©ã®ã³ã¡ã³ãã«å¯Ÿå¿ãããã®ããããŸãã ã芧ã®ãšãããPVS-Studioã¯éåžžã«åŒ·åãªããŒã«ã§ãããGCCããã蚺ææ©èœã«åªããŠããŸãã GCCã«åªãã蚺ææ©èœãããããšãåŠå®ããŸããã ãã®ã³ã³ãã€ã©ã¯ãé©åã«æ§æãããŠããã°ãã³ãŒãã®å€ãã®åé¡ãæããã«ããŸãã ããããPVS-Studioã¯å°éçãã€æ¥éã«éçºãããŠããããŒã«ã§ããã€ãŸããã³ã³ãã€ã©ãããã³ãŒãã®ãšã©ãŒãæ€åºããæ¹ãåžžã«åªããŠããŸãã
ç§ãã¡ã®ãµã€ãã®ãã®ã»ã¯ã·ã§ã³ã«ã¢ã¯ã»ã¹ããŠãä»ã®æåãªãªãŒãã³ãœãŒã¹ãããžã§ã¯ãã®ãã§ãã¯ã«ç²ŸéããŠãã ããã ãŸããTwitterã䜿çšããŠããå Žåã¯ã @ Code_Analysisããã©ããŒããŠãã ãã ã Cããã³C ++ã§ã®ããã°ã©ãã³ã°ã«é¢ããèå³æ·±ãèšäºãžã®ãªã³ã¯ãå®æçã«å ¬éããã¢ãã©ã€ã¶ãŒã®æ°ããææã«ã€ããŠã説æããŸãã
ãã®èšäºãè±èªåã®èŽè¡ãšå ±æãããå Žåã¯ã翻蚳ãžã®ãªã³ã¯ã䜿çšããŠãã ããïŒAndrey karpovã PVS-Studioã®å©ããåããŠGCCã§èŠã€ãã£ããã° ã
èšäºãèªãã§è³ªåããããŸããïŒ
å€ãã®å Žåãèšäºã«ã¯åã質åãå¯ããããŸãã ããã§åçãéããŸããïŒ PVS-StudioããŒãžã§ã³2015ã«é¢ããèšäºã®èªè
ããã®è³ªåãžã®åç ã ãªã¹ããã芧ãã ããã