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

Invalid memory access in Array#push #8594

Closed
vlazar opened this issue Dec 17, 2019 · 8 comments
Closed

Invalid memory access in Array#push #8594

vlazar opened this issue Dec 17, 2019 · 8 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. status:duplicate topic:compiler

Comments

@vlazar
Copy link
Contributor

vlazar commented Dec 17, 2019

Array#push fails

ary=[] of UInt32
p! ary.push(3)

Output

Invalid memory access (signal 11) at address 0x0
[0x55d1aecf1b06] *CallStack::print_backtrace:Int32 +118
[0x55d1aece4981] __crystal_sigfault_handler +209
[0x7f42fe0ad930] ???
[0x0] ???

Array#<< works

ary=[] of UInt32
p! ary << 3 # => [3]

Note however that locally I have this error instead for Array#push:

ary=[] of UInt32
p! ary.push(3) # => Program received and didn't handle signal ILL (4)
Crystal 0.32.0 on MacOS
$ crystal --version
Crystal 0.32.0 (2019-12-12)

LLVM: 9.0.0
Default target: x86_64-apple-macosx

The behavior changed many times in previous versions of Crystal. Although I'm not sure if I can trust playground.

In Crystal 0.24.2 both Array#push and Array#<< gives no overload matches error.

Since Crystal 0.25.0 Array#push is broken and Array#<< works.

Since Crystal 0.27.0 Array#push gives ambiguous call, implicit cast of 3 matches all of UInt32 and Array#<< works.

SInce Crystal 0.29.0 Array#push gives Program received and didn't handle signal SYS (31) and Array#<< works.

SInce Crystal 0.31.0 Array#push gives Invalid memory access and Array#<< works.

@vlazar
Copy link
Contributor Author

vlazar commented Dec 17, 2019

Seem to be related to #6074 #6618 and #7747

@vlazar
Copy link
Contributor Author

vlazar commented Dec 17, 2019

Only Int32 is working with Array#push

# ary=[] of UInt64
# p! ary.push(3) # => Program received and didn't handle signal ILL (4)

# ary=[] of UInt32
# p! ary.push(3) # => Program received and didn't handle signal ILL (4)

# ary=[] of UInt16
# p! ary.push(3) # => Program received and didn't handle signal ILL (4)

# ary=[] of UInt8
# p! ary.push(3) # => Program received and didn't handle signal ILL (4)

# ary=[] of Int64
# p! ary.push(3) # => Program received and didn't handle signal ILL (4)

ary=[] of Int32
p! ary.push(3) # => [3]

# ary=[] of Int16
# p! ary.push(3) # => Program received and didn't handle signal ILL (4)

# ary=[] of Int8
# p! ary.push(3) # => Program received and didn't handle signal ILL (4)
Crystal 0.32.0 on MacOS
$ crystal --version
Crystal 0.32.0 (2019-12-12)

LLVM: 9.0.0
Default target: x86_64-apple-macosx

@asterite
Copy link
Member

It seems to be a bug with autocasting. It works fine if you do push(3_u32).

@jhass jhass added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler labels Dec 17, 2019
@vlazar
Copy link
Contributor Author

vlazar commented Dec 17, 2019

BTW, is that by design that Array#push has overloads for single value and multiple values, but Array#<< works only for single value?

Should't there be this variant too?

class Array(T)
  def <<(*values : T)
   push(*values)
  end
end

Then Array#<< will fail as Array#push in this issue.

@asterite
Copy link
Member

asterite commented Dec 17, 2019

@vlazar the syntax doesn't allow calling << with multiple arguments, unless you do a.<<(1, 2, 3), but for that you can use push.

@vlazar
Copy link
Contributor Author

vlazar commented Dec 17, 2019

@asterite Thanks. Yeah, that was my though. I just wanted to be sure it was not forgotten, but deliberately not added in the first place.

@RX14
Copy link
Contributor

RX14 commented Dec 19, 2019

I'm certain this is #8217. If it is, close for dupe?

@asterite
Copy link
Member

Duplicate of #8217

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. status:duplicate topic:compiler
Projects
None yet
Development

No branches or pull requests

4 participants