Re: [Tinycc-devel] tcc produces incorrect output

2022-12-26 Thread Herman ten Brugge via Tinycc-devel

On 12/21/22 19:28, Kyle J. McKay wrote:

Here's the reproduction recipe:

/* bug.c */
#include 
#include 

struct squash {
uintptr_t bug;
};

static const struct squash bug = {(uintptr_t)(void *)"4321"};

int main()
{
printf("bug.bug = 0x%llx\n", (unsigned long long)bug.bug);
return 0;
}

#!/bin/sh
# bug.sh
PS4= && set -vx
${CC:-tcc} -o bug -Wall bug.c && ./bug "$@"

$ CC=gcc ./bug.sh
${CC:-tcc} -o bug -Wall bug.c && ./bug "$@"
gcc -o bug -Wall bug.c
./bug
bug.bug = 0x5606e048b004

$ CC=clang ./bug.sh
${CC:-tcc} -o bug -Wall bug.c && ./bug "$@"
clang -o bug -Wall bug.c
./bug
bug.bug = 0x556d5b578016

$ CC=pcc ./bug.sh
${CC:-tcc} -o bug -Wall bug.c && ./bug "$@"
pcc -o bug -Wall bug.c
./bug
bug.bug = 0x402022

tcc version 0.9.27 mob:909d58dd 2022-12-20T07:34:41+01:00 (x86_64 Linux)
$ ./bug.sh
${CC:-tcc} -o bug -Wall bug.c && ./bug "$@"
tcc -o bug -Wall bug.c
./bug
bug.bug = 0x31323334
# 0x31323334 is just the four ASCII values for '1' '2' '3' '4'
# and obviously wrong, it should be the address of the "4321" string

I tested out gcc and it allows these:

char var[] = "";
unsigned char var[] = "";
signed char var[] = "";

#include 
wchar_t var[] = L"";
int var[] = L"";

On the system I tested, wchar_t is apparently an int.

Any other type for the "[]" array and gcc spits an error.

--Kyle

P.S. If someone can provide a pointer to where to look in the sources 
to fix this, I'll take a stab at it, but not being familiar with the 
tcc sources at all, I'm posting this bug instead.



It looks this is mentioned at tccgen.c:7481
I do not know how to fix this.


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


Re: [Tinycc-devel] randomly failing tests

2022-12-26 Thread Herman ten Brugge via Tinycc-devel

On 12/7/22 16:06, Vincent Lefevre wrote:

Tests are failing randomly on Debian/x86_64:

[...]
Test: 107_stack_safe...
Test: 108_constructor...
Test: 109_float_struct_calling...
Test: 110_average...
Test: 111_conversion...
Test: 112_backtrace...
--- 108_constructor.expect  2022-12-07 15:57:51.358297673 +0100
+++ 108_constructor.output  2022-12-07 16:03:55.125155438 +0100
@@ -1,3 +1 @@
-constructor
-main
-destructor
+/bin/sh: 1: ./a.exe: Text file busy
make[3]: *** [Makefile:131: 108_constructor.test] Error 1
Test: 113_btdll...
Test: 115_bound_setjmp...
Test: 114_bound_signal...
Test: 116_bound_setjmp2...
Test: 117_builtins...
Test: 118_switch...
Test: 119_random_stuff...
Test: 120_alias...
Test: 121_struct_return...
Test: 122_vla_reuse...
--- 114_bound_signal.expect 2022-12-07 15:57:51.358297673 +0100
+++ 114_bound_signal.output 2022-12-07 16:03:55.169155305 +0100
@@ -1,2 +1,5 @@
-start
-end
+in target function
+in target function
+in target function
+in target function
+in target function
make[3]: *** [Makefile:131: 114_bound_signal.test] Error 1
Test: 123_vla_bug...
Test: 124_atomic_counter...
[...]


Are you using parallel build?
This does not work for the testsuite .

    Herman


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


Re: [Tinycc-devel] Large files causes infinite loop on mac

2022-12-26 Thread Herman ten Brugge via Tinycc-devel

On 12/27/22 05:45, Levo D wrote:

I'm messing around with tcc. I don't need this to be fixed, I just thought 
someone may want the report. I'm trying to figure out how fast the tcc backend 
is for my compiler.
I seem to hit an infinite loop on mac osx venture. I built tcc earlier this 
month (Dec 2022). I suspect it's an overflow bug. Here's how to reproduce, on 
linux x86-64 it errors out at a smaller number.

Run the following python script (I copied it below) 
https://bolinlang.com/genc.py

python3 ./genc.py 220 4

Create object files then try to link. It'll loop forever

tcc -c *.c
tcc *.o

You can try building it straight which will build but won't execute

$ tcc *.c
$ ./a.out
dyld[4330]: dyld cache '(null)' not loaded: syscall to map cache into shared 
region failed
dyld[4330]: Library not loaded: /usr/lib/libSystem.B.dylib
   Referenced from:  /private/tmp/t/test/a.out
   Reason: tried: '/usr/lib/libSystem.B.dylib' (no such file), 
'/System/Volumes/Preboot/Cryptexes/OS/usr/lib/libSystem.B.dylib' (no such 
file), '/usr/lib/libSystem.B.dylib' (no such file, no dyld cache), 
'/usr/local/lib/libSystem.B.dylib' (no such file)
Abort trap: 6

Using a smaller number everything works fine. I'll repeat that I'm just playing 
around and don't need this to work. Here's a copy paste of the python script

I fixed the forever loop.
The code now compiles but does not run. I get:

dyld[74088]: dyld cache '/System/Library/dyld/dyld_shared_cache_arm64e' 
not loaded: syscall to map cache into shared region failed

dyld[74088]: Library not loaded: '/usr/lib/libSystem.B.dylib'
  Referenced from: '/Users/hermantb/tinycc/tst/a.out'
  Reason: tried: '/usr/lib/libSystem.B.dylib' (no such file), 
'/usr/local/lib/libSystem.B.dylib' (no such file)

Abort trap: 6

Probably because the bss section is larger then 4G.

I also tried to compile you code with gcc/clang on fedora(x86_64) and 
also get overflow reports when compiling.

So probably there is a limit some where. I did not check.

So if gcc/clang cannot compile the code tcc can fail as well.


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


[Tinycc-devel] Large files causes infinite loop on mac

2022-12-26 Thread Levo D
I'm messing around with tcc. I don't need this to be fixed, I just thought 
someone may want the report. I'm trying to figure out how fast the tcc backend 
is for my compiler.
I seem to hit an infinite loop on mac osx venture. I built tcc earlier this 
month (Dec 2022). I suspect it's an overflow bug. Here's how to reproduce, on 
linux x86-64 it errors out at a smaller number.

Run the following python script (I copied it below) 
https://bolinlang.com/genc.py

python3 ./genc.py 220 4

Create object files then try to link. It'll loop forever

tcc -c *.c
tcc *.o

You can try building it straight which will build but won't execute

$ tcc *.c
$ ./a.out 
dyld[4330]: dyld cache '(null)' not loaded: syscall to map cache into shared 
region failed
dyld[4330]: Library not loaded: /usr/lib/libSystem.B.dylib
  Referenced from:  /private/tmp/t/test/a.out
  Reason: tried: '/usr/lib/libSystem.B.dylib' (no such file), 
'/System/Volumes/Preboot/Cryptexes/OS/usr/lib/libSystem.B.dylib' (no such 
file), '/usr/lib/libSystem.B.dylib' (no such file, no dyld cache), 
'/usr/local/lib/libSystem.B.dylib' (no such file)
Abort trap: 6

Using a smaller number everything works fine. I'll repeat that I'm just playing 
around and don't need this to work. Here's a copy paste of the python script

import sys, math, random
if len(sys.argv) != 3:
print("Error: example usage lineAmount fileAmount", file=sys.stderr)
exit(0)

random.seed(32384)
lineAmount=int(sys.argv[1])
fileAmount=int(sys.argv[2])
nextOpenIndex=0
nextFunctionIndex=0
fileIndex=0
file=0
functionNumbers=[]
functionStartIndex=0

for i in range(0, lineAmount):
if i == nextOpenIndex:
if fileIndex != 0:
file.close()
file=open(f"file{fileIndex}.c", "wt")
fileIndex += 1
nextOpenIndex = math.ceil((fileIndex/fileAmount)*lineAmount)

if i == nextFunctionIndex:
functionStartIndex = i
file.write(f"int test{i}() {{\n")
nextFunctionIndex = min(nextFunctionIndex + 
math.floor(random.random()*1600)+500, nextOpenIndex)
file.write(f"\tstatic int array[{nextFunctionIndex}];\n")
functionNumbers.append(i)
file.write(f"\tarray[{i-functionStartIndex}] = {i*3};\n")
if i == nextFunctionIndex-1:
r = math.floor(random.random()*nextFunctionIndex)
file.write(f"\treturn array[{r}];\n")
file.write(f"}}\n")

for i in functionNumbers:
file.write(f"int test{i}();\n")
file.write("int main() {\n")
for i in functionNumbers:
file.write(f"\ttest{i}();\n")
file.write("}\n")


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