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]

RFA: Add dg-require-int-sized-pointers to testsuite


testsuite/g++.dg/parse/cast1.C fails for -mabi=64 with:

    cast1.C:7: error: cast from 'char*' to 'int' loses precision

...which is true, since pointers are 8 bytes wide and ints are
only 4 bytes.  g++.old-deja/g++.mike/p784.C fails for the same
sort of reason.

cast1.C is derived directly from a PR so I didn't want to make it use
another integer type such as "long".  This patch instead adds a new
dg-require procedure that checks whether ints are the same size as
pointers.  The code needed to do this is very similar to the
named-sections check, so I moved most of the code into a separate
procedure, get_compiler_messages.  I didn't put the "output is empty"
check into g_c_m because future tests might want to check for specific
compiler messages.

Tested on mips64-linux-gnu.  I checked that parse1.C and p784.C
still run (and still pass) for -mabi=32 and -mabi=n32 and that
they're now skipped for -mabi=64.  OK to install?

Richard


	* lib/target-supports.exp (get_compiler_messages): New procedure,
	extracting and generalizing code from...
	(check_named_sections_available): ...here.
	(check_int_sized_pointers): New procedure.
	* lib/gcc-dg.exp (dg-require-int-sized-pointers): New procedure.
	* g++.dg/parse/cast1.C: Use dg-require-int-sized-pointers.
	* g++.old-deja/g++.mike/p784.C: Likewise.

Index: testsuite/lib/target-supports.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/target-supports.exp,v
retrieving revision 1.24
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.24 target-supports.exp
*** testsuite/lib/target-supports.exp	28 Oct 2004 23:38:47 -0000	1.24
--- testsuite/lib/target-supports.exp	1 Nov 2004 15:41:41 -0000
***************
*** 19,24 ****
--- 19,47 ----
  
  # This file defines procs for determining features supported by the target.
  
+ # Try to compile some code and return the messages printed by the compiler.
+ #
+ # BASENAME is a basename to use for temporary files.
+ # TYPE is the type of compilation to perform (see target_compile).
+ # CONTENTS gives the contents of the input file.
+ proc get_compiler_messages {basename type contents} {
+     global tool
+ 
+     set src ${basename}[pid].c
+     switch $type {
+ 	assembly { set output ${basename}[pid].s }
+ 	object { set output ${basename}[pid].o }
+     }
+     set f [open $src "w"]
+     puts $f $contents
+     close $f
+     set lines [${tool}_target_compile $src $output $type ""]
+     file delete $src
+     remote_file build delete $output
+ 
+     return $lines
+ }
+ 
  ###############################
  # proc check_weak_available { }
  ###############################
*************** proc check_iconv_available { test_what }
*** 274,295 ****
  # when cycling over subtarget options (e.g. irix o32/n32/n64) in
  # the same test run.
  proc check_named_sections_available { } {
!     global tool
! 
!     set src named[pid].c
!     set obj named[pid].o
!     verbose "check_named_sections_available compiling testfile $src" 2
!     set f [open $src "w"]
!     # Compile a small test program.
!     puts $f "int __attribute__ ((section(\"whatever\"))) foo;"
!     close $f
!     set lines [${tool}_target_compile $src $obj object ""]
!     file delete $src
!     remote_file build delete $obj
  
!     # If we got no error messages, everything is OK.
!     set answer [string match "" $lines]
!     verbose "check_named_sections_available  returning $answer" 2
      return $answer
  }
  
--- 297,317 ----
  # when cycling over subtarget options (e.g. irix o32/n32/n64) in
  # the same test run.
  proc check_named_sections_available { } {
!     verbose "check_named_sections_available: compiling source" 2
!     set answer [string match "" [get_compiler_messages named object {
! 	int __attribute__ ((section(\"whatever\"))) foo;
!     }]]
!     verbose "$property: returning $answer" 2
!     return $answer
! }
  
! # Return true if "int" and "void *" are the same size.
! proc check_int_sized_pointers { } {
!     verbose "check_int_sized_pointers: compiling source" 2
!     set answer [string match "" [get_compiler_messages intsizedptrs assembly {
! 	int dummy[sizeof (int) == sizeof (void *) ? 1 : -1];
!     }]]
!     verbose "check_int_sized_pointers: returning $answer" 2
      return $answer
  }
  
Index: testsuite/lib/gcc-dg.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/gcc-dg.exp,v
retrieving revision 1.36
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.36 gcc-dg.exp
*** testsuite/lib/gcc-dg.exp	25 Oct 2004 09:01:13 -0000	1.36
--- testsuite/lib/gcc-dg.exp	1 Nov 2004 15:41:38 -0000
*************** proc dg-require-named-sections { args } 
*** 430,435 ****
--- 430,446 ----
     }
  }
  
+ # Skip this test if "int" and "void *" have different sizes.
+ 
+ proc dg-require-int-sized-pointers { args } {
+    upvar name name
+ 
+    if { ![ check_int_sized_pointers ] } {
+        upvar dg-do-what dg-do-what
+        set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+    }
+ }
+ 
  # Prune any messages matching ARGS[1] (a regexp) from test output.
  proc dg-prune-output { args } {
      global additional_prunes
Index: testsuite/g++.dg/parse/cast1.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.dg/parse/cast1.C,v
retrieving revision 1.1
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.1 cast1.C
*** testsuite/g++.dg/parse/cast1.C	4 Jan 2004 22:42:17 -0000	1.1
--- testsuite/g++.dg/parse/cast1.C	1 Nov 2004 15:41:34 -0000
***************
*** 1,5 ****
--- 1,6 ----
  // PR c++/13536
  // { dg-options "-w" }
+ // { dg-require-int-sized-pointers "" }
  
  #include <typeinfo>
  
Index: testsuite/g++.old-deja/g++.mike/p784.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.mike/p784.C,v
retrieving revision 1.10
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.10 p784.C
*** testsuite/g++.old-deja/g++.mike/p784.C	1 May 2003 02:02:46 -0000	1.10
--- testsuite/g++.old-deja/g++.mike/p784.C	1 Nov 2004 15:41:37 -0000
***************
*** 1,5 ****
--- 1,6 ----
  // { dg-do assemble  }
  // { dg-options "-w" }
+ // { dg-require-int-sized-pointers "" }
  // prms-id: 784
  
  //# 1 "GctSymbol.GctSymbol.CHMap.cc"


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