DIGlobalVariableExpression doc in langref

Hi,

I don't find DIGlobalVariableExpression in langref. Should it be
documented? Could anybody explain what it is?

https://llvm.org/docs/LangRef.html

In one ll file converted from bitcode, I mostly see something like this.

!8273 = !DIGlobalVariableExpression(var: !8274, expr: !DIExpression())

Only one looks like this.

!8945 = !DIGlobalVariableExpression(var: !8946, expr:
!DIExpression(DW_OP_constu, 44, DW_OP_stack_value))

Why DIExpression is mostly empty?

Adrian - looks like LangRef didn’t get updated when DIGlobalVariableExpression was introduced - could you add a little info there?

Peng - yeah, looks like the documentation is a bit out of date, no worries.

DIGlobalVariableExpressions are referenced from LLVM global variables, eg:

@x = dso_local global i32 3, align 4, !dbg !0
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())

One where there is an empty DIExpression means that the underlying LLVM IR global describes the whole source level global variable - the value doesn’t need to be modified at all to represent the source variable.

If an expression is involved, that expression (possibly along with the underlying LLVM IR global variable) is used to compute the value of the source level global variable. (in the example you have - there may not be any LLVM IR global variable at all - just the expression computing the constant value of the source level global variable - but in other cases, say if a big constant that only holds a few different values is optimized into a lookup table (rather than storing a big integer, just store 0 or 1, if it’s 0 that means teh value is XXXXXXX, if the value is 1 that means the value is YYYYYY) it might be a combination, using the LLVM IR global variable to compute the source level value)

Hi David,

If an expression is involved, that expression (possibly along with the underlying LLVM IR global variable) is used to compute the value of the source level global variable. (in the example you have - there may not be any LLVM IR global variable at all - just the expression computing the constant value of the source level global variable - but in other cases, say if a big constant that only holds a few different values is optimized into a lookup table (rather than storing a big integer, just store 0 or 1, if it's 0 that means teh value is XXXXXXX, if the value is 1 that means the value is YYYYYY) it might be a combination, using the LLVM IR global variable to compute the source level value)

Do you have an example minimal .c file that can demonstrate this in
action? This will make it easier to understand what you mean.

I don’t have an example from C code, but here’s one from LLVM IR: https://github.com/earl/llvm-mirror/blob/master/test/Transforms/GlobalMerge/debug-info.ll

Done in r351837.

-- adrian