diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -518,8 +518,10 @@ F->setDoesNotRecurse(); // Always inline the outlined function if optimizations are enabled. - if (CGM.getCodeGenOpts().OptimizationLevel != 0) + if (CGM.getCodeGenOpts().OptimizationLevel != 0) { + F->removeFnAttr(llvm::Attribute::NoInline); F->addFnAttr(llvm::Attribute::AlwaysInline); + } // Generate the function. CGF.StartFunction(CD, Ctx.VoidTy, F, FuncInfo, TargetArgs, diff --git a/clang/test/OpenMP/parallel_for_noinline.cpp b/clang/test/OpenMP/parallel_for_noinline.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/parallel_for_noinline.cpp @@ -0,0 +1,15 @@ +// RUN: %clang -O0 -fopenmp -fno-inline %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-O0 +// RUN: %clang -O1 -fopenmp -fno-inline %s -S -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-O1 + +// CHECK-LABEL: define dso_local void @_Z3foov +// CHECK: Function Attrs: +// CHECK-O0-SAME: inline +// CHECK-O0-NOT: awaysinline +// CHECK-O1-SAME: alwaysinline +// CHECK-O1-NOT: noinline +// CHECK-LABEL: define internal void @.omp_outlined +void foo() { + #pragma omp parallel for + for (int i = 0; i < 100; ++i) + ; +}