[EXT_EP-10867] Initialization of array of structures is mistakenly filled with 0 Created: 21/Jul/22  Updated: 21/Nov/22  Resolved: 06/Oct/22

Status: Fixed
Project: Embedded Software & Tools
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Medium
Reporter: TI User Assignee: TI User
Resolution: Fixed Votes: 0
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Product: Code Generation Tools
Internal ID: CODEGEN-10251
Found In Release: ARMCLANG_1.3.0.LTS
Fix In Release: ARMCLANG_1.3.2.LTS*
Affected Platform/Device: default
Workaround: Remove const qualifier or section attribute from the definition of relevant data object definition.

 Description   

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.


Generated at Fri May 01 09:57:44 CDT 2026 using Jira 10.3.7#10030007-sha1:a563685562f94d165eb4e158cfb2a142338d8c54.