https://github.com/rsashka updated https://github.com/llvm/llvm-project/pull/173181
>From baa18363e4a33fd9cdf28504df3c2e13c675d2c1 Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabikov <[email protected]> Date: Sun, 21 Dec 2025 11:56:03 +0300 Subject: [PATCH 1/2] Fixed stack size estimates in the function for the -fstack-usage option --- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 4d2992456f6f8..4a99d7de081f5 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1679,8 +1679,10 @@ void AsmPrinter::emitStackUsage(const MachineFunction &MF) { return; const MachineFrameInfo &FrameInfo = MF.getFrameInfo(); + // The estimated maximum stack size, including alignment and + // target-specific stack size, for function return addresses. uint64_t StackSize = - FrameInfo.getStackSize() + FrameInfo.getUnsafeStackSize(); + FrameInfo.estimateStackSize(MF) + MF.getTarget().getAllocaPointerSize(); if (StackUsageStream == nullptr) { std::error_code EC; >From 0b9a763eb60fa44cab00cb43ddc2dda9cfa84f74 Mon Sep 17 00:00:00 2001 From: Aleksandr Ryabikov <[email protected]> Date: Sun, 21 Dec 2025 11:56:03 +0300 Subject: [PATCH 2/2] Fixed stack size estimates in the function for the -fstack-usage option Added test for -fstack_usage option when compiling with optimization --- clang/test/CodeGen/stack-usage.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/clang/test/CodeGen/stack-usage.c b/clang/test/CodeGen/stack-usage.c index c9f495605fefd..5ca5271c86487 100644 --- a/clang/test/CodeGen/stack-usage.c +++ b/clang/test/CodeGen/stack-usage.c @@ -1,11 +1,17 @@ // REQUIRES: aarch64-registered-target // RUN: rm -rf %t && split-file %s %t && cd %t -// RUN: %clang_cc1 -triple aarch64-unknown -I . -stack-usage-file a.su -emit-obj a.c -o a.o -// RUN: FileCheck %s < a.su +// RUN: %clang_cc1 -triple aarch64-unknown -O0 -I . -stack-usage-file a-O0.su -emit-obj a.c -o a-O0.o +// RUN: %clang_cc1 -triple aarch64-unknown -O3 -I . -stack-usage-file a-O3.su -emit-obj a.c -o a-O3.o +// RUN: FileCheck %s < a-O0.su -check-prefix=O0 +// RUN: FileCheck %s < a-O3.su -check-prefix=O3 + +// O0: {{.*}}x.inc:1:bar 56 dynamic +// O0: a.c:2:foo 24 static + +// O3: {{.*}}x.inc:1:bar 8 static +// O3: a.c:2:foo 8 static -// CHECK: {{.*}}x.inc:1:bar [[#]] dynamic -// CHECK: a.c:2:foo [[#]] static //--- a.c #include "x.inc" int foo() { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
