[llvm-bugs] [Bug 48522] New: Missing -Wreturn-local-addr warning with std::move

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Dec 15 11:46:27 PST 2020


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

            Bug ID: 48522
           Summary: Missing -Wreturn-local-addr warning with std::move
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: efriedma at quicinc.com
                CC: aaron at aaronballman.com, htmldeveloper at gmail.com,
                    llvm-bugs at lists.llvm.org, ndesaulniers at google.com,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Testcase:

#include <utility>
const int &byref() {
    int x = 0;
    return std::move(x);
}

This is returning the address of a local variable, but clang doesn't detect it.
 gcc does detect this.

There are a couple ways we could address this:

1. Special-case calls to the symbol std::move.
2. Analyze the loop body of inline functions for a return statement that
returns a reference argument/pointer (sort of like the LLVM IR "returned"
attribute).

The static analyzer's core.StackAddressEscape analysis does correctly warn. 
Not sure how far we want to go in the compiler, but this particular case seems
low-cost/high-impact.

-- 
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/20201215/e7b39856/attachment.html>


More information about the llvm-bugs mailing list