This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[lto] Add dejagnu support for multi-file tests


This patch adds initial support for tests that encompass more
than one file.  The principle is fairly straightforward.  All the
files in the test must have the same base name and end in '_N',
where N is an integer.

Quoting from the README file:

---------------------------------------------------------------------------
This directory contains tests for link-time optimization (LTO).
Tests in this directory may span multiple files, so the naming of
the files is significant.

The name of every file must end with '_N' where N is an integer.
All the files with the same name base and different _N suffixes
will be compiled separately and linked together to form the final
executable.

By default, each set of files will be compiled with list of
options listed in LTO_OPTIONS (../../lib/lto.exp), which can be
overwritten in the shell environment or using the 'dg-options'
command in the main file of the set (i.e., the file with _0
suffix).

For example, given the files a_0.C a_1.C a_2.C, they will be
compiled as:

$ g++ -c <flags> a_0.C
$ g++ -c <flags> a_1.C
$ g++ -c <flags> a_2.C
$ g++ -o <executable> a_0.o a_1.o a_2.o

Tests that do not need more than one file are a special case
where there is a single file named 'foo_0.C'.

The only supported dg-do option are 'compile', 'run' and 'link'.
Additionally, these can only be used in the main file.  If
'compile' is used, only the individual object files are
generated.  If 'link' is used, the final executable is generated
but not executed (in this case, function main() needs to exist
but it does not need to do anything).  If 'run' is used, the
final executable is generated and the resulting binary executed.

The default value for dg-do is 'run'.
---------------------------------------------------------------------------

Following Janis's suggestion, I stole a significant amount of
code from lib/compat.exp.  I am sure that I'm doing more than a
few things in non-standard ways, but this works and lets us start
adding multifile tests.

Janis, I would appreciate if you can go over lib/lto.exp,
gcc.dg/lto/lto.exp and g++.dg/lto/lto.exp to point out what I
should change.  Thanks.

This patch only adds the initial support without any actual
multi-file tests.  Those are coming in a subsequent patch, as I
didn't want to make this bigger than it already is.  Most of the
bulk in this patch is the renaming I had to do to support the new
scheme.  The code in the existing tests has not changed.

Tested on x86_64.


Diego.


	* lib/lto.exp: New.
	* gcc.dg/lto/lto.exp: Use multi-file support from lib/lto.exp.
	* g++.dg/lto/lto.exp: Use multi-file support from lib/lto.exp
	* g++.dg/lto/README: New.
	* gcc.dg/lto/README: New.
	* g++.dg/lto/20080709_0.C: Rename from 20080709.C.
	* g++.dg/lto/20080829_0.C: Rename from 20080829.C.
	* g++.dg/lto/20080904_0.C: Rename from 20080904.C.
	* g++.dg/lto/20080907_0.C: Rename from 20080907.C.
	* g++.dg/lto/20080908-1_0.C: Rename from 20080908-1.C
	* g++.dg/lto/20080908-2_0.C: Rename from 20080908-2.C.
	* g++.dg/lto/20080908-3_0.C: Rename from 20080908-3.C.
	* g++.dg/lto/20080909-1_0.C: Rename from 20080909-1.C.
	* g++.dg/lto/20080910-1_0.C: Rename from 20080910-1.C.
	* g++.dg/lto/20080912-1_0.C: Rename from 20080912-1.C.
	* g++.dg/lto/20080912_0.C: Rename from 20080912.C.
	* g++.dg/lto/20080915_0.C: Rename from 20080915.C.
	* g++.dg/lto/20080916_0.C: Rename from 20080916.C.
	* g++.dg/lto/20080917_0.C: Rename from 20080917.C.
	* g++.dg/lto/20080924_0.C: Rename from 20080924.C.
	* g++.dg/lto/20080926_0.C: Rename from 20080926.C.
	* g++.dg/lto/20081008_0.C: Rename from 20081008.C.
	* gcc.dg/lto/20080908_0.c: Rename from 20080908.c.
	* gcc.dg/lto/20080917_0.c: Rename from 20080917.c.
	* gcc.dg/lto/20080924_0.c: Rename from 20080924.c.
	* gcc.dg/lto/20081024_0.c: Rename from 20081024.c.

Index: gcc.dg/lto/20081024.c
===================================================================
--- gcc.dg/lto/20081024.c	(revision 141691)
+++ gcc.dg/lto/20081024.c	(working copy)
@@ -1,26 +0,0 @@
-/* { dg-do run } */
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-
-char *
-myprintf (const char *fmt, ...)
-{
-  va_list args;
-  static char buf[80];
-
-  va_start (args, fmt);
-  (void) vsnprintf (buf, sizeof (buf), fmt, args);
-  va_end (args);
-  return buf;
-}
-
-int
-main ()
-{
-  char *s;
-
-  s = myprintf ("%s: %d\n", "foo", 1);
-  return strcmp (s, "foo: 1\n") != 0;
-}
Index: gcc.dg/lto/20080924_0.c
===================================================================
--- gcc.dg/lto/20080924_0.c	(revision 141643)
+++ gcc.dg/lto/20080924_0.c	(working copy)
@@ -1,4 +1,4 @@
-/* { dg-do assemble }  */
+/* { dg-do compile }  */
 /* { dg-options "-O2 -flto-single -funsigned-char" }  */ 
 typedef unsigned int size_t;
 foo (const char *src, unsigned char *dst, size_t size)
Index: gcc.dg/lto/20080924.c
===================================================================
--- gcc.dg/lto/20080924.c	(revision 141691)
+++ gcc.dg/lto/20080924.c	(working copy)
@@ -1,9 +0,0 @@
-/* { dg-do assemble }  */
-/* { dg-options "-O2 -flto-single -funsigned-char" }  */ 
-typedef unsigned int size_t;
-foo (const char *src, unsigned char *dst, size_t size)
-{
-  int ch;
-  while ((ch = *src++) != '\0') {
-  }
-}
Index: gcc.dg/lto/lto.exp
===================================================================
--- gcc.dg/lto/lto.exp	(revision 141691)
+++ gcc.dg/lto/lto.exp	(working copy)
@@ -1,36 +1,51 @@
-#   Copyright (C) 1997,2002,2003, 2007 Free Software Foundation, Inc.
+# Copyright (C) 2008 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>
 
-# GCC testsuite that uses the `dg.exp' driver.
 
-# Load support procs.
-load_lib gcc-dg.exp
+# Test link-time optimization across multiple files.
+#
+# Programs are broken into multiple files.  Each one is compiled
+# separately with LTO information.  The final executable is generated
+# by collecting all the generated object files using regular LTO or WHOPR.
 
-# If a testcase doesn't have special options, use these.
-global DEFAULT_LTOFLAGS
-if ![info exists DEFAULT_LTOFLAGS] then {
-    set DEFAULT_LTOFLAGS "-flto-single -pedantic-errors"
+if $tracelevel then {
+    strace $tracelevel
 }
 
-# Initialize `dg'.
-dg-init
+# Load procedures from common libraries. 
+load_lib standard.exp
+load_lib gcc.exp
+
+# Load the language-independent compabibility support procedures.
+load_lib lto.exp
+
+gcc_init
+
+# Define an identifier for use with this suite to avoid name conflicts
+# with other lto tests running at the same time.
+set sid "c_lto"
 
 # Main loop.
-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] \
-	"" $DEFAULT_LTOFLAGS
+foreach src [lsort [find $srcdir/$subdir *_0.c]] {
+    # If we're only testing specific files and this isn't one of them, skip it.
+    if ![runtest_file_p $runtests $src] then {
+	continue
+    }
 
-# All done.
-dg-finish
+    lto-execute $src $sid
+}
Index: gcc.dg/lto/20080908_0.c
===================================================================
--- gcc.dg/lto/20080908_0.c	(revision 141643)
+++ gcc.dg/lto/20080908_0.c	(working copy)
@@ -1,7 +1,4 @@
-/* { dg-do assemble } */
-/* FIXME lto.  We should use 'dg-do compile', but -S and -flto-single
-   confuse cc1 because the flags specify two different output files.  */
-
+/* { dg-do compile } */
 void foo(void) {
  char *bar;
  int baz;
Index: gcc.dg/lto/20080917_0.c
===================================================================
--- gcc.dg/lto/20080917_0.c	(revision 141643)
+++ gcc.dg/lto/20080917_0.c	(working copy)
@@ -1,4 +1,4 @@
-/* { dg-do assemble }  */
+/* { dg-do compile }  */
 /* { dg-options "-O2 -flto-single -funsigned-char" }  */ 
 int
 foo (char *s, int flag)
Index: gcc.dg/lto/20080908.c
===================================================================
--- gcc.dg/lto/20080908.c	(revision 141691)
+++ gcc.dg/lto/20080908.c	(working copy)
@@ -1,19 +0,0 @@
-/* { dg-do assemble } */
-/* FIXME lto.  We should use 'dg-do compile', but -S and -flto-single
-   confuse cc1 because the flags specify two different output files.  */
-
-void foo(void) {
- char *bar;
- int baz;
- while (1)
-   {
-     if (baz)
-       {
-         baz = -baz;
-         do
-           *bar++ = 0;
-         while (++baz);
-       }
-     ++baz;
-   }
-}
Index: gcc.dg/lto/20080917.c
===================================================================
--- gcc.dg/lto/20080917.c	(revision 141691)
+++ gcc.dg/lto/20080917.c	(working copy)
@@ -1,29 +0,0 @@
-/* { dg-do assemble }  */
-/* { dg-options "-O2 -flto-single -funsigned-char" }  */ 
-int
-foo (char *s, int flag)
-{
-  for (;;)
-    {
-      unsigned char c;
-      if (flag)
-	c = *s;
-      else
-	c = *s;
-      return c;
-    }
-}
-
-int
-baz (const char *s, int flag)
-{
-  for (;;)
-    {
-      unsigned char c;
-      if (flag)
-	c = *s;
-      else
-	c = *s;
-      return c;
-    }
-}
Index: gcc.dg/lto/README
===================================================================
--- gcc.dg/lto/README	(revision 0)
+++ gcc.dg/lto/README	(revision 0)
@@ -0,0 +1,35 @@
+This directory contains tests for link-time optimization (LTO).
+Tests in this directory may span multiple files, so the naming of
+the files is significant.
+
+The name of every file must end with '_N' where N is an integer.
+All the files with the same name base and different _N suffixes
+will be compiled separately and linked together to form the final
+executable.
+
+By default, each set of files will be compiled with list of
+options listed in LTO_OPTIONS (../../lib/lto.exp), which can be
+overwritten in the shell environment or using the 'dg-options'
+command in the main file of the set (i.e., the file with _0
+suffix).
+
+For example, given the files a_0.C a_1.C a_2.C, they will be
+compiled as:
+
+$ g++ -c <flags> a_0.C
+$ g++ -c <flags> a_1.C
+$ g++ -c <flags> a_2.C
+$ g++ -o <executable> a_0.o a_1.o a_2.o
+
+Tests that do not need more than one file are a special case
+where there is a single file named 'foo_0.C'.
+
+The only supported dg-do option are 'compile', 'run' and 'link'.
+Additionally, these can only be used in the main file.  If
+'compile' is used, only the individual object files are
+generated.  If 'link' is used, the final executable is generated
+but not executed (in this case, function main() needs to exist
+but it does not need to do anything).  If 'run' is used, the
+final executable is generated and the resulting binary executed.
+
+The default value for dg-do is 'run'.
Index: g++.dg/lto/20080904.C
===================================================================
--- g++.dg/lto/20080904.C	(revision 141691)
+++ g++.dg/lto/20080904.C	(working copy)
@@ -1,37 +0,0 @@
-// { dg-do run }
-
-/* This test will fail to link if the vtable for Derived is not emitted.  */
-
-class Base {
-public:
-  Base(char *buf, unsigned len)
-    : _buf(buf),
-      _len(len)
-  {}
-
-  virtual int length () { return _len; }
-
-private:
-  char * _buf;
-  unsigned _len;
-};
-
-class Derived : public Base {
-public:
-  Derived(char *buf, unsigned len)
-    : Base(buf, len),
-      _ctr(len)
-  {}
-
-  virtual int length () { return _ctr; }
-
-private:
-  unsigned _ctr;
-};
-
-int main ()
-{
-  Derived *d = new Derived (new char[256], 256);
-
-  return 0;
-}
Index: g++.dg/lto/20080924.C
===================================================================
--- g++.dg/lto/20080924.C	(revision 141691)
+++ g++.dg/lto/20080924.C	(working copy)
@@ -1,16 +0,0 @@
-// { dg-do assemble }
-// { dg-options "-O2 -flto-single -fno-strict-aliasing" }
-
-namespace ns
-{
-  template <class> class hash_set { };
-}
-
-struct Foo
-{
-  long long f1, f2, f3;
-};
-
-void func(ns::hash_set<int>) {
-  Foo foo = { 0, 0, 0 };
-}
Index: g++.dg/lto/20080908-1.C
===================================================================
--- g++.dg/lto/20080908-1.C	(revision 141691)
+++ g++.dg/lto/20080908-1.C	(working copy)
@@ -1,36 +0,0 @@
-/* { dg-do run }  */
-extern "C" { extern void *memcpy (void *, const void *, unsigned); }
-
-inline int
-bci (const float &source)
-{
- int dest;
- memcpy (&dest, &source, sizeof (dest));
- return dest;
-}
-
-inline float
-bcf (const int &source)
-{
- float dest;
- memcpy (&dest, &source, sizeof (dest));
- return dest;
-}
-
-float
-Foo ()
-{
- const int foo = bci (0.0f);
- int bar = foo;
- const int baz = foo & 1;
- if (!baz && (foo & 2))
-   bar = 0;
- return bcf (bar);
-}
-
-int main ()
-{
-  if (Foo () != 0.0)
-    return 1;
-  return 0;
-}
Index: g++.dg/lto/lto.exp
===================================================================
--- g++.dg/lto/lto.exp	(revision 141691)
+++ g++.dg/lto/lto.exp	(working copy)
@@ -1,35 +1,52 @@
-#   Copyright (C) 1997,2002,2003, 2007 Free Software Foundation, Inc.
+# Copyright (C) 2002, 2004, 2007 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>
 
-# GCC testsuite that uses the `dg.exp' driver.
 
-# Load support procs.
-load_lib g++-dg.exp
+# Test link-time optimization across multiple files.
+#
+# Programs are broken into multiple files.  Each one is compiled
+# separately with LTO information.  The final executable is generated
+# by collecting all the generated object files using regular LTO or WHOPR.
 
-# If a testcase doesn't have special options, use these.
-global DEFAULT_LTOFLAGS
-if ![info exists DEFAULT_LTOFLAGS] then {
-    set DEFAULT_LTOFLAGS "-flto-single -pedantic-errors"
+if $tracelevel then {
+    strace $tracelevel
 }
 
-# Initialize `dg'.
-dg-init
+# Load procedures from common libraries. 
+load_lib standard.exp
+load_lib g++.exp
+load_lib target-libpath.exp
+
+# Load the language-independent compabibility support procedures.
+load_lib lto.exp
+
+g++_init
+
+# Define an identifier for use with this suite to avoid name conflicts
+# with other lto tests running at the same time.
+set sid "cp_lto"
 
 # Main loop.
-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C]] "" $DEFAULT_LTOFLAGS
+foreach src [lsort [find $srcdir/$subdir *_0.C]] {
+    # If we're only testing specific files and this isn't one of them, skip it.
+    if ![runtest_file_p $runtests $src] then {
+	continue
+    }
 
-# All done.
-dg-finish
+    lto-execute $src $sid
+}
Index: g++.dg/lto/20080909-1.C
===================================================================
--- g++.dg/lto/20080909-1.C	(revision 141691)
+++ g++.dg/lto/20080909-1.C	(working copy)
@@ -1,3 +0,0 @@
-// { dg-do assemble }
-// { dg-options "-flto-single" }
-int *i = (int[]) {0};
Index: g++.dg/lto/20080908-2.C
===================================================================
--- g++.dg/lto/20080908-2.C	(revision 141691)
+++ g++.dg/lto/20080908-2.C	(working copy)
@@ -1,3 +0,0 @@
-/* { dg-do assemble }  */
-struct Foo { double x[3]; };
-Foo func() { Foo f = { { 0, 0, 0 } }; return f; }
Index: g++.dg/lto/20080907.C
===================================================================
--- g++.dg/lto/20080907.C	(revision 141691)
+++ g++.dg/lto/20080907.C	(working copy)
@@ -1,3 +0,0 @@
-// { dg-do assemble }
-struct Foo { void func (); }; Foo & bar () { } struct Baz { Baz (Baz &); };
-Baz dummy() { bar().func(); }
Index: g++.dg/lto/20080709.C
===================================================================
--- g++.dg/lto/20080709.C	(revision 141691)
+++ g++.dg/lto/20080709.C	(working copy)
@@ -1,11 +0,0 @@
-// { dg-do run }
-
-class Init     {
-};
-
-int f(Init *a) {
-}
-
-int main(void){
-  return 0;
-}
Index: g++.dg/lto/20080908-3.C
===================================================================
--- g++.dg/lto/20080908-3.C	(revision 141691)
+++ g++.dg/lto/20080908-3.C	(working copy)
@@ -1,14 +0,0 @@
-/* { dg-do run }  */
-
-int foo()
-{
- double bar, baz = -__builtin_huge_val();
- return baz <= -bar;
-}
-
-int main()
-{
-  if (foo () != 1)
-    return 1;
-  return 0;
-}
Index: g++.dg/lto/20080926.C
===================================================================
--- g++.dg/lto/20080926.C	(revision 141691)
+++ g++.dg/lto/20080926.C	(working copy)
@@ -1,4 +0,0 @@
-// { dg-do assemble }
-// { dg-options "-O2 -flto-single -fno-strict-aliasing" }
-extern int foo();
-void bar() { try { int i = foo(); } catch(int) { } }
Index: g++.dg/lto/20080829.C
===================================================================
--- g++.dg/lto/20080829.C	(revision 141691)
+++ g++.dg/lto/20080829.C	(working copy)
@@ -1,11 +0,0 @@
-// FIXME lto.  We should really use 'compile' instead of 'assemble', but
-// -S confuses cc1plus.
-// { dg-do assemble }
-
-/* The replacement of cos+sin with __builtin_cexpi done by
-   pass_cse_sincos was using a builtin for which we had no attributes.
-   This was causing the operand scanner to materialize a VDEF at the
-   builtin call-site which was not marked for renaming, thus tripping
-   up the SSA verifier.  */
-extern "C" { extern double cos (double); extern double sin (double); }
-double func(double &in) { return cos(in) + sin(in); }
Index: g++.dg/lto/20080910-1_0.C
===================================================================
--- g++.dg/lto/20080910-1_0.C	(revision 141643)
+++ g++.dg/lto/20080910-1_0.C	(working copy)
@@ -1,4 +1,2 @@
-// FIXME lto.  We should really use 'compile' instead of 'assemble', but
-// -S confuses cc1plus.
-// { dg-do assemble }
+// { dg-do compile }
 struct Foo { Foo(int); }; void func() { new Foo(0); }
Index: g++.dg/lto/20081008_0.C
===================================================================
--- g++.dg/lto/20081008_0.C	(revision 141643)
+++ g++.dg/lto/20081008_0.C	(working copy)
@@ -1,4 +1,4 @@
-// { dg-do assemble }
+// { dg-do compile }
 // { dg-options "-flto-single" }
 
 struct Foo
Index: g++.dg/lto/20080912-1_0.C
===================================================================
--- g++.dg/lto/20080912-1_0.C	(revision 141643)
+++ g++.dg/lto/20080912-1_0.C	(working copy)
@@ -1,3 +1,3 @@
-// { dg-do assemble }
+// { dg-do compile }
 struct Foo { double x[3]; };
 Foo func() { Foo f = { { 0, 0, 0 } }; return f; }
Index: g++.dg/lto/20080912_0.C
===================================================================
--- g++.dg/lto/20080912_0.C	(revision 141643)
+++ g++.dg/lto/20080912_0.C	(working copy)
@@ -1,4 +1,4 @@
-// { dg-do assemble }
+// { dg-do compile }
 class Foo { virtual void f(); };
 class Bar:public Foo { };
 void func() { Bar(); }
Index: g++.dg/lto/20080915_0.C
===================================================================
--- g++.dg/lto/20080915_0.C	(revision 141643)
+++ g++.dg/lto/20080915_0.C	(working copy)
@@ -1,4 +1,4 @@
-// { dg-do assemble }
+// { dg-do compile }
 struct Foo {
  static const int dummy;
 
Index: g++.dg/lto/20080916_0.C
===================================================================
--- g++.dg/lto/20080916_0.C	(revision 141643)
+++ g++.dg/lto/20080916_0.C	(working copy)
@@ -1,6 +1,4 @@
-/* { dg-do assemble } */
-/* FIXME lto.  We should use 'dg-do compile', but -S and -flto-single
-   confuse cc1 because the flags specify two different output files.  */
+/* { dg-do compile } */
 
 enum _Ios_Fmtflags     {
  _S_boolalpha };
Index: g++.dg/lto/20080917_0.C
===================================================================
--- g++.dg/lto/20080917_0.C	(revision 141643)
+++ g++.dg/lto/20080917_0.C	(working copy)
@@ -1,4 +1,4 @@
-// { dg-do assemble }
+// { dg-do compile }
 // { dg-options "-O2 -flto-single -funsigned-char" }
 int
 foo (char *s, int flag)
Index: g++.dg/lto/20080910-1.C
===================================================================
--- g++.dg/lto/20080910-1.C	(revision 141691)
+++ g++.dg/lto/20080910-1.C	(working copy)
@@ -1,4 +0,0 @@
-// FIXME lto.  We should really use 'compile' instead of 'assemble', but
-// -S confuses cc1plus.
-// { dg-do assemble }
-struct Foo { Foo(int); }; void func() { new Foo(0); }
Index: g++.dg/lto/20081008.C
===================================================================
--- g++.dg/lto/20081008.C	(revision 141691)
+++ g++.dg/lto/20081008.C	(working copy)
@@ -1,36 +0,0 @@
-// { dg-do assemble }
-// { dg-options "-flto-single" }
-
-struct Foo
-{
- virtual void func() = 0;
-};
-
-struct Bar
-{
- Foo *field;
- void func2();
-};
-
-struct Baz
-{
- Bar &bar();
- Baz();
-};
-
-struct Zonk
-{
- virtual ~Zonk() {
- }
- virtual void func3() = 0;
-};
-
-void Mumble(Zonk *) {
-}
-
-extern "C"
-{
- void __attribute__ ((nothrow)) __cxa_pure_virtual() {
-   Baz().bar().func2();
- }
-}
Index: g++.dg/lto/20080912-1.C
===================================================================
--- g++.dg/lto/20080912-1.C	(revision 141691)
+++ g++.dg/lto/20080912-1.C	(working copy)
@@ -1,3 +0,0 @@
-// { dg-do assemble }
-struct Foo { double x[3]; };
-Foo func() { Foo f = { { 0, 0, 0 } }; return f; }
Index: g++.dg/lto/20080912.C
===================================================================
--- g++.dg/lto/20080912.C	(revision 141691)
+++ g++.dg/lto/20080912.C	(working copy)
@@ -1,4 +0,0 @@
-// { dg-do assemble }
-class Foo { virtual void f(); };
-class Bar:public Foo { };
-void func() { Bar(); }
Index: g++.dg/lto/20080915.C
===================================================================
--- g++.dg/lto/20080915.C	(revision 141691)
+++ g++.dg/lto/20080915.C	(working copy)
@@ -1,29 +0,0 @@
-// { dg-do assemble }
-struct Foo {
- static const int dummy;
-
- int bit_field:1;
- int dummy2:1;
- int dummy3:1;
-};
-
-struct Bar {
- Foo foo;
-};
-
-int func(const Bar& b) {
- return b.foo.bit_field;
-}
-
-struct Baz {
- Bar& operator*() {}
-};
-
-void func1(Baz baz, int i, Bar bar) {
- i || func(bar);
- *baz = bar;
-}
-
-void func2(Baz baz, Bar bar) {
- func1(baz, 0, bar);
-}
Index: g++.dg/lto/20080916.C
===================================================================
--- g++.dg/lto/20080916.C	(revision 141691)
+++ g++.dg/lto/20080916.C	(working copy)
@@ -1,14 +0,0 @@
-/* { dg-do assemble } */
-/* FIXME lto.  We should use 'dg-do compile', but -S and -flto-single
-   confuse cc1 because the flags specify two different output files.  */
-
-enum _Ios_Fmtflags     {
- _S_boolalpha };
-
-class ios_base   {
- static const  _Ios_Fmtflags boolalpha =   _S_boolalpha;
- _Ios_Fmtflags _M_flags;
-};
-
-ios_base& g() {
-}
Index: g++.dg/lto/20080917.C
===================================================================
--- g++.dg/lto/20080917.C	(revision 141691)
+++ g++.dg/lto/20080917.C	(working copy)
@@ -1,29 +0,0 @@
-// { dg-do assemble }
-// { dg-options "-O2 -flto-single -funsigned-char" }
-int
-foo (char *s, int flag)
-{
-  for (;;)
-    {
-      unsigned char c;
-      if (flag)
-	c = *s;
-      else
-	c = *s;
-      return c;
-    }
-}
-
-int
-baz (const char *s, int flag)
-{
-  for (;;)
-    {
-      unsigned char c;
-      if (flag)
-	c = *s;
-      else
-	c = *s;
-      return c;
-    }
-}
Index: g++.dg/lto/README
===================================================================
--- g++.dg/lto/README	(revision 0)
+++ g++.dg/lto/README	(revision 0)
@@ -0,0 +1,35 @@
+This directory contains tests for link-time optimization (LTO).
+Tests in this directory may span multiple files, so the naming of
+the files is significant.
+
+The name of every file must end with '_N' where N is an integer.
+All the files with the same name base and different _N suffixes
+will be compiled separately and linked together to form the final
+executable.
+
+By default, each set of files will be compiled with list of
+options listed in LTO_OPTIONS (../../lib/lto.exp), which can be
+overwritten in the shell environment or using the 'dg-options'
+command in the main file of the set (i.e., the file with _0
+suffix).
+
+For example, given the files a_0.C a_1.C a_2.C, they will be
+compiled as:
+
+$ g++ -c <flags> a_0.C
+$ g++ -c <flags> a_1.C
+$ g++ -c <flags> a_2.C
+$ g++ -o <executable> a_0.o a_1.o a_2.o
+
+Tests that do not need more than one file are a special case
+where there is a single file named 'foo_0.C'.
+
+The only supported dg-do option are 'compile', 'run' and 'link'.
+Additionally, these can only be used in the main file.  If
+'compile' is used, only the individual object files are
+generated.  If 'link' is used, the final executable is generated
+but not executed (in this case, function main() needs to exist
+but it does not need to do anything).  If 'run' is used, the
+final executable is generated and the resulting binary executed.
+
+The default value for dg-do is 'run'.
Index: g++.dg/lto/20080924_0.C
===================================================================
--- g++.dg/lto/20080924_0.C	(revision 141643)
+++ g++.dg/lto/20080924_0.C	(working copy)
@@ -1,4 +1,4 @@
-// { dg-do assemble }
+// { dg-do compile }
 // { dg-options "-O2 -flto-single -fno-strict-aliasing" }
 
 namespace ns
Index: g++.dg/lto/20080907_0.C
===================================================================
--- g++.dg/lto/20080907_0.C	(revision 141643)
+++ g++.dg/lto/20080907_0.C	(working copy)
@@ -1,3 +1,3 @@
-// { dg-do assemble }
+// { dg-do compile }
 struct Foo { void func (); }; Foo & bar () { } struct Baz { Baz (Baz &); };
 Baz dummy() { bar().func(); }
Index: g++.dg/lto/20080908-2_0.C
===================================================================
--- g++.dg/lto/20080908-2_0.C	(revision 141643)
+++ g++.dg/lto/20080908-2_0.C	(working copy)
@@ -1,3 +1,3 @@
-/* { dg-do assemble }  */
+/* { dg-do compile }  */
 struct Foo { double x[3]; };
 Foo func() { Foo f = { { 0, 0, 0 } }; return f; }
Index: g++.dg/lto/20080909-1_0.C
===================================================================
--- g++.dg/lto/20080909-1_0.C	(revision 141643)
+++ g++.dg/lto/20080909-1_0.C	(working copy)
@@ -1,3 +1,3 @@
-// { dg-do assemble }
+// { dg-do compile }
 // { dg-options "-flto-single" }
 int *i = (int[]) {0};
Index: g++.dg/lto/20080926_0.C
===================================================================
--- g++.dg/lto/20080926_0.C	(revision 141643)
+++ g++.dg/lto/20080926_0.C	(working copy)
@@ -1,4 +1,4 @@
-// { dg-do assemble }
+// { dg-do compile }
 // { dg-options "-O2 -flto-single -fno-strict-aliasing" }
 extern int foo();
 void bar() { try { int i = foo(); } catch(int) { } }
Index: g++.dg/lto/20080829_0.C
===================================================================
--- g++.dg/lto/20080829_0.C	(revision 141643)
+++ g++.dg/lto/20080829_0.C	(working copy)
@@ -1,6 +1,4 @@
-// FIXME lto.  We should really use 'compile' instead of 'assemble', but
-// -S confuses cc1plus.
-// { dg-do assemble }
+// { dg-do compile }
 
 /* The replacement of cos+sin with __builtin_cexpi done by
    pass_cse_sincos was using a builtin for which we had no attributes.
Index: lib/lto.exp
===================================================================
--- lib/lto.exp	(revision 0)
+++ lib/lto.exp	(revision 0)
@@ -0,0 +1,376 @@
+# Copyright (C) 2002, 2003, 2004, 2005, 2007 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>
+
+
+# Each test is run with the compiler options from this list.
+# The default option lists can be overridden by LTO_OPTIONS="[list
+# {opts_1} {opts_2}... {opts_n}]" where opts_i are lists of options.
+# You can put this in the environment before site.exp is written or
+# add it to site.exp directly.
+if ![info exists LTO_OPTIONS] {
+    set LTO_OPTIONS [list	\
+    	{-O0 -fwhopr}		\
+	{-O2 -fwhopr}		\
+	{-O0 -flto}		\
+	{-O2 -flto}		\
+	{-O0 -flto-single}	\
+	{-O2 -flto-single}	\
+	]
+}
+
+set option_list $LTO_OPTIONS
+
+# Subsets of tests can be selectively disabled by members of this list:
+#  - ATTRIBUTE: disable all tests using the __attribute__ extension,
+#  - COMPLEX: disable all tests using the complex types feature,
+#  - COMPLEX_INT: disable all tests using the complex integral types extension,
+#  - VA: disable all tests using the variable number of arguments feature,
+#  - VLA_IN_STRUCT: disable all tests using the variable-length arrays as
+#    structure members extension,
+#  - ZERO_ARRAY: disable all tests using the zero-sized arrays extension.
+# The default skip lists can be overriden by
+# LTO_SKIPS="[list {skip_1}...{skip_n}]"
+# where skip_i are skip identifiers.  You can put this in the environment
+# before site.exp is written or add it to site.exp directly.
+if ![info exists LTO_SKIPS] {
+    set LTO_SKIPS [list {}]
+}
+
+global lto_skip_list
+set lto_skip_list $LTO_SKIPS
+
+load_lib dg.exp
+load_lib gcc-dg.exp
+
+# lto-obj -- compile to an object file
+#
+# SOURCE is the source file
+# DEST is the object file
+# OPTALL is the list of compiler options to use with all tests
+# OPTFILE is the list of compiler options to use with this file
+# OPTSTR is the options to print with test messages
+# XFAILDATA is the xfail data to be passed to the compiler
+proc lto-obj { source dest optall optfile optstr xfaildata } {
+    global testcase
+    global tool
+    global compiler_conditional_xfail_data
+    global lto_skip_list
+
+    # Add the skip specifiers.
+    foreach skip $lto_skip_list {
+	if { ![string match $skip ""] } {
+	    lappend optall "-DSKIP_$skip"
+	}
+    }
+
+    # Set up the options for compiling this file.
+    set options ""
+    lappend options "additional_flags=$optfile $optall"
+
+    set compiler_conditional_xfail_data $xfaildata
+    set comp_output [${tool}_target_compile "$source" "$dest" object $options]
+    ${tool}_check_compile "$testcase $dest compile" $optstr $dest $comp_output
+}
+
+# lto-link-and-maybe-run -- link the object files and run the executable
+# if compile_type is set to "run"
+#
+# TESTNAME is the mixture of object files to link
+# OBJLIST is the list of object files to link
+# DEST is the name of the executable
+# OPTALL is a list of compiler and linker options to use for all tests
+# OPTFILE is a list of compiler and linker options to use for this test
+# OPTSTR is the list of options to list in messages
+proc lto-link-and-maybe-run { testname objlist dest optall optfile optstr } {
+    global testcase
+    global tool
+    global compile_type
+
+    # Check that all of the objects were built successfully.
+    foreach obj [split $objlist] {
+	if ![file_on_host exists $obj] then {
+	    unresolved "$testcase $testname link $optstr"
+	    unresolved "$testcase $testname execute $optstr"
+	    return
+	}
+    }
+
+    # Set up the options for linking this test.
+    set options ""
+    lappend options "additional_flags=$optfile $optall"
+
+    # Link the objects into an executable.
+    set comp_output [${tool}_target_compile "$objlist" $dest executable \
+		     "$options"]
+    if ![${tool}_check_compile "$testcase $testname link" "" \
+	 $dest $comp_output] then {
+	unresolved "$testcase $testname execute $optstr"
+	return
+    }
+
+    # Return if we only needed to link.
+    if { ![string compare "link" $compile_type] } {
+	return
+    }
+
+    # Run the self-checking executable.
+    if ![string match "*/*" $dest] then {
+	set dest "./$dest"
+    }
+    set result [${tool}_load $dest "" ""]
+    set status [lindex $result 0]
+    if { $status == "pass" } then {
+	file_on_host delete $dest
+    }
+    $status "$testcase $testname execute $optstr"
+}
+
+# lto-get-options-main -- get target requirements for a test and
+# options for the primary source file and the test as a whole
+#
+# SRC is the full pathname of the primary source file.
+proc lto-get-options-main { src } {
+    global compile_type
+
+    # dg-options sets a variable called dg-extra-tool-flags.
+    set dg-extra-tool-flags ""
+
+    # dg-options sets a variable called tool_flags.
+    set tool_flags ""
+
+    # dg-require-* sets dg-do-what.
+    upvar dg-do-what dg-do-what 
+
+    verbose "getting options for $src"
+    set tmp [dg-get-options $src]
+    foreach op $tmp {
+	set cmd [lindex $op 0]
+	verbose "cmd is $cmd"
+	if { ![string compare "dg-options" $cmd] \
+	     || [string match "dg-skip-if" $cmd] \
+	     || [string match "dg-require-*" $cmd]  } {
+	    set status [catch "$op" errmsg]
+	    if { $status != 0 } {
+		perror "src: $errmsg for \"$op\"\n"
+		unresolved "$src: $errmsg for \"$op\""
+		return
+	    }
+	} elseif { ![string compare "dg-xfail-if" $cmd] } {
+	    warning "lto.exp does not support $cmd in primary source file"
+	} elseif { ![string compare "dg-do" $cmd] } {
+	    set dgdo [lindex $op 2]
+	    verbose "dg-do command for \"$op\" is $dgdo"
+	    if { ![string compare "compile" $dgdo] } {
+		set compile_type "compile"
+	    } elseif { ![string compare "run" $dgdo] } {
+		set compile_type "run"
+	    } else {
+		warning "lto.exp does not support $cmd"
+	    }
+	} else {
+	    # Ignore unrecognized dg- commands, but warn about them.
+	    warning "lto.exp does not support $cmd"
+	}
+    }
+
+    # Return flags to use for compiling the primary source file and for
+    # linking.
+    return ${dg-extra-tool-flags}
+}
+
+
+# lto-get-options -- get special tool flags to use for a secondary
+# source file
+#
+# SRC is the full pathname of the source file.
+# The result is a list of options to use.
+#
+# This code is copied from proc dg-test in dg.exp from DejaGNU.
+proc lto-get-options { src } {
+    # dg-options sets a variable called dg-extra-tool-flags.
+    set dg-extra-tool-flags ""
+
+    # dg-xfail-if sets compiler_conditional_xfail_data.
+    global compiler_conditional_xfail_data
+    set compiler_conditional_xfail_data ""
+
+    # dg-xfail-if needs access to dg-do-what.
+    upvar dg-do-what dg-do-what 
+
+    set tmp [dg-get-options $src]
+    foreach op $tmp {
+	set cmd [lindex $op 0]
+	if { ![string compare "dg-options" $cmd] \
+	     || ![string compare "dg-xfail-if" $cmd] } {
+	    set status [catch "$op" errmsg]
+	    if { $status != 0 } {
+		perror "src: $errmsg for \"$op\"\n"
+		unresolved "$src: $errmsg for \"$op\""
+		return
+	    }
+	} elseif { [string match "dg-require-*" $cmd] } {
+	    warning "lto.exp does not support $cmd in secondary source files"
+	} else {
+	    # Ignore unrecognized dg- commands, but warn about them.
+	    warning "lto.exp does not support $cmd in secondary source files"
+	}
+    }
+
+    return ${dg-extra-tool-flags}
+}
+
+# lto-execute -- compile multi-file tests
+#
+# SRC1 is the full pathname of the main file of the testcase.
+# SID identifies a test suite in the names of temporary files.
+proc lto-execute { src1 sid } {
+    global srcdir tmpdir
+    global option_list
+    global tool
+    global verbose
+    global testcase
+    global gluefile
+    global compiler_conditional_xfail_data
+    global dg-do-what-default
+    global compile_type
+
+    # Get extra flags for this test from the primary source file, and
+    # process other dg-* options that this suite supports.  Warn about
+    # unsupported flags.
+    verbose "lto-execute: $src1" 1
+    set compile_type "run"
+    set dg-do-what [list ${dg-do-what-default} "" P]
+    set extra_flags(0) [lto-get-options-main $src1]
+    set compile_xfail(0) "" 
+
+    # If the main file defines dg-options, those flags are used to
+    # overwrite the default option_list taken from LTO_OPTIONS.
+    if { [string length $extra_flags(0)] > 0 } {
+	set option_list $extra_flags(0)
+	set extra_flags(0) ""
+    }
+
+    # Check whether this test is supported for this target.
+    if { [lindex ${dg-do-what} 1 ] == "N" } {
+	unsupported "$src1"
+	verbose "$src1 not supported on this target, skipping it" 3
+	return
+    }
+
+    # Set up the names of the other source files.
+    set dir [file dirname $src1]
+    set ext [file extension $src1]
+    set base [file rootname $src1]
+    set base [string range $base [string length $dir] end]
+    regsub "_0" $base "" base
+    regsub "/" $base "" base
+    set src_list $src1
+    set i 1
+    set done 0
+    while { !$done } {
+	set name "${dir}/${base}_${i}${ext}"
+	if { [file exists ${name}] } {
+	    lappend src_list ${name}
+	    incr i
+	} else {
+	    set num_srcs ${i}
+	    set done 1
+	}
+    }
+
+    # Use the dg-options mechanism to specify extra flags for each
+    # of the secondary files.
+    # The extra flags in each file are used to compile that file, and the
+    # extra flags in *_0.* are also used for linking.
+    verbose "\tsrc_list is: $src_list"
+    for {set i 1} {$i < $num_srcs} {incr i} {
+	set extra_flags($i) [lto-get-options [lindex $src_list $i]]
+	set compile_xfail($i) $compiler_conditional_xfail_data
+    }
+
+    # Define the names of the object files.
+    set obj_list ""
+    for {set i 0} {$i < $num_srcs} {incr i} {
+	lappend obj_list "${sid}_${base}_${i}.o"
+    }
+
+    # Get the base name of this test, for use in messages.
+    set testcase [lindex ${src_list} 0]
+
+    # Remove the $srcdir and $tmpdir prefixes from $src1.  (It would
+    # be possible to use "regsub" here, if we were careful to escape
+    # all regular expression characters in $srcdir and $tmpdir, but
+    # that would be more complicated that this approach.) 
+    if {[string first "$srcdir/" "${testcase}"] == 0} {
+	set testcase [string range "${testcase}" [string length "$srcdir/"] end]
+    }
+    if {[string first "$tmpdir/" "$testcase"] == 0} {
+	set testcase [string range "$testcase" [string length "$tmpdir/"] end]
+	set testcase "tmpdir-$testcase"
+    }
+    regsub "_0.*" $testcase "" testcase
+
+    # Set up the base name of executable files so they'll be unique.
+    regsub -all "\[./\]" $testcase "-" execbase
+
+    # If we couldn't rip $srcdir out of `src1' then just do the best we can.
+    # The point is to reduce the unnecessary noise in the logs.  Don't strip
+    # out too much because different testcases with the same name can confuse
+    # `test-tool'.
+    if [string match "/*" $testcase] then {
+        set testcase "[file tail [file dirname $src1]]/[file tail $src1]"
+    }
+
+    # Loop through all of the option lists used for this test.
+    set count 0
+    foreach option $option_list {
+	verbose "Testing $testcase, $option"
+
+	# There's a unique name for each executable we generate.
+	set execname "${execbase}-${count}1"
+	incr count
+
+	file_on_host delete $execname
+
+	# Compile pieces with the compiler under test.
+	set i 0
+	foreach src $src_list obj $obj_list {
+	    lto-obj $src $obj $option $extra_flags($i) $option \
+		    $compile_xfail($i)
+	    incr i
+	}
+
+	# Link (using the compiler under test), run, and clean up tests.
+	if { ![string compare "run" $compile_type] \
+	     || ![string compare "link" $compile_type] } {
+	    lto-link-and-maybe-run \
+		    "[lindex $obj_list 0]-[lindex $obj_list end]" \
+		    $obj_list $execname $option $extra_flags(0) $option
+	}
+
+	# Clean up object files.
+	set files [glob -nocomplain ${sid}_*.o]
+	if { $files != "" } {
+	    foreach objfile $files {
+		if { ![info exists gluefile] || $objfile != $gluefile } {
+		    eval "file_on_host delete $objfile"
+		}
+	    }
+	}
+    }
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]