diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -58,7 +58,9 @@ DiagGroup<"deprecated-experimental-coroutine">; def DeprecatedCoroutine : DiagGroup<"deprecated-coroutine", [DeprecatedExperimentalCoroutine]>; -def Coroutine : DiagGroup<"coroutine", [CoroutineMissingUnhandledException, DeprecatedCoroutine]>; +def AlwaysInlineCoroutine : + DiagGroup<"always-inline-coroutine">; +def Coroutine : DiagGroup<"coroutine", [CoroutineMissingUnhandledException, DeprecatedCoroutine, AlwaysInlineCoroutine]>; def ObjCBoolConstantConversion : DiagGroup<"objc-bool-constant-conversion">; def ConstantConversion : DiagGroup<"constant-conversion", [BitFieldConstantConversion, diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -11099,6 +11099,10 @@ def note_coroutine_function_declare_noexcept : Note< "must be declared with 'noexcept'" >; +def warn_always_inline_coroutine : Warning< + "A coroutine marked always_inline might not be inlined properly." + >, + InGroup; } // end of coroutines issue category let CategoryName = "Documentation Issue" in { diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp --- a/clang/lib/Sema/SemaCoroutine.cpp +++ b/clang/lib/Sema/SemaCoroutine.cpp @@ -1062,6 +1062,12 @@ return; } + // The coroutine marked always inline might not be inlined properly in current + // compiler support. Only the ramp function is guarantted to be inlined. It + // might be different to what users expects to. Emit a warning to tell it. + if (FD->hasAttr()) + Diag(FD->getLocation(), diag::warn_always_inline_coroutine); + // Coroutines [stmt.return]p1: // A return statement shall not appear in a coroutine. if (Fn->FirstReturnLoc.isValid()) { diff --git a/clang/test/CodeGen/lto-newpm-pipeline.c b/clang/test/CodeGen/lto-newpm-pipeline.c --- a/clang/test/CodeGen/lto-newpm-pipeline.c +++ b/clang/test/CodeGen/lto-newpm-pipeline.c @@ -26,8 +26,9 @@ // RUN: -check-prefix=CHECK-THIN-OPTIMIZED // CHECK-FULL-O0: Running pass: AlwaysInlinerPass -// CHECK-FULL-O0-NEXT: Running analysis: InnerAnalysisManagerProxy // CHECK-FULL-O0-NEXT: Running analysis: ProfileSummaryAnalysis +// CHECK-FULL-O0-NEXT: Running analysis: InnerAnalysisManagerProxy +// CHECK-FULL-O0-NEXT: Running analysis: LazyCallGraphAnalysis // CHECK-FULL-O0: Running pass: CoroSplitPass // CHECK-FULL-O0-NEXT: Running pass: CoroCleanupPass // CHECK-FULL-O0-NEXT: Running pass: CanonicalizeAliasesPass @@ -38,8 +39,9 @@ // CHECK-FULL-O0-NEXT: Running pass: BitcodeWriterPass // CHECK-THIN-O0: Running pass: AlwaysInlinerPass -// CHECK-THIN-O0-NEXT: Running analysis: InnerAnalysisManagerProxy // CHECK-THIN-O0-NEXT: Running analysis: ProfileSummaryAnalysis +// CHECK-THIN-O0-NEXT: Running analysis: InnerAnalysisManagerProxy +// CHECK-THIN-O0-NEXT: Running analysis: LazyCallGraphAnalysis // CHECK-THIN-O0: Running pass: CoroCleanupPass // CHECK-THIN-O0-NEXT: Running pass: CanonicalizeAliasesPass // CHECK-THIN-O0-NEXT: Running pass: NameAnonGlobalPass diff --git a/clang/test/CodeGenCoroutines/coro-always-inline.cpp b/clang/test/CodeGenCoroutines/coro-always-inline.cpp --- a/clang/test/CodeGenCoroutines/coro-always-inline.cpp +++ b/clang/test/CodeGenCoroutines/coro-always-inline.cpp @@ -48,3 +48,15 @@ // CHECK: [[CAST3:%[0-9]+]] = bitcast %"struct.std::awaitable"* %ref.tmp{{.*}} to i8* // CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 1, i8* [[CAST3]]) void foo() { co_return; } + +// check that bar is not inlined even it's marked as always_inline + +// CHECK-LABEL: define {{.*}} void @_Z3bazv() +// CHECK: call void @_Z3barv( +__attribute__((__always_inline__)) void bar() { + co_return; +} +void baz() { + bar(); + co_return; +} diff --git a/clang/test/SemaCXX/coroutines.cpp b/clang/test/SemaCXX/coroutines.cpp --- a/clang/test/SemaCXX/coroutines.cpp +++ b/clang/test/SemaCXX/coroutines.cpp @@ -1443,3 +1443,7 @@ co_await missing_await_suspend{}; // expected-error {{no member named 'await_suspend' in 'missing_await_suspend'}} co_await missing_await_resume{}; // expected-error {{no member named 'await_resume' in 'missing_await_resume'}} } + +__attribute__((__always_inline__)) void warn_always_inline() { // expected-warning {{A coroutine marked always_inline might not be inlined properly}} + co_await suspend_always{}; +} diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -1717,6 +1717,8 @@ for (auto &C : PipelineEarlySimplificationEPCallbacks) C(MPM, Level); + MPM.addPass(createModuleToFunctionPassAdaptor(CoroEarlyPass())); + // Build a minimal pipeline based on the semantics required by LLVM, // which is just that always inlining occurs. Further, disable generating // lifetime intrinsics to avoid enabling further optimizations during @@ -1771,7 +1773,6 @@ MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); } - MPM.addPass(createModuleToFunctionPassAdaptor(CoroEarlyPass())); CGSCCPassManager CGPM; CGPM.addPass(CoroSplitPass()); MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM))); diff --git a/llvm/test/Other/new-pass-manager.ll b/llvm/test/Other/new-pass-manager.ll --- a/llvm/test/Other/new-pass-manager.ll +++ b/llvm/test/Other/new-pass-manager.ll @@ -292,8 +292,9 @@ ; RUN: -passes='default' %s 2>&1 \ ; RUN: | FileCheck %s --check-prefix=CHECK-O0 --check-prefix=%llvmcheckext ; CHECK-O0: Running pass: AlwaysInlinerPass -; CHECK-O0-NEXT: Running analysis: InnerAnalysisManagerProxy<{{.*}}> ; CHECK-O0-NEXT: Running analysis: ProfileSummaryAnalysis +; CHECK-O0-NEXT: Running analysis: InnerAnalysisManagerProxy<{{.*}}> +; CHECK-O0-NEXT: Running analysis: LazyCallGraphAnalysis ; CHECK-EXT-NEXT: Running pass: {{.*}}Bye ; We don't have checks for CHECK-NOEXT here, but this simplifies the test, while ; avoiding FileCheck complaining about the unused prefix. diff --git a/llvm/test/Other/new-pm-O0-defaults.ll b/llvm/test/Other/new-pm-O0-defaults.ll --- a/llvm/test/Other/new-pm-O0-defaults.ll +++ b/llvm/test/Other/new-pm-O0-defaults.ll @@ -31,14 +31,13 @@ ; CHECK-DIS: Running analysis: InnerAnalysisManagerProxy ; CHECK-DIS-NEXT: Running pass: AddDiscriminatorsPass +; CHECK-CORO: Running pass: CoroEarlyPass ; CHECK-DIS-NEXT: Running pass: AlwaysInlinerPass ; CHECK-DIS-NEXT: Running analysis: ProfileSummaryAnalysis -; CHECK-DEFAULT: Running pass: AlwaysInlinerPass -; CHECK-DEFAULT-NEXT: Running analysis: InnerAnalysisManagerProxy +; CHECK-DEFAULT-NEXT: Running pass: AlwaysInlinerPass ; CHECK-DEFAULT-NEXT: Running analysis: ProfileSummaryAnalysis ; CHECK-MATRIX: Running pass: LowerMatrixIntrinsicsPass ; CHECK-MATRIX-NEXT: Running analysis: TargetIRAnalysis -; CHECK-CORO-NEXT: Running pass: CoroEarlyPass ; CHECK-CORO-NEXT: Running analysis: InnerAnalysisManagerProxy ; CHECK-CORO-NEXT: Running analysis: LazyCallGraphAnalysis ; CHECK-CORO-NEXT: Running analysis: TargetLibraryAnalysis