]> git.ipfire.org Git - thirdparty/gcc.git/commit
PR modula2/118600 Assigning to a record causes alignment exception
authorGaius Mulley <gaiusmod2@gmail.com>
Thu, 20 Mar 2025 20:10:31 +0000 (20:10 +0000)
committerGaius Mulley <gaiusmod2@gmail.com>
Thu, 20 Mar 2025 20:10:31 +0000 (20:10 +0000)
commitd286ece094ca52f41bf71096aa1de0a0cd954dfb
treeb02c71507581cb171e5f9c51fcfde0ef57d6ee73
parent9e67a160553c7f06f32c5eb53867c935bc40510f
PR modula2/118600 Assigning to a record causes alignment exception

This patch recursively tests every assignment (of a constructor
to a designator) to ensure the types are GCC equivalent.  If they
are equivalent then it uses gimple assignment and if not then it
copies a structure by field and uses __builtin_strncpy to copy a
string cst into an array.  Unions are copied by __builtin_memcpy.

gcc/m2/ChangeLog:

PR modula2/118600
* gm2-compiler/M2GenGCC.mod (PerformCodeBecomes): New procedure.
(CodeBecomes): Refactor and call PerformCodeBecomes.
* gm2-gcc/m2builtins.cc (gm2_strncpy_node): New global variable.
(DoBuiltinStrNCopy): New function.
(m2builtins_BuiltinStrNCopy): New function.
(m2builtins_init): Initialize gm2_strncpy_node.
* gm2-gcc/m2builtins.def (BuiltinStrNCopy): New procedure
function.
* gm2-gcc/m2builtins.h (m2builtins_BuiltinStrNCopy): New
function.
* gm2-gcc/m2statement.cc (copy_record_fields): New function.
(copy_array): Ditto.
(copy_strncpy): Ditto.
(copy_memcpy): Ditto.
(CopyByField_Lower): Ditto.
(m2statement_CopyByField): Ditto.
* gm2-gcc/m2statement.def (CopyByField): New procedure function.
* gm2-gcc/m2statement.h (m2statement_CopyByField): New function.
* gm2-gcc/m2type.cc (check_record_fields): Ditto.
(check_array_types): Ditto.
(m2type_IsGccStrictTypeEquivalent): Ditto.
* gm2-gcc/m2type.def (IsGccStrictTypeEquivalent): New procedure
function.
* gm2-gcc/m2type.h (m2type_IsAddress): Replace return type int
with bool.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
gcc/m2/gm2-compiler/M2GenGCC.mod
gcc/m2/gm2-gcc/m2builtins.cc
gcc/m2/gm2-gcc/m2builtins.def
gcc/m2/gm2-gcc/m2builtins.h
gcc/m2/gm2-gcc/m2statement.cc
gcc/m2/gm2-gcc/m2statement.def
gcc/m2/gm2-gcc/m2statement.h
gcc/m2/gm2-gcc/m2type.cc
gcc/m2/gm2-gcc/m2type.def
gcc/m2/gm2-gcc/m2type.h