Possible optimization bug with lambda and function returns
When calling a function or a lambda to create function arguments, the stack is not reused.
The following code replicates the problem. It there anything i missed ? Or is there a bug in ARM GCC?
-------
#include <stdint.h>
#include <stdio.h>
struct TestStruct
{
uint32_t field1;
uint32_t field2;
uint32_t field3;
uint32_t field4;
uint32_t field11;
uint32_t field21;
uint32_t field31;
uint32_t field41;
} ;
struct TestStruct initStructure(
{
struct TestStruct myStruct;
return myStruct;
}
#define MACROLAMBDA(
[&]() -> struct TestStruct { struct TestStruct ${}; \
$.field1 = f1; \
$.field2 = f2; \
$.field3 = f3; \
$.field4 = f4; \
$.field11 = f5; \
$.field21 = f6; \
$.field31 = f7; \
$.field41 = f8; \
return $; \
}()
void __attribute_
{
printf("f1 = %d, f2 = %d, f3 = %d, f4 = %d, f1 = %d, f2 = %d, f3 = %d, f4 = %d", myStruct.field1, myStruct.field2, myStruct.field3, myStruct.
}
void __attribute_
{
}
void __attribute_
{
}
void __attribute_
{
}
void __attribute_
{
}
int main(void)
{
return 0;
}
-------
wrapper1LAMBDA uses 52 bytes of stack whereas wrapper2LAMBDA uses 80. The same happens for wrapper1func and wrapper2func.
The __attribute_
The tests were compiled with and without the following options :
-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mapcs-frame -std=c++17 -D"STM32" -D"STM32L4" -D"STM32L476xx" -D"STM32L476ZG" -D"ARM_MATH_CM4" -D"USE_
Question information
- Language:
- English Edit question
- Status:
- Expired
- Assignee:
- No assignee Edit question
- Last query:
- Last reply: