Skip to content

[translate-llvm-to-std] Support bool arrays#749

Merged
Jiahui17 merged 5 commits intomainfrom
bool-array
Mar 1, 2026
Merged

[translate-llvm-to-std] Support bool arrays#749
Jiahui17 merged 5 commits intomainfrom
bool-array

Conversation

@zero9178
Copy link
Copy Markdown
Collaborator

C's _Bool type was indiscriminately compiled to i1 previously. However, this creates invalid IR when using a _Bool array as input. Since C defines a bool to always be of byte size, all memref operations (after conversion) expect a memref of type i8 rather than i1.

This PR for now does the easy and working change of adhering to C's memory representation of using a byte per bool when used in an array (aka memory).

C's `_Bool` type was indiscriminately compiled to `i1` previously. However, this creates invalid IR when using a `_Bool` array as input.
Since C defines a bool to always be of byte size, all `memref` operations (after conversion) expect a `memref` of type `i8` rather than `i1`.

This PR for now does the easy and working change of adhering to C's memory representation of using a byte per bool when used in an array (aka memory).
@zero9178 zero9178 requested a review from Jiahui17 February 26, 2026 16:29
@Jiahui17
Copy link
Copy Markdown
Member

What if we intend to describe an array of bits? Does _BitInt(1) work?

@zero9178
Copy link
Copy Markdown
Collaborator Author

zero9178 commented Feb 26, 2026

What if we intend to describe an array of bits? Does _BitInt(1) work?

I don't think it'd work right now due to how Clang compiles these to be padded to full bytes:
https://godbolt.org/z/bzTs4GjoT

That said, I don't think there is anything in the C standard that prevents us from doing so (unlike for bool where it has to be a byte, see C23 6.2.6.2. Although maybe there's nothing wrong with us doing datalayout changes?), so this could be implemented as a compiler transformation

Comment thread tools/translate-llvm-to-std/InferArgTypes.cpp
@Jiahui17 Jiahui17 merged commit 2b181d3 into main Mar 1, 2026
7 checks passed
@Jiahui17 Jiahui17 deleted the bool-array branch March 2, 2026 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants