aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorIgor Tsimbalist <igor.v.tsimbalist@intel.com>2017-10-20 19:29:02 +0200
committerIgor Tsimbalist <itsimbal@gcc.gnu.org>2017-10-20 19:29:02 +0200
commitb0926447b568fbcccd8edb6c4173864552711de0 (patch)
tree75e40ac779adece884a9e8d47b425fd564a0f34b /gcc
parentc840bf9bc92e71291a9dc653688bf496aa219b7d (diff)
downloadgcc-b0926447b568fbcccd8edb6c4173864552711de0.zip
gcc-b0926447b568fbcccd8edb6c4173864552711de0.tar.gz
gcc-b0926447b568fbcccd8edb6c4173864552711de0.tar.bz2
Add tests for -fcf-protection option and nocf_check attribute.
* 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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/ChangeLog11
-rw-r--r--gcc/testsuite/c-c++-common/attr-nocf-check-1.c30
-rw-r--r--gcc/testsuite/c-c++-common/attr-nocf-check-2.c5
-rw-r--r--gcc/testsuite/c-c++-common/attr-nocf-check-3.c29
-rw-r--r--gcc/testsuite/c-c++-common/fcf-protection-1.c4
-rw-r--r--gcc/testsuite/c-c++-common/fcf-protection-2.c4
-rw-r--r--gcc/testsuite/c-c++-common/fcf-protection-3.c4
-rw-r--r--gcc/testsuite/c-c++-common/fcf-protection-4.c2
-rw-r--r--gcc/testsuite/c-c++-common/fcf-protection-5.c4
9 files changed, 93 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 04d7910..9e0b48d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..62fa370
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/attr-nocf-check-1.c
@@ -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
index 0000000..9ab0180
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/attr-nocf-check-2.c
@@ -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
index 0000000..c7d9c8f
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/attr-nocf-check-3.c
@@ -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
index 0000000..6a27e19
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/fcf-protection-1.c
@@ -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
index 0000000..558f4c0
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/fcf-protection-2.c
@@ -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
index 0000000..ffc7346
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/fcf-protection-3.c
@@ -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
index 0000000..af4fc0b
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/fcf-protection-4.c
@@ -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
index 0000000..2ea2ce0
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/fcf-protection-5.c
@@ -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 } */