Commit Graph

770 Commits

Author SHA1 Message Date
Stephen Heumann
c169c2bf92 Fully prohibit redefinition of predefined macros.
Code like the following was previously being allowed:

#define __STDC__ /* no tokens */
2022-02-13 18:10:45 -06:00
Stephen Heumann
5d7c002819 Fix bug causing some #undefs to be ignored when using a sym file.
This would occur if the macro had already been saved in the sym file and the #undef occurred before a subsequent #include that was also recorded in the sym file. The solution is simply to terminate sym file generation if an #undef of an already-saved macro is encountered.

Here is an example showing the problem:

test.c:
#include "test1.h"
#undef x
#include "test2.h"

int main(void) {
#ifdef x
        return x;
#else
        return y;
#endif
}

test1.h:
#define x 27

test2.h:
#define y 6
2022-02-13 16:33:43 -06:00
Stephen Heumann
b231782442 Add option to use a custom pre-include file.
This is a file that will be included before the source file is processed. If specified, it is used instead of the default .h file.
2022-02-12 21:36:39 -06:00
Stephen Heumann
913a333f9f Record the cc= string in the symbol file and require it to match.
Macros and include paths from the cc= parameters may be included in the symbol file, so incorrect behavior could result if the symbol file was used for a later compilation with different cc= parameters.
2022-02-12 19:45:04 -06:00
Stephen Heumann
06e17cd8f5 Give an error if file names or command-line parameters are too long.
The source file name, keep name, NAMES= string, and cc= string are all restricted to 255 characters, but these limits were not previously enforced, and exceeding them could lead to strange behavior.
2022-02-12 15:42:15 -06:00
Stephen Heumann
bd811559d6 Fix issues with keep names in sym files.
There were a couple issues that could occur with #pragma keep and sym files:

*If a source file used #pragma keep but it was overridden by KEEP= on the command line or {KeepName} in the shell, then the overriding keep name would be saved to the sym file. It would therefore be applied to subsequent compilations even if it was no longer specified in the command line or shell variable.

*If a source file used #pragma keep, that keep name would be recorded in the sym file. On subsequent compilations, it would always be used, overriding any keep name specified by the command line or shell, contrary to the usual rule that the name on the command line takes priority.

With this patch, the keep name recorded in the sym file (if any) should always be the one specified by #pragma keep, but it can be overridden as usual.
2022-02-06 21:49:08 -06:00
Stephen Heumann
9cdf199c3a Clarify that sym files still need to be deleted when adding defaults.h.
The old wording made it sound like it applied only to .sym files generated by an old version of ORCA/C, but that is not the case.
2022-02-06 19:06:51 -06:00
Stephen Heumann
5f03dee66a Allow negated long long constants in cc= defines.
These are still treated as one token, like other negated numbers specified in cc=(-d...).
2022-02-06 15:33:42 -06:00
Stephen Heumann
efb363a04d Update a comment. 2022-02-06 15:08:04 -06:00
Stephen Heumann
7d4f923470 Improve error handling for cc= options on command line. 2022-02-06 14:24:22 -06:00
Stephen Heumann
785a6997de Record source file changes within a function as part of debug info.
This affects functions whose body spans multiple files due to includes, or is treated as doing so due to #line directives. ORCA/C will now generate a COP 6 instruction to record each source file change, allowing debuggers to properly track the flow of execution across files.
2022-02-05 18:32:11 -06:00
Stephen Heumann
5ac79ff36c Stop capitalizing file names in debug information.
This does not seem to be necessary for any of the debuggers (at least in their latest versions), and it obviously causes problems with case-sensitive filesystems.
2022-02-04 22:15:02 -06:00
Stephen Heumann
7322428e1d Add an option to print file names in error messages.
This can help identify if an error is in the main source file or an include file.
2022-02-04 22:10:50 -06:00
Stephen Heumann
4cb2106ee4 Change the name of the current source file on an #include or #append.
This causes __FILE__ to give the name of an include file if used within it, which seems to be what the standards intend (and what other compilers do). It also affects the file name recorded in debugging information for functions declared in an include file.

(Note that occ will generate a #line directive before an #append, essentially to work around the problem this patch fixes. After the patch, such a #line directive is effectively ignored. This should be OK, although it may result in a difference in whether a full or partial pathname is used for __FILE__ and in debug info.)
2022-02-03 22:22:33 -06:00
Stephen Heumann
dce9d36edd Comment out unused error messages and update docs about errors. 2022-02-01 22:16:57 -06:00
Stephen Heumann
e36503508a Allow more forms of address expressions in static initializers.
There were several forms that should be permitted but were not, such as &"str"[1], &*"str", &*a (where a is an array), and &*f (where f is a function).

This fixes #15 and also certain other cases illustrated in the following example:

char a[10];
int main(void);
static char *s1 = &"string"[1];
static char *s2 = &*"string";
static char *s3 = &*a;
static int (*f2)(void)=&*main;
2022-01-29 21:59:25 -06:00
Stephen Heumann
e8d90a1b69 Do not generate extra zero bytes after certain string constants.
These extra bytes are unnecessary after the changes in commit 5871820e0c to make string constants explicitly include their null terminators.

The extra bytes would be generated for code like the following:

int main(void) {
        static char *s1 = "abc", *s2 = "def", *s3 = "ghi";
}
2022-01-29 18:27:03 -06:00
Stephen Heumann
02fbf97a1e Work around the SANE comp conversion bug in another place.
This affects casts to comp evaluated at compile time, e.g.:

static comp c = (comp)-53019223785472.0;
2022-01-22 18:22:37 -06:00
Stephen Heumann
5357e65859 Fix indentation of a few lines. 2022-01-22 18:21:11 -06:00
Stephen Heumann
f4b0993007 Specify correct location for the default .h file. 2022-01-17 18:27:39 -06:00
Stephen Heumann
242bef1f6e Correct a comment. 2022-01-17 18:27:10 -06:00
Stephen Heumann
8eda03436a Preserve qualifiers when changing float/double/comp parameters to extended.
Changing the type is still non-standard, but at least this allows us to detect and report write-to-const errors.
2022-01-17 18:26:28 -06:00
Stephen Heumann
6f0b94bb7c Allow the pascal qualifier to appear anywhere types are used.
This is necessary to allow declarations of pascal-qualified function pointers as members of a structure, among other things.

Note that the behavior for "pascal" now differs from that for the standard function specifiers, which have more restrictive rules for where they can be used. This is justified by the fact that the "pascal" qualifier is allowed and meaningful for function pointer types, so it should be able to appear anywhere they can.

This fixes #28.
2022-01-13 20:11:43 -06:00
Stephen Heumann
b1bc840ec8 Reverse order of parameters for pascal function pointer types.
The parameters of the underlying function type were not being reversed when applying the "pascal" qualifier to a function pointer type. This resulted in the parameters not being in the expected order when a call was made using such a function pointer. This could result in spurious errors in some cases or inappropriate parameter conversions in others.

This fixes #75.
2022-01-13 19:38:22 -06:00
Stephen Heumann
3acf5844c2 Save and restore type spec when evaluating expressions in a type name.
Failing to do this could allow the type spec to be overwritten if the expression contained another type name within it (e.g. a cast). This could cause the wrong type to be computed, which could lead to incorrect behavior for constructs that use type names, e.g. sizeof.

Here is an example program that demonstrated the problem:

int main(void) {
        return sizeof(short[(long)50]);
}
2022-01-12 21:53:23 -06:00
Stephen Heumann
3b35a65b1d Give an error if a function pointer is redefined as a function.
This gives an error for code like the following, which was previously allowed:

void (*p)(int);
void p(int i) {}

Note that the opposite order still does not give a compiler error, but does give linker errors. Making sure we give a compiler error for all similar cases would require larger changes, but this patch at least catches some erroneous cases that were previously being allowed.
2022-01-12 18:31:32 -06:00
Stephen Heumann
61a382de0b Report parameter type errors the same way with and without strict type checks.
They were being reported as "type conflict" by default, but as "duplicate symbol" if strict checks were used.
2022-01-12 18:31:04 -06:00
Stephen Heumann
b5b276d0f4 Do not give a spurious error for redeclarations of a pascal function.
This could occur with strict type checking on, because the parameter types were compared at a point where they had been reversed for the original declaration but not for the subsequent one.

Here is an example that would give an error:

#pragma ignore 24
extern pascal void func(int, long);
extern pascal void func(int, long);
2022-01-12 18:30:28 -06:00
Stephen Heumann
4e59f4569f Note that structs and unions are passed by value, not by reference. 2022-01-12 18:20:21 -06:00
Stephen Heumann
8c5fba684c Add tests for fp comparison macros and type-generic math macros. 2022-01-09 18:26:32 -06:00
Stephen Heumann
d0514c5dc4 Add new tests for <math.h> functions (including C99 additions).
These test various properties of the functions, including normal computations and edge case behavior. The edge case tests are largely based on Annex F, and not all of the behavior tested is required by the main specifications in the C standard. ORCA/C does not claim to fully comply with Annex F, but it provides useful guidelines that we try to follow in most respects.
2022-01-06 18:10:10 -06:00
Stephen Heumann
3058ea6ad9 Fix FP_ILOGB0 and FP_ILOGBNAN macros.
They were missing the FP_ prefix.
2022-01-06 18:01:52 -06:00
Stephen Heumann
de5fa5bfac Update release notes.
This adds references to some more new features to the section with manual updates.
2022-01-02 21:46:53 -06:00
Stephen Heumann
ed3035cb99 Fix bug in code for varargs functions with multiple fixed parameters.
This was broken by the varargs changes in commit a20d69a211. The code was not accounting for the internal representation of the parameters being in reverse order, so it was basing address calculations on the first fixed parameter rather than the last one, resulting in the wrong number of bytes being removed from the stack (generally causing a crash).

This affected the c99stdio.c test case, and is now also covered in c99stdarg.c.
2022-01-01 22:42:42 -06:00
Stephen Heumann
45fad90d6d Add tests for new functionality (other than math functions). 2022-01-01 20:50:12 -06:00
Stephen Heumann
1fb1762458 Fix bug in initialization of auto arrays of strings.
When initializing (e.g.) an array of arrays of char, a string literal would be taken as an initializer for the outer array rather than for an inner array, so not all elements would be initialized properly. This was a bug introduced in commit 222c34a385.

This bug affected the C4.6.4.2.CC test case, and the following reduced version:

#include <stdio.h>
#include <string.h>
int main (void) {
   char ch2[][20] = {"for all good people", "to come to the aid "};
   if (strcmp(ch2[1], "to come to the aid "))
       puts("Failed");
}
2021-12-27 08:22:19 -06:00
Stephen Heumann
3997fc6dce Add new headers to test of including all headers.
Also, alphabetize all of the headers in that test.
2021-12-26 16:50:34 -06:00
Stephen Heumann
bccbcb132b Add headers and docs for additional functions. 2021-12-24 15:57:29 -06:00
Stephen Heumann
98529a9342 Add tests for recently-implemented language features. 2021-12-05 13:55:09 -06:00
Stephen Heumann
c767848ec9 Add headers and docs for the acosh functions. 2021-12-05 13:52:40 -06:00
Stephen Heumann
033ff816aa Update release notes. 2021-11-29 20:35:07 -06:00
Stephen Heumann
b43036409e Add a new optimize flag for FP math optimizations that break IEEE rules.
There were several existing optimizations that could change behavior in ways that violated the IEEE standard with regard to infinities, NaNs, or signed zeros. They are now gated behind a new #pragma optimize flag. This change allows intermediate code peephole optimization and common subexpression elimination to be used while maintaining IEEE conformance, but also keeps the rule-breaking optimizations available if desired.

See section F.9.2 of recent C standards for a discussion of how these optimizations violate IEEE rules.
2021-11-29 20:31:15 -06:00
Stephen Heumann
6fa294aa3b Add documentation and headers for new <math.h> functions. 2021-11-28 19:54:51 -06:00
Stephen Heumann
aaec648e69 Protect against undefinition/redefinition of fpclassify. 2021-11-28 19:39:03 -06:00
Stephen Heumann
6d8e019443 Work around SANE bug in FX2C.
This could give incorrect results for extended-to-comp conversions of certain negative integers like -2147483648 and -53021371269120. To get a fix for the same problem with regard to long long, ORCA/C should be linked with the latest version of ORCALib (which also works around some instances of the problem at run time). There are still other cases involving code in SysFloat that has not yet been patched.
2021-11-28 15:20:26 -06:00
Stephen Heumann
dda37cd17c Define math_errhandling to MATH_ERREXCEPT.
This indicates that floating-point exceptions are used to report math errors. The existing functions will still also set errno in the existing cases, but the new C99 functions generally will not.
2021-11-21 14:46:47 -06:00
Stephen Heumann
3e08ba39aa Note that scalbn uses FLT_RADIX.
This is the reason that it is distinct from ldexp, although they amount to the same thing in the case of binary floating-point.
2021-11-21 14:40:45 -06:00
Stephen Heumann
b2874b8bf6 Add declarations and docs for float/long double versions of existing functions. 2021-11-21 14:38:30 -06:00
Stephen Heumann
4ebdb4ad04 Add the <tgmath.h> header containing type-generic math macros.
So far this only has macros for the newly-added functions, since the existing math functions in SysFloat do not have f- and l-suffixed versions.
2021-11-20 19:45:07 -06:00
Stephen Heumann
73a081bd55 Add header declarations and documentation for new math functions. 2021-11-20 19:33:04 -06:00