[llvm-bugs] [Bug 44050] New: clang-analyzer-cplusplus.NewDelete false-positive - does not note nullification of ptr after delete

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Nov 18 12:42:01 PST 2019


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

            Bug ID: 44050
           Summary: clang-analyzer-cplusplus.NewDelete false-positive -
                    does not note nullification of ptr after delete
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: lebedev.ri at gmail.com
                CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org

This is manually reduced from a report that i got via CTU mode (yay).
The issue appears to be false-positive:

struct S {
    int *storage;
    ~S() {
        if(!storage)
            return;
        delete storage; // <- we can't 
        storage = nullptr;
    }
};

S producer();

S foo() {
    S imm = producer();
    return imm;
}

S bar() {
    S imm = foo();
    return imm;
}


warning: Attempt to free released memory [clang-analyzer-cplusplus.NewDelete]
        delete storage;
        ^

But how can that happen, after deleting we set it to nullptr?

https://godbolt.org/z/Jkusgy

-- 
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/20191118/485afec1/attachment.html>


More information about the llvm-bugs mailing list