[llvm] [StackProtector] Introduce stack-protect-refinement pass to remove unnecessary protections. (PR #150390)

Paul T Robinson via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 4 08:33:12 PDT 2025


================
@@ -0,0 +1,63 @@
+//===- StackProtectRefinement.cpp - Stack Protect Refinement --------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Transforms/Scalar/StackProtectRefinement.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "stack-protect-refinement"
+
+STATISTIC(
+    NumFuncsWithAllocaInst,
+    "Number of functions with an instruction to allocate memory on the stack");
+STATISTIC(NumFuncsWithRemovedStackProtectAttr,
+          "Number of functions with alloca and removed stack protect attr");
+
+static cl::opt<bool>
+    UseStackSafety("optimize-ssp", cl::init(true), cl::Hidden,
+                   cl::desc("Use Stack Safety analysis results"));
+
+void StackProtectRefinementPass::processFunction(Function &F) const {
+
+  bool hasAlloca = false;
+
+  for (auto &I : instructions(&F))
----------------
pogo59 wrote:

Pls put braces around this for-loop body. It is technically one statement but contains nested statements with their own braces.

https://github.com/llvm/llvm-project/pull/150390


More information about the llvm-commits mailing list