llvm.org GIT mirror llvm / b056aa7
DebugInfo: Move new hierarchy into place Move the specialized metadata nodes for the new debug info hierarchy into place, finishing off PR22464. I've done bootstraps (and all that) and I'm confident this commit is NFC as far as DWARF output is concerned. Let me know if I'm wrong :). The code changes are fairly mechanical: - Bumped the "Debug Info Version". - `DIBuilder` now creates the appropriate subclass of `MDNode`. - Subclasses of DIDescriptor now expect to hold their "MD" counterparts (e.g., `DIBasicType` expects `MDBasicType`). - Deleted a ton of dead code in `AsmWriter.cpp` and `DebugInfo.cpp` for printing comments. - Big update to LangRef to describe the nodes in the new hierarchy. Feel free to make it better. Testcase changes are enormous. There's an accompanying clang commit on its way. If you have out-of-tree debug info testcases, I just broke your build. - `upgrade-specialized-nodes.sh` is attached to PR22564. I used it to update all the IR testcases. - Unfortunately I failed to find way to script the updates to CHECK lines, so I updated all of these by hand. This was fairly painful, since the old CHECKs are difficult to reason about. That's one of the benefits of the new hierarchy. This work isn't quite finished, BTW. The `DIDescriptor` subclasses are almost empty wrappers, but not quite: they still have loose casting checks (see the `RETURN_FROM_RAW()` macro). Once they're completely gutted, I'll rename the "MD" classes to "DI" and kill the wrappers. I also expect to make a few schema changes now that it's easier to reason about everything. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231082 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
380 changed file(s) with 7702 addition(s) and 8225 deletion(s). Raw diff Collapse all Expand all
28362836
28372837 All metadata are identified in syntax by a exclamation point ('``!``').
28382838
2839 .. _metadata-string:
2840
28392841 Metadata Nodes and Metadata Strings
28402842 -----------------------------------
28412843
28952897 to generic tuples). Their fields are labelled, and can be specified in any
28962898 order.
28972899
2900 These aren't inherently debug info centric, but currently all the specialized
2901 metadata nodes are related to debug info.
2902
2903 MDCompileUnit
2904 """""""""""""
2905
2906 ``MDCompileUnit`` nodes represent a compile unit. The ``enums:``,
2907 ``retainedTypes:``, ``subprograms:``, ``globals:`` and ``imports:`` fields are
2908 tuples containing the debug info to be emitted along with the compile unit,
2909 regardless of code optimizations (some nodes are only emitted if there are
2910 references to them from instructions).
2911
2912 .. code-block:: llvm
2913
2914 !0 = !MDCompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
2915 isOptimized: true, flags: "-O2", runtimeVersion: 2,
2916 splitDebugFilename: "abc.debug", emissionKind: 1,
2917 enums: !2, retainedTypes: !3, subprograms: !4,
2918 globals: !5, imports: !6)
2919
2920 MDFile
2921 """"""
2922
2923 ``MDFile`` nodes represent files. The ``filename:`` can include slashes.
2924
2925 .. code-block:: llvm
2926
2927 !0 = !MDFile(filename: "path/to/file", directory: "/path/to/dir")
2928
2929 .. _MDLocation:
2930
2931 MDBasicType
2932 """""""""""
2933
2934 ``MDBasicType`` nodes represent primitive types. ``tag:`` defaults to
2935 ``DW_TAG_base_type``.
2936
2937 .. code-block:: llvm
2938
2939 !0 = !MDBasicType(name: "unsigned char", size: 8, align: 8,
2940 encoding: DW_ATE_unsigned_char)
2941 !1 = !MDBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
2942
2943 .. _MDSubroutineType:
2944
2945 MDSubroutineType
2946 """"""""""""""""
2947
2948 ``MDSubroutineType`` nodes represent subroutine types. Their ``types:`` field
2949 refers to a tuple; the first operand is the return type, while the rest are the
2950 types of the formal arguments in order. If the first operand is ``null``, that
2951 represents a function with no return value (such as ``void foo() {}`` in C++).
2952
2953 .. code-block:: llvm
2954
2955 !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed)
2956 !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char)
2957 !2 = !MDSubroutineType(types: !{null, !0, !1}) ; void (int, char)
2958
2959 MDDerivedType
2960 """""""""""""
2961
2962 ``MDDerivedType`` nodes represent types derived from other types, such as
2963 qualified types.
2964
2965 .. code-block:: llvm
2966
2967 !0 = !MDBasicType(name: "unsigned char", size: 8, align: 8,
2968 encoding: DW_ATE_unsigned_char)
2969 !1 = !MDDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32,
2970 align: 32)
2971
2972 .. _MDCompositeType:
2973
2974 MDCompositeType
2975 """""""""""""""
2976
2977 ``MDCompositeType`` nodes represent types composed of other types, like
2978 structures and unions. ``elements:`` points to a tuple of the composed types.
2979
2980 If the source language supports ODR, the ``identifier:`` field gives the unique
2981 identifier used for type merging between modules. When specified, other types
2982 can refer to composite types indirectly via a :ref:`metadata string
2983 ` that matches their identifier.
2984
2985 .. code-block:: llvm
2986
2987 !0 = !MDEnumerator(name: "SixKind", value: 7)
2988 !1 = !MDEnumerator(name: "SevenKind", value: 7)
2989 !2 = !MDEnumerator(name: "NegEightKind", value: -8)
2990 !3 = !MDCompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12,
2991 line: 2, size: 32, align: 32, identifier: "_M4Enum",
2992 elements: !{!0, !1, !2})
2993
2994 MDSubrange
2995 """"""""""
2996
2997 ``MDSubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of
2998 :ref:`MDCompositeType`. ``count: -1`` indicates an empty array.
2999
3000 .. code-block:: llvm
3001
3002 !0 = !MDSubrange(count: 5, lowerBound: 0) ; array counting from 0
3003 !1 = !MDSubrange(count: 5, lowerBound: 1) ; array counting from 1
3004 !2 = !MDSubrange(count: -1) ; empty array.
3005
3006 MDEnumerator
3007 """"""""""""
3008
3009 ``MDEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type``
3010 variants of :ref:`MDCompositeType`.
3011
3012 .. code-block:: llvm
3013
3014 !0 = !MDEnumerator(name: "SixKind", value: 7)
3015 !1 = !MDEnumerator(name: "SevenKind", value: 7)
3016 !2 = !MDEnumerator(name: "NegEightKind", value: -8)
3017
3018 MDTemplateTypeParameter
3019 """""""""""""""""""""""
3020
3021 ``MDTemplateTypeParameter`` nodes represent type parameters to generic source
3022 language constructs. They are used (optionally) in :ref:`MDCompositeType` and
3023 :ref:`MDSubprogram` ``templateParams:`` fields.
3024
3025 .. code-block:: llvm
3026
3027 !0 = !MDTemplateTypeParameter(name: "Ty", type: !1)
3028
3029 MDTemplateValueParameter
3030 """"""""""""""""""""""""
3031
3032 ``MDTemplateValueParameter`` nodes represent value parameters to generic source
3033 language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``,
3034 but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or
3035 ``DW_TAG_GNU_template_param_pack``. They are used (optionally) in
3036 :ref:`MDCompositeType` and :ref:`MDSubprogram` ``templateParams:`` fields.
3037
3038 .. code-block:: llvm
3039
3040 !0 = !MDTemplateValueParameter(name: "Ty", type: !1, value: i32 7)
3041
3042 MDNamespace
3043 """""""""""
3044
3045 ``MDNamespace`` nodes represent namespaces in the source language.
3046
3047 .. code-block:: llvm
3048
3049 !0 = !MDNamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7)
3050
3051 MDGlobalVariable
3052 """"""""""""""""
3053
3054 ``MDGlobalVariable`` nodes represent global variables in the source language.
3055
3056 .. code-block:: llvm
3057
3058 !0 = !MDGlobalVariable(name: "foo", linkageName: "foo", scope: !1,
3059 file: !2, line: 7, type: !3, isLocal: true,
3060 isDefinition: false, variable: i32* @foo,
3061 declaration: !4)
3062
3063 .. _MDSubprogram:
3064
3065 MDSubprogram
3066 """"""""""""
3067
3068 ``MDSubprogram`` nodes represent functions from the source language. The
3069 ``variables:`` field points at :ref:`variables ` that must be
3070 retained, even if their IR counterparts are optimized out of the IR. The
3071 ``type:`` field must point at an :ref:`MDSubroutineType`.
3072
3073 .. code-block:: llvm
3074
3075 !0 = !MDSubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
3076 file: !2, line: 7, type: !3, isLocal: true,
3077 isDefinition: false, scopeLine: 8, containingType: !4,
3078 virtuality: DW_VIRTUALITY_pure_virtual, virtualIndex: 10,
3079 flags: DIFlagPrototyped, isOptimized: true,
3080 function: void ()* @_Z3foov,
3081 templateParams: !5, declaration: !6, variables: !7)
3082
3083 .. _MDLexicalBlock:
3084
3085 MDLexicalBlock
3086 """"""""""""""
3087
3088 ``MDLexicalBlock`` nodes represent lexical blocks in the source language (a
3089 scope).
3090
3091 .. code-block:: llvm
3092
3093 !0 = !MDLexicalBlock(scope: !1, file: !2, line: 7, column: 35)
3094
3095 .. _MDLexicalBlockFile:
3096
3097 MDLexicalBlockFile
3098 """"""""""""""""""
3099
3100 ``MDLexicalBlockFile`` nodes are used to discriminate between sections of a
3101 :ref:`lexical block `. The ``file:`` field can be changed to
3102 indicate textual inclusion, or the ``discriminator:`` field can be used to
3103 discriminate between control flow within a single block in the source language.
3104
3105 .. code-block:: llvm
3106
3107 !0 = !MDLexicalBlock(scope: !3, file: !4, line: 7, column: 35)
3108 !1 = !MDLexicalBlockFile(scope: !0, file: !4, discriminator: 0)
3109 !2 = !MDLexicalBlockFile(scope: !0, file: !4, discriminator: 1)
3110
28983111 MDLocation
28993112 """"""""""
29003113
29013114 ``MDLocation`` nodes represent source debug locations. The ``scope:`` field is
2902 mandatory.
3115 mandatory, and points at an :ref:`MDLexicalBlockFile`, an
3116 :ref:`MDLexicalBlock`, or an :ref:`MDSubprogram`.
29033117
29043118 .. code-block:: llvm
29053119
29063120 !0 = !MDLocation(line: 2900, column: 42, scope: !1, inlinedAt: !2)
3121
3122 .. _MDLocalVariable:
3123
3124 MDLocalVariable
3125 """""""""""""""
3126
3127 ``MDLocalVariable`` nodes represent local variables in the source language.
3128 Instead of ``DW_TAG_variable``, they use LLVM-specific fake tags to
3129 discriminate between local variables (``DW_TAG_auto_variable``) and subprogram
3130 arguments (``DW_TAG_arg_variable``). In the latter case, the ``arg:`` field
3131 specifies the argument position, and this variable will be included in the
3132 ``variables:`` field of its :ref:`MDSubprogram`.
3133
3134 If set, the ``inlinedAt:`` field points at an :ref:`MDLocation`, and the
3135 variable represents an inlined version of a variable (with all other fields
3136 duplicated from the non-inlined version).
3137
3138 .. code-block:: llvm
3139
3140 !0 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 0,
3141 scope: !3, file: !2, line: 7, type: !3,
3142 flags: DIFlagArtificial, inlinedAt: !4)
3143 !1 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "x", arg: 1,
3144 scope: !4, file: !2, line: 7, type: !3,
3145 inlinedAt: !6)
3146 !1 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "y",
3147 scope: !5, file: !2, line: 7, type: !3,
3148 inlinedAt: !6)
3149
3150 MDExpression
3151 """"""""""""
3152
3153 ``MDExpression`` nodes represent DWARF expression sequences. They are used in
3154 :ref:`debug intrinsics` (such as ``llvm.dbg.declare``) to
3155 describe how the referenced LLVM variable relates to the source language
3156 variable.
3157
3158 The current supported vocabulary is limited:
3159
3160 - ``DW_OP_deref`` dereferences the working expression.
3161 - ``DW_OP_plus, 93`` adds ``93`` to the working expression.
3162 - ``DW_OP_bit_piece, 16, 8`` specifies the offset and size (``16`` and ``8``
3163 here, respectively) of the variable piece from the working expression.
3164
3165 .. code-block:: llvm
3166
3167 !0 = !MDExpression(DW_OP_deref)
3168 !1 = !MDExpression(DW_OP_plus, 3)
3169 !2 = !MDExpression(DW_OP_bit_piece, 3, 7)
3170 !3 = !MDExpression(DW_OP_deref, DW_OP_plus, 3, DW_OP_bit_piece, 3, 7)
3171
3172 MDObjCProperty
3173 """"""""""""""
3174
3175 ``MDObjCProperty`` nodes represent Objective-C property nodes.
3176
3177 .. code-block:: llvm
3178
3179 !3 = !MDObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
3180 getter: "getFoo", attributes: 7, type: !2)
3181
3182 MDImportedEntity
3183 """"""""""""""""
3184
3185 ``MDImportedEntity`` nodes represent entities (such as modules) imported into a
3186 compile unit.
3187
3188 .. code-block:: llvm
3189
3190 !2 = !MDImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
3191 entity: !1, line: 7)
29073192
29083193 '``tbaa``' Metadata
29093194 ^^^^^^^^^^^^^^^^^^^
92169501 %a = load i16* @x, align 2
92179502 %res = call float @llvm.convert.from.fp16(i16 %a)
92189503
9504 .. _dbg_intrinsics:
9505
92199506 Debugger Intrinsics
92209507 -------------------
92219508
164164 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
165165 Constant *getConstantField(unsigned Elt) const;
166166 Function *getFunctionField(unsigned Elt) const;
167 void replaceFunctionField(unsigned Elt, Function *F);
168167
169168 public:
170169 explicit DIDescriptor(const MDNode *N = nullptr) : DbgNode(N) {}
214213 return getHeaderIterator(Index).getNumber();
215214 }
216215
217 uint16_t getTag() const { return getHeaderFieldAs(0); }
218
219 bool isDerivedType() const;
220 bool isCompositeType() const;
221 bool isSubroutineType() const;
222 bool isBasicType() const;
223 bool isVariable() const;
224 bool isSubprogram() const;
225 bool isGlobalVariable() const;
226 bool isScope() const;
227 bool isFile() const;
228 bool isCompileUnit() const;
229 bool isNameSpace() const;
230 bool isLexicalBlockFile() const;
231 bool isLexicalBlock() const;
232 bool isSubrange() const;
233 bool isEnumerator() const;
234 bool isType() const;
235 bool isTemplateTypeParameter() const;
236 bool isTemplateValueParameter() const;
237 bool isObjCProperty() const;
238 bool isImportedEntity() const;
239 bool isExpression() const;
216 uint16_t getTag() const {
217 if (auto *N = dyn_cast_or_null(get()))
218 return N->getTag();
219 return 0;
220 }
221
222 bool isDerivedType() const { return get() && isa(get()); }
223 bool isCompositeType() const {
224 return get() && isa(get());
225 }
226 bool isSubroutineType() const {
227 return get() && isa(get());
228 }
229 bool isBasicType() const { return get() && isa(get()); }
230 bool isVariable() const { return get() && isa(get()); }
231 bool isSubprogram() const { return get() && isa(get()); }
232 bool isGlobalVariable() const {
233 return get() && isa(get());
234 }
235 bool isScope() const { return get() && isa(get()); }
236 bool isFile() const { return get() && isa(get()); }
237 bool isCompileUnit() const { return get() && isa(get()); }
238 bool isNameSpace() const{ return get() && isa(get()); }
239 bool isLexicalBlockFile() const {
240 return get() && isa(get());
241 }
242 bool isLexicalBlock() const {
243 return get() && isa(get());
244 }
245 bool isSubrange() const { return get() && isa(get()); }
246 bool isEnumerator() const { return get() && isa(get()); }
247 bool isType() const { return get() && isa(get()); }
248 bool isTemplateTypeParameter() const {
249 return get() && isa(get());
250 }
251 bool isTemplateValueParameter() const {
252 return get() && isa(get());
253 }
254 bool isObjCProperty() const { return get() && isa(get()); }
255 bool isImportedEntity() const {
256 return get() && isa(get());
257 }
258 bool isExpression() const { return get() && isa(get()); }
240259
241260 void print(raw_ostream &OS) const;
242261 void dump() const;
258277 return DESC(dyn_cast_or_null(VALID)); \
259278 return DESC(static_cast(nullptr)); \
260279 } while (false)
280 #define RETURN_REF_FROM_RAW(REF, VALID) \
281 do { \
282 if (auto *N = getRaw()) \
283 return REF::get(VALID); \
284 return REF::get(nullptr); \
285 } while (false)
261286
262287 /// \brief This is used to represent ranges, for array bounds.
263288 class DISubrange : public DIDescriptor {
264 friend class DIDescriptor;
265 void printInternal(raw_ostream &OS) const;
289 MDSubrange *getRaw() const { return dyn_cast_or_null(get()); }
266290
267291 public:
268292 explicit DISubrange(const MDNode *N = nullptr) : DIDescriptor(N) {}
269
270 int64_t getLo() const { return getHeaderFieldAs(1); }
271 int64_t getCount() const { return getHeaderFieldAs(2); }
293 DISubrange(const MDSubrange *N) : DIDescriptor(N) {}
294
295 int64_t getLo() const { RETURN_FROM_RAW(N->getLo(), 0); }
296 int64_t getCount() const { RETURN_FROM_RAW(N->getCount(), 0); }
272297 bool Verify() const;
273298 };
274299
289314 /// FIXME: it seems strange that this doesn't have either a reference to the
290315 /// type/precision or a file/line pair for location info.
291316 class DIEnumerator : public DIDescriptor {
292 friend class DIDescriptor;
293 void printInternal(raw_ostream &OS) const;
317 MDEnumerator *getRaw() const { return dyn_cast_or_null(get()); }
294318
295319 public:
296320 explicit DIEnumerator(const MDNode *N = nullptr) : DIDescriptor(N) {}
297
298 StringRef getName() const { return getHeaderField(1); }
299 int64_t getEnumValue() const { return getHeaderFieldAs(2); }
321 DIEnumerator(const MDEnumerator *N) : DIDescriptor(N) {}
322
323 StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
324 int64_t getEnumValue() const { RETURN_FROM_RAW(N->getValue(), 0); }
300325 bool Verify() const;
301326 };
302327
316341 /// (DICompileUnit, DISubprogram, etc.), but not for, e.g., a DIType.
317342 class DIScope : public DIDescriptor {
318343 protected:
319 friend class DIDescriptor;
320 void printInternal(raw_ostream &OS) const;
344 MDScope *getRaw() const { return dyn_cast_or_null(get()); }
321345
322346 public:
323347 explicit DIScope(const MDNode *N = nullptr) : DIDescriptor(N) {}
348 DIScope(const MDScope *N) : DIDescriptor(N) {}
324349
325350 /// \brief Get the parent scope.
326351 ///
361386 T resolve(const DITypeIdentifierMap &Map) const;
362387 StringRef getName() const;
363388 operator Metadata *() const { return const_cast(Val); }
389
390 static DIRef get(const Metadata *MD) { return DIRef(MD); }
364391 };
365392
366393 template
412439 /// FIXME: Types should be factored much better so that CV qualifiers and
413440 /// others do not require a huge and empty descriptor full of zeros.
414441 class DIType : public DIScope {
415 protected:
416 friend class DIDescriptor;
417 void printInternal(raw_ostream &OS) const;
442 MDType *getRaw() const { return dyn_cast_or_null(get()); }
418443
419444 public:
420445 explicit DIType(const MDNode *N = nullptr) : DIScope(N) {}
446 DIType(const MDType *N) : DIScope(N) {}
447
421448 operator DITypeRef() const {
422449 assert(isType() &&
423450 "constructing DITypeRef from an MDNode that is not a type");
426453
427454 bool Verify() const;
428455
429 DIScopeRef getContext() const { return getFieldAs(2); }
430 StringRef getName() const { return getHeaderField(1); }
431 unsigned getLineNumber() const { return getHeaderFieldAs(2); }
432 uint64_t getSizeInBits() const { return getHeaderFieldAs(3); }
433 uint64_t getAlignInBits() const { return getHeaderFieldAs(4); }
456 DIScopeRef getContext() const {
457 RETURN_REF_FROM_RAW(DIScopeRef, N->getScope());
458 }
459 StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
460 unsigned getLineNumber() const { RETURN_FROM_RAW(N->getLine(), 0); }
461 uint64_t getSizeInBits() const { RETURN_FROM_RAW(N->getSizeInBits(), 0); }
462 uint64_t getAlignInBits() const { RETURN_FROM_RAW(N->getAlignInBits(), 0); }
434463 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
435464 // carry this is just plain insane.
436 uint64_t getOffsetInBits() const { return getHeaderFieldAs(5); }
437 unsigned getFlags() const { return getHeaderFieldAs(6); }
465 uint64_t getOffsetInBits() const { RETURN_FROM_RAW(N->getOffsetInBits(), 0); }
466 unsigned getFlags() const { RETURN_FROM_RAW(N->getFlags(), 0); }
438467 bool isPrivate() const {
439468 return (getFlags() & FlagAccessibility) == FlagPrivate;
440469 }
470499
471500 /// \brief A basic type, like 'int' or 'float'.
472501 class DIBasicType : public DIType {
502 MDBasicType *getRaw() const { return dyn_cast_or_null(get()); }
503
473504 public:
474505 explicit DIBasicType(const MDNode *N = nullptr) : DIType(N) {}
475
476 unsigned getEncoding() const { return getHeaderFieldAs(7); }
506 DIBasicType(const MDBasicType *N) : DIType(N) {}
507
508 unsigned getEncoding() const { RETURN_FROM_RAW(N->getEncoding(), 0); }
477509
478510 bool Verify() const;
479511 };
483515 /// Like a const qualified type, a typedef, a pointer or reference, et cetera.
484516 /// Or, a data member of a class/struct/union.
485517 class DIDerivedType : public DIType {
486 friend class DIDescriptor;
487 void printInternal(raw_ostream &OS) const;
518 MDDerivedTypeBase *getRaw() const {
519 return dyn_cast_or_null(get());
520 }
488521
489522 public:
490523 explicit DIDerivedType(const MDNode *N = nullptr) : DIType(N) {}
491
492 DITypeRef getTypeDerivedFrom() const { return getFieldAs(3); }
524 DIDerivedType(const MDDerivedTypeBase *N) : DIType(N) {}
525
526 DITypeRef getTypeDerivedFrom() const {
527 RETURN_REF_FROM_RAW(DITypeRef, N->getBaseType());
528 }
493529
494530 /// \brief Return property node, if this ivar is associated with one.
495 MDNode *getObjCProperty() const;
531 MDNode *getObjCProperty() const {
532 if (auto *N = dyn_cast_or_null(get()))
533 return dyn_cast_or_null(N->getExtraData());
534 return nullptr;
535 }
496536
497537 DITypeRef getClassType() const {
498538 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
499 return getFieldAs(4);
539 if (auto *N = dyn_cast_or_null(get()))
540 return DITypeRef::get(N->getExtraData());
541 return DITypeRef::get(nullptr);
500542 }
501543
502544 Constant *getConstant() const {
503545 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
504 return getConstantField(4);
546 if (auto *N = dyn_cast_or_null(get()))
547 if (auto *C = dyn_cast_or_null(N->getExtraData()))
548 return C->getValue();
549
550 return nullptr;
505551 }
506552
507553 bool Verify() const;
518564 // base type in a single DIType field.
519565 class DICompositeType : public DIDerivedType {
520566 friend class DIBuilder;
521 friend class DIDescriptor;
522 void printInternal(raw_ostream &OS) const;
523567
524568 /// \brief Set the array of member DITypes.
525569 void setArraysHelper(MDNode *Elements, MDNode *TParams);
526570
571 MDCompositeTypeBase *getRaw() const {
572 return dyn_cast_or_null(get());
573 }
574
527575 public:
528576 explicit DICompositeType(const MDNode *N = nullptr) : DIDerivedType(N) {}
577 DICompositeType(const MDCompositeTypeBase *N) : DIDerivedType(N) {}
529578
530579 DIArray getElements() const {
531580 assert(!isSubroutineType() && "no elements for DISubroutineType");
532 return getFieldAs(4);
581 RETURN_DESCRIPTOR_FROM_RAW(DIArray, N->getElements());
533582 }
534583
535584 private:
543592 }
544593
545594 public:
546 unsigned getRunTimeLang() const { return getHeaderFieldAs(7); }
547 DITypeRef getContainingType() const { return getFieldAs(5); }
595 unsigned getRunTimeLang() const { RETURN_FROM_RAW(N->getRuntimeLang(), 0); }
596 DITypeRef getContainingType() const {
597 RETURN_REF_FROM_RAW(DITypeRef, N->getVTableHolder());
598 }
548599
549600 private:
550601 /// \brief Set the containing type.
551602 void setContainingType(DICompositeType ContainingType);
552603
553604 public:
554 DIArray getTemplateParams() const { return getFieldAs(6); }
555 MDString *getIdentifier() const;
605 DIArray getTemplateParams() const {
606 RETURN_DESCRIPTOR_FROM_RAW(DIArray, N->getTemplateParams());
607 }
608 MDString *getIdentifier() const {
609 RETURN_FROM_RAW(N->getRawIdentifier(), nullptr);
610 }
556611
557612 bool Verify() const;
558613 };
559614
560615 class DISubroutineType : public DICompositeType {
616 MDSubroutineType *getRaw() const {
617 return dyn_cast_or_null(get());
618 }
619
561620 public:
562621 explicit DISubroutineType(const MDNode *N = nullptr) : DICompositeType(N) {}
622 DISubroutineType(const MDSubroutineType *N) : DICompositeType(N) {}
623
563624 DITypedArray getTypeArray() const {
564 return getFieldAs>(4);
625 RETURN_DESCRIPTOR_FROM_RAW(DITypedArray, N->getTypeArray());
565626 }
566627 };
567628
568629 /// \brief This is a wrapper for a file.
569630 class DIFile : public DIScope {
570 friend class DIDescriptor;
631 MDFile *getRaw() const { return dyn_cast_or_null(get()); }
571632
572633 public:
573634 explicit DIFile(const MDNode *N = nullptr) : DIScope(N) {}
635 DIFile(const MDFile *N) : DIScope(N) {}
574636
575637 /// \brief Retrieve the MDNode for the directory/file pair.
576 MDNode *getFileNode() const;
638 MDNode *getFileNode() const { return get(); }
577639 bool Verify() const;
578640 };
579641
580642 /// \brief A wrapper for a compile unit.
581643 class DICompileUnit : public DIScope {
582 friend class DIDescriptor;
583 void printInternal(raw_ostream &OS) const;
644 MDCompileUnit *getRaw() const {
645 return dyn_cast_or_null(get());
646 }
584647
585648 public:
586649 explicit DICompileUnit(const MDNode *N = nullptr) : DIScope(N) {}
650 DICompileUnit(const MDCompileUnit *N) : DIScope(N) {}
587651
588652 dwarf::SourceLanguage getLanguage() const {
589 return static_cast(getHeaderFieldAs(1));
590 }
591 StringRef getProducer() const { return getHeaderField(2); }
592
593 bool isOptimized() const { return getHeaderFieldAs(3) != 0; }
594 StringRef getFlags() const { return getHeaderField(4); }
595 unsigned getRunTimeVersion() const { return getHeaderFieldAs(5); }
596
597 DIArray getEnumTypes() const;
598 DIArray getRetainedTypes() const;
599 DIArray getSubprograms() const;
600 DIArray getGlobalVariables() const;
601 DIArray getImportedEntities() const;
653 RETURN_FROM_RAW(static_cast(N->getSourceLanguage()),
654 static_cast(0));
655 }
656 StringRef getProducer() const { RETURN_FROM_RAW(N->getProducer(), ""); }
657 bool isOptimized() const { RETURN_FROM_RAW(N->isOptimized(), false); }
658 StringRef getFlags() const { RETURN_FROM_RAW(N->getFlags(), ""); }
659 unsigned getRunTimeVersion() const {
660 RETURN_FROM_RAW(N->getRuntimeVersion(), 0);
661 }
662
663 DIArray getEnumTypes() const {
664 RETURN_DESCRIPTOR_FROM_RAW(DIArray, N->getEnumTypes());
665 }
666 DIArray getRetainedTypes() const {
667 RETURN_DESCRIPTOR_FROM_RAW(DIArray, N->getRetainedTypes());
668 }
669 DIArray getSubprograms() const {
670 RETURN_DESCRIPTOR_FROM_RAW(DIArray, N->getSubprograms());
671 }
672 DIArray getGlobalVariables() const {
673 RETURN_DESCRIPTOR_FROM_RAW(DIArray, N->getGlobalVariables());
674 }
675 DIArray getImportedEntities() const {
676 RETURN_DESCRIPTOR_FROM_RAW(DIArray, N->getImportedEntities());
677 }
602678
603679 void replaceSubprograms(DIArray Subprograms);
604680 void replaceGlobalVariables(DIArray GlobalVariables);
605681
606 StringRef getSplitDebugFilename() const { return getHeaderField(6); }
607 unsigned getEmissionKind() const { return getHeaderFieldAs(7); }
682 StringRef getSplitDebugFilename() const {
683 RETURN_FROM_RAW(N->getSplitDebugFilename(), "");
684 }
685 unsigned getEmissionKind() const { RETURN_FROM_RAW(N->getEmissionKind(), 0); }
608686
609687 bool Verify() const;
610688 };
611689
612690 /// \brief This is a wrapper for a subprogram (e.g. a function).
613691 class DISubprogram : public DIScope {
614 friend class DIDescriptor;
615 void printInternal(raw_ostream &OS) const;
692 MDSubprogram *getRaw() const { return dyn_cast_or_null(get()); }
616693
617694 public:
618695 explicit DISubprogram(const MDNode *N = nullptr) : DIScope(N) {}
619
620 StringRef getName() const { return getHeaderField(1); }
621 StringRef getDisplayName() const { return getHeaderField(2); }
622 StringRef getLinkageName() const { return getHeaderField(3); }
623 unsigned getLineNumber() const { return getHeaderFieldAs(4); }
696 DISubprogram(const MDSubprogram *N) : DIScope(N) {}
697
698 StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
699 StringRef getDisplayName() const { RETURN_FROM_RAW(N->getDisplayName(), ""); }
700 StringRef getLinkageName() const { RETURN_FROM_RAW(N->getLinkageName(), ""); }
701 unsigned getLineNumber() const { RETURN_FROM_RAW(N->getLine(), 0); }
624702
625703 /// \brief Check if this is local (like 'static' in C).
626 unsigned isLocalToUnit() const { return getHeaderFieldAs(5); }
627 unsigned isDefinition() const { return getHeaderFieldAs(6); }
628
629 unsigned getVirtuality() const { return getHeaderFieldAs(7); }
630 unsigned getVirtualIndex() const { return getHeaderFieldAs(8); }
631
632 unsigned getFlags() const { return getHeaderFieldAs(9); }
633
634 unsigned isOptimized() const { return getHeaderFieldAs(10); }
704 unsigned isLocalToUnit() const { RETURN_FROM_RAW(N->isLocalToUnit(), 0); }
705 unsigned isDefinition() const { RETURN_FROM_RAW(N->isDefinition(), 0); }
706
707 unsigned getVirtuality() const { RETURN_FROM_RAW(N->getVirtuality(), 0); }
708 unsigned getVirtualIndex() const { RETURN_FROM_RAW(N->getVirtualIndex(), 0); }
709
710 unsigned getFlags() const { RETURN_FROM_RAW(N->getFlags(), 0); }
711
712 unsigned isOptimized() const { RETURN_FROM_RAW(N->isOptimized(), 0); }
635713
636714 /// \brief Get the beginning of the scope of the function (not the name).
637 unsigned getScopeLineNumber() const { return getHeaderFieldAs(11); }
638
639 DIScopeRef getContext() const { return getFieldAs(2); }
640 DISubroutineType getType() const { return getFieldAs(3); }
641
642 DITypeRef getContainingType() const { return getFieldAs(4); }
715 unsigned getScopeLineNumber() const { RETURN_FROM_RAW(N->getScopeLine(), 0); }
716
717 DIScopeRef getContext() const {
718 RETURN_REF_FROM_RAW(DIScopeRef, N->getScope());
719 }
720 DISubroutineType getType() const {
721 RETURN_DESCRIPTOR_FROM_RAW(DISubroutineType, N->getType());
722 }
723
724 DITypeRef getContainingType() const {
725 RETURN_REF_FROM_RAW(DITypeRef, N->getContainingType());
726 }
643727
644728 bool Verify() const;
645729
646730 /// \brief Check if this provides debugging information for the function F.
647731 bool describes(const Function *F);
648732
649 Function *getFunction() const { return getFunctionField(5); }
650 void replaceFunction(Function *F) { replaceFunctionField(5, F); }
651 DIArray getTemplateParams() const { return getFieldAs(6); }
733 Function *getFunction() const;
734
735 void replaceFunction(Function *F) {
736 if (auto *N = getRaw())
737 N->replaceFunction(F);
738 }
739 DIArray getTemplateParams() const {
740 RETURN_DESCRIPTOR_FROM_RAW(DIArray, N->getTemplateParams());
741 }
652742 DISubprogram getFunctionDeclaration() const {
653 return getFieldAs(7);
654 }
655 MDNode *getVariablesNodes() const;
656 DIArray getVariables() const;
743 RETURN_DESCRIPTOR_FROM_RAW(DISubprogram, N->getDeclaration());
744 }
745 MDNode *getVariablesNodes() const { return getVariables(); }
746 DIArray getVariables() const {
747 RETURN_DESCRIPTOR_FROM_RAW(DIArray, N->getVariables());
748 }
657749
658750 unsigned isArtificial() const { return (getFlags() & FlagArtificial) != 0; }
659751 /// \brief Check for the "private" access specifier.
692784
693785 /// \brief This is a wrapper for a lexical block.
694786 class DILexicalBlock : public DIScope {
787 MDLexicalBlockBase *getRaw() const {
788 return dyn_cast_or_null(get());
789 }
790
695791 public:
696792 explicit DILexicalBlock(const MDNode *N = nullptr) : DIScope(N) {}
697 DIScope getContext() const { return getFieldAs(2); }
698 unsigned getLineNumber() const { return getHeaderFieldAs(1); }
699 unsigned getColumnNumber() const { return getHeaderFieldAs(2); }
793 DILexicalBlock(const MDLexicalBlock *N) : DIScope(N) {}
794
795 DIScope getContext() const {
796 RETURN_DESCRIPTOR_FROM_RAW(DIScope, N->getScope());
797 }
798 unsigned getLineNumber() const {
799 if (auto *N = dyn_cast_or_null(get()))
800 return N->getLine();
801 return 0;
802 }
803 unsigned getColumnNumber() const {
804 if (auto *N = dyn_cast_or_null(get()))
805 return N->getColumn();
806 return 0;
807 }
700808 bool Verify() const;
701809 };
702810
703811 /// \brief This is a wrapper for a lexical block with a filename change.
704812 class DILexicalBlockFile : public DIScope {
813 MDLexicalBlockFile *getRaw() const {
814 return dyn_cast_or_null(get());
815 }
816
705817 public:
706818 explicit DILexicalBlockFile(const MDNode *N = nullptr) : DIScope(N) {}
819 DILexicalBlockFile(const MDLexicalBlockFile *N) : DIScope(N) {}
820
707821 DIScope getContext() const {
708822 // FIXME: This logic is horrible. getScope() returns a DILexicalBlock, but
709823 // then we check if it's a subprogram? WHAT?!?
713827 }
714828 unsigned getLineNumber() const { return getScope().getLineNumber(); }
715829 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
716 DILexicalBlock getScope() const { return getFieldAs(2); }
717 unsigned getDiscriminator() const { return getHeaderFieldAs(1); }
830 DILexicalBlock getScope() const {
831 RETURN_DESCRIPTOR_FROM_RAW(DILexicalBlock, N->getScope());
832 }
833 unsigned getDiscriminator() const {
834 RETURN_FROM_RAW(N->getDiscriminator(), 0);
835 }
718836 bool Verify() const;
719837 };
720838
721839 /// \brief A wrapper for a C++ style name space.
722840 class DINameSpace : public DIScope {
723 friend class DIDescriptor;
724 void printInternal(raw_ostream &OS) const;
841 MDNamespace *getRaw() const { return dyn_cast_or_null(get()); }
725842
726843 public:
727844 explicit DINameSpace(const MDNode *N = nullptr) : DIScope(N) {}
728 StringRef getName() const { return getHeaderField(1); }
729 unsigned getLineNumber() const { return getHeaderFieldAs(2); }
730 DIScope getContext() const { return getFieldAs(2); }
845 DINameSpace(const MDNamespace *N) : DIScope(N) {}
846
847 StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
848 unsigned getLineNumber() const { RETURN_FROM_RAW(N->getLine(), 0); }
849 DIScope getContext() const {
850 RETURN_DESCRIPTOR_FROM_RAW(DIScope, N->getScope());
851 }
731852 bool Verify() const;
732853 };
733854
734855 /// \brief This is a wrapper for template type parameter.
735856 class DITemplateTypeParameter : public DIDescriptor {
857 MDTemplateTypeParameter *getRaw() const {
858 return dyn_cast_or_null(get());
859 }
860
736861 public:
737862 explicit DITemplateTypeParameter(const MDNode *N = nullptr)
738863 : DIDescriptor(N) {}
739
740 StringRef getName() const { return getHeaderField(1); }
741
742 DITypeRef getType() const { return getFieldAs(2); }
864 DITemplateTypeParameter(const MDTemplateTypeParameter *N) : DIDescriptor(N) {}
865
866 StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
867
868 DITypeRef getType() const { RETURN_REF_FROM_RAW(DITypeRef, N->getType()); }
743869 bool Verify() const;
744870 };
745871
746872 /// \brief This is a wrapper for template value parameter.
747873 class DITemplateValueParameter : public DIDescriptor {
874 MDTemplateValueParameter *getRaw() const {
875 return dyn_cast_or_null(get());
876 }
877
748878 public:
749879 explicit DITemplateValueParameter(const MDNode *N = nullptr)
750880 : DIDescriptor(N) {}
751
752 StringRef getName() const { return getHeaderField(1); }
753
754 DITypeRef getType() const { return getFieldAs(2); }
755 Metadata *getValue() const;
881 DITemplateValueParameter(const MDTemplateValueParameter *N)
882 : DIDescriptor(N) {}
883
884 StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
885 DITypeRef getType() const { RETURN_REF_FROM_RAW(DITypeRef, N->getType()); }
886 Metadata *getValue() const { RETURN_FROM_RAW(N->getValue(), nullptr); }
756887 bool Verify() const;
757888 };
758889
759890 /// \brief This is a wrapper for a global variable.
760891 class DIGlobalVariable : public DIDescriptor {
761 friend class DIDescriptor;
762 void printInternal(raw_ostream &OS) const;
892 MDGlobalVariable *getRaw() const {
893 return dyn_cast_or_null(get());
894 }
895
896 DIFile getFile() const { RETURN_DESCRIPTOR_FROM_RAW(DIFile, N->getFile()); }
763897
764898 public:
765899 explicit DIGlobalVariable(const MDNode *N = nullptr) : DIDescriptor(N) {}
766
767 StringRef getName() const { return getHeaderField(1); }
768 StringRef getDisplayName() const { return getHeaderField(2); }
769 StringRef getLinkageName() const { return getHeaderField(3); }
770 unsigned getLineNumber() const { return getHeaderFieldAs(4); }
771 unsigned isLocalToUnit() const { return getHeaderFieldAs(5); }
772 unsigned isDefinition() const { return getHeaderFieldAs(6); }
773
774 DIScope getContext() const { return getFieldAs(1); }
775 StringRef getFilename() const { return getFieldAs(2).getFilename(); }
776 StringRef getDirectory() const {
777 return getFieldAs(2).getDirectory();
778 }
779 DITypeRef getType() const { return getFieldAs(3); }
780
781 GlobalVariable *getGlobal() const { return getGlobalVariableField(4); }
782 Constant *getConstant() const { return getConstantField(4); }
900 DIGlobalVariable(const MDGlobalVariable *N) : DIDescriptor(N) {}
901
902 StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
903 StringRef getDisplayName() const { RETURN_FROM_RAW(N->getDisplayName(), ""); }
904 StringRef getLinkageName() const { RETURN_FROM_RAW(N->getLinkageName(), ""); }
905 unsigned getLineNumber() const { RETURN_FROM_RAW(N->getLine(), 0); }
906 unsigned isLocalToUnit() const { RETURN_FROM_RAW(N->isLocalToUnit(), 0); }
907 unsigned isDefinition() const { RETURN_FROM_RAW(N->isDefinition(), 0); }
908
909 DIScope getContext() const {
910 RETURN_DESCRIPTOR_FROM_RAW(DIScope, N->getScope());
911 }
912 StringRef getFilename() const { return getFile().getFilename(); }
913 StringRef getDirectory() const { return getFile().getDirectory(); }
914 DITypeRef getType() const { RETURN_REF_FROM_RAW(DITypeRef, N->getType()); }
915
916 GlobalVariable *getGlobal() const;
917 Constant *getConstant() const {
918 if (auto *N = getRaw())
919 if (auto *C = dyn_cast_or_null(N->getVariable()))
920 return C->getValue();
921 return nullptr;
922 }
783923 DIDerivedType getStaticDataMemberDeclaration() const {
784 return getFieldAs(5);
924 RETURN_DESCRIPTOR_FROM_RAW(DIDerivedType,
925 N->getStaticDataMemberDeclaration());
785926 }
786927
787928 bool Verify() const;
789930
790931 /// \brief This is a wrapper for a variable (e.g. parameter, local, global etc).
791932 class DIVariable : public DIDescriptor {
792 friend class DIDescriptor;
793 void printInternal(raw_ostream &OS) const;
933 MDLocalVariable *getRaw() const {
934 return dyn_cast_or_null(get());
935 }
936
937 unsigned getFlags() const { RETURN_FROM_RAW(N->getFlags(), 0); }
794938
795939 public:
796940 explicit DIVariable(const MDNode *N = nullptr) : DIDescriptor(N) {}
797
798 StringRef getName() const { return getHeaderField(1); }
799 unsigned getLineNumber() const {
800 // FIXME: Line number and arg number shouldn't be merged together like this.
801 return (getHeaderFieldAs(2) << 8) >> 8;
802 }
803 unsigned getArgNumber() const { return getHeaderFieldAs(2) >> 24; }
804
805 DIScope getContext() const { return getFieldAs(1); }
806 DIFile getFile() const { return getFieldAs(2); }
807 DITypeRef getType() const { return getFieldAs(3); }
941 DIVariable(const MDLocalVariable *N) : DIDescriptor(N) {}
942
943 StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
944 unsigned getLineNumber() const { RETURN_FROM_RAW(N->getLine(), 0); }
945 unsigned getArgNumber() const { RETURN_FROM_RAW(N->getArg(), 0); }
946
947 DIScope getContext() const {
948 RETURN_DESCRIPTOR_FROM_RAW(DIScope, N->getScope());
949 }
950 DIFile getFile() const { RETURN_DESCRIPTOR_FROM_RAW(DIFile, N->getFile()); }
951 DITypeRef getType() const { RETURN_REF_FROM_RAW(DITypeRef, N->getType()); }
808952
809953 /// \brief Return true if this variable is marked as "artificial".
810954 bool isArtificial() const {
811 return (getHeaderFieldAs(3) & FlagArtificial) != 0;
955 return (getFlags() & FlagArtificial) != 0;
812956 }
813957
814958 bool isObjectPointer() const {
815 return (getHeaderFieldAs(3) & FlagObjectPointer) != 0;
959 return (getFlags() & FlagObjectPointer) != 0;
816960 }
817961
818962 /// \brief If this variable is inlined then return inline location.
819 MDNode *getInlinedAt() const;
963 MDNode *getInlinedAt() const {
964 RETURN_DESCRIPTOR_FROM_RAW(DIDescriptor, N->getInlinedAt());
965 }
820966
821967 bool Verify() const;
822968
842988 /// FIXME: Instead of DW_OP_plus taking an argument, this should use DW_OP_const
843989 /// and have DW_OP_plus consume the topmost elements on the stack.
844990 class DIExpression : public DIDescriptor {
845 friend class DIDescriptor;
846 void printInternal(raw_ostream &OS) const;
991 MDExpression *getRaw() const { return dyn_cast_or_null(get()); }
847992
848993 public:
849994 explicit DIExpression(const MDNode *N = nullptr) : DIDescriptor(N) {}
995 DIExpression(const MDExpression *N) : DIDescriptor(N) {}
850996
851997 bool Verify() const;
852998
853999 /// \brief Return the number of elements in the complex expression.
854 unsigned getNumElements() const {
855 if (!DbgNode)
856 return 0;
857 unsigned N = getNumHeaderFields();
858 assert(N > 0 && "missing tag");
859 return N - 1;
860 }
1000 unsigned getNumElements() const { RETURN_FROM_RAW(N->getNumElements(), 0); }
8611001
8621002 /// \brief return the Idx'th complex address element.
863 uint64_t getElement(unsigned Idx) const;
1003 uint64_t getElement(unsigned I) const {
1004 return cast(get())->getElement(I);
1005 }
8641006
8651007 /// \brief Return whether this is a piece of an aggregate variable.
8661008 bool isBitPiece() const;
8731015 /// \brief A lightweight wrapper around an element of a DIExpression.
8741016 class Operand {
8751017 friend class iterator;
876 DIHeaderFieldIterator I;
1018 MDExpression::element_iterator I;
8771019 Operand() {}
878 Operand(DIHeaderFieldIterator I) : I(I) {}
1020 Operand(MDExpression::element_iterator I) : I(I) {}
8791021 public:
8801022 /// \brief Operands such as DW_OP_piece have explicit (non-stack) arguments.
8811023 /// Argument 0 is the operand itself.
8821024 uint64_t getArg(unsigned N) const {
883 DIHeaderFieldIterator In = I;
1025 MDExpression::element_iterator In = I;
8841026 std::advance(In, N);
885 return In.getNumber();
1027 return *In;
8861028 }
887 operator uint64_t () const { return I.getNumber(); }
888 /// \brief Returns underlying DIHeaderFieldIterator.
889 const DIHeaderFieldIterator &getBase() const { return I; }
1029 operator uint64_t () const { return *I; }
1030 /// \brief Returns underlying MDExpression::element_iterator.
1031 const MDExpression::element_iterator &getBase() const { return I; }
8901032 /// \brief Returns the next operand.
8911033 Operand getNext() const;
8921034 };
8951037 class iterator : public std::iterator
8961038 unsigned, const Operand*, Operand> {
8971039 friend class Operand;
898 DIHeaderFieldIterator I;
1040 MDExpression::element_iterator I;
8991041 Operand Tmp;
900 iterator(DIHeaderFieldIterator I) : I(I) {}
1042
9011043 public:
902 iterator() {}
903 iterator(const DIExpression &Expr) : I(++Expr.header_begin()) {}
1044 iterator(MDExpression::element_iterator I) : I(I) {}
9041045 const Operand &operator*() { return Tmp = Operand(I); }
9051046 const Operand *operator->() { return &(Tmp = Operand(I)); }
9061047 iterator &operator++() {
9271068 }
9281069 };
9291070
930 iterator begin() const;
931 iterator end() const;
1071 iterator begin() const { return cast(get())->elements_begin(); }
1072 iterator end() const { return cast(get())->elements_end(); }
9321073 };
9331074
9341075 /// \brief This object holds location information.
9821123 };
9831124
9841125 class DIObjCProperty : public DIDescriptor {
985 friend class DIDescriptor;
986 void printInternal(raw_ostream &OS) const;
1126 MDObjCProperty *getRaw() const {
1127 return dyn_cast_or_null(get());
1128 }
9871129
9881130 public:
9891131 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) {}
990
991 StringRef getObjCPropertyName() const { return getHeaderField(1); }
992 DIFile getFile() const { return getFieldAs(1); }
993 unsigned getLineNumber() const { return getHeaderFieldAs(2); }
994
995 StringRef getObjCPropertyGetterName() const { return getHeaderField(3); }
996 StringRef getObjCPropertySetterName() const { return getHeaderField(4); }
997 unsigned getAttributes() const { return getHeaderFieldAs(5); }
1132 DIObjCProperty(const MDObjCProperty *N) : DIDescriptor(N) {}
1133
1134 StringRef getObjCPropertyName() const { RETURN_FROM_RAW(N->getName(), ""); }
1135 DIFile getFile() const { RETURN_DESCRIPTOR_FROM_RAW(DIFile, N->getFile()); }
1136 unsigned getLineNumber() const { RETURN_FROM_RAW(N->getLine(), 0); }
1137
1138 StringRef getObjCPropertyGetterName() const {
1139 RETURN_FROM_RAW(N->getGetterName(), "");
1140 }
1141 StringRef getObjCPropertySetterName() const {
1142 RETURN_FROM_RAW(N->getSetterName(), "");
1143 }
1144 unsigned getAttributes() const { RETURN_FROM_RAW(N->getAttributes(), 0); }
9981145 bool isReadOnlyObjCProperty() const {
9991146 return (getAttributes() & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
10001147 }
10181165 ///
10191166 /// \note Objective-C doesn't have an ODR, so there is no benefit in storing
10201167 /// the type as a DITypeRef here.
1021 DIType getType() const { return getFieldAs(2); }
1168 DIType getType() const { RETURN_DESCRIPTOR_FROM_RAW(DIType, N->getType()); }
10221169
10231170 bool Verify() const;
10241171 };
10251172
10261173 /// \brief An imported module (C++ using directive or similar).
10271174 class DIImportedEntity : public DIDescriptor {
1028 friend class DIDescriptor;
1029 void printInternal(raw_ostream &OS) const;
1175 MDImportedEntity *getRaw() const {
1176 return dyn_cast_or_null(get());
1177 }
10301178
10311179 public:
10321180 DIImportedEntity() = default;
10331181 explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) {}
1034 DIScope getContext() const { return getFieldAs(1); }
1035 DIDescriptorRef getEntity() const { return getFieldAs(2); }
1036 unsigned getLineNumber() const { return getHeaderFieldAs(1); }
1037 StringRef getName() const { return getHeaderField(2); }
1182 DIImportedEntity(const MDImportedEntity *N) : DIDescriptor(N) {}
1183
1184 DIScope getContext() const {
1185 RETURN_DESCRIPTOR_FROM_RAW(DIScope, N->getScope());
1186 }
1187 DIDescriptorRef getEntity() const {
1188 RETURN_REF_FROM_RAW(DIDescriptorRef, N->getEntity());
1189 }
1190 unsigned getLineNumber() const { RETURN_FROM_RAW(N->getLine(), 0); }
1191 StringRef getName() const { RETURN_FROM_RAW(N->getName(), ""); }
10381192 bool Verify() const;
10391193 };
10401194
10411195 #undef RETURN_FROM_RAW
10421196 #undef RETURN_DESCRIPTOR_FROM_RAW
1197 #undef RETURN_REF_FROM_RAW
10431198
10441199 /// \brief Find subprogram that is enclosing this scope.
10451200 DISubprogram getDISubprogram(const MDNode *Scope);
3131 template
3232 class SymbolTableListTraits;
3333
34
3534 enum LLVMConstants : uint32_t {
36 DEBUG_METADATA_VERSION = 2 // Current debug info version number.
35 DEBUG_METADATA_VERSION = 3 // Current debug info version number.
3736 };
3837
3938 /// \brief Root of the metadata hierarchy.
5454 return false;
5555 }
5656
57 static void printFile(raw_ostream &O, StringRef Filename, StringRef Directory,
58 unsigned Line = 0) {
59 if (Filename.empty())
60 return;
61
62 O << " from ";
63 if (!Directory.empty())
64 O << Directory << "/";
65 O << Filename;
66 if (Line)
67 O << ":" << Line;
68 }
69
5770 void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
71 // Printing the nodes directly isn't particularly helpful (since they
72 // reference other nodes that won't be printed, particularly for the
73 // filenames), so just print a few useful things.
5874 for (DICompileUnit CU : Finder.compile_units()) {
59 O << "Compile Unit: ";
60 CU.print(O);
75 O << "Compile unit: ";
76 if (const char *Lang = LanguageString(CU.getLanguage()))
77 O << Lang;
78 else
79 O << "unknown-language(" << CU.getLanguage() << ")";
80 printFile(O, CU.getFilename(), CU.getDirectory());
6181 O << '\n';
6282 }
6383
6484 for (DISubprogram S : Finder.subprograms()) {
65 O << "Subprogram: ";
66 S.print(O);
85 O << "Subprogram: " << S.getName();
86 printFile(O, S.getFilename(), S.getDirectory(), S.getLineNumber());
87 if (!S.getLinkageName().empty())
88 O << " ('" << S.getLinkageName() << "')";
6789 O << '\n';
6890 }
6991
7092 for (DIGlobalVariable GV : Finder.global_variables()) {
71 O << "GlobalVariable: ";
72 GV.print(O);
93 O << "Global variable: " << GV.getName();
94 printFile(O, GV.getFilename(), GV.getDirectory(), GV.getLineNumber());
95 if (!GV.getLinkageName().empty())
96 O << " ('" << GV.getLinkageName() << "')";
7397 O << '\n';
7498 }
7599
76100 for (DIType T : Finder.types()) {
77 O << "Type: ";
78 T.print(O);
101 O << "Type:";
102 if (!T.getName().empty())
103 O << ' ' << T.getName();
104 printFile(O, T.getFilename(), T.getDirectory(), T.getLineNumber());
105 if (T.isBasicType()) {
106 DIBasicType BT(T.get());
107 O << " ";
108 if (const char *Encoding =
109 dwarf::AttributeEncodingString(BT.getEncoding()))
110 O << Encoding;
111 else
112 O << "unknown-encoding(" << BT.getEncoding() << ')';
113 } else {
114 O << ' ';
115 if (const char *Tag = dwarf::TagString(T.getTag()))
116 O << Tag;
117 else
118 O << "unknown-tag(" << T.getTag() << ")";
119 }
120 if (T.isCompositeType()) {
121 DICompositeType CT(T.get());
122 if (auto *S = CT.getIdentifier())
123 O << " (identifier: '" << S->getString() << "')";
124 }
79125 O << '\n';
80126 }
81127 }
29832983 printInfoComment(I);
29842984 }
29852985
2986 static void WriteMDNodeComment(const MDNode *Node,
2987 formatted_raw_ostream &Out) {
2988 if (Node->getNumOperands() < 1)
2989 return;
2990
2991 Metadata *Op = Node->getOperand(0);
2992 if (!Op || !isa(Op))
2993 return;
2994
2995 DIDescriptor Desc(Node);
2996 if (!Desc.Verify())
2997 return;
2998
2999 unsigned Tag = Desc.getTag();
3000 Out.PadToColumn(50);
3001 if (dwarf::TagString(Tag)) {
3002 Out << "; ";
3003 Desc.print(Out);
3004 } else if (Tag == dwarf::DW_TAG_user_base) {
3005 Out << "; [ DW_TAG_user_base ]";
3006 }
3007 }
3008
30092986 void AssemblyWriter::writeMDNode(unsigned Slot, const MDNode *Node) {
30102987 Out << '!' << Slot << " = ";
30112988 printMDNodeBody(Node);
30263003
30273004 void AssemblyWriter::printMDNodeBody(const MDNode *Node) {
30283005 WriteMDNodeBodyInternal(Out, Node, &TypePrinter, &Machine, TheModule);
3029 WriteMDNodeComment(Node, Out);
30303006 }
30313007
30323008 void AssemblyWriter::writeAllAttributeGroups() {
126126 return N;
127127 }
128128
129 static MDNode *createFilePathPair(LLVMContext &VMContext, StringRef Filename,
130 StringRef Directory) {
131 assert(!Filename.empty() && "Unable to create file without name");
132 Metadata *Pair[] = {MDString::get(VMContext, Filename),
133 MDString::get(VMContext, Directory)};
134 return MDNode::get(VMContext, Pair);
135 }
136
137129 DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename,
138130 StringRef Directory,
139131 StringRef Producer, bool isOptimized,
156148 TempGVs = MDTuple::getTemporary(VMContext, None).release();
157149 TempImportedModules = MDTuple::getTemporary(VMContext, None).release();
158150
159 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_compile_unit)
160 .concat(Lang)
161 .concat(Producer)
162 .concat(isOptimized)
163 .concat(Flags)
164 .concat(RunTimeVer)
165 .concat(SplitName)
166 .concat(Kind)
167 .get(VMContext),
168 createFilePathPair(VMContext, Filename, Directory),
169 TempEnumTypes, TempRetainTypes, TempSubprograms, TempGVs,
170 TempImportedModules};
171
172151 // TODO: Switch to getDistinct(). We never want to merge compile units based
173152 // on contents.
174 MDNode *CUNode = MDNode::get(VMContext, Elts);
153 MDNode *CUNode = MDCompileUnit::get(
154 VMContext, Lang, MDFile::get(VMContext, Filename, Directory), Producer,
155 isOptimized, Flags, RunTimeVer, SplitName, Kind, TempEnumTypes,
156 TempRetainTypes, TempSubprograms, TempGVs, TempImportedModules);
175157
176158 // Create a named metadata so that it is easier to find cu in a module.
177159 // Note that we only generate this when the caller wants to actually
191173 createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope Context,
192174 Metadata *NS, unsigned Line, StringRef Name,
193175 SmallVectorImpl &AllImportedModules) {
194 const MDNode *R;
195 Metadata *Elts[] = {HeaderBuilder::get(Tag).concat(Line).concat(Name).get(C),
196 Context, NS};
197 R = MDNode::get(C, Elts);
198 DIImportedEntity M(R);
176 DIImportedEntity M = MDImportedEntity::get(C, Tag, Context, NS, Line, Name);
199177 assert(M.Verify() && "Imported module should be valid");
200178 AllImportedModules.emplace_back(M.get());
201179 return M;
235213 }
236214
237215 DIFile DIBuilder::createFile(StringRef Filename, StringRef Directory) {
238 Metadata *Elts[] = {
239 HeaderBuilder::get(dwarf::DW_TAG_file_type).get(VMContext),
240 createFilePathPair(VMContext, Filename, Directory)};
241 return DIFile(MDNode::get(VMContext, Elts));
216 return MDFile::get(VMContext, Filename, Directory);
242217 }
243218
244219 DIEnumerator DIBuilder::createEnumerator(StringRef Name, int64_t Val) {
245220 assert(!Name.empty() && "Unable to create enumerator without name");
246 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_enumerator)
247 .concat(Name)
248 .concat(Val)
249 .get(VMContext)};
250 return DIEnumerator(MDNode::get(VMContext, Elts));
221 return MDEnumerator::get(VMContext, Val, Name);
251222 }
252223
253224 DIBasicType DIBuilder::createUnspecifiedType(StringRef Name) {
254225 assert(!Name.empty() && "Unable to create type without name");
255 // Unspecified types are encoded in DIBasicType format. Line number, filename,
256 // size, alignment, offset and flags are always empty here.
257 Metadata *Elts[] = {
258 HeaderBuilder::get(dwarf::DW_TAG_unspecified_type)
259 .concat(Name)
260 .concat(0)
261 .concat(0)
262 .concat(0)
263 .concat(0)
264 .concat(0)
265 .concat(0)
266 .get(VMContext),
267 nullptr, // Filename
268 nullptr // Unused
269 };
270 return DIBasicType(MDNode::get(VMContext, Elts));
226 return MDBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name);
271227 }
272228
273229 DIBasicType DIBuilder::createNullPtrType() {
278234 DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
279235 uint64_t AlignInBits, unsigned Encoding) {
280236 assert(!Name.empty() && "Unable to create type without name");
281 // Basic types are encoded in DIBasicType format. Line number, filename,
282 // offset and flags are always empty here.
283 Metadata *Elts[] = {
284 HeaderBuilder::get(dwarf::DW_TAG_base_type)
285 .concat(Name)
286 .concat(0) // Line
287 .concat(SizeInBits)
288 .concat(AlignInBits)
289 .concat(0) // Offset
290 .concat(0) // Flags
291 .concat(Encoding)
292 .get(VMContext),
293 nullptr, // Filename
294 nullptr // Unused
295 };
296 return DIBasicType(MDNode::get(VMContext, Elts));
237 return MDBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
238 AlignInBits, Encoding);
297239 }
298240
299241 DIDerivedType DIBuilder::createQualifiedType(unsigned Tag, DIType FromTy) {
300 // Qualified types are encoded in DIDerivedType format.
301 Metadata *Elts[] = {HeaderBuilder::get(Tag)
302 .concat(StringRef()) // Name
303 .concat(0) // Line
304 .concat(0) // Size
305 .concat(0) // Align
306 .concat(0) // Offset
307 .concat(0) // Flags
308 .get(VMContext),
309 nullptr, // Filename
310 nullptr, // Unused
311 FromTy.getRef()};
312 return DIDerivedType(MDNode::get(VMContext, Elts));
242 return MDDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
243 FromTy.getRef(), 0, 0, 0, 0);
313244 }
314245
315246 DIDerivedType
316247 DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits,
317248 uint64_t AlignInBits, StringRef Name) {
318 // Pointer types are encoded in DIDerivedType format.
319 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_pointer_type)
320 .concat(Name)
321 .concat(0) // Line
322 .concat(SizeInBits)
323 .concat(AlignInBits)
324 .concat(0) // Offset
325 .concat(0) // Flags
326 .get(VMContext),
327 nullptr, // Filename
328 nullptr, // Unused
329 PointeeTy.getRef()};
330 return DIDerivedType(MDNode::get(VMContext, Elts));
249 // FIXME: Why is there a name here?
250 return MDDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
251 nullptr, 0, nullptr, PointeeTy.getRef(), SizeInBits,
252 AlignInBits, 0, 0);
331253 }
332254
333255 DIDerivedType
334256 DIBuilder::createMemberPointerType(DIType PointeeTy, DIType Base,
335257 uint64_t SizeInBits, uint64_t AlignInBits) {
336 // Pointer types are encoded in DIDerivedType format.
337 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_ptr_to_member_type)
338 .concat(StringRef())
339 .concat(0) // Line
340 .concat(SizeInBits) // Size
341 .concat(AlignInBits) // Align
342 .concat(0) // Offset
343 .concat(0) // Flags
344 .get(VMContext),
345 nullptr, // Filename
346 nullptr, // Unused
347 PointeeTy.getRef(), Base.getRef()};
348 return DIDerivedType(MDNode::get(VMContext, Elts));
258 return MDDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
259 nullptr, 0, nullptr, PointeeTy.getRef(), SizeInBits,
260 AlignInBits, 0, 0, Base.getRef());
349261 }
350262
351263 DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
352264 assert(RTy.isType() && "Unable to create reference type");
353 // References are encoded in DIDerivedType format.
354 Metadata *Elts[] = {HeaderBuilder::get(Tag)
355 .concat(StringRef()) // Name
356 .concat(0) // Line
357 .concat(0) // Size
358 .concat(0) // Align
359 .concat(0) // Offset
360 .concat(0) // Flags
361 .get(VMContext),
362 nullptr, // Filename
363 nullptr, // TheCU,
364 RTy.getRef()};
365 return DIDerivedType(MDNode::get(VMContext, Elts));
265 return MDDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
266 RTy.getRef(), 0, 0, 0, 0);
366267 }
367268
368269 DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File,
369270 unsigned LineNo, DIDescriptor Context) {
370 // typedefs are encoded in DIDerivedType format.
371 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_typedef)
372 .concat(Name)
373 .concat(LineNo)
374 .concat(0) // Size
375 .concat(0) // Align
376 .concat(0) // Offset
377 .concat(0) // Flags
378 .get(VMContext),
379 File.getFileNode(),
380 DIScope(getNonCompileUnitScope(Context)).getRef(),
381 Ty.getRef()};
382 return DIDerivedType(MDNode::get(VMContext, Elts));
271 return MDDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name,
272 File.getFileNode(), LineNo,
273 DIScope(getNonCompileUnitScope(Context)).getRef(),
274 Ty.getRef(), 0, 0, 0, 0);
383275 }
384276
385277 DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
386278 // typedefs are encoded in DIDerivedType format.
387279 assert(Ty.isType() && "Invalid type!");
388280 assert(FriendTy.isType() && "Invalid friend type!");
389 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_friend)
390 .concat(StringRef()) // Name
391 .concat(0) // Line
392 .concat(0) // Size
393 .concat(0) // Align
394 .concat(0) // Offset
395 .concat(0) // Flags
396 .get(VMContext),
397 nullptr, Ty.getRef(), FriendTy.getRef()};
398 return DIDerivedType(MDNode::get(VMContext, Elts));
281 return MDDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0,
282 Ty.getRef(), FriendTy.getRef(), 0, 0, 0, 0);
399283 }
400284
401285 DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy,
402286 uint64_t BaseOffset,
403287 unsigned Flags) {
404288 assert(Ty.isType() && "Unable to create inheritance");
405 // TAG_inheritance is encoded in DIDerivedType format.
406 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_inheritance)
407 .concat(StringRef()) // Name
408 .concat(0) // Line
409 .concat(0) // Size
410 .concat(0) // Align
411 .concat(BaseOffset)
412 .concat(Flags)
413 .get(VMContext),
414 nullptr, Ty.getRef(), BaseTy.getRef()};
415 auto R = DIDerivedType(MDNode::get(VMContext, Elts));
416 return R;
289 return MDDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
290 0, Ty.getRef(), BaseTy.getRef(), 0, 0, BaseOffset,
291 Flags);
417292 }
418293
419294 DIDerivedType DIBuilder::createMemberType(DIDescriptor Scope, StringRef Name,
422297 uint64_t AlignInBits,
423298 uint64_t OffsetInBits, unsigned Flags,
424299 DIType Ty) {
425 // TAG_member is encoded in DIDerivedType format.
426 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_member)
427 .concat(Name)
428 .concat(LineNumber)
429 .concat(SizeInBits)
430 .concat(AlignInBits)
431 .concat(OffsetInBits)
432 .concat(Flags)
433 .get(VMContext),
434 File.getFileNode(),
435 DIScope(getNonCompileUnitScope(Scope)).getRef(),
436 Ty.getRef()};
437 return DIDerivedType(MDNode::get(VMContext, Elts));
300 return MDDerivedType::get(
301 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
302 DIScope(getNonCompileUnitScope(Scope)).getRef(), Ty.getRef(), SizeInBits,
303 AlignInBits, OffsetInBits, Flags);
438304 }
439305
440306 static Metadata *getConstantOrNull(Constant *C) {
450316 llvm::Constant *Val) {
451317 // TAG_member is encoded in DIDerivedType format.
452318 Flags |= DIDescriptor::FlagStaticMember;
453 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_member)
454 .concat(Name)
455 .concat(LineNumber)
456 .concat(0) // Size
457 .concat(0) // Align
458 .concat(0) // Offset
459 .concat(Flags)
460 .get(VMContext),
461 File.getFileNode(),
462 DIScope(getNonCompileUnitScope(Scope)).getRef(),
463 Ty.getRef(), getConstantOrNull(Val)};
464 return DIDerivedType(MDNode::get(VMContext, Elts));
319 return MDDerivedType::get(
320 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
321 DIScope(getNonCompileUnitScope(Scope)).getRef(), Ty.getRef(), 0, 0, 0,
322 Flags, getConstantOrNull(Val));
465323 }
466324
467325 DIDerivedType DIBuilder::createObjCIVar(StringRef Name, DIFile File,
470328 uint64_t AlignInBits,
471329 uint64_t OffsetInBits, unsigned Flags,
472330 DIType Ty, MDNode *PropertyNode) {
473 // TAG_member is encoded in DIDerivedType format.
474 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_member)
475 .concat(Name)
476 .concat(LineNumber)
477 .concat(SizeInBits)
478 .concat(AlignInBits)
479 .concat(OffsetInBits)
480 .concat(Flags)
481 .get(VMContext),
482 File.getFileNode(), getNonCompileUnitScope(File), Ty,
483 PropertyNode};
484 return DIDerivedType(MDNode::get(VMContext, Elts));
331 return MDDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
332 LineNumber, getNonCompileUnitScope(File),
333 Ty.getRef(), SizeInBits, AlignInBits, OffsetInBits,
334 Flags, PropertyNode);
485335 }
486336
487337 DIObjCProperty
488338 DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber,
489339 StringRef GetterName, StringRef SetterName,
490340 unsigned PropertyAttributes, DIType Ty) {
491 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_APPLE_property)
492 .concat(Name)
493 .concat(LineNumber)
494 .concat(GetterName)
495 .concat(SetterName)
496 .concat(PropertyAttributes)
497 .get(VMContext),
498 File, Ty};
499 return DIObjCProperty(MDNode::get(VMContext, Elts));
341 return MDObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
342 SetterName, PropertyAttributes, Ty);
500343 }
501344
502345 DITemplateTypeParameter
504347 DIType Ty) {
505348 assert(!DIScope(getNonCompileUnitScope(Context)).getRef() &&
506349 "Expected compile unit");
507 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_template_type_parameter)
508 .concat(Name)
509 .concat(0)
510 .concat(0)
511 .get(VMContext),
512 nullptr, Ty.getRef(), nullptr};
513 return DITemplateTypeParameter(MDNode::get(VMContext, Elts));
350 return MDTemplateTypeParameter::get(VMContext, Name, Ty.getRef());
514351 }
515352
516353 static DITemplateValueParameter
519356 DIType Ty, Metadata *MD) {
520357 assert(!DIScope(getNonCompileUnitScope(Context)).getRef() &&
521358 "Expected compile unit");
522 Metadata *Elts[] = {
523 HeaderBuilder::get(Tag).concat(Name).concat(0).concat(0).get(VMContext),
524 nullptr, Ty.getRef(), MD, nullptr};
525 return DITemplateValueParameter(MDNode::get(VMContext, Elts));
359 return MDTemplateValueParameter::get(VMContext, Tag, Name, Ty.getRef(), MD);
526360 }
527361
528362 DITemplateValueParameter
562396 assert((!Context || Context.isScope() || Context.isType()) &&
563397 "createClassType should be called with a valid Context");
564398 // TAG_class_type is encoded in DICompositeType format.
565 Metadata *Elts[] = {
566 HeaderBuilder::get(dwarf::DW_TAG_class_type)
567 .concat(Name)
568 .concat(LineNumber)
569 .concat(SizeInBits)
570 .concat(AlignInBits)
571 .concat(OffsetInBits)
572 .concat(Flags)
573 .concat(0)
574 .get(VMContext),
575 File.getFileNode(), DIScope(getNonCompileUnitScope(Context)).getRef(),
576 DerivedFrom.getRef(), Elements, VTableHolder.getRef(), TemplateParams,
577 UniqueIdentifier.empty() ? nullptr
578 : MDString::get(VMContext, UniqueIdentifier)};
579 DICompositeType R(MDNode::get(VMContext, Elts));
580 assert(R.isCompositeType() &&
581 "createClassType should return a DICompositeType");
399 DICompositeType R = MDCompositeType::get(
400 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
401 DIScope(getNonCompileUnitScope(Context)).getRef(), DerivedFrom.getRef(),
402 SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, 0,
403 VTableHolder.getRef(), TemplateParams, UniqueIdentifier);
582404 if (!UniqueIdentifier.empty())
583405 retainType(R);
584406 trackIfUnresolved(R);
595417 unsigned RunTimeLang,
596418 DIType VTableHolder,
597419 StringRef UniqueIdentifier) {
598 // TAG_structure_type is encoded in DICompositeType format.
599 Metadata *Elts[] = {
600 HeaderBuilder::get(dwarf::DW_TAG_structure_type)
601 .concat(Name)
602 .concat(LineNumber)
603 .concat(SizeInBits)
604 .concat(AlignInBits)
605 .concat(0)
606 .concat(Flags)
607 .concat(RunTimeLang)
608 .get(VMContext),
609 File.getFileNode(), DIScope(getNonCompileUnitScope(Context)).getRef(),
610 DerivedFrom.getRef(), Elements, VTableHolder.getRef(), nullptr,
611 UniqueIdentifier.empty() ? nullptr
612 : MDString::get(VMContext, UniqueIdentifier)};
613 DICompositeType R(MDNode::get(VMContext, Elts));
614 assert(R.isCompositeType() &&
615 "createStructType should return a DICompositeType");
420 DICompositeType R = MDCompositeType::get(
421 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
422 DIScope(getNonCompileUnitScope(Context)).getRef(), DerivedFrom.getRef(),
423 SizeInBits, AlignInBits, 0, Flags, Elements, RunTimeLang,
424 VTableHolder.getRef(), nullptr, UniqueIdentifier);
616425 if (!UniqueIdentifier.empty())
617426 retainType(R);
618427 trackIfUnresolved(R);
626435 DIArray Elements,
627436 unsigned RunTimeLang,
628437 StringRef UniqueIdentifier) {
629 // TAG_union_type is encoded in DICompositeType format.
630 Metadata *Elts[] = {
631 HeaderBuilder::get(dwarf::DW_TAG_union_type)
632 .concat(Name)
633 .concat(LineNumber)
634 .concat(SizeInBits)
635 .concat(AlignInBits)
636 .concat(0) // Offset
637 .concat(Flags)
638 .concat(RunTimeLang)
639 .get(VMContext),
640 File.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(),
641 nullptr, Elements, nullptr, nullptr,
642 UniqueIdentifier.empty() ? nullptr
643 : MDString::get(VMContext, UniqueIdentifier)};
644 DICompositeType R(MDNode::get(VMContext, Elts));
438 DICompositeType R = MDCompositeType::get(
439 VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
440 DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr, SizeInBits,
441 AlignInBits, 0, Flags, Elements, RunTimeLang, nullptr, nullptr,
442 UniqueIdentifier);
645443 if (!UniqueIdentifier.empty())
646444 retainType(R);
647445 trackIfUnresolved(R);
651449 DISubroutineType DIBuilder::createSubroutineType(DIFile File,
652450 DITypeArray ParameterTypes,
653451 unsigned Flags) {
654 // TAG_subroutine_type is encoded in DICompositeType format.
655 Metadata *Elts[] = {
656 HeaderBuilder::get(dwarf::DW_TAG_subroutine_type)
657 .concat(StringRef())
658 .concat(0) // Line
659 .concat(0) // Size
660 .concat(0) // Align
661 .concat(0) // Offset
662 .concat(Flags) // Flags
663 .concat(0)
664 .get(VMContext),
665 nullptr, nullptr, nullptr, ParameterTypes, nullptr, nullptr,
666 nullptr // Type Identifer
667 };
668 return DISubroutineType(MDNode::get(VMContext, Elts));
452 return MDSubroutineType::get(VMContext, Flags, ParameterTypes);
669453 }
670454
671455 DICompositeType DIBuilder::createEnumerationType(
672456 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
673457 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
674458 DIType UnderlyingType, StringRef UniqueIdentifier) {
675 // TAG_enumeration_type is encoded in DICompositeType format.
676 Metadata *Elts[] = {
677 HeaderBuilder::get(dwarf::DW_TAG_enumeration_type)
678 .concat(Name)
679 .concat(LineNumber)
680 .concat(SizeInBits)
681 .concat(AlignInBits)
682 .concat(0) // Offset
683 .concat(0) // Flags
684 .concat(0)
685 .get(VMContext),
686 File.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(),
687 UnderlyingType.getRef(), Elements, nullptr, nullptr,
688 UniqueIdentifier.empty() ? nullptr
689 : MDString::get(VMContext, UniqueIdentifier)};
690 DICompositeType CTy(MDNode::get(VMContext, Elts));
459 DICompositeType CTy = MDCompositeType::get(
460 VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
461 DIScope(getNonCompileUnitScope(Scope)).getRef(), UnderlyingType.getRef(),
462 SizeInBits, AlignInBits, 0, 0, Elements, 0, nullptr, nullptr,
463 UniqueIdentifier);
691464 AllEnumTypes.push_back(CTy);
692465 if (!UniqueIdentifier.empty())
693466 retainType(CTy);
697470
698471 DICompositeType DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
699472 DIType Ty, DIArray Subscripts) {
700 // TAG_array_type is encoded in DICompositeType format.
701 Metadata *Elts[] = {
702 HeaderBuilder::get(dwarf::DW_TAG_array_type)
703 .concat(StringRef())
704 .concat(0) // Line
705 .concat(Size)
706 .concat(AlignInBits)
707 .concat(0) // Offset
708 .concat(0) // Flags
709 .concat(0)
710 .get(VMContext),
711 nullptr, // Filename/Directory,
712 nullptr, // Unused
713 Ty.getRef(), Subscripts, nullptr, nullptr,
714 nullptr // Type Identifer
715 };
716 DICompositeType R(MDNode::get(VMContext, Elts));
473 auto *R = MDCompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
474 nullptr, 0, nullptr, Ty.getRef(), Size,
475 AlignInBits, 0, 0, Subscripts, 0, nullptr);
717476 trackIfUnresolved(R);
718477 return R;
719478 }
720479
721480 DICompositeType DIBuilder::createVectorType(uint64_t Size, uint64_t AlignInBits,
722481 DIType Ty, DIArray Subscripts) {
723 // A vector is an array type with the FlagVector flag applied.
724 Metadata *Elts[] = {
725 HeaderBuilder::get(dwarf::DW_TAG_array_type)
726 .concat("")
727 .concat(0) // Line
728 .concat(Size)
729 .concat(AlignInBits)
730 .concat(0) // Offset
731 .concat(DIType::FlagVector)
732 .concat(0)
733 .get(VMContext),
734 nullptr, // Filename/Directory,
735 nullptr, // Unused
736 Ty.getRef(), Subscripts, nullptr, nullptr,
737 nullptr // Type Identifer
738 };
739 DICompositeType R(MDNode::get(VMContext, Elts));
482 auto *R = MDCompositeType::get(
483 VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, nullptr, Ty.getRef(),
484 Size, AlignInBits, 0, DIType::FlagVector, Subscripts, 0, nullptr);
740485 trackIfUnresolved(R);
741486 return R;
742487 }
743488
744 static HeaderBuilder setTypeFlagsInHeader(StringRef Header,
745 unsigned FlagsToSet) {
746 DIHeaderFieldIterator I(Header);
747 std::advance(I, 6);
748
749 unsigned Flags;
750 if (I->getAsInteger(0, Flags))
751 Flags = 0;
752 Flags |= FlagsToSet;
753
754 return HeaderBuilder()
755 .concat(I.getPrefix())
756 .concat(Flags)
757 .concat(I.getSuffix());
758 }
759
760489 static DIType createTypeWithFlags(LLVMContext &Context, DIType Ty,
761490 unsigned FlagsToSet) {
762 SmallVector Elts;
763 MDNode *N = Ty;
764 assert(N && "Unexpected input DIType!");
765 // Update header field.
766 Elts.push_back(setTypeFlagsInHeader(Ty.getHeader(), FlagsToSet).get(Context));
767 Elts.append(N->op_begin() + 1, N->op_end());
768
769 return DIType(MDNode::get(Context, Elts));
491 TempMDType NewTy = cast(static_cast(Ty))->clone();
492 NewTy->setFlags(NewTy->getFlags() | FlagsToSet);
493 return MDNode::replaceWithUniqued(std::move(NewTy));
770494 }
771495
772496 DIType DIBuilder::createArtificialType(DIType Ty) {
497 // FIXME: Restrict this to the nodes where it's valid.
773498 if (Ty.isArtificial())
774499 return Ty;
775500 return createTypeWithFlags(VMContext, Ty, DIType::FlagArtificial);
776501 }
777502
778503 DIType DIBuilder::createObjectPointerType(DIType Ty) {
504 // FIXME: Restrict this to the nodes where it's valid.
779505 if (Ty.isObjectPointer())
780506 return Ty;
781507 unsigned Flags = DIType::FlagObjectPointer | DIType::FlagArtificial;
793519 DIFile F, unsigned Line, unsigned RuntimeLang,
794520 uint64_t SizeInBits, uint64_t AlignInBits,
795521 StringRef UniqueIdentifier) {
796 // Create a temporary MDNode.
797 Metadata *Elts[] = {
798 HeaderBuilder::get(Tag)
799 .concat(Name)
800 .concat(Line)
801 .concat(SizeInBits)
802 .concat(AlignInBits)
803 .concat(0) // Offset
804 .concat(DIDescriptor::FlagFwdDecl)
805 .concat(RuntimeLang)
806 .get(VMContext),
807 F.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr,
808 DIArray(), nullptr,
809 nullptr, // TemplateParams
810 UniqueIdentifier.empty() ? nullptr
811 : MDString::get(VMContext, UniqueIdentifier)};
812 MDNode *Node = MDNode::get(VMContext, Elts);
813 DICompositeType RetTy(Node);
814 assert(RetTy.isCompositeType() &&
815 "createForwardDecl result should be a DIType");
522 // FIXME: Define in terms of createReplaceableForwardDecl() by calling
523 // replaceWithUniqued().
524 DICompositeType RetTy = MDCompositeType::get(
525 VMContext, Tag, Name, F.getFileNode(), Line,
526 DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr, SizeInBits,
527 AlignInBits, 0, DIDescriptor::FlagFwdDecl, nullptr, RuntimeLang, nullptr,
528 nullptr, UniqueIdentifier);
816529 if (!UniqueIdentifier.empty())
817530 retainType(RetTy);
818531 trackIfUnresolved(RetTy);
823536 unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F, unsigned Line,
824537 unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits,
825538 unsigned Flags, StringRef UniqueIdentifier) {
826 // Create a temporary MDNode.
827 Metadata *Elts[] = {
828 HeaderBuilder::get(Tag)
829 .concat(Name)
830 .concat(Line)
831 .concat(SizeInBits)
832 .concat(AlignInBits)
833 .concat(0) // Offset
834 .concat(Flags)
835 .concat(RuntimeLang)
836 .get(VMContext),
837 F.getFileNode(), DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr,
838 DIArray(), nullptr,
839 nullptr, // TemplateParams
840 UniqueIdentifier.empty() ? nullptr
841 : MDString::get(VMContext, UniqueIdentifier)};
842 DICompositeType RetTy(MDNode::getTemporary(VMContext, Elts).release());
843 assert(RetTy.isCompositeType() &&
844 "createReplaceableForwardDecl result should be a DIType");
539 DICompositeType RetTy =
540 MDCompositeType::getTemporary(
541 VMContext, Tag, Name, F.getFileNode(), Line,
542 DIScope(getNonCompileUnitScope(Scope)).getRef(), nullptr, SizeInBits,
543 AlignInBits, 0, Flags, nullptr, RuntimeLang,
544 nullptr, nullptr, UniqueIdentifier).release();
845545 if (!UniqueIdentifier.empty())
846546 retainType(RetTy);
847547 trackIfUnresolved(RetTy);
864564 }
865565
866566 DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) {
867 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_subrange_type)
868 .concat(Lo)
869 .concat(Count)
870 .get(VMContext)};
871
872 return DISubrange(MDNode::get(VMContext, Elts));
873 }
874
875 static DIGlobalVariable createGlobalVariableHelper(
876 LLVMContext &VMContext, DIDescriptor Context, StringRef Name,
877 StringRef LinkageName, DIFile F, unsigned LineNumber, DITypeRef Ty,
878 bool isLocalToUnit, Constant *Val, MDNode *Decl, bool isDefinition,
879 std::function)> CreateFunc) {
880
567 return MDSubrange::get(VMContext, Count, Lo);
568 }
569
570 static void checkGlobalVariableScope(DIDescriptor Context) {
881571 MDNode *TheCtx = getNonCompileUnitScope(Context);
882572 if (DIScope(TheCtx).isCompositeType()) {
883573 assert(!DICompositeType(TheCtx).getIdentifier() &&
884574 "Context of a global variable should not be a type with identifier");
885575 }
886
887 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_variable)
888 .concat(Name)
889 .concat(Name)
890 .concat(LinkageName)
891 .concat(LineNumber)
892 .concat(isLocalToUnit)
893 .concat(isDefinition)
894 .get(VMContext),
895 TheCtx, F, Ty, getConstantOrNull(Val),
896 DIDescriptor(Decl)};
897
898 return DIGlobalVariable(CreateFunc(Elts));
899576 }
900577
901578 DIGlobalVariable DIBuilder::createGlobalVariable(
902579 DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F,
903580 unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit, Constant *Val,
904581 MDNode *Decl) {
905 return createGlobalVariableHelper(
906 VMContext, Context, Name, LinkageName, F, LineNumber, Ty, isLocalToUnit,
907 Val, Decl, true, [&](ArrayRef Elts) -> MDNode *{
908 MDNode *Node = MDNode::get(VMContext, Elts);
909 AllGVs.push_back(Node);
910 return Node;
911 });
582 checkGlobalVariableScope(Context);
583
584 auto *N = MDGlobalVariable::get(VMContext, Context, Name, LinkageName, F,
585 LineNumber, Ty, isLocalToUnit, true,
586 getConstantOrNull(Val), Decl);
587 AllGVs.push_back(N);
588 return N;
912589 }
913590
914591 DIGlobalVariable DIBuilder::createTempGlobalVariableFwdDecl(
915592 DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F,
916593 unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit, Constant *Val,
917594 MDNode *Decl) {
918 return createGlobalVariableHelper(VMContext, Context, Name, LinkageName, F,
919 LineNumber, Ty, isLocalToUnit, Val, Decl,
920 false, [&](ArrayRef Elts) {
921 return MDNode::getTemporary(VMContext, Elts).release();
922 });
595 checkGlobalVariableScope(Context);
596
597 return MDGlobalVariable::getTemporary(VMContext, Context, Name, LinkageName,
598 F, LineNumber, Ty, isLocalToUnit, false,
599 getConstantOrNull(Val), Decl).release();
923600 }
924601
925602 DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
927604 unsigned LineNo, DITypeRef Ty,
928605 bool AlwaysPreserve, unsigned Flags,
929606 unsigned ArgNo) {
607 // FIXME: Why getNonCompileUnitScope()?
608 // FIXME: Why is "!Context" okay here?
609 // FIXME: WHy doesn't this check for a subprogram or lexical block (AFAICT
610 // the only valid scopes)?
930611 DIDescriptor Context(getNonCompileUnitScope(Scope));
931612 assert((!Context || Context.isScope()) &&
932613 "createLocalVariable should be called with a valid Context");
933 Metadata *Elts[] = {HeaderBuilder::get(Tag)
934 .concat(Name)
935 .concat(LineNo | (ArgNo << 24))
936 .concat(Flags)
937 .get(VMContext),
938 getNonCompileUnitScope(Scope), File, Ty};
939 MDNode *Node = MDNode::get(VMContext, Elts);
614
615 auto *Node =
616 MDLocalVariable::get(VMContext, Tag, getNonCompileUnitScope(Scope), Name,
617 File, LineNo, Ty, ArgNo, Flags);
940618 if (AlwaysPreserve) {
941619 // The optimizer may remove local variable. If there is an interest
942620 // to preserve variable info in such situation then stash it in a
945623 assert(Fn && "Missing subprogram for local variable");
946624 PreservedVariables[Fn].emplace_back(Node);
947625 }
948 DIVariable RetVar(Node);
949 assert(RetVar.isVariable() &&
950 "createLocalVariable should return a valid DIVariable");
951 return RetVar;
626 return Node;
952627 }
953628
954629 DIExpression DIBuilder::createExpression(ArrayRef Addr) {
955 auto Header = HeaderBuilder::get(DW_TAG_expression);
956 for (uint64_t I : Addr)
957 Header.concat(I);
958 Metadata *Elts[] = {Header.get(VMContext)};
959 return DIExpression(MDNode::get(VMContext, Elts));
630 return MDExpression::get(VMContext, Addr);
960631 }
961632
962633 DIExpression DIBuilder::createExpression(ArrayRef Signed) {
965636 return createExpression(Addr);
966637 }
967638
968 DIExpression DIBuilder::createBitPieceExpression(unsigned OffsetInBits,
969 unsigned SizeInBits) {
970 int64_t Addr[] = {dwarf::DW_OP_bit_piece, OffsetInBits, SizeInBits};
971 return createExpression(Addr);
639 DIExpression DIBuilder::createBitPieceExpression(unsigned OffsetInBytes,
640 unsigned SizeInBytes) {
641 uint64_t Addr[] = {dwarf::DW_OP_bit_piece, OffsetInBytes, SizeInBytes};
642 return MDExpression::get(VMContext, Addr);
972643 }
973644
974645 DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
986657 Flags, isOptimized, Fn, TParams, Decl);
987658 }
988659
989 static DISubprogram createFunctionHelper(
990 LLVMContext &VMContext, DIDescriptor Context, StringRef Name,
991 StringRef LinkageName, DIFile File, unsigned LineNo, DICompositeType Ty,
992 bool isLocalToUnit, bool isDefinition, unsigned ScopeLine, unsigned Flags,
993 bool isOptimized, Function *Fn, MDNode *TParams, MDNode *Decl, MDNode *Vars,
994 std::function)> CreateFunc) {
995 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
996 "function types should be subroutines");
997 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_subprogram)
998 .concat(Name)
999 .concat(Name)
1000 .concat(LinkageName)
1001 .concat(LineNo)
1002 .concat(isLocalToUnit)
1003 .concat(isDefinition)
1004 .concat(0)
1005 .concat(0)
1006 .concat(Flags)
1007 .concat(isOptimized)
1008 .concat(ScopeLine)
1009 .get(VMContext),
1010 File.getFileNode(),
1011 DIScope(getNonCompileUnitScope(Context)).getRef(), Ty,
1012 nullptr, getConstantOrNull(Fn), TParams, Decl, Vars};
1013
1014 DISubprogram S(CreateFunc(Elts));
1015 assert(S.isSubprogram() &&
1016 "createFunction should return a valid DISubprogram");
1017 return S;
1018 }
1019
1020
1021660 DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
1022661 StringRef LinkageName, DIFile File,
1023662 unsigned LineNo, DICompositeType Ty,
1025664 unsigned ScopeLine, unsigned Flags,
1026665 bool isOptimized, Function *Fn,
1027666 MDNode *TParams, MDNode *Decl) {
1028 return createFunctionHelper(VMContext, Context, Name, LinkageName, File,
1029 LineNo, Ty, isLocalToUnit, isDefinition,
1030 ScopeLine, Flags, isOptimized, Fn, TParams, Decl,
1031 MDNode::getTemporary(VMContext, None).release(),
1032 [&](ArrayRef Elts) -> MDNode *{
1033 MDNode *Node = MDNode::get(VMContext, Elts);
1034 // Create a named metadata so that we
1035 // do not lose this mdnode.
1036 if (isDefinition)
1037 AllSubprograms.push_back(Node);
1038 trackIfUnresolved(Node);
1039 return Node;
1040 });
667 assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
668 "function types should be subroutines");
669 auto *Node = MDSubprogram::get(
670 VMContext, DIScope(getNonCompileUnitScope(Context)).getRef(), Name,
671 LinkageName, File.getFileNode(), LineNo, Ty, isLocalToUnit, isDefinition,
672 ScopeLine, nullptr, 0, 0, Flags, isOptimized, getConstantOrNull(Fn),
673 TParams, Decl, MDNode::getTemporary(VMContext, None).release());
674
675 if (isDefinition)
676 AllSubprograms.push_back(Node);
677 trackIfUnresolved(Node);
678 return Node;
1041679 }
1042680
1043681 DISubprogram
1048686 unsigned ScopeLine, unsigned Flags,
1049687 bool isOptimized, Function *Fn,
1050688 MDNode *TParams, MDNode *Decl) {
1051 return createFunctionHelper(VMContext, Context, Name, LinkageName, File,
1052 LineNo, Ty, isLocalToUnit, isDefinition,
1053 ScopeLine, Flags, isOptimized, Fn, TParams, Decl,
1054 nullptr, [&](ArrayRef Elts) {
1055 return MDNode::getTemporary(VMContext, Elts).release();
1056 });
689 return MDSubprogram::getTemporary(
690 VMContext, DIScope(getNonCompileUnitScope(Context)).getRef(), Name,
691 LinkageName, File.getFileNode(), LineNo, Ty, isLocalToUnit,
692 isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized,
693 getConstantOrNull(Fn), TParams, Decl, nullptr).release();
1057694 }
1058695
1059696 DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
1069706 assert(getNonCompileUnitScope(Context) &&
1070707 "Methods should have both a Context and a context that isn't "
1071708 "the compile unit.");
1072 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_subprogram)
1073 .concat(Name)
1074 .concat(Name)
1075 .concat(LinkageName)
1076 .concat(LineNo)
1077 .concat(isLocalToUnit)
1078 .concat(isDefinition)
1079 .concat(VK)
1080 .concat(VIndex)
1081 .concat(Flags)
1082 .concat(isOptimized)
1083 .concat(LineNo)
1084 // FIXME: Do we want to use different scope/lines?
1085 .get(VMContext),
1086 F.getFileNode(), DIScope(Context).getRef(), Ty,
1087 VTableHolder.getRef(), getConstantOrNull(Fn), TParam,
1088 nullptr, nullptr};
1089 MDNode *Node = MDNode::get(VMContext, Elts);
709 // FIXME: Do we want to use different scope/lines?
710 auto *Node = MDSubprogram::get(
711 VMContext, DIScope(Context).getRef(), Name, LinkageName, F.getFileNode(),
712 LineNo, Ty, isLocalToUnit, isDefinition, LineNo, VTableHolder.getRef(),
713 VK, VIndex, Flags, isOptimized, getConstantOrNull(Fn), TParam, nullptr,
714 nullptr);
715
1090716 if (isDefinition)
1091717 AllSubprograms.push_back(Node);
1092718 DISubprogram S(Node);
1097723
1098724 DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
1099725 DIFile File, unsigned LineNo) {
1100 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_namespace)
1101 .concat(Name)
1102 .concat(LineNo)
1103 .get(VMContext),
1104 File.getFileNode(), getNonCompileUnitScope(Scope)};
1105 DINameSpace R(MDNode::get(VMContext, Elts));
726 DINameSpace R = MDNamespace::get(VMContext, getNonCompileUnitScope(Scope),
727 File.getFileNode(), Name, LineNo);
1106728 assert(R.Verify() &&
1107729 "createNameSpace should return a verifiable DINameSpace");
1108730 return R;
1111733 DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
1112734 DIFile File,
1113735 unsigned Discriminator) {
1114 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_lexical_block)
1115 .concat(Discriminator)
1116 .get(VMContext),
1117 File.getFileNode(), Scope};
1118 DILexicalBlockFile R(MDNode::get(VMContext, Elts));
736 DILexicalBlockFile R = MDLexicalBlockFile::get(
737 VMContext, Scope, File.getFileNode(), Discriminator);
1119738 assert(
1120739 R.Verify() &&
1121740 "createLexicalBlockFile should return a verifiable DILexicalBlockFile");
1124743
1125744 DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
1126745 unsigned Line, unsigned Col) {
1127 // FIXME: This isn't thread safe nor the right way to defeat MDNode uniquing.
1128 // I believe the right way is to have a self-referential element in the node.
1129 // Also: why do we bother with line/column - they're not used and the
1130 // documentation (SourceLevelDebugging.rst) claims the line/col are necessary
1131 // for uniquing, yet then we have this other solution (because line/col were
1132 // inadequate) anyway. Remove all 3 and replace them with a self-reference.
1133
1134 // Defeat MDNode uniquing for lexical blocks by using unique id.
1135 static unsigned int unique_id = 0;
1136 Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_lexical_block)
1137 .concat(Line)
1138 .concat(Col)
1139 .concat(unique_id++)
1140 .get(VMContext),
1141 File.getFileNode(), getNonCompileUnitScope(Scope)};
1142 DILexicalBlock R(MDNode::get(VMContext, Elts));
746 // Make these distinct, to avoid merging two lexical blocks on the same
747 // file/line/column.
748 DILexicalBlock R = MDLexicalBlock::getDistinct(
749 VMContext, getNonCompileUnitScope(Scope), File.getFileNode(), Line, Col);
1143750 assert(R.Verify() &&
1144751 "createLexicalBlock should return a verifiable DILexicalBlock");
1145752 return R;
154154 return dyn_cast_or_null(getConstantField(Elt));
155155 }
156156
157 void DIDescriptor::replaceFunctionField(unsigned Elt, Function *F) {
158 if (!DbgNode)
159 return;
160
161 if (Elt < DbgNode->getNumOperands()) {
162 MDNode *Node = const_cast(DbgNode);
163 Node->replaceOperandWith(Elt, F ? ConstantAsMetadata::get(F) : nullptr);
164 }
165 }
166
167 static unsigned DIVariableInlinedAtIndex = 4;
168 MDNode *DIVariable::getInlinedAt() const {
169 return getNodeField(DbgNode, DIVariableInlinedAtIndex);
170 }
171
172157 /// \brief Return the size reported by the variable's type.
173158 unsigned DIVariable::getSizeInBits(const DITypeIdentifierMap &Map) {
174159 DIType Ty = getType().resolve(Map);
182167 return Ty.getSizeInBits();
183168 }
184169
185 uint64_t DIExpression::getElement(unsigned Idx) const {
186 unsigned I = Idx + 1;
187 assert(I < getNumHeaderFields() &&
188 "non-existing complex address element requested");
189 return getHeaderFieldAs(I);
190 }
191
192170 bool DIExpression::isBitPiece() const {
193171 unsigned N = getNumElements();
194172 return N >=3 && getElement(N-3) == dwarf::DW_OP_bit_piece;
204182 return getElement(getNumElements()-1);
205183 }
206184
207 DIExpression::iterator DIExpression::begin() const {
208 return DIExpression::iterator(*this);
209 }
210
211 DIExpression::iterator DIExpression::end() const {
212 return DIExpression::iterator();
213 }
214
215185 DIExpression::Operand DIExpression::Operand::getNext() const {
216186 iterator it(I);
217187 return *(++it);
218 }
219
220 //===----------------------------------------------------------------------===//
221 // Predicates
222 //===----------------------------------------------------------------------===//
223
224 bool DIDescriptor::isSubroutineType() const {
225 return DbgNode && getTag() == dwarf::DW_TAG_subroutine_type;
226 }
227
228 bool DIDescriptor::isBasicType() const {
229 if (!DbgNode)
230 return false;
231 switch (getTag()) {
232 case dwarf::DW_TAG_base_type:
233 case dwarf::DW_TAG_unspecified_type:
234 return true;
235 default:
236 return false;
237 }
238 }
239
240 bool DIDescriptor::isDerivedType() const {
241 if (!DbgNode)
242 return false;
243 switch (getTag()) {
244 case dwarf::DW_TAG_typedef:
245 case dwarf::DW_TAG_pointer_type:
246 case dwarf::DW_TAG_ptr_to_member_type:
247 case dwarf::DW_TAG_reference_type:
248 case dwarf::DW_TAG_rvalue_reference_type:
249 case dwarf::DW_TAG_const_type:
250 case dwarf::DW_TAG_volatile_type:
251 case dwarf::DW_TAG_restrict_type:
252 case dwarf::DW_TAG_member:
253 case dwarf::DW_TAG_inheritance:
254 case dwarf::DW_TAG_friend:
255 return true;
256 default:
257 // CompositeTypes are currently modelled as DerivedTypes.
258 return isCompositeType();
259 }
260 }
261
262 bool DIDescriptor::isCompositeType() const {
263 if (!DbgNode)
264 return false;
265 switch (getTag()) {
266 case dwarf::DW_TAG_array_type:
267 case dwarf::DW_TAG_structure_type:
268 case dwarf::DW_TAG_union_type:
269 case dwarf::DW_TAG_enumeration_type:
270 case dwarf::DW_TAG_subroutine_type:
271 case dwarf::DW_TAG_class_type:
272 return true;
273 default:
274 return false;
275 }
276 }
277
278 bool DIDescriptor::isVariable() const {
279 if (!DbgNode)
280 return false;
281 switch (getTag()) {
282 case dwarf::DW_TAG_auto_variable:
283 case dwarf::DW_TAG_arg_variable:
284 return true;
285 default:
286 return false;
287 }
288 }
289
290 bool DIDescriptor::isType() const {
291 return isBasicType() || isCompositeType() || isDerivedType();
292 }
293
294 bool DIDescriptor::isSubprogram() const {
295 return DbgNode && getTag() == dwarf::DW_TAG_subprogram;
296 }
297
298 bool DIDescriptor::isGlobalVariable() const {
299 return DbgNode && getTag() == dwarf::DW_TAG_variable;
300 }
301
302 bool DIDescriptor::isScope() const {
303 if (!DbgNode)
304 return false;
305 switch (getTag()) {
306 case dwarf::DW_TAG_compile_unit:
307 case dwarf::DW_TAG_lexical_block:
308 case dwarf::DW_TAG_subprogram:
309 case dwarf::DW_TAG_namespace:
310 case dwarf::DW_TAG_file_type:
311 return true;
312 default:
313 break;
314 }
315 return isType();
316 }
317
318 bool DIDescriptor::isTemplateTypeParameter() const {
319 return DbgNode && getTag() == dwarf::DW_TAG_template_type_parameter;
320 }
321
322 bool DIDescriptor::isTemplateValueParameter() const {
323 return DbgNode && (getTag() == dwarf::DW_TAG_template_value_parameter ||
324 getTag() == dwarf::DW_TAG_GNU_template_template_param ||
325 getTag() == dwarf::DW_TAG_GNU_template_parameter_pack);
326 }
327
328 bool DIDescriptor::isCompileUnit() const {
329 return DbgNode && getTag() == dwarf::DW_TAG_compile_unit;
330 }
331
332 bool DIDescriptor::isFile() const {
333 return DbgNode && getTag() == dwarf::DW_TAG_file_type;
334 }
335
336 bool DIDescriptor::isNameSpace() const {
337 return DbgNode && getTag() == dwarf::DW_TAG_namespace;
338 }
339
340 bool DIDescriptor::isLexicalBlockFile() const {
341 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
342 DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 2;
343 }
344
345 bool DIDescriptor::isLexicalBlock() const {
346 // FIXME: There are always exactly 4 header fields in DILexicalBlock, but
347 // something relies on this returning true for DILexicalBlockFile.
348 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
349 DbgNode->getNumOperands() == 3 &&
350 (getNumHeaderFields() == 2 || getNumHeaderFields() == 4);
351 }
352
353 bool DIDescriptor::isSubrange() const {
354 return DbgNode && getTag() == dwarf::DW_TAG_subrange_type;
355 }
356
357 bool DIDescriptor::isEnumerator() const {
358 return DbgNode && getTag() == dwarf::DW_TAG_enumerator;
359 }
360
361 bool DIDescriptor::isObjCProperty() const {
362 return DbgNode && getTag() == dwarf::DW_TAG_APPLE_property;
363 }
364
365 bool DIDescriptor::isImportedEntity() const {
366 return DbgNode && (getTag() == dwarf::DW_TAG_imported_module ||
367 getTag() == dwarf::DW_TAG_imported_declaration);
368 }
369
370 bool DIDescriptor::isExpression() const {
371 return DbgNode && (getTag() == dwarf::DW_TAG_expression);
372188 }
373189
374190 //===----------------------------------------------------------------------===//
408224
409225 // Don't bother verifying the compilation directory or producer string
410226 // as those could be empty.
411 if (getFilename().empty())
412 return false;
413
414 return DbgNode->getNumOperands() == 7 && getNumHeaderFields() == 8;
415 }
416
417 bool DIObjCProperty::Verify() const {
418 if (!isObjCProperty())
419 return false;
420
421 // Don't worry about the rest of the strings for now.
422 return DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 6;
423 }
424
425 /// \brief Check if a field at position Elt of a MDNode is a MDNode.
426 static bool fieldIsMDNode(const MDNode *DbgNode, unsigned Elt) {
427 Metadata *Fld = getField(DbgNode, Elt);
428 return !Fld || isa(Fld);
429 }
430
431 /// \brief Check if a field at position Elt of a MDNode is a MDString.
432 static bool fieldIsMDString(const MDNode *DbgNode, unsigned Elt) {
433 Metadata *Fld = getField(DbgNode, Elt);
434 return !Fld || isa(Fld);
435 }
227 return !getFilename().empty();
228 }
229
230 bool DIObjCProperty::Verify() const { return isObjCProperty(); }
436231
437232 /// \brief Check if a value can be a reference to a type.
438233 static bool isTypeRef(const Metadata *MD) {
440235 return true;
441236 if (auto *S = dyn_cast(MD))
442237 return !S->getString().empty();
443 if (auto *N = dyn_cast(MD))
444 return DIType(N).isType();
445 return false;
446 }
447
448 /// \brief Check if referenced field might be a type.
449 static bool fieldIsTypeRef(const MDNode *DbgNode, unsigned Elt) {
450 return isTypeRef(dyn_cast_or_null(getField(DbgNode, Elt)));
238 return isa(MD);
451239 }
452240
453241 /// \brief Check if a value can be a ScopeRef.
456244 return true;
457245 if (auto *S = dyn_cast(MD))
458246 return !S->getString().empty();
459 if (auto *N = dyn_cast(MD))
460 return DIScope(N).isScope();
461 return false;
462 }
463
464 /// \brief Check if a field at position Elt of a MDNode can be a ScopeRef.
465 static bool fieldIsScopeRef(const MDNode *DbgNode, unsigned Elt) {
466 return isScopeRef(dyn_cast_or_null(getField(DbgNode, Elt)));
247 return isa(MD);
467248 }
468249
469250 #ifndef NDEBUG
478259 #endif
479260
480261 bool DIType::Verify() const {
481 if (!isType())
482 return false;
483 // Make sure Context @ field 2 is MDNode.
484 if (!fieldIsScopeRef(DbgNode, 2))
262 auto *N = getRaw();
263 if (!N)
264 return false;
265 if (!isScopeRef(N->getScope()))
485266 return false;
486267
487268 // FIXME: Sink this into the various subclass verifies.
510291 return false;
511292 }
512293
513 bool DIBasicType::Verify() const {
514 return isBasicType() && DbgNode->getNumOperands() == 3 &&
515 getNumHeaderFields() == 8;
516 }
294 bool DIBasicType::Verify() const { return getRaw(); }
517295
518296 bool DIDerivedType::Verify() const {
519 // Make sure DerivedFrom @ field 3 is TypeRef.
520 if (!fieldIsTypeRef(DbgNode, 3))
521 return false;
522 if (getTag() == dwarf::DW_TAG_ptr_to_member_type)
523 // Make sure ClassType @ field 4 is a TypeRef.
524 if (!fieldIsTypeRef(DbgNode, 4))
297 auto *N = getRaw();
298 if (!N)
299 return false;
300 if (getTag() == dwarf::DW_TAG_ptr_to_member_type) {
301 auto *D = dyn_cast(N);
302 if (!D)
525303 return false;
526
527 return isDerivedType() && DbgNode->getNumOperands() >= 4 &&
528 DbgNode->getNumOperands() <= 8 && getNumHeaderFields() >= 7 &&
529 getNumHeaderFields() <= 8;
304 if (!isTypeRef(D->getExtraData()))
305 return false;
306 }
307 return isTypeRef(N->getBaseType());
530308 }
531309
532310 bool DICompositeType::Verify() const {
533 if (!isCompositeType())
534 return false;
535
536 // Make sure DerivedFrom @ field 3 and ContainingType @ field 5 are TypeRef.
537 if (!fieldIsTypeRef(DbgNode, 3))
538 return false;
539 if (!fieldIsTypeRef(DbgNode, 5))
540 return false;
541
542 // Make sure the type identifier at field 7 is MDString, it can be null.
543 if (!fieldIsMDString(DbgNode, 7))
544 return false;
545
546 // A subroutine type can't be both & and &&.
547 if (isLValueReference() && isRValueReference())
548 return false;
549
550 return DbgNode->getNumOperands() == 8 && getNumHeaderFields() == 8;
311 auto *N = getRaw();
312 return N && isTypeRef(N->getBaseType()) && isTypeRef(N->getVTableHolder()) &&
313 !(isLValueReference() && isRValueReference());
551314 }
552315
553316 bool DISubprogram::Verify() const {
554 if (!isSubprogram())
555 return false;
556
557 // Make sure context @ field 2 is a ScopeRef and type @ field 3 is a MDNode.
558 if (!fieldIsScopeRef(DbgNode, 2))
559 return false;
560 if (!fieldIsMDNode(DbgNode, 3))
561 return false;
562 // Containing type @ field 4.
563 if (!fieldIsTypeRef(DbgNode, 4))
564 return false;
565
566 // A subprogram can't be both & and &&.
317 auto *N = getRaw();
318 if (!N)
319 return false;
320
321 if (!isScopeRef(N->getScope()))
322 return false;
323
324 if (auto *Op = N->getType())
325 if (!isa(Op))
326 return false;
327
328 if (!isTypeRef(getContainingType()))
329 return false;
330
567331 if (isLValueReference() && isRValueReference())
568332 return false;
569333
598362 }
599363 }
600364 }
601 return DbgNode->getNumOperands() == 9 && getNumHeaderFields() == 12;
365
366 return true;
602367 }
603368
604369 bool DIGlobalVariable::Verify() const {
605 if (!isGlobalVariable())
606 return false;
607
608 if (getDisplayName().empty())
609 return false;
610 // Make sure context @ field 1 is an MDNode.
611 if (!fieldIsMDNode(DbgNode, 1))
612 return false;
613 // Make sure that type @ field 3 is a DITypeRef.
614 if (!fieldIsTypeRef(DbgNode, 3))
615 return false;
616 // Make sure StaticDataMemberDeclaration @ field 5 is MDNode.
617 if (!fieldIsMDNode(DbgNode, 5))
618 return false;
619
620 return DbgNode->getNumOperands() == 6 && getNumHeaderFields() == 7;
370 auto *N = getRaw();
371
372 if (!N)
373 return false;
374
375 if (N->getDisplayName().empty())
376 return false;
377
378 if (auto *Op = N->getScope())
379 if (!isa(Op))
380 return false;
381
382 if (auto *Op = N->getStaticDataMemberDeclaration())
383 if (!isa(Op))
384 return false;
385
386 return isTypeRef(N->getType());
621387 }
622388
623389 bool DIVariable::Verify() const {
624 if (!isVariable())
625 return false;
626
627 // Make sure context @ field 1 is an MDNode.
628 if (!fieldIsMDNode(DbgNode, 1))
629 return false;
630 // Make sure that type @ field 3 is a DITypeRef.
631 if (!fieldIsTypeRef(DbgNode, 3))
632 return false;
633
634 // Check the number of header fields, which is common between complex and
635 // simple variables.
636 if (getNumHeaderFields() != 4)
637 return false;
638
639 // Variable without an inline location.
640 if (DbgNode->getNumOperands() == 4)
641 return true;
642
643 // Variable with an inline location.
644 return getInlinedAt() != nullptr && DbgNode->getNumOperands() == 5;
390 auto *N = getRaw();
391
392 if (!N)
393 return false;
394
395 if (auto *Op = N->getScope())
396 if (!isa(Op))
397 return false;
398
399 return isTypeRef(N->getType());
645400 }
646401
647402 bool DIExpression::Verify() const {
648 // Empty DIExpressions may be represented as a nullptr.
649 if (!DbgNode)
650 return true;
651
652 if (!(isExpression() && DbgNode->getNumOperands() == 1))
653 return false;
654
655 for (auto Op : *this)
656 switch (Op) {
657 case DW_OP_bit_piece:
658 // Must be the last element of the expression.
659 return std::distance(Op.getBase(), DIHeaderFieldIterator()) == 3;
660 case DW_OP_plus:
661 if (std::distance(Op.getBase(), DIHeaderFieldIterator()) < 2)
662 return false;
663 break;
664 case DW_OP_deref:
665 break;
666 default:
667 // Other operators are not yet supported by the backend.
668 return false;
669 }
670 return true;
671 }
672
673 bool DILocation::Verify() const {
674 return DbgNode && isa(DbgNode);
675 }
676
677 bool DINameSpace::Verify() const {
678 if (!isNameSpace())
679 return false;
680 return DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 3;
681 }
682
683 MDNode *DIFile::getFileNode() const { return getNodeField(DbgNode, 1); }
684
685 bool DIFile::Verify() const {
686 return isFile() && DbgNode->getNumOperands() == 2;
687 }
688
689 bool DIEnumerator::Verify() const {
690 return isEnumerator() && DbgNode->getNumOperands() == 1 &&
691 getNumHeaderFields() == 3;
692 }
693
694 bool DISubrange::Verify() const {
695 return isSubrange() && DbgNode->getNumOperands() == 1 &&
696 getNumHeaderFields() == 3;
697 }
698
699 bool DILexicalBlock::Verify() const {
700 return isLexicalBlock() && DbgNode->getNumOperands() == 3 &&
701 getNumHeaderFields() == 4;
702 }
703
704 bool DILexicalBlockFile::Verify() const {
705 return isLexicalBlockFile() && DbgNode->getNumOperands() == 3 &&
706 getNumHeaderFields() == 2;
707 }
708
709 bool DITemplateTypeParameter::Verify() const {
710 return isTemplateTypeParameter() && DbgNode->getNumOperands() == 4 &&
711 getNumHeaderFields() == 4;
712 }
713
714 bool DITemplateValueParameter::Verify() const {
715 return isTemplateValueParameter() && DbgNode->getNumOperands() == 5 &&
716 getNumHeaderFields() == 4;
717 }
718
719 bool DIImportedEntity::Verify() const {
720 return isImportedEntity() && DbgNode->getNumOperands() == 3 &&
721 getNumHeaderFields() == 3;
722 }
723
724 MDNode *DIDerivedType::getObjCProperty() const {
725 return getNodeField(DbgNode, 4);
726 }
727
728 MDString *DICompositeType::getIdentifier() const {
729 return cast_or_null(getField(DbgNode, 7));
730 }
731
732 #ifndef NDEBUG
733 static void VerifySubsetOf(const MDNode *LHS, const MDNode *RHS) {
734 for (unsigned i = 0; i != LHS->getNumOperands(); ++i) {
735 // Skip the 'empty' list (that's a single i32 0, rather than truly empty).
736 if (i == 0 && mdconst::hasa(LHS->getOperand(i)))
737 continue;
738 const MDNode *E = cast(LHS->getOperand(i));
739 bool found = false;
740 for (unsigned j = 0; !found && j != RHS->getNumOperands(); ++j)
741 found = (E == cast(RHS->getOperand(j)));
742 assert(found && "Losing a member during member list replacement");
743 }
744 }
745 #endif
403 // FIXME: This should return false if it's null!
404 auto *N = getRaw();
405 return !N || N->isValid();
406 }
407
408 bool DILocation::Verify() const { return getRaw(); }
409 bool DINameSpace::Verify() const { return getRaw(); }
410 bool DIFile::Verify() const { return getRaw(); }
411 bool DIEnumerator::Verify() const { return getRaw(); }
412 bool DISubrange::Verify() const { return getRaw(); }
413 bool DILexicalBlock::Verify() const { return getRaw(); }
414 bool DILexicalBlockFile::Verify() const { return getRaw(); }
415 bool DITemplateTypeParameter::Verify() const { return getRaw(); }
416 bool DITemplateValueParameter::Verify() const { return getRaw(); }
417 bool DIImportedEntity::Verify() const { return getRaw(); }
746418
747419 void DICompositeType::setArraysHelper(MDNode *Elements, MDNode *TParams) {
748 TrackingMDNodeRef N(*this);
749 if (Elements) {
750 #ifndef NDEBUG
751 // Check that the new list of members contains all the old members as well.
752 if (const MDNode *El = cast_or_null(N->getOperand(4)))
753 VerifySubsetOf(El, Elements);
754 #endif
755 N->replaceOperandWith(4, Elements);
756 }
420 TypedTrackingMDRef N(getRaw());
421 if (Elements)
422 N->replaceElements(cast(Elements));
757423 if (TParams)
758 N->replaceOperandWith(6, TParams);
424 N->replaceTemplateParams(cast(TParams));
759425 DbgNode = N;
760426 }
761427
769435 }
770436
771437 void DICompositeType::setContainingType(DICompositeType ContainingType) {
772 TrackingMDNodeRef N(*this);
773 N->replaceOperandWith(5, ContainingType.getRef());
438 TypedTrackingMDRef N(getRaw());
439 N->replaceVTableHolder(ContainingType.getRef());
774440 DbgNode = N;
775441 }
776442
781447 // This variable is not inlined function argument if its scope
782448 // does not describe current function.
783449 return !DISubprogram(getContext()).describes(CurFn);
450 }
451
452 Function *DISubprogram::getFunction() const {
453 if (auto *N = getRaw())
454 if (auto *C = dyn_cast_or_null(N->getFunction()))
455 return dyn_cast(C->getValue());
456 return nullptr;
784457 }
785458
786459 bool DISubprogram::describes(const Function *F) {
795468 return false;
796469 }
797470
798 MDNode *DISubprogram::getVariablesNodes() const {
799 return getNodeField(DbgNode, 8);
800 }
801
802 DIArray DISubprogram::getVariables() const {
803 return DIArray(getNodeField(DbgNode, 8));
804 }
805
806 Metadata *DITemplateValueParameter::getValue() const {
807 return DbgNode->getOperand(3);
471 GlobalVariable *DIGlobalVariable::getGlobal() const {
472 return dyn_cast_or_null(getConstant());
808473 }
809474
810475 DIScopeRef DIScope::getContext() const {
842507 }
843508
844509 StringRef DIScope::getFilename() const {
845 if (!DbgNode)
846 return StringRef();
847 return ::getStringField(getNodeField(DbgNode, 1), 0);
510 if (auto *N = getRaw())
511 return ::getStringField(dyn_cast_or_null(N->getFile()), 0);
512 return "";
848513 }
849514
850515 StringRef DIScope::getDirectory() const {
851 if (!DbgNode)
852 return StringRef();
853 return ::getStringField(getNodeField(DbgNode, 1), 1);
854 }
855
856 DIArray DICompileUnit::getEnumTypes() const {
857 if (!DbgNode || DbgNode->getNumOperands() < 7)
858 return DIArray();
859
860 return DIArray(getNodeField(DbgNode, 2));
861 }
862
863 DIArray DICompileUnit::getRetainedTypes() const {
864 if (!DbgNode || DbgNode->getNumOperands() < 7)
865 return DIArray();
866
867 return DIArray(getNodeField(DbgNode, 3));
868 }
869
870 DIArray DICompileUnit::getSubprograms() const {
871 if (!DbgNode || DbgNode->getNumOperands() < 7)
872 return DIArray();
873
874 return DIArray(getNodeField(DbgNode, 4));
875 }
876
877 DIArray DICompileUnit::getGlobalVariables() const {
878 if (!DbgNode || DbgNode->getNumOperands() < 7)
879 return DIArray();
880
881 return DIArray(getNodeField(DbgNode, 5));
882 }
883
884 DIArray DICompileUnit::getImportedEntities() const {
885 if (!DbgNode || DbgNode->getNumOperands() < 7)
886 return DIArray();
887
888 return DIArray(getNodeField(DbgNode, 6));
516 if (auto *N = getRaw())
517 return ::getStringField(dyn_cast_or_null(N->getFile()), 1);
518 return "";
889519 }
890520
891521 void DICompileUnit::replaceSubprograms(DIArray Subprograms) {
892522 assert(Verify() && "Expected compile unit");
893 if (Subprograms == getSubprograms())
894 return;
895
896 const_cast(DbgNode)->replaceOperandWith(4, Subprograms);
523 getRaw()->replaceSubprograms(cast_or_null(Subprograms.get()));
897524 }
898525
899526 void DICompileUnit::replaceGlobalVariables(DIArray GlobalVariables) {
900527 assert(Verify() && "Expected compile unit");
901 if (GlobalVariables == getGlobalVariables())
902 return;
903
904 const_cast(DbgNode)->replaceOperandWith(5, GlobalVariables);
528 getRaw()->replaceGlobalVariables(
529 cast_or_null(GlobalVariables.get()));
905530 }
906531
907532 DILocation DILocation::copyWithNewScope(LLVMContext &Ctx,
922547 DIVariable llvm::createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
923548 LLVMContext &VMContext) {
924549 assert(DIVariable(DV).Verify() && "Expected a DIVariable");
925 if (!InlinedScope)
926 return cleanseInlinedVariable(DV, VMContext);
927
928 // Insert inlined scope.
929 SmallVector Elts(DV->op_begin(),
930 DV->op_begin() + DIVariableInlinedAtIndex);
931 Elts.push_back(InlinedScope);
932
933 DIVariable Inlined(MDNode::get(VMContext, Elts));
934 assert(Inlined.Verify() && "Expected to create a DIVariable");
935 return Inlined;
550 return cast(DV)
551 ->withInline(cast_or_null(InlinedScope));
936552 }
937553
938554 DIVariable llvm::cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext) {
939555 assert(DIVariable(DV).Verify() && "Expected a DIVariable");
940 if (!DIVariable(DV).getInlinedAt())
941 return DIVariable(DV);
942
943 // Remove inlined scope.
944 SmallVector Elts(DV->op_begin(),
945 DV->op_begin() + DIVariableInlinedAtIndex);
946
947 DIVariable Cleansed(MDNode::get(VMContext, Elts));
948 assert(Cleansed.Verify() && "Expected to create a DIVariable");
949 return Cleansed;
556 return cast(DV)->withoutInline();
950557 }
951558
952559 DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
1262869 }
1263870
1264871 void DIDescriptor::print(raw_ostream &OS) const {
1265 if (!DbgNode)
1266 return;
1267
1268 if (const char *Tag = dwarf::TagString(getTag()))
1269 OS << "[ " << Tag << " ]";
1270
1271 if (this->isSubrange()) {
1272 DISubrange(DbgNode).printInternal(OS);
1273 } else if (this->isCompileUnit()) {
1274 DICompileUnit(DbgNode).printInternal(OS);
1275 } else if (this->isFile()) {
1276 DIFile(DbgNode).printInternal(OS);
1277 } else if (this->isEnumerator()) {
1278 DIEnumerator(DbgNode).printInternal(OS);
1279 } else if (this->isBasicType()) {
1280 DIType(DbgNode).printInternal(OS);
1281 } else if (this->isDerivedType()) {
1282 DIDerivedType(DbgNode).printInternal(OS);
1283 } else if (this->isCompositeType()) {
1284 DICompositeType(DbgNode).printInternal(OS);
1285 } else if (this->isSubprogram()) {
1286 DISubprogram(DbgNode).printInternal(OS);
1287 } else if (this->isGlobalVariable()) {
1288 DIGlobalVariable(DbgNode).printInternal(OS);
1289 } else if (this->isVariable()) {
1290 DIVariable(DbgNode).printInternal(OS);
1291 } else if (this->isObjCProperty()) {
1292 DIObjCProperty(DbgNode).printInternal(OS);
1293 } else if (this->isNameSpace()) {
1294 DINameSpace(DbgNode).printInternal(OS);
1295 } else if (this->isScope()) {
1296 DIScope(DbgNode).printInternal(OS);
1297 } else if (this->isExpression()) {
1298 DIExpression(DbgNode).printInternal(OS);
1299 }
1300 }
1301
1302 void DISubrange::printInternal(raw_ostream &OS) const {
1303 int64_t Count = getCount();
1304 if (Count != -1)
1305 OS << " [" << getLo() << ", " << Count - 1 << ']';
1306 else
1307 OS << " [unbounded]";
1308 }
1309
1310 void DIScope::printInternal(raw_ostream &OS) const {
1311 OS << " [" << getDirectory() << "/" << getFilename() << ']';
1312 }
1313
1314 void DICompileUnit::printInternal(raw_ostream &OS) const {
1315 DIScope::printInternal(OS);
1316 OS << " [";
1317 unsigned Lang = getLanguage();
1318 if (const char *LangStr = dwarf::LanguageString(Lang))
1319 OS << LangStr;
1320 else
1321 (OS << "lang 0x").write_hex(Lang);
1322 OS << ']';
1323 }
1324
1325 void DIEnumerator::printInternal(raw_ostream &OS) const {
1326 OS << " [" << getName() << " :: " << getEnumValue() << ']';
1327 }
1328
1329 void DIType::printInternal(raw_ostream &OS) const {
1330 if (!DbgNode)
1331 return;
1332
1333 StringRef Res = getName();
1334 if (!Res.empty())
1335 OS << " [" << Res << "]";
1336
1337 // TODO: Print context?
1338
1339 OS << " [line " << getLineNumber() << ", size " << getSizeInBits()
1340 << ", align " << getAlignInBits() << ", offset " << getOffsetInBits();
1341 if (isBasicType())
1342 if (const char *Enc =
1343 dwarf::AttributeEncodingString(DIBasicType(DbgNode).getEncoding()))
1344 OS << ", enc " << Enc;
1345 OS << "]";
1346
1347 if (isPrivate())
1348 OS << " [private]";
1349 else if (isProtected())
1350 OS << " [protected]";
1351 else if (isPublic())
1352 OS << " [public]";
1353
1354 if (isArtificial())
1355 OS << " [artificial]";
1356
1357 if (isForwardDecl())
1358 OS << " [decl]";
1359 else if (getTag() == dwarf::DW_TAG_structure_type ||
1360 getTag() == dwarf::DW_TAG_union_type ||
1361 getTag() == dwarf::DW_TAG_enumeration_type ||
1362 getTag() == dwarf::DW_TAG_class_type)
1363 OS << " [def]";
1364 if (isVector())
1365 OS << " [vector]";
1366 if (isStaticMember())
1367 OS << " [static]";
1368
1369 if (isLValueReference())
1370 OS << " [reference]";
1371
1372 if (isRValueReference())
1373 OS << " [rvalue reference]";
1374 }
1375
1376 void DIDerivedType::printInternal(raw_ostream &OS) const {
1377 DIType::printInternal(OS);
1378 OS << " [from " << getTypeDerivedFrom().getName() << ']';
1379 }
1380
1381 void DICompositeType::printInternal(raw_ostream &OS) const {
1382 DIType::printInternal(OS);
1383 DIArray A = getElements();
1384 OS << " [" << A.getNumElements() << " elements]";
1385 }
1386
1387 void DINameSpace::printInternal(raw_ostream &OS) const {
1388 StringRef Name = getName();
1389 if (!Name.empty())
1390 OS << " [" << Name << ']';
1391
1392 OS << " [line " << getLineNumber() << ']';
1393 }
1394
1395 void DISubprogram::printInternal(raw_ostream &OS) const {
1396 // TODO : Print context
1397 OS << " [line " << getLineNumber() << ']';
1398
1399 if (isLocalToUnit())
1400 OS << " [local]";
1401
1402 if (isDefinition())
1403 OS << " [def]";
1404
1405 if (getScopeLineNumber() != getLineNumber())
1406 OS << " [scope " << getScopeLineNumber() << "]";
1407
1408 if (isPrivate())
1409 OS << " [private]";
1410 else if (isProtected())
1411 OS << " [protected]";
1412 else if (isPublic())
1413 OS << " [public]";
1414
1415 if (isLValueReference())
1416 OS << " [reference]";
1417
1418 if (isRValueReference())
1419 OS << " [rvalue reference]";
1420
1421 StringRef Res = getName();
1422 if (!Res.empty())
1423 OS << " [" << Res << ']';
1424 }
1425
1426 void DIGlobalVariable::printInternal(raw_ostream &OS) const {
1427 StringRef Res = getName();
1428 if (!Res.empty())
1429 OS << " [" << Res << ']';
1430
1431 OS << " [line " << getLineNumber() << ']';
1432
1433 // TODO : Print context
1434
1435 if (isLocalToUnit())
1436 OS << " [local]";
1437
1438 if (isDefinition())
1439 OS << " [def]";
1440 }
1441
1442 void DIVariable::printInternal(raw_ostream &OS) const {
1443 StringRef Res = getName();
1444 if (!Res.empty())
1445 OS << " [" << Res << ']';
1446
1447 OS << " [line " << getLineNumber() << ']';
1448 }
1449
1450 void DIExpression::printInternal(raw_ostream &OS) const {
1451 for (auto Op : *this) {
1452 OS << " [" << OperationEncodingString(Op);
1453 switch (Op) {
1454 case DW_OP_plus: {
1455 OS << " " << Op.getArg(1);
1456 break;
1457 }
1458 case DW_OP_bit_piece: {
1459 OS << " offset=" << Op.getArg(1) << ", size=" << Op.getArg(2);
1460 break;
1461 }
1462 case DW_OP_deref:
1463 // No arguments.
1464 break;
1465 default:
1466 llvm_unreachable("unhandled operation");
1467 }
1468 OS << "]";
1469 }
1470 }
1471
1472 void DIObjCProperty::printInternal(raw_ostream &OS) const {
1473 StringRef Name = getObjCPropertyName();
1474 if (!Name.empty())
1475 OS << " [" << Name << ']';
1476
1477 OS << " [line " << getLineNumber() << ", properties " << getUnsignedField(6)
1478 << ']';
872 if (!get())
873 return;
874 get()->print(OS);
1479875 }
1480876
1481877 static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS,
1212 define i32 @main() nounwind readonly {
1313 %diff1 = alloca i64 ; [#uses=2]
1414 ; CHECK: call void @llvm.dbg.value(metadata i64 72,
15 call void @llvm.dbg.declare(metadata i64* %diff1, metadata !0, metadata !{!"0x102"})
15 call void @llvm.dbg.declare(metadata i64* %diff1, metadata !0, metadata !MDExpression())
1616 store i64 72, i64* %diff1, align 8
1717 %v1 = load %struct.test*, %struct.test** @TestArrayPtr, align 8 ; <%struct.test*> [#uses=1]
1818 %v2 = ptrtoint %struct.test* %v1 to i64 ; [#uses=1]
2424 declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
2525
2626 !7 = !{!1}
27 !6 = !{!"0x11\0012\00clang version 3.0 (trunk 131941)\001\00\000\00\000", !8, !9, !9, !7, null, null} ; [ DW_TAG_compile_unit ]
28 !0 = !{!"0x100\00c\002\000", !1, !2, !5} ; [ DW_TAG_auto_variable ]
29 !1 = !{!"0x2e\00main\00main\00\001\000\001\000\006\00256\000\001", !8, !2, !3, null, i32 ()* @main, null, null, null} ; [ DW_TAG_subprogram ]
30 !2 = !{!"0x29", !8} ; [ DW_TAG_file_type ]
31 !3 = !{!"0x15\00\000\000\000\000\000\000", !8, !2, null, !4, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
27 !6 = !MDCompileUnit(language: DW_LANG_C99, producer: "clang version 3.0 (trunk 131941)", isOptimized: true, emissionKind: 0, file: !8, enums: !9, retainedTypes: !9, subprograms: !7)
28 !0 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "c", line: 2, scope: !1, file: !2, type: !5)
29 !1 = !MDSubprogram(name: "main", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 1, file: !8, scope: !2, type: !3, function: i32 ()* @main)
30 !2 = !MDFile(filename: "/d/j/debug-test.c", directory: "/Volumes/Data/b")
31 !3 = !MDSubroutineType(types: !4)
3232 !4 = !{!5}
33 !5 = !{!"0x24\00int\000\0032\0032\000\000\005", null, !6} ; [ DW_TAG_base_type ]
34 !8 = !{!"/d/j/debug-test.c", !"/Volumes/Data/b"}
33 !5 = !MDBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
34 !8 = !MDFile(filename: "/d/j/debug-test.c", directory: "/Volumes/Data/b")
3535 !9 = !{i32 0}
3636
3737 !llvm.module.flags = !{!10}
38 !10 = !{i32 1, !"Debug Info Version", i32 2}
38 !10 = !{i32 1, !"Debug Info Version", i32 3}
1111 !llvm.dbg.cu = !{!0}
1212 !llvm.module.flags = !{!9}
1313
14 !0 = !{!"0x11\0012\00clang version 3.5 (trunk 195495) (llvm/trunk 195495:195504M)\000\00\000\00\000", !1, !2, !2, !3, !2, !2} ; [ DW_TAG_compile_unit ] [/Users/manmanren/llvm_gmail/release/../llvm/tools/clang/test/CodeGen/debug-info-version.c] [DW_LANG_C99]
15 !1 = !{!"../llvm/tools/clang/test/CodeGen/debug-info-version.c", !"/Users/manmanren/llvm_gmail/release"}
14 !0 = !MDCompileUnit(language: DW_LANG_C99, producer: "clang version 3.5 (trunk 195495) (llvm/trunk 195495:195504M)", isOptimized: false, emissionKind: 0, file: !1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
15 !1 = !MDFile(filename: "../llvm/tools/clang/test/CodeGen/debug-info-version.c", directory: "/Users/manmanren/llvm_gmail/release")
1616 !2 = !{i32 0}
1717 !3 = !{!4}
18 !4 = !{!"0x2e\00main\00main\00\003\000\001\000\006\00256\000\003", !1, !5, !6, null, i32 ()* @main, null, null, !2} ; [ DW_TAG_subprogram ] [line 3] [def] [main]
19 !5 = !{!"0x29", !1} ; [ DW_TAG_file_type ] [/Users/manmanren/llvm_gmail/release/../llvm/tools/clang/test/CodeGen/debug-info-version.c]
20 !6 = !{!"0x15\00\000\000\000\000\000\000", i32 0, null, null, !7, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
18 !4 = !MDSubprogram(name: "main", line: 3, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 3, file: !1, scope: !5, type: !6, function: i32 ()* @main, variables: !2)
19 !5 = !MDFile(filename: "../llvm/tools/clang/test/CodeGen/debug-info-version.c", directory: "/Users/manmanren/llvm_gmail/release")
20 !6 = !MDSubroutineType(types: !7)
2121 !7 = !{!8}
22 !8 = !{!"0x24\00int\000\0032\0032\000\000\005", null, null} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
22 !8 = !MDBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
2323 !9 = !{i32 2, !"Dwarf Version", i32 2}
2424 !12 = !MDLocation(line: 4, scope: !4)
2525
22
33 define void @Foo(i32 %a, i32 %b) {
44 entry:
5 call void @llvm.dbg.value(metadata i32* %1, i64 16, metadata !2, metadata !{!"0x102"})
5 call void @llvm.dbg.value(metadata i32* %1, i64 16, metadata !2, metadata !MDExpression())
66 ; CHECK: call void @llvm.dbg.value(metadata i32* %1, i64 16, metadata ![[ID2:[0-9]+]], metadata {{.*}})
77 %0 = add i32 %a, 1 ; [#uses=1]
88 %two = add i32 %b, %0 ; [#uses=0]
99 %1 = alloca i32 ; [#uses=1]
1010
11 call void @llvm.dbg.declare(metadata i32* %1, metadata i32* %1, metadata !{!"0x102"})
11 call void @llvm.dbg.declare(metadata i32* %1, metadata i32* %1, metadata !MDExpression())
1212 ; CHECK: call void @llvm.dbg.declare(metadata i32* %1, metadata i32* %1, metadata {{.*}})
13 call void @llvm.dbg.declare(metadata i32 %two, metadata i32 %0, metadata !{!"0x102"})
13 call void @llvm.dbg.declare(metadata i32 %two, metadata i32 %0, metadata !MDExpression())
1414 ; CHECK: call void @llvm.dbg.declare(metadata i32 %two, metadata i32 %0, metadata {{.*}})
15 call void @llvm.dbg.declare(metadata i32* %1, metadata i32 %b, metadata !{!"0x102"})
15 call void @llvm.dbg.declare(metadata i32* %1, metadata i32 %b, metadata !MDExpression())
1616 ; CHECK: call void @llvm.dbg.declare(metadata i32* %1, metadata i32 %b, metadata {{.*}})
17 call void @llvm.dbg.declare(metadata i32 %a, metadata i32 %a, metadata !{!"0x102"})
17 call void @llvm.dbg.declare(metadata i32 %a, metadata i32 %a, metadata !MDExpression())
1818 ; CHECK: call void @llvm.dbg.declare(metadata i32 %a, metadata i32 %a, metadata {{.*}})
19 call void @llvm.dbg.declare(metadata i32 %b, metadata i32 %two, metadata !{!"0x102"})
19 call void @llvm.dbg.declare(metadata i32 %b, metadata i32 %two, metadata !MDExpression())
2020 ; CHECK: call void @llvm.dbg.declare(metadata i32 %b, metadata i32 %two, metadata {{.*}})
2121
22 call void @llvm.dbg.value(metadata i32 %a, i64 0, metadata !1, metadata !{!"0x102"})
22 call void @llvm.dbg.value(metadata i32 %a, i64 0, metadata !1, metadata !MDExpression())
2323 ; CHECK: call void @llvm.dbg.value(metadata i32 %a, i64 0, metadata ![[ID1:[0-9]+]], metadata {{.*}})
24 call void @llvm.dbg.value(metadata i32 %0, i64 25, metadata !0, metadata !{!"0x102"})
24 call void @llvm.dbg.value(metadata i32 %0, i64 25, metadata !0, metadata !MDExpression())
2525 ; CHECK: call void @llvm.dbg.value(metadata i32 %0, i64 25, metadata ![[ID0:[0-9]+]], metadata {{.*}})
26 call void @llvm.dbg.value(metadata i32* %1, i64 16, metadata !3, metadata !{!"0x102"})
26 call void @llvm.dbg.value(metadata i32* %1, i64 16, metadata !3, metadata !MDExpression())
2727 ; CHECK: call void @llvm.dbg.value(metadata i32* %1, i64 16, metadata ![[ID3:[0-9]+]], metadata {{.*}})
28 call void @llvm.dbg.value(metadata !3, i64 12, metadata !2, metadata !{!"0x102"})
28 call void @llvm.dbg.value(metadata !3, i64 12, metadata !2, metadata !MDExpression())
2929 ; CHECK: call void @llvm.dbg.value(metadata ![[ID3]], i64 12, metadata ![[ID2]], metadata {{.*}})
3030
3131 ret void, !foo !0, !bar !1
3838 !1 = !{i32 4, !"foo"}
3939 !2 = !{!"bar"}
4040 !3 = !{!"foo"}
41 !4 = !{i32 1, !"Debug Info Version", i32 2}
41 !4 = !{i32 1, !"Debug Info Version", i32 3}
4242
4343 declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
4444 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) nounwind readnone
14421442 (* End-of-file checks for things like metdata and attributes.
14431443 * CHECK: attributes #0 = {{.*}}uwtable{{.*}}
14441444 * CHECK: !llvm.module.flags = !{!0}
1445 * CHECK: !0 = !{i32 1, !"Debug Info Version", i32 2}
1445 * CHECK: !0 = !{i32 1, !"Debug Info Version", i32 3}
14461446 * CHECK: !1 = !{i32 1, !"metadata test"}
14471447 * CHECK: !2 = !MDLocation(line: 2, column: 3, scope: !3, inlinedAt: !3)
14481448 *)
55
66 ; CHECK: call void @foo(), !dbg ![[LOC:[0-9]+]], !attach ![[CALL:[0-9]+]]
77 ; CHECK: ![[LOC]] = !MDLocation(line: 104, column: 105, scope: ![[SCOPE:[0-9]+]], inlinedAt: ![[SCOPE]])
8 ; CHECK: ![[SCOPE]] = !{!"0x11\000\00me\001\00\000\00\000", ![[FILE:[0-9]+]], ![[LIST:[0-9]+]], ![[LIST]], null, null, null}
9 ; CHECK: ![[FILE]] = !{!"source.c", !"/dir"}
8 ; CHECK: ![[SCOPE]] = !MDCompileUnit(language: 0, file: ![[FILE:[0-9]+]], producer: "me", isOptimized: true, runtimeVersion: 0, emissionKind: 0, enums: ![[LIST:[0-9]+]], retainedTypes: ![[LIST]])
9 ; CHECK: ![[FILE]] = !MDFile(filename: "source.c", directory: "/dir")
1010 ; CHECK: ![[LIST]] = !{i32 0}
1111 ; CHECK: ![[CALL]] = !{!"the call to foo"}
1212
3030 !3 = !{!"noise"}
3131 !4 = !{!"filler"}
3232
33 !9 = !{!"0x11\000\00me\001\00\000\00\000", !15, !16, !16, null, null, null} ; [ DW_TAG_compile_unit ]
33 !9 = !MDCompileUnit(language: 0, producer: "me", isOptimized: true, emissionKind: 0, file: !15, enums: !16, retainedTypes: !16)
3434 !10 = !MDLocation(line: 100, column: 101, scope: !9, inlinedAt: !9)
3535 !11 = !MDLocation(line: 102, column: 103, scope: !9, inlinedAt: !9)
3636 !12 = !MDLocation(line: 104, column: 105, scope: !9, inlinedAt: !9)
3737 !13 = !MDLocation(line: 106, column: 107, scope: !9, inlinedAt: !9)
3838 !14 = !MDLocation(line: 108, column: 109, scope: !9, inlinedAt: !9)
39 !15 = !{!"source.c", !"/dir"}