diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 61ce3b5a891e3b..a8ae35c62a75f0 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -1916,12 +1916,13 @@ static jl_cgval_t typed_load(jl_codectx_t &ctx, Value *ptr, Value *idx_0based, j Value *fld0 = ctx.builder.CreateStructGEP(elty, data, 0); LoadInst *load0 = ctx.builder.CreateAlignedLoad(elty->getStructElementType(0), fld0, Align(alignment), false); load0->setOrdering(Order); - maybe_mark_load_dereferenceable(load0, true, sizeof(void*)*2, alignof(void*)); jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, tbaa); ai.scope = MDNode::concatenate(aliasscope, ai.scope); ai.decorateInst(load0); Value *fld1 = ctx.builder.CreateStructGEP(elty, data, 1); LoadInst *load1 = ctx.builder.CreateAlignedLoad(elty->getStructElementType(1), fld1, Align(alignment), false); + static_assert(offsetof(jl_genericmemoryref_t, data) == 0, "wrong field order"); + maybe_mark_load_dereferenceable(load1, true, sizeof(void*)*2, alignof(void*)); load1->setOrdering(Order); ai.decorateInst(load1); instr = Constant::getNullValue(elty); diff --git a/stdlib/Mmap/src/Mmap.jl b/stdlib/Mmap/src/Mmap.jl index 9dd02d5aa9d040..6d328c40cd7b3f 100644 --- a/stdlib/Mmap/src/Mmap.jl +++ b/stdlib/Mmap/src/Mmap.jl @@ -367,8 +367,9 @@ Forces synchronization between the in-memory version of a memory-mapped `Array` [`BitArray`](@ref) and the on-disk version. """ function sync!(m::Array, flags::Integer=MS_SYNC) - offset = rem(UInt(pointer(m)), PAGESIZE) - ptr = pointer(m) - offset + ptr = pointer(m) + offset = rem(UInt(ptr), PAGESIZE) + ptr = ptr - offset mmaplen = sizeof(m) + offset GC.@preserve m @static if Sys.isunix() systemerror("msync", @@ -429,8 +430,9 @@ Advises the kernel on the intended usage of the memory-mapped `array`, with the `flag` being one of the available `MADV_*` constants. """ function madvise!(m::Array, flag::Integer=MADV_NORMAL) - offset = rem(UInt(pointer(m)), PAGESIZE) - ptr = pointer(m) - offset + ptr = pointer(m) + offset = rem(UInt(ptr), PAGESIZE) + ptr = ptr - offset mmaplen = sizeof(m) + offset GC.@preserve m begin systemerror("madvise", diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 2489b1503b3bdb..3a57fdb4e5f905 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -1562,32 +1562,43 @@ end f_typeof_tfunc(x) = typeof(x) @test Base.return_types(f_typeof_tfunc, (Union{<:T, Int} where T<:Complex,)) == Any[Union{Type{Int}, Type{Complex{T}} where T<:Real}] -# memoryref, memoryrefget_tfunc / memoryrefset_tfunc -import Core.Compiler: Const +# memoryref_tfunc, memoryrefget_tfunc, memoryrefset_tfunc let memoryref_tfunc(@nospecialize xs...) = Core.Compiler.memoryref_tfunc(Core.Compiler.fallback_lattice, xs...) memoryrefget_tfunc(@nospecialize xs...) = Core.Compiler.memoryrefget_tfunc(Core.Compiler.fallback_lattice, xs...) memoryrefset_tfunc(@nospecialize xs...) = Core.Compiler.memoryrefset_tfunc(Core.Compiler.fallback_lattice, xs...) @test memoryref_tfunc(Memory{Int}) == MemoryRef{:not_atomic, Int} @test memoryref_tfunc(Memory{Integer}) == MemoryRef{:not_atomic, Integer} @test memoryref_tfunc(MemoryRef{:not_atomic, Int}, Int) == MemoryRef{:not_atomic, Int} - @test_broken memoryref_tfunc(Memory{Int}, Int) == MemoryRef{:not_atomic, Int} + @test memoryref_tfunc(MemoryRef{:not_atomic, Int}, Int, Symbol) == Union{} + @test memoryref_tfunc(MemoryRef{:not_atomic, Int}, Int, Bool) == MemoryRef{:not_atomic, Int} + @test memoryref_tfunc(Memory{Int}, Int) == Union{} + @test memoryref_tfunc(Any, Any, Any) == Any # TODO: make this MemoryRef? + @test memoryref_tfunc(Any, Any) == Any # TODO: make this MemoryRef? + @test memoryref_tfunc(Any) == MemoryRef @test memoryrefget_tfunc(MemoryRef{:not_atomic, Int}, Symbol, Bool) === Int - @test memoryrefget_tfunc(MemoryRef{:not_atomic, <:Integer}, Symbol, Bool) === Integer + @test memoryrefget_tfunc(MemoryRef{:not_atomic, Int}, Any, Any) === Int + @test memoryrefget_tfunc(MemoryRef{:not_atomic,<:Integer}, Symbol, Bool) === Integer @test memoryrefget_tfunc(MemoryRef, Symbol, Bool) === Any + @test memoryrefget_tfunc(MemoryRef{:not_atomic}, Symbol, Bool) === Any @test memoryrefget_tfunc(Vector{Int}, Symbol, Bool) === Union{} @test memoryrefget_tfunc(String, Symbol, Bool) === Union{} - @test_throws MethodError memoryrefget_tfunc(MemoryRef{:not_atomic, Int}, Int, Int, Symbol, Bool) === Union{} + @test memoryrefget_tfunc(MemoryRef{:not_atomic, Int}, String, Bool) === Union{} + @test memoryrefget_tfunc(MemoryRef{:not_atomic, Int}, Symbol, String) === Union{} + @test memoryrefget_tfunc(Any, Any, Any) === Any @test memoryrefset_tfunc(MemoryRef{:not_atomic, Int}, Int, Symbol, Bool) === MemoryRef{:not_atomic, Int} - let ua = MemoryRef{:not_atomic, <:Integer} + let ua = MemoryRef{:not_atomic,<:Integer} @test memoryrefset_tfunc(ua, Int, Symbol, Bool) === ua end @test memoryrefset_tfunc(MemoryRef, Int, Symbol, Bool) === MemoryRef + @test memoryrefset_tfunc(MemoryRef{:not_atomic}, Int, Symbol, Bool) === MemoryRef{:not_atomic} @test memoryrefset_tfunc(Any, Int, Symbol, Bool) === Any - @test_throws MethodError memoryrefset_tfunc(MemoryRef{:not_atomic, String}, Symbol, Bool) === Union{} + @test memoryrefset_tfunc(MemoryRef{:not_atomic, String}, Int, Symbol, Bool) === Union{} @test memoryrefset_tfunc(String, Char, Symbol, Bool) === Union{} - @test memoryrefset_tfunc(MemoryRef{:not_atomic, Int}, Float64, Symbol, Bool) === Union{} - @test_throws MethodError memoryrefset_tfunc(MemoryRef{:not_atomic, Int}, Int, Int, Symbol, Bool) === Union{} - @test memoryrefset_tfunc(MemoryRef{:not_atomic, Int}, Float64, Symbol, Bool) === Union{} + @test memoryrefset_tfunc(MemoryRef{:not_atomic, Int}, Any, Symbol, Bool) === MemoryRef{:not_atomic, Int} + @test memoryrefset_tfunc(MemoryRef{:not_atomic, Int}, Any, Any, Any) === MemoryRef{:not_atomic, Int} + @test memoryrefset_tfunc(MemoryRef{:not_atomic}, Any, Any, Any) === MemoryRef{:not_atomic} + @test memoryrefset_tfunc(MemoryRef, Any, Any, Any) === MemoryRef + @test memoryrefset_tfunc(Any, Any, Any, Any) === Any # TODO: make this MemoryRef? end let tuple_tfunc(@nospecialize xs...) =