PATCH: PR 19664: Don't change visibility if set by user

H. J. Lu hjl@lucon.org
Tue Feb 8 17:56:00 GMT 2005


On Mon, Feb 07, 2005 at 01:51:10AM +0100, Giovanni Bajo wrote:
> H. J. Lu <hjl@lucon.org> wrote:
> 
> > This patch may fix visibility push(default)/pop. When visibility
> > has been set by user, we shouldn't change it.
> 
> 
> As noted in Bugzilla, this is missing a testcase.
> 

This patch adds 3 testcases:

1. With visibility push(default)/pop, it should work.
2. Without visibility push(default)/pop, it should fail.
3. Without visibility push(default)/pop + definition in another file,
it should work.

Right now only #2 passes. My patch fixes #1. #3 still doesn't work.

They are based on the testcase for PR 19520. 


H.J.
----
2005-02-07  H.J. Lu  <hongjiu.lu@intel.com>

	PR c++/19664
	* g++.special/inline-hidden-1.cc: New file.
	* g++.special/inline-hidden-1.x: Likewise.
	* g++.special/inline-hidden-2.cc: Likewise.
	* g++.special/inline-hidden-2.x: Likewise.
	* g++.special/inline-hidden-3.x: Likewise.
	* g++.special/inline-hidden-3a.cc: Likewise.
	* g++.special/inline-hidden-3b.cc: Likewise.

	PR target/19520
	* gcc.special/protfunc-1-dso.c: New file.
	* gcc.special/protfunc-1-main.c: Likewise.
	* gcc.special/protfunc-1.x: Likewise.
	* testsuite/gcc.special/special.exp: Likewise.

	* g++.special/special.exp: Likewise.

--- gcc/testsuite/g++.special/inline-hidden-1.cc.special	2005-02-07 16:31:07.422573606 -0800
+++ gcc/testsuite/g++.special/inline-hidden-1.cc	2005-02-07 16:00:38.526638151 -0800
@@ -0,0 +1,16 @@
+#pragma GCC visibility push(default)
+template<typename CharT>
+struct VisTest
+{
+  inline VisTest ();
+};
+template<typename CharT>
+inline VisTest<CharT>::VisTest()
+{}
+extern template class VisTest<char>;
+#pragma GCC visibility pop
+int some_function( int do_something )
+{
+  VisTest<char> a;
+  return 0;
+}
--- gcc/testsuite/g++.special/inline-hidden-1.x.special	2005-02-07 16:31:07.423573459 -0800
+++ gcc/testsuite/g++.special/inline-hidden-1.x	2005-02-07 16:26:13.160864966 -0800
@@ -0,0 +1,5 @@
+#
+# build shared libray
+#
+gcc-special-compile $srcdir/$subdir/inline-hidden-1.cc \
+	"-shared -fPIC -fvisibility-inlines-hidden" "" "no"
--- gcc/testsuite/g++.special/inline-hidden-2.cc.special	2005-02-07 16:31:07.427572871 -0800
+++ gcc/testsuite/g++.special/inline-hidden-2.cc	2005-02-07 16:02:50.428232978 -0800
@@ -0,0 +1,14 @@
+template<typename CharT>
+struct VisTest
+{
+  inline VisTest ();
+};
+template<typename CharT>
+inline VisTest<CharT>::VisTest()
+{}
+extern template class VisTest<char>;
+int some_function( int do_something )
+{
+  VisTest<char> a;
+  return 0;
+}
--- gcc/testsuite/g++.special/inline-hidden-2.x.special	2005-02-07 16:31:07.424573312 -0800
+++ gcc/testsuite/g++.special/inline-hidden-2.x	2005-02-07 16:26:18.434089177 -0800
@@ -0,0 +1,5 @@
+#
+# build shared libray
+#
+gcc-special-compile $srcdir/$subdir/inline-hidden-2.cc \
+	"-shared -fPIC -fvisibility-inlines-hidden" "" "yes"
--- gcc/testsuite/g++.special/inline-hidden-3.x.special	2005-02-07 16:31:07.425573165 -0800
+++ gcc/testsuite/g++.special/inline-hidden-3.x	2005-02-07 16:27:49.083752929 -0800
@@ -0,0 +1,7 @@
+#
+# build shared libray
+#
+set obj [gcc-special-compile "$srcdir/$subdir/inline-hidden-3a.cc" \
+	 "-fPIC -fvisibility-inlines-hidden" "" "no"]
+gcc-special-compile $srcdir/$subdir/inline-hidden-3b.cc \
+	"-shared -fPIC" "$obj" "no"
--- gcc/testsuite/g++.special/inline-hidden-3a.cc.special	2005-02-07 16:31:07.426573018 -0800
+++ gcc/testsuite/g++.special/inline-hidden-3a.cc	2005-02-07 16:15:04.478240594 -0800
@@ -0,0 +1,14 @@
+template<typename CharT>
+struct VisTest
+{
+  inline VisTest ();
+};
+template<typename CharT>
+inline VisTest<CharT>::VisTest()
+{}
+extern template class VisTest<char>;
+int some_function( int do_something )
+{
+  VisTest<char> a;
+  return 0;
+}
--- gcc/testsuite/g++.special/inline-hidden-3b.cc.special	2005-02-07 16:31:07.422573606 -0800
+++ gcc/testsuite/g++.special/inline-hidden-3b.cc	2005-02-07 16:15:19.335054881 -0800
@@ -0,0 +1,9 @@
+template<typename CharT>
+struct VisTest
+{
+  inline VisTest ();
+};
+template<typename CharT>
+inline VisTest<CharT>::VisTest()
+{}
+template class VisTest<char>;
--- gcc/testsuite/g++.special/special.exp.special	2005-02-07 16:31:07.425573165 -0800
+++ gcc/testsuite/g++.special/special.exp	2005-02-07 16:00:19.691409163 -0800
@@ -0,0 +1,30 @@
+# Copyright (C) 2005 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 2 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+# load support procs
+load_lib gcc-special.exp
+
+#
+# run special tests 
+#
+
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.x]] {
+    source $src
+}
--- gcc/testsuite/gcc.special/protfunc-1-dso.c.special	2005-02-07 16:31:03.742115070 -0800
+++ gcc/testsuite/gcc.special/protfunc-1-dso.c	2005-02-07 14:00:30.287570816 -0800
@@ -0,0 +1,13 @@
+void
+__attribute__ ((visibility ("protected")))
+foo ()
+{
+}
+
+void (*foo_p) () = foo;
+
+void *
+bar (void)
+{
+  return foo;
+}
--- gcc/testsuite/gcc.special/protfunc-1-main.c.special	2005-02-07 16:31:03.741115217 -0800
+++ gcc/testsuite/gcc.special/protfunc-1-main.c	2005-02-07 15:45:29.951306449 -0800
@@ -0,0 +1,14 @@
+extern void (*foo_p) (void);
+extern void foo (void);
+extern void* bar (void);
+
+int
+main ()
+{
+  void *p;
+  p = bar ();
+  if (p == foo && p == foo_p)
+    return 0;
+  else
+    return 1;
+}
--- gcc/testsuite/gcc.special/protfunc-1.x.special	2005-02-07 16:31:03.744114776 -0800
+++ gcc/testsuite/gcc.special/protfunc-1.x	2005-02-07 16:29:49.169086147 -0800
@@ -0,0 +1,10 @@
+#
+# build shared libray
+#
+set dso [gcc-special-compile $srcdir/$subdir/protfunc-1-dso.c \
+	 "-fPIC -shared -O" "" "no"]
+
+#
+# build and run executable
+#
+gcc-special-execute $srcdir/$subdir/protfunc-1-main.c $dso "-O"
--- gcc/testsuite/gcc.special/special.exp.special	2005-02-07 16:31:03.743114923 -0800
+++ gcc/testsuite/gcc.special/special.exp	2005-02-07 15:06:29.283167934 -0800
@@ -0,0 +1,30 @@
+# Copyright (C) 2005 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 2 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+# load support procs
+load_lib gcc-special.exp
+
+#
+# run special tests 
+#
+
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.x]] {
+    source $src
+}
--- gcc/testsuite/lib/gcc-special.exp.special	2005-02-07 14:00:30.290570373 -0800
+++ gcc/testsuite/lib/gcc-special.exp	2005-02-07 16:29:15.483041989 -0800
@@ -0,0 +1,163 @@
+# Copyright (C) 2005 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 2 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 this program; if not, write to the Free Software
+# Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# Based on c-torture.exp.
+
+load_lib file-format.exp
+
+#
+# gcc-special-compile -- compile source file or build shared library.
+#
+# SRC is the full pathname of the testcase.
+# OPTION is the specific compiler flag we're testing (eg: -O2).
+# OBJ is the additional object.
+# XFAIL is to indicate if it should fail.
+#
+proc gcc-special-compile { src option obj xfail } {
+    global tool
+    global output
+    global srcdir tmpdir
+    global host_triplet
+
+    if [string match "yes" $xfail] {
+	setup_xfail "*-*-*"
+    }
+
+    if [regexp -- "-shared" $option] {
+	set type "executable"
+	set output "$tmpdir/[file tail [file rootname $src]].so"
+    } else {
+	set type "object"
+	set output "$tmpdir/[file tail [file rootname $src]].o"
+    }
+
+    regsub "^$srcdir/?" $src "" testcase
+    # If we couldn't rip $srcdir out of `src' 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] {
+	set testcase "[file tail [file dirname $src]]/[file tail $src]"
+    }
+
+    verbose "Testing $testcase, $option" 1
+
+    # Run the compiler and analyze the results.
+    set options ""
+    lappend options "additional_flags=-w $option $obj"
+
+    set comp_output [${tool}_target_compile "$src" "$output" $type $options];
+    if [${tool}_check_compile $testcase $option $output $comp_output] {
+	if [string match "yes" $xfail] {
+	    fail "$testcase, $option"
+	} else {
+	    foreach file "$obj" {
+		remote_file build delete $file
+	    }
+	}
+    } elseif [string match "yes" $xfail] {
+	foreach file "$obj" {
+	    remote_file build delete $file
+	}
+    }
+    return $output
+}
+
+#
+# gcc-special-execute -- utility to compile and execute a testcase
+#
+# SOURCES is a list of full pathnames to the test source files.
+# The first filename in this list forms the "testcase".
+#
+# If the testcase has an associated .x file, we source that to run the
+# test instead.  We use .x so that we don't lengthen the existing filename
+# to more than 14 chars.
+#
+proc gcc-special-execute { sources shlib additional_flags } {
+    global tmpdir tool srcdir output compiler_conditional_xfail_data
+
+    # Use the first source filename given as the filename under test.
+    set src [lindex $sources 0]
+
+    set option ""
+
+    # Check for alternate driver.
+    if [file exists [file rootname $src].x] {
+	verbose "Using alternate driver [file rootname [file tail $src]].x" 2
+	set done_p 0
+	catch "set done_p \[source [file rootname $src].x\]"
+	if { $done_p } {
+	    return
+	}
+    }
+
+    set executable $tmpdir/[file tail [file rootname $src].x]
+
+    regsub "^$srcdir/?" $src "" testcase
+    # If we couldn't rip $srcdir out of `src' 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] {
+	set testcase "[file tail [file dirname $src]]/[file tail $src]"
+    }
+
+    # torture_{compile,execute}_xfail are set by the .x script
+    # (if present)
+    if [info exists torture_compile_xfail] {
+	setup_xfail $torture_compile_xfail
+    }
+
+    # torture_execute_before_{compile,execute} can be set by the .x script
+    # (if present)
+    if [info exists torture_eval_before_compile] {
+	set ignore_me [eval $torture_eval_before_compile]
+    }
+
+    verbose "Testing $testcase, $option" 1
+
+    set options ""
+    lappend options "additional_flags=-w $option $shlib"
+    if { $additional_flags != "" } {
+	lappend options "additional_flags=$additional_flags";
+    }
+
+    set comp_output [${tool}_target_compile "$sources" "${executable}" executable $options];
+
+    if ![${tool}_check_compile "$testcase compilation" $option $executable $comp_output] {
+	unresolved "$testcase execution, $option"
+	remote_file build delete $executable
+	return
+    }
+
+    if [info exists torture_execute_xfail] {
+	setup_xfail $torture_execute_xfail
+    }
+
+    if [info exists torture_eval_before_execute] {
+	set ignore_me [eval $torture_eval_before_execute]
+    }
+
+    set result [${tool}_load "$executable" "" ""]
+    set status [lindex $result 0];
+    set output [lindex $result 1];
+    $status "$testcase execution, $option"
+    if { $status == "pass" } {
+	foreach file "$executable $shlib" {
+	    remote_file build delete $file
+	}
+    }
+}



More information about the Gcc-patches mailing list