r303719 - [XRay][clang] Allow imbuing arg1 logging attribute via -fxray-always-instrument=

Dean Michael Berris via cfe-commits cfe-commits at lists.llvm.org
Tue May 23 22:46:37 PDT 2017


Author: dberris
Date: Wed May 24 00:46:36 2017
New Revision: 303719

URL: http://llvm.org/viewvc/llvm-project?rev=303719&view=rev
Log:
[XRay][clang] Allow imbuing arg1 logging attribute via -fxray-always-instrument=

Summary:
This change allows us to add arg1 logging support to functions through
the special case list provided through -fxray-always-instrument=. This
is useful for adding arg1 logging to functions that are either in
headers that users don't have control over (i.e. cannot change the
source) or would rather not do.

It only takes effect when the pattern is matched through the "fun:"
special case, as a category. As in:

  fun:*pattern=arg1

Reviewers: pelikan, rnk

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D33392

Added:
    cfe/trunk/test/CodeGen/xray-imbue-arg1.cpp
Modified:
    cfe/trunk/include/clang/Basic/XRayLists.h
    cfe/trunk/lib/Basic/XRayLists.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/include/clang/Basic/XRayLists.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/XRayLists.h?rev=303719&r1=303718&r2=303719&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/XRayLists.h (original)
+++ cfe/trunk/include/clang/Basic/XRayLists.h Wed May 24 00:46:36 2017
@@ -37,6 +37,7 @@ public:
     NONE,
     ALWAYS,
     NEVER,
+    ALWAYS_ARG1,
   };
 
   ImbueAttribute shouldImbueFunction(StringRef FunctionName) const;

Modified: cfe/trunk/lib/Basic/XRayLists.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/XRayLists.cpp?rev=303719&r1=303718&r2=303719&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/XRayLists.cpp (original)
+++ cfe/trunk/lib/Basic/XRayLists.cpp Wed May 24 00:46:36 2017
@@ -26,6 +26,8 @@ XRayFunctionFilter::ImbueAttribute
 XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const {
   // First apply the always instrument list, than if it isn't an "always" see
   // whether it's treated as a "never" instrument function.
+  if (AlwaysInstrument->inSection("fun", FunctionName, "arg1"))
+    return ImbueAttribute::ALWAYS_ARG1;
   if (AlwaysInstrument->inSection("fun", FunctionName))
     return ImbueAttribute::ALWAYS;
   if (NeverInstrument->inSection("fun", FunctionName))

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=303719&r1=303718&r2=303719&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed May 24 00:46:36 2017
@@ -1508,6 +1508,10 @@ bool CodeGenModule::imbueXRayAttrs(llvm:
   case ImbueAttr::ALWAYS:
     Fn->addFnAttr("function-instrument", "xray-always");
     break;
+  case ImbueAttr::ALWAYS_ARG1:
+    Fn->addFnAttr("function-instrument", "xray-always");
+    Fn->addFnAttr("xray-log-args", "1");
+    break;
   case ImbueAttr::NEVER:
     Fn->addFnAttr("function-instrument", "xray-never");
     break;

Added: cfe/trunk/test/CodeGen/xray-imbue-arg1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/xray-imbue-arg1.cpp?rev=303719&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/xray-imbue-arg1.cpp (added)
+++ cfe/trunk/test/CodeGen/xray-imbue-arg1.cpp Wed May 24 00:46:36 2017
@@ -0,0 +1,12 @@
+// RUN: echo "fun:*arg1*=arg1" >> %t.always-instrument
+// RUN: %clang_cc1 -fxray-instrument -x c++ -std=c++11 -fxray-always-instrument=%t.always-instrument -emit-llvm -o - %s -triple x86_64-unknown-linux-gnu | FileCheck %s
+
+void foo() {}
+
+void arg1(void*) {}
+
+// CHECK: define void @_Z3foov() #[[FOO:[0-9]+]] {
+// CHECK: define void {{.*}}arg1{{.*}} #[[ALWAYSARG1:[0-9]+]] {
+
+// CHECK: attributes #[[FOO]] = {{.*}}
+// CHECK: attributes #[[ALWAYSARG1]] = {{.*}} "function-instrument"="xray-always" {{.*}} "xray-log-args"="1"




More information about the cfe-commits mailing list