tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] tcc produces incorrect output


From: Herman ten Brugge
Subject: Re: [Tinycc-devel] tcc produces incorrect output
Date: Tue, 27 Dec 2022 08:33:27 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0

On 12/21/22 19:28, Kyle J. McKay wrote:
Here's the reproduction recipe:

/* bug.c */
#include <stdint.h>
#include <stdio.h>

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 <stddef.h>
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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]