Commit graph

1830 commits

Author SHA1 Message Date
Tee-Kiah Chia 4d5b1ec115 util/ego: inlining pass now tries to remove unused procedures
This addresses issue #230, though only partially.
2021-04-26 14:27:45 +00:00
Tee-Kiah Chia a29507d9e4 aslod: fix: use section alignments when computing section sizes
The follows( ) function uses pa->os_lign when determining
whether an output section pa immediately follows another
section pb.

However, emits( ) was not using this alignment information
when laying out and padding the output sections.  This seems
to be a bug.

I suspect that mach/arm/cv/cv.c might need a similar fix.
2021-03-18 18:25:04 +00:00
Tee-Kiah Chia 9c7ce04cec Fix static buffer overflow in genname( ) in LLgen
This should fix at least some instances of the "undefined
reference to `LLnc_recover'" error that happens in some
builds (https://github.com/davidgiven/ack/issues/218).

The bug was that genname( ) used a static `namebuf' buffer
and did not properly check for overflow when writing into
it.  The result was that the `non_corr' variable was
sometimes overwritten with a non-zero value when it should
be zero, causing bogus results later.

This proposed patch makes genname( ) dynamically allocate
and resize a buffer for holding a target file name.

I also take this chance to fix a typo in correct_prefix().
2021-03-16 17:59:29 +00:00
David Given 3eed6db007 Fix some issues caused by, I think, COMMON variables no longer working in
recent gccs?
2020-09-14 22:38:01 +02:00
George Koehler e841adf970 Fix END pseudo in util/ego/sr; closes #203
The strength reduction (SR) phase mishandled the END pseudo when SR
found at least 2 different expressions in the same loop, and SR made a
new header for the loop.

Since 1987 (commit 159b84e), SR appended the new header to the end of
the procedure.  Later, SR fixed the header by adding a BRA branch to
the loop's entry, and moving the END pseudo from the previous basic
block to the header.  If SR found multiple expressions, it called
fix_header() multiple times, and tried to move the END again.  The
extra move failed assert(INSTR(e) == ps_end), or moved another line
after the END, so opt2 (the peephole optimizer) would crash.

Fix by removing fix_header() and moving the code to make_header(), so
SR adds the BRA and moves the END when it makes the header, and does
so only once for each header.

Adjust init_code(), which inserts code into a header.  Stop checking
for an empty header, because make_header() now adds BRA.  After
inserting code before BRA, don't move LP_INSTR, because later
insertions should go before BRA, not after END.
2019-11-15 11:50:05 -05:00
George Koehler fc1476c88b Add -DDEBUG to enable assertions in util/ego
Our build enables assertions in some other ACK tools (like assemblers
and LLgen), but disabled them in ego until now.  Bug #203 becomes a
failed assertion in ego's SR phase:

    sr: util/ego/sr/sr_reduce.c:483: fix_header: Assertion
    `INSTR(e) == ps_end' failed.

Comment out 2 assertions in util/ego/share, because they fail on
systems with 4-byte int, 8-byte long.
2019-11-14 17:17:24 -05:00
George Koehler 3f3bf1e164 Reduce warnings, adjust format strings in util/led
Calls like `debug("something\n", 0, 0, 0, 0)` cause clang warnings,
because debug() is a macro that passes its arguments to printf(), and
clang warns about extra 0s to printf().  Silence the warnings by
hiding the printf() in a new function do_debug().  The code still
passes extra 0s to printf(), but clang can't warn.

Macros debug() and verbose() should use C99 __VA_ARGS__, so they don't
require the extra 0s; but ACK doesn't use __VA_ARGS__ yet.

Adjust some format strings for debug() or fatal(), or cast their
arguments, to match their types.  I don't know whether uint32_t is
unsigned int or unsigned long, so I cast it to unsigned long, and
print it with "%lx".

In util/led/sym.c, #include "save.h" to declare savechar(), and use
parentheses to silence a clang warning in hash().
2019-11-01 18:27:34 -04:00
George Koehler 17bc9cdef7 More void, fewer clang warnings in util/ego
Most warnings are for functions implicitly returning int.  Change most
of these functions to return void.  (Traditional K&R C had no void
type, but C89 has it.)

Add prototypes to most function declarations in headers.  This is
easy, because ego declares most of its extern functions, and the
comments listed most parameters.  There were a few outdated or missing
declarations, and a few .c files that failed to include an .h with the
declarations.

Add prototypes to a few function definitions in .c files.  Most
functions still have traditional K&R definitions.  Most STATIC
functions still don't have prototypes, because they have no earlier
declaration where I would have added the prototype.

Change some prototypes in util/ego/share/alloc.h.  Functions newmap()
and oldmap() handle an array of pointers to something; change the
array's type from `short **` to `void **`.  Callers use casts to go
between `void **` and the correct type, like `line_p *`.  Function
oldtable() takes a `short *`, not a `short **`; I added the wrong type
in 5bbbaf4.

Make a few other changes to silence warnings.  There are a few places
where clang wants extra parentheses in the code.

Edit util/ego/ra/build.lua to add the missing dependency on ra*.h; I
needed this to prevent crashes from ra.
2019-11-01 15:27:16 -04:00
George Koehler be1662dd15 Change the optional parameter of n_coerc() to a pointer
Fixes https://github.com/davidgiven/ack/issues/188

One call to n_coerc() omits the 6th and last argument.  This worked in
traditional K&R C, but stops working if we declare n_coerc() with a
prototype of all 6 parameters.

Change the last parameter to a pointer.  Declare n_coerc() with
prototype, so it now requires all 6 arguments.  Pass NULL when have no
iocc_t.  This NULL exists only to satisfy the prototype; n_coerc()
will not use this NULL.

A different fix would declare n_coerc() with 5 parameters and `...`,
then use <stdarg.h> to read the 6th argument when it exists.
2019-10-30 18:36:56 -04:00
George Koehler 0576641cae Reduce clang warnings from top
Also add `static` and remove `register` in mach/proto/top/top.c.  A
static function is only in one file, so its function declaration may
go in that file, instead of a header file.
2019-10-30 18:36:55 -04:00
George Koehler 51e34acab1 Add a syntax to declare functions in a top table
Use the new syntax in the mips, pdp, powerpc tables to declare
functions before calling them.  These declarations prevent compiler
warnings about implicitly declaring functions.  They also provide
prototypes of the function parameters.

Also fix a warning in the powerpc table: use `bsearch(...) != NULL` to
avoid converting the pointer from bsearch() to an int.

The syntax for topgen is a block `{...}` among the parameters in the
top table.  It looks like the syntax of LLgen, but topgen doesn't
allow nested blocks, so declarations like `struct whatever {...};`
don't work.  The token OPEN_BRACKET that begins a declaration_block
doesn't conflict with the LETTER that begins a parameter_line or the
'%' that begins a separator.

Because a block writes a #line command to gen.h, a parameter line now
also writes a #line command to gen.h, so it doesn't get a wrong line
number from a previous block.
2019-10-30 18:36:55 -04:00
George Koehler 777d0abb00 Add util/int/switch.h to declare do_instr() and Do???()
Use switch.h to reduce warnings from clang about implicit declarations
of functions.  I used `grep ... do_*.c | sed ... | sort`, and some
manual editing, to make the big list of Do???() functions.
2019-10-30 18:36:55 -04:00
George Koehler 36f16b0cb8 Cut down some clang warnings
Edit C code to reduce warnings from clang.  Most warnings are for
implicit declarations of functions, but some warnings want me to add
parentheses or curly braces, or to cast arguments for printf().

Make a few other changes, like declaring float_cst() in h/con_float to
be static, and using C99 bool in ego/ra/makeitems.c and
ego/share/makecldef.c.  Such changes don't silence warnings; I make
such changes while I silence warnings in the same file.  In
float_cst(), rename parameter `str` to `float_str`, so it doesn't
share a name with the global variable `str`.

Remove `const` from `newmodule(const char *)` in mach/proto/as to
silence a warning.  I wrongly added the `const` in d347207.

For warnings about implicit declarations of functions, the fix is to
declare the function before calling it.  For example, my OpenBSD
system needs <sys/wait.h> to declare wait().

In util/int, add "whatever.h" to declare more functions.  Remove old
declarations from "mem.h", to prefer the newer declarations of the
same functions in "data.h" and "stack.h".
2019-10-30 18:36:38 -04:00
George Koehler 8bb395b147 LLgen: use size_t, reduce warnings, other small changes
Use C89 size_t for sizes from sizeof() or to malloc() or realloc().
Remove obsolete (unsigned) casts.  Sizes were unsigned int in
traditional C but are size_t in C89.

Silence some clang warnings.  Add the second pair of round brackets in
`while ((ff = ff->ff_next))` to silence -Wparentheses.  Change
`if (nc_first(...))/*nothing*/;` to `(void)nc_first(...);` to silence
-Wempty-body.  The code in compute.c nc_first() had the form
`if (x) if (y) s; else t;`.  The old indentation (before 10717cc)
suggests that the "else" belongs to the 2nd "if", so add braces like
`if (x) { if (y) s; else t; }` to silence -Wdangling-else.

Shuffle extern function declarations.  Add missing declaration for
LLparse().  Stop declaring RENAME(); it doesn't exist.  Move some
declarations from main.c to extern.h, so the C compiler may check that
the declarations are compatible with the function definitions.

Assume that standard C89 remove() is available and doesn't need the
UNLINK() wrapper.

In lib/incl, don't need to include <stdio.h> nor <stdlib.h> to use
assert().

Remove alloc.h.  If you don't clean your build, then an outdated
BUILDDIR/obj/util/LLgen/headers/alloc.h will survive but should not
cause harm, because nothing includes it.  Don't need to remove alloc.h
from util/LLgen/distr.sh, because it isn't there.

Run the bootstrap to rebuild LLgen.c, Lpars.c, tokens.c.
2019-10-22 15:32:23 -04:00
George Koehler eb520a343d Add ACK target util/LLgen+bootstrap
The ACK builds an internal LLgen without installing it.  The new
target would rebuild LLgen's own parser using the ACK's internal
LLgen.  Keep bootstrap.sh, which uses an installed LLgen.  The new
target is more convenient for those who build the ACK but don't build
and install a separate LLgen.
2019-10-21 18:15:52 -04:00
carl 0223069d29 Cleanup of modified code fixing several overflow checking issues. 2019-06-16 01:27:49 +08:00
carl 3133141a08 Interpreter fixes according to EM testsuit. 2019-06-16 01:20:53 +08:00
carl 55eb19acf8 * Fix merge conflict issue. 2019-06-16 01:19:15 +08:00
carl ef246bd8e2 Closes #193 (signed integer shift left does not correctly check overflow in the interpreter when shifting by 0 bits), Closes #192 (integer division overflow is not handled in the interpreter and crashes it) and closes #194 (lar instruction does not accept negative bounds in interpreter when doing array index checking). 2019-06-16 01:03:01 +08:00
carl 08b9482ac7 Merge remote-tracking branch 'upstream/default' into default
Conflicts:
	util/arch/archiver.c
2019-06-15 23:53:35 +08:00
carl 53d2894ed1 ANSI C conversion. 2019-05-11 01:18:01 +08:00
carl 21e15965cc ANSI C conversion and add procedure declarations. 2019-05-11 01:17:40 +08:00
carl 472654c366 ANSI C conversion and add procedure declarations. 2019-05-11 01:17:24 +08:00
carl 0301827482 ANSI C conversion. 2019-05-11 01:15:51 +08:00
carl 970e7da896 Adapt to new object API 2019-05-11 01:15:18 +08:00
carl 16f89747b1 ANSI C conversion. 2019-05-11 01:14:54 +08:00
carl fa2859df79 ANSI C conversion. 2019-05-11 01:14:01 +08:00
carl dfefbcae86 ANSI C conversion. 2019-05-11 01:13:43 +08:00
carl f9916fb680 Fix call to fwrite with proper parameters. 2019-05-11 01:12:48 +08:00
carl 2330d35ade * Fix compilation warning. 2019-05-11 00:49:10 +08:00
carl 715717a4f6 Read beyond buffer bugfix. 2019-03-31 00:53:09 +08:00
carl 496795f0cf Fix memory overflow error. 2019-03-26 00:59:16 +08:00
carl 415ec163a7 Fix tabs. 2019-03-26 00:58:36 +08:00
carl 97cb247b39 Merge remote-tracking branch 'upstream/default' into default
# Conflicts:
#	util/arch/archiver.c
2019-03-25 00:04:41 +08:00
carl 5ec9de401d * More ANSI C portability fixes. 2019-03-24 23:53:13 +08:00
carl f7e4fac687 Revert "* Adapt to more ANSI C"
This reverts commit da0e0ac257.
2019-03-24 23:39:04 +08:00
carl a58ad2bc31 * Adapt to more ANSI C 2019-03-24 23:36:52 +08:00
carl da0e0ac257 * Adapt to more ANSI C 2019-03-24 23:35:59 +08:00
carl 56e64a1fd0 Merge remote-tracking branch 'upstream/default' into carl-ansi-part1
# Conflicts:
#	util/arch/archiver.c
#	util/led/finish.c
#	util/led/output.c
2019-03-24 21:42:56 +08:00
carl 9b6e1774ea ANSI C version
More portability fixes.
2019-03-24 17:37:49 +08:00
carl 53fa893738 ANSI C version
More portability fixes.
2019-03-24 17:11:56 +08:00
carl 7063301f8c Add additional defines for compilation. 2019-03-24 17:09:29 +08:00
carl 086a2ac9ab Add additional defines for compilation. 2019-03-24 17:09:12 +08:00
carl c5f5bace63 Add additional defines for compilation. 2019-03-24 17:08:45 +08:00
George Koehler bec236c108 Include more headers to declare functions.
This causes clang to give fewer warnings of implicit declarations of
functions.

In mach/pdp/cv/cv.c, rename wr_int2() to cv_int2() because it
conflicts with wr_int2() in <object.h>.

In util/ack, rename F_OK to F_TRANSFORM because it conflicts with F_OK
for access() in <unistd.h>.
2019-03-22 15:59:35 -04:00
George Koehler dd328215d8 Use %zu to print size_t count
This silences a compiler warning.
2019-03-22 14:09:50 -04:00
carl b3814af1ba * Bugfix of "rename" across volumes, now simply copies the file instead. 2019-03-17 23:19:16 +08:00
carl 8b525f59c3 + ANSI C conversion 2019-03-17 22:46:32 +08:00
carl 3ac4504a5a + ANSI C conversion 2019-03-17 22:46:32 +08:00
carl 5a18b85b3f + ANSI C conversion 2019-03-17 22:46:32 +08:00