===================================================================
@@ -0,0 +1,79 @@
+# Copyright (C) 2011 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# Contributed by Diego Novillo <dnovillo@google.com>
+
+load_lib copy-file.exp
+
+proc dg-flags-pph { subdir test otherflags options suffix } {
+ global runtests dg-do-what-default
+
+ # If we're only testing specific files and this isn't one of them, skip it.
+ if ![runtest_file_p $runtests $test] {
+ return
+ }
+ set nshort "$subdir/[file tail $test]"
+ set bname "[file rootname [file tail $nshort]]"
+
+ foreach flags $options {
+ verbose "Testing $nshort, $otherflags $flags" 1
+
+ set dg-do-what-default compile
+
+ set have_errs [llength [grep $test "{\[ \t\]\+dg-error\[ \t\]\+.*\[ \t\]\+}"]]
+ # Compile the file the first time to produce PPH/PTH images.
+ dg-test -keep-output $test "$otherflags $flags -I." ""
+
+ if { !$have_errs } {
+ if { [ file_on_host exists "$bname.s" ] } {
+ # Rename the .s file into .s-pph to compare it after the
+ # second build.
+ remote_upload host "$bname.s" "$bname.s-pph"
+ remote_download host "$bname.s-pph"
+
+ # Compile a second time to use the generated images.
+ dg-test -keep-output $test "$otherflags $flags -I." ""
+ remote_upload host "$bname.s"
+
+ # Compare the two assembly files. They should be identical.
+ set tmp [ diff "$bname.s" "$bname.s-pph" ]
+ if { $tmp == 0 } {
+ verbose -log "assembly file '$bname.s', '$bname.s-pph' comparison error"
+ fail "$nshort $otherflags $flags assembly comparison"
+ } elseif { $tmp == 1 } {
+ pass "$nshort $otherflags $flags assembly comparison"
+ } else {
+ fail "$nshort $otherflags $flags assembly comparison"
+ }
+ file_on_host delete "$bname$suffix"
+ file_on_host delete "$bname.s"
+ file_on_host delete "$bname.s-pph"
+ } else {
+ verbose -log "assembly file '$bname.s' missing"
+ fail "$nshort $flags assembly comparison"
+ }
+ }
+
+ # Remove stale .pth files, if any.
+ foreach pth_file [glob -nocomplain *.pth] {
+ file_on_host delete $pth_file
+ }
+ }
+}
+
+proc dg-pph { subdir test options suffix } {
+ return [dg-flags-pph $subdir $test "" $options $suffix]
+}
===================================================================
@@ -39,6 +39,7 @@ set tests [prune $tests $srcdir/$subdir/
set tests [prune $tests $srcdir/$subdir/gcov/*]
set tests [prune $tests $srcdir/$subdir/lto/*]
set tests [prune $tests $srcdir/$subdir/pch/*]
+set tests [prune $tests $srcdir/$subdir/pph/*]
set tests [prune $tests $srcdir/$subdir/plugin/*]
set tests [prune $tests $srcdir/$subdir/special/*]
set tests [prune $tests $srcdir/$subdir/tls/*]
===================================================================
@@ -0,0 +1,38 @@
+# Copyright (C) 2011 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite for preparsed header interaction.
+
+# Contributed by Diego Novillo <dnovillo@google.com>
+
+# Load support procs.
+load_lib "g++-dg.exp"
+load_lib dg-pph.exp
+
+# Initialize `dg'.
+dg-init
+
+set old_dg_do_what_default "${dg-do-what-default}"
+
+# Main loop.
+foreach test [lsort [glob -nocomplain $srcdir/$subdir/*.cc]] {
+ dg-pph $subdir $test [list "-fpth" ] ".pth"
+}
+
+set dg-do-what-default "$old_dg_do_what_default"
+
+# All done.
+dg-finish
===================================================================
===================================================================
@@ -0,0 +1,5 @@
+struct D {
+ int method() { return mbr; }
+ static int mbr;
+};
+int D::mbr = 4;
===================================================================
@@ -0,0 +1,18 @@
+struct base {
+ int field;
+};
+base function();
+int base_from_var() {
+ base variable;
+}
+int base_from_func() {
+ function();
+}
+struct derived : base {
+ int method();
+};
+int derived::method() {
+ return field;
+}
+struct vderived : virtual base {
+};
===================================================================
@@ -0,0 +1,29 @@
+template< typename T >
+struct wrapper {
+ T value;
+ static T cache;
+};
+
+template< typename T >
+T wrapper<T>::cache = 3;
+
+template<>
+struct wrapper<char> {
+ int value;
+ static int cache;
+};
+
+int wrapper<char>::cache = 2;
+
+template
+struct wrapper<short>;
+
+template
+long wrapper<long>::cache;
+
+int main() {
+ wrapper<char> vc;
+ wrapper<short> vs;
+ wrapper<int> vi;
+ return 0;
+}
===================================================================
@@ -0,0 +1,2 @@
+#include <stdlib.h>
+size_t X;
===================================================================
@@ -0,0 +1,17 @@
+extern int gbl_init_extern = 3; // need body pass
+extern int gbl_uninit_extern; // head only pass
+int gbl_tentative; // need body pass
+int gbl_initial = 1; // need body pass
+extern const int gbl_extern_const; // head only pass
+const float gbl_init_const = 1.5; // need body pass
+const int gbl_manifest = 2; // lazy body merge head pass
+struct D {
+ static int mbr_init_plain; // head only pass
+ static int mbr_uninit_plain; // head only pass
+ static const int mbr_init_const; // head only pass
+ static const int mbr_uninit_const; // head only pass
+ static const int mbr_manifest = 3; // lazy body merge head okay
+};
+int D::mbr_init_plain = 4; // need body merge body pass
+int D::mbr_uninit_plain; // need body merge body FAIL
+const int D::mbr_init_const = 5; // need body merge body FAIL
===================================================================
@@ -0,0 +1,3 @@
+int main()
+{
+}
===================================================================
@@ -0,0 +1,21 @@
+namespace A {
+int x = 3;
+struct B;
+struct C {
+ B* b;
+ int method();
+ int another()
+ { return 1; }
+};
+int C::method()
+{ return 1; }
+} // namespace A
+struct D : A::C {
+ int method();
+ int another()
+ { return 1; }
+};
+int D::method()
+{ return 1; }
+int main()
+{ }
===================================================================
@@ -0,0 +1,24 @@
+namespace A {
+int x = 3;
+struct B;
+template< typename T >
+struct C {
+ T* b;
+ int method();
+ int another()
+ { return *b; }
+};
+template< typename T >
+int C< T >::method()
+{ return x; }
+} // namespace A
+int y = 4;
+struct D : A::C< int > {
+ int method();
+ int another()
+ { return *b; }
+};
+int D::method()
+{ return y; }
+int main()
+{ }
===================================================================
@@ -0,0 +1,13 @@
+#ifndef __CFLOW_H
+#define __CFLOW_H
+
+extern void foo (void);
+
+#define X 1
+#if defined X
+#include "inif.h"
+extern int var1;
+extern int var2;
+#endif
+#include "inif.h"
+#endif
===================================================================
@@ -0,0 +1,11 @@
+#ifndef SIMPLE1_H
+#define SIMPLE1_H
+
+#include "simple2.h"
+
+inline int foo()
+{
+ assert(1);
+}
+
+#endif
===================================================================
@@ -0,0 +1,7 @@
+#ifndef SIMPLE2_H
+#define SIMPLE2_H
+
+#define assert(x) yellow(x)
+extern void yellow(int);
+
+#endif
===================================================================
@@ -0,0 +1 @@
+#define ONE 1
===================================================================
@@ -0,0 +1,6 @@
+class one {
+};
+typedef one type;
+class two {
+ type fld;
+};
===================================================================
@@ -0,0 +1 @@
+#define TWO ONE
===================================================================
@@ -0,0 +1,162 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+
+static unsigned long long MAX_ITEMS = 10000;
+
+static int
+cmpdouble (const void *p1, const void *p2)
+{
+ double n1 = *((double *)p1);
+ double n2 = *((double *)p2);
+
+ if (n1 < n2)
+ return -1;
+ else if (n1 > n2)
+ return 1;
+ else
+ return 0;
+}
+
+
+double
+compute_median (int n, double vec[])
+{
+ qsort (vec, n, sizeof (double), cmpdouble);
+
+ if (n % 2 == 0)
+ return ((vec[n / 2] + vec[n / 2 - 1]) / 2.0);
+ else
+ return vec[n / 2];
+}
+
+double
+compute_stddev (int n, double avg, double vec[])
+{
+ double sd, sum, s, x;
+ int i;
+
+ for (x = 0.0, sum = 0.0, i = 0; i < n; i++)
+ {
+ double d;
+
+ x = x + vec[i];
+ d = vec[i] - avg;
+ sum += d * d;
+ }
+
+ s = sum / n;
+ sd = sqrt (s);
+
+ return sd;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ double *vec;
+ double x, sum, product, inverse_sum, arithmetic, geometric, harmonic;
+ double min, max, median, variance, stddev;
+ int count;
+ int ret;
+
+ sum = 0.0;
+ product = 1.0;
+ inverse_sum = 0.0;
+ count = 0;
+ min = 0.0;
+ max = 0.0;
+
+ vec = (double *) malloc (MAX_ITEMS * sizeof (double));
+
+ while (1)
+ {
+ ret = scanf ("%lg", &x);
+ if (ret == EOF)
+ break;
+
+ if (count == 0)
+ min = max = x;
+
+ if (x < min)
+ min = x;
+
+ if (x > max)
+ max = x;
+
+ sum += x;
+ product *= x;
+ inverse_sum += 1.0 / x;
+ vec[count] = x;
+
+ count++;
+ if (count >= MAX_ITEMS)
+ {
+ MAX_ITEMS *= 3;
+ vec = (double *) realloc (vec, MAX_ITEMS * sizeof (double));
+ }
+ }
+
+ int do_min = (strstr (argv[0], "min") != NULL);
+ int do_max = (strstr (argv[0], "max") != NULL);
+ int do_avg = (strstr (argv[0], "avg") != NULL);
+ int do_geo = (strstr (argv[0], "geoavg") != NULL);
+ int do_harmonic = (strstr (argv[0], "harmonic") != NULL);
+ int do_median = (strstr (argv[0], "median") != NULL);
+ int do_variance = (strstr (argv[0], "variance") != NULL);
+ int do_stdev = (strstr (argv[0], "stdev") != NULL);
+ int do_all = (argc > 1 && strcmp (argv[1], "-a") == 0);
+
+ if (count > 0)
+ {
+ arithmetic = sum / count;
+ geometric = pow (product, (double) 1.0 / (double) count);
+ harmonic = count / inverse_sum;
+ median = compute_median (count, vec);
+ stddev = compute_stddev (count, arithmetic, vec);
+ variance = stddev * stddev;
+
+ if (do_all)
+ {
+ printf ("# of items read --> %d\n", count);
+ printf ("Min --------------> %lg\n", min);
+ printf ("Max --------------> %lg\n", max);
+ printf ("Arithmetic mean --> %lg\n", arithmetic);
+ printf ("Geometric mean ---> %lg\n", geometric);
+ printf ("Harmonic mean ----> %lg\n", harmonic);
+ printf ("Median -----------> %lg\n", median);
+ printf ("Variance ---------> %lg\n", variance);
+ printf ("Standard dev -----> %lg\n", stddev);
+ }
+ else if (do_min)
+ printf ("%lg\n", min);
+ else if (do_max)
+ printf ("%lg\n", max);
+ else if (do_avg)
+ printf ("%lg\n", arithmetic);
+ else if (do_geo)
+ printf ("%lg\n", geometric);
+ else if (do_harmonic)
+ printf ("%lg\n", harmonic);
+ else if (do_median)
+ printf ("%lg\n", median);
+ else if (do_variance)
+ printf ("%lg\n", variance);
+ else if (do_stdev)
+ printf ("%lg\n", stddev);
+ else
+ {
+ fprintf (stderr, "ERROR: Unknown value '%s' to compute\n", argv[0]);
+ return 1;
+ }
+ }
+ else
+ {
+ fprintf (stderr, "ERROR: none of the input is positive\n");
+ return 1;
+ }
+
+ return 0;
+}
===================================================================
@@ -0,0 +1,30 @@
+struct B {
+ B( int );
+ B( double );
+ B( const B& );
+ B& operator=( const B& );
+ B& operator=( int );
+ operator double();
+ ~B();
+};
+
+struct D {
+ D( const B& );
+};
+
+int F( D );
+int G( double );
+
+B b(1);
+//B q("hhh");
+
+int H() {
+ F(b);
+ B a(3.2);
+ B c = b;
+ B d(b);
+ c = b;
+ d = 4;
+ //G(double(""));
+ G(d);
+}
===================================================================
@@ -0,0 +1,2 @@
+int y = 0;
+int x = y+1;
===================================================================
@@ -0,0 +1,2 @@
+struct B {
+};
===================================================================
@@ -0,0 +1,10 @@
+int H( int a, int b) {
+}
+
+int I( int a, int b) {
+ return a+b;
+}
+
+int F( int c, int d) {
+ return H(c, d) + I(c, d);
+}
===================================================================
@@ -0,0 +1,11 @@
+class base {
+ virtual int method() {
+ return 0;
+ }
+ int field;
+};
+void function() {
+ base var1;
+ base var2( var1 );
+ var1 = var2;
+}
===================================================================
@@ -0,0 +1,17 @@
+typedef int type;
+type val = 3;
+
+template< typename T >
+T identity(T arg)
+{ return arg + val; }
+
+template<>
+int identity< type >(type arg)
+{ return arg + val; }
+
+template
+short identity(short arg);
+
+int main() {
+ return identity( 'a' );
+}
===================================================================
@@ -0,0 +1,7 @@
+/* comment */
+#include "simple1.h"
+
+int main()
+{
+ return foo();
+}
===================================================================
@@ -0,0 +1,2 @@
+#define QUOTE(arg) #arg
+#define VALUE(arg) QUOTE(arg)
===================================================================
@@ -0,0 +1,7 @@
+const char *date = VALUE(__DATE__);
+const char *time = VALUE(__TIME__);
+const char *file = VALUE(__FILE__);
+const char *line = VALUE(__LINE__);
+const char *vers = VALUE(__cplusplus);
+const char *optm = VALUE(__OPTIMIZE__);
+const char *func() { return __func__; }
===================================================================
@@ -0,0 +1,6 @@
+#include "invoke.h"
+#define outer(major, minor) inner(major, minor)
+
+void outer(long one, short two) { }
+major(three);
+minor(four);
===================================================================
@@ -0,0 +1,3 @@
+#include "chained1.h"
+#include "chained2.h"
+int x = TWO;
===================================================================
@@ -0,0 +1,8 @@
+#include "usearray.h"
+const int x = 3;
+const int y = 10;
+float array[x + y];
+float foo (int i)
+{
+ return array[i * 3];
+}
===================================================================
@@ -0,0 +1,2 @@
+const char *refile = VALUE(__FILE__);
+const char *reline = VALUE(__LINE__);
===================================================================
@@ -0,0 +1,7 @@
+typedef int type;
+type x = 2;
+type y = x;
+type f() { return x; }
+const type n = 3;
+const type m = 4;
+type a[n+m];
===================================================================
@@ -0,0 +1,4 @@
+# define gnu_dev_major(dev) long dev
+# define gnu_dev_minor(dev) short dev
+# define major(dev) gnu_dev_major (dev)
+# define minor(dev) gnu_dev_minor (dev)
===================================================================
@@ -0,0 +1,4 @@
+typedef int type;
+class base {
+ type fld;
+};
===================================================================
@@ -0,0 +1 @@
+float foo(int);
===================================================================
@@ -0,0 +1,6 @@
+#ifndef GUARDED1_H
+#define GUARDED1_H
+
+typedef int type;
+
+#endif
===================================================================
@@ -0,0 +1,8 @@
+#ifndef GUARDED2_H
+#define GUARDED2_H
+
+#include "guarded1.h"
+
+type variable2;
+
+#endif
===================================================================
@@ -0,0 +1,8 @@
+#ifndef GUARDED3_H
+#define GUARDED3_H
+
+#include "guarded1.h"
+
+type variable3;
+
+#endif
===================================================================
@@ -0,0 +1,3 @@
+int f() {
+ static int x = 3;
+}
===================================================================
@@ -0,0 +1,3 @@
+#include "builtin1.h"
+#include "builtin2.h"
+#include "builtin3.h"
===================================================================
@@ -0,0 +1,29 @@
+struct V { int a; static int b;};
+namespace N {
+ int V;
+ struct C { };
+ int operator + (int i, C c);
+ C O;
+ int I(int arg)
+ { return arg + V; }
+ struct V w;
+ int x = V::b;
+}
+
+int V;
+struct D { };
+D P;
+int operator + (int i, D d);
+int I(int arg)
+{ return arg + V; }
+
+int F() {
+ return I(N::V + N::O);
+}
+
+int G() {
+ return I(::V + P);
+}
+
+struct V w;
+int x = V::b;
===================================================================
@@ -0,0 +1,22 @@
+extern int extern_only(int); //
+extern int extern_then_body(int); //
+inline int extern_inline(int i) // lazy body
+{ return extern_then_body(i); }
+int extern_then_body(int i) // need body, merge head to body
+{ return extern_only( i ); }
+static int fwdref_static(int);
+int fwdref_static(int i)
+{ return extern_then_body( i ); } // need body, merge head to body
+struct type {
+ int mbr_decl_only(int);
+ int mbr_decl_then_def(int);
+ inline int mbr_inl_then_def(int);
+ int mbr_decl_inline(int i) // lazy body
+ { return mbr_decl_only( i ); }
+ virtual int mbr_virtual_inline() // lazy body, but circular dependence
+ { return mbr_decl_only( 1 ); }
+};
+int type::mbr_decl_then_def(int i) // need body
+{ return mbr_decl_inline( i ); }
+int type::mbr_inl_then_def(int i) // lazy body
+{ return mbr_decl_then_def( i ); }
===================================================================
@@ -0,0 +1,9 @@
+struct T { int f; };
+#define NAME v
+#define VALUE 1
+#include "incmod.h"
+#undef NAME
+#define NAME w
+#undef VALUE
+#define VALUE 2
+#include "incmod.h"
===================================================================
@@ -0,0 +1,6 @@
+#include "cflow.h"
+
+void foo (void)
+{
+ int x = var1 + var2 - (int) f1;
+}
===================================================================
@@ -0,0 +1,2 @@
+#include "guarded2.h"
+#include "guarded3.h"
===================================================================
@@ -0,0 +1 @@
+struct T NAME = { VALUE };
===================================================================
@@ -0,0 +1,10 @@
+#define major "beef"
+#define M(major) foo##_##major##_(major)
+
+void foo_30_(int);
+void bar(void);
+
+void bar(void)
+{
+ M(30);
+}
===================================================================
@@ -0,0 +1,5 @@
+struct T { int f; };
+struct T v
+#include "incsame.h"
+struct T w
+#include "incsame.h"
===================================================================
@@ -0,0 +1 @@
+#include <sys/types.h>
===================================================================
@@ -0,0 +1 @@
+= { 1 };
===================================================================
@@ -0,0 +1,7 @@
+typedef int language;
+struct program {
+ language field;
+};
+struct client {
+ program field;
+};
===================================================================
@@ -0,0 +1,19 @@
+typedef int type;
+type gbl = 1;
+struct B {
+ type fld;
+};
+struct D : B {
+ type method();
+ type another()
+ { return fld + mbr + gbl; }
+ type fld;
+ static type mbr;
+};
+type D::method()
+{ static int x = 2;
+ return fld + mbr + gbl; }
+type D::mbr = 4;
+typedef D D2;
+D2 var1;
+D2 var2 = var1;
===================================================================
@@ -0,0 +1,2 @@
+int one;
+int two;
===================================================================
@@ -0,0 +1,11 @@
+template< typename T >
+struct C {
+ int* b;
+ int method();
+ int another()
+ { return 1; }
+};
+template< typename T >
+int C< T >::method()
+{ return 1; }
+C<int> v;
===================================================================
@@ -0,0 +1 @@
+extern float f1;