brintos

brintos / llvm-project-archived public Read only

0
0
Text · 32.6 KiB · 8dcef30 Raw
1313 lines · cpp
1// RUN: %check_clang_tidy %s misc-redundant-expression -check-suffix=IDENTEXPR %t2 3/* Only one expected warning per function allowed at the very end. */4 5int func(void)6{7  return 0;8}9 10int func2(void)11{12  return 0;13}14 15int funcParam(int a)16{17  return 0;18}19 20/* '!=' operator*/21 22/* '!=' with float */23int checkNotEqualFloatLiteralCompare1(void) {24  return (5.14F != 5.14F); // no warning25}26 27int checkNotEqualFloatLiteralCompare2(void) {28  return (6.14F != 7.14F); // no warning29}30 31int checkNotEqualFloatDeclCompare1(void) {32  float f = 7.1F;33  float g = 7.1F;34  return (f != g); // no warning35}36 37int checkNotEqualFloatDeclCompare12(void) {38  float f = 7.1F;39  return (f != f); // no warning40}41 42int checkNotEqualFloatDeclCompare3(void) {43  float f = 7.1F;44  return (f != 7.1F); // no warning45}46 47int checkNotEqualFloatDeclCompare4(void) {48  float f = 7.1F;49  return (7.1F != f); // no warning50}51 52int checkNotEqualFloatDeclCompare5(void) {53  float f = 7.1F;54  int t = 7;55  return (t != f); // no warning56}57 58int checkNotEqualFloatDeclCompare6(void) {59  float f = 7.1F;60  int t = 7;61  return (f != t); // no warning62}63 64 65 66int checkNotEqualCastFloatDeclCompare11(void) {67  float f = 7.1F;68  return ((int)f != (int)f);69// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:18: warning: both sides of operator are equivalent [misc-redundant-expression]70}71int checkNotEqualCastFloatDeclCompare12(void) {72  float f = 7.1F;73  return ((char)f != (int)f); // no warning74}75int checkNotEqualBinaryOpFloatCompare1(void) {76  int res;77  float f= 3.14F;78  res = (f + 3.14F != f + 3.14F);  // no warning79// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:20: warning: both sides of operator are equivalent [misc-redundant-expression]80  return (0);81}82int checkNotEqualBinaryOpFloatCompare2(void) {83  float f = 7.1F;84  float g = 7.1F;85  return (f + 3.14F != g + 3.14F); // no warning86}87int checkNotEqualBinaryOpFloatCompare3(void) {88  int res;89  float f= 3.14F;90  res = ((int)f + 3.14F != (int)f + 3.14F);  // no warning91// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:25: warning: both sides of operator are equivalent [misc-redundant-expression]92  return (0);93}94int checkNotEqualBinaryOpFloatCompare4(void) {95  int res;96  float f= 3.14F;97  res = ((int)f + 3.14F != (char)f + 3.14F);  // no warning98  return (0);99}100 101int checkNotEqualNestedBinaryOpFloatCompare1(void) {102  int res;103  int t= 1;104  int u= 2;105  float f= 3.14F;106  res = (((int)f + (3.14F - u)*t) != ((int)f + (3.14F - u)*t));  // no warning107// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:35: warning: both sides of operator are equivalent [misc-redundant-expression]108  return (0);109}110 111int checkNotEqualNestedBinaryOpFloatCompare2(void) {112  int res;113  int t= 1;114  int u= 2;115  float f= 3.14F;116  res = (((int)f + (u - 3.14F)*t) != ((int)f + (3.14F - u)*t));  // no warning117  return (0);118}119 120int checkNotEqualNestedBinaryOpFloatCompare3(void) {121  int res;122  int t= 1;123  int u= 2;124  float f= 3.14F;125  res = (((int)f + (u - 3.14F)*t) != ((int)f + (3.14F - u)*(f + t != f + t)));  // no warning126// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:67: warning: both sides of operator are equivalent [misc-redundant-expression]127  return (0);128}129 130 131/* end '!=' with float*/132 133/* '!=' with int*/134 135int checkNotEqualIntLiteralCompare1(void) {136  return (5 != 5);137// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:13: warning: both sides of operator are equivalent [misc-redundant-expression]138}139 140int checkNotEqualIntLiteralCompare2(void) {141  return (6 != 7); // no warning142}143 144int checkNotEqualIntDeclCompare1(void) {145  int f = 7;146  int g = 7;147  return (f != g); // no warning148}149 150int checkNotEqualIntDeclCompare3(void) {151  int f = 7;152  return (f != 7); // no warning153}154 155int checkNotEqualIntDeclCompare4(void) {156  int f = 7;157  return (7 != f); // no warning158}159 160int checkNotEqualCastIntDeclCompare11(void) {161  int f = 7;162  return ((int)f != (int)f);163// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:18: warning: both sides of operator are equivalent [misc-redundant-expression]164}165int checkNotEqualCastIntDeclCompare12(void) {166  int f = 7;167  return ((char)f != (int)f); // no warning168}169int checkNotEqualBinaryOpIntCompare1(void) {170  int res;171  int t= 1;172  int u= 2;173  int f= 4;174  res = (f + 4 != f + 4);175// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:16: warning: both sides of operator are equivalent [misc-redundant-expression]176  return (0);177}178int checkNotEqualBinaryOpIntCompare2(void) {179  int f = 7;180  int g = 7;181  return (f + 4 != g + 4); // no warning182}183 184 185int checkNotEqualBinaryOpIntCompare3(void) {186  int res;187  int t= 1;188  int u= 2;189  int f= 4;190  res = ((int)f + 4 != (int)f + 4);191// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:21: warning: both sides of operator are equivalent [misc-redundant-expression]192  return (0);193}194int checkNotEqualBinaryOpIntCompare4(void) {195  int res;196  int t= 1;197  int u= 2;198  int f= 4;199  res = ((int)f + 4 != (char)f + 4);  // no warning200  return (0);201}202int checkNotEqualBinaryOpIntCompare5(void) {203  int res;204  int t= 1;205  int u= 2;206  res = (u + t != u + t);207// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:16: warning: both sides of operator are equivalent [misc-redundant-expression]208  return (0);209}210 211int checkNotEqualNestedBinaryOpIntCompare1(void) {212  int res;213  int t= 1;214  int u= 2;215  int f= 3;216  res = (((int)f + (3 - u)*t) != ((int)f + (3 - u)*t));217// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:31: warning: both sides of operator are equivalent [misc-redundant-expression]218  return (0);219}220 221int checkNotEqualNestedBinaryOpIntCompare2(void) {222  int res;223  int t= 1;224  int u= 2;225  int f= 3;226  res = (((int)f + (u - 3)*t) != ((int)f + (3 - u)*t));  // no warning227  return (0);228}229 230int checkNotEqualNestedBinaryOpIntCompare3(void) {231  int res;232  int t= 1;233  int u= 2;234  int f= 3;235  res = (((int)f + (u - 3)*t) != ((int)f + (3 - u)*(t + 1 != t + 1)));236// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:59: warning: both sides of operator are equivalent [misc-redundant-expression]237  return (0);238}239 240/*   end '!=' int          */241 242/* '!=' with int pointer */243 244int checkNotEqualIntPointerLiteralCompare1(void) {245  int* p = 0;246  return (p != 0); // no warning247}248 249int checkNotEqualIntPointerLiteralCompare2(void) {250  return (6 != 7); // no warning251}252 253int checkNotEqualIntPointerDeclCompare1(void) {254  int k = 3;255  int* f = &k;256  int* g = &k;257  return (f != g); // no warning258}259 260int checkNotEqualCastIntPointerDeclCompare11(void) {261  int k = 7;262  int* f = &k;263  return ((int*)f != (int*)f);264// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:19: warning: both sides of operator are equivalent [misc-redundant-expression]265}266int checkNotEqualCastIntPointerDeclCompare12(void) {267  int k = 7;268  int* f = &k;269  return ((int*)((char*)f) != (int*)f); // no warning270}271int checkNotEqualBinaryOpIntPointerCompare1(void) {272  int k = 7;273  int res;274  int* f= &k;275  res = (f + 4 != f + 4);276// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:16: warning: both sides of operator are equivalent [misc-redundant-expression]277  return (0);278}279int checkNotEqualBinaryOpIntPointerCompare2(void) {280  int k = 7;281  int* f = &k;282  int* g = &k;283  return (f + 4 != g + 4); // no warning284}285 286 287int checkNotEqualBinaryOpIntPointerCompare3(void) {288  int k = 7;289  int res;290  int* f= &k;291  res = ((int*)f + 4 != (int*)f + 4);292// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:22: warning: both sides of operator are equivalent [misc-redundant-expression]293  return (0);294}295int checkNotEqualBinaryOpIntPointerCompare4(void) {296  int k = 7;297  int res;298  int* f= &k;299  res = ((int*)f + 4 != (int*)((char*)f) + 4);  // no warning300  return (0);301}302 303int checkNotEqualNestedBinaryOpIntPointerCompare1(void) {304  int res;305  int k = 7;306  int t= 1;307  int* u= &k+2;308  int* f= &k+3;309  res = ((f + (3)*t) != (f + (3)*t));310// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:22: warning: both sides of operator are equivalent [misc-redundant-expression]311  return (0);312}313 314int checkNotEqualNestedBinaryOpIntPointerCompare2(void) {315  int res;316  int k = 7;317  int t= 1;318  int* u= &k+2;319  int* f= &k+3;320  res = (((3)*t + f) != (f + (3)*t));  // no warning321  return (0);322}323/*   end '!=' int*          */324 325/* '!=' with function*/326 327int checkNotEqualSameFunction() {328  unsigned a = 0;329  unsigned b = 1;330  int res = (a+func() != a+func());  // no warning331// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:23: warning: both sides of operator are equivalent [misc-redundant-expression]332  return (0);333}334 335int checkNotEqualDifferentFunction() {336  unsigned a = 0;337  unsigned b = 1;338  int res = (a+func() != a+func2());  // no warning339  return (0);340}341 342int checkNotEqualSameFunctionSameParam() {343  unsigned a = 0;344  unsigned b = 1;345  int res = (a+funcParam(a) != a+funcParam(a));  // no warning346// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:29: warning: both sides of operator are equivalent [misc-redundant-expression]347  return (0);348}349 350int checkNotEqualSameFunctionDifferentParam() {351  unsigned a = 0;352  unsigned b = 1;353  int res = (a+funcParam(a) != a+funcParam(b));  // no warning354  return (0);355}356 357/*   end '!=' with function*/358 359/*   end '!=' */360 361 362 363/* EQ operator           */364 365int checkEqualIntPointerDeclCompare(void) {366  int k = 3;367  int* f = &k;368  int* g = &k;369  return (f == g); // no warning370}371 372int checkEqualIntPointerDeclCompare0(void) {373  int k = 3;374  int* f = &k;375  return (f+1 == f+1);376// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:15: warning: both sides of operator are equivalent [misc-redundant-expression]377}378 379/* EQ with float*/380 381int checkEqualFloatLiteralCompare1(void) {382  return (5.14F == 5.14F); // no warning383}384 385int checkEqualFloatLiteralCompare2(void) {386  return (6.14F == 7.14F); // no warning387}388 389int checkEqualFloatDeclCompare1(void) {390  float f = 7.1F;391  float g = 7.1F;392  return (f == g); // no warning393}394 395int checkEqualFloatDeclCompare12(void) {396  float f = 7.1F;397  return (f == f); // no warning398}399 400 401int checkEqualFloatDeclCompare3(void) {402  float f = 7.1F;403  return (f == 7.1F); // no warning404}405 406int checkEqualFloatDeclCompare4(void) {407  float f = 7.1F;408  return (7.1F == f); // no warning409}410 411int checkEqualFloatDeclCompare5(void) {412  float f = 7.1F;413  int t = 7;414  return (t == f); // no warning415}416 417int checkEqualFloatDeclCompare6(void) {418  float f = 7.1F;419  int t = 7;420  return (f == t); // no warning421}422 423 424 425 426int checkEqualCastFloatDeclCompare11(void) {427  float f = 7.1F;428  return ((int)f == (int)f);429// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:18: warning: both sides of operator are equivalent [misc-redundant-expression]430}431int checkEqualCastFloatDeclCompare12(void) {432  float f = 7.1F;433  return ((char)f == (int)f); // no warning434}435int checkEqualBinaryOpFloatCompare1(void) {436  int res;437  float f= 3.14F;438  res = (f + 3.14F == f + 3.14F);439// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:20: warning: both sides of operator are equivalent [misc-redundant-expression]440  return (0);441}442int checkEqualBinaryOpFloatCompare2(void) {443  float f = 7.1F;444  float g = 7.1F;445  return (f + 3.14F == g + 3.14F); // no warning446}447int checkEqualBinaryOpFloatCompare3(void) {448  int res;449  float f= 3.14F;450  res = ((int)f + 3.14F == (int)f + 3.14F);451// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:25: warning: both sides of operator are equivalent [misc-redundant-expression]452  return (0);453}454int checkEqualBinaryOpFloatCompare4(void) {455  int res;456  float f= 3.14F;457  res = ((int)f + 3.14F == (char)f + 3.14F);  // no warning458  return (0);459}460 461int checkEqualNestedBinaryOpFloatCompare1(void) {462  int res;463  int t= 1;464  int u= 2;465  float f= 3.14F;466  res = (((int)f + (3.14F - u)*t) == ((int)f + (3.14F - u)*t));467// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:35: warning: both sides of operator are equivalent [misc-redundant-expression]468  return (0);469}470 471int checkEqualNestedBinaryOpFloatCompare2(void) {472  int res;473  int t= 1;474  int u= 2;475  float f= 3.14F;476  res = (((int)f + (u - 3.14F)*t) == ((int)f + (3.14F - u)*t));  // no warning477  return (0);478}479 480int checkEqualNestedBinaryOpFloatCompare3(void) {481  int res;482  int t= 1;483  int u= 2;484  float f= 3.14F;485  res = (((int)f + (u - 3.14F)*t) == ((int)f + (3.14F - u)*(f + t == f + t)));486// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:67: warning: both sides of operator are equivalent [misc-redundant-expression]487  return (0);488}489 490/* Equal with int*/491 492int checkEqualIntLiteralCompare1(void) {493  return (5 == 5);494// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:13: warning: both sides of operator are equivalent [misc-redundant-expression]495}496 497int checkEqualIntLiteralCompare2(void) {498  return (6 == 7); // no warning499}500 501int checkEqualIntDeclCompare1(void) {502  int f = 7;503  int g = 7;504  return (f == g); // no warning505}506 507int checkEqualCastIntDeclCompare11(void) {508  int f = 7;509  return ((int)f == (int)f);510// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:18: warning: both sides of operator are equivalent [misc-redundant-expression]511}512int checkEqualCastIntDeclCompare12(void) {513  int f = 7;514  return ((char)f == (int)f); // no warning515}516 517int checkEqualIntDeclCompare3(void) {518  int f = 7;519  return (f == 7); // no warning520}521 522int checkEqualIntDeclCompare4(void) {523  int f = 7;524  return (7 == f); // no warning525}526 527int checkEqualBinaryOpIntCompare1(void) {528  int res;529  int t= 1;530  int u= 2;531  int f= 4;532  res = (f + 4 == f + 4);533// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:16: warning: both sides of operator are equivalent [misc-redundant-expression]534  return (0);535}536int checkEqualBinaryOpIntCompare2(void) {537  int f = 7;538  int g = 7;539  return (f + 4 == g + 4); // no warning540}541 542 543int checkEqualBinaryOpIntCompare3(void) {544  int res;545  int t= 1;546  int u= 2;547  int f= 4;548  res = ((int)f + 4 == (int)f + 4);549// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:21: warning: both sides of operator are equivalent [misc-redundant-expression]550  return (0);551 552}553int checkEqualBinaryOpIntCompare4(void) {554  int res;555  int t= 1;556  int u= 2;557  int f= 4;558  res = ((int)f + 4 == (char)f + 4);  // no warning559  return (0);560}561int checkEqualBinaryOpIntCompare5(void) {562  int res;563  int t= 1;564  int u= 2;565  res = (u + t == u + t);566// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:16: warning: both sides of operator are equivalent [misc-redundant-expression]567  return (0);568}569 570int checkEqualNestedBinaryOpIntCompare1(void) {571  int res;572  int t= 1;573  int u= 2;574  int f= 3;575  res = (((int)f + (3 - u)*t) == ((int)f + (3 - u)*t));576// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:31: warning: both sides of operator are equivalent [misc-redundant-expression]577  return (0);578}579 580int checkEqualNestedBinaryOpIntCompare2(void) {581  int res;582  int t= 1;583  int u= 2;584  int f= 3;585  res = (((int)f + (u - 3)*t) == ((int)f + (3 - u)*t));  // no warning586  return (0);587}588 589int checkEqualNestedBinaryOpIntCompare3(void) {590  int res;591  int t= 1;592  int u= 2;593  int f= 3;594  res = (((int)f + (u - 3)*t) == ((int)f + (3 - u)*(t + 1 == t + 1)));595// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:59: warning: both sides of operator are equivalent [misc-redundant-expression]596  return (0);597}598 599/* '==' with function*/600 601int checkEqualSameFunction() {602  unsigned a = 0;603  unsigned b = 1;604  int res = (a+func() == a+func());605// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:23: warning: both sides of operator are equivalent [misc-redundant-expression]606  return (0);607}608 609int checkEqualDifferentFunction() {610  unsigned a = 0;611  unsigned b = 1;612  int res = (a+func() == a+func2());  // no warning613  return (0);614}615 616int checkEqualSameFunctionSameParam() {617  unsigned a = 0;618  unsigned b = 1;619  int res = (a+funcParam(a) == a+funcParam(a));620// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:29: warning: both sides of operator are equivalent [misc-redundant-expression]621  return (0);622}623 624int checkEqualSameFunctionDifferentParam() {625  unsigned a = 0;626  unsigned b = 1;627  int res = (a+funcParam(a) == a+funcParam(b));  // no warning628  return (0);629}630 631/*   end '==' with function*/632 633/*   end EQ int          */634 635/* end EQ */636 637 638/*  LT */639 640/*  LT with float */641 642int checkLessThanFloatLiteralCompare1(void) {643  return (5.14F < 5.14F);644// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:17: warning: both sides of operator are equivalent [misc-redundant-expression]645}646 647int checkLessThanFloatLiteralCompare2(void) {648  return (6.14F < 7.14F); // no warning649}650 651int checkLessThanFloatDeclCompare1(void) {652  float f = 7.1F;653  float g = 7.1F;654  return (f < g); // no warning655}656 657int checkLessThanFloatDeclCompare12(void) {658  float f = 7.1F;659  return (f < f);660// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:13: warning: both sides of operator are equivalent [misc-redundant-expression]661}662 663int checkLessThanFloatDeclCompare3(void) {664  float f = 7.1F;665  return (f < 7.1F); // no warning666}667 668int checkLessThanFloatDeclCompare4(void) {669  float f = 7.1F;670  return (7.1F < f); // no warning671}672 673int checkLessThanFloatDeclCompare5(void) {674  float f = 7.1F;675  int t = 7;676  return (t < f); // no warning677}678 679int checkLessThanFloatDeclCompare6(void) {680  float f = 7.1F;681  int t = 7;682  return (f < t); // no warning683}684 685 686int checkLessThanCastFloatDeclCompare11(void) {687  float f = 7.1F;688  return ((int)f < (int)f);689// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:18: warning: both sides of operator are equivalent [misc-redundant-expression]690}691int checkLessThanCastFloatDeclCompare12(void) {692  float f = 7.1F;693  return ((char)f < (int)f); // no warning694}695int checkLessThanBinaryOpFloatCompare1(void) {696  int res;697  float f= 3.14F;698  res = (f + 3.14F < f + 3.14F);699// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:20: warning: both sides of operator are equivalent [misc-redundant-expression]700  return (0);701}702int checkLessThanBinaryOpFloatCompare2(void) {703  float f = 7.1F;704  float g = 7.1F;705  return (f + 3.14F < g + 3.14F); // no warning706}707int checkLessThanBinaryOpFloatCompare3(void) {708  int res;709  float f= 3.14F;710  res = ((int)f + 3.14F < (int)f + 3.14F);711// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:25: warning: both sides of operator are equivalent [misc-redundant-expression]712  return (0);713}714int checkLessThanBinaryOpFloatCompare4(void) {715  int res;716  float f= 3.14F;717  res = ((int)f + 3.14F < (char)f + 3.14F);  // no warning718  return (0);719}720 721int checkLessThanNestedBinaryOpFloatCompare1(void) {722  int res;723  int t= 1;724  int u= 2;725  float f= 3.14F;726  res = (((int)f + (3.14F - u)*t) < ((int)f + (3.14F - u)*t));727// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:35: warning: both sides of operator are equivalent [misc-redundant-expression]728  return (0);729}730 731int checkLessThanNestedBinaryOpFloatCompare2(void) {732  int res;733  int t= 1;734  int u= 2;735  float f= 3.14F;736  res = (((int)f + (u - 3.14F)*t) < ((int)f + (3.14F - u)*t));  // no warning737  return (0);738}739 740int checkLessThanNestedBinaryOpFloatCompare3(void) {741  int res;742  int t= 1;743  int u= 2;744  float f= 3.14F;745  res = (((int)f + (u - 3.14F)*t) < ((int)f + (3.14F - u)*(f + t < f + t)));746// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:66: warning: both sides of operator are equivalent [misc-redundant-expression]747  return (0);748}749 750/*  end LT with float */751 752/*  LT with int */753 754 755int checkLessThanIntLiteralCompare1(void) {756  return (5 < 5);757// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:13: warning: both sides of operator are equivalent [misc-redundant-expression]758}759 760int checkLessThanIntLiteralCompare2(void) {761  return (6 < 7); // no warning762}763 764int checkLessThanIntDeclCompare1(void) {765  int f = 7;766  int g = 7;767  return (f < g); // no warning768}769 770int checkLessThanIntDeclCompare3(void) {771  int f = 7;772  return (f < 7); // no warning773}774 775int checkLessThanIntDeclCompare4(void) {776  int f = 7;777  return (7 < f); // no warning778}779 780int checkLessThanIntDeclCompare5(void) {781  int f = 7;782  int t = 7;783  return (t < f); // no warning784}785 786int checkLessThanIntDeclCompare6(void) {787  int f = 7;788  int t = 7;789  return (f < t); // no warning790}791 792int checkLessThanCastIntDeclCompare11(void) {793  int f = 7;794  return ((int)f < (int)f);795// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:18: warning: both sides of operator are equivalent [misc-redundant-expression]796}797int checkLessThanCastIntDeclCompare12(void) {798  int f = 7;799  return ((char)f < (int)f); // no warning800}801int checkLessThanBinaryOpIntCompare1(void) {802  int res;803  int f= 3;804  res = (f + 3 < f + 3);805// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:16: warning: both sides of operator are equivalent [misc-redundant-expression]806  return (0);807}808int checkLessThanBinaryOpIntCompare2(void) {809  int f = 7;810  int g = 7;811  return (f + 3 < g + 3); // no warning812}813int checkLessThanBinaryOpIntCompare3(void) {814  int res;815  int f= 3;816  res = ((int)f + 3 < (int)f + 3);817// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:21: warning: both sides of operator are equivalent [misc-redundant-expression]818  return (0);819}820int checkLessThanBinaryOpIntCompare4(void) {821  int res;822  int f= 3;823  res = ((int)f + 3 < (char)f + 3);  // no warning824  return (0);825}826 827int checkLessThanNestedBinaryOpIntCompare1(void) {828  int res;829  int t= 1;830  int u= 2;831  int f= 3;832  res = (((int)f + (3 - u)*t) < ((int)f + (3 - u)*t));833// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:31: warning: both sides of operator are equivalent [misc-redundant-expression]834  return (0);835}836 837int checkLessThanNestedBinaryOpIntCompare2(void) {838  int res;839  int t= 1;840  int u= 2;841  int f= 3;842  res = (((int)f + (u - 3)*t) < ((int)f + (3 - u)*t));  // no warning843  return (0);844}845 846int checkLessThanNestedBinaryOpIntCompare3(void) {847  int res;848  int t= 1;849  int u= 2;850  int f= 3;851  res = (((int)f + (u - 3)*t) < ((int)f + (3 - u)*(t + u < t + u)));852// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:58: warning: both sides of operator are equivalent [misc-redundant-expression]853  return (0);854}855 856/* end LT with int */857 858/* end LT */859 860 861/* GT */862 863/* GT with float */864 865int checkGreaterThanFloatLiteralCompare1(void) {866  return (5.14F > 5.14F);867// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:17: warning: both sides of operator are equivalent [misc-redundant-expression]868}869 870int checkGreaterThanFloatLiteralCompare2(void) {871  return (6.14F > 7.14F); // no warning872}873 874int checkGreaterThanFloatDeclCompare1(void) {875  float f = 7.1F;876  float g = 7.1F;877 878  return (f > g); // no warning879}880 881int checkGreaterThanFloatDeclCompare12(void) {882  float f = 7.1F;883  return (f > f);884// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:13: warning: both sides of operator are equivalent [misc-redundant-expression]885}886 887 888int checkGreaterThanFloatDeclCompare3(void) {889  float f = 7.1F;890  return (f > 7.1F); // no warning891}892 893int checkGreaterThanFloatDeclCompare4(void) {894  float f = 7.1F;895  return (7.1F > f); // no warning896}897 898int checkGreaterThanFloatDeclCompare5(void) {899  float f = 7.1F;900  int t = 7;901  return (t > f); // no warning902}903 904int checkGreaterThanFloatDeclCompare6(void) {905  float f = 7.1F;906  int t = 7;907  return (f > t); // no warning908}909 910int checkGreaterThanCastFloatDeclCompare11(void) {911  float f = 7.1F;912  return ((int)f > (int)f);913// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:18: warning: both sides of operator are equivalent [misc-redundant-expression]914}915int checkGreaterThanCastFloatDeclCompare12(void) {916  float f = 7.1F;917  return ((char)f > (int)f); // no warning918}919int checkGreaterThanBinaryOpFloatCompare1(void) {920  int res;921  float f= 3.14F;922  res = (f + 3.14F > f + 3.14F);923// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:20: warning: both sides of operator are equivalent [misc-redundant-expression]924  return (0);925}926int checkGreaterThanBinaryOpFloatCompare2(void) {927  float f = 7.1F;928  float g = 7.1F;929  return (f + 3.14F > g + 3.14F); // no warning930}931int checkGreaterThanBinaryOpFloatCompare3(void) {932  int res;933  float f= 3.14F;934  res = ((int)f + 3.14F > (int)f + 3.14F);935// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:25: warning: both sides of operator are equivalent [misc-redundant-expression]936  return (0);937}938int checkGreaterThanBinaryOpFloatCompare4(void) {939  int res;940  float f= 3.14F;941  res = ((int)f + 3.14F > (char)f + 3.14F);  // no warning942  return (0);943}944 945int checkGreaterThanNestedBinaryOpFloatCompare1(void) {946  int res;947  int t= 1;948  int u= 2;949  float f= 3.14F;950  res = (((int)f + (3.14F - u)*t) > ((int)f + (3.14F - u)*t));951// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:35: warning: both sides of operator are equivalent [misc-redundant-expression]952  return (0);953}954 955int checkGreaterThanNestedBinaryOpFloatCompare2(void) {956  int res;957  int t= 1;958  int u= 2;959  float f= 3.14F;960  res = (((int)f + (u - 3.14F)*t) > ((int)f + (3.14F - u)*t));  // no warning961  return (0);962}963 964int checkGreaterThanNestedBinaryOpFloatCompare3(void) {965  int res;966  int t= 1;967  int u= 2;968  float f= 3.14F;969  res = (((int)f + (u - 3.14F)*t) > ((int)f + (3.14F - u)*(f + t > f + t)));  // no warning970// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:66: warning: both sides of operator are equivalent [misc-redundant-expression]971  return (0);972}973 974/*  end GT with float */975 976/*  GT with int */977 978 979int checkGreaterThanIntLiteralCompare1(void) {980  return (5 > 5);981// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:13: warning: both sides of operator are equivalent [misc-redundant-expression]982}983 984int checkGreaterThanIntLiteralCompare2(void) {985  return (6 > 7); // no warning986}987 988int checkGreaterThanIntDeclCompare1(void) {989  int f = 7;990  int g = 7;991 992  return (f > g); // no warning993}994 995int checkGreaterThanIntDeclCompare3(void) {996  int f = 7;997  return (f > 7); // no warning998}999 1000int checkGreaterThanIntDeclCompare4(void) {1001  int f = 7;1002  return (7 > f); // no warning1003}1004 1005int checkGreaterThanCastIntDeclCompare11(void) {1006  int f = 7;1007  return ((int)f > (int)f);1008// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:18: warning: both sides of operator are equivalent [misc-redundant-expression]1009}1010int checkGreaterThanCastIntDeclCompare12(void) {1011  int f = 7;1012  return ((char)f > (int)f); // no warning1013}1014int checkGreaterThanBinaryOpIntCompare1(void) {1015  int res;1016  int f= 3;1017  res = (f + 3 > f + 3);1018// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:16: warning: both sides of operator are equivalent [misc-redundant-expression]1019  return (0);1020}1021int checkGreaterThanBinaryOpIntCompare2(void) {1022  int f = 7;1023  int g = 7;1024  return (f + 3 > g + 3); // no warning1025}1026int checkGreaterThanBinaryOpIntCompare3(void) {1027  int res;1028  int f= 3;1029  res = ((int)f + 3 > (int)f + 3);1030// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:21: warning: both sides of operator are equivalent [misc-redundant-expression]1031  return (0);1032}1033int checkGreaterThanBinaryOpIntCompare4(void) {1034  int res;1035  int f= 3;1036  res = ((int)f + 3 > (char)f + 3);  // no warning1037  return (0);1038}1039 1040int checkGreaterThanNestedBinaryOpIntCompare1(void) {1041  int res;1042  int t= 1;1043  int u= 2;1044  int f= 3;1045  res = (((int)f + (3 - u)*t) > ((int)f + (3 - u)*t));1046// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:31: warning: both sides of operator are equivalent [misc-redundant-expression]1047  return (0);1048}1049 1050int checkGreaterThanNestedBinaryOpIntCompare2(void) {1051  int res;1052  int t= 1;1053  int u= 2;1054  int f= 3;1055  res = (((int)f + (u - 3)*t) > ((int)f + (3 - u)*t));  // no warning1056  return (0);1057}1058 1059int checkGreaterThanNestedBinaryOpIntCompare3(void) {1060  int res;1061  int t= 1;1062  int u= 2;1063  int f= 3;1064  res = (((int)f + (u - 3)*t) > ((int)f + (3 - u)*(t + u > t + u)));1065// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:58: warning: both sides of operator are equivalent [misc-redundant-expression]1066  return (0);1067}1068 1069/* end GT with int */1070 1071/* end GT */1072 1073 1074/* Checking use of identical expressions in conditional operator*/1075 1076unsigned test_unsigned(unsigned a) {1077  unsigned b = 1;1078  a = a > 5 ? b : b;1079// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:17: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]1080  return a;1081}1082 1083void test_signed() {1084  int a = 0;1085  a = a > 5 ? a : a;1086// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:17: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]1087}1088 1089void test_bool(bool a) {1090  a = a > 0 ? a : a;1091// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:17: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]1092}1093 1094void test_float() {1095  float a = 0;1096  float b = 0;1097  a = a > 5 ? a : a;1098// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:17: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]1099}1100 1101const char *test_string() {1102  float a = 0;1103  return a > 5 ? "abc" : "abc";1104// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:24: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]1105}1106 1107void test_unsigned_expr() {1108  unsigned a = 0;1109  unsigned b = 0;1110  a = a > 5 ? a+b : a+b;1111// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:19: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]1112}1113 1114void test_signed_expr() {1115  int a = 0;1116  int b = 1;1117  a = a > 5 ? a+b : a+b;1118// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:19: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]1119}1120 1121void test_bool_expr(bool a) {1122  bool b = 0;1123  a = a > 0 ? a&&b : a&&b;1124// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:20: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]1125}1126 1127void test_unsigned_expr_negative() {1128  unsigned a = 0;1129  unsigned b = 0;1130  a = a > 5 ? a+b : b+a; // no warning1131}1132 1133void test_signed_expr_negative() {1134  int a = 0;1135  int b = 1;1136  a = a > 5 ? b+a : a+b; // no warning1137}1138 1139void test_bool_expr_negative(bool a) {1140  bool b = 0;1141  a = a > 0 ? a&&b : b&&a; // no warning1142}1143 1144void test_float_expr_positive() {1145  float a = 0;1146  float b = 0;1147  a = a > 5 ? a+b : a+b;1148// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:19: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]1149}1150 1151void test_expr_positive_func() {1152  unsigned a = 0;1153  unsigned b = 1;1154  a = a > 5 ? a+func() : a+func();1155// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:24: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]1156}1157 1158void test_expr_negative_func() {1159  unsigned a = 0;1160  unsigned b = 1;1161  a = a > 5 ? a+func() : a+func2(); // no warning1162}1163 1164void test_expr_positive_funcParam() {1165  unsigned a = 0;1166  unsigned b = 1;1167  a = a > 5 ? a+funcParam(b) : a+funcParam(b);1168// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:30: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]1169}1170 1171void test_expr_negative_funcParam() {1172  unsigned a = 0;1173  unsigned b = 1;1174  a = a > 5 ? a+funcParam(a) : a+funcParam(b); // no warning1175}1176 1177void test_expr_negative_inc() {1178  unsigned a = 0;1179  unsigned b = 1;1180  a = a > 5 ? a++ : b++; // no warning1181}1182 1183void test_expr_negative_assign() {1184  unsigned a = 0;1185  unsigned b = 1;1186  a = a > 5 ? a=1 : a=2; // no warning1187}1188 1189void test_signed_nested_expr() {1190  int a = 0;1191  int b = 1;1192  int c = 3;1193  a = a > 5 ? a+b+(c+a)*(a + b*(c+a)) : a+b+(c+a)*(a + b*(c+a));1194// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:39: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]1195}1196 1197void test_signed_nested_expr_negative() {1198  int a = 0;1199  int b = 1;1200  int c = 3;1201  a = a > 5 ? a+b+(c+a)*(a + b*(c+a)) : a+b+(c+a)*(a + b*(a+c)); // no warning1202}1203 1204void test_signed_nested_cond_expr_negative() {1205  int a = 0;1206  int b = 1;1207  int c = 3;1208  a = a > 5 ? (b > 5 ? 1 : 4) : (b > 5 ? 2 : 4); // no warning1209}1210 1211void test_signed_nested_cond_expr() {1212  int a = 0;1213  int b = 1;1214  int c = 3;1215  a = a > 5 ? (b > 5 ? 1 : 4) : (b > 5 ? 4 : 4);1216// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:44: warning: 'true' and 'false' expressions are equivalent [misc-redundant-expression]1217}1218 1219void test_identical_bitwise1() {1220  int a = 5 | 5;1221// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:13: warning: both sides of operator are equivalent [misc-redundant-expression]1222}1223 1224void test_identical_bitwise2() {1225  int a = 5;1226  int b = a | a;1227// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:13: warning: both sides of operator are equivalent [misc-redundant-expression]1228}1229 1230void test_identical_bitwise3() {1231  int a = 5;1232  int b = (a | a);1233// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:14: warning: both sides of operator are equivalent [misc-redundant-expression]1234}1235 1236void test_identical_bitwise4() {1237  int a = 4;1238  int b = a | 4; // no-warning1239}1240 1241void test_identical_bitwise5() {1242  int a = 4;1243  int b = 4;1244  int c = a | b; // no-warning1245}1246 1247void test_identical_bitwise6() {1248  int a = 5;1249  int b = a | 4 | a;1250// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:17: warning: operator has equivalent nested operands [misc-redundant-expression]1251}1252 1253void test_identical_bitwise7() {1254  int a = 5;1255  int b = func() | func();1256// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:18: warning: both sides of operator are equivalent [misc-redundant-expression]1257}1258 1259void test_identical_logical1(int a) {1260  if (a == 4 && a == 4)1261// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:14: warning: both sides of operator are equivalent [misc-redundant-expression]1262    ;1263}1264 1265void test_identical_logical2(int a) {1266  if (a == 4 || a == 5 || a == 4)1267// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:24: warning: operator has equivalent nested operands [misc-redundant-expression]1268    ;1269}1270 1271void test_identical_logical3(int a) {1272  if (a == 4 || a == 5 || a == 6) // no-warning1273    ;1274}1275 1276void test_identical_logical4(int a) {1277  if (a == func() || a == func())1278// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:19: warning: both sides of operator are equivalent [misc-redundant-expression]1279    ;1280}1281 1282#pragma clang diagnostic push1283#pragma clang diagnostic ignored "-Wlogical-op-parentheses"1284void test_identical_logical5(int x, int y) {1285  if (x == 4 && y == 5 || x == 4 && y == 6) // no-warning1286    ;1287}1288 1289void test_identical_logical6(int x, int y) {1290  if (x == 4 && y == 5 || x == 4 && y == 5)1291// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:24: warning: both sides of operator are equivalent [misc-redundant-expression]1292    ;1293}1294 1295void test_identical_logical7(int x, int y) {1296  // FIXME: We should warn here1297  if (x == 4 && y == 5 || x == 4)1298    ;1299}1300 1301void test_identical_logical8(int x, int y) {1302  // FIXME: We should warn here1303  if (x == 4 || y == 5 && x == 4)1304    ;1305}1306 1307void test_identical_logical9(int x, int y) {1308  // FIXME: We should warn here1309  if (x == 4 || x == 4 && y == 5)1310    ;1311}1312#pragma clang diagnostic pop1313