[PATCH] D112645: [OpenMP] Fix: opposite attributes could be set by -fno-inline

Igor Kirillov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 27 11:46:59 PDT 2021


igor.kirillov created this revision.
Herald added subscribers: guansong, yaxunl.
igor.kirillov requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

After the changes introduced by D106799 <https://reviews.llvm.org/D106799> it is possible to tag
outlined function with both AlwaysInline and NoInline attributes using
-fno-inline command line options.
This issue is similiar to D107649 <https://reviews.llvm.org/D107649>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112645

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/parallel_for_noinline.cpp


Index: clang/test/OpenMP/parallel_for_noinline.cpp
===================================================================
--- /dev/null
+++ 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)
+     ;
+}
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===================================================================
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ 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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112645.382738.patch
Type: text/x-patch
Size: 1364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211027/d66de975/attachment.bin>


More information about the cfe-commits mailing list