identical-expressions.cpp revision 9a7a568821b85cc83b80056268ef0dc32aecea12
1// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core.IdenticalExpr -verify %s 2 3/* Only one expected warning per function allowed at the very end. */ 4 5/* '!=' operator*/ 6 7/* '!=' with float */ 8int checkNotEqualFloatLiteralCompare1(void) { 9 return (5.14F != 5.14F); // no warning 10} 11 12int checkNotEqualFloatLiteralCompare2(void) { 13 return (6.14F != 7.14F); // no warning 14} 15 16int checkNotEqualFloatDeclCompare1(void) { 17 float f = 7.1F; 18 float g = 7.1F; 19 return (f != g); // no warning 20} 21 22int checkNotEqualFloatDeclCompare12(void) { 23 float f = 7.1F; 24 return (f != f); // no warning 25} 26 27int checkNotEqualFloatDeclCompare3(void) { 28 float f = 7.1F; 29 return (f != 7.1F); // no warning 30} 31 32int checkNotEqualFloatDeclCompare4(void) { 33 float f = 7.1F; 34 return (7.1F != f); // no warning 35} 36 37int checkNotEqualFloatDeclCompare5(void) { 38 float f = 7.1F; 39 int t = 7; 40 return (t != f); // no warning 41} 42 43int checkNotEqualFloatDeclCompare6(void) { 44 float f = 7.1F; 45 int t = 7; 46 return (f != t); // no warning 47} 48 49 50 51int checkNotEqualCastFloatDeclCompare11(void) { 52 float f = 7.1F; 53 return ((int)f != (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}} 54} 55int checkNotEqualCastFloatDeclCompare12(void) { 56 float f = 7.1F; 57 return ((char)f != (int)f); // no warning 58} 59int checkNotEqualBinaryOpFloatCompare1(void) { 60 int res; 61 float f= 3.14F; 62 res = (f + 3.14F != f + 3.14F); // no warning 63 return (0); 64} 65int checkNotEqualBinaryOpFloatCompare2(void) { 66 float f = 7.1F; 67 float g = 7.1F; 68 return (f + 3.14F != g + 3.14F); // no warning 69} 70int checkNotEqualBinaryOpFloatCompare3(void) { 71 int res; 72 float f= 3.14F; 73 res = ((int)f + 3.14F != (int)f + 3.14F); // no warning 74 return (0); 75} 76int checkNotEqualBinaryOpFloatCompare4(void) { 77 int res; 78 float f= 3.14F; 79 res = ((int)f + 3.14F != (char)f + 3.14F); // no warning 80 return (0); 81} 82 83int checkNotEqualNestedBinaryOpFloatCompare1(void) { 84 int res; 85 int t= 1; 86 int u= 2; 87 float f= 3.14F; 88 res = (((int)f + (3.14F - u)*t) != ((int)f + (3.14F - u)*t)); // no warning 89 return (0); 90} 91 92int checkNotEqualNestedBinaryOpFloatCompare2(void) { 93 int res; 94 int t= 1; 95 int u= 2; 96 float f= 3.14F; 97 res = (((int)f + (u - 3.14F)*t) != ((int)f + (3.14F - u)*t)); // no warning 98 return (0); 99} 100 101int checkNotEqualNestedBinaryOpFloatCompare3(void) { 102 int res; 103 int t= 1; 104 int u= 2; 105 float f= 3.14F; 106 res = (((int)f + (u - 3.14F)*t) != ((int)f + (3.14F - u)*(f + t != f + t))); // no warning 107 return (0); 108} 109 110 111 112 113/* end '!=' with float*/ 114 115/* '!=' with int*/ 116 117int checkNotEqualIntLiteralCompare1(void) { 118 return (5 != 5); // expected-warning {{comparison of identical expressions always evaluates to false}} 119} 120 121int checkNotEqualIntLiteralCompare2(void) { 122 return (6 != 7); // no warning 123} 124 125int checkNotEqualIntDeclCompare1(void) { 126 int f = 7; 127 int g = 7; 128 return (f != g); // no warning 129} 130 131int checkNotEqualIntDeclCompare3(void) { 132 int f = 7; 133 return (f != 7); // no warning 134} 135 136int checkNotEqualIntDeclCompare4(void) { 137 int f = 7; 138 return (7 != f); // no warning 139} 140 141int checkNotEqualCastIntDeclCompare11(void) { 142 int f = 7; 143 return ((int)f != (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}} 144} 145int checkNotEqualCastIntDeclCompare12(void) { 146 int f = 7; 147 return ((char)f != (int)f); // no warning 148} 149int checkNotEqualBinaryOpIntCompare1(void) { 150 int res; 151 int t= 1; 152 int u= 2; 153 int f= 4; 154 res = (f + 4 != f + 4); // expected-warning {{comparison of identical expressions always evaluates to false}} 155 return (0); 156} 157int checkNotEqualBinaryOpIntCompare2(void) { 158 int f = 7; 159 int g = 7; 160 return (f + 4 != g + 4); // no warning 161} 162 163 164int checkNotEqualBinaryOpIntCompare3(void) { 165 int res; 166 int t= 1; 167 int u= 2; 168 int f= 4; 169 res = ((int)f + 4 != (int)f + 4); // expected-warning {{comparison of identical expressions always evaluates to false}} 170 return (0); 171} 172int checkNotEqualBinaryOpIntCompare4(void) { 173 int res; 174 int t= 1; 175 int u= 2; 176 int f= 4; 177 res = ((int)f + 4 != (char)f + 4); // no warning 178 return (0); 179} 180int checkNotEqualBinaryOpIntCompare5(void) { 181 int res; 182 int t= 1; 183 int u= 2; 184 res = (u + t != u + t); // expected-warning {{comparison of identical expressions always evaluates to false}} 185 return (0); 186} 187 188int checkNotEqualNestedBinaryOpIntCompare1(void) { 189 int res; 190 int t= 1; 191 int u= 2; 192 int f= 3; 193 res = (((int)f + (3 - u)*t) != ((int)f + (3 - u)*t)); // expected-warning {{comparison of identical expressions always evaluates to false}} 194 return (0); 195} 196 197int checkNotEqualNestedBinaryOpIntCompare2(void) { 198 int res; 199 int t= 1; 200 int u= 2; 201 int f= 3; 202 res = (((int)f + (u - 3)*t) != ((int)f + (3 - u)*t)); // no warning 203 return (0); 204} 205 206int checkNotEqualNestedBinaryOpIntCompare3(void) { 207 int res; 208 int t= 1; 209 int u= 2; 210 int f= 3; 211 res = (((int)f + (u - 3)*t) != ((int)f + (3 - u)*(t + 1 != t + 1))); // expected-warning {{comparison of identical expressions always evaluates to false}} 212 return (0); 213} 214 215/* end '!=' int */ 216 217 218 219/* '!=' with int pointer */ 220 221int checkNotEqualIntPointerLiteralCompare1(void) { 222 int* p = 0; 223 return (p != 0); // no warning 224} 225 226int checkNotEqualIntPointerLiteralCompare2(void) { 227 return (6 != 7); // no warning 228} 229 230int checkNotEqualIntPointerDeclCompare1(void) { 231 int k = 3; 232 int* f = &k; 233 int* g = &k; 234 return (f != g); // no warning 235} 236 237int checkNotEqualCastIntPointerDeclCompare11(void) { 238 int k = 7; 239 int* f = &k; 240 return ((int*)f != (int*)f); // expected-warning {{comparison of identical expressions always evaluates to false}} 241} 242int checkNotEqualCastIntPointerDeclCompare12(void) { 243 int k = 7; 244 int* f = &k; 245 return ((int*)((char*)f) != (int*)f); // no warning 246} 247int checkNotEqualBinaryOpIntPointerCompare1(void) { 248 int k = 7; 249 int res; 250 int* f= &k; 251 res = (f + 4 != f + 4); // expected-warning {{comparison of identical expressions always evaluates to false}} 252 return (0); 253} 254int checkNotEqualBinaryOpIntPointerCompare2(void) { 255 int k = 7; 256 int* f = &k; 257 int* g = &k; 258 return (f + 4 != g + 4); // no warning 259} 260 261 262int checkNotEqualBinaryOpIntPointerCompare3(void) { 263 int k = 7; 264 int res; 265 int* f= &k; 266 res = ((int*)f + 4 != (int*)f + 4); // expected-warning {{comparison of identical expressions always evaluates to false}} 267 return (0); 268} 269int checkNotEqualBinaryOpIntPointerCompare4(void) { 270 int k = 7; 271 int res; 272 int* f= &k; 273 res = ((int*)f + 4 != (int*)((char*)f) + 4); // no warning 274 return (0); 275} 276 277int checkNotEqualNestedBinaryOpIntPointerCompare1(void) { 278 int res; 279 int k = 7; 280 int t= 1; 281 int* u= &k+2; 282 int* f= &k+3; 283 res = ((f + (3)*t) != (f + (3)*t)); // expected-warning {{comparison of identical expressions always evaluates to false}} 284 return (0); 285} 286 287int checkNotEqualNestedBinaryOpIntPointerCompare2(void) { 288 int res; 289 int k = 7; 290 int t= 1; 291 int* u= &k+2; 292 int* f= &k+3; 293 res = (((3)*t + f) != (f + (3)*t)); // no warning 294 return (0); 295} 296/* end '!=' int* */ 297 298/* end '!=' */ 299 300 301 302/* EQ operator */ 303 304int checkEqualIntPointerDeclCompare(void) { 305 int k = 3; 306 int* f = &k; 307 int* g = &k; 308 return (f == g); // no warning 309} 310 311int checkEqualIntPointerDeclCompare0(void) { 312 int k = 3; 313 int* f = &k; 314 return (f+1 == f+1); // expected-warning {{comparison of identical expressions always evaluates to true}} 315} 316 317/* EQ with float*/ 318 319int checkEqualFloatLiteralCompare1(void) { 320 return (5.14F == 5.14F); // no warning 321} 322 323int checkEqualFloatLiteralCompare2(void) { 324 return (6.14F == 7.14F); // no warning 325} 326 327int checkEqualFloatDeclCompare1(void) { 328 float f = 7.1F; 329 float g = 7.1F; 330 return (f == g); // no warning 331} 332 333int checkEqualFloatDeclCompare12(void) { 334 float f = 7.1F; 335 return (f == f); // no warning 336} 337 338 339int checkEqualFloatDeclCompare3(void) { 340 float f = 7.1F; 341 return (f == 7.1F); // no warning 342} 343 344int checkEqualFloatDeclCompare4(void) { 345 float f = 7.1F; 346 return (7.1F == f); // no warning 347} 348 349int checkEqualFloatDeclCompare5(void) { 350 float f = 7.1F; 351 int t = 7; 352 return (t == f); // no warning 353} 354 355int checkEqualFloatDeclCompare6(void) { 356 float f = 7.1F; 357 int t = 7; 358 return (f == t); // no warning 359} 360 361 362 363 364int checkEqualCastFloatDeclCompare11(void) { 365 float f = 7.1F; 366 return ((int)f == (int)f); // expected-warning {{comparison of identical expressions always evaluates to true}} 367} 368int checkEqualCastFloatDeclCompare12(void) { 369 float f = 7.1F; 370 return ((char)f == (int)f); // no warning 371} 372int checkEqualBinaryOpFloatCompare1(void) { 373 int res; 374 float f= 3.14F; 375 res = (f + 3.14F == f + 3.14F); // no warning 376 return (0); 377} 378int checkEqualBinaryOpFloatCompare2(void) { 379 float f = 7.1F; 380 float g = 7.1F; 381 return (f + 3.14F == g + 3.14F); // no warning 382} 383int checkEqualBinaryOpFloatCompare3(void) { 384 int res; 385 float f= 3.14F; 386 res = ((int)f + 3.14F == (int)f + 3.14F); // no warning 387 return (0); 388} 389int checkEqualBinaryOpFloatCompare4(void) { 390 int res; 391 float f= 3.14F; 392 res = ((int)f + 3.14F == (char)f + 3.14F); // no warning 393 return (0); 394} 395 396int checkEqualNestedBinaryOpFloatCompare1(void) { 397 int res; 398 int t= 1; 399 int u= 2; 400 float f= 3.14F; 401 res = (((int)f + (3.14F - u)*t) == ((int)f + (3.14F - u)*t)); // no warning 402 return (0); 403} 404 405int checkEqualNestedBinaryOpFloatCompare2(void) { 406 int res; 407 int t= 1; 408 int u= 2; 409 float f= 3.14F; 410 res = (((int)f + (u - 3.14F)*t) == ((int)f + (3.14F - u)*t)); // no warning 411 return (0); 412} 413 414int checkEqualNestedBinaryOpFloatCompare3(void) { 415 int res; 416 int t= 1; 417 int u= 2; 418 float f= 3.14F; 419 res = (((int)f + (u - 3.14F)*t) == ((int)f + (3.14F - u)*(f + t == f + t))); // no warning 420 return (0); 421} 422 423 424 425 426 427/* Equal with int*/ 428 429int checkEqualIntLiteralCompare1(void) { 430 return (5 == 5); // expected-warning {{comparison of identical expressions always evaluates to true}} 431} 432 433int checkEqualIntLiteralCompare2(void) { 434 return (6 == 7); // no warning 435} 436 437int checkEqualIntDeclCompare1(void) { 438 int f = 7; 439 int g = 7; 440 return (f == g); // no warning 441} 442 443int checkEqualCastIntDeclCompare11(void) { 444 int f = 7; 445 return ((int)f == (int)f); // expected-warning {{comparison of identical expressions always evaluates to true}} 446} 447int checkEqualCastIntDeclCompare12(void) { 448 int f = 7; 449 return ((char)f == (int)f); // no warning 450} 451 452int checkEqualIntDeclCompare3(void) { 453 int f = 7; 454 return (f == 7); // no warning 455} 456 457int checkEqualIntDeclCompare4(void) { 458 int f = 7; 459 return (7 == f); // no warning 460} 461 462int checkEqualBinaryOpIntCompare1(void) { 463 int res; 464 int t= 1; 465 int u= 2; 466 int f= 4; 467 res = (f + 4 == f + 4); // expected-warning {{comparison of identical expressions always evaluates to true}} 468 return (0); 469} 470int checkEqualBinaryOpIntCompare2(void) { 471 int f = 7; 472 int g = 7; 473 return (f + 4 == g + 4); // no warning 474} 475 476 477int checkEqualBinaryOpIntCompare3(void) { 478 int res; 479 int t= 1; 480 int u= 2; 481 int f= 4; 482 res = ((int)f + 4 == (int)f + 4); // expected-warning {{comparison of identical expressions always evaluates to true}} 483 return (0); 484 485} 486int checkEqualBinaryOpIntCompare4(void) { 487 int res; 488 int t= 1; 489 int u= 2; 490 int f= 4; 491 res = ((int)f + 4 == (char)f + 4); // no warning 492 return (0); 493} 494int checkEqualBinaryOpIntCompare5(void) { 495 int res; 496 int t= 1; 497 int u= 2; 498 res = (u + t == u + t); // expected-warning {{comparison of identical expressions always evaluates to true}} 499 return (0); 500} 501 502int checkEqualNestedBinaryOpIntCompare1(void) { 503 int res; 504 int t= 1; 505 int u= 2; 506 int f= 3; 507 res = (((int)f + (3 - u)*t) == ((int)f + (3 - u)*t)); // expected-warning {{comparison of identical expressions always evaluates to true}} 508 return (0); 509} 510 511int checkEqualNestedBinaryOpIntCompare2(void) { 512 int res; 513 int t= 1; 514 int u= 2; 515 int f= 3; 516 res = (((int)f + (u - 3)*t) == ((int)f + (3 - u)*t)); // no warning 517 return (0); 518} 519 520int checkEqualNestedBinaryOpIntCompare3(void) { 521 int res; 522 int t= 1; 523 int u= 2; 524 int f= 3; 525 res = (((int)f + (u - 3)*t) == ((int)f + (3 - u)*(t + 1 == t + 1))); // expected-warning {{comparison of identical expressions always evaluates to true}} 526 return (0); 527} 528 529 530/* end EQ int */ 531 532/* end EQ */ 533 534 535/* LT */ 536 537/* LT with float */ 538 539int checkLessThanFloatLiteralCompare1(void) { 540 return (5.14F < 5.14F); // expected-warning {{comparison of identical expressions always evaluates to false}} 541} 542 543int checkLessThanFloatLiteralCompare2(void) { 544 return (6.14F < 7.14F); // no warning 545} 546 547int checkLessThanFloatDeclCompare1(void) { 548 float f = 7.1F; 549 float g = 7.1F; 550 return (f < g); // no warning 551} 552 553int checkLessThanFloatDeclCompare12(void) { 554 float f = 7.1F; 555 return (f < f); // expected-warning {{comparison of identical expressions always evaluates to false}} 556} 557 558int checkLessThanFloatDeclCompare3(void) { 559 float f = 7.1F; 560 return (f < 7.1F); // no warning 561} 562 563int checkLessThanFloatDeclCompare4(void) { 564 float f = 7.1F; 565 return (7.1F < f); // no warning 566} 567 568int checkLessThanFloatDeclCompare5(void) { 569 float f = 7.1F; 570 int t = 7; 571 return (t < f); // no warning 572} 573 574int checkLessThanFloatDeclCompare6(void) { 575 float f = 7.1F; 576 int t = 7; 577 return (f < t); // no warning 578} 579 580 581int checkLessThanCastFloatDeclCompare11(void) { 582 float f = 7.1F; 583 return ((int)f < (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}} 584} 585int checkLessThanCastFloatDeclCompare12(void) { 586 float f = 7.1F; 587 return ((char)f < (int)f); // no warning 588} 589int checkLessThanBinaryOpFloatCompare1(void) { 590 int res; 591 float f= 3.14F; 592 res = (f + 3.14F < f + 3.14F); // no warning 593 return (0); 594} 595int checkLessThanBinaryOpFloatCompare2(void) { 596 float f = 7.1F; 597 float g = 7.1F; 598 return (f + 3.14F < g + 3.14F); // no warning 599} 600int checkLessThanBinaryOpFloatCompare3(void) { 601 int res; 602 float f= 3.14F; 603 res = ((int)f + 3.14F < (int)f + 3.14F); // no warning 604 return (0); 605} 606int checkLessThanBinaryOpFloatCompare4(void) { 607 int res; 608 float f= 3.14F; 609 res = ((int)f + 3.14F < (char)f + 3.14F); // no warning 610 return (0); 611} 612 613int checkLessThanNestedBinaryOpFloatCompare1(void) { 614 int res; 615 int t= 1; 616 int u= 2; 617 float f= 3.14F; 618 res = (((int)f + (3.14F - u)*t) < ((int)f + (3.14F - u)*t)); // no warning 619 return (0); 620} 621 622int checkLessThanNestedBinaryOpFloatCompare2(void) { 623 int res; 624 int t= 1; 625 int u= 2; 626 float f= 3.14F; 627 res = (((int)f + (u - 3.14F)*t) < ((int)f + (3.14F - u)*t)); // no warning 628 return (0); 629} 630 631int checkLessThanNestedBinaryOpFloatCompare3(void) { 632 int res; 633 int t= 1; 634 int u= 2; 635 float f= 3.14F; 636 res = (((int)f + (u - 3.14F)*t) < ((int)f + (3.14F - u)*(f + t < f + t))); // no warning 637 return (0); 638} 639 640/* end LT with float */ 641 642/* LT with int */ 643 644 645int checkLessThanIntLiteralCompare1(void) { 646 return (5 < 5); // expected-warning {{comparison of identical expressions always evaluates to false}} 647} 648 649int checkLessThanIntLiteralCompare2(void) { 650 return (6 < 7); // no warning 651} 652 653int checkLessThanIntDeclCompare1(void) { 654 int f = 7; 655 int g = 7; 656 return (f < g); // no warning 657} 658 659int checkLessThanIntDeclCompare3(void) { 660 int f = 7; 661 return (f < 7); // no warning 662} 663 664int checkLessThanIntDeclCompare4(void) { 665 int f = 7; 666 return (7 < f); // no warning 667} 668 669int checkLessThanIntDeclCompare5(void) { 670 int f = 7; 671 int t = 7; 672 return (t < f); // no warning 673} 674 675int checkLessThanIntDeclCompare6(void) { 676 int f = 7; 677 int t = 7; 678 return (f < t); // no warning 679} 680 681int checkLessThanCastIntDeclCompare11(void) { 682 int f = 7; 683 return ((int)f < (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}} 684} 685int checkLessThanCastIntDeclCompare12(void) { 686 int f = 7; 687 return ((char)f < (int)f); // no warning 688} 689int checkLessThanBinaryOpIntCompare1(void) { 690 int res; 691 int f= 3; 692 res = (f + 3 < f + 3); // expected-warning {{comparison of identical expressions always evaluates to false}} 693 return (0); 694} 695int checkLessThanBinaryOpIntCompare2(void) { 696 int f = 7; 697 int g = 7; 698 return (f + 3 < g + 3); // no warning 699} 700int checkLessThanBinaryOpIntCompare3(void) { 701 int res; 702 int f= 3; 703 res = ((int)f + 3 < (int)f + 3); // expected-warning {{comparison of identical expressions always evaluates to false}} 704 return (0); 705} 706int checkLessThanBinaryOpIntCompare4(void) { 707 int res; 708 int f= 3; 709 res = ((int)f + 3 < (char)f + 3); // no warning 710 return (0); 711} 712 713int checkLessThanNestedBinaryOpIntCompare1(void) { 714 int res; 715 int t= 1; 716 int u= 2; 717 int f= 3; 718 res = (((int)f + (3 - u)*t) < ((int)f + (3 - u)*t)); // expected-warning {{comparison of identical expressions always evaluates to false}} 719 return (0); 720} 721 722int checkLessThanNestedBinaryOpIntCompare2(void) { 723 int res; 724 int t= 1; 725 int u= 2; 726 int f= 3; 727 res = (((int)f + (u - 3)*t) < ((int)f + (3 - u)*t)); // no warning 728 return (0); 729} 730 731int checkLessThanNestedBinaryOpIntCompare3(void) { 732 int res; 733 int t= 1; 734 int u= 2; 735 int f= 3; 736 res = (((int)f + (u - 3)*t) < ((int)f + (3 - u)*(t + u < t + u))); // expected-warning {{comparison of identical expressions always evaluates to false}} 737 return (0); 738} 739 740/* end LT with int */ 741 742/* end LT */ 743 744 745/* GT */ 746 747/* GT with float */ 748 749int checkGreaterThanFloatLiteralCompare1(void) { 750 return (5.14F > 5.14F); // expected-warning {{comparison of identical expressions always evaluates to false}} 751} 752 753int checkGreaterThanFloatLiteralCompare2(void) { 754 return (6.14F > 7.14F); // no warning 755} 756 757int checkGreaterThanFloatDeclCompare1(void) { 758 float f = 7.1F; 759 float g = 7.1F; 760 761 return (f > g); // no warning 762} 763 764int checkGreaterThanFloatDeclCompare12(void) { 765 float f = 7.1F; 766 return (f > f); // expected-warning {{comparison of identical expressions always evaluates to false}} 767} 768 769 770int checkGreaterThanFloatDeclCompare3(void) { 771 float f = 7.1F; 772 return (f > 7.1F); // no warning 773} 774 775int checkGreaterThanFloatDeclCompare4(void) { 776 float f = 7.1F; 777 return (7.1F > f); // no warning 778} 779 780int checkGreaterThanFloatDeclCompare5(void) { 781 float f = 7.1F; 782 int t = 7; 783 return (t > f); // no warning 784} 785 786int checkGreaterThanFloatDeclCompare6(void) { 787 float f = 7.1F; 788 int t = 7; 789 return (f > t); // no warning 790} 791 792int checkGreaterThanCastFloatDeclCompare11(void) { 793 float f = 7.1F; 794 return ((int)f > (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}} 795} 796int checkGreaterThanCastFloatDeclCompare12(void) { 797 float f = 7.1F; 798 return ((char)f > (int)f); // no warning 799} 800int checkGreaterThanBinaryOpFloatCompare1(void) { 801 int res; 802 float f= 3.14F; 803 res = (f + 3.14F > f + 3.14F); // no warning 804 return (0); 805} 806int checkGreaterThanBinaryOpFloatCompare2(void) { 807 float f = 7.1F; 808 float g = 7.1F; 809 return (f + 3.14F > g + 3.14F); // no warning 810} 811int checkGreaterThanBinaryOpFloatCompare3(void) { 812 int res; 813 float f= 3.14F; 814 res = ((int)f + 3.14F > (int)f + 3.14F); // no warning 815 return (0); 816} 817int checkGreaterThanBinaryOpFloatCompare4(void) { 818 int res; 819 float f= 3.14F; 820 res = ((int)f + 3.14F > (char)f + 3.14F); // no warning 821 return (0); 822} 823 824int checkGreaterThanNestedBinaryOpFloatCompare1(void) { 825 int res; 826 int t= 1; 827 int u= 2; 828 float f= 3.14F; 829 res = (((int)f + (3.14F - u)*t) > ((int)f + (3.14F - u)*t)); // no warning 830 return (0); 831} 832 833int checkGreaterThanNestedBinaryOpFloatCompare2(void) { 834 int res; 835 int t= 1; 836 int u= 2; 837 float f= 3.14F; 838 res = (((int)f + (u - 3.14F)*t) > ((int)f + (3.14F - u)*t)); // no warning 839 return (0); 840} 841 842int checkGreaterThanNestedBinaryOpFloatCompare3(void) { 843 int res; 844 int t= 1; 845 int u= 2; 846 float f= 3.14F; 847 res = (((int)f + (u - 3.14F)*t) > ((int)f + (3.14F - u)*(f + t > f + t))); // no warning 848 return (0); 849} 850 851/* end GT with float */ 852 853/* GT with int */ 854 855 856int checkGreaterThanIntLiteralCompare1(void) { 857 return (5 > 5); // expected-warning {{comparison of identical expressions always evaluates to false}} 858} 859 860int checkGreaterThanIntLiteralCompare2(void) { 861 return (6 > 7); // no warning 862} 863 864int checkGreaterThanIntDeclCompare1(void) { 865 int f = 7; 866 int g = 7; 867 868 return (f > g); // no warning 869} 870 871int checkGreaterThanIntDeclCompare3(void) { 872 int f = 7; 873 return (f > 7); // no warning 874} 875 876int checkGreaterThanIntDeclCompare4(void) { 877 int f = 7; 878 return (7 > f); // no warning 879} 880 881int checkGreaterThanCastIntDeclCompare11(void) { 882 int f = 7; 883 return ((int)f > (int)f); // expected-warning {{comparison of identical expressions always evaluates to false}} 884} 885int checkGreaterThanCastIntDeclCompare12(void) { 886 int f = 7; 887 return ((char)f > (int)f); // no warning 888} 889int checkGreaterThanBinaryOpIntCompare1(void) { 890 int res; 891 int f= 3; 892 res = (f + 3 > f + 3); // expected-warning {{comparison of identical expressions always evaluates to false}} 893 return (0); 894} 895int checkGreaterThanBinaryOpIntCompare2(void) { 896 int f = 7; 897 int g = 7; 898 return (f + 3 > g + 3); // no warning 899} 900int checkGreaterThanBinaryOpIntCompare3(void) { 901 int res; 902 int f= 3; 903 res = ((int)f + 3 > (int)f + 3); // expected-warning {{comparison of identical expressions always evaluates to false}} 904 return (0); 905} 906int checkGreaterThanBinaryOpIntCompare4(void) { 907 int res; 908 int f= 3; 909 res = ((int)f + 3 > (char)f + 3); // no warning 910 return (0); 911} 912 913int checkGreaterThanNestedBinaryOpIntCompare1(void) { 914 int res; 915 int t= 1; 916 int u= 2; 917 int f= 3; 918 res = (((int)f + (3 - u)*t) > ((int)f + (3 - u)*t)); // expected-warning {{comparison of identical expressions always evaluates to false}} 919 return (0); 920} 921 922int checkGreaterThanNestedBinaryOpIntCompare2(void) { 923 int res; 924 int t= 1; 925 int u= 2; 926 int f= 3; 927 res = (((int)f + (u - 3)*t) > ((int)f + (3 - u)*t)); // no warning 928 return (0); 929} 930 931int checkGreaterThanNestedBinaryOpIntCompare3(void) { 932 int res; 933 int t= 1; 934 int u= 2; 935 int f= 3; 936 res = (((int)f + (u - 3)*t) > ((int)f + (3 - u)*(t + u > t + u))); // expected-warning {{comparison of identical expressions always evaluates to false}} 937 return (0); 938} 939 940/* end GT with int */ 941 942/* end GT */ 943