[testsuite/guality] Don't use attribute used in pr45882.c for -O0
authorTom de Vries <tdevries@suse.de>
Sat, 30 Jun 2018 08:09:26 +0000 (08:09 +0000)
committerTom de Vries <vries@gcc.gnu.org>
Sat, 30 Jun 2018 08:09:26 +0000 (08:09 +0000)
2018-06-30  Tom de Vries  <tdevries@suse.de>

* gcc.dg/guality/guality.exp (guality_transform_options): New proc.
(toplevel): Apply guality_transform_options on DG_TORTURE_OPTIONS and
LTO_TORTURE_OPTIONS.
* gcc.dg/guality/prevent-optimization.h: New file.
* gcc.dg/guality/pr45882.c: Include prevent-optimization.h.
(a): Replace __attribute__((used)) with ATTRIBUTE_USED.

From-SVN: r262270

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/guality/guality.exp
gcc/testsuite/gcc.dg/guality/pr45882.c
gcc/testsuite/gcc.dg/guality/prevent-optimization.h [new file with mode: 0644]

index da2abc1937ed7c447e154ca1cd131971f675f521..aa05ce747127e6ae7e26df4ed7453b2c3c028c73 100644 (file)
@@ -1,3 +1,12 @@
+2018-06-30  Tom de Vries  <tdevries@suse.de>
+
+       * gcc.dg/guality/guality.exp (guality_transform_options): New proc.
+       (toplevel): Apply guality_transform_options on DG_TORTURE_OPTIONS and
+       LTO_TORTURE_OPTIONS.
+       * gcc.dg/guality/prevent-optimization.h: New file.
+       * gcc.dg/guality/pr45882.c: Include prevent-optimization.h.
+       (a): Replace __attribute__((used)) with ATTRIBUTE_USED.
+
 2018-06-30  Tom de Vries  <tdevries@suse.de>
 
        * gcc.dg/guality/pr45882.c (foo): Use relative line numbers.
index 04e889caa2f8e2167ca0ec68d20b351064478d17..d9994341477ca635bfa98e53d524bc03b0e1c2dc 100644 (file)
@@ -48,6 +48,28 @@ if ![info exists ::env(GUALITY_GDB_NAME)] {
 }
 report_gdb $::env(GUALITY_GDB_NAME) [info script]
 
+proc guality_transform_options { args } {
+    set res [list]
+    foreach opt [lindex $args 0] {
+       #
+       if { ! [regexp -- "-O0" $opt] } {
+           set opt "$opt -DPREVENT_OPTIMIZATION"
+       }
+       lappend res $opt
+    }
+
+    return $res
+}
+
+global DG_TORTURE_OPTIONS
+set guality_dg_torture_options [guality_transform_options $DG_TORTURE_OPTIONS]
+set guality_lto_torture_options [guality_transform_options $LTO_TORTURE_OPTIONS]
+torture-init
+set-torture-options \
+    $guality_dg_torture_options \
+    [list {}] \
+    $guality_lto_torture_options
+
 if {[check_guality "
   #include \"$srcdir/$subdir/guality.h\"
   volatile long int varl = 6;
@@ -65,4 +87,5 @@ if [info exists guality_gdb_name] {
     unsetenv GUALITY_GDB_NAME
 }
 
+torture-finish
 dg-finish
index 02d74389ea05e829c2d7cf141c4a8458faeb47fa..3e60a93a2d85da57f63fdb6f6f4663bb253768ca 100644 (file)
@@ -2,8 +2,10 @@
 /* { dg-do run } */
 /* { dg-options "-g" } */
 
+#include "prevent-optimization.h"
+
 extern void abort (void);
-int a[1024] __attribute__((used));
+int a[1024] ATTRIBUTE_USED;
 volatile short int v;
 
 __attribute__((noinline,noclone,used)) int
diff --git a/gcc/testsuite/gcc.dg/guality/prevent-optimization.h b/gcc/testsuite/gcc.dg/guality/prevent-optimization.h
new file mode 100644 (file)
index 0000000..0ef84a3
--- /dev/null
@@ -0,0 +1,28 @@
+/* Copyright (C) 2018 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC 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, or (at your option)
+any later version.
+
+GCC 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/>.  */
+
+#ifndef PREVENT_OPTIMIZATION_H
+#define PREVENT_OPTIMIZATION_H
+
+#ifdef PREVENT_OPTIMIZATION
+#define ATTRIBUTE_USED __attribute__((used))
+#else
+#define ATTRIBUTE_USED
+#endif
+
+#endif