-
Bug
-
Resolution: Fixed
-
Medium
-
Code Generation Tools
-
CODEGEN-10251
-
ARMCLANG_1.3.0.LTS
-
ARMCLANG_1.3.2.LTS*
-
default
-
Remove const qualifier or section attribute from the definition of relevant data object definition.
In the attached source file, there is code similar to ...
__attribute__ ((section ("section_name"))) extern const ns1::ns2::struct_type array_name[LENGTH] = { /* many non-trivial initializations here */ };
Use the attached files to build it ...
% tiarmclang @options.txt -S file.cpp
Inspect the resulting file.s to see assembly code similar to ...
array_name: .zero 10944
The array is created, but incorrectly filled with 0 and no initialization of the array is performed at run-time.
Note:
This is a defect in the tiarmclang 1.3.0.LTS and 1.3.1.LTS. A fix will be made available in the 1.3.2.LTS maintenance release.
However, beginning with the tiarmclang 2.1.0.LTS release, the originally submitted test case source code will trigger an error diagnostic to be emitted by the compiler. This is because the code in question violates a C++ language rule with respect to constant expressions used in the initialization of the array that was involved in the original defect report.
Specifically, the C++ language violation is that an expected constant expression used in the initialization of an array. That is, an expression that includes a reinterpretation cast applied to an address constant is not considered to be a valid constant expression in an initializer for a const-qualified array.
We can see this in the following C++ code:
typedef struct { unsigned long X_m1; } element_X; __attribute__ ((section (".bss.X"),aligned(128))) element_X array_X[3U]; typedef struct { unsigned long A_m1; } element_A; typedef struct { unsigned long B_m1; } element_B; __attribute__ ((section ("my.config.lists"))) const element_A array_A[342] = { { (unsigned long)&array_X[0] }, }; __attribute__ ((section ("my.config.lists"))) const element_B array_B[] = { { 123456 }, };
When compiled the above code will generate an error:
%> tiarmclang -mcpu=cortex-m33 -Oz -c err_diag.cpp err_diag.cpp:15:17: error: 'array_B' causes a section type conflict with 'array_A' const element_B array_B[] = { { 123456 }, }; ^ err_diag.cpp:9:17: note: declared here const element_A array_A[342] = ^ 1 error generated.
To avoid the error in the above example, the type of member A_m1 can be changed to element_X* and the cast to a scalar unsigned long can be removed from the initializer for the first element of array_A.