facebookexperimental/object-introspection

References are codegenned as pointers

Opened this issue · 0 comments

References in the original code become pointers once through codegen. We can't differentiate references from pointers, and therefore can't assume that references are always valid. This means that we require the --chase-raw-pointers flag for references when it shouldn't be necessary.

Code in base code (test case OidIntegration.references_int_ref):

struct IntRef {
  int &n;
};

Code in generated code:

struct IntRef{
/* 8         |     8 */int* n;
};

Further testing:

$ cat test.cc
struct Foo {
  int& a;
  int *b;
};

int main() {
  int x;
  Foo foo{ .a = x, .b = &x };
}
$ g++ -g test.cc && llvm-dwarfdump a.out
...
0x00000051:   DW_TAG_reference_type
                DW_AT_byte_size (0x08)
                DW_AT_type      (0x00000057 "int")
...
0x0000005e:   DW_TAG_pointer_type
                DW_AT_byte_size (0x08)
                DW_AT_type      (0x00000057 "int")
...

So there is enough information in the DWARF to generate the original example correctly. However we see that the drgn support for references doesn't differentiate them (added here). Therefore we can't support this without first supporting it in drgn.