llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.19k stars 12.04k forks source link

ICE when compiling with -g3 at -O0 #51825

Open theo-lw opened 3 years ago

theo-lw commented 3 years ago
Bugzilla Link 52483
Version trunk
OS All
CC @chengniansun,@topperc,@dwblaikie,@jmorse,@RKSimon,@pogo59,@phoebewang,@rotateright

Extended Description

The following program compiles at -O0 without -g3, but ICE's when you add the -g3 flag.

$ clang-trunk -v
clang version 14.0.0 (https://github.com/llvm/llvm-project.git 3330a6670ee8d725f16c61fa127ba93613f1fc1f)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/cnsun/usr/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
$
$ cat line_program-234c9c.c
a() {
  for (;; 1)
# 0
  {
  }
}
main() {}
$
$ clang-trunk -w -O0 -g3 line_program-234c9c.c
cannot have column info without line info
!15 = distinct !DILexicalBlock(scope: !16, file: !1, column: 3)
cannot have column info without line info
!15 = distinct !DILexicalBlock(scope: !16, file: !1, column: 3)
fatal error: error in backend: Broken module found, compilation aborted!
clang-14: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 14.0.0 (https://github.com/llvm/llvm-project.git 3330a6670ee8d725f16c61fa127ba93613f1fc1f)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/cnsun/usr/bin
clang-14: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-14: note: diagnostic msg: /tmp/line_program-234c9c-56d2f2.c
clang-14: note: diagnostic msg: /tmp/line_program-234c9c-56d2f2.sh
clang-14: note: diagnostic msg:

********************
$
$ clang-trunk -w -O0 line_program-234c9c.c
$
dwblaikie commented 3 years ago

(also, why are we complaining about the decl line/column on a lexical scope? We don't emit them anyway - perhaps we should remove them?)

We emit them sometimes... if there's a local declaration. The front-end would have to notice whether there are any locals, in order to suppress the unnecessarily lexical scopes.

Sorry, I meant we don't emit the line/file of lexical scopes (I get that we emit lexical scopes - if they contain variables, etc, but we don't seem to ever put a file/line/column on those)

https://github.com/llvm/llvm-project/blob/f0d997c4723214f5bc098b0acd2e61f3215d4a49/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp#L696

pogo59 commented 3 years ago

(also, why are we complaining about the decl line/column on a lexical scope? We don't emit them anyway - perhaps we should remove them?)

We emit them sometimes... if there's a local declaration. The front-end would have to notice whether there are any locals, in order to suppress the unnecessarily lexical scopes.

dwblaikie commented 3 years ago

Yeah, /probably/ should just relax the verifier and allow this - GCC seems fine with using line 0 if the user asked for it like this.

(also, why are we complaining about the decl line/column on a lexical scope? We don't emit them anyway - perhaps we should remove them?)

phoebewang commented 3 years ago

I think this is a front end issue. It crashes with -emit-llvm.

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-frontend