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

Don't emit debug info for unused variable declarations #10957

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions spec/compiler/codegen/debug_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ describe "Code gen: debug" do
), debug: Crystal::Debug::All)
end

it "doesn't emit debug info for unused variable declarations (#9882)" do
codegen(%(
x : Int32
), debug: Crystal::Debug::All)
end

it "stores and restores debug location after jumping to main (#6920)" do
codegen(%(
require "prelude"
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/crystal/codegen/debug.cr
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ module Crystal
return if @debug.none?
in_alloca_block do
vars.each do |name, var|
llvm_var = context.vars[name]
# If a variable is deduced to have type `NoReturn` it might not be
# allocated at all
next unless (llvm_var = context.vars[name]?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is totally optional, but I prefer the assignment and the condition to be split. Then the comment is only relevant to the condition, not the assignment.

next if llvm_var.debug_variable_created
set_current_debug_location var.location
declare_variable name, var.type, llvm_var.pointer, var.location, alloca_block
Expand Down