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) ...
It might be the expected behavior not to generate debuginfo for
extern "void" variables. But the fatal error (with assert on) is not
nice.
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.