[DebugInfo] Fix assertion for extern void type
authorYonghong Song <yhs@fb.com>
Sat, 6 Jun 2020 01:37:38 +0000 (18:37 -0700)
committerYonghong Song <yhs@fb.com>
Mon, 8 Jun 2020 20:43:18 +0000 (13:43 -0700)
commit3eb465a329e2547a19848f978ce6c5cf85aff121
tree16b0bc3ffeee9c8f0d168decff35789771714d6e
parent39b3c41b65302a969fa5507402976a255a07c158
[DebugInfo] Fix assertion for extern void type

Commit d77ae1552fc2 ("[DebugInfo] Support to emit debugInfo
for extern variables") added support to emit debuginfo
for extern variables. Currently, only BPF target enables to
emit debuginfo for extern variables.

But if the extern variable has "void" type, the compilation will
fail.

  -bash-4.4$ cat t.c
  extern void bla;
  void *test() {
    void *x = &bla;
    return x;
  }
  -bash-4.4$ clang -target bpf -g -O2 -S t.c
  missing global variable type
  !1 = distinct !DIGlobalVariable(name: "bla", scope: !2, file: !3, line: 1,
                                  isLocal: false, isDefinition: false)
  ...
  fatal error: error in backend: Broken module found, compilation aborted!
  PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace,
      preprocessed source, and associated run script.
  Stack dump:
  ...

The IR requires a DIGlobalVariable must have a valid type and the
"void" type does not generate any type, hence the above fatal error.

Note that if the extern variable is defined as "const void", the
compilation will succeed.

-bash-4.4$ cat t.c
extern const void bla;
const void *test() {
  const void *x = &bla;
  return x;
}
-bash-4.4$ clang -target bpf -g -O2 -S t.c
-bash-4.4$ cat t.ll
...
!1 = distinct !DIGlobalVariable(name: "bla", scope: !2, file: !3, line: 1,
                                type: !6, isLocal: false, isDefinition: false)
!6 = !DIDerivedType(tag: DW_TAG_const_type, baseType: null)
...

Since currently, "const void extern_var" is supported by the
debug info, it is natural that "void extern_var" should also
be supported. This patch disabled assertion of "void extern_var"
in IR verifier and add proper guarding when emiting potential
null debug info type to dwarf types.

Differential Revision: https://reviews.llvm.org/D81131
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/IR/Verifier.cpp
llvm/test/DebugInfo/BPF/extern-void.ll [new file with mode: 0644]
llvm/test/DebugInfo/BPF/lit.local.cfg [new file with mode: 0644]