[llvm-bugs] [Bug 46238] New: False negative analyse c++ code in asserts

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Jun 7 21:58:21 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46238

            Bug ID: 46238
           Summary: False negative analyse c++ code in asserts
           Product: clang
           Version: 10.0
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: spider.ch at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Hello.
I found an issue with warnings and asserts.
Let's say we have code:


    #include <cassert>

    enum class State
    {
        A = 0,
        B,
        C,
        D,
        E,
        F
    };

    void ProcessState(State s)
    {
        assert(s > State::A || s < State::E); // < No warning
        (__builtin_expect(!(s > State::A || s < State::E), 0) ?
__assert_rtn(__func__, "main.cpp", 15, "s > State::A || s < State::E") :
(void)0); // < main.cpp:16:38: warning: overlapping comparisons always evaluate
to true [-Wtautological-overlap-compare]
        if (s > State::A || s < State::E) // < main.cpp:17:22: warning:
overlapping comparisons always evaluate to true
[-Wtautological-overlap-compare]
            void(0);
    }

    int main(int, char**)
    {
        ProcessState(State::B);
        return 0;
    }

And compile code with:
    clang++ -std=c++17 -g -O1 -Wtautological-compare main.cpp -o test

There will be no warning on line 15, but there is a mistake. If we move code
from assert to if or change assert with preprocessed code (as in line 16) then
a warning appears.

This behavior was seen in clang 5.0(Maybe and earlier, but I didn't check) and
later.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200608/ff16659e/attachment.html>


More information about the llvm-bugs mailing list