Add '__OPTIMIZE__' DejaGnu selector
authorThomas Schwinge <thomas@codesourcery.com>
Tue, 18 May 2021 15:30:34 +0000 (17:30 +0200)
committerThomas Schwinge <thomas@codesourcery.com>
Fri, 21 May 2021 18:09:16 +0000 (20:09 +0200)
gcc/testsuite/
* lib/target-supports.exp (check_effective_target___OPTIMIZE__):
New proc.
* gcc.c-torture/compile/ssa-unused-1.c: New file.
gcc/
* doc/sourcebuild.texi (Other attributes): Document '__OPTIMIZE__'
DejaGnu selector.

gcc/doc/sourcebuild.texi
gcc/testsuite/gcc.c-torture/compile/ssa-unused-1.c [new file with mode: 0644]
gcc/testsuite/lib/target-supports.exp

index ed811d1..cf30987 100644 (file)
@@ -2755,6 +2755,10 @@ constant.
 
 @item lgccjit
 Target supports -lgccjit, i.e. libgccjit.so can be linked into jit tests.
+
+@item __OPTIMIZE__
+Optimizations are enabled (@code{__OPTIMIZE__}) per the current
+compiler flags.
 @end table
 
 @subsubsection Local to tests in @code{gcc.target/i386}
diff --git a/gcc/testsuite/gcc.c-torture/compile/ssa-unused-1.c b/gcc/testsuite/gcc.c-torture/compile/ssa-unused-1.c
new file mode 100644 (file)
index 0000000..e8fb93c
--- /dev/null
@@ -0,0 +1,15 @@
+/* This is just to exercise the '__OPTIMIZE__' DejaGnu selector.  */
+
+/* { dg-do "assemble" } */
+/* { dg-additional-options "-fdump-tree-ssa" } */
+
+void f()
+{
+  int unused = 3;
+  (void) &unused;
+}
+
+/* { dg-final { scan-tree-dump-not {No longer having address taken: unused} ssa { target { ! __OPTIMIZE__ } } } }
+   { dg-final { scan-tree-dump-times {No longer having address taken: unused} 1 ssa { target __OPTIMIZE__ } } } */
+/* { dg-final { scan-tree-dump-not {Now a gimple register: unused} ssa { target { ! __OPTIMIZE__ } } } }
+   { dg-final { scan-tree-dump-times {Now a gimple register: unused} 1 ssa { target __OPTIMIZE__ } } } */
index 8192da5..849f1bb 100644 (file)
@@ -11103,3 +11103,13 @@ proc check_effective_target_lra { } {
     return 1
 }
 
+# Test whether optimizations are enabled ('__OPTIMIZE__') per the
+# 'current_compiler_flags' (thus don't cache).
+
+proc check_effective_target___OPTIMIZE__ {} {
+    return [check_no_compiler_messages_nocache __OPTIMIZE__ assembly {
+       #ifndef __OPTIMIZE__
+       # error nein
+       #endif
+    } [current_compiler_flags]]
+}