Skip to content

Compiler warnings arising from use of stack-allocated temporary FB instances #8

@DavidHopkinsFbr

Description

@DavidHopkinsFbr

Hi,

When I build projects that use TcMatrix I often get a fair few warnings like these:
image

I've seen these in TwinCAT 3.1.4024.17, .29, and .44.

In case the image doesn't upload properly, here's a text version:

Severity	Code	Description	Project	File	Line	Suppression State
Warning		Compatibility warning: FB_Exit is now called in Vector_CrossProduct for FB instance M_Vectors which is located on the stack. This has not been the case for code compiled with compiler versions < 3.1.4022.0. [tcmatrix, 1.4.3 (burks engineering)]		Vector_CrossProduct	0	
Warning		Compatibility warning: FB_Exit is now called in Grow for FB instance Temp which is located on the stack. This has not been the case for code compiled with compiler versions < 3.1.4022.0. [tcmatrix, 1.4.3 (burks engineering)]		DynamicMatrix.Grow	0	
Warning		Compatibility warning: FB_Exit is now called in Shrink for FB instance Temp which is located on the stack. This has not been the case for code compiled with compiler versions < 3.1.4022.0. [tcmatrix, 1.4.3 (burks engineering)]		DynamicMatrix.Shrink	0	
Warning		Compatibility warning: FB_Exit is now called in Transpose for FB instance Temp which is located on the stack. This has not been the case for code compiled with compiler versions < 3.1.4022.0. [tcmatrix, 1.4.3 (burks engineering)]		DynamicMatrix.Transpose	0	
Warning		Compatibility warning: FB_Exit is now called in TransposeSquare for FB instance Temp which is located on the stack. This has not been the case for code compiled with compiler versions < 3.1.4022.0. [tcmatrix, 1.4.3 (burks engineering)]		Matrix.TransposeSquare	0	

The issue appears to arise from a new compiler warning added to CoDeSys in V3.5.9.70. (You are probably aware that the TwinCAT PLC module is based on CoDeSys. New CoDeSys features and bug fixes generally show up in a new TwinCAT release after a while....) Luckily for us, CoDeSys actually publishes release notes, unlike Beckhoff.

https://www.codesys.com/fileadmin/data/Images/System/Releaseinformation/ReleaseNote-CODESYS-V35970.pdf

FB_Exit should be called to destroy local instances CDS-383
FB_EXIT is now called for instances allocated on the stack before the owning scope returns.
A warning has been added to inform users about the change of semantics in these cases.
In order to suppress the warning, decorate the POU declaring the local instance with the warning disable
macro for the warning code C0394 ("{warning disable C0394}")

Basically, this {warning disable C0394} attribute needs to be attached to the Function or Method or Property getter/setter which allocates the temporary FB.

I have tested that the warning suppression works on my machine; it does. I can submit a PR if it would be helpful. I haven't been through the whole library yet to locate every POU which allocates an FB instance on the stack, though.

However I'm less confident in my belief that suppressing the warning is the correct thing to do in all cases. Do you think there are any situations in TcMatrix (or TcTransform) where calling FB_Exit() for temporary stack-allocated FB instances will cause problems? What's your minimum TwinCAT support version? If it's less than 4022.0, are code changes necessary to make sure that those stack-allocated FBs are cleaned up properly in the absence of a compiler-enforced call to FB_Exit()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions