[PATCH] D97311: [DebugInfo] Introduce DIConstant metadata for representing named constants

Sourabh Singh Tomar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 10 02:52:34 PST 2021


SouraVX added a comment.

In D97311#2590688 <https://reviews.llvm.org/D97311#2590688>, @aprantl wrote:

> Here's an example that seems to work:

...

Thanks @aprantl for quick example. Apologies for delayed response, I got occupied with something else.
One question I have is for `Negative(or Signed) constants` Consider slightly tweaked version of sample provide by you.
I tried representing `Negative` 10(for demonstration purpose only) as:

  !DIGlobalVariableExpression(var: !7, expr: !DIExpression(DW_OP_consts, 10, DW_OP_stack_value))

Compiling this, as you may notice, results in no warning/error, **but** `DW_AT_location` is missing from the DWARF so variable not visible in debugger.

  source_filename = "globalconst.c"
  target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
  target triple = "x86_64-apple-macosx10.13.0"
  
  !llvm.dbg.cu = !{!2}
  !llvm.module.flags = !{!10, !11, !12, !13}
  
  !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
  !3 = !DIFile(filename: "globalconst.c", directory: "/")
  !4 = !{}
  !5 = !{!16}
  !7 = distinct !DIGlobalVariable(name: "constant", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true)
  !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
  !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  !10 = !{i32 2, !"Dwarf Version", i32 4}
  !11 = !{i32 2, !"Debug Info Version", i32 3}
  !12 = !{i32 1, !"wchar_size", i32 4}
  !13 = !{i32 7, !"PIC Level", i32 2}
  !16 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression(DW_OP_consts, 10, DW_OP_stack_value))  !Tweaked slightly, to check for negative constants



  $ bin/llc -filetype=obj /tmp/globalconst.ll -o - | dwarfdump -
  0x0000001e:   DW_TAG_variable
                  DW_AT_name	("constant")
                  DW_AT_type	(0x0000002a "int*")
                  DW_AT_external	(true)
                  DW_AT_decl_file	("globalconst.c")
                  DW_AT_decl_line	(2)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97311/new/

https://reviews.llvm.org/D97311



More information about the llvm-commits mailing list