Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing debug information for constant read #11416

Closed
straight-shoota opened this issue Nov 8, 2021 · 5 comments · Fixed by #11417
Closed

Missing debug information for constant read #11416

straight-shoota opened this issue Nov 8, 2021 · 5 comments · Fixed by #11417
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:regression Something that used to correctly work but no longer works topic:compiler:codegen topic:compiler:debugger
Milestone

Comments

@straight-shoota
Copy link
Member

Latest 1.2.1

$ crystal --version
Crystal 1.2.1 [4e6c0f26e] (2021-10-21)

LLVM: 10.0.0
Default target: x86_64-unknown-linux-gnu

A simple source

$ cat false.cr 
STDERR.puts "false"
exit(1)

Another error with --debug

$ crystal build --debug false.cr
Module validation failed: inlinable function call in a function with debug info must have a !dbg location
  %57 = call %"IO::FileDescriptor"** @"~STDERR:read"()
 (Exception)
  from /crystal/src/int.cr:541:9 in 'finish'
  from /crystal/src/compiler/crystal/codegen/codegen.cr:69:7 in 'codegen'
  from /crystal/src/compiler/crystal/compiler.cr:169:16 in 'compile'
  from /crystal/src/compiler/crystal/command.cr:296:3 in 'run'
  from /crystal/src/compiler/crystal.cr:11:1 in '__crystal_main'
  from /crystal/src/crystal/main.cr:110:5 in 'main'
  from src/env/__libc_start_main.c:94:2 in 'libc_start_main_stage2'
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues

And it was the same with crystal 1.2.0 [9f90efe33] (2021-10-13)

Originally posted by @Val in #11385 (comment)

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:regression Something that used to correctly work but no longer works topic:compiler:debugger topic:compiler:codegen labels Nov 8, 2021
@straight-shoota
Copy link
Member Author

straight-shoota commented Nov 8, 2021

This is a regression introduced in #10934.

/cc @HertzDevil

@straight-shoota
Copy link
Member Author

Found another related bug, also introduced by #10934.

$ crystal build --debug samples/llvm/brainfuck.cr
Module validation failed: !dbg attachment points at wrong subprogram for function
!2261 = distinct !DISubprogram(name: "__crystal_main", linkageName: "__crystal_main", scope: !2262, file: !2262, type: !2263, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !2266)
void (i32, i8**)* @__crystal_main
  %56 = load %"Array(String)"*, %"Array(String)"** @ARGV, !dbg !2718
!2718 = !DILocation(line: 5, column: 19, scope: !2719)
!2719 = distinct !DISubprogram(name: "~LLVM::initialized:init", linkageName: "~LLVM::initialized:init", scope: !2720, file: !2720, line: 5, type: !2263, scopeLine: 5, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !2347)
!2719 = distinct !DISubprogram(name: "~LLVM::initialized:init", linkageName: "~LLVM::initialized:init", scope: !2720, file: !2720, line: 5, type: !2263, scopeLine: 5, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !2347)

@straight-shoota
Copy link
Member Author

Are reading constants and reading class vars the only locations where #10934 could've introduced a bug? I think so, but I'm not sure. Let's not miss something. What about external vars? Or any of the reads inside pointerof?

I'm also wondering why the missing debug locations don't show up more often. Stdlib is full of STDERR.puts and similar constant reads. But it appears to be only an issue in the main scope (put the constant read in a method and everything is fine). Recreating STDERR with a custom constant doesn't error either:

FOO = IO::FileDescriptor.from_stdio(2)
FOO.puts "foo"

@HertzDevil
Copy link
Contributor

The constant needs to be read before it is assigned, otherwise no lazy initialization is done. Presumably something in the prelude uses STDERR before kernel.cr is required.

If this indeed happens only at the top-level scope then class variable read calls cannot fail because they are no top-level class variables.

@straight-shoota
Copy link
Member Author

No, I mean the constant read happens in main scope. This code doesn't error:

def foo
  STDOUT.puts "false"
end

foo

Adding a read to STDOUT after the call to foo is fine as well. But before foo, it errors.

beta-ziliani pushed a commit that referenced this issue Nov 9, 2021
…11417)

Fixes #11416.

Although the constant read functions have a debug location, for some reason the calls themselves to the read functions do not. This PR adds them.
straight-shoota pushed a commit that referenced this issue Nov 9, 2021
…11417)

Fixes #11416.

Although the constant read functions have a debug location, for some reason the calls themselves to the read functions do not. This PR adds them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:regression Something that used to correctly work but no longer works topic:compiler:codegen topic:compiler:debugger
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants