diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h --- a/llvm/lib/IR/LLVMContextImpl.h +++ b/llvm/lib/IR/LLVMContextImpl.h @@ -513,11 +513,20 @@ bool isKeyOf(const DIStringType *RHS) const { return Tag == RHS->getTag() && Name == RHS->getRawName() && + StringLength == RHS->getRawStringLength() && + StringLengthExp == RHS->getRawStringLengthExp() && + StringLocationExp == RHS->getRawStringLocationExp() && SizeInBits == RHS->getSizeInBits() && AlignInBits == RHS->getAlignInBits() && Encoding == RHS->getEncoding(); } - unsigned getHashValue() const { return hash_combine(Tag, Name, Encoding); } + unsigned getHashValue() const { + // Intentionally computes the hash on a subset of the operands for + // performance reason. The subset has to be significant enough to avoid + // collision "most of the time". There is no correctness issue in case of + // collision because of the full check above. + return hash_combine(Tag, Name, StringLength, Encoding); + } }; template <> struct MDNodeKeyImpl { diff --git a/llvm/test/DebugInfo/Inputs/distringtype1.ll b/llvm/test/DebugInfo/Inputs/distringtype1.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/Inputs/distringtype1.ll @@ -0,0 +1,29 @@ +define void @sub2_(ptr %string, i64 %.U0001.arg) !dbg !5 { +L.entry: + call void @llvm.dbg.declare(metadata ptr %string, metadata !12, metadata !DIExpression()), !dbg !14 + call void @llvm.dbg.value(metadata i64 %.U0001.arg, metadata !10, metadata !DIExpression()), !dbg !14 + ret void, !dbg !15 +} + +declare void @llvm.dbg.declare(metadata, metadata, metadata) +declare void @llvm.dbg.value(metadata, metadata, metadata) + +!llvm.module.flags = !{!0, !1} +!llvm.dbg.cu = !{!2} + +!0 = !{i32 2, !"Dwarf Version", i32 4} +!1 = !{i32 2, !"Debug Info Version", i32 3} +!2 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !3, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: false, flags: "'+flang -g distringtype1.f90 -S -emit-llvm'", runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !4, globals: !4, imports: !4, nameTableKind: None) +!3 = !DIFile(filename: "distringtype1.f90", directory: "/tmp/") +!4 = !{} +!5 = distinct !DISubprogram(name: "sub2", scope: !2, file: !3, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !9) +!6 = !DISubroutineType(types: !7) +!7 = !{null, !8} +!8 = !DIStringType(name: "character(*)!1", size: 32) +!9 = !{!10, !12} +!10 = !DILocalVariable(arg: 2, scope: !5, file: !3, line: 1, type: !11, flags: DIFlagArtificial) +!11 = !DIBasicType(name: "integer*8", size: 64, align: 64, encoding: DW_ATE_signed) +!12 = !DILocalVariable(name: "string", arg: 1, scope: !5, file: !3, line: 1, type: !13) +!13 = !DIStringType(name: "character(*)!2", stringLength: !10, stringLengthExpression: !DIExpression(), size: 32) +!14 = !DILocation(line: 0, scope: !5) +!15 = !DILocation(line: 3, column: 1, scope: !5) diff --git a/llvm/test/DebugInfo/distringtype.ll b/llvm/test/DebugInfo/distringtype.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/distringtype.ll @@ -0,0 +1,45 @@ +; RUN: llvm-link %s %p/Inputs/distringtype1.ll -S -o - | FileCheck %s + +; This test checks that DIStringType is properly linked. + +; CHECK: !DIStringType(name: "character(*)!1", size: 32) +; CHECK: !DIStringType(name: "character(*)!2", size: 32) +; CHECK: !DIStringType(name: "character(*)!3", stringLength: !{{[0-9]+}}, stringLengthExpression: !DIExpression(), size: 32) +; CHECK: !DIStringType(name: "character(*)!4", stringLength: !{{[0-9]+}}, stringLengthExpression: !DIExpression(), size: 32) +; CHECK: !DIStringType(name: "character(*)!2", stringLength: !{{[0-9]+}}, stringLengthExpression: !DIExpression(), size: 32) + +define void @sub1_(ptr %string1, ptr %string2, i64 %.U0002.arg, i64 %.U0003.arg) !dbg !5 { +L.entry: + call void @llvm.dbg.declare(metadata ptr %string1, metadata !13, metadata !DIExpression()), !dbg !18 + call void @llvm.dbg.declare(metadata ptr %string2, metadata !16, metadata !DIExpression()), !dbg !18 + call void @llvm.dbg.value(metadata i64 %.U0002.arg, metadata !11, metadata !DIExpression()), !dbg !18 + call void @llvm.dbg.value(metadata i64 %.U0003.arg, metadata !15, metadata !DIExpression()), !dbg !18 + ret void, !dbg !19 +} + +declare void @llvm.dbg.declare(metadata, metadata, metadata) +declare void @llvm.dbg.value(metadata, metadata, metadata) + +!llvm.module.flags = !{!0, !1} +!llvm.dbg.cu = !{!2} + +!0 = !{i32 2, !"Dwarf Version", i32 4} +!1 = !{i32 2, !"Debug Info Version", i32 3} +!2 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !3, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: false, flags: "'+flang -g distringtype.f90 -S -emit-llvm'", runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !4, globals: !4, imports: !4, nameTableKind: None) +!3 = !DIFile(filename: "distringtype.f90", directory: "/tmp/") +!4 = !{} +!5 = distinct !DISubprogram(name: "sub1", scope: !2, file: !3, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !10) +!6 = !DISubroutineType(types: !7) +!7 = !{null, !8, !9} +!8 = !DIStringType(name: "character(*)!1", size: 32) +!9 = !DIStringType(name: "character(*)!2", size: 32) +!10 = !{!11, !13, !15, !16} +!11 = !DILocalVariable(arg: 3, scope: !5, file: !3, line: 1, type: !12, flags: DIFlagArtificial) +!12 = !DIBasicType(name: "integer*8", size: 64, align: 64, encoding: DW_ATE_signed) +!13 = !DILocalVariable(name: "string1", arg: 1, scope: !5, file: !3, line: 1, type: !14) +!14 = !DIStringType(name: "character(*)!3", stringLength: !11, stringLengthExpression: !DIExpression(), size: 32) +!15 = !DILocalVariable(arg: 4, scope: !5, file: !3, line: 1, type: !12, flags: DIFlagArtificial) +!16 = !DILocalVariable(name: "string2", arg: 2, scope: !5, file: !3, line: 1, type: !17) +!17 = !DIStringType(name: "character(*)!4", stringLength: !15, stringLengthExpression: !DIExpression(), size: 32) +!18 = !DILocation(line: 0, scope: !5) +!19 = !DILocation(line: 4, column: 1, scope: !5)