[PATCH] Builtins and C++ and such (take 2)

Roger Sayle roger@eyesopen.com
Sun Mar 24 07:11:00 GMT 2002


> Here's the full version of the patch to enable built-ins in g++ in
> both the global and std namespaces.

One nice (safe) feature of this implementation, is that in g++
a built-in is only enabled/recognized if its definition exactly
matches the prototype expected by the compiler.  Declaring the
built-in identifiers as different types or as functions with
different arguments or return types is therefore safe, as the
anticipated declaration is overwritten, and no transformations
are applied by the compiler. This is much stricter than the C
front-end.  I know both Joseph Myers and Gabriel Dos Reis had
concerns about this.

An example of this is demonstrated by the changes to the test suite
below.  In the original code, the prototype for printf doesn't precisely
match what the compiler is expecting, this is fine with the compiler
but it won't apply printf optimizations such as printf("Hello world!\n")
into puts("Hello world!").  However changing the prototypes to
extern "C" int printf(const char*, ...) enables these transforms.

Another example is that unfortunately Kaveh's transformations of
fprintf are never applied by the g++ front-end.  The expected built-in
prototypes use void* instead of FILE*, not knowing the actual defintion
of FILE when the compiler is built.  As a result, this prototype
almost never matches the actual definition given in <stdio.h>.


The following patch doesn't need to be applied, and is primarily posted
as on-line documentation.  But these changes better reflect the intentions
of the original tests.


2002-03-24  Roger Sayle  <roger@eyesopen.com>
	* g++.old-deja/g++.other/vbase5.C: Fix printf prototype.
	* g++.dg/opt/alias2.C: And fix the same thing here.


*** gcc/gcc/testsuite/g++.dg/opt/alias2.C	Mon Mar 18 15:25:50 2002
--- patch/gcc/testsuite/g++.dg/opt/alias2.C	Sat Mar 23 06:15:20 2002
***************
*** 1,7 ****
  // { dg-do run }
  // { dg-options "-O2" }

! extern "C" int printf (...);

  struct _Deque_iterator {
    int _M_cur;
--- 1,7 ----
  // { dg-do run }
  // { dg-options "-O2" }

! extern "C" int printf (const char*, ...);

  struct _Deque_iterator {
    int _M_cur;
*** gcc/gcc/testsuite/g++.old-deja/g++.other/vbase5.C	Fri Jan 19 06:32:53 2001
--- patch/gcc/testsuite/g++.old-deja/g++.other/vbase5.C	Sat Mar 23 06:23:40 2002
***************
*** 5,11 ****
  // vbases. Normally that's just a pessimization, unfortunately during
  // constructoring it leads to uninitialized reads.

! extern "C" int printf (...);

  int fail = 0;

--- 5,11 ----
  // vbases. Normally that's just a pessimization, unfortunately during
  // constructoring it leads to uninitialized reads.

! extern "C" int printf (const char*, ...);

  int fail = 0;


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833



More information about the Gcc-patches mailing list