@@ -195,6 +195,49 @@ TEST(MetadataTest, DeleteInstUsedByDbgRecord) {
195
195
EXPECT_TRUE (isa<UndefValue>(DVRs[0 ]->getValue (0 )));
196
196
}
197
197
198
+ TEST (MetadataTest, GlobalConstantMetadataUsedByDbgRecord) {
199
+ LLVMContext C;
200
+ std::unique_ptr<Module> M = parseIR (C, R"(
201
+ @x = dso_local global i32 0, align 4
202
+ declare void @llvm.dbg.value(metadata, metadata, metadata) #0
203
+
204
+ define i16 @f(i16 %a) !dbg !6 {
205
+ %b = add i16 %a, 1, !dbg !11
206
+ call void @llvm.dbg.declare(metadata ptr @x, metadata !9, metadata !DIExpression()), !dbg !11
207
+ call void @llvm.dbg.value(metadata ptr @x, metadata !9, metadata !DIExpression()), !dbg !11
208
+ ret i16 0, !dbg !11
209
+ }
210
+
211
+ attributes #0 = { nounwind readnone speculatable willreturn }
212
+
213
+ !llvm.dbg.cu = !{!0}
214
+ !llvm.module.flags = !{!5}
215
+
216
+ !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
217
+ !1 = !DIFile(filename: "t.ll", directory: "/")
218
+ !2 = !{}
219
+ !5 = !{i32 2, !"Debug Info Version", i32 3}
220
+ !6 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !1, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
221
+ !7 = !DISubroutineType(types: !2)
222
+ !8 = !{!9}
223
+ !9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10)
224
+ !10 = !DIBasicType(name: "ty16", size: 16, encoding: DW_ATE_unsigned)
225
+ !11 = !DILocation(line: 1, column: 1, scope: !6)
226
+ )" );
227
+
228
+ // Find the global @x
229
+ Value *V = M->getNamedValue (" x" );
230
+
231
+ // Find the dbg.value
232
+ auto DVIs = findDbgDeclares (V);
233
+ auto DVRs = findDVRDeclares (V);
234
+ auto DVRVs = findDVRValues (V);
235
+
236
+ EXPECT_EQ (DVRs[0 ]->getNumVariableLocationOps (), 1u );
237
+ EXPECT_TRUE (DVRVs.size () == 1 );
238
+ EXPECT_FALSE (isa<UndefValue>(DVRs[0 ]->getValue (0 )));
239
+ }
240
+
198
241
TEST (DbgVariableIntrinsic, EmptyMDIsKillLocation) {
199
242
LLVMContext Ctx;
200
243
std::unique_ptr<Module> M = parseIR (Ctx, R"(
0 commit comments