[PATCH] D108618: [CGCall] Add NoInline attr if presented for the target

Djordje Todorovic via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 24 01:39:54 PDT 2021


djtodoro created this revision.
djtodoro added a reviewer: rjmccall.
djtodoro added projects: clang, LLVM.
djtodoro requested review of this revision.

The `CodeGen` is missing to add the `NoInline` attribute to the target of a call, even the declaration has the __attribute__ presented. This fixes it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108618

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/test/CodeGen/noinline-attr-on-target.c


Index: clang/test/CodeGen/noinline-attr-on-target.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/noinline-attr-on-target.c
@@ -0,0 +1,13 @@
+// Make sure the `noinline` attribute has been attached to the `bar()`.
+
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: define dso_local void @foo() #[[#ATTR0:]] {
+// CHECK: declare void @bar() #[[#ATTR1:]]
+// CHECK: attributes #[[#ATTR0]] = { noinline
+// CHECK: attributes #[[#ATTR1]] = { noinline
+
+extern void __attribute__((noinline)) bar(void);
+void foo() {
+  bar();
+}
Index: clang/lib/CodeGen/CGClass.cpp
===================================================================
--- clang/lib/CodeGen/CGClass.cpp
+++ clang/lib/CodeGen/CGClass.cpp
@@ -1535,8 +1535,11 @@
     }
     // -fapple-kext must inline any call to this dtor into
     // the caller's body.
-    if (getLangOpts().AppleKext)
+    if (getLangOpts().AppleKext) {
+      if (CurFn->hasFnAttribute(llvm::Attribute::NoInline))
+        CurFn->removeFnAttr(llvm::Attribute::NoInline);
       CurFn->addFnAttr(llvm::Attribute::AlwaysInline);
+    }
 
     break;
   }
Index: clang/lib/CodeGen/CGCall.cpp
===================================================================
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2043,6 +2043,9 @@
     if (TargetDecl->hasAttr<ConvergentAttr>())
       FuncAttrs.addAttribute(llvm::Attribute::Convergent);
 
+    if (!AttrOnCallSite && TargetDecl->hasAttr<NoInlineAttr>())
+      FuncAttrs.addAttribute(llvm::Attribute::NoInline);
+
     if (const FunctionDecl *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
       AddAttributesFromFunctionProtoType(
           getContext(), FuncAttrs, Fn->getType()->getAs<FunctionProtoType>());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108618.368302.patch
Type: text/x-patch
Size: 1785 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210824/dcab8879/attachment-0001.bin>


More information about the cfe-commits mailing list