CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
89 lines
2.0 KiB
C++
89 lines
2.0 KiB
C++
// Test for PR59221. Tests the compiler wouldn't misoptimize the final result.
|
|
//
|
|
// REQUIRES: x86-registered-target
|
|
//
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 %s -O1 -emit-llvm -o - | FileCheck %s
|
|
|
|
#include "Inputs/coroutine.h"
|
|
|
|
template <typename T> struct task {
|
|
struct promise_type {
|
|
T value{123};
|
|
std::coroutine_handle<> caller{std::noop_coroutine()};
|
|
|
|
struct final_awaiter: std::suspend_always {
|
|
auto await_suspend(std::coroutine_handle<promise_type> me) const noexcept {
|
|
return me.promise().caller;
|
|
}
|
|
};
|
|
|
|
constexpr auto initial_suspend() const noexcept {
|
|
return std::suspend_always();
|
|
}
|
|
constexpr auto final_suspend() const noexcept {
|
|
return final_awaiter{};
|
|
}
|
|
auto unhandled_exception() noexcept {
|
|
// ignore
|
|
}
|
|
constexpr void return_value(T v) noexcept {
|
|
value = v;
|
|
}
|
|
constexpr auto & get_return_object() noexcept {
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
using coroutine_handle = std::coroutine_handle<promise_type>;
|
|
|
|
promise_type & promise{nullptr};
|
|
|
|
task(promise_type & p) noexcept: promise{p} { }
|
|
|
|
~task() noexcept {
|
|
coroutine_handle::from_promise(promise).destroy();
|
|
}
|
|
|
|
auto await_ready() noexcept {
|
|
return false;
|
|
}
|
|
|
|
auto await_suspend(std::coroutine_handle<> caller) noexcept {
|
|
promise.caller = caller;
|
|
return coroutine_handle::from_promise(promise);
|
|
}
|
|
|
|
constexpr auto await_resume() const noexcept {
|
|
return promise.value;
|
|
}
|
|
|
|
// non-coroutine access to result
|
|
auto get() noexcept {
|
|
const auto handle = coroutine_handle::from_promise(promise);
|
|
|
|
if (!handle.done()) {
|
|
handle.resume();
|
|
}
|
|
|
|
return promise.value;
|
|
}
|
|
};
|
|
|
|
|
|
static inline auto a() noexcept -> task<int> {
|
|
co_return 42;
|
|
}
|
|
|
|
static inline auto test() noexcept -> task<int> {
|
|
co_return co_await a();
|
|
}
|
|
|
|
int foo() {
|
|
return test().get();
|
|
}
|
|
|
|
// Checks that the store for the result value 42 is not misoptimized out.
|
|
// CHECK: define{{.*}}_Z3foov(
|
|
// CHECK: store i32 42, ptr %{{.*}}
|
|
// CHECK: }
|