Use i8 for stack boolean variable allocation #321
No reviewers
Labels
No Milestone
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Depends on
#322 Meta changes from #321
M-Labs/nac3
Reference: M-Labs/nac3#321
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "issue-315"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Copied from the relevant commit description:
Additional Context:
The bug in #315 is manifested via the use of (1)
i1
as theList
element type, and (2) a pointer cast ofi1*
toi8*
incodegen::irrt::list_slice_assignment
. Thei1*
toi8*
cast is to facilitate the use of__builtin_memcpy
and__builtin_memmove
for implementing assignment of list slices, but becausei1
is represented as ani8
with 7 upper undefined bits, this cast effectively extends0b{0,1}
into0b???????{0,1}
(?
are undefined bits). This erroneous cast is then propagated to the backend, where the upper 7 bits of the boolean is not masked (& 0x1
), causing the output of 255.The ABI remains unchanged after this change, i.e. function parameters and return types will still be
i1
to remain consistent with LLVM IR generated by other compilers (e.g. Clang). To bridge the difference betweeni1
andi8
, two conversion functions (bool_to_i1
andbool_to_i8
) are added to convert between the types when necessary.This bug cannot be reproduced using the New Pass Manager because as opposed to the Legacy PM, the New PM is implemented such that it executes loop analysis, CG-SCC (call graph strongly-connected components) analysis, and module analysis in addition to function analysis, causing the bug to be masked by aggressive optimizations. A future commit may be necessary to fully control the optimizations used for the entire compilation pipeline.
Other Information:This PR also contains infrastructural improvements, including updated Rust dependencies, replacement of deprecated LLVM intrinsics, implementation ofMoved to #322.__nac3_raise
in Standalone, C implementation of thedemo
library andlli
support, and improved documentation.Fixes #315.
Yep, using
i8
as the "storage type" for bool is, unfortunately, the way to go; this is the standard approach in other compilers.Should we just use i8 everywhere then to avoid complexity/confusion and potentially other similar bugs?
IIRC this just adds more complexity, as
i1
is still used for IR-level boolean operations (comparisons,select
, etc.). The clearest solution re complexity/confusion seems to be to just insist on a distinction between value type and memory/storage type.47d9f8d5c6
to6a2da69317
v2: Extracted other changes into #322. This PR is now dependent on it as it contains a test regression fix.
6a2da69317
to899c0d8cd3
v3: Rebased against
meta-changes-from-issue-315
.899c0d8cd3
to3c0b5eb1b6
v4: Rebased against
master
.@ -0,0 +1,84 @@
#include <assert.h>
This file does not belong in this PR.
3c0b5eb1b6
toacdb1de6fe
v5: Dropped irrelevant commits.