debug-info-enum.ll 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. ; Test enumeration representation in DWARF debug info:
  2. ; * test value representation for each possible underlying integer type
  3. ; * test the integer type is as expected
  4. ; * test the DW_AT_enum_class attribute is present (resp. absent) as expected.
  5. ; RUN: llc -debugger-tune=gdb -dwarf-version=4 -filetype=obj -o %t.o < %s
  6. ; RUN: llvm-dwarfdump -debug-info %t.o | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-DW4
  7. ; RUN: llc -debugger-tune=gdb -dwarf-version=2 -filetype=obj -o %t.o < %s
  8. ; RUN: llvm-dwarfdump -debug-info %t.o | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-DW2
  9. @x0 = global i8 0, align 1, !dbg !0
  10. @x1 = global i8 0, align 1, !dbg !46
  11. @x2 = global i16 0, align 2, !dbg !48
  12. @x3 = global i16 0, align 2, !dbg !50
  13. @x4 = global i32 0, align 4, !dbg !52
  14. @x5 = global i32 0, align 4, !dbg !54
  15. @x6 = global i64 0, align 8, !dbg !56
  16. @x7 = global i64 0, align 8, !dbg !58
  17. @x8 = global i32 0, align 4, !dbg !60
  18. !llvm.dbg.cu = !{!2}
  19. !llvm.module.flags = !{!62}
  20. !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
  21. !1 = distinct !DIGlobalVariable(name: "x0", scope: !2, file: !3, line: 5, type: !5, isLocal: false, isDefinition: true)
  22. !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 7.0.0 (/data/src/llvm/tools/clang 0c08d9830124a75675348b4eeb47256f3da6693d) (/data/src/llvm cf29510f52faa77b98510cd53276f564d1f4f41f)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !45)
  23. !3 = !DIFile(filename: "/data/src/llvm-dev/tools/clang/test/CodeGen/debug-info-enum.cpp", directory: "/work/build/clang-dev")
  24. !4 = !{!5, !10, !14, !19, !23, !28, !32, !37, !41}
  25. ; Test enumeration with a fixed "signed char" underlying type.
  26. !5 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E0", file: !3, line: 2, baseType: !6, size: 8, flags: DIFlagEnumClass, elements: !7, identifier: "_ZTS2E0")
  27. !6 = !DIBasicType(name: "signed char", size: 8, encoding: DW_ATE_signed_char)
  28. !7 = !{!8, !9}
  29. !8 = !DIEnumerator(name: "A0", value: -128)
  30. !9 = !DIEnumerator(name: "B0", value: 127)
  31. ; CHECK: DW_TAG_enumeration_type
  32. ; CHECK-DW2-NOT: DW_AT_type
  33. ; CHECK-DW4: DW_AT_type{{.*}}"signed char"
  34. ; CHECK-DW4: DW_AT_enum_class (true)
  35. ; CHECK: DW_AT_name ("E0")
  36. ; CHECK: DW_TAG_enumerator
  37. ; CHECK: DW_AT_name ("A0")
  38. ; CHECK-NEXT: DW_AT_const_value (-128)
  39. ; CHECK: DW_TAG_enumerator
  40. ; CHECK: DW_AT_name ("B0")
  41. ; CHECK-NEXT: DW_AT_const_value (127)
  42. ; Test enumeration with a fixed "unsigned char" underlying type.
  43. !10 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E1", file: !3, line: 12, baseType: !11, size: 8, flags: DIFlagEnumClass, elements: !12, identifier: "_ZTS2E1")
  44. !11 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char)
  45. !12 = !{!13}
  46. !13 = !DIEnumerator(name: "A1", value: 255, isUnsigned: true)
  47. ; CHECK: DW_TAG_enumeration_type
  48. ; CHECK-DW2-NOT: DW_AT_type
  49. ; CHECK-DW4: DW_AT_type{{.*}}"unsigned char"
  50. ; CHECK-DW4: DW_AT_enum_class (true)
  51. ; CHECK: DW_AT_name ("E1")
  52. ; CHECK: DW_TAG_enumerator
  53. ; CHECK: DW_AT_name ("A1")
  54. ; CHECK-NEXT: DW_AT_const_value (255)
  55. ; Test enumeration with a fixed "short" underlying type.
  56. !14 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E2", file: !3, line: 18, baseType: !15, size: 16, flags: DIFlagEnumClass, elements: !16, identifier: "_ZTS2E2")
  57. !15 = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed)
  58. !16 = !{!17, !18}
  59. !17 = !DIEnumerator(name: "A2", value: -32768)
  60. !18 = !DIEnumerator(name: "B2", value: 32767)
  61. ; CHECK: DW_TAG_enumeration_type
  62. ; CHECK-DW2-NOT: DW_AT_type
  63. ; CHECK-DW4: DW_AT_type{{.*}} "short"
  64. ; CHECK-DW4: DW_AT_enum_class (true)
  65. ; CHECK: DW_AT_name ("E2")
  66. ; CHECK: DW_TAG_enumerator
  67. ; CHECK: DW_AT_name ("A2")
  68. ; CHECK-NEXT: DW_AT_const_value (-32768)
  69. ; CHECK: DW_TAG_enumerator
  70. ; CHECK: DW_AT_name ("B2")
  71. ; CHECK-NEXT: DW_AT_const_value (32767)
  72. ; Test enumeration with a fixed "unsigned short" underlying type.
  73. !19 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E3", file: !3, line: 28, baseType: !20, size: 16, flags: DIFlagEnumClass, elements: !21, identifier: "_ZTS2E3")
  74. !20 = !DIBasicType(name: "unsigned short", size: 16, encoding: DW_ATE_unsigned)
  75. !21 = !{!22}
  76. !22 = !DIEnumerator(name: "A3", value: 65535, isUnsigned: true)
  77. ; CHECK: DW_TAG_enumeration_type
  78. ; CHECK-DW2-NOT: DW_AT_type
  79. ; CHECK-DW4: DW_AT_type{{.*}}"unsigned short"
  80. ; CHECK-DW4: DW_AT_enum_class (true)
  81. ; CHECK: DW_AT_name ("E3")
  82. ; CHECK: DW_TAG_enumerator
  83. ; CHECK: DW_AT_name ("A3")
  84. ; CHECK-NEXT: DW_AT_const_value (65535)
  85. ; Test enumeration with a fixed "int" underlying type.
  86. !23 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E4", file: !3, line: 34, baseType: !24, size: 32, flags: DIFlagEnumClass, elements: !25, identifier: "_ZTS2E4")
  87. !24 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  88. !25 = !{!26, !27}
  89. !26 = !DIEnumerator(name: "A4", value: -2147483648)
  90. !27 = !DIEnumerator(name: "B4", value: 2147483647)
  91. ; CHECK: DW_TAG_enumeration_type
  92. ; CHECK-DW2-NOT: DW_AT_type
  93. ; CHECK-DW4: DW_AT_type{{.*}}"int"
  94. ; CHECK-DW4: DW_AT_enum_class (true)
  95. ; CHECK: DW_AT_name ("E4")
  96. ; CHECK: DW_TAG_enumerator
  97. ; CHECK: DW_AT_name ("A4")
  98. ; CHECK-NEXT: DW_AT_const_value (-2147483648)
  99. ; CHECK: DW_TAG_enumerator
  100. ; CHECK: DW_AT_name ("B4")
  101. ; CHECK-NEXT: DW_AT_const_value (2147483647)
  102. ; Test enumeration with a fixed "unsigend int" underlying type.
  103. !28 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E5", file: !3, line: 41, baseType: !29, size: 32, flags: DIFlagEnumClass, elements: !30, identifier: "_ZTS2E5")
  104. !29 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
  105. !30 = !{!31}
  106. !31 = !DIEnumerator(name: "A5", value: 4294967295, isUnsigned: true)
  107. ; CHECK: DW_TAG_enumeration_type
  108. ; CHECK-DW2-NOT: DW_AT_type
  109. ; CHECK-DW4: DW_AT_type{{.*}}"unsigned int"
  110. ; CHECK-DW4: DW_AT_enum_class (true)
  111. ; CHECK: DW_AT_name ("E5")
  112. ; CHECK: DW_TAG_enumerator
  113. ; CHECK: DW_AT_name ("A5")
  114. ; CHECK-NEXT: DW_AT_const_value (4294967295)
  115. ; Test enumeration with a fixed "long long" underlying type.
  116. !32 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E6", file: !3, line: 47, baseType: !33, size: 64, flags: DIFlagEnumClass, elements: !34, identifier: "_ZTS2E6")
  117. !33 = !DIBasicType(name: "long long int", size: 64, encoding: DW_ATE_signed)
  118. !34 = !{!35, !36}
  119. !35 = !DIEnumerator(name: "A6", value: -9223372036854775808)
  120. !36 = !DIEnumerator(name: "B6", value: 9223372036854775807)
  121. ; CHECK: DW_TAG_enumeration_type
  122. ; CHECK-DW2-NOT: DW_AT_type
  123. ; CHECK-DW4: DW_AT_type{{.*}}"long long int"
  124. ; CHECK-DW4: DW_AT_enum_class (true)
  125. ; CHECK: DW_AT_name ("E6")
  126. ; CHECK: DW_TAG_enumerator
  127. ; CHECK: DW_AT_name ("A6")
  128. ; CHECK-NEXT: DW_AT_const_value (-9223372036854775808)
  129. ; CHECK: DW_TAG_enumerator
  130. ; CHECK: DW_AT_name ("B6")
  131. ; CHECK-NEXT: DW_AT_const_value (9223372036854775807)
  132. ; Test enumeration with a fixed "unsigned long long" underlying type.
  133. !37 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E7", file: !3, line: 57, baseType: !38, size: 64, flags: DIFlagEnumClass, elements: !39, identifier: "_ZTS2E7")
  134. !38 = !DIBasicType(name: "long long unsigned int", size: 64, encoding: DW_ATE_unsigned)
  135. !39 = !{!40}
  136. !40 = !DIEnumerator(name: "A7", value: 18446744073709551615, isUnsigned: true)
  137. ; CHECK: DW_TAG_enumeration_type
  138. ; CHECK-DW2-NOT: DW_AT_type
  139. ; CHECK-DW4: DW_AT_type{{.*}}"long long unsigned int"
  140. ; CHECK-DW4: DW_AT_enum_class (true)
  141. ; CHECK: DW_AT_name ("E7")
  142. ; CHECK: DW_TAG_enumerator
  143. ; CHECK: DW_AT_name ("A7")
  144. ; CHECK-NEXT: DW_AT_const_value (18446744073709551615)
  145. ; Test enumeration without a fixed underlying type. The underlying type should
  146. ; still be present (for DWARF >= 3), but the DW_AT_enum_class attribute should
  147. ; be absent.
  148. !41 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E8", file: !3, line: 63, baseType: !24, size: 32, elements: !42, identifier: "_ZTS2E8")
  149. !42 = !{!43, !44}
  150. !43 = !DIEnumerator(name: "A8", value: -128)
  151. !44 = !DIEnumerator(name: "B8", value: 127)
  152. ; CHECK: DW_TAG_enumeration_type
  153. ; CHECK-DW2-NOT: DW_AT_type
  154. ; CHECK-DW4: DW_AT_type{{.*}}"int"
  155. ; CHECK-NOT: DW_AT_enum_class
  156. ; CHECK: DW_AT_name ("E8")
  157. ; Test enumeration without a fixed underlying type, but with the DIFlagEnumClass
  158. ; set. The DW_AT_enum_class attribute should be absent. This behaviour is
  159. ; intented to keep compatibilty with existing DWARF consumers, which may imply
  160. ; the type is present whenever DW_AT_enum_class is set.
  161. !63 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E9", file: !3, line: 63, size: 32, flags: DIFlagEnumClass, elements: !64, identifier: "_ZTS2E9")
  162. !64 = !{!65, !66}
  163. !65 = !DIEnumerator(name: "A9", value: -128)
  164. !66 = !DIEnumerator(name: "B9", value: 127)
  165. ; CHECK: DW_TAG_enumeration_type
  166. ; CHECK-NOT: DW_AT_type
  167. ; CHECK-NOT: DW_AT_enum_class
  168. ; CHECK: DW_AT_name ("E9")
  169. !45 = !{!0, !46, !48, !50, !52, !54, !56, !58, !60, !67}
  170. !46 = !DIGlobalVariableExpression(var: !47, expr: !DIExpression())
  171. !47 = distinct !DIGlobalVariable(name: "x1", scope: !2, file: !3, line: 12, type: !10, isLocal: false, isDefinition: true)
  172. !48 = !DIGlobalVariableExpression(var: !49, expr: !DIExpression())
  173. !49 = distinct !DIGlobalVariable(name: "x2", scope: !2, file: !3, line: 21, type: !14, isLocal: false, isDefinition: true)
  174. !50 = !DIGlobalVariableExpression(var: !51, expr: !DIExpression())
  175. !51 = distinct !DIGlobalVariable(name: "x3", scope: !2, file: !3, line: 28, type: !19, isLocal: false, isDefinition: true)
  176. !52 = !DIGlobalVariableExpression(var: !53, expr: !DIExpression())
  177. !53 = distinct !DIGlobalVariable(name: "x4", scope: !2, file: !3, line: 34, type: !23, isLocal: false, isDefinition: true)
  178. !54 = !DIGlobalVariableExpression(var: !55, expr: !DIExpression())
  179. !55 = distinct !DIGlobalVariable(name: "x5", scope: !2, file: !3, line: 41, type: !28, isLocal: false, isDefinition: true)
  180. !56 = !DIGlobalVariableExpression(var: !57, expr: !DIExpression())
  181. !57 = distinct !DIGlobalVariable(name: "x6", scope: !2, file: !3, line: 50, type: !32, isLocal: false, isDefinition: true)
  182. !58 = !DIGlobalVariableExpression(var: !59, expr: !DIExpression())
  183. !59 = distinct !DIGlobalVariable(name: "x7", scope: !2, file: !3, line: 57, type: !37, isLocal: false, isDefinition: true)
  184. !60 = !DIGlobalVariableExpression(var: !61, expr: !DIExpression())
  185. !61 = distinct !DIGlobalVariable(name: "x8", scope: !2, file: !3, line: 63, type: !41, isLocal: false, isDefinition: true)
  186. !67 = !DIGlobalVariableExpression(var: !68, expr: !DIExpression())
  187. !68 = distinct !DIGlobalVariable(name: "x9", scope: !2, file: !3, line: 63, type: !63, isLocal: false, isDefinition: true)
  188. !62 = !{i32 2, !"Debug Info Version", i32 3}