Issue an error when -mindirect-branch or -mfunction-return are used with incompatible -fcf-protection.
gcc/ PR target/87412 * config/i386/i386.c (ix86_set_indirect_branch_type): Issue an error for -mindirect-branch/-mfunction-return with incompatible -fcf-protection. gcc/testsuite/ PR target/87412 * gcc.target/i386/pr87412-1.c: New file. * gcc.target/i386/pr87412-2.c: Likewise. * gcc.target/i386/pr87412-3.c: Likewise. * gcc.target/i386/pr87412-4.c: Likewise. --- gcc/config/i386/i386.c | 10 ++++++++++ gcc/testsuite/gcc.target/i386/pr87412-1.c | 9 +++++++++ gcc/testsuite/gcc.target/i386/pr87412-2.c | 10 ++++++++++ gcc/testsuite/gcc.target/i386/pr87412-3.c | 9 +++++++++ gcc/testsuite/gcc.target/i386/pr87412-4.c | 7 +++++++ 5 files changed, 45 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/pr87412-1.c create mode 100644 gcc/testsuite/gcc.target/i386/pr87412-2.c create mode 100644 gcc/testsuite/gcc.target/i386/pr87412-3.c create mode 100644 gcc/testsuite/gcc.target/i386/pr87412-4.c diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 3d76c896d83..08402bed5f3 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -5600,6 +5600,11 @@ ix86_set_indirect_branch_type (tree fndecl) ((cfun->machine->indirect_branch_type == indirect_branch_thunk_extern) ? "thunk-extern" : "thunk")); + + if (cfun->machine->indirect_branch_type != indirect_branch_keep + && (flag_cf_protection & CF_RETURN)) + error ("%<-mindirect-branch%> and %<-fcf-protection%> are not " + "compatible"); } if (cfun->machine->function_return_type == indirect_branch_unset) @@ -5638,6 +5643,11 @@ ix86_set_indirect_branch_type (tree fndecl) ((cfun->machine->function_return_type == indirect_branch_thunk_extern) ? "thunk-extern" : "thunk")); + + if (cfun->machine->function_return_type != indirect_branch_keep + && (flag_cf_protection & CF_RETURN)) + error ("%<-mfunction-return%> and %<-fcf-protection%> are not " + "compatible"); } } diff --git a/gcc/testsuite/gcc.target/i386/pr87412-1.c b/gcc/testsuite/gcc.target/i386/pr87412-1.c new file mode 100644 index 00000000000..e04f1fbe96c --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr87412-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcf-protection -mfunction-return=thunk -mindirect-branch=thunk" } */ + +void +bar (void) +{ +/* { dg-error "'-mindirect-branch' and '-fcf-protection' are not compatible" "" { target *-*-* } .-1 } */ +/* { dg-error "'-mfunction-return' and '-fcf-protection' are not compatible" "" { target *-*-* } .-2 } */ +} diff --git a/gcc/testsuite/gcc.target/i386/pr87412-2.c b/gcc/testsuite/gcc.target/i386/pr87412-2.c new file mode 100644 index 00000000000..33a9e8aed4e --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr87412-2.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcf-protection -mfunction-return=keep -mindirect-branch=keep" } */ + +void + __attribute__ ((indirect_branch("thunk"), function_return("thunk"))) +bar (void) +{ +/* { dg-error "'-mindirect-branch' and '-fcf-protection' are not compatible" "" { target *-*-* } .-1 } */ +/* { dg-error "'-mfunction-return' and '-fcf-protection' are not compatible" "" { target *-*-* } .-2 } */ +} diff --git a/gcc/testsuite/gcc.target/i386/pr87412-3.c b/gcc/testsuite/gcc.target/i386/pr87412-3.c new file mode 100644 index 00000000000..e67d727d871 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr87412-3.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcf-protection=return -mfunction-return=thunk -mindirect-branch=thunk" } */ + +void +bar (void) +{ +/* { dg-error "'-mindirect-branch' and '-fcf-protection' are not compatible" "" { target *-*-* } .-1 } */ +/* { dg-error "'-mfunction-return' and '-fcf-protection' are not compatible" "" { target *-*-* } .-2 } */ +} diff --git a/gcc/testsuite/gcc.target/i386/pr87412-4.c b/gcc/testsuite/gcc.target/i386/pr87412-4.c new file mode 100644 index 00000000000..5b9dce5e82c --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr87412-4.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcf-protection=branch -mfunction-return=keep -mindirect-branch=thunk" } */ + +void +bar (void) +{ +} -- 2.17.1