tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] __builtin_constant_p is buggy on argument with side effec


From: Vincent Lefevre
Subject: [Tinycc-devel] __builtin_constant_p is buggy on argument with side effect and constant value
Date: Wed, 17 Jun 2020 19:03:10 +0200
User-agent: Mutt/1.14.3+64 (75be2b07) vl-127292 (2020-06-15)

FYI, I hve reported the following bug:

  https://savannah.nongnu.org/bugs/?58606

When the evaluation of a __builtin_constant_p argument would have
a side effect, this argument should not be regarded as a constant
because in practice, it may be used in an expression that evaluates
the argument several times (for instance, think of a macro to compute
min(x,y), avoiding a function call when x and y are constants). The
current tcc (8fb8d88 in mob branch) fails to behave correctly, as
shown on the following example.

#include <stdio.h>

#define FOO(X) (__builtin_constant_p (X) ? ((X), (X), (X)) : (X))

int main (void)
{
  int c = 0, i;

  i = FOO ((c++, 7));
  printf ("%d %d\n", c, i);
  return c == 1 && i == 7 ? 0 : 1;
}

With GCC and Clang, I get "1 7" since FOO ((c++, 7)) is replaced
by ((c++, 7)).

But with tcc, I get "3 7".

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



reply via email to

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