Skip to content

Conversation

@MaskRay
Copy link
Member

@MaskRay MaskRay commented Oct 23, 2023

Fix #69889

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Oct 23, 2023
@llvmbot
Copy link
Member

llvmbot commented Oct 23, 2023

@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)

Changes

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

@pzhengqc
Copy link
Collaborator

Thanks for the MR, @MaskRay! The patch LGTM. Can you confirm that the failing checks are not related to this patch?

@MaskRay
Copy link
Member Author

MaskRay commented Oct 24, 2023

Thanks for the MR, @MaskRay! The patch LGTM. Can you confirm that the failing checks are not related to this patch?

Thanks for review. I confirm it is an unrelated clang-format issue (grep -rnI '[[:blank:]]$' clang/lib clang/include clang/docs) caused by another patch and fixed now.

@MaskRay MaskRay merged commit d5b0ad6 into llvm:main Oct 24, 2023
@MaskRay MaskRay deleted the fstack-usage branch October 24, 2023 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-fstack-usage prints incorrect source file names

4 participants