[clang] -fstack-usage: fix filename for functions in an included file (PR #69896)

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 22 22:23:25 PDT 2023


https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/69896

Fix #69889


>From 343f5abcd269701f526b64508237fb992ad7828d Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Sun, 22 Oct 2023 22:04:31 -0700
Subject: [PATCH] -fstack-usage: fix filename for functions in an included file

Fix #69889
---
 clang/test/CodeGen/stack-usage.c           | 13 ++++++++-----
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp |  5 +++--
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/test/CodeGen/stack-usage.c b/clang/test/CodeGen/stack-usage.c
index f7dc486c500586b..c9f495605fefd92 100644
--- a/clang/test/CodeGen/stack-usage.c
+++ b/clang/test/CodeGen/stack-usage.c
@@ -1,17 +1,20 @@
 // REQUIRES: aarch64-registered-target
 
-// RUN: rm -rf %t && mkdir %t && cd %t
-// RUN: %clang_cc1 -triple aarch64-unknown -stack-usage-file b.su -emit-obj %s -o b.o
-// RUN: FileCheck %s < b.su
+// 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
 
-// CHECK: stack-usage.c:[[#@LINE+1]]:foo	{{[0-9]+}}	static
+// CHECK: {{.*}}x.inc:1:bar	[[#]]	dynamic
+// CHECK: a.c:2:foo	[[#]]	static
+//--- a.c
+#include "x.inc"
 int foo() {
   char a[8];
 
   return 0;
 }
 
-// CHECK: stack-usage.c:[[#@LINE+1]]:bar	{{[0-9]+}}	dynamic
+//--- x.inc
 int bar(int len) {
   char a[len];
 
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 072c55f79caa9dc..b1a670fa3c2555c 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1469,9 +1469,10 @@ void AsmPrinter::emitStackUsage(const MachineFunction &MF) {
     }
   }
 
-  *StackUsageStream << MF.getFunction().getParent()->getName();
   if (const DISubprogram *DSP = MF.getFunction().getSubprogram())
-    *StackUsageStream << ':' << DSP->getLine();
+    *StackUsageStream << DSP->getFilename() << ':' << DSP->getLine();
+  else
+    *StackUsageStream << MF.getFunction().getParent()->getName();
 
   *StackUsageStream << ':' << MF.getName() << '\t' << StackSize << '\t';
   if (FrameInfo.hasVarSizedObjects())



More information about the cfe-commits mailing list