Add tests for -fcf-protection option and nocf_check attribute.
authorIgor Tsimbalist <igor.v.tsimbalist@intel.com>
Fri, 20 Oct 2017 17:29:02 +0000 (19:29 +0200)
committerIgor Tsimbalist <itsimbal@gcc.gnu.org>
Fri, 20 Oct 2017 17:29:02 +0000 (19:29 +0200)
* c-c++-common/fcf-protection-1.c: New test.
* c-c++-common/fcf-protection-2.c: Likewise.
* c-c++-common/fcf-protection-3.c: Likewise.
* c-c++-common/fcf-protection-4.c: Likewise.
* c-c++-common/fcf-protection-5.c: Likewise.
* c-c++-common/attr-nocf-check-1.c: Likewise.
* c-c++-common/attr-nocf-check-2.c: Likewise.
* c-c++-common/attr-nocf-check-3.c: Likewise.

From-SVN: r253949

gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/attr-nocf-check-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/attr-nocf-check-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/attr-nocf-check-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/fcf-protection-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/fcf-protection-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/fcf-protection-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/fcf-protection-4.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/fcf-protection-5.c [new file with mode: 0644]

index 04d7910..9e0b48d 100644 (file)
@@ -1,3 +1,14 @@
+2017-10-20  Igor Tsimbalist  <igor.v.tsimbalist@intel.com>
+
+       * c-c++-common/fcf-protection-1.c: New test.
+       * c-c++-common/fcf-protection-2.c: Likewise.
+       * c-c++-common/fcf-protection-3.c: Likewise.
+       * c-c++-common/fcf-protection-4.c: Likewise.
+       * c-c++-common/fcf-protection-5.c: Likewise.
+       * c-c++-common/attr-nocf-check-1.c: Likewise.
+       * c-c++-common/attr-nocf-check-2.c: Likewise.
+       * c-c++-common/attr-nocf-check-3.c: Likewise.
+
 2017-10-20  Ed Schonberg  <schonberg@adacore.com>
 
        * gnat.dg/sync_iface_call.adb, gnat.dg/sync_iface_call_pkg.ads,
diff --git a/gcc/testsuite/c-c++-common/attr-nocf-check-1.c b/gcc/testsuite/c-c++-common/attr-nocf-check-1.c
new file mode 100644 (file)
index 0000000..62fa370
--- /dev/null
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+
+int func (int) __attribute__ ((nocf_check)); /* { dg-warning "'nocf_check' attribute ignored. Use -fcf-protection option to enable it" } */
+int (*fptr) (int) __attribute__ ((nocf_check)); /* { dg-warning "'nocf_check' attribute ignored. Use -fcf-protection option to enable it" } */
+typedef void (*nocf_check_t) (void) __attribute__ ((nocf_check)); /* { dg-warning "'nocf_check' attribute ignored. Use -fcf-protection option to enable it" } */
+
+int
+foo1 (int arg)
+{
+  return func (arg) + fptr (arg);
+}
+
+void
+foo2 (void (*foo) (void))
+{
+  void (*func) (void) __attribute__((nocf_check)) = foo; /* { dg-warning "'nocf_check' attribute ignored. Use -fcf-protection option to enable it" } */
+  func ();
+}
+
+void
+foo3 (nocf_check_t foo)
+{
+  foo ();
+}
+
+void
+foo4 (void (*foo) (void) __attribute__((nocf_check))) /* { dg-warning "'nocf_check' attribute ignored. Use -fcf-protection option to enable it" } */
+{
+  foo ();
+}
diff --git a/gcc/testsuite/c-c++-common/attr-nocf-check-2.c b/gcc/testsuite/c-c++-common/attr-nocf-check-2.c
new file mode 100644 (file)
index 0000000..9ab0180
--- /dev/null
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+
+int var1 __attribute__((nocf_check)); /* { dg-warning "'nocf_check' attribute only applies to function types" } */
+int *var2 __attribute__((nocf_check)); /* { dg-warning "'nocf_check' attribute only applies to function types" } */
+void (**var3) (void) __attribute__((nocf_check)); /* { dg-warning "'nocf_check' attribute only applies to function types" } */
diff --git a/gcc/testsuite/c-c++-common/attr-nocf-check-3.c b/gcc/testsuite/c-c++-common/attr-nocf-check-3.c
new file mode 100644 (file)
index 0000000..c7d9c8f
--- /dev/null
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+
+int  foo (void) __attribute__ ((nocf_check)); /* { dg-warning "'nocf_check' attribute ignored. Use -fcf-protection option to enable it" } */
+void (*foo1) (void) __attribute__((nocf_check)); /* { dg-warning "'nocf_check' attribute ignored. Use -fcf-protection option to enable it" } */
+void (*foo2) (void);
+
+int
+foo (void) /* The function's address is not tracked.  */
+{
+  /* This call site is not tracked for
+     control-flow instrumentation.  */
+  (*foo1)();
+
+  foo1 = foo2;
+  /* This call site is still not tracked for
+     control-flow instrumentation.  */
+  (*foo1)();
+
+  /* This call site is tracked for
+     control-flow instrumentation.  */
+  (*foo2)();
+
+  foo2 = foo1;
+  /* This call site is still tracked for
+     control-flow instrumentation.  */
+  (*foo2)();
+
+  return 0;
+}
diff --git a/gcc/testsuite/c-c++-common/fcf-protection-1.c b/gcc/testsuite/c-c++-common/fcf-protection-1.c
new file mode 100644 (file)
index 0000000..6a27e19
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-fcf-protection=full" } */
+/* { dg-error "'-fcf-protection=full' is not supported for this target" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
+/* { dg-error "'-fcf-protection=full' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */
diff --git a/gcc/testsuite/c-c++-common/fcf-protection-2.c b/gcc/testsuite/c-c++-common/fcf-protection-2.c
new file mode 100644 (file)
index 0000000..558f4c0
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-fcf-protection=branch" } */
+/* { dg-error "'-fcf-protection=branch' is not supported for this target" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
+/* { dg-error "'-fcf-protection=branch' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */
diff --git a/gcc/testsuite/c-c++-common/fcf-protection-3.c b/gcc/testsuite/c-c++-common/fcf-protection-3.c
new file mode 100644 (file)
index 0000000..ffc7346
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-fcf-protection=return" } */
+/* { dg-error "'-fcf-protection=return' is not supported for this target" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
+/* { dg-error "'-fcf-protection=return' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */
diff --git a/gcc/testsuite/c-c++-common/fcf-protection-4.c b/gcc/testsuite/c-c++-common/fcf-protection-4.c
new file mode 100644 (file)
index 0000000..af4fc0b
--- /dev/null
@@ -0,0 +1,2 @@
+/* { dg-do compile } */
+/* { dg-options "-fcf-protection=none" } */
diff --git a/gcc/testsuite/c-c++-common/fcf-protection-5.c b/gcc/testsuite/c-c++-common/fcf-protection-5.c
new file mode 100644 (file)
index 0000000..2ea2ce0
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-fcf-protection" } */
+/* { dg-error "'-fcf-protection=full' is not supported for this target" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
+/* { dg-error "'-fcf-protection=full' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */