From: Gaius Mulley Date: Tue, 2 Jun 2026 11:14:51 +0000 (+0100) Subject: PR modula2/125544: ISO reallocate does not call allocate if the address is NIL X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=23229bea30efc917bdb0d65cc6bffade0d2017ea;p=thirdparty%2Fgcc.git PR modula2/125544: ISO reallocate does not call allocate if the address is NIL This bugfix is for the ISO Storage.REALLOCATE procedure which is a GNU extension. It should behave in the same way as the PIM version by first checking whether the pointer parameter is NIL and then calling ALLOCATE. gcc/m2/ChangeLog: PR modula2/125544 * gm2-libs-iso/Storage.def (REALLOCATE): Updated comment describing new behavior. * gm2-libs-iso/Storage.mod (REALLOCATE): Check addr and call ALLOCATE if NIL else call lowerReallocate. (lowerReallocate): New procedure. Signed-off-by: Gaius Mulley --- diff --git a/gcc/m2/gm2-libs-iso/Storage.def b/gcc/m2/gm2-libs-iso/Storage.def index 24bf8537896..586fb20ae67 100644 --- a/gcc/m2/gm2-libs-iso/Storage.def +++ b/gcc/m2/gm2-libs-iso/Storage.def @@ -28,7 +28,8 @@ PROCEDURE DEALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL); *) PROCEDURE REALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL); - (* Attempts to reallocate, amount of storage. Effectively it + (* If addr is NIL then ALLOCATE is called otherwise it + attempts to reallocate amount of storage. Effectively it calls ALLOCATE, copies the amount of data pointed to by addr into the new space and DEALLOCATES the addr. This procedure is a GNU extension. diff --git a/gcc/m2/gm2-libs-iso/Storage.mod b/gcc/m2/gm2-libs-iso/Storage.mod index 4f853bf2fcf..153386b96dc 100644 --- a/gcc/m2/gm2-libs-iso/Storage.mod +++ b/gcc/m2/gm2-libs-iso/Storage.mod @@ -89,17 +89,18 @@ BEGIN END DEALLOCATE ; -PROCEDURE REALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL); - (* Attempts to reallocate, amount of storage. Effectively it - calls ALLOCATE, copies the amount of data pointed to by - addr into the new space and DEALLOCATES the addr. - This procedure is a GNU extension. - *) +(* + LowerReallocate - attempts to reallocate amount of storage by + calling ALLOCATE and then coping the amount of data + pointed to by addr into the new space. + Lastly the original addr is deallocated. +*) + +PROCEDURE LowerReallocate (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL) ; VAR newa: SYSTEM.ADDRESS ; n : CARDINAL ; BEGIN - assert (initialized) ; IF NOT IsIn (storageTree, addr) THEN RAISE (storageException, ORD(pointerToUnallocatedStorage), @@ -115,6 +116,24 @@ BEGIN END ; DEALLOCATE(addr, n) ; addr := newa +END LowerReallocate ; + + +PROCEDURE REALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL); + (* If addr is NIL then ALLOCATE is called otherwise it + attempts to reallocate amount of storage. Effectively it + calls ALLOCATE, copies the amount of data pointed to by + addr into the new space and DEALLOCATES the addr. + This procedure is a GNU extension. + *) +BEGIN + assert (initialized) ; + IF addr = NIL + THEN + ALLOCATE (addr, amount) + ELSE + LowerReallocate (addr, amount) + END END REALLOCATE ;