1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-17 00:29:31 +00:00
Commit Graph

305 Commits

Author SHA1 Message Date
acqn
81d6321cd7 Fixed internal representation of calculated constant results.
Minor clean-up.
2021-02-22 14:14:59 -05:00
acqn
eadaf2fef8 Fixed deferred post-inc and post-dec in unevaluated context such as 'sizeof(i++)'. 2021-02-22 11:02:47 +01:00
acqn
40b26f4060 Now the compiler removes code that has no observable effect. 2021-02-22 13:47:32 +08:00
acqn
7f05bd797f Now the compiler tracks code that has no observable effect. 2021-02-21 16:36:29 +08:00
acqn
bfc7a51a44 Fixed Issue #1265 according to C89/C99 standards. 2021-01-30 14:31:51 +01:00
Greg King
8b42f570e9 Fixed code that caused a seg-fault after parsing a (deferred) post-count argument followed by a (nested) function-call argument.
The old broken code defers the count until the end of the (parent function's) argument list.  But, a nested function call clears the pointer to the deferred type.  That leads to an access violation.
The new code defers only until the end of each argument.  Fixes #1320.
2020-11-20 17:45:14 -05:00
Polluks
bd6e5927c4 Fixed #1341 2020-11-18 10:28:19 +01:00
Jesse Rosenstock
060417b0dc Adjust type of int constants that fit in char
When there is an integral constant like `3` in an expression, it has
type `int` according to the C spec, even though it can be represented
as an `unsigned char`.  Change codegen (`hie_internal` and `typeadjust`)
to treat it as `unsigned char` instead of `int` so that faster,
unsigned operations can be used.

For the test case in #1298, reduces the cycles per iteration from
4311 to 1884.  This is a great improvement, but still much worse than
the 1053 cycles/iter from `c4698df~`, so more work remains to be done.

Further partial fix for #1298 and #1308.
2020-11-16 00:56:19 +01:00
acqn
5c43d1e04f Changed codegen for postfix inc/dec operations by deferring them till sequence points.
This usually allows faster & smaller code.
Note that deferred operations must still be called at sequence points even if the whole expressions containing them had constant values.
2020-10-20 22:01:55 +02:00
acqn
86ced2bd4c Avoided unnecessarily boosting the code label numbers with boolean AND. 2020-09-18 08:59:56 +02:00
acqn
ab7e9f8424 Hotfix for Issue #1250. 2020-09-08 16:28:21 +02:00
acqn
e2f950b15e Avoided referencing string literals with sizeof so that they are not output if unused elsewhere. 2020-09-05 13:21:21 +02:00
acqn
903e84c24c Std-functions are no longer inlined if they are unevaluated. 2020-09-05 13:21:21 +02:00
acqn
f849de6769 Object addresses as non-NULL for comparison with NULL. 2020-09-04 19:50:32 +02:00
acqn
8e0b2f0833 Object addresses as non-NULL in boolean context. 2020-09-04 19:50:32 +02:00
acqn
bc5570b708 Fixed logical-NOT in constant context. 2020-09-04 19:50:32 +02:00
acqn
fb6bc275bc Fixed evaluation flags propagation to subexpressions in assignments and function calls. 2020-09-02 21:36:59 +02:00
acqn
2379504449 Fixed AND/OR in certain cases where the 'E_NEED_TEST' flag set for usage only in subexpressions should be cleared. 2020-09-02 21:36:59 +02:00
acqn
28de3423eb Merged some switch cases in code generation subroutines. 2020-08-31 09:12:03 +02:00
acqn
6b64b43395 Made local static data use a separated label pool from the code label pool. 2020-08-31 09:12:03 +02:00
Oliver Schmidt
bee559d5f4
Merge pull request #1220 from acqn/StaticConst
[cc65] Fixed constant boolean expressions
2020-08-31 08:59:25 +02:00
acqn
74def4608a The 'E_NEED_TEST' flag shouldn't be overwritten when loading the expression result. 2020-08-31 02:30:12 +08:00
acqn
c0a873e0c8 Reduced exess errors on wrong initializations with curly braces. 2020-08-30 17:35:48 +02:00
acqn
60c59f59a3 Renamed StaticConstExpr() and StaticConstAbsIntExpr() with clearer comments. 2020-08-30 00:26:52 +08:00
acqn
0a96ffc878 Fixed function parameter checking.
Fixed function return type checking.
2020-08-29 16:37:16 +02:00
acqn
504aee3835
Merge branch 'master' into StaticConst 2020-08-27 06:27:23 +08:00
acqn
bb9c203222 Fixed integer promotion of unary operations. 2020-08-26 22:17:16 +02:00
acqn
f289ea6c14 Avoided generating unnecessary true-case labels in logic AND/OR. 2020-08-22 11:10:17 +08:00
acqn
0536f4f9bd Minor fixes on constant expression checking and comments. 2020-08-21 23:27:41 +02:00
acqn
85ea06687b Fixed logical AND and logical OR. 2020-08-20 07:52:15 +08:00
acqn
725511131a Fixed constant expression checks with no-code requirement.
Used return-by-value initialization for ExprDesc.
2020-08-20 07:52:11 +08:00
acqn
3ea3887c77 Fixed warnings on const comparison.
Warnings on expressions with no effects.
Fixed const ternary.
Fixed ternary with struct/union types as the true/false-branch expressions.
2020-08-20 07:52:06 +08:00
acqn
17bbba7327 Added integer boolean type string.
No longer set the "expression tested" flag with constant results in comparison.
2020-08-20 07:52:03 +08:00
acqn
87889df9e9 Fixed type checking in relation operations. 2020-08-18 09:39:43 +02:00
acqn
ebae994dc9 Fixed CHECK failure when calling functions defined with repeated parameter names.
Clarified the terms "parameter" vs "argument" in FunctionParamList().
2020-08-17 20:27:57 +02:00
Jesse Rosenstock
c4698dfd07 Use C89 semantics for integer conversions
Previously, the following rules were used for binary operators:
* If one of the values is a long, the result is long.
* If one of the values is unsigned, the result is also unsigned.
* Otherwise the result is an int.

C89 specifies the "usual arithmetic conversions" as:
* The integral promotions are performed on both operands.
* Then the following rules are applied:
  * If either operand has type unsigned long int, the other operand is
    converted to unsigned long int.
  * Otherwise, if one operand has type long int and the other has type
    unsigned int, if a long int can represent all values of an unsigned int,
    the operand of type unsigned int is converted to long int; if a long int
    cannot represent all the values of an unsigned int, both operands are
    converted to unsigned long int.
  * Otherwise, if either operand has type long int, the other operand is
    converted to long int.
  * Otherwise, if either operand has type unsigned int, the other operand is
    converted to unsigned int.
  * Otherwise, both operands have type int.
https://port70.net/~nsz/c/c89/c89-draft.html#3.2.1.5

As one example, these rules give a different result for an operator
with one long operand and one unsigned int operand.  Previously,
the result type was unsigned long.  With C89 semantics, it is just long,
since long can represent all unsigned ints.

Integral promotions convert types shorter than int to int (or unsigned int).
Both char and unsigned char are promoted to int since int can represent
all unsigned chars.
https://port70.net/~nsz/c/c89/c89-draft.html#3.2.1.1

Rename promoteint to ArithmeticConvert, since this is more accurate.

Fixes #170
2020-08-15 19:14:31 +02:00
acqn
0dfe9ff5fe Fixed testing 'struct->field'. 2020-08-14 08:32:22 +08:00
acqn
9317db6642 Slightly improved type error messages of 'op='. 2020-08-12 15:01:31 +02:00
acqn
68d63b089d Reduced error flood raised by misplaced variable declarations. 2020-08-12 15:01:31 +02:00
acqn
fdef067629 Fixed tentative definition of variables of incomplete types that may be completed later.
Tenative arrays that never get completed are now assumed each to have one element.
2020-08-07 10:16:33 +02:00
acqn
6df4f1996b Improved diagnostics with more detailed type names. 2020-08-02 23:51:11 +02:00
acqn
003d47cc8b Improved type conversion diagnostic messages.
Allowed incompatible pointer assignments with warnings.
Fixed Issue #1089.
2020-08-02 18:55:46 +02:00
acqn
30fd8592ae Avoid internal errors when using function-type objects in expressions. 2020-08-02 12:28:11 +02:00
acqn
25d10d9d9a Fixed nested struct/union initialization.
Fixed bit-fields offsets in anonymous structs.
2020-07-30 08:38:24 +02:00
acqn
65081aebed Made able to recognize global declarations of static arrays. Fixed Issue #975. 2020-07-21 18:23:52 +02:00
acqn
0250c87ac6 Fixed SC_* type masks by making them all bitwise-exclusive. 2020-07-21 18:23:52 +02:00
acqn
b67b8ddd38 Disabled applying 'sizeof' to bit-fields. 2020-07-20 14:54:32 +02:00
acqn
62a6e37487 Made the code handling '&expression' slightly tidier. 2020-07-20 14:54:32 +02:00
Greg King
fd0a6955da Changed "IsTypeStruct() || IsTypeUnion()" expressions into shorter "IsClassStruct()" expressions.
Type-classes are groups of types that can be handled in the same way (similar syntax).
2020-07-19 14:30:22 -04:00
acqn
29c50ab25f Corrected the error message about struct/union members not found. 2020-07-19 12:57:59 +02:00
acqn
768e03a474 Small fixes and tidy-up based on PR review.
Renamed GetReplacementType() to GetStructReplacementType().
Clarified in comments that most *Struct* facilities work for unions as well.
Made it clear in some error messages with regards to structs/unions.
2020-07-19 10:58:33 +02:00
acqn
b45d373fd6 Fixed passing by value structs/unions <= 4 bytes in size to functions. Larger ones are forbidden for now. 2020-07-19 10:58:33 +02:00
acqn
9f67b45ea0 Fixed returning by value structs/unions <= 4 bytes in size from functions. Larger ones are forbidden for now. 2020-07-19 10:58:33 +02:00
acqn
333fa97326 Whitespaces/newlines fixes. 2020-07-18 12:54:29 +02:00
acqn
9198b3be00 Fixed '&function' and '&array'. 2020-07-18 12:54:29 +02:00
acqn
d23b577331 More compiler flags on address types to match the location types of expressions. 2020-07-18 12:54:29 +02:00
acqn
2108489523 Fix for Issue #1075 and #1077. 2020-07-18 12:54:29 +02:00
acqn
8066cd9ace Fixed wrong case in PreDec codegen, which never seems to be in use though. 2020-06-01 22:37:40 +02:00
acqn
33e103fdc6 Fixed Issue #1040: non-byte pointer +=/-= byte codegen bug. 2020-06-01 22:37:40 +02:00
Greg King
90a2edcfa2 Made cc65 detect a possibly missing argument at the end of a function argument list.
(It could be a stray comma at the end of the list.)
2020-01-25 04:14:58 -05:00
Greg King
a0db846a97 Allowed old-style (K and R) function declarations to be fastcall.
That lets them match old-style definitions.  It avoids "Type conflict" error messages.  It allows shorter function calls.

Fixed the types of some variables in "test/ref/otccex.c".  It avoids crashes on 64-bit Windows (32-bit Windows with 64-bit pointers).
2019-07-22 09:26:23 -04:00
Lauri Kasanen
654d972288 C90 param, void 2019-04-21 12:46:03 -04:00
Lauri Kasanen
a9cbb5305c Fix missing spaces 2019-04-21 12:46:03 -04:00
Lauri Kasanen
3b3b16ee9c Add support for computed gotos
This is a GCC extension that allows C to use fast jump tables.
2019-04-21 12:46:03 -04:00
Greg King
a6b04f6e97 Changed most "backticks" (grave accents) into apostrophes.
Quotations that are embraced by tick marks now look better, in most fonts.
2019-01-05 14:57:12 -05:00
Laubzega
581c46c213 Add checks for risky goto statements. 2018-10-02 18:49:53 +02:00
Greg King
c67e90dd19 Changed the type of a compiler variable that holds either integers or pointers.
The change allows cc65 to be compiled on 64-bit Windows, without getting warnings.  That OS is actually 32 bits with 64-bit pointers.  Its pointers are "long long" instead of "long".  The change uses type-names that are configured for the actual pointer width.
2018-01-09 05:34:16 -05:00
Oliver Schmidt
c8d6ca908d Minor style fix. 2017-10-23 18:22:51 +02:00
Oliver Schmidt
11b01b908d Merge pull request #424 from clbr/trampoline
Trampoline support
2017-05-18 16:29:34 +02:00
Lauri Kasanen
f6fa74a636 Rename trampoline to wrappedcall everywhere 2017-05-18 16:00:04 +03:00
Lauri Kasanen
a2f61c667a Update comments and location checks according to Greg 2017-05-07 20:31:41 +03:00
Lauri Kasanen
ead0338c0d Add fast path for char postdec 2017-05-06 13:35:39 +03:00
Lauri Kasanen
767f093ff8 Add fast path for char postinc 2017-05-06 13:35:39 +03:00
Lauri Kasanen
2890b3a810 Pragma trampoline 2017-05-02 20:51:53 +03:00
Greg King
7e14dde07b Fixed the cc65 code that handled an addition of a pointer to a 32-bit offset.
It didn't demote the offset to int because it looked at the pointer (instead of the offset) which already was 16 bits.
2015-12-31 17:41:48 -05:00
Greg King
3b303396bf Made cc65 accept comparisons between pointers with different qualifiers (similarly to subtractions between pointers). 2015-12-29 04:18:17 -05:00
Oliver Schmidt
d3eebc8fcf Merge branch 'pointer' of https://github.com/mrdudz/cc65 into mrdudz-pointer 2015-07-15 12:24:09 +02:00
mrdudz
6ab197f364 patch from Uz that makes some illegal operations on pointers error out 2015-07-10 14:27:49 +02:00
Greg King
8189339e7d Added special-case compiler code that handles a pointer-to-array dereference.
The type needs to change (to array); but, the address shouldn't be changed -- it already points to the first element.
Based on a bug analysis by Daniel Serpell.
2015-07-01 06:55:57 -04:00
Greg King
8743e9911d Added a command-line option to compile a program, with __cdecl__ as the default calling convention. 2015-04-22 09:59:23 -04:00
Greg King
a798b1d648 Made __fastcall__ be the default calling convention for non-variadic functions. 2015-03-10 05:53:52 -04:00
Greg King
0390c34e88 Changed multi-line C comments into another style.
The left side doesn't look unbalanced.
2014-06-30 16:51:07 -04:00
Oliver Schmidt
4185caf855 Normalized code. 2014-03-04 01:11:19 +01:00
Oliver Schmidt
f488f7576c Applied fix contributed by Greg King.
The code
  void foo(void)
  {
    int i;
    long l = 1L * i;
  }
triggered an
  Internal compiler error:
  Code generation messed up: StackPtr is -4, should be -2

Greg King: "We are lucky that the bug is simple -- a missing "else".  The result is that the compiler thinks that it does the opposite of what it actually does:  It thinks that it pushes the non-constant expression onto the stack. It doesn't; so, cc65's stack pointer is wrong."
2013-10-08 23:04:41 +02:00
Oliver Schmidt
85885001b1 Removed (pretty inconsistently used) tab chars from source code base. 2013-05-09 13:57:12 +02:00
uz
0eed753578 Prevent a literal string that is an argument for sizeof to be output into the
literal pool.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5968 b7a2c559-68d2-44c3-8de9-860c34a00d81
2013-01-25 20:45:40 +00:00
uz
ec1f955a6e For commutative operators processed by hie_internal, if the left side is a
constant, exchange the order of the operands so that better code can be
generated.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5721 b7a2c559-68d2-44c3-8de9-860c34a00d81
2012-06-16 18:12:24 +00:00
uz
b5d88fdedd Mark commutative operators as such (no change in code until now).
git-svn-id: svn://svn.cc65.org/cc65/trunk@5720 b7a2c559-68d2-44c3-8de9-860c34a00d81
2012-06-16 15:49:53 +00:00
uz
cbefb85d47 Fixed a problem reported by Greg King. structs returned from functions in the
primary register are actually rvalues and need special treatment.
                                                                 


git-svn-id: svn://svn.cc65.org/cc65/trunk@5413 b7a2c559-68d2-44c3-8de9-860c34a00d81
2012-01-20 16:01:25 +00:00
uz
80a5686bd9 The code for compares with a constant result may not be removed, because it
may contain side effects.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5010 b7a2c559-68d2-44c3-8de9-860c34a00d81
2011-05-01 18:48:06 +00:00
uz
3f5b2a8fbd Allow to disable the "Result of comparison is constant" warning.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4883 b7a2c559-68d2-44c3-8de9-860c34a00d81
2010-11-28 21:16:46 +00:00
uz
477b77f528 Another minor improvement in compares.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4745 b7a2c559-68d2-44c3-8de9-860c34a00d81
2010-07-11 21:53:48 +00:00
uz
2bb2d97ab0 Fixed and improved the code for compares. Before, compares of chars to a
constant where sometimes passed down to the code generator in a way that
caused wrong code to be generated.

This change may go into 2.13 after some testing.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4743 b7a2c559-68d2-44c3-8de9-860c34a00d81
2010-07-11 16:11:45 +00:00
uz
1a4e2edede Reenable compile time evaluation of strlen for string literals.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4631 b7a2c559-68d2-44c3-8de9-860c34a00d81
2010-03-20 18:51:59 +00:00
uz
3976746735 Rewrote literal handling. Literals are now saved together with other function
data, and at the end of compilation merged if possible. Literals for unused
functions are removed together with the function.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4501 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-12-05 22:39:45 +00:00
uz
50ff6d0768 Create one literal pool per function, so that literal pool data is removed
together with a function, if it is not used. Literal storage can now be
controlled by #pragma writable-strings on a per function basis.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4499 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-12-04 14:12:25 +00:00
uz
ce931b85be In case of parse errors for structs, don't just set the type of the result to
"int", return a valid lvalue instead.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4483 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-11-24 23:02:58 +00:00
uz
548336a7bd Renamed attribute handling functions. Added SymHasAttr().
git-svn-id: svn://svn.cc65.org/cc65/trunk@4375 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-10-19 10:19:26 +00:00
uz
5a00b38aab Fixed the existing but unused attribute parsing code. Added
__attribute__((noexit)) that may be used to mark functions that won't return.
Added this attribute to the exit() function in stdlib.h.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4372 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-10-18 18:31:02 +00:00
uz
0ce362a69b Some cleanup in the code generator. Added a g_drop function. g_drop and
g_space can now handle sizes > 255 bytes.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4370 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-10-15 21:08:03 +00:00