That did not help. It seems that there is a problem on ARM or Apple
Silicon, specifically:

#include <stdio.h>
int main() {
  printf("%%lu: %lu\n", sizeof("this is a string"));
  printf("%%d: %d\n", sizeof("this is a string"));
  printf("%%zu: %zu\n", sizeof("this is a string"));
}


CLANG:

$ clang tcc-string-literal-sizeof.c ; and ./a.out
tcc-string-literal-sizeof.c:4:23: warning: format specifies type 'int' but
the argument has type 'unsigned long' [-Wformat]
  printf("%%d: %d\n", sizeof("this is a string"));
               ~~     ^~~~~~~~~~~~~~~~~~~~~~~~~~
               %lu
1 warning generated.
%lu: 17
%d: 17
%zu: 17

GCC:

$ gcc tcc-string-literal-play.c ; and ./a.out
tcc-string-literal-play.c: In function ‘main’:
tcc-string-literal-play.c:5:17: warning: format ‘%d’ expects argument of
type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
    5 |   printf("%%d: %d\n", sizeof("this is a string"));
      |                ~^     ~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                 |     |
      |                 int   long unsigned int
      |                %ld
%lu: 17
%d: 17
%zu: 17

TCC (on Linux x86_64):

$ ./tcc -run ../tcc-string-literal-play.c
%lu: 17
%d: 17
%zu: 17

TCC (on macOS w/ Apple Silicon):

$ tcc -run tcc-string-literal-sizeof.c
%lu: 6165754624
%d: 1870787328
%zu: 6165754624

$ tcc -run tcc-string-literal-sizeof.c
%lu: 6127891200
%d: 1832923904
%zu: 6127891200

$tcc -run tcc-string-literal-sizeof.c
%lu: 6100595456
%d: 1805628160
%zu: 6100595456

$ tcc tcc-string-literal-sizeof.c
FIXME: handle reloc type 9 at 1052 [0x60000155c032] to 1050

-- Karl

On Thu, Aug 4, 2022 at 11:55 AM Volodymyr Boyko <boyko....@gmail.com> wrote:

> replace %d with %zu
> br
>
> On Thu, Aug 4, 2022 at 12:47 PM Karl Yerkes <karl.yer...@gmail.com> wrote:
>
>> I am using...
>>
>> tcc version 0.9.27 HEAD:d3e940c (AArch64 Darwin)
>>
>> I want to know the size of a string literal:
>>
>> #include <stdio.h>
>> int main() {
>>   printf("%d\n", sizeof("this is a string"));
>> }
>>
>> With clang, I see 17.
>> With tcc, I see 1828565760 (a different large, wrong number each time I
>> execute).
>>
>> Is this expected behavior or a known issue? Should I use an older or
>> newer version of TCC?
>>
>> And just out of curiosity, does anyone have a tool that does a binary
>> search of TCC versions to find which version introduced a regression?
>>
>> -- Karl
>>
>>
>> _______________________________________________
>> Tinycc-devel mailing list
>> Tinycc-devel@nongnu.org
>> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>>
> _______________________________________________
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to