Skip to content

Commit

Permalink
Avoid overflow in create_debug_types
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardiff committed Jan 11, 2019
1 parent c3fbfef commit 3f32aeb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/compiler/crystal/codegen/debug.cr
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module Crystal
end

def create_debug_type(type : FloatType)
di_builder.create_basic_type(type.to_s, type.bytes * 8, type.bytes * 8, LLVM::DwarfTypeEncoding::Float)
di_builder.create_basic_type(type.to_s, type.bytes &* 8, type.bytes &* 8, LLVM::DwarfTypeEncoding::Float)
end

def create_debug_type(type : BoolType)
Expand Down Expand Up @@ -98,17 +98,17 @@ module Crystal

ivars.each_with_index do |(name, ivar), idx|
if (ivar_type = ivar.type?) && (ivar_debug_type = get_debug_type(ivar_type))
offset = @program.target_machine.data_layout.offset_of_element(struct_type, idx + (type.struct? ? 0 : 1))
offset = @program.target_machine.data_layout.offset_of_element(struct_type, idx &+ (type.struct? ? 0 : 1))
size = @program.target_machine.data_layout.size_in_bits(llvm_embedded_type(ivar_type))
member = di_builder.create_member_type(nil, name[1..-1], nil, 1, size, size, offset * 8, LLVM::DIFlags::Zero, ivar_debug_type)
member = di_builder.create_member_type(nil, name[1..-1], nil, 1, size, size, offset &* 8, LLVM::DIFlags::Zero, ivar_debug_type)
element_types << member
end
end

size = @program.target_machine.data_layout.size_in_bits(struct_type)
debug_type = di_builder.create_struct_type(nil, type.to_s, nil, 1, size, size, LLVM::DIFlags::Zero, nil, di_builder.get_or_create_type_array(element_types))
unless type.struct?
debug_type = di_builder.create_pointer_type(debug_type, llvm_typer.pointer_size * 8, llvm_typer.pointer_size * 8, type.to_s)
debug_type = di_builder.create_pointer_type(debug_type, llvm_typer.pointer_size &* 8, llvm_typer.pointer_size &* 8, type.to_s)
end
di_builder.replace_temporary(tmp_debug_type, debug_type)
debug_type
Expand All @@ -117,7 +117,7 @@ module Crystal
def create_debug_type(type : PointerInstanceType)
element_type = get_debug_type(type.element_type)
return unless element_type
di_builder.create_pointer_type(element_type, llvm_typer.pointer_size * 8, llvm_typer.pointer_size * 8, type.to_s)
di_builder.create_pointer_type(element_type, llvm_typer.pointer_size &* 8, llvm_typer.pointer_size &* 8, type.to_s)
end

def create_debug_type(type : StaticArrayInstanceType)
Expand Down

3 comments on commit 3f32aeb

@asterite
Copy link
Member

Choose a reason for hiding this comment

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

Is it good to silently ignore these overflows?

@bcardiff
Copy link
Member Author

Choose a reason for hiding this comment

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

One of those are probably breaking the CI every now or then. I will give it a try, but the worst it will happen is to keep the same code we are using today, adding one more thing to review later.

@asterite
Copy link
Member

Choose a reason for hiding this comment

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

Sounds good, though I'd leave a TODO somewhere to check it later

Please sign in to comment.