aboutsummaryrefslogtreecommitdiff
path: root/type.c
AgeCommit message (Collapse)Author
2024-04-27Implement variable length arraysNihal Jere
Variably modified types are required for C23. Since QBE doesn't currently support saving and restoring the stack pointer, a current limitation is that we can't reclaim stack space from VLAs that go out of scope. This is potentially problematic for VLAs appearing in a loop, but this case is uncommon enough that it is silently ignored for now. Implements: https://todo.sr.ht/~mcf/cproc/1 References: https://todo.sr.ht/~mcf/cproc/88 Co-authored-by: Michael Forney <mforney@mforney.org>
2024-04-15Remove support for non-prototype function declarations and definitionsMichael Forney
These were removed in C23.
2024-04-12Use struct decl for function parametersMichael Forney
2024-04-07Store length expression in array typesMichael Forney
We don't need the length constant anymore, so just use that name for the length expression. References: https://todo.sr.ht/~mcf/cproc/1
2024-04-06Remove some unnecessary use of array type lengthMichael Forney
2024-04-04type: Fix qualifiers of adjusted array types of parametersMichael Forney
2024-04-02map: Use simpler fnv-1a hash functionMichael Forney
2024-03-22Implement C23 nullptr constantMichael Forney
2024-03-21decl: Add support for enums with large values and fixed underlying typesMichael Forney
Fixes: https://todo.sr.ht/~mcf/cproc/64
2024-03-16Store enum underlying type in base fieldMichael Forney
This will facilitate supporting underlying types other than int or unsigned, possible in C23. References: https://todo.sr.ht/~mcf/cproc/64
2022-01-22Remove unused type propertiesMichael Forney
2022-01-22Port to C99Michael Forney
2021-09-29Use unsigned long long for sizes and offsetsMichael Forney
We don't need exact-width integer types here.
2021-09-06Fix type-checking of va_list arguments to varargs built-insMichael Forney
If the argument was a function parameter, its type has already been adjusted. So on x86_64, we can't just ignore the automatic array-to-pointer conversion, since it was never a pointer to begin with. Instead, keep track of the adjusted va_list type, and check that the arguments to varargs built-ins match that type.
2021-09-04Use architecture-specific va_list typeMichael Forney
Previously, cproc effectively used used typedef struct { /* 32 bytes, 8-byte aligned */ } __builtin_va_list[1]; However, this is not quite correct for x86_64 nor aarch64, though it was close enough for both to work in most cases. In actuality, for x86_64 we want typedef struct { /* 24 bytes, 8-byte aligned */ } __builtin_va_list[1]; and for aarch64 we want typedef struct { /* 32 bytes, 8-byte aligned */ } __builtin_va_list; The difference only appears when the size of va_list matters, or when va_list is passed as a parameter. However, the former is not often the case, and the aarch64 ABI replaces aggregate arguments with pointers to caller-allocated memory, which is quite similar to arrays decaying to pointers in C except that the struct is not copied. Additionally, riscv64 simply uses typedef void *__builtin_va_list; which again has a different size and calling convention. To fix this, make the __builtin_va_list type architecture-specific and use architecture-specific tests for varargs-related functionality.
2021-09-04Prepare for supporting architecture-specific va_list typeMichael Forney
2021-07-02qbe: Remove repr from struct value and use per-instruction class insteadMichael Forney
This way we avoid leaking backend-specific details of type representation outside qbe.c. It also facilitates some future simplifications.
2021-07-01decl: Check that the flexible array member (if present) is lastMichael Forney
2021-03-31qbe: Use second argument of call/arg to store type nameMichael Forney
2020-06-03Revert "decl: Allow out-of-range enum constants when they don't change type"Michael Forney
This reverts commit 6229709b8ae21d7722fef48ad8a9f2f10b900030. I still don't understand how out-of-range enum constants are supposed to work.
2020-06-03decl: Allow out-of-range enum constants when they don't change typeMichael Forney
gcc and clang allow enum constants out of range of int, but this means that the type of enumerator may differ inside and outside the enum specifier. Instead, only allow out-of-range enum constants when their types are compatible with the final enum type.
2020-04-04type: Remove unnecessary check for TYPEVOIDMichael Forney
There is only one type with this kind, so the equality check above suffices.
2019-07-07type: Ignore parameter qualifiers when determining type compatibilityMichael Forney
The end of C11 6.7.6.3p15 says that qualifiers should be ignored when checking compatibility of function types.
2019-05-16Remove incorrect type equality check in usual arithmetic conversionsMichael Forney
Integer types still undergo integer promotions even if they are the same type.
2019-05-08Bump size of va_list to 32 to support both x86_64 and aarch64Michael Forney
2019-04-23Fix integer promotion on bit-fieldsMichael Forney
Fixes #47.
2019-04-21Keep track of type properties in typeMichael Forney
2019-04-20Make basic types have their own kindMichael Forney
2019-04-20Shorten some names with 'long'Michael Forney
2019-04-10type: unions are object typesMichael Forney
2019-04-06Use common code for checking for compatibility of base type for derived typesMichael Forney
2019-04-06Track type qualifiers separatelyMichael Forney
Using a special qualified type kind has a number of problems: - Important fields such as size, align, and incomplete may not be set, since the qualified type was created before a struct was completed. - When we don't care about type qualifiers (which is the usual case), we have to explicitly unqualify the type which is annoying and error-prone. Instead, in derived types, keep track of the qualifiers of the base type alongside the base type (similar to what is done for members, parameters, declarations, and expressions in the past few commits).
2019-04-06Separate unqualified type and qualifiers in struct paramMichael Forney
2019-04-04Merge headers into cc.hMichael Forney
2019-04-03Error on bit-field access for nowMichael Forney
2019-03-14Abbreviate tag namesMichael Forney
2019-03-13Drop base parameter from mktypeMichael Forney
2019-02-19Add missing lvalue conversionsMichael Forney
typeintpromote and typeargpromote assume they are dealing with an unqualified type, and return an incorrect result if they are given a qualified one. So, add an assert here. This was causing const integer types to get promoted to themselves due to missing lvalue conversions. Thanks to Andrew Chambers for the bug report and test case.
2019-02-18void is an incomplete typeMichael Forney
2019-02-18Fix compatible check for basic typesMichael Forney
This check was only supposed to return true for enum types and their corresponding integer type. However, it had the side effect of making 'int' compatible with 'unsigned'. To fix this, introduce a new basic type kind for enums with the same rank as 'int', that is only compatible with itself and the 'int' type with the matching sign. Thanks to Andrew Chambers for the bug report.
2019-02-17Make enum types compatible with their corresponding integer type (int)Michael Forney
2019-02-17Improve old-style function declaration supportMichael Forney
Implement typecompatible for types created with non-prototype function declarations. Require a function definition with parameter declaration list after a declaration with a non-empty identifier list. Detect function definitions with parameter declaration lists containing types incompatible with the promoted types, and report an error for now.
2019-02-15Don't embed anonymous struct members into parentMichael Forney
While this works nicely for structs, when unions are involved it makes it impossible to find the next member to initialize without keeping track of extra data per member.
2019-02-15Use bool typedef in .c filesMichael Forney
2019-02-15Rename emit.h -> backend.hMichael Forney
2019-02-12Fix nested arraysMichael Forney
We need to traverse the type hierarchy from inside to out to calculate size/alignment of arrays.
2019-02-12Initial importMichael Forney