llvm-capstone/llvm
Yonghong Song 3eb465a329 [DebugInfo] Fix assertion for extern void type
Commit d77ae1552f ("[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
2020-06-08 13:43:18 -07:00
..
benchmarks
bindings
cmake [CMake] Do not append -lm to CMAKE_REQUIRED_LIBRARIES on Apple 2020-06-05 12:45:30 -04:00
docs [Docs] fix typos for llvm-mca; NFC 2020-06-07 11:14:24 -04:00
examples
include [XCOFF][AIX] report_fatal_error when an overflow section is needed 2020-06-08 19:59:04 +00:00
lib [DebugInfo] Fix assertion for extern void type 2020-06-08 13:43:18 -07:00
projects
resources
runtimes
test [DebugInfo] Fix assertion for extern void type 2020-06-08 13:43:18 -07:00
tools [SVE] Eliminate calls to default-false VectorType::get() from llvm-stress 2020-06-08 11:32:37 -07:00
unittests [SuffixTree][MachOpt] Factoring out Suffix Tree and adding Unit Tests 2020-06-08 12:44:18 -07:00
utils [gn build] Port bb677cacc8 2020-06-08 19:44:56 +00:00
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt Automatically configure MLIR when flang is enabled 2020-05-27 07:31:49 +00:00
CODE_OWNERS.TXT Add self as code owner for SCEV and IndVars 2020-05-26 17:35:54 -07:00
configure
CREDITS.TXT
LICENSE.TXT
llvm.spec.in
LLVMBuild.txt
README.txt
RELEASE_TESTERS.TXT

The LLVM Compiler Infrastructure
================================

This directory and its subdirectories contain source code for LLVM,
a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you are writing a package for LLVM, see docs/Packaging.rst for our
suggestions.