Commit Graph
100 Commits
Author SHA1 Message Date
Stephen Heumann 84c47841a7 Add headers, tests, and documentation for strfromd/f/l (C23). 2026-04-05 20:27:36 -05:00
Stephen Heumann b46cbc4ae2 Add headers, tests, and documentation for strdup and strndup (C23). 2026-04-05 18:29:05 -05:00
Stephen Heumann c889254d52 Add headers, tests, and documentation for memalignment (C23). 2026-04-05 16:09:49 -05:00
Stephen Heumann 829d87d099 Define char8_t (C23).
We don't yet have the functions that operate on char8_t, but this can still be used in user code (e.g. to indicate what is a UTF-8 string).
2026-04-05 13:29:29 -05:00
Stephen Heumann 629bc3d3a8 Define _PRINTF_NAN_LEN_MAX (C23).
This is the maximum length of the printed representation for a NaN. In our case, it's for something like -NAN(123).

This is a new feature for C23, but since it was a reserved identifier under earlier standards, we just define it unconditionally.
2026-04-05 13:26:38 -05:00
Stephen Heumann 765ecca7e7 Generate better code for 32-bit assignments used as subexpressions.
This improves code for things like a=b=c=123. It also improves the setup code at the beginning of varargs functions.
2026-04-02 20:50:31 -05:00
Stephen Heumann c406011696 Allow varargs functions with no fixed parameters (C23). 2026-04-02 20:11:04 -05:00
Stephen Heumann 2ee05a2ff7 Update tests to avoid using trigraphs in C23 mode.
In C23 mode, C2.1.0.4.CC now tests that the former trigraph sequences are treated as regular characters (not trigraphs) in strings.
2026-04-02 18:04:38 -05:00
Stephen Heumann 99bc1d5534 Avoid defining true and false in <types.h> in C23 modes.
This prevents the macro definitions from overriding the C23 keywords, which would change the types of true and false.
2026-04-01 22:12:30 -05:00
Stephen Heumann d57f0567b3 Small edits to release notes. 2026-04-01 22:00:21 -05:00
Stephen Heumann 844ba0c01f Add tests for recent C23 library updates. 2026-03-31 19:01:04 -05:00
Stephen Heumann 16e8c983d2 Add docs and headers for new and updated <time.h> functions (C23). 2026-03-22 22:08:51 -05:00
Stephen Heumann 56e6029825 Add PRIb*, PRIB*, and SCNb* macros in <inttypes.h> (C23).
These correspond to the new binary conversions for printf and scanf.
2026-03-16 18:30:01 -05:00
Stephen Heumann b6960255ed Document strto* updates. 2026-03-15 21:29:25 -05:00
Stephen Heumann 58307280eb Document new printf/scanf features. 2026-03-15 16:02:59 -05:00
Stephen Heumann 5b0eca5e8a Handle wN/wfN length modifiers in printf/scanf format checker. 2026-03-15 16:00:42 -05:00
Stephen Heumann ca2c558cb6 Handle C23 'b' format for scanf.
As with printf, the format checker expects 'b' to have its traditional ORCA/C behavior in pre-C23 modes, or the C23 standard behavior in C23 modes.

Also as with printf, it can detect when 'b' is being used in the traditional way and automatically change it to 'p'. Specifically, this is done when 'b' is used with no length modifier and the corresponding argument is a pointer to a character type. This behavior is controlled by the same #pragma extensions bit as for printf, and it also only works when the scanf-family function is called directly and has a string literal for the format string.
2026-03-06 22:24:06 -06:00
Stephen Heumann ce41769d8c Add extension to auto-convert printf 'b' format to 'P' for pstrings.
This uses the printf format-checking mechanism to parse the format string and associate conversions in it with arguments. If the argument corresponding to 'b' is a pointer (and no length modifier is used), the 'b' is converted to 'P'. The effect is that most code that used 'b' in the old way will keep working, but code using 'b' with integers will get the new behavior (in C23 mode). Note that this only works if the format string is given by a string literal, and the printf-family function is called directly (not via a function pointer).

This is controlled bit a new #pragma extensions bit (bit 2), which is enabled by default when not in strict mode.
2026-03-05 21:02:28 -06:00
Stephen Heumann cfc95f68ab Adjust printf format checker to support 'B' and C23 version of 'b'.
It adjusts to use either the old or new version of 'b' depending on the language mode.
2026-03-04 19:52:58 -06:00
Stephen Heumann fe5a77addf Reference a label to indicate C23 mode to the library.
When compiling in C23 mode, ORCA/C now generates references to the label ~C23ORLATER, which is defined in the library. The presence of this label in the linked executable can be used by library functions to determine whether they should operate in C23 mode.
2026-03-04 19:47:25 -06:00
Stephen Heumann 3c8788e36c Allow K&R-style parameters without explicit decl in c23compat mode.
This applies to code like the following, which is allowed by C89 but not C99+:

int f(a) { /* code using a, implicitly declared as int */ }

Such code was inadvertently broken in c23compat mode due to changes to handle C23 rules, but it should be allowed in that mode for compatibility with old code. It is still disallowed by strict mode, or by appropriate lint checks.
2026-03-02 19:46:32 -06:00
Stephen Heumann 76433a64cd Remove some nil/garbage pointer dereferences.
These are similar to the ones from the last commit, in that there are earlier checks for the pointer being nil, but the nil dereferences can still occur because short-circuit evaluation is not used. These ones have somewhat more complicated control flow, and also the added aspect that a value read through the nil pointer is itself treated as a pointer and dereferenced. This still doesn't cause problems most of the time, but dereferencing that garbage value may possibly hit a soft switch or IO location. Apart from fixing that potential issue, there should be no functional changes.
2026-03-02 19:37:37 -06:00
Stephen Heumann b35bd91077 Remove several possible nil pointer dereferences.
These were in code like "if (ptr <> nil) and (ptr^.field = XYZ) then ..." or similar. ORCA/Pascal does not use short-circuit evaluation for boolean operators, so the code that would dereference the pointer would get evaluated even if it was nil. In the situations here, this was basically harmless, since the IIGS does not have memory protection and the value read from the nil pointer would not affect the program's behavior. However, it is still cleaner to avoid the nil pointer dereferences.

(Some similar code with more complex control flow is still present.)
2026-03-02 18:30:32 -06:00
Stephen Heumann 12276d456c Implement C23 enum enhancements.
This implements the enhancements to enum types in C23. There are three major elements to these enhancements, which are all implemented here:

-Enumeration constants can have values outside the range of int; enum types using the traditional syntax are automatically assigned an underlying type that is able to hold their constant values (WG14 N3029)
-The underlying type for an enumeration can be explicitly specified using a new syntax (WG14 N3030)
-Enumeration types and their constants can be declared multiple times within the same scope (parts of WG14 N3037)
2026-02-26 22:04:44 -06:00
Stephen Heumann 794ca70beb Prevent casts to void in integer constant expressions.
This gives an error when an expression cast to void is used somewhere that an integer constant expression is required, e.g.:

int main(int argc, char *argv[]) {
        switch (argc) {
                case (void)0: 1;
        }
}
2026-02-24 22:26:19 -06:00
Stephen Heumann ac23d1de4f Comment out code to handle enum types in debug info.
This was dead code, because types with kind=enumType are not used as variable types.
2026-02-24 20:01:35 -06:00
Stephen Heumann df3f364931 Make the type of comma expressions be exactly that of the right operand.
This is what the standards specify. Previously, ORCA/C was applying the usual unary conversions (aka integer promotions), which could change the type.
2026-02-21 22:17:40 -06:00
Stephen Heumann 713aacb70f Comment out code generation for enumConst.
This was dead code, because enumConst tokens get converted to intconst as part of ExpressionTree (in DoOperand).
2026-02-17 20:23:08 -06:00
Stephen Heumann 3003f89ee4 Fix bugs when enum constant names shadow something from an outer scope.
One bug is that the scope of the enum constant only begins at the end of the enumerator, so a definition of the same name from an outer scope should be visible and usable within the expression giving the enum constant value. The other bug is that spurious errors would be reported if the enum constant matched the name of a typedef from an outer scope.
2026-02-13 19:26:57 -06:00
Stephen Heumann bdc081e787 Comment out code for enum-typed expressions, variables, or return types.
In ORCA/C, types with kind = enumType are only used for enum type tags. They do not appear in other places, because an enum type specifier is treated as yielding the type int. Thus, there can never be an expression or variable with an enum type. This has been the case in ORCA/C at least back to 2.1.0 (and likely farther). This is technically not quite standard-conformant, but it makes very little difference in practice, because ORCA/C currently makes all enum types compatible with int.

There was code in some places to handle enum-typed expressions, variables, or function return types, but this is dead code. Most of this code looks reasonable as far as I can tell, but it has not actually been used for a long time (if ever), and it is likely incomplete relative to what would actually be needed to support enum-typed expressions and variables.

This patch comments out that dead code and replaces it with calls to produce an error if those code paths are ever triggered, which effectively act as assertions that they are not used. If ORCA/C was ever changed to use enum types more widely, the code for handling them could be uncommented at that time, but it would need to audited and updated as appropriate.
2026-02-11 17:30:37 -06:00
Stephen Heumann 8a3830645d Implement nullptr and nullptr_t (C23). 2026-02-10 20:38:01 -06:00
Stephen Heumann 583feaf300 Remove an unneeded variable. 2026-02-09 17:55:24 -06:00
Stephen Heumann ca5a93e974 Disallow mistyped expressions for the function in function calls.
Previously, the code would remove any number of "pointer to" and "array of" elements in the type, and accept it if this ultimately yielded a function type. Thus, the expressions denoting the function to be called could be, e.g., a pointer to a function pointer or an array of function pointers. The code generated in these cases would not work properly, but no error was reported.

Now only function pointers or expressions of function type are accepted, as they should be.
2026-02-08 18:17:35 -06:00
Stephen Heumann 9fffb51b96 Allow use of function-typed expressions as boolean values.
This includes conversion to bool, use as the condition for "if", etc.
2026-02-08 18:08:48 -06:00
Stephen Heumann 68786e4ac8 Allow casts from function-typed expressions to pointer or scalar types. 2026-02-07 22:23:05 -06:00
Stephen Heumann e057df4db3 Allow assignment of function-typed expressions to function pointers.
This affects code like function_ptr1 = *function_ptr2. This should be allowed (if the function types are compatible), since the function type is converted to a function pointer type in this context.
2026-02-07 21:53:54 -06:00
Stephen Heumann 42feb8b01e Report an error for ++/-- on expressions of function type.
This affects things like (*function_pointer)++.
2026-02-07 15:48:40 -06:00
Stephen Heumann b0e10d2e80 Allow comparison of expressions of function type with function pointers.
This affects equality comparisons where one side has function type (e.g. *function_pointer) and the other side has function pointer type (pointing to a compatible function type) or is a null pointer constant. These should be permitted, because the function type is converted to a function pointer type in this context. ORCA/C could report a spurious error for such comparisons, because it was not always performing those conversions.

(ORCA/C would treat function names as having function pointer type for these purposes, since for those the type conversion is performed elsewhere.)

Here is an example showing several expressions that gave spurious errors:

void f(void) {}
void (*fp)(void);
int main(void) {
        *fp == f;
        *fp == 0;
        *fp == (void *)0;
}
2026-02-06 23:10:21 -06:00
Stephen Heumann bdb8f3cf2b Allow empty initializers for single-valued types (C23).
An empty initializer {} is now allowed for numeric or pointer types, and is equivalent to {0}. ORCA/C already allowed empty initializers for structs/unions/arrays.
2026-02-03 22:07:30 -06:00
Stephen Heumann b9daf5159c Make bsearch and string search functions into generic functions (C23).
This means that if the parameter giving the array to search is a pointer to a const-qualified type, the return type will be modified so that its pointed-to type is also const-qualified. This functionality is implemented using macros, so the underlying functions still have the same types as before. In addition to the functions specified as generic in C23, this change is also applied to the non-standard strrpbrk function, since it is analogous to strpbrk and has the same issue of potentially discarding const qualifiers.

Note that under ORCA/C's default loose type checking rules, assignments that discard qualifiers are permitted, so these changes have a somewhat limited safety benefit (but also should very rarely require code changes). If using strict type checking, the type rules for assignments will be enforced as per the standard, so assignments that discard qualifiers will produce an error.
2026-02-02 21:27:13 -06:00
Stephen Heumann 3aa96f8a10 Update definition of assert to pass a 32-bit line number.
This requires a new call in ORCALib (__assert3), which is equivalent to the previous __assert2 except for the type of the line number.
2025-11-25 22:20:16 -06:00
Stephen Heumann 719453e2a2 Define assert using ... so that the argument can contain a comma (C23).
This affects cases where the argument expression to assert contains an un-parenthesized comma, which can occur when using compound literals.

When NDEBUG is not defined, this still requires the argument to be something that would count as one argument to a function (i.e. it cannot use an un-parenthesized comma operator). We do this by including an unevaluated call to a fake function using that argument as part of the expansion of the assert macro. (This behavior is specified by a note in the standard, and it's not entirely clear to me that it follows from the normative text, but I've implemented it that way since that's apparently the intent.)
2025-11-25 22:17:46 -06:00
Stephen Heumann d631326efc Add headers, tests, and documentation for free_sized and free_aligned_sized. 2025-11-13 20:46:32 -06:00
Stephen Heumann dcd530c09d Add headers, tests, and documentation for memccpy. 2025-11-12 20:03:29 -06:00
Stephen Heumann 1efbedb362 Add headers, tests, and documentation for memset_explicit. 2025-09-21 17:52:54 -05:00
Stephen Heumann ec1f49d12c Add headers, tests, and documentation for call_once. 2025-09-21 16:29:27 -05:00
Stephen Heumann b29517c7b9 Add BOOL_MAX macro (C23). 2025-09-17 20:54:31 -05:00
Stephen Heumann ee8be78a8b Allow initialization of static/global bool variables from addresses.
This permits code like the following, which the standards seem to allow:

int x;
_Bool b = &x;

(The bool variable is always initialized to one in cases like this. If would be undefined behavior if the address evaluated to 0, so we can assume it doesn't.)
2025-09-06 20:33:05 -05:00
Stephen Heumann be97e598d2 Implement pointer subtraction for pointers to VLA types. 2025-09-03 22:18:20 -05:00
Stephen Heumann 174028dc0e Check that right operand in ptr subtraction points to a complete type.
This check is currently only enabled under strict type checking, since ORCA/C traditionally did not require it but the C11 and later standards do. (The left operand has always been required to point to a complete type, and the two types have been required to be compatible, but the traditional ORCA/C rules could allow the right operand to point to an incomplete array type.)
2025-09-03 22:17:28 -05:00
Stephen Heumann 88a85b1a2e Make casts yield the unqualified version of the type.
This is what C17 and later specify. It traditionally would not have had an observable effect, but in C23 it does affect typeof.
2025-09-02 22:20:25 -05:00
Stephen Heumann 50650453ae Small edits in CGI.Comments. 2025-09-02 22:18:46 -05:00
Stephen Heumann 911e955ef9 Implement _BitInt types (C23).
This is a near-complete implementation of _BitInt types as specified in the C23 standard. The only missing element is support for _BitInt bitfields wider than 32 bits.

This implementation supports _BitInt widths up to 64 and stores _BitInt types using either 16, 32, or 64 bits, whichever is required to fit them. They are sign-extended or zero-extended out to the width used to store them, and for calling conventions and most other purposes they are treated like integers of that width. Unsigned _BitInt types are truncated and zero-extended as necessary to implement the standard wrap-around semantics for unsigned types. When a value is converted to a signed _BitInt type, it is truncated and sign-extended. However, signed _BitInt types are generally not truncated and sign-extended in cases of arithmetic overflow, since that would be fairly expensive and overflow is UB according to the standard; thus, overflow involving signed _BitInt types can effectively produce values outside the range of the type.

This also incidentally (due to changes in GetLongLongVal) fixes a bug where constant division operations such as -1 / 12345u could be mis-evaluated because the usual arithmetic conversions were not applied to them correctly. (Both operands would be promoted to wider types, rather than just converting -1 to 0xFFFF.)
2025-09-02 22:17:54 -05:00
Stephen Heumann 0717bd9d50 Avoid incorrect optimization of sign-extension code.
If native code peephole optimizations and register optimizations were both in use, incorrect code could be generated for sign extension during a 16-bit to 32/64-bit conversion. This could occur because a lda instruction moved by peephole optimization might subsequently be removed by register optimization, even though it was actually needed for its effect on flags.

This could affect code like the following:

#pragma optimize 7
int main(void) {
        int a  = -1;
        0;
        unsigned b = a;
        unsigned long c = a;
        return c == -1; // should be 1
}
2025-08-28 20:54:45 -05:00
Stephen Heumann b78759a653 Use types instead of kinds in integer constant expression evaluation.
Helper functions are also introduced to perform the usual arithmetic conversions over a pair of integer types and to set a token to hold an integer constant based on its type.

These changes are in preparation for the introduction of _BitInt types.
2025-08-20 20:11:02 -05:00
Stephen Heumann a31514e475 Include type in longConstant and longlongConstant tokens.
This mirrors what was already done with intConstant, and is preparatory for supporting _BitInt types.
2025-08-13 21:55:04 -05:00
Stephen Heumann 2bbcf326c8 Always use 64-bit integers for evaluating constant expressions.
This removes the 32-bit code paths that were previously used for constant expressions with 16-bit or 32-bit types. The two code paths were mostly duplicates apart from the type of the operands.
2025-08-12 22:12:41 -05:00
Stephen Heumann 53e84fb2f1 Remove charconst/shortconst/boolconst token kinds.
These are now represented by including the type in intConstant tokens, rather than effectively encoding all the possible types in the token kind.
2025-08-11 21:56:04 -05:00
Stephen Heumann 7f1d96b629 Ensure integer promotions promote unsigned short to unsigned int.
Previously, the type of expressions like -us or us+us (where us is a variable of type unsigned short) would be left as unsigned short.
2025-08-09 17:51:51 -05:00
Stephen Heumann e8e01b3263 Implement C23 rules requiring function prototypes.
For compatibility with old code, a new #pragma ignore bit is also provided to partially reverse these new rules in a way that should maintain compatibility with most K&R-style C code. This bit is enabled by default in C23 compatibility mode, but disabled in strict C23 mode.
2025-08-09 17:38:54 -05:00
Stephen Heumann f25c9a9210 Avoid null pointer dereferences in parameter type checking.
These could occur in some situations where a K&R-style function definition followed a prototyped declaration of the function.

There should generally be no functional change, although the old code could potentially have misbehaved if the null pointer dereferences gave certain values.
2025-08-06 18:43:24 -05:00
Stephen Heumann 788d167f31 Small cleanups in StrictCompTypes.
There should be no functional change.
2025-07-27 22:12:13 -05:00
Stephen Heumann e0cc6b2b18 Correctly handle (void) function prototypes in type names.
The code for parsing prototypes in type names did not special-case (void) as declaring no parameters.

This also fixes a slight issue with parsing prototypes in declarations in C23 mode, in that (typeof(void)) should be treated as equivalent to (void) but was not.
2025-06-29 13:22:08 -05:00
Stephen Heumann e6b7535b8f Implement __has_c_attribute preprocessor operator (C23). 2025-06-28 21:52:27 -05:00
Stephen Heumann 069f97f51f Correct indentation and end-of-block comments. 2025-06-28 21:32:02 -05:00
Stephen Heumann 19ecd81c30 Implement __has_include preprocessor operator (C23). 2025-06-28 21:17:47 -05:00
Stephen Heumann 9630392c5e Prevent spurious errors when a #embed expands to nothing. 2025-06-28 20:21:21 -05:00
Stephen Heumann bb58a1a264 Fix handling of K&R-style parameters without explicit declarations.
The changes to support VLAs broke how these were handled, so they would not be accessed at the right location on the stack.
2025-06-28 14:16:25 -05:00
Stephen Heumann aaa7ae01ce Use an enumeration for special macro algorithms. 2025-06-28 14:06:04 -05:00
Stephen Heumann abffba7969 Implement __has_embed preprocessor operator (C23). 2025-06-28 13:32:53 -05:00
Stephen Heumann 3803d28f08 Implement #embed directive (C23).
This is a fairly straightforward implementation, which works fine for small files but can be slow or run out of memory for sufficiently large ones. This should be good enough for most realistic use cases on the IIGS, but it could be refined in the future if desired.

Also, it behaves more like the version specified in C++26 in that embed parameters are always macro-expanded, rather than following the somewhat complicated C23 rules about macro expansion. GCC and Clang also seem to work similarly, even in C23 mode.
2025-06-28 13:31:14 -05:00
Stephen Heumann 13f2487f28 Declare unsigned comparison functions as returning a 16-bit integer.
This is consistent with what the assembly code actually does. Previously, the result was treated as a 32-bit integer, but since the assembly code only returns 16 bits, the upper 16 bits would be garbage. This wouldn't end up mattering, because the result was later truncated to 16 bits, but it's cleaner to just declare the functions correctly.
2025-06-26 23:12:59 -05:00
Stephen Heumann ca2ed24817 Support #pragma STDC FENV_ROUND FE_DYNAMIC (C23).
This just specifies dynamic rounding mode that can be configured with <fenv.h> calls, like before C23. The other #pragma STDC FENV_ROUND values (specifying static rounding modes) are still not supported.
2025-06-24 19:50:49 -05:00
Stephen Heumann 2cc445e25e Avoid reporting "compiler error" for attempts to initialize VLAs. 2025-06-24 18:18:54 -05:00
Stephen Heumann 1a0d0cdb65 Slight rewording of release notes. 2025-06-23 22:23:24 -05:00
Stephen Heumann c8f0e9c008 Update VLA tests. 2025-06-23 21:41:11 -05:00
Stephen Heumann 9ac829707c Evaluate typeof operand expressions with variably modified type. 2025-06-23 21:40:48 -05:00
Stephen Heumann a9f247c7cf Give compound literals in parameters automatic storage duration in C23. 2025-06-23 18:11:34 -05:00
Stephen Heumann 4189ba80ca Enforce constraint that array size expressions have integer type. 2025-06-23 18:09:17 -05:00
Stephen Heumann 5496122a9a Avoid generating sign extension code for VLA sizes of type int.
This is unnecessary, since a negative size would produce undefined behavior.
2025-06-22 21:25:41 -05:00
Stephen Heumann cf9c24b530 Document VLA support. 2025-06-22 21:12:30 -05:00
Stephen Heumann 0c70063081 Check for goto or switch entering scope of identifier with VM type.
These violate constraints in the C standards.
2025-06-22 20:37:21 -05:00
Stephen Heumann ec8c26202f Add support for variable length array types.
This follows the C23 requirement to support VLA types, but not necessarily to support local variables of VLA type (which we still do not). This should be essentially a full implementation of VLA types as specified by C23, except that errors about branching into the scope of a variably modified variable are not detected.
2025-06-22 17:28:24 -05:00
Stephen Heumann 7446687559 Move C23 tests to separate test script so they can be run in C23 mode.
It is now possible to invoke C23 tests in C23 mode by running "DOIT4 TEST.C23".

A test for the new true and false keywords is also added, taking advantage of this. Additional tests for C23-specific features may be added in the future.
2025-06-22 17:21:59 -05:00
Stephen Heumann 6bd344c9ec Change ChangePointer to take the pointed-to type, not just its size.
This is in preparation for supporting VLA types.
2025-06-18 17:07:43 -05:00
Stephen Heumann 64dfdf9c2c Rename arrayExpression to integerConstantExpression.
This aligns the terminology with the C standard and better reflects how these expressions are used (i.e. not just for arrays). This will be particularly relevant once variable-length array types are supported, since at that point array sizes may not be integer constant expressions.
2025-06-17 18:20:33 -05:00
Stephen Heumann 1841e949d4 Implement type inference with "auto" (C23).
Note that this overlaps with the old C89/C90 syntax for declarations with "implicit int." In C23 modes, declarations meeting the requirements for type inference will use it, but in "c23compat" mode other declarations using "auto" are still eligible to be interpreted as using implicit int. (C23 also allows for type inference in some implementation-defined situations that go beyond the minimum required to be supported, but this implementation mostly follows the minimum requirements.)
2025-06-12 22:22:08 -05:00
Stephen Heumann eaad35c1ed Implement typeof and typeof_unqual (C23). 2025-06-11 18:01:17 -05:00
Stephen Heumann 3b9b4d5355 Parse function prototypes in type names.
Previously, the prototype would just be ignored, creating an un-prototyped function type.
2025-06-09 22:31:36 -05:00
Stephen Heumann 19804e013b Handle function-typed parameters whose own params start with attributes.
The parsing logic for unnamed parameters sometimes needs to look ahead an extra token to account for this.

Here are examples of function declarations affected by this logic, as well as equivalent and compatible ways of declaring the same functions:

int f(int([[]] int));
int f(int (*)(int));

int g(int([]));
int g(int*);
2025-06-08 22:55:10 -05:00
Stephen Heumann 5a4fef4175 Parse type names involving function types more correctly.
This affects type names such as "int (int)", which should indicate a function type. Previously, it would not be parsed as such.

Function types are not generally legal where type names are used (other than in typeof, but that's not yet implemented), so use of such type names will still result in an error, but a better error message may be reported.

This also removes the previous special-case code to handle type names like "int ()". They can now be handled by the general code for function abstract declarators.

This still does not actually process prototypes in type names to generate the appropriate prototyped function type. That will be handled later.
2025-06-08 22:18:23 -05:00
Stephen Heumann d4b62eeebc Allow for unnamed parameters declared with function type.
This handles function declarations like:

int (int (int));

Note that this also applies to parameter declarations like "int (foo)" where foo is a typedef name, per the rule that it is treated as a typedef name (making this an unnamed parameter declared with function type) rather than the name of the parameter.
2025-06-08 20:22:25 -05:00
Stephen Heumann f096bf83c9 Allow parameters declared with function types (adjusted to pointers).
All C standards permit this, but ORCA/C formerly did not.
2025-06-08 16:19:42 -05:00
Stephen Heumann 67e3b4b2de Avoid usage of global numberOfParameters variable.
This could wind up with the wrong value in some cases involving functions returning function pointers. This could cause spurious errors in cases where a function's parameters were declared in the K&R style relying on "implicit int", but the function returned a prototyped function pointer type, e.g.:

int (*f(x,y))(int, long) { /*...*/ }
2025-06-08 13:57:19 -05:00
Stephen Heumann 9251bd08cd Avoid spurious errors about some functions returning function pointers.
There errors stemmed from including parameters from the returned function pointer type in the list of parameters associated with the function being declared. This could cause spurious errors about unnamed parameters for code like:

void (*f(void))(int, long) { /*...*/ }

It could also cause miscompilation resulting from trying to access parameters at the wrong stack positions for "pascal" functions returning a function pointer, like:

int pascal (*f(char x, double y))(int a, long b) {
        printf("x = %c, y = %f\n", x, y);
        return 0;
}
2025-06-08 13:48:26 -05:00
Stephen Heumann de058c5e50 Fix test name in c23misc. 2025-06-05 18:24:01 -05:00
Stephen Heumann a0a8bbf389 Add support for true and false keywords (C23). 2025-06-04 21:48:31 -05:00
Stephen Heumann 951355623a Use proper types for constants cast to short, unsigned short, or bool.
This basically affects how they match in _Generic, but it is also preparatory to support for true/false and auto from C23.
2025-06-04 20:04:55 -05:00
Stephen Heumann a1506a5248 Support #elifdef and #elifndef preprocessor directives (C23).
This also adds the previously-missing check for an #elif after #else.
2025-06-03 21:03:12 -05:00
Stephen Heumann aff5b0c277 Add support for u8-prefixed character constants (C23).
In C23 mode, this also enforces the new constraints that u- or U-prefixed character constants must only contain a single character, and it must be representable in a single UTF-16 or UTF-32 code unit.
2025-06-03 19:57:03 -05:00