Skip to content

[Debug info] Base sub-object of a derived variable is described with an empty !DIExpression() #8751

Description

@hbystuff

Version: dxcompiler.dll 1.9(5402-0d3ee6b5)(1.9.0.5402) - 1.9.0.5402 (0d3ee6b55-dirty)
Repro files: inheritance.zip

dxc -T cs_6_0 -Zi -Qembed_debug -Od -Fc inheritance.ll inheritance.hlsl
class Base
{
    int baseValue;
    void SetBase(int v)      { baseValue = v; }
};

class Derived : Base
{
    int derivedValue;
    void SetDerived(int v)   { derivedValue = v; }
    int  GetTotal()          { return baseValue + derivedValue; }
};

[numthreads(1, 1, 1)]
void main()
{
    Derived obj;                 // line 38
    obj.SetBase(input[0]);
    obj.SetDerived(input[1]);
    output[0] = obj.GetTotal();
}

The type metadata is correct. Derived is 64 bits, Base at offset 0 and
derivedValue at offset 32:

!8  = !DICompositeType(tag: DW_TAG_class_type, name: "Base",    file: !1, line: 10, size: 32, align: 32, elements: !9)
!17 = !DICompositeType(tag: DW_TAG_class_type, name: "Derived", file: !1, line: 20, size: 64, align: 32, elements: !18)
!19 = !DIDerivedType(tag: DW_TAG_inheritance, scope: !17, baseType: !8, flags: DIFlagPublic)
!20 = !DIDerivedType(tag: DW_TAG_member, name: "derivedValue", scope: !17, ..., size: 32, align: 32, offset: 32, flags: DIFlagPublic)

!69 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "obj", scope: !4, file: !1, line: 38, type: !17)   ; Derived

Actual

; obj.baseValue: the base sub-object
call void @llvm.dbg.value(metadata i32 %2, i64 0, metadata !69, metadata !62)   ; var:"obj" !DIExpression()

; obj.derivedValue
call void @llvm.dbg.value(metadata i32 %7, i64 0, metadata !69, metadata !78)   ; var:"obj" !DIExpression(DW_OP_bit_piece, 32, 32)

The write to the base part uses an empty !DIExpression(), which claims a
32-bit value is the whole 64-bit variable. The derived part correctly uses
bit_piece 32, 32.

The same shape appears for this in GetTotal, whose DILocalVariable also has
type Derived:

call void @llvm.dbg.value(metadata i32 %2, i64 0, metadata !66, metadata !62)   ; var:"this" !DIExpression()
call void @llvm.dbg.value(metadata i32 %7, i64 0, metadata !66, metadata !78)   ; var:"this" !DIExpression(DW_OP_bit_piece, 32, 32)

Separately, SetBase gets no dbg.value for its this at all. The only
this entries in the module are for SetDerived and GetTotal.

Expected

; Correct DIExpression
call void @llvm.dbg.value(metadata i32 %2, i64 0, metadata !69, metadata !<expr>)   ; var:"obj" !DIExpression(DW_OP_bit_piece, 0, 32)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug, regression, crashneeds-triageAwaiting triage

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions