[llvm-bugs] [Bug 40101] New: __assume not handled correctly by clang-cl static analyzer

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Dec 19 10:46:38 PST 2018


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

            Bug ID: 40101
           Summary: __assume not handled correctly by clang-cl static
                    analyzer
           Product: clang
           Version: 7.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: steveire at gmail.com
                CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org

Using this file:



#if _MSC_VER
#define ASSUME(COND) __assume((COND))
#else
#define ASSUME(COND) do { if (!(COND)) __builtin_unreachable(); } while (0)
#endif

struct A
{
  int someApi();
};

int testAssert(A* a) {
    ASSUME(a != nullptr);
    return a->someApi();
}

int testAssert2(int* a) {
    ASSUME(a != nullptr);
    return *a;
}

int testAssert3(A* a) {
    ASSUME(a);
    return a->someApi();
}

int testAssert4(int* a) {
    ASSUME(a);
    return *a;
}



on linux, I get no output:

$ clang++ --analyze ../tmp/assert.cpp
$


On windows I get false positives:

$ "c:\Program Files\LLVM\bin\clang-cl.exe" --analyze assert.cpp
assert.cpp(16,12):  warning: Called C++ object pointer is null
    return a->someApi();
           ^~~~~~~~~~~~
assert.cpp(21,12):  warning: Dereference of null pointer (loaded from variable
'a')
    return *a;
           ^~
2 warnings generated.

-- 
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/20181219/4684194e/attachment.html>


More information about the llvm-bugs mailing list