diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CodeGen/attributes.c | 14 | ||||
-rw-r--r-- | clang/test/CodeGen/cetintrin.c | 4 | ||||
-rw-r--r-- | clang/test/CodeGen/x86-cf-protection.c | 4 | ||||
-rw-r--r-- | clang/test/Misc/pragma-attribute-supported-attributes-list.test | 3 | ||||
-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 |
7 files changed, 70 insertions, 6 deletions
diff --git a/clang/test/CodeGen/attributes.c b/clang/test/CodeGen/attributes.c index 34833a24692..e7fd076581d 100644 --- a/clang/test/CodeGen/attributes.c +++ b/clang/test/CodeGen/attributes.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -emit-llvm -triple i386-linux-gnu -o %t %s +// RUN: %clang_cc1 -emit-llvm -fcf-protection=branch -target-feature +ibt -triple i386-linux-gnu -o %t %s // RUN: FileCheck --input-file=%t %s // CHECK: @t5 = weak global i32 2 @@ -97,8 +97,20 @@ void __attribute__((section(".bar"))) t22(void) {} // CHECK: define void @t22() [[NUW]] section ".bar" +// CHECK: define void @t23() [[NOCF_CHECK_FUNC:#[0-9]+]] +void __attribute__((nocf_check)) t23(void) {} + +// CHECK: call void %{{[a-z0-9]+}}() [[NOCF_CHECK_CALL:#[0-9]+]] +typedef void (*f_t)(void); +void t24(f_t f1) { + __attribute__((nocf_check)) f_t p = f1; + (*p)(); +} + // CHECK: attributes [[NUW]] = { noinline nounwind{{.*}} } // CHECK: attributes [[NR]] = { noinline noreturn nounwind{{.*}} } // CHECK: attributes [[COLDDEF]] = { cold {{.*}}} // CHECK: attributes [[COLDDECL]] = { cold {{.*}}} +// CHECK: attributes [[NOCF_CHECK_FUNC]] = { nocf_check {{.*}}} // CHECK: attributes [[COLDSITE]] = { cold {{.*}}} +// CHECK: attributes [[NOCF_CHECK_CALL]] = { nocf_check } diff --git a/clang/test/CodeGen/cetintrin.c b/clang/test/CodeGen/cetintrin.c index 4d2f87a4a3c..f70d1c80e1c 100644 --- a/clang/test/CodeGen/cetintrin.c +++ b/clang/test/CodeGen/cetintrin.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -ffreestanding %s -triple=i386-apple-darwin -target-feature +shstk -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=I386 --check-prefix=CHECK -// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +shstk -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=X86_64 --check-prefix=CHECK +// RUN: %clang_cc1 -ffreestanding %s -triple=i386-unknown-unknown -target-feature +shstk -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=I386 --check-prefix=CHECK +// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-unknown -target-feature +shstk -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=X86_64 --check-prefix=CHECK #include <immintrin.h> diff --git a/clang/test/CodeGen/x86-cf-protection.c b/clang/test/CodeGen/x86-cf-protection.c index c853791d2dd..044f839c348 100644 --- a/clang/test/CodeGen/x86-cf-protection.c +++ b/clang/test/CodeGen/x86-cf-protection.c @@ -1,5 +1,5 @@ -// RUN: not %clang_cc1 -fsyntax-only -S -emit-llvm -o %t -triple i386-unknown-unknown -fcf-protection=return %s 2>&1 | FileCheck %s --check-prefix=RETURN -// RUN: not %clang_cc1 -fsyntax-only -S -emit-llvm -o %t -triple i386-unknown-unknown -fcf-protection=branch %s 2>&1 | FileCheck %s --check-prefix=BRANCH +// RUN: not %clang_cc1 -fsyntax-only -S -o %t -triple i386-unknown-unknown -fcf-protection=return %s 2>&1 | FileCheck %s --check-prefix=RETURN +// RUN: not %clang_cc1 -fsyntax-only -S -o %t -triple i386-unknown-unknown -fcf-protection=branch %s 2>&1 | FileCheck %s --check-prefix=BRANCH // RETURN: error: option 'cf-protection=return' cannot be specified without '-mshstk' // BRANCH: error: option 'cf-protection=branch' cannot be specified without '-mibt' diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test b/clang/test/Misc/pragma-attribute-supported-attributes-list.test index 1004459e9a1..c911c503f8c 100644 --- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test +++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test @@ -2,7 +2,7 @@ // The number of supported attributes should never go down! -// CHECK: #pragma clang attribute supports 67 attributes: +// CHECK: #pragma clang attribute supports 68 attributes: // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function) // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function) // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function) @@ -12,6 +12,7 @@ // CHECK-NEXT: AlignValue (SubjectMatchRule_variable, SubjectMatchRule_type_alias) // CHECK-NEXT: AllocSize (SubjectMatchRule_function) // CHECK-NEXT: Annotate () +// CHECK-NEXT: AnyX86NoCfCheck (SubjectMatchRule_hasType_functionType) // CHECK-NEXT: AssumeAligned (SubjectMatchRule_objc_method, SubjectMatchRule_function) // CHECK-NEXT: Availability ((SubjectMatchRule_record, SubjectMatchRule_enum, SubjectMatchRule_enum_constant, SubjectMatchRule_field, SubjectMatchRule_function, SubjectMatchRule_namespace, SubjectMatchRule_objc_category, SubjectMatchRule_objc_interface, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, SubjectMatchRule_objc_protocol, SubjectMatchRule_record, SubjectMatchRule_type_alias, SubjectMatchRule_variable)) // CHECK-NEXT: CXX11NoReturn (SubjectMatchRule_function) 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))}}}} |