From b0926447b568fbcccd8edb6c4173864552711de0 Mon Sep 17 00:00:00 2001 From: Igor Tsimbalist Date: Fri, 20 Oct 2017 19:29:02 +0200 Subject: [PATCH] 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 --- gcc/testsuite/ChangeLog | 11 +++++++ .../c-c++-common/attr-nocf-check-1.c | 30 +++++++++++++++++++ .../c-c++-common/attr-nocf-check-2.c | 5 ++++ .../c-c++-common/attr-nocf-check-3.c | 29 ++++++++++++++++++ gcc/testsuite/c-c++-common/fcf-protection-1.c | 4 +++ gcc/testsuite/c-c++-common/fcf-protection-2.c | 4 +++ gcc/testsuite/c-c++-common/fcf-protection-3.c | 4 +++ gcc/testsuite/c-c++-common/fcf-protection-4.c | 2 ++ gcc/testsuite/c-c++-common/fcf-protection-5.c | 4 +++ 9 files changed, 93 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/attr-nocf-check-1.c create mode 100644 gcc/testsuite/c-c++-common/attr-nocf-check-2.c create mode 100644 gcc/testsuite/c-c++-common/attr-nocf-check-3.c create mode 100644 gcc/testsuite/c-c++-common/fcf-protection-1.c create mode 100644 gcc/testsuite/c-c++-common/fcf-protection-2.c create mode 100644 gcc/testsuite/c-c++-common/fcf-protection-3.c create mode 100644 gcc/testsuite/c-c++-common/fcf-protection-4.c create mode 100644 gcc/testsuite/c-c++-common/fcf-protection-5.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 04d7910c148..9e0b48d23b8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,14 @@ +2017-10-20 Igor Tsimbalist + + * 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 * 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 00000000000..62fa370b22e --- /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 00000000000..9ab01804782 --- /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 00000000000..c7d9c8f401f --- /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 00000000000..6a27e1973d8 --- /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 00000000000..558f4c0a580 --- /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 00000000000..ffc73469ad9 --- /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 00000000000..af4fc0b2812 --- /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 00000000000..2ea2ce0d825 --- /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 } */ -- 2.30.2