[llvm-bugs] [Bug 49744] New: Can't get any warnings or errors for code full of bugs

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Mar 27 11:20:27 PDT 2021


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

            Bug ID: 49744
           Summary: Can't get any warnings or errors for code full of bugs
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jeanmichael.celerier at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Hello,

consider the following code, ostensibly broken: it assigns a string that lives
on the stack to a string_view, uses another in a reference lambda capture, it's
a mess:

    #include <string>
    #include <string_view>
    #include <functional>
    struct foo
    {
        std::string_view s;
        std::function<void()> v;
    };

    struct bar
    {
        foo* the_foo{};
        void x(foo& f)
        {
            std::string z = "hello";
            f.s = std::string("hello");
            f.v = [&] { printf("%s", z.c_str()); };
            the_foo = &f;
        }

        void y(foo& f)
        {
            printf("%s", f.s.data());
            f.v();
        }
    };

    void do_stuff(bar& b, foo& f)
    {
        b.x(f);
    }

    int main()
    {
        bar b;
        foo f;
        do_stuff(b, f);
        b.y(f);
    }


Yet neither of clang-tidy -checks='*' or -fsanitize=address
-fsanitize=undefined is able to find anything wrong.
At -O3 the output is obviously bogus.
What is missing in the toolchain for detection of such cases, either at
static-analysis-time or at run-time, to work ?

-- 
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/20210327/7dc55647/attachment-0001.html>


More information about the llvm-bugs mailing list