[PATCH] D100015: [debug-info] make fortran CHARACTER(1) type as valid unsigned type

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 6 21:38:33 PDT 2021


shchenz created this revision.
shchenz added reviewers: aprantl, dblaikie, jsji, echristo, PowerPC.
shchenz added a project: debug-info.
Herald added a subscriber: hiraditya.
shchenz requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This resolves https://bugs.llvm.org/show_bug.cgi?id=49872

SROA will create `llvm.dbg.value` to assign an unsigned integer to a variable with the type `CHARACTER(1)`. For now, this dbg value will cause llc crash in `AsmPrinter` pass.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100015

Files:
  llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
  llvm/test/CodeGen/Generic/pr49872.ll


Index: llvm/test/CodeGen/Generic/pr49872.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/Generic/pr49872.ll
@@ -0,0 +1,40 @@
+; RUN: llc < %s | FileCheck %s
+
+; PR49872
+; Check a interger constant for Fortran CHARACTER(1) will not cause a crash in
+; DebugHandlerBase::isUnsignedDIType when calling DwarfUnit::addConstantValue
+
+; CHECK-LABEL: s1_after_sroa
+
+source_filename = "1.ll"
+
+define dso_local void @s1_after_sroa([1 x i8] %arg) local_unnamed_addr #0 !dbg !5 {            
+s1_entry:                                                                           
+  call void @llvm.dbg.value(metadata i8 122, metadata !10, metadata !DIExpression()), !dbg !11
+  ret void, !dbg !12                                                                
+}                                                                                   
+
+declare void @llvm.dbg.value(metadata, metadata, metadata) #5
+
+!llvm.module.flags = !{!0, !1}
+!llvm.dbg.cu = !{!2}
+
+!0 = !{i32 2, !"Dwarf Version", i32 3}
+!1 = !{i32 2, !"Debug Info Version", i32 3}
+!2 = distinct !DICompileUnit(language: DW_LANG_Fortran95, file: !3, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, splitDebugInlining: false)
+!3 = !DIFile(filename: "1.f", directory: ".")
+!4 = !{}
+!5 = distinct !DISubprogram(name: "s1", linkageName: "s1", scope: !3, file: !3, line: 1, type: !6, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4)
+!6 = !DISubroutineType(types: !7)
+!7 = !{!8, !9}
+!8 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "void")
+!9 = !DIStringType(name: "char string", size: 8)
+!10 = !DILocalVariable(name: "arg", arg: 1, scope: !5, file: !3, type: !9)
+!11 = !DILocation(line: 0, scope: !5)
+!12 = !DILocation(line: 4, scope: !5)
+!13 = !DILocation(line: 5, scope: !5)
+!14 = distinct !DISubprogram(name: "p", linkageName: "main", scope: !3, file: !3, line: 7, type: !15, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4)
+!15 = !DISubroutineType(types: !16)
+!16 = !{!17}
+!17 = !DIBasicType(name: "INTEGER", size: 32, encoding: DW_ATE_signed)
+!18 = !DILocation(line: 8, scope: !14)
Index: llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
@@ -174,6 +174,12 @@
 }
 
 bool DebugHandlerBase::isUnsignedDIType(const DIType *Ty) {
+  // SROA may generate dbg value intrinsics to assign an unsigned value to a
+  // Fortran CHARACTER(1) type variables. Make them as unsigned.
+  if (isa<DIStringType>(Ty)) {
+    assert((Ty->getSizeInBits()) == 8 && "Not a valid unsigned type!");
+    return true;
+  }
   if (auto *CTy = dyn_cast<DICompositeType>(Ty)) {
     // FIXME: Enums without a fixed underlying type have unknown signedness
     // here, leading to incorrectly emitted constants.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100015.335715.patch
Type: text/x-patch
Size: 3028 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210407/f30fa9b2/attachment-0001.bin>


More information about the llvm-commits mailing list