[Tinycc-devel] Commit 0c6adcb (tccgen: multi-dimensional vla: bug fixes) causes segfaults on OpenBSD

2022-03-16 Thread Brian Callahan
Hello TinyCC developers --

One of the three commits from today, 0c6adcb (tccgen: multi-dimensional
vla: bug fixes), causes tcc to segfault on OpenBSD.

Here is the test log:
```
 hello-exe 
Hello World
 hello-run 
Hello World
 libtest 
Hello World!
fib(32) = 2178309
add(32, 64) = 96
 libtest_mt 
running fib with mixed calls
  1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946
 (55 ms)
running fib in threads
  1 55 144 3 13 6765 377 21 34 5 2584 1597 10946 233 8 2 987 89 4181 610
 (49 ms)
running tcc.c in threads to run fib
 gmake[2]: *** [Makefile:95: libtest_mt] Segmentation fault (core dumped)
gmake[1]: *** [Makefile:83: all] Error 2
```

Commit ec5d942 (tccgen: accept array-size expressions in function
paramters) works OK. Also, applying commit 719d966 (tccgen: Allow struct
init from struct) directly on top of commit ec5d942 also works OK. It is
just commit 0c6adcb that is causing issues.

Please let me know if anything else is needed to help fix the issue.

Thanks.

~Brian

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Initialiser overflow bug

2022-03-16 Thread grischka

Arthur Williams via Tinycc-devel wrote:

On Thu, Mar 10, 2022 at 10:27:25AM -0800, Elijah Stone wrote:

Hi,

The following code results in an initialiser overflow ICE on the latest
version of tcc (917aad3), amd64 linux.

#include 
#include 

typedef struct { char b[2]; } Barb;

Barb *f(Barb x, Barb y) {
return memcpy(malloc(2*sizeof(Barb)), &(Barb[]){x,y}, 2*sizeof(Barb));
}

Note: if I declare char b[1] in Barb, there is no error; but the error
occurs on any larger size.


Posted about the same issue a month ago. And I believe someone had
reported the issue even before that. Last theory I heard was that the
cast might be affecting padding. I believe if you have
```
Barb temp[2] = {x,y};
```
and used temp in the memcpy you can avoid this issue. At least for me,
the fact the issue is so easy to avoid is why it isn't at the top of my
priority list.


The problem with

Barb temp[] = {x,y}

was that in the 1st pass (meant to determine the actual size)
tcc didn't realize that 'x' is meant to initialize the complete
struct.  Rather it assumed that braces were omitted and 'x'
was to initialize the first member of the struct.  It didn't really
care about the type of 'x' at that point.

Also fixed the problem mentioned elsewhere with array-size
expressions in function parameters:

   int main(int argc, char *argv[argc + 1]);

Anyway, some things get fixed, others get broken ...

-- gr



Arthur



___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel