Repository navigation
WIP: Construct preallocated arrays without the allocating vector runtime [GH #561] - #571
Draft
lexx42xxel wants to merge 13 commits into
Draft
lexx42xxel wants to merge 13 commits into
lexx42xxel wants to merge 13 commits into
Conversation
… [GH edgcpp#557] Partially initialized multidimensional GNU variable-length arrays (e.g., "E a[n][3] = {{E(3)}};") could be constructed and destroyed with the wrong number of elements, and some shapes caused an assertion failure: the repeat count of the remaining elements was taken from the total element count of the array, and the starting element was not scaled for rows of variable length. The repeat counts of such initializers are now encoded and decoded in one place (documented in il_def.h). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…dgcpp#558] An initializer such as "int a[2][n] = {{1}, {2, 3}};" (or "= {}") can be neither kept as a C initializer nor copied from a static temporary, but it caused an internal error (class types) or generated C that used an undeclared temporary. Zero the whole array and then assign the elements individually; elements without an explicit initializer are zero (or default-initialized). Requires the runtime repeat count change for partially initialized multidimensional VLAs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…cpp#559] Without exceptions, such an initialization keeps the constant part of the initializer and leaves zeroing the remainder to the back end. That did not zero the array at all when no constant part was kept ("= {}"), and zeroing gives the wrong value for a null pointer to data member, which is not all-bits-zero in the IA-64 ABI. Requires the fix for brace initialization of VLAs whose rows have variable length. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
edgcpp#554] For "G g{};" where G has a member "P a[4]" and P has a nontrivial default constructor and a destructor, the elements were initialized by a generated helper routine without cleanups for the elements already constructed (or with a cleanup for only one of them), cleanups of preceding members were lost, and the helper's exception-handling epilogue was missing. Also affected: default member initializers, multidimensional and nested arrays, and new G{}. Initialize such element sequences with the runtime array construction routine, using a helper that initializes one element and the element destructor, and add the return statements of generated helper routines to the return memo list. Requires the fix for brace initialization of VLAs of a class with a destructor (textual overlap only). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Generate an element construction loop when no zeroing or exception cleanup is needed. Retain the existing runtime path for cases requiring cleanup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Simplify regression filters and clarify the lowering condition. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use nested construction loops and a nonallocating runtime for preallocated arrays. Preserve vector allocation entry points and exception cleanup behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Document the remaining traversal limitation. Clarify that exception handling can still allocate memory. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move __cleanup_vec_new_or_delete back to vec_newdel.c so it can call free_array directly, and drop the free_array function pointer. The exception runtime calls it, so programs that use exception handling link the allocating vector runtime; programs that are compiled without exception handling and do not use array new still do not. Document this. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Traverse array elements through unqualified pointers so constructors can be called on cv-qualified arrays. For multidimensional arrays of empty classes, traverse the innermost elements, because the generated C may give such rows a size of zero. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The fix for the initialization of VLAs (edgcpp#557, edgcpp#558, edgcpp#559) constructs a sequence of array elements initialized with an aggregate by calling make_vec_new_call. The array construction changes add a fixed_array parameter to that routine; pass TRUE, as the storage is that of the VLA being initialized and is not dynamically allocated.
…p#561] The new array construction tests examine the generated C and require the C-generating back end; record them as REQUIREMENTS NOT MET for the edg_x86_64_cp and edg_x86_32_cp configurations. The preallocated array construction routines make the runtime library larger, which moves static data in the 32-bit executables. Update the edg_x86_32 and edg_x86_32_cp recordings of edg/rma/init33, which print absolute object addresses.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Collaborator
|
AcknowlEDG review results updated for
|
Collaborator
|
AcknowlEDG review results updated for
CI success. |
Apply the review cleanup of the VLA initialization fix (GH edgcpp#557) to this branch: test dynamic initialization and constant kinds with dyn_init_is and constant_is, drop the remaining redundant enumerator casts, and rewrap the calls that now fit on fewer lines. No functional change.
Collaborator
|
AcknowlEDG review results updated for
CI success. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed in discussion #561; there is no feature issue yet.
Important
This branch is based on the VLA initialization fix PR #569 (#557, #558, #559,
#554), so its first 4 commits belong to that PR and drop out once it is
merged. The feature changes
make_vec_new_call, which the VLA fix alsocalls; commit "Construct VLA element sequences without allocation" adapts
that call. The last commit updates test expectations: the new tests need
the C-generating back end (REQUIREMENTS NOT MET on the
_cpconfigurations), and the larger runtime library moves the absolute
addresses printed by edg/rma/init33 on the 32-bit configurations.
Note
Work in progress. The implementation is complete and tested, but it is
opened as WIP pending agreement on the design in #561. Feedback sought on:
needed, otherwise a new non-allocating runtime file);
because generated code now needs the matching runtime library;
[GH #561](the discussion) is acceptable as the commit tag orshould be replaced by a feature issue number.
Problem
The target is embedded real-time code, where building without exception
handling and without dynamic memory allocation is standard practice (coding
guidelines for such code commonly prohibit both).
TASKING uses the EDG front end in its compiler toolchains for safety-critical
embedded systems, and would like to contribute this and related fixes to the
EDG project on GitHub.
In such programs, construction and destruction of arrays with static,
automatic or otherwise preallocated storage are still lowered to calls into
the vector runtime (
vec_newdel.c), which also implements the allocatingnew[]/delete[]support. A program that never allocates therefore stilllinks the allocation code.
Design
src/lower_init.c: when no exception cleanup is needed, the array is notvariably sized and the nested bounds are known and nonzero, generate nested
element construction loops, zeroing each element first if
value-initialization requires it. Otherwise call
__edg_vec_ctor.lib_src/vec_preallocated.c(new): the non-allocating entry points(
__edg_vec_ctor,__edg_vec_dtor,__edg_vec_cctor) for preallocatedstorage.
vec_newdel.ckeeps the allocating entry points and theunwinder's array cleanup
__cleanup_vec_new_or_delete(so that it cancall
free_arraydirectly). A program compiled without exceptionhandling that does not use array new no longer links
vec_newdel.o. Withexception handling it still does, because the unwinder's array cleanup
lives there; that is acceptable, since the targets that care about this
are built without exceptions.
cv-qualified arrays). For multidimensional arrays of empty classes the
innermost elements are traversed, because the generated C may give such
rows size zero.
doc/source/lower_il.rstdocuments the behaviour and remaining limits:points remain for previously generated code).
Alternatives considered
vec_newdel.cinto separate object files. Exceptioncleanup would still reference the allocating code, so the dependency would
remain.
code for every array with a nontrivial destructor; the runtime path is kept
for those cases.
Compatibility and performance
call).
Related
(Sized operator delete[] gets a different size than operator new[] for a zero-length array new #550 to Objects of empty classes have size zero in generated C (memset overwrites neighbours) #560).
Tests
tests/tests/regressions/array-construction-*.sft.cpp(14 tests:semantics, nested/copy shapes, cleanup and double throw, zero-length, VLA,
runtime cleanup, no allocation helper referenced in the generated C).
Checklist
[GH #561].doc/source/lower_il.rstupdated.src/pending_changes/gh-561-static-array-construction.txt,lib_src/pending_changes/gh-561-static-array-construction.txt.edg-docker-test --posture=extensiveon all four configurations: no regressions; recordings updated with-W.