bugTiny C Compiler - Bugs: bug #58606, __builtin_constant_p is buggy on...

 
 

bug #58606: __builtin_constant_p is buggy on argument with side effect and constant value

Submitter:  Vincent Lefèvre <vinc17>
Submitted:  Wed 17 Jun 2020 02:41:10 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 29 Nov 2022 06:24:43 PM UTC, comment #1: 

I fixed it on:
git clone git://repo.or.cz/tinycc.git


Herman ten Brugge <hermantb>
Wed 17 Jun 2020 02:41:10 PM UTC, original submission:  

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 <vinc17>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by hermantb (Posted a comment)
  • -email is unavailable- added by vinc17 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code