https://github.com/snehasish created 
https://github.com/llvm/llvm-project/pull/233289

Sample PGO testing of -debug-info-macro-expansion-loc is complete. Make its 
expansion-location behavior unconditional and remove the temporary cc1 flag, 
code generation option, and location helper.

Update the macro debug-info regression test to check the default behavior, 
including function line and column locations, and document the removed flag in 
the release notes.

Fixes #175249

>From a50c25f0653a3fbd26571d7285b1d630831af1bd Mon Sep 17 00:00:00 2001
From: Snehasish Kumar <[email protected]>
Date: Sun, 18 Oct 2026 18:51:05 +0000
Subject: [PATCH] [Clang][DebugInfo] Use macro expansion locations by default

Sample PGO testing of -debug-info-macro-expansion-loc is complete.
Make its expansion-location behavior unconditional and remove the
temporary cc1 flag, code generation option, and location helper.

Update the macro debug-info regression test to check the default
behavior, including function line and column locations, and document
the removed flag in the release notes.

Fixes #175249
---
 clang/docs/ReleaseNotes.md                 |  4 ++++
 clang/include/clang/Basic/DebugOptions.def |  4 ----
 clang/include/clang/Options/Options.td     |  4 ----
 clang/lib/CodeGen/CGDebugInfo.cpp          | 26 ++++++----------------
 clang/test/DebugInfo/Generic/macro-info.c  | 21 ++++++++---------
 5 files changed, 20 insertions(+), 39 deletions(-)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 7d6347414cc5c8..a956787904b8a4 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -352,6 +352,10 @@ features cannot lower the translation-unit ABI level;
 
 ### Removed Compiler Flags
 
+- Removed the experimental `-cc1` flag `-debug-info-macro-expansion-loc`.
+  Debug information now always uses macro expansion locations for macro 
arguments.
+  (#GH175249)
+
 ### Attribute Changes in Clang
 
 - Clang now properly propagates attributes on class and variable templates to 
their redeclarations, which will result in redeclarations not interfering with 
diagnostics. (#GH209812)
diff --git a/clang/include/clang/Basic/DebugOptions.def 
b/clang/include/clang/Basic/DebugOptions.def
index e496825d512743..480f1f41fad082 100644
--- a/clang/include/clang/Basic/DebugOptions.def
+++ b/clang/include/clang/Basic/DebugOptions.def
@@ -107,10 +107,6 @@ ENUM_DEBUGOPT(DebugInfo, DebugInfoKind, 4,
 /// Whether to generate macro debug info.
 DEBUGOPT(MacroDebugInfo, 1, 0, Compatible)
 
-/// Whether to use expansion location for debug info.
-/// TODO: #175249: Remove once testing is complete for sample pgo users.
-DEBUGOPT(DebugInfoMacroExpansionLoc, 1, 0, Compatible)
-
 /// Tune the debug info for this debugger.
 ENUM_DEBUGOPT(DebuggerTuning, DebuggerKind, 3,
               DebuggerKind::Default, Compatible)
diff --git a/clang/include/clang/Options/Options.td 
b/clang/include/clang/Options/Options.td
index 38d285b8268e15..f5f829bf85eadf 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -8128,10 +8128,6 @@ let Visibility = [CC1Option, CC1AsOption] in {
 def debug_info_macro : Flag<["-"], "debug-info-macro">,
   HelpText<"Emit macro debug information">,
   MarshallingInfoFlag<CodeGenOpts<"MacroDebugInfo">>;
-def debug_info_macro_expansion_loc
-    : Flag<["-"], "debug-info-macro-expansion-loc">,
-      HelpText<"Use expansion location for debug info for multi line macros">,
-      MarshallingInfoFlag<CodeGenOpts<"DebugInfoMacroExpansionLoc">>;
 def default_function_attr : Separate<["-"], "default-function-attr">,
   HelpText<"Apply given attribute to all functions">,
   MarshallingInfoStringVector<CodeGenOpts<"DefaultFunctionAttrs">>;
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 93428777b9b24c..57cee670c3b9dd 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -59,13 +59,6 @@
 using namespace clang;
 using namespace clang::CodeGen;
 
-static SourceLocation getMacroDebugLoc(const CodeGenModule &CGM,
-                                       SourceLocation Loc) {
-  if (CGM.getCodeGenOpts().DebugInfoMacroExpansionLoc)
-    return Loc;
-  return CGM.getContext().getSourceManager().getFileLoc(Loc);
-}
-
 static uint32_t getTypeAlignIfRequired(const Type *Ty, const ASTContext &Ctx) {
   auto TI = Ctx.getTypeInfo(Ty);
   if (TI.isAlignRequired())
@@ -353,7 +346,7 @@ void CGDebugInfo::setLocation(SourceLocation Loc) {
     return;
 
   SourceManager &SM = CGM.getContext().getSourceManager();
-  SourceLocation NewLoc = SM.getExpansionLoc(getMacroDebugLoc(CGM, Loc));
+  SourceLocation NewLoc = SM.getExpansionLoc(Loc);
   if (CurLoc != NewLoc) {
     CurLoc = NewLoc;
     CurLocFile = nullptr;
@@ -596,7 +589,6 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation 
Loc) {
     FileName = TheCU->getFile()->getFilename();
     CSInfo = TheCU->getFile()->getChecksum();
   } else {
-    Loc = getMacroDebugLoc(CGM, Loc);
     if (Loc == CurLoc && CurLocFile)
       return CurLocFile;
 
@@ -627,8 +619,7 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation 
Loc) {
     if (CSKind)
       CSInfo.emplace(*CSKind, Checksum);
   }
-  return createFile(FileName, CSInfo,
-                    getSource(SM, SM.getFileID(getMacroDebugLoc(CGM, Loc))));
+  return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc)));
 }
 
 llvm::DIFile *CGDebugInfo::createFile(
@@ -679,10 +670,9 @@ unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) {
   if (Loc.isInvalid())
     return 0;
   SourceManager &SM = CGM.getContext().getSourceManager();
-  SourceLocation DebugLoc = getMacroDebugLoc(CGM, Loc);
-  if (DebugLoc == CurLoc)
+  if (Loc == CurLoc)
     return CurLocLine;
-  return SM.getPresumedLoc(DebugLoc).getLine();
+  return SM.getPresumedLoc(Loc).getLine();
 }
 
 unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc) {
@@ -694,7 +684,7 @@ unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc) {
   if (Loc.isInvalid() && CurLoc.isInvalid())
     return 0;
   SourceManager &SM = CGM.getContext().getSourceManager();
-  SourceLocation DebugLoc = Loc.isValid() ? getMacroDebugLoc(CGM, Loc) : 
CurLoc;
+  SourceLocation DebugLoc = Loc.isValid() ? Loc : CurLoc;
   if (DebugLoc == CurLoc)
     return CurLocColumn;
   PresumedLoc PLoc = SM.getPresumedLoc(DebugLoc);
@@ -5317,9 +5307,7 @@ void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, 
SourceLocation Loc) {
   // Update our current location
   setLocation(Loc);
 
-  if (CurLoc.isInvalid() ||
-      (CGM.getCodeGenOpts().DebugInfoMacroExpansionLoc && CurLoc.isMacroID()) 
||
-      LexicalBlockStack.empty())
+  if (CurLoc.isInvalid() || LexicalBlockStack.empty())
     return;
 
   llvm::MDNode *Scope = LexicalBlockStack.back();
@@ -6592,7 +6580,7 @@ void 
CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
                                             const StringLiteral *S) {
   SourceLocation Loc = S->getStrTokenLoc(0);
   SourceManager &SM = CGM.getContext().getSourceManager();
-  PresumedLoc PLoc = SM.getPresumedLoc(getMacroDebugLoc(CGM, Loc));
+  PresumedLoc PLoc = SM.getPresumedLoc(Loc);
   if (!PLoc.isValid())
     return;
 
diff --git a/clang/test/DebugInfo/Generic/macro-info.c 
b/clang/test/DebugInfo/Generic/macro-info.c
index 8d9d2502be03f5..4b95588e6bd331 100644
--- a/clang/test/DebugInfo/Generic/macro-info.c
+++ b/clang/test/DebugInfo/Generic/macro-info.c
@@ -1,5 +1,4 @@
-// RUN: %clang_cc1 %s -debug-info-kind=standalone -emit-llvm -o - | FileCheck 
%s --check-prefix=NEW
-// RUN: %clang_cc1 %s -debug-info-kind=standalone -emit-llvm 
-debug-info-macro-expansion-loc -o - | FileCheck %s --check-prefix=OLD
+// RUN: %clang_cc1 %s -debug-info-kind=standalone -emit-llvm -o - | FileCheck 
%s
 
 #define GLOBAL(num) global## num
 #define DECL_GLOBAL(x) int x
@@ -10,13 +9,11 @@
 
 SAME_ORDER(
   int
-// NEW: DIGlobalVariable(name: "global",{{.*}} line: [[@LINE+2]]
-// OLD: DIGlobalVariable(name: "global",{{.*}} line: [[@LINE-3]]
+// CHECK: DIGlobalVariable(name: "global",{{.*}} line: [[@LINE-2]]
     GLOBAL  // <- global
       () = 42,
   const char* s() {
-// NEW: DIGlobalVariable({{.*}}line: [[@LINE+2]],{{.*}} type: 
[[TYPEID:![0-9]+]]
-// OLD: DIGlobalVariable({{.*}}line: [[@LINE-8]],{{.*}} type: 
[[TYPEID:![0-9]+]]
+// CHECK: DIGlobalVariable({{.*}}line: [[@LINE-6]],{{.*}} type: 
[[TYPEID:![0-9]+]]
     return "1234567890";
   }
 )
@@ -24,10 +21,8 @@ SAME_ORDER(
 SWAP_ORDER(
   int GLOBAL(  // <- global2
     2) = 43,
-// NEW: DIGlobalVariable(name: "global3",{{.*}} line: [[@LINE+5]]
-// NEW: DIGlobalVariable(name: "global2",{{.*}} line: [[@LINE-3]]
-// OLD: DIGlobalVariable(name: "global3",{{.*}} line: [[@LINE-5]]
-// OLD: DIGlobalVariable(name: "global2",{{.*}} line: [[@LINE-6]]
+// CHECK: DIGlobalVariable(name: "global3",{{.*}} line: [[@LINE-3]]
+// CHECK: DIGlobalVariable(name: "global2",{{.*}} line: [[@LINE-4]]
   DECL_GLOBAL(
     GLOBAL(  // <- global3
       3)) = 44
@@ -35,7 +30,9 @@ SWAP_ORDER(
 
 
 DECL_GLOBAL(
-// NEW: DIGlobalVariable(name: "global4",{{.*}} line: [[@LINE+2]]
-// OLD: DIGlobalVariable(name: "global4",{{.*}} line: [[@LINE-2]]
+// CHECK: DIGlobalVariable(name: "global4",{{.*}} line: [[@LINE-1]]
   GLOBAL(  // <- global4
     4));
+
+// CHECK: ![[SP:[0-9]+]] = distinct !DISubprogram(name: "s",{{.*}} line: 
[[@LINE-27]],
+// CHECK: !DILocation(line: [[@LINE-28]], column: 1, scope: ![[SP]])

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to