Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • sac2c sac2c
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 402
    • Issues 402
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 15
    • Merge requests 15
  • Deployments
    • Deployments
    • Releases
  • Wiki
    • Wiki
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • sac-group
  • sac2csac2c
  • Issues
  • #2515
Closed
Open
Created Nov 11, 2025 by Thomas Koopman@thomasDeveloper

The struct wrappers generated by the FFI generate code where arrays of size 0 are allocated (?)

I have a guess at what the problem is and how to fix this, but I have not worked in this area of the compiler before. @sbs can you confirm this makes sense? Then I will implement the fix.

Bug

(From Stdlib Vector3f)

In the function SACf_Vector3f__wrap__struct_Vector3f__sa_S__sa_S__sa_S, we generate code that allocates an AKS of size 0:

    SAC_ND_ALLOC_BEGIN((SACp_emal_5145__ggtc_943, (AKS, (NHD, (NUQ, (INT, (GLO, (NON, (NOT, (OTH, ))))))))), 1, 1, SACarg *)

and the compiler rightfully complains that malloc(0) is implementation-defined behaviour. If it is intended that this array has size 0, we should set it to NULL.

Proposed fix

We can insert a check (SAC_ND_A_SIZE (var_NT) == NULL) as in the AKS case, the C-compiler knows statically that this is 0 and will optimize the check away.

I think this variable comes from generate_generic_type_conversions.c:

        /* Here, we build the standard variant:
         *
         *external
         * SACarg(---) <ns>::wrap_<name> (<ns>::<name>[*] arg);
         * #pragma linkname "SACARGwrap_<ns>__<name>"
         * #pragma linksign [1,2]
         */
        argtype = TYmakeAUD (TYcopyType (TYgetScalar (type)));
        rettype = TYmakeAKS (TYmakeSacargSimpleType (UT_NOT_DEFINED),
                             SHmakeShape (0));

which does suggest it is intended.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking