Skip to content

Commit bae1fde

Browse files
authored
[MLIR][LLVM] Add distinct identifier to the DISubprogram attribute (#77093)
This commit adds an optional distinct attribute parameter to the DISubprogramAttr. This enables modeling of distinct subprograms, as required for LLVM IR. This change is required to avoid accidential uniquing of subprograms on functions that would lead to invalid LLVM IR post export.
1 parent 9de81ce commit bae1fde

File tree

9 files changed

+84
-33
lines changed

9 files changed

+84
-33
lines changed

flang/lib/Optimizer/Transforms/AddDebugFoundation.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,18 @@ void AddDebugFoundationPass::runOnOperation() {
9393
context, llvm::dwarf::getCallingConvention("DW_CC_normal"),
9494
{bT, bT});
9595
mlir::LLVM::DIFileAttr funcFileAttr = getFileAttr(funcFilePath);
96+
97+
// Only definitions need a distinct identifier and a compilation unit.
98+
mlir::DistinctAttr id;
99+
mlir::LLVM::DICompileUnitAttr compilationUnit;
100+
if (!funcOp.isExternal()) {
101+
id = mlir::DistinctAttr::create(mlir::UnitAttr::get(context));
102+
compilationUnit = cuAttr;
103+
}
96104
mlir::LLVM::DISubprogramAttr spAttr = mlir::LLVM::DISubprogramAttr::get(
97-
context, cuAttr, fileAttr, funcName, funcName, funcFileAttr, /*line=*/1,
105+
context, id, compilationUnit, fileAttr, funcName, funcName,
106+
funcFileAttr,
107+
/*line=*/1,
98108
/*scopeline=*/1, mlir::LLVM::DISubprogramFlags::Definition,
99109
subTypeAttr);
100110
funcOp->setLoc(builder.getFusedLoc({funcOp->getLoc()}, spAttr));

flang/test/Transforms/debug-line-table-inc-file.fir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ module attributes {} {
3030
// CHECK: #[[MODULE_LOC]] = loc("{{.*}}simple.f90":0:0)
3131
// CHECK: #[[LOC_INC_FILE:.*]] = loc("{{.*}}inc.f90":1:1)
3232
// CHECK: #[[LOC_FILE:.*]] = loc("{{.*}}simple.f90":3:1)
33-
// CHECK: #[[DI_CU:.*]] = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_Fortran95, file = #[[DI_FILE]], producer = "Flang", isOptimized = false, emissionKind = LineTablesOnly>
34-
// CHECK: #[[DI_SP_INC:.*]] = #llvm.di_subprogram<compileUnit = #[[DI_CU]], scope = #[[DI_FILE]], name = "_QPsinc", linkageName = "_QPsinc", file = #[[DI_INC_FILE]], {{.*}}>
35-
// CHECK: #[[DI_SP:.*]] = #llvm.di_subprogram<compileUnit = #[[DI_CU]], scope = #[[DI_FILE]], name = "_QQmain", linkageName = "_QQmain", file = #[[DI_FILE]], {{.*}}>
33+
// CHECK: #[[DI_CU:.*]] = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #[[DI_FILE]], producer = "Flang", isOptimized = false, emissionKind = LineTablesOnly>
34+
// CHECK: #[[DI_SP_INC:.*]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #[[DI_CU]], scope = #[[DI_FILE]], name = "_QPsinc", linkageName = "_QPsinc", file = #[[DI_INC_FILE]], {{.*}}>
35+
// CHECK: #[[DI_SP:.*]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #[[DI_CU]], scope = #[[DI_FILE]], name = "_QQmain", linkageName = "_QQmain", file = #[[DI_FILE]], {{.*}}>
3636
// CHECK: #[[FUSED_LOC_INC_FILE]] = loc(fused<#[[DI_SP_INC]]>[#[[LOC_INC_FILE]]])
3737
// CHECK: #[[FUSED_LOC_FILE]] = loc(fused<#[[DI_SP]]>[#[[LOC_FILE]]])

flang/test/Transforms/debug-line-table.fir

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,26 @@ module attributes { fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.dat
55
func.func @_QPsb() {
66
return loc(#loc_sb)
77
} loc(#loc_sb)
8+
func.func private @decl() -> i32 loc(#loc_decl)
89
} loc(#loc_module)
910
#loc_module = loc("./simple.f90":1:1)
1011
#loc_sb = loc("./simple.f90":2:1)
12+
#loc_decl = loc("./simple.f90":10:1)
1113

1214
// CHECK: module attributes
1315
// CHECK: func.func @[[SB_NAME:.*]]() {
1416
// CHECK: return loc(#[[SB_LOC:.*]])
1517
// CHECK: } loc(#[[FUSED_SB_LOC:.*]])
18+
// CHECK: func.func private @[[DECL_NAME:.*]]() -> i32 loc(#[[FUSED_DECL_LOC:.*]])
1619
// CHECK: } loc(#[[MODULE_LOC:.*]])
1720
// CHECK: #di_basic_type = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "void", encoding = DW_ATE_address>
1821
// CHECK: #di_file = #llvm.di_file<"[[FILE_NAME:.*]]" in "[[DIR_NAME:.*]]">
1922
// CHECK: #[[MODULE_LOC]] = loc("[[DIR_NAME]]/[[FILE_NAME]]":1:1)
2023
// CHECK: #[[SB_LOC]] = loc("./simple.f90":2:1)
21-
// CHECK: #di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "Flang", isOptimized = false, emissionKind = LineTablesOnly>
24+
// CHECK: #[[DECL_LOC:.*]] = loc("./simple.f90":10:1)
25+
// CHECK: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "Flang", isOptimized = false, emissionKind = LineTablesOnly>
2226
// CHECK: #di_subroutine_type = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #di_basic_type, #di_basic_type>
23-
// CHECK: #di_subprogram = #llvm.di_subprogram<compileUnit = #di_compile_unit, scope = #di_file, name = "[[SB_NAME]]", linkageName = "[[SB_NAME]]", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = Definition, type = #di_subroutine_type>
24-
// CHECK: #[[FUSED_SB_LOC]] = loc(fused<#di_subprogram>[#[[SB_LOC]]])
27+
// CHECK: #[[SB_SUBPROGRAM:.*]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #di_compile_unit, scope = #di_file, name = "[[SB_NAME]]", linkageName = "[[SB_NAME]]", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = Definition, type = #di_subroutine_type>
28+
// CHECK: #[[DECL_SUBPROGRAM:.*]] = #llvm.di_subprogram<scope = #di_file, name = "[[DECL_NAME]]", linkageName = "[[DECL_NAME]]", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = Definition, type = #di_subroutine_type>
29+
// CHECK: #[[FUSED_SB_LOC]] = loc(fused<#[[SB_SUBPROGRAM]]>[#[[SB_LOC]]])
30+
// CHECK: #[[FUSED_DECL_LOC]] = loc(fused<#[[DECL_SUBPROGRAM]]>[#[[DECL_LOC]]])

mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ def LLVM_DILocalVariableAttr : LLVM_Attr<"DILocalVariable", "di_local_variable",
517517
def LLVM_DISubprogramAttr : LLVM_Attr<"DISubprogram", "di_subprogram",
518518
/*traits=*/[], "DIScopeAttr"> {
519519
let parameters = (ins
520+
OptionalParameter<"DistinctAttr">:$id,
520521
OptionalParameter<"DICompileUnitAttr">:$compileUnit,
521522
"DIScopeAttr":$scope,
522523
OptionalParameter<"StringAttr">:$name,
@@ -529,13 +530,13 @@ def LLVM_DISubprogramAttr : LLVM_Attr<"DISubprogram", "di_subprogram",
529530
);
530531
let builders = [
531532
AttrBuilderWithInferredContext<(ins
532-
"DICompileUnitAttr":$compileUnit, "DIScopeAttr":$scope, "StringRef":$name,
533-
"StringRef":$linkageName, "DIFileAttr":$file, "unsigned":$line,
534-
"unsigned":$scopeLine, "DISubprogramFlags":$subprogramFlags,
535-
"DISubroutineTypeAttr":$type
533+
"DistinctAttr":$id, "DICompileUnitAttr":$compileUnit,
534+
"DIScopeAttr":$scope, "StringRef":$name, "StringRef":$linkageName,
535+
"DIFileAttr":$file, "unsigned":$line, "unsigned":$scopeLine,
536+
"DISubprogramFlags":$subprogramFlags, "DISubroutineTypeAttr":$type
536537
), [{
537538
MLIRContext *ctx = file.getContext();
538-
return $_get(ctx, compileUnit, scope, StringAttr::get(ctx, name),
539+
return $_get(ctx, id, compileUnit, scope, StringAttr::get(ctx, name),
539540
StringAttr::get(ctx, linkageName), file, line,
540541
scopeLine, subprogramFlags, type);
541542
}]>

mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,15 @@ static void addScopeToFunction(LLVM::LLVMFuncOp llvmFunc,
6666
LLVM::DISubroutineTypeAttr::get(context, llvm::dwarf::DW_CC_normal, {});
6767

6868
StringAttr funcNameAttr = llvmFunc.getNameAttr();
69-
auto subprogramAttr = LLVM::DISubprogramAttr::get(
70-
context, compileUnitAttr, fileAttr, funcNameAttr, funcNameAttr, fileAttr,
69+
// Only definitions need a distinct identifier and a compilation unit.
70+
mlir::DistinctAttr id;
71+
if (!llvmFunc.isExternal())
72+
id = mlir::DistinctAttr::create(mlir::UnitAttr::get(context));
73+
else
74+
compileUnitAttr = {};
75+
mlir::LLVM::DISubprogramAttr subprogramAttr = LLVM::DISubprogramAttr::get(
76+
context, id, compileUnitAttr, fileAttr, funcNameAttr, funcNameAttr,
77+
fileAttr,
7178
/*line=*/line,
7279
/*scopeline=*/col,
7380
LLVM::DISubprogramFlags::Definition | LLVM::DISubprogramFlags::Optimized,

mlir/lib/Target/LLVMIR/DebugImporter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ DINamespaceAttr DebugImporter::translateImpl(llvm::DINamespace *node) {
163163
}
164164

165165
DISubprogramAttr DebugImporter::translateImpl(llvm::DISubprogram *node) {
166+
// Only definitions require a distinct identifier.
167+
mlir::DistinctAttr id;
168+
if (node->isDistinct())
169+
id = DistinctAttr::create(UnitAttr::get(context));
166170
std::optional<DISubprogramFlags> subprogramFlags =
167171
symbolizeDISubprogramFlags(node->getSubprogram()->getSPFlags());
168172
// Return nullptr if the scope or type is a cyclic dependency.
@@ -172,7 +176,7 @@ DISubprogramAttr DebugImporter::translateImpl(llvm::DISubprogram *node) {
172176
DISubroutineTypeAttr type = translate(node->getType());
173177
if (node->getType() && !type)
174178
return nullptr;
175-
return DISubprogramAttr::get(context, translate(node->getUnit()), scope,
179+
return DISubprogramAttr::get(context, id, translate(node->getUnit()), scope,
176180
getStringAttrOrNull(node->getRawName()),
177181
getStringAttrOrNull(node->getRawLinkageName()),
178182
translate(node->getFile()), node->getLine(),

mlir/test/Dialect/LLVMIR/add-debuginfo-func-scope.mlir

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// CHECK: llvm.return loc(#loc
55
// CHECK: loc(#loc[[LOC:[0-9]+]])
66
// CHECK: #di_file = #llvm.di_file<"<unknown>" in "">
7-
// CHECK: #di_subprogram = #llvm.di_subprogram<compileUnit = #di_compile_unit, scope = #di_file, name = "func_no_debug", linkageName = "func_no_debug", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
7+
// CHECK: #di_subprogram = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #di_compile_unit, scope = #di_file, name = "func_no_debug", linkageName = "func_no_debug", file = #di_file, line = 1, scopeLine = 1, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
88
// CHECK: #loc[[LOC]] = loc(fused<#di_subprogram>
99
module {
1010
llvm.func @func_no_debug() {
@@ -14,12 +14,22 @@ module {
1414

1515
// -----
1616

17+
// Test that the declarations subprogram is not made distinct.
18+
// CHECK-LABEL: llvm.func @func_decl_no_debug()
19+
// CHECK: #di_subprogram = #llvm.di_subprogram<
20+
// CHECK-NOT: id = distinct
21+
module {
22+
llvm.func @func_decl_no_debug() loc(unknown)
23+
} loc(unknown)
24+
25+
// -----
26+
1727
// Test that existing debug info is not overwritten.
1828
// CHECK-LABEL: llvm.func @func_with_debug()
1929
// CHECK: llvm.return loc(#loc
2030
// CHECK: loc(#loc[[LOC:[0-9]+]])
2131
// CHECK: #di_file = #llvm.di_file<"<unknown>" in "">
22-
// CHECK: #di_subprogram = #llvm.di_subprogram<compileUnit = #di_compile_unit, scope = #di_file, name = "func_with_debug", linkageName = "func_with_debug", file = #di_file, line = 42, scopeLine = 42, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
32+
// CHECK: #di_subprogram = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #di_compile_unit, scope = #di_file, name = "func_with_debug", linkageName = "func_with_debug", file = #di_file, line = 42, scopeLine = 42, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
2333
// CHECK: #loc[[LOC]] = loc(fused<#di_subprogram>
2434
module {
2535
llvm.func @func_with_debug() {
@@ -31,7 +41,7 @@ module {
3141
#loc = loc("foo":0:0)
3242
#loc1 = loc(unknown)
3343
#di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #di_file, producer = "MLIR", isOptimized = true, emissionKind = LineTablesOnly>
34-
#di_subprogram = #llvm.di_subprogram<compileUnit = #di_compile_unit, scope = #di_file, name = "func_with_debug", linkageName = "func_with_debug", file = #di_file, line = 42, scopeLine = 42, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
44+
#di_subprogram = #llvm.di_subprogram<id = distinct[1]<>, compileUnit = #di_compile_unit, scope = #di_file, name = "func_with_debug", linkageName = "func_with_debug", file = #di_file, line = 42, scopeLine = 42, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
3545
#loc2 = loc(fused<#di_subprogram>[#loc1])
3646

3747
// -----
@@ -44,8 +54,8 @@ module {
4454
// CHECK-DAG: #[[DI_FILE_MODULE:.+]] = #llvm.di_file<"bar.mlir" in "baz">
4555
// CHECK-DAG: #[[DI_FILE_FUNC:.+]] = #llvm.di_file<"file.mlir" in "">
4656
// CHECK-DAG: #loc[[FUNCFILELOC:[0-9]+]] = loc("file.mlir":9:8)
47-
// CHECK-DAG: #di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #[[DI_FILE_MODULE]], producer = "MLIR", isOptimized = true, emissionKind = LineTablesOnly>
48-
// CHECK-DAG: #di_subprogram = #llvm.di_subprogram<compileUnit = #di_compile_unit, scope = #[[DI_FILE_FUNC]], name = "propagate_compile_unit", linkageName = "propagate_compile_unit", file = #[[DI_FILE_FUNC]], line = 9, scopeLine = 8, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
57+
// CHECK-DAG: #di_compile_unit = #llvm.di_compile_unit<id = distinct[{{.*}}]<>, sourceLanguage = DW_LANG_C, file = #[[DI_FILE_MODULE]], producer = "MLIR", isOptimized = true, emissionKind = LineTablesOnly>
58+
// CHECK-DAG: #di_subprogram = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #di_compile_unit, scope = #[[DI_FILE_FUNC]], name = "propagate_compile_unit", linkageName = "propagate_compile_unit", file = #[[DI_FILE_FUNC]], line = 9, scopeLine = 8, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type>
4959
// CHECK-DAG: #loc[[MODULELOC]] = loc(fused<#di_compile_unit>[#loc])
5060
// CHECK-DAG: #loc[[FUNCLOC]] = loc(fused<#di_subprogram>[#loc[[FUNCFILELOC]]
5161
module {

mlir/test/Target/LLVMIR/Import/debug-info.ll

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ define i32 @instruction_loc(i32 %arg1) {
3030
}
3131

3232
; CHECK-DAG: #[[RAW_FILE_LOC:.+]] = loc("debug-info.ll":1:2)
33-
; CHECK-DAG: #[[SP:.+]] = #llvm.di_subprogram<compileUnit = #{{.*}}, scope = #{{.*}}, name = "instruction_loc"
34-
; CHECK-DAG: #[[CALLEE:.+]] = #llvm.di_subprogram<compileUnit = #{{.*}}, scope = #{{.*}}, name = "callee"
33+
; CHECK-DAG: #[[SP:.+]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #{{.*}}, scope = #{{.*}}, name = "instruction_loc"
34+
; CHECK-DAG: #[[CALLEE:.+]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #{{.*}}, scope = #{{.*}}, name = "callee"
3535
; CHECK-DAG: #[[FILE_LOC]] = loc(fused<#[[SP]]>[#[[RAW_FILE_LOC]]])
3636
; CHECK-DAG: #[[RAW_CALLEE_LOC:.+]] = loc("debug-info.ll":7:4)
3737
; CHECK-DAG: #[[CALLEE_LOC:.+]] = loc(fused<#[[CALLEE]]>[#[[RAW_CALLEE_LOC]]])
@@ -63,7 +63,7 @@ define i32 @lexical_block(i32 %arg1) {
6363
ret i32 %2
6464
}
6565
; CHECK: #[[FILE:.+]] = #llvm.di_file<"debug-info.ll" in "/">
66-
; CHECK: #[[SP:.+]] = #llvm.di_subprogram<compileUnit =
66+
; CHECK: #[[SP:.+]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit =
6767
; CHECK: #[[LB0:.+]] = #llvm.di_lexical_block<scope = #[[SP]]>
6868
; CHECK: #[[LB1:.+]] = #llvm.di_lexical_block<scope = #[[SP]], file = #[[FILE]], line = 2, column = 2>
6969
; CHECK: #[[LOC0]] = loc(fused<#[[LB0]]>[{{.*}}])
@@ -93,7 +93,7 @@ define i32 @lexical_block_file(i32 %arg1) {
9393
ret i32 %2
9494
}
9595
; CHECK: #[[FILE:.+]] = #llvm.di_file<"debug-info.ll" in "/">
96-
; CHECK: #[[SP:.+]] = #llvm.di_subprogram<compileUnit =
96+
; CHECK: #[[SP:.+]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit =
9797
; CHECK: #[[LB0:.+]] = #llvm.di_lexical_block_file<scope = #[[SP]], discriminator = 0>
9898
; CHECK: #[[LB1:.+]] = #llvm.di_lexical_block_file<scope = #[[SP]], file = #[[FILE]], discriminator = 0>
9999
; CHECK: #[[LOC0]] = loc(fused<#[[LB0]]>[
@@ -200,7 +200,7 @@ define void @composite_type() !dbg !3 {
200200
; CHECK-DAG: #[[CU:.+]] = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #[[FILE]], isOptimized = false, emissionKind = None>
201201
; Verify an empty subroutine types list is supported.
202202
; CHECK-DAG: #[[SP_TYPE:.+]] = #llvm.di_subroutine_type<callingConvention = DW_CC_normal>
203-
; CHECK-DAG: #[[SP:.+]] = #llvm.di_subprogram<compileUnit = #[[CU]], scope = #[[FILE]], name = "subprogram", linkageName = "subprogram", file = #[[FILE]], line = 42, scopeLine = 42, subprogramFlags = Definition, type = #[[SP_TYPE]]>
203+
; CHECK-DAG: #[[SP:.+]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #[[CU]], scope = #[[FILE]], name = "subprogram", linkageName = "subprogram", file = #[[FILE]], line = 42, scopeLine = 42, subprogramFlags = Definition, type = #[[SP_TYPE]]>
204204

205205
define void @subprogram() !dbg !3 {
206206
ret void
@@ -224,7 +224,7 @@ define void @func_loc() !dbg !3 {
224224
}
225225
; CHECK-DAG: #[[NAME_LOC:.+]] = loc("func_loc")
226226
; CHECK-DAG: #[[FILE_LOC:.+]] = loc("debug-info.ll":42:0)
227-
; CHECK-DAG: #[[SP:.+]] = #llvm.di_subprogram<compileUnit = #{{.*}}, scope = #{{.*}}, name = "func_loc", file = #{{.*}}, line = 42, subprogramFlags = Definition>
227+
; CHECK-DAG: #[[SP:.+]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #{{.*}}, scope = #{{.*}}, name = "func_loc", file = #{{.*}}, line = 42, subprogramFlags = Definition>
228228

229229
; CHECK: loc(fused<#[[SP]]>[#[[NAME_LOC]], #[[FILE_LOC]]]
230230

@@ -300,7 +300,7 @@ define void @class_method() {
300300
; CHECK: #[[COMP:.+]] = #llvm.di_composite_type<tag = DW_TAG_class_type, name = "class_name", file = #{{.*}}, line = 42, flags = "TypePassByReference|NonTrivial">
301301
; CHECK: #[[COMP_PTR:.+]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, baseType = #[[COMP]], sizeInBits = 64>
302302
; CHECK: #[[SP_TYPE:.+]] = #llvm.di_subroutine_type<types = #{{.*}}, #[[COMP_PTR]]>
303-
; CHECK: #[[SP:.+]] = #llvm.di_subprogram<compileUnit = #{{.*}}, scope = #[[COMP]], name = "class_method", file = #{{.*}}, subprogramFlags = Definition, type = #[[SP_TYPE]]>
303+
; CHECK: #[[SP:.+]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #{{.*}}, scope = #[[COMP]], name = "class_method", file = #{{.*}}, subprogramFlags = Definition, type = #[[SP_TYPE]]>
304304
; CHECK: #[[LOC]] = loc(fused<#[[SP]]>
305305

306306
!llvm.dbg.cu = !{!1}
@@ -485,7 +485,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
485485
; // -----
486486

487487
; CHECK-DAG: #[[NAMESPACE:.+]] = #llvm.di_namespace<name = "std", exportSymbols = false>
488-
; CHECK-DAG: #[[SUBPROGRAM:.+]] = #llvm.di_subprogram<compileUnit = #{{.*}}, scope = #[[NAMESPACE]], name = "namespace"
488+
; CHECK-DAG: #[[SUBPROGRAM:.+]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #{{.*}}, scope = #[[NAMESPACE]], name = "namespace"
489489

490490
define void @namespace(ptr %arg) {
491491
call void @llvm.dbg.value(metadata ptr %arg, metadata !7, metadata !DIExpression()), !dbg !9
@@ -506,7 +506,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
506506

507507
; // -----
508508

509-
; CHECK-DAG: #[[SUBPROGRAM:.+]] = #llvm.di_subprogram<compileUnit = #{{.*}}, scope = #{{.*}}, name = "noname_variable"
509+
; CHECK-DAG: #[[SUBPROGRAM:.+]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #{{.*}}, scope = #{{.*}}, name = "noname_variable"
510510
; CHECK-DAG: #[[LOCAL_VARIABLE:.+]] = #llvm.di_local_variable<scope = #[[SUBPROGRAM]]>
511511

512512
define void @noname_variable(ptr %arg) {
@@ -527,7 +527,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
527527

528528
; // -----
529529

530-
; CHECK: #[[SUBPROGRAM:.*]] = #llvm.di_subprogram<compileUnit = #{{.*}}, scope = #{{.*}}, file = #{{.*}}, subprogramFlags = Definition>
530+
; CHECK: #[[SUBPROGRAM:.*]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #{{.*}}, scope = #{{.*}}, file = #{{.*}}, subprogramFlags = Definition>
531531
; CHECK: #[[FUNC_LOC:.*]] = loc(fused<#[[SUBPROGRAM]]>[{{.*}}])
532532
define void @noname_subprogram(ptr %arg) !dbg !8 {
533533
ret void
@@ -547,7 +547,7 @@ define void @noname_subprogram(ptr %arg) !dbg !8 {
547547
; CHECK-SAME: configMacros = "bar", includePath = "/",
548548
; CHECK-SAME: apinotes = "/", line = 42, isDecl = true
549549
; CHECK-SAME: >
550-
; CHECK: #[[SUBPROGRAM:.+]] = #llvm.di_subprogram<compileUnit = #{{.*}}, scope = #[[MODULE]], name = "func_in_module"
550+
; CHECK: #[[SUBPROGRAM:.+]] = #llvm.di_subprogram<id = distinct[{{.*}}]<>, compileUnit = #{{.*}}, scope = #[[MODULE]], name = "func_in_module"
551551

552552
define void @func_in_module(ptr %arg) !dbg !8 {
553553
ret void
@@ -614,3 +614,16 @@ define void @distinct_cu_func1() !dbg !5 {
614614
!4 = distinct !DISubprogram(name: "func", linkageName: "func", scope: !6, file: !6, line: 1, scopeLine: 1, flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: !0)
615615
!5 = distinct !DISubprogram(name: "func", linkageName: "func", scope: !6, file: !6, line: 1, scopeLine: 1, flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: !1)
616616
!6 = !DIFile(filename: "file.hpp", directory: "/")
617+
618+
; // -----
619+
620+
; CHECK-LABEL: @declaration
621+
declare !dbg !1 void @declaration()
622+
623+
; CHECK: #di_subprogram = #llvm.di_subprogram<
624+
; CHECK-NOT: id = distinct
625+
626+
!llvm.module.flags = !{!0}
627+
!0 = !{i32 2, !"Debug Info Version", i32 3}
628+
!1 = !DISubprogram(name: "declaration", scope: !2, file: !2, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
629+
!2 = !DIFile(filename: "debug-info.ll", directory: "/")

0 commit comments

Comments
 (0)