================
@@ -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 {}
+};
----------------
NagyDonat wrote:

Mock standard library definitions are usually placed in files named 
`clang/test/Analysis/Inputs/system-header-simulator-$TOPIC.h`. Consider moving 
this code there.

https://github.com/llvm/llvm-project/pull/208569
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to