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

via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 22 22:24:34 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)

<details>
<summary>Changes</summary>

Fix #<!-- -->69889


---
Full diff: https://github.com/llvm/llvm-project/pull/69896.diff


2 Files Affected:

- (modified) clang/test/CodeGen/stack-usage.c (+8-5) 
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+3-2) 


``````````diff
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())

``````````

</details>


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


More information about the cfe-commits mailing list