PB 5.73 - ReDim Array inside structure - IMA

Post bugreports for the Linux version here
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

PB 5.73 - ReDim Array inside structure - IMA

Post by StarBootics »

The following code is self explanatory.

Best regards
StarBootics

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : ReDim Array inside structure - IMA
; File Name : ReDim Array inside structure - IMA.pb
; File version: 1.0.0
; Programming : Bug Demonstrator
; Programmed by : StarBootics
; Date : 23-11-2021
; Last Update : 23-11-2021
; PureBasic code : 5.73 LTS
; Platform : Ubuntu 21.10 (Impish Indri) x86-64
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Bug Description :
;
; Apparently we can ReDim a multi-dimensions array calling
; ArraySize() instruction for the 1st dimensions without
; any problems.
;
; However if we try to do the same thing on an Array inside
; a structure we end up with an Invalid Memory Access
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Dim MyArray.l(5,5,5)

; This will work perfectly
ReDim MyArray(ArraySize(MyArray(), 1), ArraySize(MyArray(), 2), 10)

Structure MyStructure
  
  Array MyArray.l(5,5,5)
  
EndStructure 

Define MyVar.MyStructure

; This will work perfectly
D1 = ArraySize(MyVar\MyArray(), 1)
D2 = ArraySize(MyVar\MyArray(), 2)
ReDim MyVar\MyArray(D1, D2, 10)

; This will work perfectly
ReDim MyVar\MyArray(5, 5, 10)

; This will not work, IMA
ReDim MyVar\MyArray(ArraySize(MyVar\MyArray(), 1), ArraySize(MyVar\MyArray(), 2), 10)

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
The Stone Age did not end due to a shortage of stones !
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: PB 5.73 - ReDim Array inside structure - IMA

Post by StarBootics »

A little update about this problem since PB 6.00 Beta 1 has been released.

ASM Backend -> IMA
C Backend -> No problem

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
juergenkulow
Enthusiast
Enthusiast
Posts: 544
Joined: Wed Sep 25, 2019 10:18 am

Re: PB 5.73 - ReDim Array inside structure - IMA

Post by juergenkulow »

Code: Select all

; 2D ReDim and ArraySize IMA Windows and Linux 
Structure Struct 
  Array m.i(5,5)
EndStructure 

Define a.Struct
i=ArraySize(a\m(),1)
ReDim a\m(i,10)
ReDim a\m(ArraySize(a\m(),1),11)
; [16:32:42] Executable type: Windows - x64  (64bit, Unicode)
; [16:32:42] Executable started.
; [16:32:42] [ERROR] ReDim4.pb (Line: 9)
; [16:32:42] [ERROR] Invalid memory access. (Read error at address 18446744073709551568)

; ; ReDim a\m(ArraySize(a\m(),1),11)
;   LEA    rbp,[v_a]
;   PUSH   rbp
;   SUB    rsp,8
;   PUSH   qword 1
;   LEA    rbp,[v_a]
;   PUSH   rbp
;   MOV    rdx,[rsp+0]
;   POP    rax
;   PUSH   qword [rbp+0]
;   POP    rdi
;   POP    rsi
;   CALL   PB_ArraySize2
;   ADD    rsp,8
;   MOV    rdx,[rsp+-24]
;   MOV    qword [rdx+16],12
;   POP    rbp
;   MOV    rdx,[rsp+-32]
;   LEA    rsi,[rdx+0]
;   MOV    rdi,2
;   CALL   SYS_ReAllocateMultiArray

; RAX : 0000000000000005
; RBX : 000000000000000A
; RCX : 0000000000000002
; RDX : 0000000000211350     <---?
; RBP : 000000013FA74B38     redim4.000000013FA74B38
; RSP : 000000000014F710
; RSI : 0000000000000000
; RDI : 0000000000000000
; R8  : 000000000000000B
; R9  : 0000000000000020     ' '
; R10 : 000000013FA50000     "MZ"
; R11 : 000000013FA62075     redim4.000000013FA62075
; R12 : 0000000000000000
; R13 : 0000000000000000
; R14 : 0000000000000000
; R15 : 0000000000000000
; RIP : 000000013FA5112B     redim4.000000013FA5112B
; RFLAGS : 0000000000000202     L'Ȃ'

; 000000000014F680   000000000000000B   
; 000000000014F688   0000000000000042   
; 000000000014F690   0000000000000024   
; 000000000014F698   000000013FA74B38   redim4.000000013FA74B38
; 000000000014F6A0   0000000000211320   
; 000000000014F6A8   0000000000000008   
; 000000000014F6B0   000000013FA74B38   redim4.000000013FA74B38
; 000000000014F6B8   000000013FA52190   zurück zu redim4.000000013FA52190 von ???
; 000000000014F6C0   000000013FA74080   redim4.000000013FA74080
; 000000000014F6C8   0000000000000000   
; 000000000014F6D0   0000000000000000   
; 000000000014F6D8   0000000000000000   
; 000000000014F6E0   0000000000000000   
; 000000000014F6E8   0000000000000000   
; 000000000014F6F0   0000000000000000   
; 000000000014F6F8   000000013FA74B38   redim4.000000013FA74B38
; 000000000014F700   000000000000000A   
; 000000000014F708   000000013FA51130   zurück zu redim4.000000013FA51130 von redim4.000000013FA65340
; 000000000014F710   0000000000000024   
; 000000000014F718   0000000000211350   
; 000000000014F720   000000000000000B   
; 000000000014F728   0000000000000006   

; 0000000000211350  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................  

; 000000013FA65340                    | 48:895424 10                | mov qword ptr ss:[rsp+10],rdx                        |
; 000000013FA65345                    | 53                          | push rbx                                             |
; 000000013FA65346                    | 55                          | push rbp                                             |
; 000000013FA65347                    | 56                          | push rsi                                             |
; 000000013FA65348                    | 57                          | push rdi                                             |
; 000000013FA65349                    | 41:54                       | push r12                                             |
; 000000013FA6534B                    | 41:55                       | push r13                                             |
; 000000013FA6534D                    | 41:56                       | push r14                                             |
; 000000013FA6534F                    | 41:57                       | push r15                                             |
; 000000013FA65351                    | 48:83EC 48                  | sub rsp,48                                           |
; 000000013FA65355                    | 4C:8B2A                     | mov r13,qword ptr ds:[rdx]                           | r13=0 RDX : 0000000000211350 
; 000000013FA65358                    | 4C:8BFA                     | mov r15,rdx                                          |
; 000000013FA6535B                    | 4C:63F1                     | movsxd r14,ecx                                       |
; 000000013FA6535E                    | BF 01000000                 | mov edi,1                                            |
; 000000013FA65363                    | 49:8D45 D0                  | lea rax,qword ptr ds:[r13-30]                        | qword ptr ds:[r13-30]=[FFFFFFFFFFFFFFD0]=???
; 
Post Reply