[PATCH] D111286: Add no_instrument_function attribute to Objective C methods as well

Aditya Kumar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 6 21:43:04 PDT 2021


hiraditya created this revision.
hiraditya added a reviewer: rjmccall.
Herald added a reviewer: aaron.ballman.
hiraditya requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

There are several methods where we do not want function instrumentation which is why we have `__attribute__((no_instrument_function))`. Extending this functionality to disable instrumentation for Objective-C methods as well. Objective C methods like `+load` run premain and having instrumentation on them causes runtime errors depending on the implementation of `__cyg_profile_func_enter` etc. functions


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111286

Files:
  clang/include/clang/Basic/Attr.td
  clang/test/CodeGen/instrument-objc-method.m


Index: clang/test/CodeGen/instrument-objc-method.m
===================================================================
--- /dev/null
+++ clang/test/CodeGen/instrument-objc-method.m
@@ -0,0 +1,24 @@
+#import <Foundation/Foundation.h>
+// RUN: %clang_cc1 -S -triple x86_64-apple-darwin10 -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions -disable-llvm-passes | FileCheck %s
+// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-function-entry-bare -disable-llvm-passes | FileCheck -check-prefix=BARE %s
+
+
+ at interface ObjCClass
+ at end
+
+ at implementation ObjCClass
+
+// CHECK: @load
+// CHECK: "instrument-function-entry"="__cyg_profile_func_enter"
++ (void)load __attribute__((no_instrument_function))
+{
+}
+
++ (void)initialize
+{
+}
+
+-(void)dealloc __attribute__((no_instrument_function))
+{
+}
+ at end
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1979,7 +1979,7 @@
 
 def NoInstrumentFunction : InheritableAttr {
   let Spellings = [GCC<"no_instrument_function">];
-  let Subjects = SubjectList<[Function]>;
+  let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Documentation = [Undocumented];
   let SimpleHandler = 1;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111286.377740.patch
Type: text/x-patch
Size: 1327 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211007/0dbfeef2/attachment.bin>


More information about the cfe-commits mailing list