================
@@ -0,0 +1,178 @@
+// RUN: %clang_analyze_cc1 -std=c++20 -analyzer-checker=core -verify %s
+
+// Regression test for the Clang Static Analyzer treating a coroutine
+// promise object's data members as uninitialized garbage even when they
+// are guaranteed to be initialized (via in-class default member
+// initializers, a user-provided constructor, brace-init, etc.), because
+// the promise object's construction was never represented in the CFG that
+// the analyzer walks. See the CFG.cpp change to
+// CFG::BuildOptions::AddImplicitCoroutinePromiseConstruction.
+
+namespace std {
+
+template <typename R, typename...> struct coroutine_traits {
+ using promise_type = typename R::promise_type;
+};
+
+template <typename Promise = void> struct coroutine_handle {
+ static coroutine_handle from_address(void *addr) noexcept { return {}; }
+ static coroutine_handle from_promise(Promise &promise) { return {}; }
+ constexpr coroutine_handle() noexcept = default;
+};
+
+template <> struct coroutine_handle<void> {
+ template <typename Promise>
+ coroutine_handle(coroutine_handle<Promise>) noexcept {}
+ static coroutine_handle from_address(void *addr) noexcept { return {}; }
+ constexpr coroutine_handle() noexcept = default;
+};
+
+struct suspend_never {
+ bool await_ready() noexcept { return true; }
+ void await_suspend(coroutine_handle<>) noexcept {}
+ void await_resume() noexcept {}
+};
+
+} // namespace std
+
+struct Ready {
+ bool await_ready() noexcept { return true; }
+ void await_suspend(std::coroutine_handle<>) noexcept {}
+ void await_resume() noexcept {}
+};
+
+using uintptr_t = __UINTPTR_TYPE__;
----------------
NagyDonat wrote:
Are you confident that this is portable and is defined in `clang` for all
targets?
It may be portable, but a quick search did not provide any documentation that
would confirm this. If it is not portable or you are uncertain, it may be
preferable to use a more mundane integer type here. I know that then it
wouldn't be an _exact_ reproducer, but the type seems to be obviously
irrelevant, so this isn't a problem.
https://github.com/llvm/llvm-project/pull/208569
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits