[DebugInfo]: Representing constants in debug-info

Hi Everyone,

Is there a way of representing constants in LLVM debug-info ? Languages such as FORTRAN has constants

i.e, consider the following Fortran snippet

[…]

Module foo

Integer, parameter :: bar = 200 ! Constant

End module foo

[…]

A front-end may choose to emit as Global Constant in LLVM IR as:

[…]

@bar… = internal constant i32 200

A naïve attempt to represent it as GlobalVariable(or constant) as

[…]

!7 = !DIGlobalVariableExpression(var: !8, expr: !DIExpression(DW_OP_consts, 200))

!8 = distinct !DIGlobalVariable(name: “bar”, scope: !2, file: !3, line: 3, type: !9, isLocal: false, isDefinition: true)

This will materialize in DWARF as:

0x0000004a: DW_TAG_variable

DW_AT_name (“bar”)

DW_AT_location (DW_OP_addr 0x2007d4, DW_OP_consts +200) // This is incorrect, pointing to data section

[…]

Gfortran is representing this as: DW_TAG_constant
0x00000055: DW_TAG_constant

DW_AT_name (“bar”)

DW_AT_type (0x0000006a “const integer(kind=4)”)

DW_AT_external (true)

DW_AT_const_value (0xc8)

Do we have Metadata analog of (DW_TAG_constant) ? I think the primary question here is to how represent this ?

Any inputs appreciated!

Thanks… much!
Sourabh.

I don’t see any use of DW_TAG_constant in the LLVM tree, except in the DWARFLinker, which isn’t what you need.

Most things not needed by C-family languages aren’t supported, because to date nobody has needed them (or if they did, they implemented the support downstream). The closest similar thing would be enumerator constants; you could probably imitate what’s done for those fairly easily.

–paulr

[AMD Public Use]

Hi Paul,

Thanks for the hints for a possible implementation by mimicking something close to Enumerations. I noticed 2 problems doing so:

Hi Sourabh,

Just from reading the commit messages you quoted, I can guess what happened: Trying to use DW_TAG_constant for a single-valued variable, when in the C family this should be a DW_TAG_variable (presumably with a const type) and ideally DW_AT_const_value.

I think you should proceed with the plan to introduce DIConstant, as Flang is not the only Fortran compiler planning to use LLVM and Fortran is not the only language that has true constants. And if we can fix the scoping issues with enumerations along the way, so much the better!

Thanks,

–paulr