Skip to content

Commit

Permalink
Compiler: sizeof(Bool) must be 1, not 0 (#8273)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Oct 5, 2019
1 parent 7a1112c commit 0bb318e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/compiler/codegen/sizeof_spec.cr
Expand Up @@ -95,6 +95,10 @@ describe "Code gen: sizeof" do
run("sizeof(Nil)").to_i.should eq(0)
end

it "gets sizeof Bool (#8272)" do
run("sizeof(Bool)").to_i.should eq(1)
end

it "can use sizeof in type argument (1)" do
run(%(
struct StaticArray
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/crystal/codegen/codegen.cr
Expand Up @@ -85,6 +85,9 @@ module Crystal
# `Pointer(Void).malloc` must work like `Pointer(UInt8).malloc`,
# that is, consider Void like the size of a byte.
1
elsif type.is_a?(BoolType)
# LLVM reports 0 for bool (i1) but it must be 1 because it does occupy memory
1
else
llvm_typer.size_of(llvm_typer.llvm_type(type))
end
Expand Down

0 comments on commit 0bb318e

Please sign in to comment.