diff options
Diffstat (limited to 'clang/test/Sema')
-rw-r--r-- | clang/test/Sema/attr-nocf_check.c | 23 | ||||
-rw-r--r-- | clang/test/Sema/attr-nocf_check.cpp | 23 | ||||
-rw-r--r-- | clang/test/Sema/nocf_check_attr_not_allowed.c | 5 |
3 files changed, 51 insertions, 0 deletions
diff --git a/clang/test/Sema/attr-nocf_check.c b/clang/test/Sema/attr-nocf_check.c new file mode 100644 index 00000000000..aab4eace890 --- /dev/null +++ b/clang/test/Sema/attr-nocf_check.c @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -verify -fcf-protection=branch -target-feature +ibt -fsyntax-only %s + +// Function pointer definition. +typedef void (*FuncPointerWithNoCfCheck)(void) __attribute__((nocf_check)); // no-warning +typedef void (*FuncPointer)(void); + +// Dont allow function declaration and definition mismatch. +void __attribute__((nocf_check)) testNoCfCheck(); // expected-note {{previous declaration is here}} +void testNoCfCheck(){}; // expected-error {{conflicting types for 'testNoCfCheck'}} + +// No variable or parameter declaration +__attribute__((nocf_check)) int i; // expected-warning {{'nocf_check' attribute only applies to function}} +void testNoCfCheckImpl(double __attribute__((nocf_check)) i) {} // expected-warning {{'nocf_check' attribute only applies to function}} + +// Allow attributed function pointers as well as casting between attributed +// and non-attributed function pointers. +void testNoCfCheckMismatch(FuncPointer f) { + FuncPointerWithNoCfCheck fNoCfCheck = f; // expected-warning {{incompatible function pointer types}} + (*fNoCfCheck)(); // no-warning +} + +// 'nocf_check' Attribute has no parameters. +int testNoCfCheckParams() __attribute__((nocf_check(1))); // expected-error {{'nocf_check' attribute takes no arguments}} diff --git a/clang/test/Sema/attr-nocf_check.cpp b/clang/test/Sema/attr-nocf_check.cpp new file mode 100644 index 00000000000..b785f982dc6 --- /dev/null +++ b/clang/test/Sema/attr-nocf_check.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -triple=i386-unknown-unknown -verify -fcf-protection=branch -target-feature +ibt -std=c++11 -fsyntax-only %s + +// Function pointer definition. +[[gnu::nocf_check]] typedef void (*FuncPointerWithNoCfCheck)(void); // no-warning +typedef void (*FuncPointer)(void); + +// Dont allow function declaration and definition mismatch. +[[gnu::nocf_check]] void testNoCfCheck(); // expected-note {{previous declaration is here}} +void testNoCfCheck(){}; // expected-error {{conflicting types for 'testNoCfCheck'}} + +// No variable or parameter declaration +int [[gnu::nocf_check]] i; // expected-error {{'nocf_check' attribute cannot be applied to types}} +void testNoCfCheckImpl(double i [[gnu::nocf_check]]) {} // expected-warning {{'nocf_check' attribute only applies to functions and function pointers}} + +// Allow attributed function pointers as well as casting between attributed +// and non-attributed function pointers. +void testNoCfCheckMismatch(FuncPointer f) { + FuncPointerWithNoCfCheck fNoCfCheck = f; // expected-error {{cannot initialize a variable of type}} + (*fNoCfCheck)(); // no-warning +} + +// 'nocf_check' Attribute has no parameters. +[[gnu::nocf_check(1)]] int testNoCfCheckParams(); // expected-error {{'nocf_check' attribute takes no arguments}} diff --git a/clang/test/Sema/nocf_check_attr_not_allowed.c b/clang/test/Sema/nocf_check_attr_not_allowed.c new file mode 100644 index 00000000000..2ba71d4aa4c --- /dev/null +++ b/clang/test/Sema/nocf_check_attr_not_allowed.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -triple powerpc-unknown-linux-gnu -fsyntax-only -verify -fcf-protection=branch %s +// RUN: %clang_cc1 -triple arm-unknown-linux-gnu -fsyntax-only -verify -fcf-protection=branch %s +// RUN: %clang_cc1 -triple arm-unknown-linux-gnu -fsyntax-only -verify %s + +void __attribute__((nocf_check)) foo(); // expected-warning-re{{{{((unknown attribute 'nocf_check' ignored)|('nocf_check' attribute ignored; use -fcf-protection to enable the attribute))}}}} |