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

codegen: fix bug with String egal test #31585

Merged
merged 2 commits into from
Apr 3, 2019
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
2 changes: 1 addition & 1 deletion base/strings/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ end
function ==(a::String, b::String)
pointer_from_objref(a) == pointer_from_objref(b) && return true
al = sizeof(a)
return al == sizeof(b) && 0 == ccall(:memcmp, Int32, (Ptr{UInt8}, Ptr{UInt8}, UInt), a, b, al)
return al == sizeof(b) && 0 == ccall(:memcmp, Int32, (Ptr{UInt8}, Ptr{UInt8}, UInt), a, b, al % UInt)
end

typemin(::Type{String}) = ""
Expand Down
11 changes: 7 additions & 4 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2388,7 +2388,13 @@ static Value *emit_f_is(jl_codectx_t &ctx, const jl_cgval_t &arg1, const jl_cgva
int ptr_comparable = 0; // whether this type is unique'd by pointer
if (rt1 == (jl_value_t*)jl_sym_type || rt2 == (jl_value_t*)jl_sym_type)
ptr_comparable = 1;
if (jl_is_mutable_datatype(rt1) || jl_is_mutable_datatype(rt2)) // excludes abstract types
if (jl_is_mutable_datatype(rt1) && // excludes abstract types
rt1 != (jl_value_t*)jl_string_type && // technically mutable, but compared by contents
rt1 != (jl_value_t*)jl_simplevector_type)
ptr_comparable = 1;
if (jl_is_mutable_datatype(rt2) && // excludes abstract types
rt2 != (jl_value_t*)jl_string_type && // technically mutable, but compared by contents
rt2 != (jl_value_t*)jl_simplevector_type)
ptr_comparable = 1;
if (jl_subtype(rt1, (jl_value_t*)jl_type_type) ||
jl_subtype(rt2, (jl_value_t*)jl_type_type)) {
Expand All @@ -2400,9 +2406,6 @@ static Value *emit_f_is(jl_codectx_t &ctx, const jl_cgval_t &arg1, const jl_cgva
ptr_comparable = 1;
}
}
if ((rt1 == (jl_value_t*)jl_string_type && rt2 == (jl_value_t*)jl_string_type) ||
(rt1 == (jl_value_t*)jl_simplevector_type && rt2 == (jl_value_t*)jl_simplevector_type))
ptr_comparable = 0; // technically mutable, but compared by contents
if (ptr_comparable) {
Value *varg1 = arg1.constant ? literal_pointer_val(ctx, arg1.constant) : arg1.V;
Value *varg2 = arg2.constant ? literal_pointer_val(ctx, arg2.constant) : arg2.V;
Expand Down
7 changes: 7 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5828,6 +5828,13 @@ for U in boxedunions
end
end

# issue 31583
a31583 = "a"
f31583() = a31583 === "a"
@test f31583()
a31583 = "b"
@test !f31583()

# unsafe_wrap
let
A4 = [1, 2, 3]
Expand Down