[PATCH][TEST] Improve tests for #pragma clang optimize off/on

Dario Domizioli dario.domizioli at gmail.com
Mon Jul 28 07:16:30 PDT 2014


Ping. :-)

It's just a test improvement patch so it shouldn't be controversial.

Cheers,
    Dario Domizioli
    SN Systems - Sony Computer Entertainment Group






On 15 July 2014 16:45, Dario Domizioli <dario.domizioli at gmail.com> wrote:

> Hello cfe-dev,
>
> I am attaching a patch which improves the tests for #pragma clang optimize
> off/on.
>
> It's just a few minor points, but we were missing some coverage.
> Specifically:
> - A few more test cases are added to the SemaCXX test, so that they verify
> the behaviour of multiple "off" regions in the same file.
> - One of those test cases also documents the fact that an "off" region can
> fall through the end of a #included file.
> - A comment is added in the PCH test so that it's clearer how it works.
>
> No functional change - only test changes.
>
> Cheers,
>     Dario Domizioli
>     SN Systems - Sony Computer Entertainment Group
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140728/519765e4/attachment.html>
-------------- next part --------------
Index: test/PCH/pragma-optimize.c
===================================================================
--- test/PCH/pragma-optimize.c	(revision 214082)
+++ test/PCH/pragma-optimize.c	(working copy)
@@ -5,6 +5,12 @@
 // RUN: %clang_cc1 %s -emit-pch -o %t
 // RUN: %clang_cc1 %s -emit-llvm -include-pch %t -o - | FileCheck %s
 
+// The first run line creates a pch, and since at that point HEADER is not
+// defined, the only thing contained in the pch is the pragma. The second line
+// then includes that pch, so HEADER is defined and the actual code is compiled.
+// The check then makes sure that the pragma is in effect in the file that
+// includes the pch.
+
 // expected-no-diagnostics
 
 #ifndef HEADER
Index: test/SemaCXX/Inputs/header-with-pragma-optimize-off.h
===================================================================
--- test/SemaCXX/Inputs/header-with-pragma-optimize-off.h	(revision 0)
+++ test/SemaCXX/Inputs/header-with-pragma-optimize-off.h	(working copy)
@@ -0,0 +1,5 @@
+
+// Open an "off" region in this header.
+#pragma clang optimize off
+
+// Let the "off" region fall through to anything including this header.
Index: test/SemaCXX/pragma-optimize.cpp
===================================================================
--- test/SemaCXX/pragma-optimize.cpp	(revision 214082)
+++ test/SemaCXX/pragma-optimize.cpp	(working copy)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -x c++ -std=c++11 -triple x86_64-unknown-linux -emit-llvm -O2 < %s | FileCheck %s
+// RUN: %clang_cc1 -I %S/Inputs -x c++ -std=c++11 -triple x86_64-unknown-linux -emit-llvm -O2 < %s | FileCheck %s
 
 #pragma clang optimize off
 
@@ -96,11 +96,50 @@
 // CHECK-DAG: @_Z6thriceIiET_S0_{{.*}} [[ATTRTHRICEINT:#[0-9]+]]
 
 
+// Test that we can re-open and re-close an "off" region after the first one,
+// and that this works as expected.
+
+#pragma clang optimize off
+
+int another_optnone(int x) {
+    return x << 1;
+}
+// CHECK-DAG: @_Z15another_optnonei{{.*}} [[ATTRANOTHEROPTNONE:#[0-9]+]]
+
+#pragma clang optimize on
+
+int another_normal(int x) {
+    return x << 2;
+}
+// CHECK-DAG: @_Z14another_normali{{.*}} [[ATTRANOTHERNORMAL:#[0-9]+]]
+
+
+// Test that we can re-open an "off" region by including a header with the
+// pragma and that this works as expected (i.e. the off region "falls through"
+// the end of the header into this file).
+
+#include <header-with-pragma-optimize-off.h>
+
+int yet_another_optnone(int x) {
+    return x << 3;
+}
+// CHECK-DAG: @_Z19yet_another_optnonei{{.*}} [[ATTRYETANOTHEROPTNONE:#[0-9]+]]
+
+#pragma clang optimize on
+
+int yet_another_normal(int x) {
+    return x << 4;
+}
+// CHECK-DAG: @_Z18yet_another_normali{{.*}} [[ATTRYETANOTHERNORMAL:#[0-9]+]]
+
+
 // Check for both noinline and optnone on each function that should have them.
 // CHECK-DAG: attributes [[ATTRBAR]] = { {{.*}}noinline{{.*}}optnone{{.*}} }
 // CHECK-DAG: attributes [[ATTRCREATED]] = { {{.*}}noinline{{.*}}optnone{{.*}} }
 // CHECK-DAG: attributes [[ATTRMETHOD]] = { {{.*}}noinline{{.*}}optnone{{.*}} }
 // CHECK-DAG: attributes [[ATTRTHRICEFLOAT]] = { {{.*}}noinline{{.*}}optnone{{.*}} }
+// CHECK-DAG: attributes [[ATTRANOTHEROPTNONE]] = { {{.*}}noinline{{.*}}optnone{{.*}} }
+// CHECK-DAG: attributes [[ATTRYETANOTHEROPTNONE]] = { {{.*}}noinline{{.*}}optnone{{.*}} }
 
 // Check that the other functions do NOT have optnone.
 // CHECK-DAG-NOT: attributes [[ATTRFOO]] = { {{.*}}optnone{{.*}} }
@@ -111,3 +150,5 @@
 // CHECK-DAG-NOT: attributes [[ATTRCONTAINER2]] = { {{.*}}optnone{{.*}} }
 // CHECK-DAG-NOT: attributes [[ATTRCONTAINER3]] = { {{.*}}optnone{{.*}} }
 // CHECK-DAG-NOT: attributes [[ATTRTHRICEINT]] = { {{.*}}optnone{{.*}} }
+// CHECK-DAG-NOT: attributes [[ATTRANOTHERNORMAL]] = { {{.*}}optnone{{.*}} }
+// CHECK-DAG-NOT: attributes [[ATTRYETANOTHERNORMAL]] = { {{.*}}optnone{{.*}} }


More information about the cfe-commits mailing list