[llvm] r297362 - [SSP] In opt remarks, stream Function directly

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 8 22:10:27 PST 2017


Author: anemet
Date: Thu Mar  9 00:10:27 2017
New Revision: 297362

URL: http://llvm.org/viewvc/llvm-project?rev=297362&view=rev
Log:
[SSP] In opt remarks, stream Function directly

With this, it shows up as an attribute in YAML and non-printable characters
are properly removed by GlobalValue::getRealLinkageName.

Modified:
    llvm/trunk/lib/CodeGen/StackProtector.cpp
    llvm/trunk/test/CodeGen/X86/stack-protector-remarks.ll

Modified: llvm/trunk/lib/CodeGen/StackProtector.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/StackProtector.cpp?rev=297362&r1=297361&r2=297362&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/StackProtector.cpp (original)
+++ llvm/trunk/lib/CodeGen/StackProtector.cpp Thu Mar  9 00:10:27 2017
@@ -234,13 +234,12 @@ bool StackProtector::RequiresStackProtec
   // using the analysis pass to avoid building DominatorTree and LoopInfo which
   // are not available this late in the IR pipeline.
   OptimizationRemarkEmitter ORE(F);
-  auto ReasonStub =
-      Twine("Stack protection applied to function " + F->getName() + " due to ")
-          .str();
 
   if (F->hasFnAttribute(Attribute::StackProtectReq)) {
     ORE.emit(OptimizationRemark(DEBUG_TYPE, "StackProtectorRequested", F)
-             << ReasonStub << "a function attribute or command-line switch");
+             << "Stack protection applied to function "
+             << ore::NV("Function", F)
+             << " due to a function attribute or command-line switch");
     NeedsProtector = true;
     Strong = true; // Use the same heuristic as strong to determine SSPLayout
   } else if (F->hasFnAttribute(Attribute::StackProtectStrong))
@@ -256,8 +255,10 @@ bool StackProtector::RequiresStackProtec
         if (AI->isArrayAllocation()) {
           OptimizationRemark Remark(DEBUG_TYPE, "StackProtectorAllocaOrArray",
                                     &I);
-          Remark << ReasonStub
-                 << "a call to alloca or use of a variable length array";
+          Remark
+              << "Stack protection applied to function "
+              << ore::NV("Function", F)
+              << " due to a call to alloca or use of a variable length array";
           if (const auto *CI = dyn_cast<ConstantInt>(AI->getArraySize())) {
             if (CI->getLimitedValue(SSPBufferSize) >= SSPBufferSize) {
               // A call to alloca with size >= SSPBufferSize requires
@@ -285,8 +286,10 @@ bool StackProtector::RequiresStackProtec
           Layout.insert(std::make_pair(AI, IsLarge ? SSPLK_LargeArray
                                                    : SSPLK_SmallArray));
           ORE.emit(OptimizationRemark(DEBUG_TYPE, "StackProtectorBuffer", &I)
-                   << ReasonStub
-                   << "a stack allocated buffer or struct containing a buffer");
+                   << "Stack protection applied to function "
+                   << ore::NV("Function", F)
+                   << " due to a stack allocated buffer or struct containing a "
+                      "buffer");
           NeedsProtector = true;
           continue;
         }
@@ -296,7 +299,9 @@ bool StackProtector::RequiresStackProtec
           Layout.insert(std::make_pair(AI, SSPLK_AddrOf));
           ORE.emit(
               OptimizationRemark(DEBUG_TYPE, "StackProtectorAddressTaken", &I)
-              << ReasonStub << "the address of a local variable being taken");
+              << "Stack protection applied to function "
+              << ore::NV("Function", F)
+              << " due to the address of a local variable being taken");
           NeedsProtector = true;
         }
       }

Modified: llvm/trunk/test/CodeGen/X86/stack-protector-remarks.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/stack-protector-remarks.ll?rev=297362&r1=297361&r2=297362&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/stack-protector-remarks.ll (original)
+++ llvm/trunk/test/CodeGen/X86/stack-protector-remarks.ll Thu Mar  9 00:10:27 2017
@@ -30,6 +30,18 @@
 ; RUN: llc %s -mtriple=x86_64-unknown-unknown -o /dev/null 2>&1 | FileCheck %s -check-prefix=NOREMARK -allow-empty
 ; NOREMARK-NOT: ssp
 
+; RUN: llc %s -mtriple=x86_64-unknown-unknown -o /dev/null -pass-remarks-output=%t.yaml
+; RUN: cat %t.yaml | FileCheck %s -check-prefix=YAML
+; YAML:      --- !Passed
+; YAML-NEXT: Pass:            stack-protector
+; YAML-NEXT: Name:            StackProtectorRequested
+; YAML-NEXT: Function:        attribute_ssp
+; YAML-NEXT: Args:
+; YAML-NEXT:   - String:          'Stack protection applied to function '
+; YAML-NEXT:   - Function:        attribute_ssp
+; YAML-NEXT:   - String:          ' due to a function attribute or command-line switch'
+; YAML-NEXT: ...
+
 define void @nossp() ssp {
   ret void
 }




More information about the llvm-commits mailing list