[llvm-bugs] [Bug 48541] New: [clang-analyzer] False report about moved-from object with coroutines

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 17 07:18:47 PST 2020


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

            Bug ID: 48541
           Summary: [clang-analyzer] False report about moved-from object
                    with coroutines
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: dmitry.polukhin at gmail.com
                CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org

Minimal reproducer is a bit long due to coroutine boilerplate
https://godbolt.org/z/P3P6ax:

#include <string>

namespace std {
namespace experimental {

template <class Ret, typename... T>
struct coroutine_traits { using promise_type = typename Ret::promise_type; };

template <class Promise = void>
struct coroutine_handle {
  static coroutine_handle from_address(void *) noexcept;
};
template <>
struct coroutine_handle<void> {
  template <class PromiseType>
  coroutine_handle(coroutine_handle<PromiseType>) noexcept;
  static coroutine_handle from_address(void *);
};

struct suspend_always {
  bool await_ready() noexcept { return false; }
  void await_suspend(coroutine_handle<>) noexcept {}
  void await_resume() noexcept {}
};

struct suspend_never {
  bool await_ready() { return true; }
  void await_suspend(coroutine_handle<>) {}
  void await_resume() {}
};

} // namespace experimental
} // namespace std

namespace folly {
namespace coro {

using std::experimental::suspend_always;
using std::experimental::suspend_never;
using std::experimental::coroutine_handle;

template<class T>
struct Task {
    struct promise_type {
        Task<T> get_return_object();
        suspend_always initial_suspend();
        suspend_always final_suspend() noexcept;
        void return_value(T);
        void unhandled_exception();
        auto yield_value(Task<T>) { return final_suspend(); }
    };
    bool await_ready() { return false; }
    void await_suspend(coroutine_handle<>) {}
    T await_resume();
};

template<>
struct Task<void> {
    struct promise_type {
        Task<void> get_return_object();
        suspend_always initial_suspend();
        suspend_always final_suspend();
        void return_void();
        void unhandled_exception();
        auto yield_value(Task<void>) { return final_suspend(); }
    };
    bool await_ready() { return false; }
    void await_suspend(coroutine_handle<>) {}
    void await_resume() {}
};

}} // namespace folly::coro

folly::coro::Task<std::string> foo() {
  std::string operationsMap;
  co_return operationsMap;
}

Command line options: -std=c++17 -fcoroutines-ts

<source>:76:13: warning: Moved-from object 'operationsMap' of type
'std::basic_string' is moved [clang-analyzer-cplusplus.Move]
  co_return operationsMap;
            ^
<source>:76:13: note: Object 'operationsMap' of type 'std::basic_string' is
left in a valid but unspecified state after move
<source>:76:13: note: Moved-from object 'operationsMap' of type
'std::basic_string' is moved
1 warning 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/20201217/a55aea48/attachment.html>


More information about the llvm-bugs mailing list