Re: [Tinycc-devel] Fwd: TCC VLA bug?

2021-12-07 Thread grischka

Michael Matz wrote:

So, the problematic type was:

  int (*)[a][b]

That's pointer to an vla-array of an vla-array of int.  All three (inner
array, outer array and pointer, but not the int) should be marked
VT_VLA.


Hm...,

IMO one (very) invariant convention is that VT_ARRAY rsp. VT_VLA
always also have VT_PTR.

Therefor if the outer pointer would have VT_VLA as you say above,
then it would be not a pointer to a VLA, but it would be a VLA,
as in

int arr[z][a][b];

Anyway, now that I already did look into it (which initially I was
trying to avoid ;) I would maybe just replace all this:


if (type1.ref->type.t & VT_VLA)
vla_runtime_pointed_size();
else {
u = pointed_size();
if (u < 0)
tcc_error("unknown array element size");
   #if PTR_SIZE == 8
vpushll(u);
   #else
/* XXX: cast to int ? (long long case) */
vpushi(u);
   #endif


by that single line:

vla_runtime_type_size(pointed_type([-1].type), ):

which looks as it would do the right thing automatically also for the
normal array (non-vla) case (but except the "unknown array size" check).

Of course one could rename "vla_runtime_type_size" to something better, then.

Btw, now that I already did look into it (which initially ... ;) I think
I found 2 related problems as can be seen with this (added to the original
test case):

// int (*arr)[h][w];
printf("diff = %d, size = %d/%d\n",
arr + 1 - arr, sizeof *arr, sizeof (*arr + 1));

-- gr



In TCC we collapse the outer array+pointer into one type (a
pointer that also has VT_ARRAY/VT_VLA set), so there actually should be
two levels: the inner level a VT_VLA pointing to the VT_INT (with its
VLA runtime length being evaluated to sizeof(int) * b) and the outer
level a VT_VLA pointing to the inner VT_VLA (and its VLA runtime length
being evaluated to inner length * a).

I'm surprised that your patch didn't cause other problems, it seems
either the testsuite isn't testing VLAs very much, or that the VT_VLA
flag is set on types where it shouldn't have been (e.g. on the VT_INT
type that is in the type->ref of the 'int [n]' array type).


Ciao,
Michael.




___
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


Re: [Tinycc-devel] Fwd: TCC VLA bug?

2021-12-07 Thread Kyryl Melekhin
Hello Michael Matz,

On a side note about tcc and VLA, I have reported a valgrind bug
on their mailing list. But there might be a chance that it is
actually tcc bug, though I could not find any incorrect behavior
in my programs compiled by tcc.

I think it's quite normal for valgrind to complain about VLAs
generated by tcc on x86_64? 

Here's the archived emails:
https://sourceforge.net/p/valgrind/mailman/message/37382347/
https://sourceforge.net/p/valgrind/mailman/message/37382384/
https://sourceforge.net/p/valgrind/mailman/message/37382663/
https://sourceforge.net/p/valgrind/mailman/message/37382912/

John did not update on the results of further investigation
and I suppose he did hit a hard wall.

What's your opinion on the matter? I am not awfully familiar
with tcc's VLA implementation itself, but it does something
that triggers valgrind to think there are uninitialized values
when it's not actually possible.

Kind Regards,
Kyryl.

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


Re: [Tinycc-devel] How exactly inline works and should I inline all the time?

2021-12-07 Thread Michael Matz

Hey,

On Tue, 7 Dec 2021, Antoni Gual Via wrote:


Perhaps it's  time to have a new official release?Antoni


Perhaps, but not because inlining would be done now: it isn't.  TCC 
doesn't inline functions into others.  But due to how c99 and c11 have 
special requirement for functions marked "inline" the keyword isn't 
completely ignored either, but it still doesn't cause called functions to 
be integrated into their callers.


Inline asm is something else (and doesn't use an "inline" keyword 
anyway), it simply describes the fact that you can write assembler 
instructions in C files, "in line" with the C sources, and don't have to 
resort writing .s files.



Ciao,
Michael.



[icon-envelope-tick-round-orange-animated-no-repeat-v1.gif] Libre de 
virus. www.avast.com


Missatge de l'adreça  del dia dt., 7 de des. 2021
a les 10:44:
  Probably in 0.9.27 (which is almost 4 years old, btw
  -17-Dec-2017 08:27-) :

  http://download.savannah.nongnu.org/releases/tinycc/
  https://repo.or.cz/tinycc.git ("release_0_9_27" tag)

  Yet it officially supports inlined assembly, that also uses the
  'inline' keyword, hence not completely "ignored".

  Anyway, if you look at the tcc source code (tccgen.c, tccpp.c,
  ...) there is already plenty of "inline" inside.

  Regards.

  - Mail d'origine -
  De: Antoni Gual Via 
  À: tinycc-devel@nongnu.org
  Envoyé: Tue, 07 Dec 2021 09:32:35 +0100 (CET)
  Objet: Re: [Tinycc-devel] How exactly inline works and should I
  inline all the time?

  Have I missed anything?
  The documentation for TCC 0.27 states that the inline keyword is
  ignored

  Antonio



  Libre
  de virus. www.avast.com

  <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

  Missatge de Antonio Prates  del dia
  dt., 7 de des.
  2021 a les 0:35:

  > Also note you can't inline recursive functions, and other
  restrictions
  > could apply.
  >
  > Maybe have a look into this thread on quora:
  > https://www.quora.com/Can-a-inline-function-be-recursive
  >
  > On Dec 6 2021, at 6:23 pm, david.k...@libertysurf.fr wrote:
  >
  > > Inline is used very specifically where the code has to be
  fast.
  > >
  > > Best is only to inline tiny parts of code that will be
  "inlined".
  > >
  > > That's to say "injected" into the source code where it is
  needed.
  > >
  > > Otherwise it is a full jump to a distant function, with
  context saving.
  > >
  > > Hence the "inlining" only serves a very specific purpose.
  > >
  > > Regards.
  > >
  > > - Mail d'origine -
  > > De: rempas via Tinycc-devel 
  > > À: Tinycc Devel 
  > > Cc: rem...@tutanota.com
  > > Envoyé: Mon, 06 Dec 2021 09:35:19 +0100 (CET)
  > > Objet: [Tinycc-devel] How exactly inline works and should I
  inline all
  > > the time?
  > >
  > > Hi!
  > >
  > > I don't know if we must only post questions that are
  specific to the
  > > TCC compiler
  > > specifically (even tho this question can differ from
  compiler to
  > > compiler) or we can
  > > make questions about C in general and in the case that the
  first is
  > > true then please
  > > inform me so I know. Anyway I wanted to ask how inline works
  > > specifically and not
  > > generally. I know generally that it "puts the source code"
  inline so
  > > we don't have to use
  > > "jmp" but is there anything else to it that I should know?
  Are there
  > > any dangers or reasons
  > > than someone should not use it? Also is there a way to tell
  the
  > > compiler to inline every
  > > function rather than always having to add the "inline"
  keyword?
  > >
  > > ___
  > > 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
  >


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


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org

Re: [Tinycc-devel] Fwd: TCC VLA bug?

2021-12-07 Thread Michael Matz

Hey,

On Sun, 5 Dec 2021, Herman ten Brugge via Tinycc-devel wrote:


On 12/1/21 15:18, grischka wrote:
  Got this report on private email.  Not sure what it means ...
  -->>

  Output of the code below if compiled with TCC is pretty messy:
  array values are "misplaced" and overwrite each other.
  But everything's ok if compiled with GCC.


The patch below seems to fix it. Can I push it?

    Herman

diff --git a/tccgen.c b/tccgen.c
index e0b5fd6..67e205b 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -3494,7 +3494,7 @@ redo:
gen_cast_s(VT_INT);
#endif
type1 = vtop[-1].type;
-    if (vtop[-1].type.t & VT_VLA)
+    if (vtop[-1].type.ref->type.t & VT_VLA)
vla_runtime_pointed_size([-1].type);


Hmm, that would mean the VT_VLA flags are wrongly set.  The invariant of 
vla_runtime_pointed_size(type...) is that type->t has VT_VLA (and that 
type->ref is meaningful).  If your patch helps in this situation that 
means the flag setting is going wrong somewhere.  I see that the testcase 
has doubly-vla types, maybe only the innermost level is marked, but a 
variable length type is of course variably length if any of the referred 
types is, so maybe that's the problem.  Just speculation, though.


So, the problematic type was:

  int (*)[a][b]

That's pointer to an vla-array of an vla-array of int.  All three (inner 
array, outer array and pointer, but not the int) should be marked VT_VLA. 
In TCC we collapse the outer array+pointer into one type (a pointer that 
also has VT_ARRAY/VT_VLA set), so there actually should be two levels: the 
inner level a VT_VLA pointing to the VT_INT (with its VLA runtime length 
being evaluated to sizeof(int) * b) and the outer level a VT_VLA pointing 
to the inner VT_VLA (and its VLA runtime length being evaluated to inner 
length * a).


I'm surprised that your patch didn't cause other problems, it seems 
either the testsuite isn't testing VLAs very much, or that the VT_VLA 
flag is set on types where it shouldn't have been (e.g. on the VT_INT type 
that is in the type->ref of the 'int [n]' array type).



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


Re: [Tinycc-devel] How exactly inline works and should I inline all the time?

2021-12-07 Thread Antoni Gual Via
Perhaps it's  time to have a new official release?
Antoni


Libre
de virus. www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Missatge de l'adreça  del dia dt., 7 de des.
2021 a les 10:44:

> Probably in 0.9.27 (which is almost 4 years old, btw -17-Dec-2017 08:27-) :
>
> http://download.savannah.nongnu.org/releases/tinycc/
> https://repo.or.cz/tinycc.git ("release_0_9_27" tag)
>
> Yet it officially supports inlined assembly, that also uses the 'inline'
> keyword, hence not completely "ignored".
>
> Anyway, if you look at the tcc source code (tccgen.c, tccpp.c, ...) there
> is already plenty of "inline" inside.
>
> Regards.
>
> - Mail d'origine -
> De: Antoni Gual Via 
> À: tinycc-devel@nongnu.org
> Envoyé: Tue, 07 Dec 2021 09:32:35 +0100 (CET)
> Objet: Re: [Tinycc-devel] How exactly inline works and should I inline all
> the time?
>
> Have I missed anything?
> The documentation for TCC 0.27 states that the inline keyword is
> ignored
>
> Antonio
>
>
> <
> https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail
> >
> Libre
> de virus. www.avast.com
> <
> https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail
> >
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> Missatge de Antonio Prates  del dia dt., 7 de
> des.
> 2021 a les 0:35:
>
> > Also note you can't inline recursive functions, and other restrictions
> > could apply.
> >
> > Maybe have a look into this thread on quora:
> > https://www.quora.com/Can-a-inline-function-be-recursive
> >
> > On Dec 6 2021, at 6:23 pm, david.k...@libertysurf.fr wrote:
> >
> > > Inline is used very specifically where the code has to be fast.
> > >
> > > Best is only to inline tiny parts of code that will be "inlined".
> > >
> > > That's to say "injected" into the source code where it is needed.
> > >
> > > Otherwise it is a full jump to a distant function, with context saving.
> > >
> > > Hence the "inlining" only serves a very specific purpose.
> > >
> > > Regards.
> > >
> > > - Mail d'origine -
> > > De: rempas via Tinycc-devel 
> > > À: Tinycc Devel 
> > > Cc: rem...@tutanota.com
> > > Envoyé: Mon, 06 Dec 2021 09:35:19 +0100 (CET)
> > > Objet: [Tinycc-devel] How exactly inline works and should I inline all
> > > the time?
> > >
> > > Hi!
> > >
> > > I don't know if we must only post questions that are specific to the
> > > TCC compiler
> > > specifically (even tho this question can differ from compiler to
> > > compiler) or we can
> > > make questions about C in general and in the case that the first is
> > > true then please
> > > inform me so I know. Anyway I wanted to ask how inline works
> > > specifically and not
> > > generally. I know generally that it "puts the source code" inline so
> > > we don't have to use
> > > "jmp" but is there anything else to it that I should know? Are there
> > > any dangers or reasons
> > > than someone should not use it? Also is there a way to tell the
> > > compiler to inline every
> > > function rather than always having to add the "inline" keyword?
> > >
> > > ___
> > > 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
> >
>
>
> ___
> 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] Re : Re: How exactly inline works and should I inline all the time?

2021-12-07 Thread david . koch
Probably in 0.9.27 (which is almost 4 years old, btw -17-Dec-2017 08:27-) :

http://download.savannah.nongnu.org/releases/tinycc/
https://repo.or.cz/tinycc.git ("release_0_9_27" tag)

Yet it officially supports inlined assembly, that also uses the 'inline' 
keyword, hence not completely "ignored".

Anyway, if you look at the tcc source code (tccgen.c, tccpp.c, ...) there is 
already plenty of "inline" inside.

Regards.

- Mail d'origine -
De: Antoni Gual Via 
À: tinycc-devel@nongnu.org
Envoyé: Tue, 07 Dec 2021 09:32:35 +0100 (CET)
Objet: Re: [Tinycc-devel] How exactly inline works and should I inline all the 
time?

Have I missed anything?
The documentation for TCC 0.27 states that the inline keyword is ignored

Antonio



Libre
de virus. www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Missatge de Antonio Prates  del dia dt., 7 de des.
2021 a les 0:35:

> Also note you can't inline recursive functions, and other restrictions
> could apply.
>
> Maybe have a look into this thread on quora:
> https://www.quora.com/Can-a-inline-function-be-recursive
>
> On Dec 6 2021, at 6:23 pm, david.k...@libertysurf.fr wrote:
>
> > Inline is used very specifically where the code has to be fast.
> >
> > Best is only to inline tiny parts of code that will be "inlined".
> >
> > That's to say "injected" into the source code where it is needed.
> >
> > Otherwise it is a full jump to a distant function, with context saving.
> >
> > Hence the "inlining" only serves a very specific purpose.
> >
> > Regards.
> >
> > - Mail d'origine -
> > De: rempas via Tinycc-devel 
> > À: Tinycc Devel 
> > Cc: rem...@tutanota.com
> > Envoyé: Mon, 06 Dec 2021 09:35:19 +0100 (CET)
> > Objet: [Tinycc-devel] How exactly inline works and should I inline all
> > the time?
> >
> > Hi!
> >
> > I don't know if we must only post questions that are specific to the
> > TCC compiler
> > specifically (even tho this question can differ from compiler to
> > compiler) or we can
> > make questions about C in general and in the case that the first is
> > true then please
> > inform me so I know. Anyway I wanted to ask how inline works
> > specifically and not
> > generally. I know generally that it "puts the source code" inline so
> > we don't have to use
> > "jmp" but is there anything else to it that I should know? Are there
> > any dangers or reasons
> > than someone should not use it? Also is there a way to tell the
> > compiler to inline every
> > function rather than always having to add the "inline" keyword?
> >
> > ___
> > 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
>


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


Re: [Tinycc-devel] How exactly inline works and should I inline all the time?

2021-12-07 Thread Antoni Gual Via
Have I missed anything?
The documentation for TCC 0.27 states that the inline keyword is ignored

Antonio



Libre
de virus. www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Missatge de Antonio Prates  del dia dt., 7 de des.
2021 a les 0:35:

> Also note you can't inline recursive functions, and other restrictions
> could apply.
>
> Maybe have a look into this thread on quora:
> https://www.quora.com/Can-a-inline-function-be-recursive
>
> On Dec 6 2021, at 6:23 pm, david.k...@libertysurf.fr wrote:
>
> > Inline is used very specifically where the code has to be fast.
> >
> > Best is only to inline tiny parts of code that will be "inlined".
> >
> > That's to say "injected" into the source code where it is needed.
> >
> > Otherwise it is a full jump to a distant function, with context saving.
> >
> > Hence the "inlining" only serves a very specific purpose.
> >
> > Regards.
> >
> > - Mail d'origine -
> > De: rempas via Tinycc-devel 
> > À: Tinycc Devel 
> > Cc: rem...@tutanota.com
> > Envoyé: Mon, 06 Dec 2021 09:35:19 +0100 (CET)
> > Objet: [Tinycc-devel] How exactly inline works and should I inline all
> > the time?
> >
> > Hi!
> >
> > I don't know if we must only post questions that are specific to the
> > TCC compiler
> > specifically (even tho this question can differ from compiler to
> > compiler) or we can
> > make questions about C in general and in the case that the first is
> > true then please
> > inform me so I know. Anyway I wanted to ask how inline works
> > specifically and not
> > generally. I know generally that it "puts the source code" inline so
> > we don't have to use
> > "jmp" but is there anything else to it that I should know? Are there
> > any dangers or reasons
> > than someone should not use it? Also is there a way to tell the
> > compiler to inline every
> > function rather than always having to add the "inline" keyword?
> >
> > ___
> > 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
>
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel