[clang] ed2c321 - Revert "[dwarf] Emit a DIGlobalVariable for constant strings."

Mitch Phillips via cfe-commits cfe-commits at lists.llvm.org
Mon May 16 19:08:41 PDT 2022


Author: Mitch Phillips
Date: 2022-05-16T19:07:38-07:00
New Revision: ed2c3218f5badf88cb7897fabf8faa01e8aa2044

URL: https://github.com/llvm/llvm-project/commit/ed2c3218f5badf88cb7897fabf8faa01e8aa2044
DIFF: https://github.com/llvm/llvm-project/commit/ed2c3218f5badf88cb7897fabf8faa01e8aa2044.diff

LOG: Revert "[dwarf] Emit a DIGlobalVariable for constant strings."

This reverts commit 4680982b36a84770a1600fc438be8ec090671724.

Broke a fuchsia windows bot. More details in the review:
https://reviews.llvm.org/D123534

Added: 
    llvm/test/Assembler/invalid-diglobalvariable-missing-name.ll

Modified: 
    clang/lib/CodeGen/CGDebugInfo.cpp
    clang/lib/CodeGen/CGDebugInfo.h
    clang/lib/CodeGen/CodeGenModule.cpp
    clang/test/VFS/external-names.c
    llvm/lib/AsmParser/LLParser.cpp
    llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
    llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Removed: 
    clang/test/CodeGen/debug-info-variables.c
    llvm/test/DebugInfo/COFF/global-no-strings.ll


################################################################################
diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 7534270294415..3d73bfb8ce793 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5132,7 +5132,7 @@ std::string CGDebugInfo::GetName(const Decl *D, bool Qualified) const {
     return Name;
   codegenoptions::DebugTemplateNamesKind TemplateNamesKind =
       CGM.getCodeGenOpts().getDebugSimpleTemplateNames();
-
+  
   if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
     TemplateNamesKind = codegenoptions::DebugTemplateNamesKind::Full;
 
@@ -5459,21 +5459,6 @@ void CGDebugInfo::EmitGlobalAlias(const llvm::GlobalValue *GV,
   ImportedDeclCache[GD.getCanonicalDecl().getDecl()].reset(ImportDI);
 }
 
-void CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
-                                            const StringLiteral *S) {
-  SourceLocation Loc = S->getStrTokenLoc(0);
-  PresumedLoc PLoc = CGM.getContext().getSourceManager().getPresumedLoc(Loc);
-  if (!PLoc.isValid())
-    return;
-
-  llvm::DIFile *File = getOrCreateFile(Loc);
-  llvm::DIGlobalVariableExpression *Debug =
-      DBuilder.createGlobalVariableExpression(
-          nullptr, StringRef(), StringRef(), getOrCreateFile(Loc),
-          getLineNumber(Loc), getOrCreateType(S->getType(), File), true);
-  GV->addDebugInfo(Debug);
-}
-
 llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
   if (!LexicalBlockStack.empty())
     return LexicalBlockStack.back();

diff  --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 38e3fa5b2fa96..8984f3eb1d7a0 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -533,14 +533,6 @@ class CGDebugInfo {
   /// Emit an @import declaration.
   void EmitImportDecl(const ImportDecl &ID);
 
-  /// DebugInfo isn't attached to string literals by default. While certain
-  /// aspects of debuginfo aren't useful for string literals (like a name), it's
-  /// nice to be able to symbolize the line and column information. This is
-  /// especially useful for sanitizers, as it allows symbolization of
-  /// heap-buffer-overflows on constant strings.
-  void AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
-                                 const StringLiteral *S);
-
   /// Emit C++ namespace alias.
   llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
 

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 703cf4edf5f56..f8bf210dc0e21 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5670,11 +5670,6 @@ CodeGenModule::GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
   }
 
   auto GV = GenerateStringLiteral(C, LT, *this, GlobalVariableName, Alignment);
-
-  CGDebugInfo *DI = getModuleDebugInfo();
-  if (DI && getCodeGenOpts().hasReducedDebugInfo())
-    DI->AddStringLiteralDebugInfo(GV, S);
-
   if (Entry)
     *Entry = GV;
 

diff  --git a/clang/test/CodeGen/debug-info-variables.c b/clang/test/CodeGen/debug-info-variables.c
deleted file mode 100644
index 1e3b4fb979d7a..0000000000000
--- a/clang/test/CodeGen/debug-info-variables.c
+++ /dev/null
@@ -1,19 +0,0 @@
-// RUN: %clang_cc1 %s -debug-info-kind=standalone -S -emit-llvm -o - | FileCheck %s
-
-// CHECK: DIGlobalVariable(name: "global",{{.*}} line: [[@LINE+1]]
-int global = 42;
-
-// CHECK: DIGlobalVariable({{.*}}line: [[@LINE+4]],{{.*}} type: [[TYPEID:![0-9]+]]
-// CHECK: [[TYPEID]] = !DICompositeType(tag: DW_TAG_array_type, baseType: [[BASETYPE:![0-9]+]]
-// CHECK: [[BASETYPE]] = !DIBasicType(name: "char"
-const char* s() {
-  return "1234567890";
-}
-
-// CHECK: DILocalVariable(name: "p"
-// CHECK: DILocalVariable(name: "q"
-// CHECK: DILocalVariable(name: "r"
-int sum(int p, int q) {
-  int r = p + q;
-  return r;
-}

diff  --git a/clang/test/VFS/external-names.c b/clang/test/VFS/external-names.c
index 964b174ee57eb..c50d240a32ebd 100644
--- a/clang/test/VFS/external-names.c
+++ b/clang/test/VFS/external-names.c
@@ -30,8 +30,8 @@
 // Debug info
 
 // RUN: %clang_cc1 -I %t -ivfsoverlay %t.external.yaml -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-DEBUG-EXTERNAL %s
-// CHECK-DEBUG-EXTERNAL: ![[Num:[0-9]+]] = !DIFile(filename: "{{[^"]*}}Inputs{{..?}}external-names.h"
-// CHECK-DEBUG-EXTERNAL: !DISubprogram({{.*}}file: ![[Num]]
+// CHECK-DEBUG-EXTERNAL: !DISubprogram({{.*}}file: ![[Num:[0-9]+]]
+// CHECK-DEBUG-EXTERNAL: ![[Num]] = !DIFile(filename: "{{[^"]*}}Inputs{{..?}}external-names.h"
 
 // RUN: %clang_cc1 -I %t -ivfsoverlay %t.yaml -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-DEBUG %s
 // CHECK-DEBUG-NOT: Inputs

diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index c872f5911dbfe..c723d71b744c9 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -5010,7 +5010,7 @@ bool LLParser::parseDITemplateValueParameter(MDNode *&Result, bool IsDistinct) {
 ///                         declaration: !4, align: 8)
 bool LLParser::parseDIGlobalVariable(MDNode *&Result, bool IsDistinct) {
 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED)                                    \
-  OPTIONAL(name, MDStringField, (/* AllowEmpty */ false));                     \
+  REQUIRED(name, MDStringField, (/* AllowEmpty */ false));                     \
   OPTIONAL(scope, MDField, );                                                  \
   OPTIONAL(linkageName, MDStringField, );                                      \
   OPTIONAL(file, MDField, );                                                   \

diff  --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index ece4167c791c0..83d77cbeeac6d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -3175,11 +3175,6 @@ void CodeViewDebug::collectGlobalVariableInfo() {
     for (const auto *GVE : CU->getGlobalVariables()) {
       const DIGlobalVariable *DIGV = GVE->getVariable();
       const DIExpression *DIE = GVE->getExpression();
-      // Don't emit string literals in CodeView, as the only useful parts are
-      // generally the filename and line number, which isn't possible to output
-      // in CodeView. String literals should be the only unnamed GlobalVariable
-      // with debug info.
-      if (DIGV->getName().empty()) continue;
 
       if ((DIE->getNumElements() == 2) &&
           (DIE->getElement(0) == dwarf::DW_OP_plus_uconst))

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index b2095ae5d11d9..06fd724b2197d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -165,9 +165,7 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(
   } else {
     DeclContext = GV->getScope();
     // Add name and type.
-    StringRef DisplayName = GV->getDisplayName();
-    if (!DisplayName.empty())
-      addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName());
+    addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName());
     if (GTy)
       addType(*VariableDIE, GTy);
 

diff  --git a/llvm/test/Assembler/invalid-diglobalvariable-missing-name.ll b/llvm/test/Assembler/invalid-diglobalvariable-missing-name.ll
new file mode 100644
index 0000000000000..baf4d73d94f48
--- /dev/null
+++ b/llvm/test/Assembler/invalid-diglobalvariable-missing-name.ll
@@ -0,0 +1,4 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: <stdin>:[[@LINE+1]]:24: error: missing required field 'name'
+!0 = !DIGlobalVariable()

diff  --git a/llvm/test/DebugInfo/COFF/global-no-strings.ll b/llvm/test/DebugInfo/COFF/global-no-strings.ll
deleted file mode 100644
index bc3a3a11dd136..0000000000000
--- a/llvm/test/DebugInfo/COFF/global-no-strings.ll
+++ /dev/null
@@ -1,59 +0,0 @@
-; RUN: llc < %s | FileCheck %s
-; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s
-
-; This test ensures that no debuginfo is emitted for the constant "123456789"
-; string. These global variables have debug expressions because DWARF has the
-; ability to tie them to a file name and line number, but this isn't possible
-; in CodeView, so we make sure it's omitted to save file size.
-;
-; The various CodeView outputs should have a description of "my_string", but not
-; the string contents itself.
-
-; C++ source to regenerate:
-; $ cat a.cpp
-; char* my_string =
-;   "12345679";
-;
-; $ clang-cl a.cpp /GS- /Z7 /GR- /clang:-S /clang:-emit-llvm
-
-; CHECK-NOT: S_LDATA
-; CHECK: S_GDATA
-; CHECK-NOT: S_LDATA
-; CHECK-NOT: S_GDATA
-
-; ModuleID = '/tmp/a.c'
-source_filename = "/tmp/a.c"
-target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-pc-windows-msvc19.20.0"
-
-$"??_C at _08HCBFHPJA@12345679?$AA@" = comdat any
-
-@"??_C at _08HCBFHPJA@12345679?$AA@" = linkonce_odr dso_local unnamed_addr constant [9 x i8] c"12345679\00", comdat, align 1, !dbg !0
- at my_string = dso_local global ptr @"??_C at _08HCBFHPJA@12345679?$AA@", align 8, !dbg !7
-
-!llvm.dbg.cu = !{!9}
-!llvm.linker.options = !{!13, !14}
-!llvm.module.flags = !{!15, !16, !17, !18, !19}
-!llvm.ident = !{!20}
-
-!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
-!1 = distinct !DIGlobalVariable(scope: null, file: !2, line: 2, type: !3, isLocal: true, isDefinition: true)
-!2 = !DIFile(filename: "/tmp/a.c", directory: "", checksumkind: CSK_MD5, checksum: "b972961d64de3c90497767110ab58eb6")
-!3 = !DICompositeType(tag: DW_TAG_array_type, baseType: !4, size: 72, elements: !5)
-!4 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
-!5 = !{!6}
-!6 = !DISubrange(count: 9)
-!7 = !DIGlobalVariableExpression(var: !8, expr: !DIExpression())
-!8 = distinct !DIGlobalVariable(name: "my_string", scope: !9, file: !2, line: 1, type: !12, isLocal: false, isDefinition: true)
-!9 = distinct !DICompileUnit(language: DW_LANG_C99, file: !10, producer: "clang version 15.0.0 (https://github.com/llvm/llvm-project.git 7c1c0849f8a1a6f1bf5f5b554484bbf8b0debd0a)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !11, splitDebugInlining: false, nameTableKind: None)
-!10 = !DIFile(filename: "/tmp/a.c", directory: "/usr/local/google/home/mitchp/llvm-build/opt", checksumkind: CSK_MD5, checksum: "b972961d64de3c90497767110ab58eb6")
-!11 = !{!0, !7}
-!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 64)
-!13 = !{!"/DEFAULTLIB:libcmt.lib"}
-!14 = !{!"/DEFAULTLIB:oldnames.lib"}
-!15 = !{i32 2, !"CodeView", i32 1}
-!16 = !{i32 2, !"Debug Info Version", i32 3}
-!17 = !{i32 1, !"wchar_size", i32 2}
-!18 = !{i32 7, !"PIC Level", i32 2}
-!19 = !{i32 7, !"uwtable", i32 2}
-!20 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git 7c1c0849f8a1a6f1bf5f5b554484bbf8b0debd0a)"}


        


More information about the cfe-commits mailing list