# Changeset View

Changeset View

# Standalone View

Standalone View

# test/Analysis/multiplicative-folding.c

Show First 20 Lines • Show All 564 Lines • ▼ Show 20 Line(s) | 564 | if (n / 4 != UINT_MAX) { | |||
---|---|---|---|---|---|

565 | clang_analyzer_eval(n == UINT_MAX); //expected-warning{{FALSE}} | 565 | clang_analyzer_eval(n == UINT_MAX); //expected-warning{{FALSE}} | ||

566 | //expected-warning@-1{{TRUE}} | 566 | //expected-warning@-1{{TRUE}} | ||

567 | } | 567 | } | ||

568 | } | 568 | } | ||

569 | } | 569 | } | ||

570 | } | 570 | } | ||

571 | } | 571 | } | ||

572 | 572 | | |||

573 | void signed_multiplication_lt_0(int32_t n) { | ||||

574 | if (n * 2 < 3) { | ||||

575 | int32_t U1 = 0x80000001, | ||||

576 | L2 = 0xc0000000, U2 = 1, | ||||

577 | L3 = 0x40000000; | ||||

578 | | ||||

579 | assert(INT_MIN * 2 < 3); | ||||

580 | assert(U1 * 2 < 3); | ||||

581 | assert((U1 + 1) * 2 >= 3); | ||||

582 | assert(L2 * 2 < 3); | ||||

583 | assert((L2 - 1) * 2 >= 3); | ||||

584 | assert(U2 * 2 < 3); | ||||

585 | assert((U2 + 1) * 2 >= 3); | ||||

586 | assert(L3 * 2 < 3); | ||||

587 | assert((L3 - 1) * 2 >= 3); | ||||

588 | assert(INT_MAX * 2 < 3); | ||||

589 | | ||||

590 | if (n < INT_MIN / 2) { | ||||

591 | clang_analyzer_eval(n == INT_MIN); //expected-warning{{FALSE}} | ||||

592 | //expected-warning@-1{{TRUE}} | ||||

593 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

594 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

595 | } else if (n < INT_MAX / 2){ | ||||

596 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

597 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

598 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

599 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

600 | } else { | ||||

601 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

602 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

603 | clang_analyzer_eval(n == INT_MAX); //expected-warning{{FALSE}} | ||||

604 | //expected-warning@-1{{TRUE}} | ||||

605 | } | ||||

606 | } | ||||

607 | } | ||||

608 | | ||||

609 | void signed_multiplication_lt_1(int32_t n) { | ||||

610 | if (n * 2 < 4) { | ||||

611 | int32_t U1 = 0x80000001, | ||||

612 | L2 = 0xc0000000, U2 = 1, | ||||

613 | L3 = 0x40000000; | ||||

614 | | ||||

615 | assert(INT_MIN * 2 < 4); | ||||

616 | assert(U1 * 2 < 4); | ||||

617 | assert((U1 + 1) * 2 >= 4); | ||||

618 | assert(L2 * 2 < 4); | ||||

619 | assert((L2 - 1) * 2 >= 4); | ||||

620 | assert(U2 * 2 < 4); | ||||

621 | assert((U2 + 1) * 2 >= 4); | ||||

622 | assert(L3 * 2 < 4); | ||||

623 | assert((L3 - 1) * 2 >= 4); | ||||

624 | assert(INT_MAX * 2 < 4); | ||||

625 | | ||||

626 | if (n < INT_MIN / 2) { | ||||

627 | clang_analyzer_eval(n == INT_MIN); //expected-warning{{FALSE}} | ||||

628 | //expected-warning@-1{{TRUE}} | ||||

629 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

630 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

631 | } else if (n < INT_MAX / 2){ | ||||

632 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

633 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

634 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

635 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

636 | } else { | ||||

637 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

638 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

639 | clang_analyzer_eval(n == INT_MAX); //expected-warning{{FALSE}} | ||||

640 | //expected-warning@-1{{TRUE}} | ||||

641 | } | ||||

642 | } | ||||

643 | } | ||||

644 | | ||||

645 | void signed_multiplication_lt_2(int32_t n) { | ||||

646 | if (n * 2 < 5) { | ||||

647 | int32_t U1 = 0x80000002, | ||||

648 | L2 = 0xc0000000, U2 = 2, | ||||

649 | L3 = 0x40000000; | ||||

650 | | ||||

651 | assert(INT_MIN * 2 < 5); | ||||

652 | assert(U1 * 2 < 5); | ||||

653 | assert((U1 + 1) * 2 >= 5); | ||||

654 | assert(L2 * 2 < 5); | ||||

655 | assert((L2 - 1) * 2 >= 5); | ||||

656 | assert(U2 * 2 < 5); | ||||

657 | assert((U2 + 1) * 2 >= 5); | ||||

658 | assert(L3 * 2 < 5); | ||||

659 | assert((L3 - 1) * 2 >= 5); | ||||

660 | assert(INT_MAX * 2 < 5); | ||||

661 | | ||||

662 | if (n < INT_MIN / 2) { | ||||

663 | clang_analyzer_eval(n == INT_MIN); //expected-warning{{FALSE}} | ||||

664 | //expected-warning@-1{{TRUE}} | ||||

665 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

666 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

667 | } else if (n < INT_MAX / 2){ | ||||

668 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

669 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

670 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

671 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

672 | } else { | ||||

673 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

674 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

675 | clang_analyzer_eval(n == INT_MAX); //expected-warning{{FALSE}} | ||||

676 | //expected-warning@-1{{TRUE}} | ||||

677 | } | ||||

678 | } | ||||

679 | } | ||||

680 | | ||||

681 | void signed_multiplication_lt_3(int32_t n) { | ||||

682 | if (n * 3 < 4) { | ||||

683 | int32_t U1 = 0xaaaaaaab, | ||||

684 | L2 = 0xd5555556, U2 = 1, | ||||

685 | L3 = 0x2aaaaaab, U3 = 0x55555556; | ||||

686 | | ||||

687 | assert(INT_MIN * 3 < 4); | ||||

688 | assert(U1 * 3 < 4); | ||||

689 | assert((U1 + 1) * 3 >= 4); | ||||

690 | assert(L2 * 3 < 4); | ||||

691 | assert((L2 - 1) * 3 >= 4); | ||||

692 | assert(U2 * 3 < 4); | ||||

693 | assert((U2 + 1) * 3 >= 4); | ||||

694 | assert(L3 * 3 < 4); | ||||

695 | assert((L3 - 1) * 3 >= 4); | ||||

696 | assert(U3 * 3 < 4); | ||||

697 | assert((U3 + 1) * 3 >= 4); | ||||

698 | | ||||

699 | if (n < (int32_t) 0xc0000000) { | ||||

700 | clang_analyzer_eval(n == INT_MIN); //expected-warning{{FALSE}} | ||||

701 | //expected-warning@-1{{TRUE}} | ||||

702 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

703 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

704 | } else if (n < (int32_t) 0x15555556) { | ||||

705 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

706 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

707 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

708 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

709 | } else { | ||||

710 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

711 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

712 | clang_analyzer_eval(n <= U3); //expected-warning{{TRUE}} | ||||

713 | clang_analyzer_eval(n > U3); //expected-warning{{FALSE}} | ||||

714 | } | ||||

715 | } | ||||

716 | } | ||||

717 | | ||||

718 | void signed_multiplication_lt_4(int32_t n) { | ||||

719 | if (n * 6 < -2) { | ||||

720 | int32_t L1 = 0x95555556, U1 = 0xaaaaaaaa, | ||||

721 | L2 = 0xc0000000, U2 = 0x55555554, | ||||

722 | L3 = 0xeaaaaaab, U3 = -1, | ||||

723 | L4 = 0x15555556, U4 = 0x2aaaaaaa, | ||||

724 | L5 = 0x40000000, U5 = 0x55555554, | ||||

725 | L6 = 0x6aaaaaab; | ||||

726 | | ||||

727 | assert(L1 * 6 < -2); | ||||

728 | assert((L1 - 1) * 6 >= -2); | ||||

729 | assert(U1 * 6 < -2); | ||||

730 | assert((U1 + 1) * 6 >= -2); | ||||

731 | assert(L2 * 6 < -2); | ||||

732 | assert((L2 - 1) * 6 >= -2); | ||||

733 | assert(U2 * 6 < -2); | ||||

734 | assert((U2 + 1) * 6 >= -2); | ||||

735 | assert(L3 * 6 < -2); | ||||

736 | assert((L3 - 1) * 6 >= -2); | ||||

737 | assert(U3 * 6 < -2); | ||||

738 | assert((U3 + 1) * 6 >= -2); | ||||

739 | assert(L4 * 6 < -2); | ||||

740 | assert((L4 - 1) * 6 >= -2); | ||||

741 | assert(U4 * 6 < -2); | ||||

742 | assert((U4 + 1) * 6 >= -2); | ||||

743 | assert(L5 * 6 < -2); | ||||

744 | assert((L5 - 1) * 6 >= -2); | ||||

745 | assert(U5 * 6 < -2); | ||||

746 | assert((U5 + 1) * 6 >= -2); | ||||

747 | assert(L6 * 6 < -2); | ||||

748 | assert((L6 - 1) * 6 >= -2); | ||||

749 | assert(INT_MAX * 6 < -2); | ||||

750 | | ||||

751 | if (n < (int32_t) 0xb5555555) { | ||||

752 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

753 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

754 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

755 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

756 | } else if (n < (int32_t) 0xdfffffff) { | ||||

757 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

758 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

759 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

760 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

761 | } else if (n < (int32_t) 0x0aaaaaaa) { | ||||

762 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

763 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

764 | clang_analyzer_eval(n <= U3); //expected-warning{{TRUE}} | ||||

765 | clang_analyzer_eval(n > U3); //expected-warning{{FALSE}} | ||||

766 | } else if (n < (int32_t) 0x35555555) { | ||||

767 | clang_analyzer_eval(n < L4); //expected-warning{{FALSE}} | ||||

768 | clang_analyzer_eval(n >= L4); //expected-warning{{TRUE}} | ||||

769 | clang_analyzer_eval(n <= U4); //expected-warning{{TRUE}} | ||||

770 | clang_analyzer_eval(n > U4); //expected-warning{{FALSE}} | ||||

771 | } else if (n < (int32_t) 0x5fffffff) { | ||||

772 | clang_analyzer_eval(n < L5); //expected-warning{{FALSE}} | ||||

773 | clang_analyzer_eval(n >= L5); //expected-warning{{TRUE}} | ||||

774 | clang_analyzer_eval(n <= U5); //expected-warning{{TRUE}} | ||||

775 | clang_analyzer_eval(n > U5); //expected-warning{{FALSE}} | ||||

776 | } else { | ||||

777 | clang_analyzer_eval(n < L6); //expected-warning{{FALSE}} | ||||

778 | clang_analyzer_eval(n >= L6); //expected-warning{{TRUE}} | ||||

779 | clang_analyzer_eval(n == INT_MAX); //expected-warning{{FALSE}} | ||||

780 | //expected-warning@-1{{TRUE}} | ||||

781 | } | ||||

782 | } | ||||

783 | } | ||||

784 | | ||||

785 | void signed_division_lt_0(int32_t n) { | ||||

786 | if (n / 4 < 0) { | ||||

787 | const int32_t C = -4; | ||||

788 | | ||||

789 | assert(C / 4 < 0); | ||||

790 | assert((C + 1) / 4 >= 0); | ||||

791 | | ||||

792 | clang_analyzer_eval(n <= C); //expected-warning{{TRUE}} | ||||

793 | clang_analyzer_eval(n > C); //expected-warning{{FALSE}} | ||||

794 | } | ||||

795 | } | ||||

796 | | ||||

797 | void signed_division_lt_1(int32_t n) { | ||||

798 | if (n / 3 < 2) { | ||||

799 | const int32_t C = 5; | ||||

800 | | ||||

801 | assert(C / 3 < 2); | ||||

802 | assert((C + 1) / 3 >= 2); | ||||

803 | | ||||

804 | clang_analyzer_eval(n <= C); //expected-warning{{TRUE}} | ||||

805 | clang_analyzer_eval(n > C); //expected-warning{{FALSE}} | ||||

806 | } | ||||

807 | } | ||||

808 | | ||||

809 | void signed_division_lt_2(int32_t n) { | ||||

810 | if (n / 5 < -7) { | ||||

811 | const int32_t C = -40; | ||||

812 | | ||||

813 | assert(C / 5 < -7); | ||||

814 | assert((C + 1) / 5 >= -7); | ||||

815 | | ||||

816 | clang_analyzer_eval(n <= C); //expected-warning{{TRUE}} | ||||

817 | clang_analyzer_eval(n > C); //expected-warning{{FALSE}} | ||||

818 | } | ||||

819 | } | ||||

820 | | ||||

821 | void unsigned_multiplication_lt_0(uint32_t n) { | ||||

822 | if (n * 2 < 3) { | ||||

823 | uint32_t U1 = 1, | ||||

824 | L2 = 0x80000000, U2 = 0x80000001; | ||||

825 | | ||||

826 | assert(U1 * 2 < 3); | ||||

827 | assert((U1 + 1) * 2 >= 3); | ||||

828 | assert(L2 * 2 < 3); | ||||

829 | assert((L2 - 1) * 2 >= 3); | ||||

830 | assert(U2 * 2 < 3); | ||||

831 | assert((U2 + 1) * 2 >= 3); | ||||

832 | | ||||

833 | if (n < UINT_MAX / 2) { | ||||

834 | clang_analyzer_eval(n == 0); //expected-warning{{FALSE}} | ||||

835 | //expected-warning@-1{{TRUE}} | ||||

836 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

837 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

838 | } else { | ||||

839 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

840 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

841 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

842 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

843 | } | ||||

844 | } | ||||

845 | } | ||||

846 | | ||||

847 | void unsigned_multiplication_lt_1(uint32_t n) { | ||||

848 | if (n * 2 < 4) { | ||||

849 | uint32_t U1 = 1, | ||||

850 | L2 = 0x80000000, U2 = 0x80000001; | ||||

851 | | ||||

852 | assert(U1 * 2 < 4); | ||||

853 | assert((U1 + 1) * 2 >= 4); | ||||

854 | assert(L2 * 2 < 4); | ||||

855 | assert((L2 - 1) * 2 >= 4); | ||||

856 | assert(U2 * 2 < 4); | ||||

857 | assert((U2 + 1) * 2 >= 4); | ||||

858 | | ||||

859 | if (n < UINT_MAX / 2) { | ||||

860 | clang_analyzer_eval(n == 0); //expected-warning{{FALSE}} | ||||

861 | //expected-warning@-1{{TRUE}} | ||||

862 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

863 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

864 | } else { | ||||

865 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

866 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

867 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

868 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

869 | } | ||||

870 | } | ||||

871 | } | ||||

872 | | ||||

873 | void unsigned_multiplication_lt_2(uint32_t n) { | ||||

874 | if (n * 2 < 5) { | ||||

875 | uint32_t U1 = 2, | ||||

876 | L2 = 0x80000000, U2 = 0x80000002; | ||||

877 | | ||||

878 | assert(U1 * 2 < 5); | ||||

879 | assert((U1 + 1) * 2 >= 5); | ||||

880 | assert(L2 * 2 < 5); | ||||

881 | assert((L2 - 1) * 2 >= 5); | ||||

882 | assert(U2 * 2 < 5); | ||||

883 | assert((U2 + 1) * 2 >= 5); | ||||

884 | | ||||

885 | if (n < UINT_MAX / 2) { | ||||

886 | clang_analyzer_eval(n == 0); //expected-warning{{FALSE}} | ||||

887 | //expected-warning@-1{{TRUE}} | ||||

888 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

889 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

890 | } else { | ||||

891 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

892 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

893 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

894 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

895 | } | ||||

896 | } | ||||

897 | } | ||||

898 | | ||||

899 | void unsigned_multiplication_lt_3(uint32_t n) { | ||||

900 | if (n * 3 < 4) { | ||||

901 | uint32_t U1 = 1, C2 = 0x55555556, C3 = 0xaaaaaaab; | ||||

902 | | ||||

903 | assert(U1 * 3 < 4); | ||||

904 | assert((U1 + 1) * 3 >= 4); | ||||

905 | assert(C2 * 3 < 4); | ||||

906 | assert((C2 - 1) * 3 >= 4); | ||||

907 | assert((C2 + 1) * 3 >= 4); | ||||

908 | assert(C3 * 3 < 4); | ||||

909 | assert((C3 - 1) * 3 >= 4); | ||||

910 | assert((C3 + 1) * 3 >= 4); | ||||

911 | | ||||

912 | if (n < 0x2aaaaaab) { | ||||

913 | clang_analyzer_eval(n == 0); //expected-warning{{FALSE}} | ||||

914 | //expected-warning@-1{{TRUE}} | ||||

915 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

916 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

917 | } else if (n < 0x80000000) { | ||||

918 | clang_analyzer_eval(n < C2); //expected-warning{{FALSE}} | ||||

919 | clang_analyzer_eval(n == C2); //expected-warning{{TRUE}} | ||||

920 | clang_analyzer_eval(n > C2); //expected-warning{{FALSE}} | ||||

921 | } else { | ||||

922 | clang_analyzer_eval(n < C3); //expected-warning{{FALSE}} | ||||

923 | clang_analyzer_eval(n == C3); //expected-warning{{TRUE}} | ||||

924 | clang_analyzer_eval(n > C3); //expected-warning{{FALSE}} | ||||

925 | } | ||||

926 | } | ||||

927 | } | ||||

928 | | ||||

929 | void unsigned_division_lt_0(uint32_t n) { | ||||

930 | if (n / 3 < 2) { | ||||

931 | const uint32_t C = 5; | ||||

932 | | ||||

933 | assert(C / 3 < 2); | ||||

934 | assert((C + 1) / 3 >= 2); | ||||

935 | | ||||

936 | clang_analyzer_eval(n <= C); //expected-warning{{TRUE}} | ||||

937 | clang_analyzer_eval(n > C); //expected-warning{{FALSE}} | ||||

938 | } | ||||

939 | } | ||||

940 | | ||||

941 | void signed_multiplication_le_0(int32_t n) { | ||||

942 | if (n * 2 <= 3) { | ||||

943 | int32_t U1 = 0x80000001, | ||||

944 | L2 = 0xc0000000, U2 = 1, | ||||

945 | L3 = 0x40000000; | ||||

946 | | ||||

947 | assert(INT_MIN * 2 <= 3); | ||||

948 | assert(U1 * 2 <= 3); | ||||

949 | assert((U1 + 1) * 2 > 3); | ||||

950 | assert(L2 * 2 <= 3); | ||||

951 | assert((L2 - 1) * 2 > 3); | ||||

952 | assert(U2 * 2 <= 3); | ||||

953 | assert((U2 + 1) * 2 > 3); | ||||

954 | assert(L3 * 2 <= 3); | ||||

955 | assert((L3 - 1) * 2 > 3); | ||||

956 | assert(INT_MAX * 2 <= 3); | ||||

957 | | ||||

958 | if (n < INT_MIN / 2) { | ||||

959 | clang_analyzer_eval(n == INT_MIN); //expected-warning{{FALSE}} | ||||

960 | //expected-warning@-1{{TRUE}} | ||||

961 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

962 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

963 | } else if (n < INT_MAX / 2) { | ||||

964 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

965 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

966 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

967 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

968 | } else { | ||||

969 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

970 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

971 | clang_analyzer_eval(n == INT_MAX); //expected-warning{{FALSE}} | ||||

972 | //expected-warning@-1{{TRUE}} | ||||

973 | } | ||||

974 | } | ||||

975 | } | ||||

976 | | ||||

977 | void signed_multiplication_le_1(int32_t n) { | ||||

978 | if (n * 2 <= 4) { | ||||

979 | int32_t U1 = 0x80000002, | ||||

980 | L2 = 0xc0000000, U2 = 2, | ||||

981 | L3 = 0x40000000; | ||||

982 | | ||||

983 | assert(INT_MIN * 2 <= 4); | ||||

984 | assert(U1 * 2 <= 4); | ||||

985 | assert((U1 + 1) * 2 > 4); | ||||

986 | assert(L2 * 2 <= 4); | ||||

987 | assert((L2 - 1) * 2 > 4); | ||||

988 | assert(U2 * 2 <= 4); | ||||

989 | assert((U2 + 1) * 2 > 4); | ||||

990 | assert(L3 * 2 <= 4); | ||||

991 | assert((L3 - 1) * 2 > 4); | ||||

992 | assert(INT_MAX * 2 <= 4); | ||||

993 | | ||||

994 | if (n < INT_MIN / 2) { | ||||

995 | clang_analyzer_eval(n == INT_MIN); //expected-warning{{FALSE}} | ||||

996 | //expected-warning@-1{{TRUE}} | ||||

997 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

998 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

999 | } else if (n < INT_MAX / 2){ | ||||

1000 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1001 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1002 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1003 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1004 | } else { | ||||

1005 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

1006 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

1007 | clang_analyzer_eval(n == INT_MAX); //expected-warning{{FALSE}} | ||||

1008 | //expected-warning@-1{{TRUE}} | ||||

1009 | } | ||||

1010 | } | ||||

1011 | } | ||||

1012 | | ||||

1013 | void signed_multiplication_le_2(int32_t n) { | ||||

1014 | if (n * 2 <= 5) { | ||||

1015 | int32_t U1 = 0x80000002, | ||||

1016 | L2 = 0xc0000000, U2 = 2, | ||||

1017 | L3 = 0x40000000; | ||||

1018 | | ||||

1019 | assert(INT_MIN * 2 <= 5); | ||||

1020 | assert(U1 * 2 <= 5); | ||||

1021 | assert((U1 + 1) * 2 > 5); | ||||

1022 | assert(L2 * 2 <= 5); | ||||

1023 | assert((L2 - 1) * 2 > 5); | ||||

1024 | assert(U2 * 2 <= 5); | ||||

1025 | assert((U2 + 1) * 2 > 5); | ||||

1026 | assert(L3 * 2 <= 5); | ||||

1027 | assert((L3 - 1) * 2 > 5); | ||||

1028 | assert(INT_MAX * 2 <= 5); | ||||

1029 | | ||||

1030 | if (n < INT_MIN / 2) { | ||||

1031 | clang_analyzer_eval(n == INT_MIN); //expected-warning{{FALSE}} | ||||

1032 | //expected-warning@-1{{TRUE}} | ||||

1033 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1034 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1035 | } else if (n < INT_MAX / 2) { | ||||

1036 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1037 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1038 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1039 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1040 | } else { | ||||

1041 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

1042 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

1043 | clang_analyzer_eval(n == INT_MAX); //expected-warning{{FALSE}} | ||||

1044 | //expected-warning@-1{{TRUE}} | ||||

1045 | } | ||||

1046 | } | ||||

1047 | } | ||||

1048 | | ||||

1049 | void signed_multiplication_le_3(int32_t n) { | ||||

1050 | if (n * 3 <= 4) { | ||||

1051 | int32_t U1 = 0xaaaaaaac, | ||||

1052 | L2 = 0xd5555556, U2 = 1, | ||||

1053 | L3 = 0x2aaaaaab, U3 = 0x55555556; | ||||

1054 | | ||||

1055 | assert(INT_MIN * 3 <= 4); | ||||

1056 | assert(U1 * 3 <= 4); | ||||

1057 | assert((U1 + 1) * 3 > 4); | ||||

1058 | assert(L2 * 3 <= 4); | ||||

1059 | assert((L2 - 1) * 3 > 4); | ||||

1060 | assert(U2 * 3 <= 4); | ||||

1061 | assert((U2 + 1) * 3 > 4); | ||||

1062 | assert(L3 * 3 <= 4); | ||||

1063 | assert((L3 - 1) * 3 > 4); | ||||

1064 | assert(U3 * 3 <= 4); | ||||

1065 | assert((U3 + 1) * 3 > 4); | ||||

1066 | | ||||

1067 | if (n < (int32_t) 0xc0000001) { | ||||

1068 | clang_analyzer_eval(n == INT_MIN); //expected-warning{{FALSE}} | ||||

1069 | //expected-warning@-1{{TRUE}} | ||||

1070 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1071 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1072 | } else if (n < (int32_t) 0x15555556) { | ||||

1073 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1074 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1075 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1076 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1077 | } else { | ||||

1078 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

1079 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

1080 | clang_analyzer_eval(n <= U3); //expected-warning{{TRUE}} | ||||

1081 | clang_analyzer_eval(n > U3); //expected-warning{{FALSE}} | ||||

1082 | } | ||||

1083 | } | ||||

1084 | } | ||||

1085 | | ||||

1086 | void signed_multiplication_le_4(int32_t n) { | ||||

1087 | if (n * 6 <= -2) { | ||||

1088 | int32_t L1 = 0x95555556, U1 = 0xaaaaaaaa, | ||||

1089 | L2 = 0xc0000000, U2 = 0x55555555, | ||||

1090 | L3 = 0xeaaaaaab, U3 = -1, | ||||

1091 | L4 = 0x15555556, U4 = 0x2aaaaaaa, | ||||

1092 | L5 = 0x40000000, U5 = 0x55555555, | ||||

1093 | L6 = 0x6aaaaaab; | ||||

1094 | | ||||

1095 | assert(L1 * 6 <= -2); | ||||

1096 | assert((L1 - 1) * 6 > -2); | ||||

1097 | assert(U1 * 6 <= -2); | ||||

1098 | assert((U1 + 1) * 6 > -2); | ||||

1099 | assert(L2 * 6 <= -2); | ||||

1100 | assert((L2 - 1) * 6 > -2); | ||||

1101 | assert(U2 * 6 <= -2); | ||||

1102 | assert((U2 + 1) * 6 > -2); | ||||

1103 | assert(L3 * 6 <= -2); | ||||

1104 | assert((L3 - 1) * 6 > -2); | ||||

1105 | assert(U3 * 6 <= -2); | ||||

1106 | assert((U3 + 1) * 6 > -2); | ||||

1107 | assert(L4 * 6 <= -2); | ||||

1108 | assert((L4 - 1) * 6 > -2); | ||||

1109 | assert(U4 * 6 <= -2); | ||||

1110 | assert((U4 + 1) * 6 > -2); | ||||

1111 | assert(L5 * 6 <= -2); | ||||

1112 | assert((L5 - 1) * 6 > -2); | ||||

1113 | assert(U5 * 6 <= -2); | ||||

1114 | assert((U5 + 1) * 6 > -2); | ||||

1115 | assert(L6 * 6 <= -2); | ||||

1116 | assert((L6 - 1) * 6 > -2); | ||||

1117 | assert(INT_MAX * 6 <= -2); | ||||

1118 | | ||||

1119 | if (n < (int32_t) 0xb5555555) { | ||||

1120 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1121 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1122 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1123 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1124 | } else if (n < (int32_t) 0xe0000000) { | ||||

1125 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1126 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1127 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1128 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1129 | } else if (n < (int32_t) 0x0aaaaaaa) { | ||||

1130 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

1131 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

1132 | clang_analyzer_eval(n <= U3); //expected-warning{{TRUE}} | ||||

1133 | clang_analyzer_eval(n > U3); //expected-warning{{FALSE}} | ||||

1134 | } else if (n < (int32_t) 0x35555555) { | ||||

1135 | clang_analyzer_eval(n < L4); //expected-warning{{FALSE}} | ||||

1136 | clang_analyzer_eval(n >= L4); //expected-warning{{TRUE}} | ||||

1137 | clang_analyzer_eval(n <= U4); //expected-warning{{TRUE}} | ||||

1138 | clang_analyzer_eval(n > U4); //expected-warning{{FALSE}} | ||||

1139 | } else if (n < (int32_t) 0x60000000) { | ||||

1140 | clang_analyzer_eval(n < L5); //expected-warning{{FALSE}} | ||||

1141 | clang_analyzer_eval(n >= L5); //expected-warning{{TRUE}} | ||||

1142 | clang_analyzer_eval(n <= U5); //expected-warning{{TRUE}} | ||||

1143 | clang_analyzer_eval(n > U5); //expected-warning{{FALSE}} | ||||

1144 | } else { | ||||

1145 | clang_analyzer_eval(n < L6); //expected-warning{{FALSE}} | ||||

1146 | clang_analyzer_eval(n >= L6); //expected-warning{{TRUE}} | ||||

1147 | clang_analyzer_eval(n == INT_MAX); //expected-warning{{FALSE}} | ||||

1148 | //expected-warning@-1{{TRUE}} | ||||

1149 | } | ||||

1150 | } | ||||

1151 | } | ||||

1152 | | ||||

1153 | void signed_division_le_0(int32_t n) { | ||||

1154 | if (n / 4 <= 0) { | ||||

1155 | const int32_t C = 3; | ||||

1156 | | ||||

1157 | assert(C / 4 <= 0); | ||||

1158 | assert((C + 1) / 4 > 0); | ||||

1159 | | ||||

1160 | clang_analyzer_eval(n <= C); //expected-warning{{TRUE}} | ||||

1161 | clang_analyzer_eval(n > C); //expected-warning{{FALSE}} | ||||

1162 | } | ||||

1163 | } | ||||

1164 | | ||||

1165 | void signed_division_le_1(int32_t n) { | ||||

1166 | if (n / 3 <= 2) { | ||||

1167 | const int32_t C = 8; | ||||

1168 | | ||||

1169 | assert(C / 3 <= 2); | ||||

1170 | assert((C + 1) / 3 > 2); | ||||

1171 | | ||||

1172 | clang_analyzer_eval(n <= C); //expected-warning{{TRUE}} | ||||

1173 | clang_analyzer_eval(n > C); //expected-warning{{FALSE}} | ||||

1174 | } | ||||

1175 | } | ||||

1176 | | ||||

1177 | void signed_division_le_2(int32_t n) { | ||||

1178 | if (n / 5 <= -7) { | ||||

1179 | const int32_t C = -35; | ||||

1180 | | ||||

1181 | assert(C / 5 <= -7); | ||||

1182 | assert((C + 1) / 5 > -7); | ||||

1183 | | ||||

1184 | clang_analyzer_eval(n <= C); //expected-warning{{TRUE}} | ||||

1185 | clang_analyzer_eval(n > C); //expected-warning{{FALSE}} | ||||

1186 | } | ||||

1187 | } | ||||

1188 | | ||||

1189 | void unsigned_multiplication_le_0(uint32_t n) { | ||||

1190 | if (n * 2 <= 3) { | ||||

1191 | uint32_t U1 = 1, | ||||

1192 | L2 = 0x80000000, U2 = 0x80000001; | ||||

1193 | | ||||

1194 | assert(U1 * 2 <= 3); | ||||

1195 | assert((U1 + 1) * 2 > 3); | ||||

1196 | assert(L2 * 2 <= 3); | ||||

1197 | assert((L2 - 1) * 2 > 3); | ||||

1198 | assert(U2 * 2 <= 3); | ||||

1199 | assert((U2 + 1) * 2 > 3); | ||||

1200 | | ||||

1201 | if (n < UINT_MAX / 2) { | ||||

1202 | clang_analyzer_eval(n == 0); //expected-warning{{FALSE}} | ||||

1203 | //expected-warning@-1{{TRUE}} | ||||

1204 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1205 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1206 | } else { | ||||

1207 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1208 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1209 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1210 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1211 | } | ||||

1212 | } | ||||

1213 | } | ||||

1214 | | ||||

1215 | void unsigned_multiplication_le_1(uint32_t n) { | ||||

1216 | if (n * 2 <= 4) { | ||||

1217 | uint32_t U1 = 2, | ||||

1218 | L2 = 0x80000000, U2 = 0x80000002; | ||||

1219 | | ||||

1220 | assert(U1 * 2 <= 4); | ||||

1221 | assert((U1 + 1) * 2 > 4); | ||||

1222 | assert(L2 * 2 <= 4); | ||||

1223 | assert((L2 - 1) * 2 > 4); | ||||

1224 | assert(U2 * 2 <= 4); | ||||

1225 | assert((U2 + 1) * 2 > 4); | ||||

1226 | | ||||

1227 | if (n < UINT_MAX / 2) { | ||||

1228 | clang_analyzer_eval(n == 0); //expected-warning{{FALSE}} | ||||

1229 | //expected-warning@-1{{TRUE}} | ||||

1230 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1231 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1232 | } else { | ||||

1233 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1234 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1235 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1236 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1237 | } | ||||

1238 | } | ||||

1239 | } | ||||

1240 | | ||||

1241 | void unsigned_multiplication_le_2(uint32_t n) { | ||||

1242 | if (n * 2 <= 5) { | ||||

1243 | uint32_t U1 = 2, | ||||

1244 | L2 = 0x80000000, U2 = 0x80000002; | ||||

1245 | | ||||

1246 | assert(U1 * 2 <= 5); | ||||

1247 | assert((U1 + 1) * 2 > 5); | ||||

1248 | assert(L2 * 2 <= 5); | ||||

1249 | assert((L2 - 1) * 2 > 5); | ||||

1250 | assert(U2 * 2 <= 5); | ||||

1251 | assert((U2 + 1) * 2 > 5); | ||||

1252 | | ||||

1253 | if (n < UINT_MAX / 2) { | ||||

1254 | clang_analyzer_eval(n == 0); //expected-warning{{FALSE}} | ||||

1255 | //expected-warning@-1{{TRUE}} | ||||

1256 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1257 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1258 | } else { | ||||

1259 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1260 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1261 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1262 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1263 | } | ||||

1264 | } | ||||

1265 | } | ||||

1266 | | ||||

1267 | void unsigned_multiplication_le_3(uint32_t n) { | ||||

1268 | if (n * 3 <= 4) { | ||||

1269 | uint32_t U1 = 1, | ||||

1270 | C2 = 0x55555556, | ||||

1271 | L3 = 0xaaaaaaab, U3 = 0xaaaaaaac; | ||||

1272 | | ||||

1273 | assert(U1 * 3 <= 4); | ||||

1274 | assert((U1 + 1) * 3 > 4); | ||||

1275 | assert(C2 * 3 <= 4); | ||||

1276 | assert((C2 - 1) * 3 > 4); | ||||

1277 | assert((C2 + 1) * 3 > 4); | ||||

1278 | assert(L3 * 3 <= 4); | ||||

1279 | assert((L3 - 1) * 3 > 4); | ||||

1280 | assert(U3 * 3 <= 4); | ||||

1281 | assert((U3 + 1) * 3 > 4); | ||||

1282 | | ||||

1283 | if (n < 0x2aaaaaab) { | ||||

1284 | clang_analyzer_eval(n == 0); //expected-warning{{FALSE}} | ||||

1285 | //expected-warning@-1{{TRUE}} | ||||

1286 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1287 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1288 | } else if (n < 0x80000000) { | ||||

1289 | clang_analyzer_eval(n < C2); //expected-warning{{FALSE}} | ||||

1290 | clang_analyzer_eval(n == C2); //expected-warning{{TRUE}} | ||||

1291 | clang_analyzer_eval(n > C2); //expected-warning{{FALSE}} | ||||

1292 | } else { | ||||

1293 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

1294 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

1295 | clang_analyzer_eval(n <= U3); //expected-warning{{TRUE}} | ||||

1296 | clang_analyzer_eval(n > U3); //expected-warning{{FALSE}} | ||||

1297 | } | ||||

1298 | } | ||||

1299 | } | ||||

1300 | | ||||

1301 | void unsigned_division_le_0(uint32_t n) { | ||||

1302 | if (n / 4 <= 0) { | ||||

1303 | const uint32_t C = 3; | ||||

1304 | | ||||

1305 | assert(C / 4 <= 0); | ||||

1306 | assert((C + 1) / 4 > 0); | ||||

1307 | | ||||

1308 | clang_analyzer_eval(n <= C); //expected-warning{{TRUE}} | ||||

1309 | clang_analyzer_eval(n > C); //expected-warning{{FALSE}} | ||||

1310 | } | ||||

1311 | } | ||||

1312 | | ||||

1313 | void unsigned_division_le_1(uint32_t n) { | ||||

1314 | if (n / 3 <= 2) { | ||||

1315 | const uint32_t C = 8; | ||||

1316 | | ||||

1317 | assert(C / 3 <= 2); | ||||

1318 | assert((C + 1) / 3 > 2); | ||||

1319 | | ||||

1320 | clang_analyzer_eval(n <= C); //expected-warning{{TRUE}} | ||||

1321 | clang_analyzer_eval(n > C); //expected-warning{{FALSE}} | ||||

1322 | } | ||||

1323 | } | ||||

1324 | | ||||

1325 | void signed_multiplication_gt_0(int32_t n) { | ||||

1326 | if (n * 2 > 3) { | ||||

1327 | int32_t L1 = 0x80000002, U1 = 0xbfffffff, | ||||

1328 | L2 = 2, U2 = 0x3fffffff; | ||||

1329 | | ||||

1330 | assert(L1 * 2 > 3); | ||||

1331 | assert((L1 - 1) * 2 <= 3); | ||||

1332 | assert(U1 * 2 > 3); | ||||

1333 | assert((U1 + 1) * 2 <= 3); | ||||

1334 | assert(L2 * 2 > 3); | ||||

1335 | assert((L2 - 1) * 2 <= 3); | ||||

1336 | assert(U2 * 2 > 3); | ||||

1337 | assert((U2 + 1) * 2 <= 3); | ||||

1338 | | ||||

1339 | if (n < 0) { | ||||

1340 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1341 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1342 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1343 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1344 | } else { | ||||

1345 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1346 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1347 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1348 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1349 | } | ||||

1350 | } | ||||

1351 | } | ||||

1352 | | ||||

1353 | void signed_multiplication_gt_1(int32_t n) { | ||||

1354 | if (n * 2 > 4) { | ||||

1355 | int32_t L1 = 0x80000003, U1 = 0xbfffffff, | ||||

1356 | L2 = 3, U2 = 0x3fffffff; | ||||

1357 | | ||||

1358 | assert(L1 * 2 > 4); | ||||

1359 | assert((L1 - 1) * 2 <= 4); | ||||

1360 | assert(U1 * 2 > 4); | ||||

1361 | assert((U1 + 1) * 2 <= 4); | ||||

1362 | assert(L2 * 2 > 4); | ||||

1363 | assert((L2 - 1) * 2 <= 4); | ||||

1364 | assert(U2 * 2 > 4); | ||||

1365 | assert((U2 + 1) * 2 <= 4); | ||||

1366 | | ||||

1367 | if (n < 0) { | ||||

1368 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1369 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1370 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1371 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1372 | } else { | ||||

1373 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1374 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1375 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1376 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1377 | } | ||||

1378 | } | ||||

1379 | } | ||||

1380 | | ||||

1381 | void signed_multiplication_gt_2(int32_t n) { | ||||

1382 | if (n * 2 > 5) { | ||||

1383 | int32_t L1 = 0x80000003, U1 = 0xbfffffff, | ||||

1384 | L2 = 3, U2 = 0x3fffffff; | ||||

1385 | | ||||

1386 | assert(L1 * 2 > 5); | ||||

1387 | assert((L1 - 1) * 2 <= 5); | ||||

1388 | assert(U1 * 2 > 5); | ||||

1389 | assert((U1 + 1) * 2 <= 5); | ||||

1390 | assert(L2 * 2 > 5); | ||||

1391 | assert((L2 - 1) * 2 <= 5); | ||||

1392 | assert(U2 * 2 > 5); | ||||

1393 | assert((U2 + 1) * 2 <= 5); | ||||

1394 | | ||||

1395 | if (n < 0) { | ||||

1396 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1397 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1398 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1399 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1400 | } else { | ||||

1401 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1402 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1403 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1404 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1405 | } | ||||

1406 | } | ||||

1407 | } | ||||

1408 | | ||||

1409 | void signed_multiplication_gt_3(int32_t n) { | ||||

1410 | if (n * 3 > 4) { | ||||

1411 | int32_t L1 = 0xaaaaaaad, U1 = 0xd5555555, | ||||

1412 | L2 = 2, U2 = 0x2aaaaaaa, | ||||

1413 | L3 = 0x55555557; | ||||

1414 | | ||||

1415 | assert(L1 * 3 > 4); | ||||

1416 | assert((L1 - 1) * 3 <= 4); | ||||

1417 | assert(U1 * 3 > 4); | ||||

1418 | assert((U1 + 1) * 3 <= 4); | ||||

1419 | assert(L2 * 3 > 4); | ||||

1420 | assert((L2 - 1) * 3 <= 4); | ||||

1421 | assert(U2 * 3 > 4); | ||||

1422 | assert((U2 + 1) * 3 <= 4); | ||||

1423 | assert(L3 * 3 > 4); | ||||

1424 | assert((L3 - 1) * 3 <= 4); | ||||

1425 | assert(INT_MAX * 3 > 4); | ||||

1426 | | ||||

1427 | if (n < 0) { | ||||

1428 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1429 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1430 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1431 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1432 | } else if (n < INT_MAX / 2) { | ||||

1433 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1434 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1435 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1436 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1437 | } else { | ||||

1438 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

1439 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

1440 | clang_analyzer_eval(n == INT_MAX); //expected-warning{{FALSE}} | ||||

1441 | //expected-warning@-1{{TRUE}} | ||||

1442 | } | ||||

1443 | } | ||||

1444 | } | ||||

1445 | | ||||

1446 | void signed_multiplication_gt_4(int32_t n) { | ||||

1447 | if (n * 6 > -2) { | ||||

1448 | int32_t U1 = 0x95555555, | ||||

1449 | L2 = 0xaaaaaaab, U2 = 0xbfffffff, | ||||

1450 | L3 = 0xd5555556, U3 = 0xeaaaaaaa, | ||||

1451 | L4 = 0, U4 = 0x15555555, | ||||

1452 | L5 = 0x2aaaaaab, U5 = 0x3fffffff, | ||||

1453 | L6 = 0x55555556, U6 = 0x6aaaaaaa; | ||||

1454 | | ||||

1455 | assert(INT_MIN * 6 > -2); | ||||

1456 | assert(U1 * 6 > -2); | ||||

1457 | assert((U1 + 1) * 6 <= -2); | ||||

1458 | assert(L2 * 6 > -2); | ||||

1459 | assert((L2 - 1) * 6 <= -2); | ||||

1460 | assert(U2 * 6 > -2); | ||||

1461 | assert((U2 + 1) * 6 <= -2); | ||||

1462 | assert(L3 * 6 > -2); | ||||

1463 | assert((L3 - 1) * 6 <= -2); | ||||

1464 | assert(U3 * 6 > -2); | ||||

1465 | assert((U3 + 1) * 6 <= -2); | ||||

1466 | assert(L4 * 6 > -2); | ||||

1467 | assert((L4 - 1) * 6 <= -2); | ||||

1468 | assert(U4 * 6 > -2); | ||||

1469 | assert((U4 + 1) * 6 <= -2); | ||||

1470 | assert(L5 * 6 > -2); | ||||

1471 | assert((L5 - 1) * 6 <= -2); | ||||

1472 | assert(U5 * 6 > -2); | ||||

1473 | assert((U5 + 1) * 6 <= -2); | ||||

1474 | assert(L6 * 6 > -2); | ||||

1475 | assert((L6 - 1) * 6 <= -2); | ||||

1476 | assert(U6 * 6 > -2); | ||||

1477 | assert((U6 + 1) * 6 <= -2); | ||||

1478 | | ||||

1479 | if (n < (int32_t) 0xa0000000) { | ||||

1480 | clang_analyzer_eval(n == INT_MIN); //expected-warning{{FALSE}} | ||||

1481 | //expected-warning@-1{{TRUE}} | ||||

1482 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1483 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1484 | } else if (n < (int32_t) 0xcaaaaaaa) { | ||||

1485 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1486 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1487 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1488 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1489 | } else if (n < (int32_t) 0xf5555555) { | ||||

1490 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

1491 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

1492 | clang_analyzer_eval(n <= U3); //expected-warning{{TRUE}} | ||||

1493 | clang_analyzer_eval(n > U3); //expected-warning{{FALSE}} | ||||

1494 | } else if (n < (int32_t) 0x20000000) { | ||||

1495 | clang_analyzer_eval(n < L4); //expected-warning{{FALSE}} | ||||

1496 | clang_analyzer_eval(n >= L4); //expected-warning{{TRUE}} | ||||

1497 | clang_analyzer_eval(n <= U4); //expected-warning{{TRUE}} | ||||

1498 | clang_analyzer_eval(n > U4); //expected-warning{{FALSE}} | ||||

1499 | } else if (n < (int32_t) 0x4aaaaaaa) { | ||||

1500 | clang_analyzer_eval(n < L5); //expected-warning{{FALSE}} | ||||

1501 | clang_analyzer_eval(n >= L5); //expected-warning{{TRUE}} | ||||

1502 | clang_analyzer_eval(n <= U5); //expected-warning{{TRUE}} | ||||

1503 | clang_analyzer_eval(n > U5); //expected-warning{{FALSE}} | ||||

1504 | } else { | ||||

1505 | clang_analyzer_eval(n < L6); //expected-warning{{FALSE}} | ||||

1506 | clang_analyzer_eval(n >= L6); //expected-warning{{TRUE}} | ||||

1507 | clang_analyzer_eval(n <= U6); //expected-warning{{TRUE}} | ||||

1508 | clang_analyzer_eval(n > U6); //expected-warning{{FALSE}} | ||||

1509 | } | ||||

1510 | } | ||||

1511 | } | ||||

1512 | | ||||

1513 | void signed_division_gt_0(int32_t n) { | ||||

1514 | if (n / 4 > 0) { | ||||

1515 | const int32_t C = 4; | ||||

1516 | | ||||

1517 | assert(C / 4 > 0); | ||||

1518 | assert((C - 1) / 4 <= 0); | ||||

1519 | | ||||

1520 | clang_analyzer_eval(n >= C); //expected-warning{{TRUE}} | ||||

1521 | clang_analyzer_eval(n < C); //expected-warning{{FALSE}} | ||||

1522 | } | ||||

1523 | } | ||||

1524 | | ||||

1525 | void signed_division_gt_1(int32_t n) { | ||||

1526 | if (n / 3 > 2) { | ||||

1527 | const int32_t C = 9; | ||||

1528 | | ||||

1529 | assert(C / 3 > 2); | ||||

1530 | assert((C - 1) / 3 <= 2); | ||||

1531 | | ||||

1532 | clang_analyzer_eval(n >= C); //expected-warning{{TRUE}} | ||||

1533 | clang_analyzer_eval(n < C); //expected-warning{{FALSE}} | ||||

1534 | } | ||||

1535 | } | ||||

1536 | | ||||

1537 | void signed_division_gt_2(int32_t n) { | ||||

1538 | if (n / 5 > -7) { | ||||

1539 | const int32_t C = -34; | ||||

1540 | | ||||

1541 | assert(C / 5 > -7); | ||||

1542 | assert((C - 1) / 5 <= -7); | ||||

1543 | | ||||

1544 | clang_analyzer_eval(n >= C); //expected-warning{{TRUE}} | ||||

1545 | clang_analyzer_eval(n < C); //expected-warning{{FALSE}} | ||||

1546 | } | ||||

1547 | } | ||||

1548 | | ||||

1549 | void unsigned_multiplication_gt_0(uint32_t n) { | ||||

1550 | if (n * 2 > 3) { | ||||

1551 | uint32_t L1 = 2, U1 = 0x7fffffff, | ||||

1552 | L2 = 0x80000002; | ||||

1553 | | ||||

1554 | assert(L1 * 2 > 3); | ||||

1555 | assert((L1 - 1) * 2 <= 3); | ||||

1556 | assert(U1 * 2 > 3); | ||||

1557 | assert((U1 + 1) * 2 <= 3); | ||||

1558 | assert(L2 * 2 > 3); | ||||

1559 | assert((L2 - 1) * 2 <= 3); | ||||

1560 | assert(UINT_MAX * 2 > 3); | ||||

1561 | | ||||

1562 | if (n < UINT_MAX / 2 + 1) { | ||||

1563 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1564 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1565 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1566 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1567 | } else { | ||||

1568 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1569 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1570 | clang_analyzer_eval(n == UINT_MAX); //expected-warning{{FALSE}} | ||||

1571 | //expected-warning@-1{{TRUE}} | ||||

1572 | } | ||||

1573 | } | ||||

1574 | } | ||||

1575 | | ||||

1576 | void unsigned_multiplication_gt_1(uint32_t n) { | ||||

1577 | if (n * 2 > 4) { | ||||

1578 | uint32_t L1 = 3, U1 = 0x7fffffff, | ||||

1579 | L2 = 0x80000003; | ||||

1580 | | ||||

1581 | assert(L1 * 2 > 4); | ||||

1582 | assert((L1 - 1) * 2 <= 4); | ||||

1583 | assert(U1 * 2 > 4); | ||||

1584 | assert((U1 + 1) * 2 <= 4); | ||||

1585 | assert(L2 * 2 > 4); | ||||

1586 | assert((L2 - 1) * 2 <= 4); | ||||

1587 | assert(UINT_MAX * 2 > 4); | ||||

1588 | | ||||

1589 | if (n < UINT_MAX / 2 + 1) { | ||||

1590 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1591 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1592 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1593 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1594 | } else { | ||||

1595 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1596 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1597 | clang_analyzer_eval(n == UINT_MAX); //expected-warning{{FALSE}} | ||||

1598 | //expected-warning@-1{{TRUE}} | ||||

1599 | } | ||||

1600 | } | ||||

1601 | } | ||||

1602 | | ||||

1603 | void unsigned_multiplication_gt_2(uint32_t n) { | ||||

1604 | if (n * 2 > 5) { | ||||

1605 | uint32_t L1 = 3, U1 = 0x7fffffff, | ||||

1606 | L2 = 0x80000003; | ||||

1607 | | ||||

1608 | assert(L1 * 2 > 5); | ||||

1609 | assert((L1 - 1) * 2 <= 5); | ||||

1610 | assert(U1 * 2 > 5); | ||||

1611 | assert((U1 + 1) * 2 <= 5); | ||||

1612 | assert(L2 * 2 > 5); | ||||

1613 | assert((L2 - 1) * 2 <= 5); | ||||

1614 | assert(UINT_MAX * 2 > 5); | ||||

1615 | | ||||

1616 | if (n < UINT_MAX / 2 + 1) { | ||||

1617 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1618 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1619 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1620 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1621 | } else { | ||||

1622 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1623 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1624 | clang_analyzer_eval(n == UINT_MAX); //expected-warning{{FALSE}} | ||||

1625 | //expected-warning@-1{{TRUE}} | ||||

1626 | } | ||||

1627 | } | ||||

1628 | } | ||||

1629 | | ||||

1630 | void unsigned_multiplication_gt_3(uint32_t n) { | ||||

1631 | if (n * 3 > 4) { | ||||

1632 | uint32_t L1 = 2, U1 = 0x55555555, | ||||

1633 | L2 = 0x55555557, U2 = 0xaaaaaaaa, | ||||

1634 | L3 = 0xaaaaaaad; | ||||

1635 | | ||||

1636 | assert(L1 * 3 > 4); | ||||

1637 | assert((L1 - 1) * 3 <= 4); | ||||

1638 | assert(U1 * 3 > 4); | ||||

1639 | assert((U1 + 1) * 3 <= 4); | ||||

1640 | assert(L2 * 3 > 4); | ||||

1641 | assert((L2 - 1) * 3 <= 4); | ||||

1642 | assert(U2 * 3 > 4); | ||||

1643 | assert((U2 + 1) * 3 <= 4); | ||||

1644 | assert(L3 * 3 > 4); | ||||

1645 | assert((L3 - 1) * 3 <= 4); | ||||

1646 | assert(INT_MAX * 3 > 4); | ||||

1647 | | ||||

1648 | if (n < UINT_MAX / 3 + 1) { | ||||

1649 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1650 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1651 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1652 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1653 | } else if (n < 2 * (UINT_MAX / 3 + 1)) { | ||||

1654 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1655 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1656 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1657 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1658 | } else { | ||||

1659 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

1660 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

1661 | clang_analyzer_eval(n == UINT_MAX); //expected-warning{{FALSE}} | ||||

1662 | //expected-warning@-1{{TRUE}} | ||||

1663 | } | ||||

1664 | } | ||||

1665 | } | ||||

1666 | | ||||

1667 | void unsigned_division_gt_0(uint32_t n) { | ||||

1668 | if (n / 4 > 0) { | ||||

1669 | const uint32_t C = 4; | ||||

1670 | | ||||

1671 | assert(C / 4 > 0); | ||||

1672 | assert((C - 1) / 4 <= 0); | ||||

1673 | | ||||

1674 | clang_analyzer_eval(n >= C); //expected-warning{{TRUE}} | ||||

1675 | clang_analyzer_eval(n < C); //expected-warning{{FALSE}} | ||||

1676 | } | ||||

1677 | } | ||||

1678 | | ||||

1679 | void unsigned_division_gt_1(uint32_t n) { | ||||

1680 | if (n / 3 > 2) { | ||||

1681 | const uint32_t C = 9; | ||||

1682 | | ||||

1683 | assert(C / 3 > 2); | ||||

1684 | assert((C - 1) / 3 <= 2); | ||||

1685 | | ||||

1686 | clang_analyzer_eval(n >= C); //expected-warning{{TRUE}} | ||||

1687 | clang_analyzer_eval(n < C); //expected-warning{{FALSE}} | ||||

1688 | } | ||||

1689 | } | ||||

1690 | | ||||

1691 | void signed_multiplication_ge_0(int32_t n) { | ||||

1692 | if (n * 2 >= 3) { | ||||

1693 | int32_t L1 = 0x80000002, U1 = 0xbfffffff, | ||||

1694 | L2 = 2, U2 = 0x3fffffff; | ||||

1695 | | ||||

1696 | assert(L1 * 2 >= 3); | ||||

1697 | assert((L1 - 1) * 2 < 3); | ||||

1698 | assert(U1 * 2 >= 3); | ||||

1699 | assert((U1 + 1) * 2 < 3); | ||||

1700 | assert(L2 * 2 >= 3); | ||||

1701 | assert((L2 - 1) * 2 < 3); | ||||

1702 | assert(U2 * 2 >= 3); | ||||

1703 | assert((U2 + 1) * 2 < 3); | ||||

1704 | | ||||

1705 | if (n < 0) { | ||||

1706 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1707 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1708 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1709 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1710 | } else { | ||||

1711 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1712 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1713 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1714 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1715 | } | ||||

1716 | } | ||||

1717 | } | ||||

1718 | | ||||

1719 | void signed_multiplication_ge_1(int32_t n) { | ||||

1720 | if (n * 2 >= 4) { | ||||

1721 | int32_t L1 = 0x80000002, U1 = 0xbfffffff, | ||||

1722 | L2 = 2, U2 = 0x3fffffff; | ||||

1723 | | ||||

1724 | assert(L1 * 2 >= 4); | ||||

1725 | assert((L1 - 1) * 2 < 4); | ||||

1726 | assert(U1 * 2 >= 4); | ||||

1727 | assert((U1 + 1) * 2 < 4); | ||||

1728 | assert(L2 * 2 >= 4); | ||||

1729 | assert((L2 - 1) * 2 < 4); | ||||

1730 | assert(U2 * 2 >= 4); | ||||

1731 | assert((U2 + 1) * 2 < 4); | ||||

1732 | | ||||

1733 | if (n < 0) { | ||||

1734 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1735 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1736 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1737 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1738 | } else { | ||||

1739 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1740 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1741 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1742 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1743 | } | ||||

1744 | } | ||||

1745 | } | ||||

1746 | | ||||

1747 | void signed_multiplication_ge_2(int32_t n) { | ||||

1748 | if (n * 2 >= 5) { | ||||

1749 | int32_t L1 = 0x80000003, U1 = 0xbfffffff, | ||||

1750 | L2 = 3, U2 = 0x3fffffff; | ||||

1751 | | ||||

1752 | assert(L1 * 2 >= 5); | ||||

1753 | assert((L1 - 1) * 2 < 5); | ||||

1754 | assert(U1 * 2 >= 5); | ||||

1755 | assert((U1 + 1) * 2 < 5); | ||||

1756 | assert(L2 * 2 >= 5); | ||||

1757 | assert((L2 - 1) * 2 < 5); | ||||

1758 | assert(U2 * 2 >= 5); | ||||

1759 | assert((U2 + 1) * 2 < 5); | ||||

1760 | | ||||

1761 | if (n < 0) { | ||||

1762 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1763 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1764 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1765 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1766 | } else { | ||||

1767 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1768 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1769 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1770 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1771 | } | ||||

1772 | } | ||||

1773 | } | ||||

1774 | | ||||

1775 | void signed_multiplication_ge_3(int32_t n) { | ||||

1776 | if (n * 3 >= 4) { | ||||

1777 | int32_t L1 = 0xaaaaaaac, U1 = 0xd5555555, | ||||

1778 | L2 = 2, U2 = 0x2aaaaaaa, | ||||

1779 | L3 = 0x55555557; | ||||

1780 | | ||||

1781 | assert(L1 * 3 >= 4); | ||||

1782 | assert((L1 - 1) * 3 < 4); | ||||

1783 | assert(U1 * 3 >= 4); | ||||

1784 | assert((U1 + 1) * 3 < 4); | ||||

1785 | assert(L2 * 3 >= 4); | ||||

1786 | assert((L2 - 1) * 3 < 4); | ||||

1787 | assert(U2 * 3 >= 4); | ||||

1788 | assert((U2 + 1) * 3 < 4); | ||||

1789 | assert(L3 * 3 >= 4); | ||||

1790 | assert((L3 - 1) * 3 < 4); | ||||

1791 | assert(INT_MAX * 3 >= 4); | ||||

1792 | | ||||

1793 | if (n < 0) { | ||||

1794 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1795 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1796 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1797 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1798 | } else if (n < INT_MAX / 2) { | ||||

1799 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1800 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1801 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1802 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1803 | } else { | ||||

1804 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

1805 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

1806 | clang_analyzer_eval(n == INT_MAX); //expected-warning{{FALSE}} | ||||

1807 | //expected-warning@-1{{TRUE}} | ||||

1808 | } | ||||

1809 | } | ||||

1810 | } | ||||

1811 | | ||||

1812 | void signed_multiplication_ge_4(int32_t n) { | ||||

1813 | if (n * 6 >= -2) { | ||||

1814 | int32_t U1 = 0x95555555, | ||||

1815 | L2 = 0xaaaaaaab, U2 = 0xbfffffff, | ||||

1816 | L3 = 0xd5555555, U3 = 0xeaaaaaaa, | ||||

1817 | L4 = 0, U4 = 0x15555555, | ||||

1818 | L5 = 0x2aaaaaab, U5 = 0x3fffffff, | ||||

1819 | L6 = 0x55555555, U6 = 0x6aaaaaaa; | ||||

1820 | | ||||

1821 | assert(INT_MIN * 6 >= -2); | ||||

1822 | assert(U1 * 6 >= -2); | ||||

1823 | assert((U1 + 1) * 6 < -2); | ||||

1824 | assert(L2 * 6 >= -2); | ||||

1825 | assert((L2 - 1) * 6 < -2); | ||||

1826 | assert(U2 * 6 >= -2); | ||||

1827 | assert((U2 + 1) * 6 < -2); | ||||

1828 | assert(L3 * 6 >= -2); | ||||

1829 | assert((L3 - 1) * 6 < -2); | ||||

1830 | assert(U3 * 6 >= -2); | ||||

1831 | assert((U3 + 1) * 6 < -2); | ||||

1832 | assert(L4 * 6 >= -2); | ||||

1833 | assert((L4 - 1) * 6 < -2); | ||||

1834 | assert(U4 * 6 >= -2); | ||||

1835 | assert((U4 + 1) * 6 < -2); | ||||

1836 | assert(L5 * 6 >= -2); | ||||

1837 | assert((L5 - 1) * 6 < -2); | ||||

1838 | assert(U5 * 6 >= -2); | ||||

1839 | assert((U5 + 1) * 6 < -2); | ||||

1840 | assert(L6 * 6 >= -2); | ||||

1841 | assert((L6 - 1) * 6 < -2); | ||||

1842 | assert(U6 * 6 >= -2); | ||||

1843 | assert((U6 + 1) * 6 < -2); | ||||

1844 | | ||||

1845 | if (n < (int32_t) 0xa0000000) { | ||||

1846 | clang_analyzer_eval(n == INT_MIN); //expected-warning{{FALSE}} | ||||

1847 | //expected-warning@-1{{TRUE}} | ||||

1848 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1849 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1850 | } else if (n < (int32_t) 0xcaaaaaaa) { | ||||

1851 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1852 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1853 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

1854 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

1855 | } else if (n < (int32_t) 0xf5555555) { | ||||

1856 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

1857 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

1858 | clang_analyzer_eval(n <= U3); //expected-warning{{TRUE}} | ||||

1859 | clang_analyzer_eval(n > U3); //expected-warning{{FALSE}} | ||||

1860 | } else if (n < (int32_t) 0x20000000) { | ||||

1861 | clang_analyzer_eval(n < L4); //expected-warning{{FALSE}} | ||||

1862 | clang_analyzer_eval(n >= L4); //expected-warning{{TRUE}} | ||||

1863 | clang_analyzer_eval(n <= U4); //expected-warning{{TRUE}} | ||||

1864 | clang_analyzer_eval(n > U4); //expected-warning{{FALSE}} | ||||

1865 | } else if (n < (int32_t) 0x4aaaaaaa) { | ||||

1866 | clang_analyzer_eval(n < L5); //expected-warning{{FALSE}} | ||||

1867 | clang_analyzer_eval(n >= L5); //expected-warning{{TRUE}} | ||||

1868 | clang_analyzer_eval(n <= U5); //expected-warning{{TRUE}} | ||||

1869 | clang_analyzer_eval(n > U5); //expected-warning{{FALSE}} | ||||

1870 | } else { | ||||

1871 | clang_analyzer_eval(n < L6); //expected-warning{{FALSE}} | ||||

1872 | clang_analyzer_eval(n >= L6); //expected-warning{{TRUE}} | ||||

1873 | clang_analyzer_eval(n <= U6); //expected-warning{{TRUE}} | ||||

1874 | clang_analyzer_eval(n > U6); //expected-warning{{FALSE}} | ||||

1875 | } | ||||

1876 | } | ||||

1877 | } | ||||

1878 | | ||||

1879 | void signed_division_ge_0(int32_t n) { | ||||

1880 | if (n / 4 >= 0) { | ||||

1881 | const int32_t C = -3; | ||||

1882 | | ||||

1883 | assert(C / 4 >= 0); | ||||

1884 | assert((C - 1) / 4 < 0); | ||||

1885 | | ||||

1886 | clang_analyzer_eval(n >= C); //expected-warning{{TRUE}} | ||||

1887 | clang_analyzer_eval(n < C); //expected-warning{{FALSE}} | ||||

1888 | } | ||||

1889 | } | ||||

1890 | | ||||

1891 | void signed_division_ge_1(int32_t n) { | ||||

1892 | if (n / 3 >= 2) { | ||||

1893 | const int32_t C = 6; | ||||

1894 | | ||||

1895 | assert(C / 3 >= 2); | ||||

1896 | assert((C - 1) / 3 < 2); | ||||

1897 | | ||||

1898 | clang_analyzer_eval(n >= C); //expected-warning{{TRUE}} | ||||

1899 | clang_analyzer_eval(n < C); //expected-warning{{FALSE}} | ||||

1900 | } | ||||

1901 | } | ||||

1902 | | ||||

1903 | void signed_division_ge_2(int32_t n) { | ||||

1904 | if (n / 5 >= -7) { | ||||

1905 | const int32_t C = -39; | ||||

1906 | | ||||

1907 | assert(C / 5 >= -7); | ||||

1908 | assert((C - 1) / 5 < -7); | ||||

1909 | | ||||

1910 | clang_analyzer_eval(n >= C); //expected-warning{{TRUE}} | ||||

1911 | clang_analyzer_eval(n < C); //expected-warning{{FALSE}} | ||||

1912 | } | ||||

1913 | } | ||||

1914 | | ||||

1915 | void unsigned_multiplication_ge_0(uint32_t n) { | ||||

1916 | if (n * 2 >= 3) { | ||||

1917 | uint32_t L1 = 2, U1 = 0x7fffffff, | ||||

1918 | L2 = 0x80000002; | ||||

1919 | | ||||

1920 | assert(L1 * 2 >= 3); | ||||

1921 | assert((L1 - 1) * 2 < 3); | ||||

1922 | assert(U1 * 2 >= 3); | ||||

1923 | assert((U1 + 1) * 2 < 3); | ||||

1924 | assert(L2 * 2 >= 3); | ||||

1925 | assert((L2 - 1) * 2 < 3); | ||||

1926 | assert(UINT_MAX * 2 >= 3); | ||||

1927 | | ||||

1928 | if (n < UINT_MAX / 2 + 1) { | ||||

1929 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1930 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1931 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1932 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1933 | } else { | ||||

1934 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1935 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1936 | clang_analyzer_eval(n == UINT_MAX); //expected-warning{{FALSE}} | ||||

1937 | //expected-warning@-1{{TRUE}} | ||||

1938 | } | ||||

1939 | } | ||||

1940 | } | ||||

1941 | | ||||

1942 | void unsigned_multiplication_ge_1(uint32_t n) { | ||||

1943 | if (n * 2 >= 4) { | ||||

1944 | uint32_t L1 = 2, U1 = 0x7fffffff, | ||||

1945 | L2 = 0x80000002; | ||||

1946 | | ||||

1947 | assert(L1 * 2 >= 4); | ||||

1948 | assert((L1 - 1) * 2 < 4); | ||||

1949 | assert(U1 * 2 >= 4); | ||||

1950 | assert((U1 + 1) * 2 < 4); | ||||

1951 | assert(L2 * 2 >= 4); | ||||

1952 | assert((L2 - 1) * 2 < 4); | ||||

1953 | assert(UINT_MAX * 2 >= 4); | ||||

1954 | | ||||

1955 | if (n < UINT_MAX / 2 + 1) { | ||||

1956 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1957 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1958 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1959 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1960 | } else { | ||||

1961 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1962 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1963 | clang_analyzer_eval(n == UINT_MAX); //expected-warning{{FALSE}} | ||||

1964 | //expected-warning@-1{{TRUE}} | ||||

1965 | } | ||||

1966 | } | ||||

1967 | } | ||||

1968 | | ||||

1969 | void unsigned_multiplication_ge_2(uint32_t n) { | ||||

1970 | if (n * 2 >= 5) { | ||||

1971 | uint32_t L1 = 3, U1 = 0x7fffffff, | ||||

1972 | L2 = 0x80000003; | ||||

1973 | | ||||

1974 | assert(L1 * 2 >= 5); | ||||

1975 | assert((L1 - 1) * 2 < 5); | ||||

1976 | assert(U1 * 2 >= 5); | ||||

1977 | assert((U1 + 1) * 2 < 5); | ||||

1978 | assert(L2 * 2 >= 5); | ||||

1979 | assert((L2 - 1) * 2 < 5); | ||||

1980 | assert(UINT_MAX * 2 >= 5); | ||||

1981 | | ||||

1982 | if (n < UINT_MAX / 2 + 1) { | ||||

1983 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

1984 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

1985 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

1986 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

1987 | } else { | ||||

1988 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

1989 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

1990 | clang_analyzer_eval(n == UINT_MAX); //expected-warning{{FALSE}} | ||||

1991 | //expected-warning@-1{{TRUE}} | ||||

1992 | } | ||||

1993 | } | ||||

1994 | } | ||||

1995 | | ||||

1996 | void unsigned_multiplication_ge_3(uint32_t n) { | ||||

1997 | if (n * 3 >= 4) { | ||||

1998 | uint32_t L1 = 2, U1 = 0x55555555, | ||||

1999 | L2 = 0x55555557, U2 = 0xaaaaaaaa, | ||||

2000 | L3 = 0xaaaaaaac; | ||||

2001 | | ||||

2002 | assert(L1 * 3 >= 4); | ||||

2003 | assert((L1 - 1) * 3 < 4); | ||||

2004 | assert(U1 * 3 >= 4); | ||||

2005 | assert((U1 + 1) * 3 < 4); | ||||

2006 | assert(L2 * 3 >= 4); | ||||

2007 | assert((L2 - 1) * 3 < 4); | ||||

2008 | assert(U2 * 3 >= 4); | ||||

2009 | assert((U2 + 1) * 3 < 4); | ||||

2010 | assert(L3 * 3 >= 4); | ||||

2011 | assert((L3 - 1) * 3 < 4); | ||||

2012 | assert(INT_MAX * 3 >= 4); | ||||

2013 | | ||||

2014 | if (n < UINT_MAX / 3 + 1) { | ||||

2015 | clang_analyzer_eval(n < L1); //expected-warning{{FALSE}} | ||||

2016 | clang_analyzer_eval(n >= L1); //expected-warning{{TRUE}} | ||||

2017 | clang_analyzer_eval(n <= U1); //expected-warning{{TRUE}} | ||||

2018 | clang_analyzer_eval(n > U1); //expected-warning{{FALSE}} | ||||

2019 | } else if (n < 2 * (UINT_MAX / 3 + 1)) { | ||||

2020 | clang_analyzer_eval(n < L2); //expected-warning{{FALSE}} | ||||

2021 | clang_analyzer_eval(n >= L2); //expected-warning{{TRUE}} | ||||

2022 | clang_analyzer_eval(n <= U2); //expected-warning{{TRUE}} | ||||

2023 | clang_analyzer_eval(n > U2); //expected-warning{{FALSE}} | ||||

2024 | } else { | ||||

2025 | clang_analyzer_eval(n < L3); //expected-warning{{FALSE}} | ||||

2026 | clang_analyzer_eval(n >= L3); //expected-warning{{TRUE}} | ||||

2027 | clang_analyzer_eval(n == UINT_MAX); //expected-warning{{FALSE}} | ||||

2028 | //expected-warning@-1{{TRUE}} | ||||

2029 | } | ||||

2030 | } | ||||

2031 | } | ||||

2032 | | ||||

2033 | void unsigned_division_ge_0(uint32_t n) { | ||||

2034 | if (n / 3 >= 2) { | ||||

2035 | const uint32_t C = 6; | ||||

2036 | | ||||

2037 | assert(C / 3 >= 2); | ||||

2038 | assert((C - 1) / 3 < 2); | ||||

2039 | | ||||

2040 | clang_analyzer_eval(n >= C); //expected-warning{{TRUE}} | ||||

2041 | clang_analyzer_eval(n < C); //expected-warning{{FALSE}} | ||||

2042 | } | ||||

2043 | } | ||||

2044 | | ||||

573 | void additive(int32_t n) { | 2045 | void additive(int32_t n) { | ||

574 | if (n * 2 + 1 == 4) { | 2046 | if (n * 2 + 1 == 4) { | ||

575 | clang_analyzer_warnIfReached(); // no-warning | 2047 | clang_analyzer_warnIfReached(); // no-warning | ||

576 | 2048 | | |||

577 | } else if (n * 4 - 1 == 15) { | 2049 | } else if (n * 4 - 1 == 15) { | ||

578 | const int32_t C1 = 0x80000004, C2 = 0xc0000004, C3 = 4, C4 = 0x40000004; | 2050 | const int32_t C1 = 0x80000004, C2 = 0xc0000004, C3 = 4, C4 = 0x40000004; | ||

579 | 2051 | | |||

580 | assert(C1 * 4 - 1 == 15); | 2052 | assert(C1 * 4 - 1 == 15); | ||

▲ Show 20 Lines • Show All 106 Lines • Show Last 20 Lines |