diff options
Diffstat (limited to 'test/Sema')
62 files changed, 1429 insertions, 108 deletions
diff --git a/test/Sema/128bitfloat.cpp b/test/Sema/128bitfloat.cpp index cb76dac96001..2449cb6b6596 100644 --- a/test/Sema/128bitfloat.cpp +++ b/test/Sema/128bitfloat.cpp @@ -1,24 +1,35 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=gnu++11 %s // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +#ifdef __FLOAT128__ +__float128 f; +template<typename> struct __is_floating_point_helper {}; +template<> struct __is_floating_point_helper<__float128> {}; +int g(int x, __float128 *y) { + return x + *y; +} + +// expected-no-diagnostics +#else #if !defined(__STRICT_ANSI__) -__float128 f; // expected-error {{support for type '__float128' is not yet implemented}} +__float128 f; // expected-error {{__float128 is not supported on this target}} // But this should work: template<typename> struct __is_floating_point_helper {}; -template<> struct __is_floating_point_helper<__float128> {}; +template<> struct __is_floating_point_helper<__float128> {}; // expected-error {{__float128 is not supported on this target}} // FIXME: This could have a better diag. -void g(int x, __float128 *y) { - x + *y; // expected-error {{invalid operands to binary expression ('int' and '__float128')}} +int g(int x, __float128 *y) { // expected-error {{__float128 is not supported on this target}} + return x + *y; } #else -__float128 f; // expected-error {{unknown type name '__float128'}} +__float128 f; // expected-error {{__float128 is not supported on this target}} template<typename> struct __is_floating_point_helper {}; -template<> struct __is_floating_point_helper<__float128> {}; // expected-error {{use of undeclared identifier '__float128'}} +template<> struct __is_floating_point_helper<__float128> {}; // expected-error {{__float128 is not supported on this target}} -void g(int x, __float128 *y) { // expected-error {{unknown type name '__float128'}} - x + *y; +int g(int x, __float128 *y) { // expected-error {{__float128 is not supported on this target}} + return x + *y; } #endif +#endif diff --git a/test/Sema/MicrosoftExtensions.c b/test/Sema/MicrosoftExtensions.c index e7032305fc07..62e5285970a7 100644 --- a/test/Sema/MicrosoftExtensions.c +++ b/test/Sema/MicrosoftExtensions.c @@ -6,6 +6,12 @@ struct A int a[]; /* expected-warning {{flexible array member 'a' in otherwise empty struct is a Microsoft extension}} */ }; +struct PR28407 +{ + int : 1; + int a[]; /* expected-warning {{flexible array member 'a' in otherwise empty struct is a Microsoft extension}} */ +}; + struct C { int l; union { @@ -170,3 +176,13 @@ void myprintf(const char *f, ...) { __va_start(ap, f); // expected-warning {{incompatible pointer types passing 'my_va_list'}} } } + +// __unaligned handling +void test_unaligned() { + __unaligned int *p1 = 0; + int *p2 = p1; // expected-warning {{initializing 'int *' with an expression of type '__unaligned int *' discards qualifiers}} + __unaligned int *p3 = p2; +} + +void test_unaligned2(int x[__unaligned 4]) {} + diff --git a/test/Sema/aarch64-special-register.c b/test/Sema/aarch64-special-register.c index 40d4033967f8..a4fb92b5235b 100644 --- a/test/Sema/aarch64-special-register.c +++ b/test/Sema/aarch64-special-register.c @@ -13,7 +13,7 @@ void wsrp_1(void *v) { } void wsr64_1(unsigned long v) { - __builtin_arm_wsr64("sysreg", v); //expected-error {{invalid special register for builtin}} + __builtin_arm_wsr64("sysreg", v); } unsigned rsr_1() { @@ -25,7 +25,7 @@ void *rsrp_1() { } unsigned long rsr64_1() { - return __builtin_arm_rsr64("sysreg"); //expected-error {{invalid special register for builtin}} + return __builtin_arm_rsr64("sysreg"); } void wsr_2(unsigned v) { diff --git a/test/Sema/address_spaces.c b/test/Sema/address_spaces.c index 1922c8ae4f6f..3fe93155451f 100644 --- a/test/Sema/address_spaces.c +++ b/test/Sema/address_spaces.c @@ -20,7 +20,7 @@ void foo(_AS3 float *a, _AS1 int arrarr[5][5]; // expected-error {{automatic variable qualified with an address space}} __attribute__((address_space(-1))) int *_boundsA; // expected-error {{address space is negative}} - __attribute__((address_space(0xFFFFFF))) int *_boundsB; + __attribute__((address_space(0x7FFFFF))) int *_boundsB; __attribute__((address_space(0x1000000))) int *_boundsC; // expected-error {{address space is larger than the maximum supported}} // chosen specifically to overflow 32 bits and come out reasonable __attribute__((address_space(4294967500))) int *_boundsD; // expected-error {{address space is larger than the maximum supported}} @@ -71,4 +71,4 @@ __attribute__((address_space("12"))) int *i; // expected-error {{'address_space' // Clang extension doesn't forbid operations on pointers to different address spaces. char* cmp(_AS1 char *x, _AS2 char *y) { return x < y ? x : y; // expected-warning {{pointer type mismatch ('__attribute__((address_space(1))) char *' and '__attribute__((address_space(2))) char *')}} -}
\ No newline at end of file +} diff --git a/test/Sema/arm-no-fp16.c b/test/Sema/arm-no-fp16.c new file mode 100644 index 000000000000..6443d83198ce --- /dev/null +++ b/test/Sema/arm-no-fp16.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -triple thumbv7-none-eabi %s -target-feature +neon -target-feature -fp16 -fsyntax-only -verify + +#include <arm_neon.h> + +float16x4_t test_vcvt_f16_f32(float32x4_t a) { + return vcvt_f16_f32(a); // expected-warning{{implicit declaration of function 'vcvt_f16_f32'}} expected-error{{returning 'int' from a function with incompatible result type 'float16x4_t'}} +} + +float32x4_t test_vcvt_f32_f16(float16x4_t a) { + return vcvt_f32_f16(a); // expected-warning{{implicit declaration of function 'vcvt_f32_f16'}} expected-error{{returning 'int' from a function with incompatible result type 'float32x4_t'}} +} diff --git a/test/Sema/arm64-neon-header.c b/test/Sema/arm64-neon-header.c new file mode 100644 index 000000000000..0ae082113a57 --- /dev/null +++ b/test/Sema/arm64-neon-header.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -triple arm64-apple-darwin -target-feature +neon -Wvector-conversion -fsyntax-only -ffreestanding -verify %s + +#include <arm_neon.h> + +int16x8_t foo(int8x8_t p0, int16x8_t p1) { + return vqmovun_high_s16(p0, p1); // expected-warning {{incompatible vector types returning 'uint8x16_t'}} +} diff --git a/test/Sema/arm_vfma.c b/test/Sema/arm_vfma.c new file mode 100644 index 000000000000..8c08b4d8b9e7 --- /dev/null +++ b/test/Sema/arm_vfma.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple thumbv7-none-eabi -target-feature +neon -target-feature +vfp4 -fsyntax-only -verify %s +#include <arm_neon.h> + +// expected-no-diagnostics + +void func(float32x2_t v2f32, float32x4_t v4f32) { + vfma_f32(v2f32, v2f32, v2f32); + vfmaq_f32(v4f32, v4f32, v4f32); + + vfms_f32(v2f32, v2f32, v2f32); + vfmsq_f32(v4f32, v4f32, v4f32); +} diff --git a/test/Sema/asm.c b/test/Sema/asm.c index d29b136a117a..69c33f7ccf24 100644 --- a/test/Sema/asm.c +++ b/test/Sema/asm.c @@ -25,7 +25,7 @@ void clobbers() { asm ("nop" : : : "0", "%0", "#0"); asm ("nop" : : : "foo"); // expected-error {{unknown register name 'foo' in asm}} asm ("nop" : : : "52"); - asm ("nop" : : : "104"); // expected-error {{unknown register name '104' in asm}} + asm ("nop" : : : "204"); // expected-error {{unknown register name '204' in asm}} asm ("nop" : : : "-1"); // expected-error {{unknown register name '-1' in asm}} asm ("nop" : : : "+1"); // expected-error {{unknown register name '+1' in asm}} } diff --git a/test/Sema/ast-print.c b/test/Sema/ast-print.c index b4d76844fef7..4c0aef5b2f3f 100644 --- a/test/Sema/ast-print.c +++ b/test/Sema/ast-print.c @@ -1,4 +1,5 @@ // RUN: %clang_cc1 %s -ast-print | FileCheck %s +// RUN: %clang_cc1 %s -ast-print | %clang_cc1 -fsyntax-only - typedef void func_typedef(); func_typedef xxx; @@ -39,6 +40,7 @@ int rvarr(int n, int a[restrict static n]) { return a[2]; } +// CHECK: typedef struct { typedef struct { int f; } T __attribute__ ((__aligned__)); @@ -53,3 +55,13 @@ struct pair_t { // CHECK: struct pair_t p = {a: 3, .b = 4}; struct pair_t p = {a: 3, .b = 4}; + +void initializers() { + // CHECK: int *x = ((void *)0), *y = ((void *)0); + int *x = ((void *)0), *y = ((void *)0); + struct Z{}; + struct { + struct Z z; + // CHECK: } z = {(struct Z){}}; + } z = {(struct Z){}}; +} diff --git a/test/Sema/atomic-ops.c b/test/Sema/atomic-ops.c index 9a37ec2a3876..05836214247c 100644 --- a/test/Sema/atomic-ops.c +++ b/test/Sema/atomic-ops.c @@ -121,7 +121,10 @@ void f(_Atomic(int) *i, const _Atomic(int) *ci, __atomic_load(I, *P, memory_order_relaxed, 42); // expected-error {{too many arguments}} (int)__atomic_load(I, I, memory_order_seq_cst); // expected-error {{operand of type 'void'}} __atomic_load(s1, s2, memory_order_acquire); - (void)__atomic_load(I, CI, memory_order_relaxed); // expected-warning {{passing 'const int *' to parameter of type 'int *' discards qualifiers}} + __atomic_load(CI, I, memory_order_relaxed); + __atomic_load(I, CI, memory_order_relaxed); // expected-warning {{passing 'const int *' to parameter of type 'int *' discards qualifiers}} + __atomic_load(CI, CI, memory_order_relaxed); // expected-warning {{passing 'const int *' to parameter of type 'int *' discards qualifiers}} + __c11_atomic_store(i, 1, memory_order_seq_cst); __c11_atomic_store(p, 1, memory_order_seq_cst); // expected-warning {{incompatible integer to pointer conversion}} (int)__c11_atomic_store(d, 1, memory_order_seq_cst); // expected-error {{operand of type 'void'}} diff --git a/test/Sema/attr-alias-elf.c b/test/Sema/attr-alias-elf.c index f14514dccd2c..e56f23e4fa51 100644 --- a/test/Sema/attr-alias-elf.c +++ b/test/Sema/attr-alias-elf.c @@ -55,7 +55,7 @@ typedef int b4; void test2_bar() {} void test2_foo() __attribute__((weak, alias("test2_bar"))); -void test2_zed() __attribute__((alias("test2_foo"))); // expected-warning {{alias will always resolve to test2_bar even if weak definition of alias test2_foo is overridden}} +void test2_zed() __attribute__((alias("test2_foo"))); // expected-warning {{alias will always resolve to test2_bar even if weak definition of test2_foo is overridden}} void test3_bar() { } void test3_foo() __attribute__((section("test"))); // expected-warning {{alias will not be in section 'test' but in the same section as the aliasee}} diff --git a/test/Sema/attr-aligned.c b/test/Sema/attr-aligned.c index 0a2698ec91af..b8d2fc6863d2 100644 --- a/test/Sema/attr-aligned.c +++ b/test/Sema/attr-aligned.c @@ -3,6 +3,9 @@ int x __attribute__((aligned(3))); // expected-error {{requested alignment is not a power of 2}} int y __attribute__((aligned(1 << 29))); // expected-error {{requested alignment must be 268435456 bytes or smaller}} +// PR26444 +int y __attribute__((aligned(1 << 28))); + // PR3254 short g0[3] __attribute__((aligned)); short g0_chk[__alignof__(g0) == 16 ? 1 : -1]; diff --git a/test/Sema/attr-availability-macosx.c b/test/Sema/attr-availability-macosx.c index 38f149ba62ae..f422811708fa 100644 --- a/test/Sema/attr-availability-macosx.c +++ b/test/Sema/attr-availability-macosx.c @@ -1,21 +1,37 @@ // RUN: %clang_cc1 "-triple" "x86_64-apple-darwin9.0.0" -fsyntax-only -verify %s +#if !__has_feature(attribute_availability_with_strict) +#error "Missing __has_feature" +#endif + void f0(int) __attribute__((availability(macosx,introduced=10.4,deprecated=10.6))); void f1(int) __attribute__((availability(macosx,introduced=10.5))); void f2(int) __attribute__((availability(macosx,introduced=10.4,deprecated=10.5))); // expected-note {{'f2' has been explicitly marked deprecated here}} void f3(int) __attribute__((availability(macosx,introduced=10.6))); void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(ios,introduced=2.0,deprecated=3.0))); // expected-note{{explicitly marked unavailable}} void f5(int) __attribute__((availability(ios,introduced=3.2), availability(macosx,unavailable))); // expected-note{{'f5' has been explicitly marked unavailable here}} +void f6(int) __attribute__((availability(macosx,strict,introduced=10.6))); //expected-note{{'f6' has been explicitly marked unavailable here}} void test() { f0(0); f1(0); - f2(0); // expected-warning{{'f2' is deprecated: first deprecated in OS X 10.5}} + f2(0); // expected-warning{{'f2' is deprecated: first deprecated in macOS 10.5}} f3(0); - f4(0); // expected-error{{f4' is unavailable: obsoleted in OS X 10.5}} - f5(0); // expected-error{{'f5' is unavailable: not available on OS X}} + f4(0); // expected-error{{f4' is unavailable: obsoleted in macOS 10.5}} + f5(0); // expected-error{{'f5' is unavailable: not available on macOS}} + f6(0); // expected-error{{'f6' is unavailable: introduced in macOS 10.6}} } +struct __attribute__((availability(macosx,strict,introduced=10.6))) + not_yet_introduced_struct; // \ + expected-note{{'not_yet_introduced_struct' has been explicitly marked unavailable here}} + +void uses_not_introduced_struct(struct not_yet_introduced_struct *); // \ + expected-error{{'not_yet_introduced_struct' is unavailable: introduced in macOS 10.6}} + +__attribute__((availability(macosx,strict,introduced=10.6))) +void uses_not_introduced_struct_same_availability(struct not_yet_introduced_struct *); + // rdar://10535640 enum { @@ -29,3 +45,14 @@ enum { enum __attribute__((availability(macosx,introduced=8.0,deprecated=9.0))) { bar1 = foo }; + +// Make sure the note is on the declaration with the actual availability attributes. +struct __attribute__((availability(macosx,strict,introduced=10.9))) type_info // \ + expected-note{{'type_info' has been explicitly marked unavailable here}} +{ +}; +struct type_info; +int test2() { + struct type_info *t; // expected-error{{'type_info' is unavailable: introduced in macOS 10.9}} + return 0; +} diff --git a/test/Sema/attr-availability-tvos.c b/test/Sema/attr-availability-tvos.c index b60fdb0d19cc..642246425b37 100644 --- a/test/Sema/attr-availability-tvos.c +++ b/test/Sema/attr-availability-tvos.c @@ -27,6 +27,12 @@ void test_transcribed_availability() { f9(0); } +__attribute__((availability(ios,introduced=9_0,deprecated=9_0,message="" ))) // expected-note{{previous attribute is here}} \ + // expected-note{{previous attribute is here}} +__attribute__((availability(ios,introduced=7_0))) // expected-warning{{availability does not match previous declaration}} \ + // expected-warning{{availability does not match previous declaration}} +void f10(int); + // Test tvOS specific attributes. void f0_tvos(int) __attribute__((availability(tvos,introduced=2.0,deprecated=2.1))); // expected-note {{'f0_tvos' has been explicitly marked deprecated here}} void f1_tvos(int) __attribute__((availability(tvos,introduced=2.1))); diff --git a/test/Sema/attr-availability.c b/test/Sema/attr-availability.c index d003e1e2e363..8fe6be3804ed 100644 --- a/test/Sema/attr-availability.c +++ b/test/Sema/attr-availability.c @@ -2,7 +2,7 @@ // RUN: %clang_cc1 -D WARN_PARTIAL -Wpartial-availability -triple x86_64-apple-darwin9 -fsyntax-only -fblocks -verify %s // -void f0() __attribute__((availability(macosx,introduced=10.4,deprecated=10.2))); // expected-warning{{feature cannot be deprecated in OS X version 10.2 before it was introduced in version 10.4; attribute ignored}} +void f0() __attribute__((availability(macosx,introduced=10.4,deprecated=10.2))); // expected-warning{{feature cannot be deprecated in macOS version 10.2 before it was introduced in version 10.4; attribute ignored}} void f1() __attribute__((availability(ios,obsoleted=2.1,deprecated=3.0))); // expected-warning{{feature cannot be obsoleted in iOS version 2.1 before it was deprecated in version 3.0; attribute ignored}} void f2() __attribute__((availability(ios,introduced=2.1,deprecated=2.1))); @@ -26,11 +26,11 @@ enum __attribute__((availability(macosx,introduced=10.8))) PartialEnum { }; void test_10095131() { - ATSFontGetName("Hello"); // expected-warning {{'ATSFontGetName' is deprecated: first deprecated in OS X 9.0 - use CTFontCopyFullName}} - ATSFontGetPostScriptName(100); // expected-error {{'ATSFontGetPostScriptName' is unavailable: obsoleted in OS X 9.0 - use ATSFontGetFullPostScriptName}} + ATSFontGetName("Hello"); // expected-warning {{'ATSFontGetName' is deprecated: first deprecated in macOS 9.0 - use CTFontCopyFullName}} + ATSFontGetPostScriptName(100); // expected-error {{'ATSFontGetPostScriptName' is unavailable: obsoleted in macOS 9.0 - use ATSFontGetFullPostScriptName}} #if defined(WARN_PARTIAL) - // expected-warning@+2 {{is partial: introduced in OS X 10.8}} expected-note@+2 {{explicitly redeclare 'PartiallyAvailable' to silence this warning}} + // expected-warning@+2 {{is partial: introduced in macOS 10.8}} expected-note@+2 {{explicitly redeclare 'PartiallyAvailable' to silence this warning}} #endif PartiallyAvailable(); } diff --git a/test/Sema/attr-deprecated.c b/test/Sema/attr-deprecated.c index 2e3e722942a0..8566a0e94362 100644 --- a/test/Sema/attr-deprecated.c +++ b/test/Sema/attr-deprecated.c @@ -122,5 +122,10 @@ struct test22 { }; typedef int test23_ty __attribute((deprecated)); +// Redefining a typedef is a C11 feature. +#if __STDC_VERSION__ <= 199901L +// expected-note@-3 {{'test23_ty' has been explicitly marked deprecated here}} +#else typedef int test23_ty; // expected-note {{'test23_ty' has been explicitly marked deprecated here}} +#endif test23_ty test23_v; // expected-warning {{'test23_ty' is deprecated}} diff --git a/test/Sema/attr-ifunc.c b/test/Sema/attr-ifunc.c new file mode 100644 index 000000000000..d177b7168488 --- /dev/null +++ b/test/Sema/attr-ifunc.c @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -triple x86_64-windows -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm-only -DCHECK_ALIASES %s +// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm-only %s + +#if defined(_WIN32) +void foo() {} +void bar() __attribute__((ifunc("foo"))); +//expected-warning@-1 {{'ifunc' attribute ignored}} + +#else +#if defined(CHECK_ALIASES) +void* f1_ifunc(); +void f1() __attribute__((ifunc("f1_ifunc"))); +//expected-error@-1 {{ifunc must point to a defined function}} + +void* f2_a() __attribute__((ifunc("f2_b"))); +//expected-error@-1 {{ifunc definition is part of a cycle}} +void* f2_b() __attribute__((ifunc("f2_a"))); +//expected-error@-1 {{ifunc definition is part of a cycle}} + +void* f3_a() __attribute__((ifunc("f3_b"))); +//expected-warning@-1 {{ifunc will always resolve to f3_c even if weak definition of f3_b is overridden}} +void* f3_b() __attribute__((weak, alias("f3_c"))); +void* f3_c() { return 0; } + +void f4_ifunc() {} +void f4() __attribute__((ifunc("f4_ifunc"))); +//expected-error@-1 {{ifunc resolver function must return a pointer}} + +void* f5_ifunc(int i) { return 0; } +void f5() __attribute__((ifunc("f5_ifunc"))); +//expected-error@-1 {{ifunc resolver function must have no parameters}} + +#else +void f1a() __asm("f1"); +void f1a() {} +//expected-note@-1 {{previous definition is here}} +void f1() __attribute__((ifunc("f1_ifunc"))); +//expected-error@-1 {{definition with same mangled name as another definition}} +void* f1_ifunc() { return 0; } + +#endif +#endif diff --git a/test/Sema/attr-mode-enums.c b/test/Sema/attr-mode-enums.c new file mode 100644 index 000000000000..4b98c3b4472d --- /dev/null +++ b/test/Sema/attr-mode-enums.c @@ -0,0 +1,51 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// Test checks that 'mode' attribute is handled correctly with enums, i. e. code +// 1. "typedef enum { A } __attribute__((mode(HI))) T;" is accepted, +// 2. "enum X __attribute__((mode(QI))) var;" forms a complete integer type. +// 3. "enum { A } __attribute__((mode(V4SI))) var;" is not accepted (vector mode). + +typedef enum { E4 } EnumType; + +int main() { + // Vector mode are not allowed with enums. + typedef enum { E1 } __attribute__((mode(V4QI))) RejectedType1; // expected-error{{mode 'V4QI' is not supported for enumeration types}} + // expected-warning@-1{{specifying vector types with the 'mode' attribute is deprecated}} + typedef enum __attribute__((mode(V8HI))) { E2 } RejectedType2; // expected-error{{mode 'V8HI' is not supported for enumeration types}} + // expected-warning@-1{{deprecated}} + typedef enum E3 __attribute__((mode(V2SI))) RejectedType3; // expected-error{{mode 'V2SI' is not supported for enumeration types}} + // expected-warning@-1{{deprecated}} + typedef EnumType __attribute__((mode(V4DI))) RejectedType4; // expected-error{{mode 'V4DI' is not supported for enumeration types}} + // expected-warning@-1{{deprecated}} + EnumType v1 __attribute__((mode(V4QI))); // expected-error{{mode 'V4QI' is not supported for enumeration types}} + // expected-warning@-1{{deprecated}} + enum __attribute__((mode(V8HI))) { E5 } v2; // expected-error{{mode 'V8HI' is not supported for enumeration types}} + // expected-warning@-1{{deprecated}} + + // Incomplete enums without mode attribute are not allowed. + typedef enum Y IncompleteYType; // expected-note{{forward declaration of 'enum Y'}} + + enum X a1; // expected-error{{variable has incomplete type 'enum X'}} + // expected-note@-1{{forward declaration of 'enum X'}} + IncompleteYType a2; // expected-error{{variable has incomplete type 'IncompleteYType' (aka 'enum Y')}} + + // OK with 'mode' attribute. + typedef enum Y __attribute__((mode(QI))) CompleteYType1; + typedef enum Y CompleteYType2 __attribute__((mode(HI))); + typedef enum { A1, B1 } __attribute__((mode(QI))) CompleteType3; + typedef enum { A2, B2 } CompleteType4 __attribute__((mode(QI))); + typedef enum __attribute__((mode(QI))) { A3, B3 } CompleteType5; + + enum X __attribute__((mode(QI))) a3; + enum X a4 __attribute__((mode(HI))); + IncompleteYType __attribute__((mode(QI))) a5; + IncompleteYType a6 __attribute__((mode(HI))); + CompleteYType1 a7; + CompleteYType2 a8; + CompleteType3 a9; + CompleteType4 a10; + CompleteType5 a11; + enum __attribute__((mode(QI))) { A4, B4 } a12; + + return 0; +} diff --git a/test/Sema/attr-mode.c b/test/Sema/attr-mode.c index 49e41d210d03..e160d8d4846d 100644 --- a/test/Sema/attr-mode.c +++ b/test/Sema/attr-mode.c @@ -4,6 +4,8 @@ // RUN: -verify %s // RUN: %clang_cc1 -triple powerpc64-pc-linux-gnu -DTEST_64BIT_PPC64 -fsyntax-only \ // RUN: -verify %s +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnux32 -DTEST_64BIT_X86 -fsyntax-only \ +// RUN: -verify %s typedef int i16_1 __attribute((mode(HI))); int i16_1_test[sizeof(i16_1) == 2 ? 1 : -1]; @@ -24,6 +26,9 @@ typedef unsigned unwind_word __attribute((mode(unwind_word))); int **__attribute((mode(QI)))* i32; // expected-error{{mode attribute}} +__attribute__((mode(QI))) int invalid_func() { return 1; } // expected-error{{'mode' attribute only applies to variables, enums, fields and typedefs}} +enum invalid_enum { A1 __attribute__((mode(QI))) }; // expected-error{{'mode' attribute only applies to variables, enums, fields and typedefs}} + typedef _Complex double c32 __attribute((mode(SC))); int c32_test[sizeof(c32) == 8 ? 1 : -1]; typedef _Complex float c64 __attribute((mode(DC))); @@ -60,9 +65,18 @@ void test_int_to_ui32(unsigned int* y) { f_ui32_arg(y); } void test_long_to_i64(long long* y) { f_i64_arg(y); } void test_long_to_ui64(unsigned long long* y) { f_ui64_arg(y); } #elif TEST_64BIT_X86 +#ifdef __ILP32__ +typedef unsigned int gcc_word __attribute__((mode(word))); +int foo[sizeof(gcc_word) == 8 ? 1 : -1]; +typedef unsigned int gcc_unwind_word __attribute__((mode(unwind_word))); +int foo[sizeof(gcc_unwind_word) == 8 ? 1 : -1]; +void test_long_to_i64(long long* y) { f_i64_arg(y); } +void test_long_to_ui64(unsigned long long* y) { f_ui64_arg(y); } +#else void test_long_to_i64(long* y) { f_i64_arg(y); } void test_long_to_ui64(unsigned long* y) { f_ui64_arg(y); } -typedef float f128ibm __attribute__ ((mode (TF))); // expected-error{{unsupported machine mode 'TF'}} +#endif +typedef float f128ibm __attribute__ ((mode (TF))); #elif TEST_64BIT_PPC64 typedef float f128ibm __attribute__ ((mode (TF))); typedef _Complex float c128ibm __attribute__ ((mode (TC))); @@ -73,3 +87,7 @@ void test_TCtype(c128ibm *a) { f_ft128_complex_arg (a); } #else #error Unknown test architecture. #endif + +struct S { + int n __attribute((mode(HI))); +}; diff --git a/test/Sema/attr-nodebug.c b/test/Sema/attr-nodebug.c index 03ec49b850d6..e7ca58d3ba15 100644 --- a/test/Sema/attr-nodebug.c +++ b/test/Sema/attr-nodebug.c @@ -2,8 +2,8 @@ int a __attribute__((nodebug)); -void b() { - int b __attribute__((nodebug)); // expected-warning {{'nodebug' only applies to variables with static storage duration and functions}} +void b(int p __attribute__((nodebug))) { // expected-warning {{'nodebug' attribute only applies to variables and functions}} + int b __attribute__((nodebug)); } void t1() __attribute__((nodebug)); diff --git a/test/Sema/attr-print.c b/test/Sema/attr-print.c index b3bdfd72e645..7ffbbb800d51 100644 --- a/test/Sema/attr-print.c +++ b/test/Sema/attr-print.c @@ -32,3 +32,6 @@ int * __uptr __ptr32 p32_3; // CHECK: int * __sptr * __ptr32 ppsp32; int * __sptr * __ptr32 ppsp32; + +// CHECK: __attribute__((availability(macos, strict, introduced=10.6))); +void f6(int) __attribute__((availability(macosx,strict,introduced=10.6))); diff --git a/test/Sema/attr-swiftcall.c b/test/Sema/attr-swiftcall.c new file mode 100644 index 000000000000..3458167cf2e8 --- /dev/null +++ b/test/Sema/attr-swiftcall.c @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s + +#define SWIFTCALL __attribute__((swiftcall)) +#define INDIRECT_RESULT __attribute__((swift_indirect_result)) +#define ERROR_RESULT __attribute__((swift_error_result)) +#define CONTEXT __attribute__((swift_context)) + +int notAFunction SWIFTCALL; // expected-warning {{'swiftcall' only applies to function types; type here is 'int'}} +void variadic(int x, ...) SWIFTCALL; // expected-error {{variadic function cannot use swiftcall calling convention}} +void unprototyped() SWIFTCALL; // expected-error {{function with no prototype cannot use the swiftcall calling convention}} +void multiple_ccs(int x) SWIFTCALL __attribute__((vectorcall)); // expected-error {{vectorcall and swiftcall attributes are not compatible}} +void (*functionPointer)(void) SWIFTCALL; + +void indirect_result_nonswift(INDIRECT_RESULT void *out); // expected-error {{'swift_indirect_result' parameter can only be used with swiftcall calling convention}} +void indirect_result_bad_position(int first, INDIRECT_RESULT void *out) SWIFTCALL; // expected-error {{'swift_indirect_result' parameters must be first parameters of function}} +void indirect_result_bad_type(INDIRECT_RESULT int out) SWIFTCALL; // expected-error {{'swift_indirect_result' parameter must have pointer type; type here is 'int'}} +void indirect_result_single(INDIRECT_RESULT void *out) SWIFTCALL; +void indirect_result_multiple(INDIRECT_RESULT void *out1, INDIRECT_RESULT void *out2) SWIFTCALL; + +void error_result_nonswift(ERROR_RESULT void **error); // expected-error {{'swift_error_result' parameter can only be used with swiftcall calling convention}} expected-error{{'swift_error_result' parameter must follow 'swift_context' parameter}} +void error_result_bad_position(ERROR_RESULT void **error, int last) SWIFTCALL; // expected-error {{'swift_error_result' parameter must be last parameter of function}} +void error_result_bad_position2(int first, ERROR_RESULT void **error) SWIFTCALL; // expected-error {{'swift_error_result' parameter must follow 'swift_context' parameter}} +void error_result_bad_type(CONTEXT void *context, ERROR_RESULT int error) SWIFTCALL; // expected-error {{'swift_error_result' parameter must have pointer to unqualified pointer type; type here is 'int'}} +void error_result_bad_type2(CONTEXT void *context, ERROR_RESULT int *error) SWIFTCALL; // expected-error {{'swift_error_result' parameter must have pointer to unqualified pointer type; type here is 'int *'}} +void error_result_okay(int a, int b, CONTEXT void *context, ERROR_RESULT void **error) SWIFTCALL; + +void context_nonswift(CONTEXT void *context); // expected-error {{'swift_context' parameter can only be used with swiftcall calling convention}} +void context_bad_position(CONTEXT void *context, int x) SWIFTCALL; // expected-error {{'swift_context' parameter can only be followed by 'swift_error_result' parameter}} +void context_bad_type(CONTEXT int context) SWIFTCALL; // expected-error {{'swift_context' parameter must have pointer type; type here is 'int'}} +void context_okay(CONTEXT void *context) SWIFTCALL; diff --git a/test/Sema/attr-x86-interrupt.c b/test/Sema/attr-x86-interrupt.c new file mode 100644 index 000000000000..0785fdfcb1b3 --- /dev/null +++ b/test/Sema/attr-x86-interrupt.c @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-pc-win32 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i386-pc-win32 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnux32 -fsyntax-only -verify %s + +struct a { + int b; +}; + +struct a test __attribute__((interrupt)); // expected-warning {{'interrupt' attribute only applies to non-K&R-style functions}} + +__attribute__((interrupt)) int foo1(void) { return 0; } // expected-error-re {{{{(x86|x86-64)}} 'interrupt' attribute only applies to functions that have a 'void' return type}} +__attribute__((interrupt)) void foo2(void) {} // expected-error-re {{{{(x86|x86-64)}} 'interrupt' attribute only applies to functions that have only a pointer parameter optionally followed by an integer parameter}} +__attribute__((interrupt)) void foo3(void *a, unsigned b, int c) {} // expected-error-re {{{{(x86|x86-64)}} 'interrupt' attribute only applies to functions that have only a pointer parameter optionally followed by an integer parameter}} +__attribute__((interrupt)) void foo4(int a) {} // expected-error-re {{{{(x86|x86-64)}} 'interrupt' attribute only applies to functions that have a pointer as the first parameter}} +#ifdef _LP64 +// expected-error-re@+6 {{{{(x86|x86-64)}} 'interrupt' attribute only applies to functions that have a 'unsigned long' type as the second parameter}} +#elif defined(__x86_64__) +// expected-error-re@+4 {{{{(x86|x86-64)}} 'interrupt' attribute only applies to functions that have a 'unsigned long long' type as the second parameter}} +#else +// expected-error-re@+2 {{{{(x86|x86-64)}} 'interrupt' attribute only applies to functions that have a 'unsigned int' type as the second parameter}} +#endif +__attribute__((interrupt)) void foo5(void *a, float b) {} +#ifdef _LP64 +// expected-error-re@+6 {{{{(x86|x86-64)}} 'interrupt' attribute only applies to functions that have a 'unsigned long' type as the second parameter}} +#elif defined(__x86_64__) +// expected-error-re@+4 {{{{(x86|x86-64)}} 'interrupt' attribute only applies to functions that have a 'unsigned long long' type as the second parameter}} +#else +// expected-error-re@+2 {{{{(x86|x86-64)}} 'interrupt' attribute only applies to functions that have a 'unsigned int' type as the second parameter}} +#endif +__attribute__((interrupt)) void foo6(float *a, int b) {} + +#ifdef _LP64 +// expected-error-re@+4 {{{{(x86|x86-64)}} 'interrupt' attribute only applies to functions that have a 'unsigned long' type as the second parameter}} +#elif defined(__x86_64__) +// expected-error-re@+2 {{{{(x86|x86-64)}} 'interrupt' attribute only applies to functions that have a 'unsigned long long' type as the second parameter}} +#endif +__attribute__((interrupt)) void foo7(int *a, unsigned b) {} +__attribute__((interrupt)) void foo8(int *a) {} + +void g(void (*fp)(int *)); +int main(int argc, char **argv) { + void *ptr = (void *)&foo7; + g(foo8); + + (void)ptr; +#ifndef __x86_64__ + // expected-error@+2 {{interrupt service routine cannot be called directly}} +#endif + foo7((int *)argv, argc); + foo8((int *)argv); // expected-error {{interrupt service routine cannot be called directly}} + return 0; +} + diff --git a/test/Sema/bitfield-layout.c b/test/Sema/bitfield-layout.c index b96b38686417..079720cc9b40 100644 --- a/test/Sema/bitfield-layout.c +++ b/test/Sema/bitfield-layout.c @@ -1,6 +1,8 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=i686-apple-darwin9 // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=arm-linux-gnueabihf // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=aarch64-linux-gnu +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-pc-linux-gnu +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-scei-ps4 // expected-no-diagnostics #include <stddef.h> @@ -95,9 +97,15 @@ struct g0 { char c; }; +#if defined(__ORBIS__) +CHECK_SIZE(struct, g0, 16); +CHECK_ALIGN(struct, g0, 16); +CHECK_OFFSET(struct, g0, c, 2); +#else CHECK_SIZE(struct, g0, 32); CHECK_ALIGN(struct, g0, 16); CHECK_OFFSET(struct, g0, c, 17); +#endif // Bit-field with explicit align smaller than normal. struct g1 { @@ -108,7 +116,11 @@ struct g1 { CHECK_SIZE(struct, g1, 4); CHECK_ALIGN(struct, g1, 4); +#if defined(__ORBIS__) +CHECK_OFFSET(struct, g1, c, 2); +#else CHECK_OFFSET(struct, g1, c, 3); +#endif // Same as above but without explicit align. struct g2 { @@ -129,9 +141,14 @@ struct __attribute__((packed)) g3 { char c; }; -CHECK_SIZE(struct, g3, 32); CHECK_ALIGN(struct, g3, 16); +#if defined(__ORBIS__) +CHECK_SIZE(struct, g3, 16); +CHECK_OFFSET(struct, g3, c, 2); +#else +CHECK_SIZE(struct, g3, 32); CHECK_OFFSET(struct, g3, c, 17); +#endif struct __attribute__((packed)) g4 { char a; @@ -141,7 +158,11 @@ struct __attribute__((packed)) g4 { CHECK_SIZE(struct, g4, 4); CHECK_ALIGN(struct, g4, 2); +#if defined(__ORBIS__) +CHECK_OFFSET(struct, g4, c, 2); +#else CHECK_OFFSET(struct, g4, c, 3); +#endif struct g5 { char : 1; @@ -161,28 +182,44 @@ struct g7 { char : 1; __attribute__((aligned(1))) int n : 25; }; +#if defined(__ORBIS__) +CHECK_SIZE(struct, g7, 4); +#else CHECK_SIZE(struct, g7, 8); +#endif CHECK_ALIGN(struct, g7, 4); struct __attribute__((packed)) g8 { char : 1; __attribute__((aligned(1))) int n : 25; }; +#if defined(__ORBIS__) +CHECK_SIZE(struct, g8, 4); +#else CHECK_SIZE(struct, g8, 5); +#endif CHECK_ALIGN(struct, g8, 1); struct g9 { __attribute__((aligned(1))) char a : 2, b : 2, c : 2, d : 2, e : 2; int i; }; +#if defined(__ORBIS__) +CHECK_SIZE(struct, g9, 8); +#else CHECK_SIZE(struct, g9, 12); +#endif CHECK_ALIGN(struct, g9, 4); struct __attribute__((packed)) g10 { __attribute__((aligned(1))) char a : 2, b : 2, c : 2, d : 2, e : 2; int i; }; +#if defined(__ORBIS__) +CHECK_SIZE(struct, g10, 6); +#else CHECK_SIZE(struct, g10, 9); +#endif CHECK_ALIGN(struct, g10, 1); struct g11 { @@ -190,7 +227,7 @@ struct g11 { __attribute__((aligned(1))) long long b : 62; char c; }; -#if defined(__arm__) || defined(__aarch64__) +#if defined(__arm__) || defined(__aarch64__) || defined(__x86_64__) CHECK_SIZE(struct, g11, 24); CHECK_ALIGN(struct, g11, 8); CHECK_OFFSET(struct, g11, c, 16); @@ -218,6 +255,10 @@ struct g13 { CHECK_SIZE(struct, g13, 16); CHECK_ALIGN(struct, g13, 8); CHECK_OFFSET(struct, g13, c, 8); +#elif defined(__x86_64__) +CHECK_SIZE(struct, g13, 9); +CHECK_ALIGN(struct, g13, 1); +CHECK_OFFSET(struct, g13, c, 8); #else CHECK_SIZE(struct, g13, 5); CHECK_ALIGN(struct, g13, 1); @@ -233,6 +274,10 @@ struct __attribute__((packed)) g14 { CHECK_SIZE(struct, g14, 16); CHECK_ALIGN(struct, g14, 8); CHECK_OFFSET(struct, g14, c, 8); +#elif defined(__x86_64__) +CHECK_SIZE(struct, g14, 9); +CHECK_ALIGN(struct, g14, 1); +CHECK_OFFSET(struct, g14, c, 8); #else CHECK_SIZE(struct, g14, 5); CHECK_ALIGN(struct, g14, 1); diff --git a/test/Sema/bitfield-layout_1.c b/test/Sema/bitfield-layout_1.c new file mode 100644 index 000000000000..24277c391149 --- /dev/null +++ b/test/Sema/bitfield-layout_1.c @@ -0,0 +1,202 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=i686-apple-darwin9 +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=arm-linux-gnueabihf +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=aarch64-linux-gnu +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-pc-linux-gnu +// expected-no-diagnostics + +#define CHECK_SIZE(name, size) \ + extern int name##_1[sizeof(name) == size ? 1 : -1]; + + +struct __attribute__((packed)) { + int a; + int b : 4; + int c : 32; +} s0; +CHECK_SIZE(s0,9) + +#pragma pack (1) +struct { + int a; + int b : 4; + int c : 32; +} s1; +CHECK_SIZE(s1,9) + +#pragma pack (2) +struct { + int a; + int b : 4; + int c : 32; +} s2; +CHECK_SIZE(s2,10) + +#pragma pack (2) +struct __attribute__((packed)) { + int a; + int b : 4; + int c : 32; +} s3; +CHECK_SIZE(s3,10) + +#pragma pack (4) +struct __attribute__((packed)) { + int a; + int b : 4; + int c : 32; +} s4; +CHECK_SIZE(s4,12) + +#pragma pack (16) +struct { + int a; + int __attribute__((packed)) b : 4; + int __attribute__((packed)) c : 32; +} s41; +CHECK_SIZE(s41,12) + +#pragma pack (16) +struct { + int a; + int b : 4; + int c : 32; +} s5; +CHECK_SIZE(s5,12) + +#pragma pack (1) +struct __attribute__((aligned(4))) { + int a; + int b : 4; + int c : 32; +} s6; +CHECK_SIZE(s6,12) + +#pragma pack (2) +struct { + char a; + int b : 4; + int c : 32; + char s; +} s7; +CHECK_SIZE(s7,8) + +#pragma pack (1) +struct { + char a; + int b : 4; + int c : 28; + char s; +} s8; +CHECK_SIZE(s8,6) + +#pragma pack (8) +struct { + char a; + int b : 4; + int c : 28; + char s; +} s9; +CHECK_SIZE(s9,8) + +#pragma pack (8) +struct { + char a; + char s; +} s10; +CHECK_SIZE(s10,2) + +#pragma pack(4) +struct { + char a; + int b : 4; + int c : 28; + char s1; + char s2; + char s3; +} s11; +CHECK_SIZE(s11,8) + +#pragma pack(4) +struct { + short s1; + int a1 : 17; + int a2 : 17; + int a3 : 30; + short s2; +} s12; +CHECK_SIZE(s12,12) + +#pragma pack(4) +struct { + char c1; + int i1 : 17; + int i2 : 17; + int i3 : 30; + char c2; +} s13; +CHECK_SIZE(s13,12) + +#pragma pack(2) +struct { + char a; + int s; +} s14; +CHECK_SIZE(s14,6) + +#pragma pack(4) +struct { + char a; + short s; +} s15; +CHECK_SIZE(s15,4) + +#pragma pack(2) +struct { + char a; + int b : 4; + int c : 28; + char s1; + char s2; + char s3; +} s16; +CHECK_SIZE(s16,8) + +#pragma pack (16) +struct { + int __attribute__((packed)) a; + int __attribute__((packed)) b : 4; + int __attribute__((packed)) c : 32; +} s17; +CHECK_SIZE(s17,12) + +#pragma pack (16) +struct { + int __attribute__((aligned(8))) a; + int __attribute__((aligned(8))) b : 4; + int __attribute__((aligned(8))) c : 32; +} s18; +CHECK_SIZE(s18,24) + +#pragma pack (16) +struct { + int __attribute__((aligned(1))) a; + int __attribute__((aligned(1))) b : 4; + int __attribute__((aligned(1))) c : 32; +} s19; +CHECK_SIZE(s19,12) + +#pragma pack (1) +struct __attribute__((aligned(8))) { + int a; + int b : 4; + int c : 32; +} s20; +CHECK_SIZE(s20,16) + +#pragma pack (2) +struct { + int __attribute__((aligned(8))) a; + int __attribute__((aligned(8))) b : 4; + int __attribute__((aligned(8))) c : 32; +} s21; +CHECK_SIZE(s21,10) diff --git a/test/Sema/builtin-classify-type.c b/test/Sema/builtin-classify-type.c new file mode 100644 index 000000000000..376e73d1118c --- /dev/null +++ b/test/Sema/builtin-classify-type.c @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// expected-no-diagnostics + +enum gcc_type_class { + no_type_class = -1, + void_type_class, integer_type_class, char_type_class, + enumeral_type_class, boolean_type_class, + pointer_type_class, reference_type_class, offset_type_class, + real_type_class, complex_type_class, + function_type_class, method_type_class, + record_type_class, union_type_class, + array_type_class, string_type_class, + lang_type_class +}; + +void foo() { + int i; + char c; + enum { red, green, blue } enum_obj; + int *p; + double d; + _Complex double cc; + extern void f(); + struct { int a; float b; } s_obj; + union { int a; float b; } u_obj; + int arr[10]; + + int a1[__builtin_classify_type(f()) == void_type_class ? 1 : -1]; + int a2[__builtin_classify_type(i) == integer_type_class ? 1 : -1]; + int a3[__builtin_classify_type(c) == integer_type_class ? 1 : -1]; + int a4[__builtin_classify_type(enum_obj) == integer_type_class ? 1 : -1]; + int a5[__builtin_classify_type(p) == pointer_type_class ? 1 : -1]; + int a6[__builtin_classify_type(d) == real_type_class ? 1 : -1]; + int a7[__builtin_classify_type(cc) == complex_type_class ? 1 : -1]; + int a8[__builtin_classify_type(f) == pointer_type_class ? 1 : -1]; + int a0[__builtin_classify_type(s_obj) == record_type_class ? 1 : -1]; + int a10[__builtin_classify_type(u_obj) == union_type_class ? 1 : -1]; + int a11[__builtin_classify_type(arr) == pointer_type_class ? 1 : -1]; + int a12[__builtin_classify_type("abc") == pointer_type_class ? 1 : -1]; +} + diff --git a/test/Sema/builtin-longjmp.c b/test/Sema/builtin-longjmp.c index fdfbcf861dda..d80208f82c67 100644 --- a/test/Sema/builtin-longjmp.c +++ b/test/Sema/builtin-longjmp.c @@ -3,6 +3,7 @@ // RUN: %clang_cc1 -triple x86_64-windows -emit-llvm < %s| FileCheck %s // RUN: %clang_cc1 -triple powerpc-unknown-unknown -emit-llvm < %s| FileCheck %s // RUN: %clang_cc1 -triple powerpc64-unknown-unknown -emit-llvm < %s| FileCheck %s +// RUN: %clang_cc1 -triple sparc-eabi-unknown -emit-llvm < %s | FileCheck %s // RUN: %clang_cc1 -triple aarch64-unknown-unknown -emit-llvm-only -verify %s // RUN: %clang_cc1 -triple mips-unknown-unknown -emit-llvm-only -verify %s diff --git a/test/Sema/builtin-object-size.c b/test/Sema/builtin-object-size.c index b1bda0652c14..14674c66f3a6 100644 --- a/test/Sema/builtin-object-size.c +++ b/test/Sema/builtin-object-size.c @@ -52,3 +52,27 @@ void f6(void) __builtin___memccpy_chk (buf, b, '\0', sizeof(b), __builtin_object_size (buf, 0)); __builtin___memccpy_chk (b, buf, '\0', sizeof(buf), __builtin_object_size (b, 0)); // expected-warning {{'__builtin___memccpy_chk' will always overflow destination buffer}} } + +int pr28314(void) { + struct { + struct InvalidField a; // expected-error{{has incomplete type}} expected-note 3{{forward declaration of 'struct InvalidField'}} + char b[0]; + } *p; + + struct { + struct InvalidField a; // expected-error{{has incomplete type}} + char b[1]; + } *p2; + + struct { + struct InvalidField a; // expected-error{{has incomplete type}} + char b[2]; + } *p3; + + int a = 0; + a += __builtin_object_size(&p->a, 0); + a += __builtin_object_size(p->b, 0); + a += __builtin_object_size(p2->b, 0); + a += __builtin_object_size(p3->b, 0); + return a; +} diff --git a/test/Sema/builtins-arm.c b/test/Sema/builtins-arm.c index 39cb2fa2962c..668b8284ffeb 100644 --- a/test/Sema/builtins-arm.c +++ b/test/Sema/builtins-arm.c @@ -48,6 +48,50 @@ void test5() { } void test6(int a, int b, int c) { + __builtin_arm_ldc(1, 2, &a); + __builtin_arm_ldc(a, 2, &a); // expected-error {{argument to '__builtin_arm_ldc' must be a constant integer}} + __builtin_arm_ldc(1, a, &a); // expected-error {{argument to '__builtin_arm_ldc' must be a constant integer}} + + __builtin_arm_ldcl(1, 2, &a); + __builtin_arm_ldcl(a, 2, &a); // expected-error {{argument to '__builtin_arm_ldcl' must be a constant integer}} + __builtin_arm_ldcl(1, a, &a); // expected-error {{argument to '__builtin_arm_ldcl' must be a constant integer}} + + __builtin_arm_ldc2(1, 2, &a); + __builtin_arm_ldc2(a, 2, &a); // expected-error {{argument to '__builtin_arm_ldc2' must be a constant integer}} + __builtin_arm_ldc2(1, a, &a); // expected-error {{argument to '__builtin_arm_ldc2' must be a constant integer}} + + __builtin_arm_ldc2l(1, 2, &a); + __builtin_arm_ldc2l(a, 2, &a); // expected-error {{argument to '__builtin_arm_ldc2l' must be a constant integer}} + __builtin_arm_ldc2l(1, a, &a); // expected-error {{argument to '__builtin_arm_ldc2l' must be a constant integer}} + + __builtin_arm_stc(1, 2, &a); + __builtin_arm_stc(a, 2, &a); // expected-error {{argument to '__builtin_arm_stc' must be a constant integer}} + __builtin_arm_stc(1, a, &a); // expected-error {{argument to '__builtin_arm_stc' must be a constant integer}} + + __builtin_arm_stcl(1, 2, &a); + __builtin_arm_stcl(a, 2, &a); // expected-error {{argument to '__builtin_arm_stcl' must be a constant integer}} + __builtin_arm_stcl(1, a, &a); // expected-error {{argument to '__builtin_arm_stcl' must be a constant integer}} + + __builtin_arm_stc2(1, 2, &a); + __builtin_arm_stc2(a, 2, &a); // expected-error {{argument to '__builtin_arm_stc2' must be a constant integer}} + __builtin_arm_stc2(1, a, &a); // expected-error {{argument to '__builtin_arm_stc2' must be a constant integer}} + + __builtin_arm_stc2l(1, 2, &a); + __builtin_arm_stc2l(a, 2, &a); // expected-error {{argument to '__builtin_arm_stc2l' must be a constant integer}} + __builtin_arm_stc2l(1, a, &a); // expected-error {{argument to '__builtin_arm_stc2l' must be a constant integer}} + + __builtin_arm_cdp(a, 2, 3, 4, 5, 6); // expected-error {{argument to '__builtin_arm_cdp' must be a constant integer}} + __builtin_arm_cdp(1, a, 3, 4, 5, 6); // expected-error {{argument to '__builtin_arm_cdp' must be a constant integer}} + __builtin_arm_cdp(1, 2, a, 4, 5, 6); // expected-error {{argument to '__builtin_arm_cdp' must be a constant integer}} + __builtin_arm_cdp(1, 2, 3, a, 5, 6); // expected-error {{argument to '__builtin_arm_cdp' must be a constant integer}} + __builtin_arm_cdp(1, 2, 3, 4, 5, a); // expected-error {{argument to '__builtin_arm_cdp' must be a constant integer}} + + __builtin_arm_cdp2(a, 2, 3, 4, 5, 6); // expected-error {{argument to '__builtin_arm_cdp2' must be a constant integer}} + __builtin_arm_cdp2(1, a, 3, 4, 5, 6); // expected-error {{argument to '__builtin_arm_cdp2' must be a constant integer}} + __builtin_arm_cdp2(1, 2, a, 4, 5, 6); // expected-error {{argument to '__builtin_arm_cdp2' must be a constant integer}} + __builtin_arm_cdp2(1, 2, 3, a, 5, 6); // expected-error {{argument to '__builtin_arm_cdp2' must be a constant integer}} + __builtin_arm_cdp2(1, 2, 3, 4, 5, a); // expected-error {{argument to '__builtin_arm_cdp2' must be a constant integer}} + __builtin_arm_mrc( a, 0, 13, 0, 3); // expected-error {{argument to '__builtin_arm_mrc' must be a constant integer}} __builtin_arm_mrc(15, a, 13, 0, 3); // expected-error {{argument to '__builtin_arm_mrc' must be a constant integer}} __builtin_arm_mrc(15, 0, a, 0, 3); // expected-error {{argument to '__builtin_arm_mrc' must be a constant integer}} @@ -72,11 +116,23 @@ void test6(int a, int b, int c) { __builtin_arm_mcr2(15, 0, b, 13, a, 3); // expected-error {{argument to '__builtin_arm_mcr2' must be a constant integer}} __builtin_arm_mcr2(15, 0, b, 13, 0, a); // expected-error {{argument to '__builtin_arm_mcr2' must be a constant integer}} - __builtin_arm_mcrr( a, 0, b, c, 0); // expected-error {{argument to '__builtin_arm_mcrr' must be a constant integer}} - __builtin_arm_mcrr(15, a, b, c, 0); // expected-error {{argument to '__builtin_arm_mcrr' must be a constant integer}} - __builtin_arm_mcrr(15, 0, b, c, a); // expected-error {{argument to '__builtin_arm_mcrr' must be a constant integer}} + __builtin_arm_mcrr(15, 0, b, 0); + __builtin_arm_mcrr( a, 0, b, 0); // expected-error {{argument to '__builtin_arm_mcrr' must be a constant integer}} + __builtin_arm_mcrr(15, a, b, 0); // expected-error {{argument to '__builtin_arm_mcrr' must be a constant integer}} + __builtin_arm_mcrr(15, 0, b, a); // expected-error {{argument to '__builtin_arm_mcrr' must be a constant integer}} + + __builtin_arm_mcrr2(15, 0, b, 0); + __builtin_arm_mcrr2( a, 0, b, 0); // expected-error {{argument to '__builtin_arm_mcrr2' must be a constant integer}} + __builtin_arm_mcrr2(15, a, b, 0); // expected-error {{argument to '__builtin_arm_mcrr2' must be a constant integer}} + __builtin_arm_mcrr2(15, 0, b, a); // expected-error {{argument to '__builtin_arm_mcrr2' must be a constant integer}} + + __builtin_arm_mrrc(15, 0, 0); + __builtin_arm_mrrc( a, 0, 0); // expected-error {{argument to '__builtin_arm_mrrc' must be a constant integer}} + __builtin_arm_mrrc(15, a, 0); // expected-error {{argument to '__builtin_arm_mrrc' must be a constant integer}} + __builtin_arm_mrrc(15, 0, a); // expected-error {{argument to '__builtin_arm_mrrc' must be a constant integer}} - __builtin_arm_mcrr2( a, 0, b, c, 0); // expected-error {{argument to '__builtin_arm_mcrr2' must be a constant integer}} - __builtin_arm_mcrr2(15, a, b, c, 0); // expected-error {{argument to '__builtin_arm_mcrr2' must be a constant integer}} - __builtin_arm_mcrr2(15, 0, b, c, a); // expected-error {{argument to '__builtin_arm_mcrr2' must be a constant integer}} + __builtin_arm_mrrc2(15, 0, 0); + __builtin_arm_mrrc2( a, 0, 0); // expected-error {{argument to '__builtin_arm_mrrc2' must be a constant integer}} + __builtin_arm_mrrc2(15, a, 0); // expected-error {{argument to '__builtin_arm_mrrc2' must be a constant integer}} + __builtin_arm_mrrc2(15, 0, a); // expected-error {{argument to '__builtin_arm_mrrc2' must be a constant integer}} } diff --git a/test/Sema/callingconv-cast.c b/test/Sema/callingconv-cast.c new file mode 100644 index 000000000000..12c0dcbc256a --- /dev/null +++ b/test/Sema/callingconv-cast.c @@ -0,0 +1,63 @@ +// RUN: %clang_cc1 -fms-extensions -triple i686-pc-windows-msvc -Wcast-calling-convention -DMSVC -Wno-pointer-bool-conversion -verify -x c %s +// RUN: %clang_cc1 -fms-extensions -triple i686-pc-windows-msvc -Wcast-calling-convention -DMSVC -Wno-pointer-bool-conversion -verify -x c++ %s +// RUN: %clang_cc1 -fms-extensions -triple i686-pc-windows-msvc -Wcast-calling-convention -DMSVC -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s --check-prefix=MSFIXIT +// RUN: %clang_cc1 -triple i686-pc-windows-gnu -Wcast-calling-convention -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s --check-prefix=GNUFIXIT + +// expected-note@+1 {{consider defining 'mismatched_before_winapi' with the 'stdcall' calling convention}} +void mismatched_before_winapi(int x) {} + +#ifdef MSVC +#define WINAPI __stdcall +#else +#define WINAPI __attribute__((stdcall)) +#endif + +// expected-note@+1 3 {{consider defining 'mismatched' with the 'stdcall' calling convention}} +void mismatched(int x) {} + +typedef void (WINAPI *callback_t)(int); +void take_callback(callback_t callback); + +void WINAPI mismatched_stdcall(int x) {} + +void take_opaque_fn(void (*callback)(int)); + +int main() { + // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}} + take_callback((callback_t)mismatched); + + // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}} + callback_t callback = (callback_t)mismatched; // warns + (void)callback; + + // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}} + callback = (callback_t)&mismatched; // warns + + // No warning, just to show we don't drill through other kinds of unary operators. + callback = (callback_t)!mismatched; + + // expected-warning@+1 {{cast between incompatible calling conventions 'cdecl' and 'stdcall'}} + callback = (callback_t)&mismatched_before_winapi; // warns + + // Probably a bug, but we don't warn. + void (*callback2)(int) = mismatched; + take_callback((callback_t)callback2); + + // Another way to suppress the warning. + take_callback((callback_t)(void*)mismatched); + + // Don't warn, because we're casting from stdcall to cdecl. Usually that means + // the programmer is rinsing the function pointer through some kind of opaque + // API. + take_opaque_fn((void (*)(int))mismatched_stdcall); +} + +// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{16:6-16:6}:"WINAPI " +// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{16:6-16:6}:"WINAPI " +// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{16:6-16:6}:"WINAPI " +// MSFIXIT: fix-it:"{{.*}}callingconv-cast.c":{7:6-7:6}:"__stdcall " + +// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{16:6-16:6}:"WINAPI " +// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{16:6-16:6}:"WINAPI " +// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{16:6-16:6}:"WINAPI " +// GNUFIXIT: fix-it:"{{.*}}callingconv-cast.c":{7:6-7:6}:"__attribute__((stdcall)) " diff --git a/test/Sema/constant-conversion.c b/test/Sema/constant-conversion.c index 137633396712..b717f9325336 100644 --- a/test/Sema/constant-conversion.c +++ b/test/Sema/constant-conversion.c @@ -80,3 +80,36 @@ void test8() { struct { enum E x : 1; } f; f.x = C; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 2 to 0}} } + +void test9() { + const char max_char = 0x7F; + const short max_short = 0x7FFF; + const int max_int = 0x7FFFFFFF; + + const short max_char_plus_one = (short)max_char + 1; + const int max_short_plus_one = (int)max_short + 1; + const long max_int_plus_one = (long)max_int + 1; + + char new_char = max_char_plus_one; // expected-warning {{implicit conversion from 'const short' to 'char' changes value from 128 to -128}} + short new_short = max_short_plus_one; // expected-warning {{implicit conversion from 'const int' to 'short' changes value from 32768 to -32768}} + int new_int = max_int_plus_one; // expected-warning {{implicit conversion from 'const long' to 'int' changes value from 2147483648 to -2147483648}} + + char hex_char = 0x80; + short hex_short = 0x8000; + int hex_int = 0x80000000; + + char oct_char = 0200; + short oct_short = 0100000; + int oct_int = 020000000000; + + char bin_char = 0b10000000; + short bin_short = 0b1000000000000000; + int bin_int = 0b10000000000000000000000000000000; + +#define CHAR_MACRO_HEX 0xff + char macro_char_hex = CHAR_MACRO_HEX; +#define CHAR_MACRO_DEC 255 + char macro_char_dec = CHAR_MACRO_DEC; // expected-warning {{implicit conversion from 'int' to 'char' changes value from 255 to -1}} + + char array_init[] = { 255, 127, 128, 129, 0 }; +} diff --git a/test/Sema/dllexport.c b/test/Sema/dllexport.c index 56c9e74225f2..7991a455b4de 100644 --- a/test/Sema/dllexport.c +++ b/test/Sema/dllexport.c @@ -4,12 +4,18 @@ // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c99 %s // Invalid usage. -__declspec(dllexport) typedef int typedef1; // expected-warning{{'dllexport' attribute only applies to variables and functions}} -typedef __declspec(dllexport) int typedef2; // expected-warning{{'dllexport' attribute only applies to variables and functions}} -typedef int __declspec(dllexport) typedef3; // expected-warning{{'dllexport' attribute only applies to variables and functions}} -typedef __declspec(dllexport) void (*FunTy)(); // expected-warning{{'dllexport' attribute only applies to variables and functions}} -enum __declspec(dllexport) Enum { EnumVal }; // expected-warning{{'dllexport' attribute only applies to variables and functions}} -struct __declspec(dllexport) Record {}; // expected-warning{{'dllexport' attribute only applies to variables and functions}} +__declspec(dllexport) typedef int typedef1; +// expected-warning@-1{{'dllexport' attribute only applies to variables and functions}} +typedef __declspec(dllexport) int typedef2; +// expected-warning@-1{{'dllexport' attribute only applies to variables and functions}} +typedef int __declspec(dllexport) typedef3; +// expected-warning@-1{{'dllexport' attribute only applies to variables and functions}} +typedef __declspec(dllexport) void (*FunTy)(); +// expected-warning@-1{{'dllexport' attribute only applies to variables and functions}} +enum __declspec(dllexport) Enum { EnumVal }; +// expected-warning@-1{{'dllexport' attribute only applies to variables and functions}} +struct __declspec(dllexport) Record {}; +// expected-warning@-1{{'dllexport' attribute only applies to variables and functions}} diff --git a/test/Sema/dllimport.c b/test/Sema/dllimport.c index f863499cf840..0728cf14a8e3 100644 --- a/test/Sema/dllimport.c +++ b/test/Sema/dllimport.c @@ -4,12 +4,18 @@ // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c99 -DGNU %s // Invalid usage. -__declspec(dllimport) typedef int typedef1; // expected-warning{{'dllimport' attribute only applies to variables and functions}} -typedef __declspec(dllimport) int typedef2; // expected-warning{{'dllimport' attribute only applies to variables and functions}} -typedef int __declspec(dllimport) typedef3; // expected-warning{{'dllimport' attribute only applies to variables and functions}} -typedef __declspec(dllimport) void (*FunTy)(); // expected-warning{{'dllimport' attribute only applies to variables and functions}} -enum __declspec(dllimport) Enum { EnumVal }; // expected-warning{{'dllimport' attribute only applies to variables and functions}} -struct __declspec(dllimport) Record {}; // expected-warning{{'dllimport' attribute only applies to variables and functions}} +__declspec(dllimport) typedef int typedef1; +// expected-warning@-1{{'dllimport' attribute only applies to variables and functions}} +typedef __declspec(dllimport) int typedef2; +// expected-warning@-1{{'dllimport' attribute only applies to variables and functions}} +typedef int __declspec(dllimport) typedef3; +// expected-warning@-1{{'dllimport' attribute only applies to variables and functions}} +typedef __declspec(dllimport) void (*FunTy)(); +// expected-warning@-1{{'dllimport' attribute only applies to variables and functions}} +enum __declspec(dllimport) Enum { EnumVal }; +// expected-warning@-1{{'dllimport' attribute only applies to variables and functions}} +struct __declspec(dllimport) Record {}; +// expected-warning@-1{{'dllimport' attribute only applies to variables and functions}} @@ -34,17 +40,49 @@ __declspec(dllimport) int GlobalInit1 = 1; // expected-error{{definition of dlli int __declspec(dllimport) GlobalInit2 = 1; // expected-error{{definition of dllimport data}} // Declare, then reject definition. -__declspec(dllimport) extern int ExternGlobalDeclInit; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} -int ExternGlobalDeclInit = 1; // expected-warning{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +#ifdef GNU +// expected-note@+2{{previous attribute is here}} +#endif +__declspec(dllimport) extern int ExternGlobalDeclInit; // expected-note{{previous declaration is here}} +#ifdef MS +// expected-warning@+4{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}} +#else +// expected-warning@+2{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +#endif +int ExternGlobalDeclInit = 1; -__declspec(dllimport) int GlobalDeclInit; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} -int GlobalDeclInit = 1; // expected-warning{{'GlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +#ifdef GNU +// expected-note@+2{{previous attribute is here}} +#endif +__declspec(dllimport) int GlobalDeclInit; // expected-note{{previous declaration is here}} +#ifdef MS +// expected-warning@+4{{'GlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}} +#else +// expected-warning@+2{{'GlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +#endif +int GlobalDeclInit = 1; -int *__attribute__((dllimport)) GlobalDeclChunkAttrInit; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} -int *GlobalDeclChunkAttrInit = 0; // expected-warning{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +#ifdef GNU +// expected-note@+2{{previous attribute is here}} +#endif +int *__attribute__((dllimport)) GlobalDeclChunkAttrInit; // expected-note{{previous declaration is here}} +#ifdef MS +// expected-warning@+4{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}} +#else +// expected-warning@+2{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +#endif +int *GlobalDeclChunkAttrInit = 0; -int GlobalDeclAttrInit __attribute__((dllimport)); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} -int GlobalDeclAttrInit = 1; // expected-warning{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +#ifdef GNU +// expected-note@+2{{previous attribute is here}} +#endif +int GlobalDeclAttrInit __attribute__((dllimport)); // expected-note{{previous declaration is here}} +#ifdef MS +// expected-warning@+4{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}} +#else +// expected-warning@+2{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +#endif +int GlobalDeclAttrInit = 1; // Redeclarations __declspec(dllimport) extern int GlobalRedecl1; @@ -59,8 +97,7 @@ int *__attribute__((dllimport)) GlobalRedecl2b; int GlobalRedecl2c __attribute__((dllimport)); int GlobalRedecl2c __attribute__((dllimport)); -// NB: MSVC issues a warning and makes GlobalRedecl3 dllexport. We follow GCC -// and drop the dllimport with a warning. +// We follow GCC and drop the dllimport with a warning. __declspec(dllimport) extern int GlobalRedecl3; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} extern int GlobalRedecl3; // expected-warning{{'GlobalRedecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} @@ -133,13 +170,20 @@ inline void __attribute__((dllimport)) inlineFunc2() {} __declspec(dllimport) void redecl1(); __declspec(dllimport) void redecl1(); -// NB: MSVC issues a warning and makes redecl2/redecl3 dllexport. We follow GCC -// and drop the dllimport with a warning. __declspec(dllimport) void redecl2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} void redecl2(); // expected-warning{{'redecl2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} -__declspec(dllimport) void redecl3(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}} - void redecl3() {} // expected-warning{{'redecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +#ifdef GNU + // expected-note@+2{{previous attribute is here}} +#endif + __declspec(dllimport) void redecl3(); // expected-note{{previous declaration is here}} + // NB: Both MSVC and Clang issue a warning and make redecl3 dllexport. +#ifdef MS + // expected-warning@+4{{'redecl3' redeclared without 'dllimport' attribute: 'dllexport' attribute added}} +#else + // expected-warning@+2{{'redecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} +#endif + void redecl3() {} void redecl4(); // expected-note{{previous declaration is here}} void useRedecl4() { redecl4(); } diff --git a/test/Sema/enable_if-ext.c b/test/Sema/enable_if-ext.c new file mode 100644 index 000000000000..1e605d49b60f --- /dev/null +++ b/test/Sema/enable_if-ext.c @@ -0,0 +1,50 @@ +// RUN: %clang_cc1 -fsyntax-only %s -include %s -verify +// RUN: %clang_cc1 -Wpedantic -fsyntax-only %s -include %s -verify -DWARN_PEDANTIC + +#ifndef enable_if_ext_included +#define enable_if_ext_included + +#if !defined(WARN_PEDANTIC) +// expected-no-diagnostics +#endif + +__attribute__ (( enable_if(1, "") )) +#if defined(WARN_PEDANTIC) +// expected-warning@-2 {{'enable_if' is a clang extension}} +#endif +void f() { } + +__attribute__ (( __enable_if__(1, "") )) +#if defined(WARN_PEDANTIC) +// expected-warning@-2 {{'enable_if' is a clang extension}} +#endif +void g() { } + +__attribute__ (( enable_if(0, "") )) +#if defined(WARN_PEDANTIC) +// expected-warning@-2 {{'enable_if' is a clang extension}} +#endif +void h() { } + +__attribute__ (( __enable_if__(0, "") )) +#if defined(WARN_PEDANTIC) +// expected-warning@-2 {{'enable_if' is a clang extension}} +#endif +void i() { } + +#pragma clang system_header + +__attribute__ (( enable_if(1, "") )) +void j() { } + +__attribute__ (( __enable_if__(1, "") )) +void k() { } + +__attribute__ (( enable_if(0, "") )) +void l() { } + +__attribute__ (( __enable_if__(0, "") )) +void m() { } + +#endif + diff --git a/test/Sema/enable_if.c b/test/Sema/enable_if.c index 0cd9c48f42b5..1cc14659021d 100644 --- a/test/Sema/enable_if.c +++ b/test/Sema/enable_if.c @@ -72,8 +72,8 @@ int isdigit(int c) __attribute__((overloadable)) // expected-note{{candidate fu __attribute__((unavailable("'c' must have the value of an unsigned char or EOF"))); void test3(int c) { - isdigit(c); - isdigit(10); + isdigit(c); // expected-warning{{ignoring return value of function declared with pure attribute}} + isdigit(10); // expected-warning{{ignoring return value of function declared with pure attribute}} #ifndef CODEGEN isdigit(-10); // expected-error{{call to unavailable function 'isdigit': 'c' must have the value of an unsigned char or EOF}} #endif @@ -142,4 +142,11 @@ void test8() { void (*p1)(int) = &f4; // expected-error{{cannot take address of function 'f4' becuase it has one or more non-tautological enable_if conditions}} void (*p2)(int) = f4; // expected-error{{cannot take address of function 'f4' becuase it has one or more non-tautological enable_if conditions}} } + +void regular_enable_if(int a) __attribute__((enable_if(a, ""))); // expected-note 3{{declared here}} +void PR27122_ext() { + regular_enable_if(0, 2); // expected-error{{too many arguments}} + regular_enable_if(1, 2); // expected-error{{too many arguments}} + regular_enable_if(); // expected-error{{too few arguments}} +} #endif diff --git a/test/Sema/ext_vector_casts.c b/test/Sema/ext_vector_casts.c index 924013aeb29d..6aaedbe7fd15 100644 --- a/test/Sema/ext_vector_casts.c +++ b/test/Sema/ext_vector_casts.c @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -fsyntax-only -verify -fno-lax-vector-conversions -Wconversion %s +typedef __attribute__((ext_vector_type(8))) _Bool BoolVector; // expected-error {{invalid vector element type '_Bool'}} + typedef __attribute__(( ext_vector_type(2) )) float float2; typedef __attribute__(( ext_vector_type(3) )) float float3; typedef __attribute__(( ext_vector_type(4) )) int int4; diff --git a/test/Sema/float128-ld-incompatibility.cpp b/test/Sema/float128-ld-incompatibility.cpp new file mode 100644 index 000000000000..d993ed7b081c --- /dev/null +++ b/test/Sema/float128-ld-incompatibility.cpp @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 \ +// RUN: -triple powerpc64le-unknown-linux-gnu -target-cpu pwr8 \ +// RUN: -target-feature +float128 %s + +__float128 qf(); +long double ldf(); + +// FIXME: once operations between long double and __float128 are implemented for +// targets where the types are different, these next two will change +long double ld{qf()}; // expected-error {{cannot initialize a variable of type 'long double' with an rvalue of type '__float128'}} +__float128 q{ldf()}; // expected-error {{cannot initialize a variable of type '__float128' with an rvalue of type 'long double'}} + +auto test1(__float128 q, long double ld) -> decltype(q + ld) { // expected-error {{invalid operands to binary expression ('__float128' and 'long double')}} + return q + ld; // expected-error {{invalid operands to binary expression ('__float128' and 'long double')}} +} + +auto test2(long double a, __float128 b) -> decltype(a + b) { // expected-error {{invalid operands to binary expression ('long double' and '__float128')}} + return a + b; // expected-error {{invalid operands to binary expression ('long double' and '__float128')}} +} + +void test3(bool b) { + long double ld; + __float128 q; + + ld + q; // expected-error {{invalid operands to binary expression ('long double' and '__float128')}} + q + ld; // expected-error {{invalid operands to binary expression ('__float128' and 'long double')}} + ld - q; // expected-error {{invalid operands to binary expression ('long double' and '__float128')}} + q - ld; // expected-error {{invalid operands to binary expression ('__float128' and 'long double')}} + ld * q; // expected-error {{invalid operands to binary expression ('long double' and '__float128')}} + q * ld; // expected-error {{invalid operands to binary expression ('__float128' and 'long double')}} + ld / q; // expected-error {{invalid operands to binary expression ('long double' and '__float128')}} + q / ld; // expected-error {{invalid operands to binary expression ('__float128' and 'long double')}} + ld = q; // expected-error {{assigning to 'long double' from incompatible type '__float128'}} + q = ld; // expected-error {{assigning to '__float128' from incompatible type 'long double'}} + q + b ? q : ld; // expected-error {{incompatible operand types ('__float128' and 'long double')}} +} diff --git a/test/Sema/format-strings-freebsd.c b/test/Sema/format-strings-freebsd.c index cdf273ae1093..965d7c287be6 100644 --- a/test/Sema/format-strings-freebsd.c +++ b/test/Sema/format-strings-freebsd.c @@ -1,10 +1,11 @@ // RUN: %clang_cc1 -fsyntax-only -verify -triple i386-unknown-freebsd %s // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd %s +// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-scei-ps4 %s // Test FreeBSD kernel printf extensions. int freebsd_kernel_printf(const char *, ...) __attribute__((__format__(__freebsd_kprintf__, 1, 2))); -void check_freebsd_kernel_extensions(int i, long l, char *s) +void check_freebsd_kernel_extensions(int i, long l, char *s, short h) { // %b expects an int and a char * freebsd_kernel_printf("reg=%b\n", i, "\10\2BITTWO\1BITONE\n"); // no-warning @@ -32,6 +33,12 @@ void check_freebsd_kernel_extensions(int i, long l, char *s) freebsd_kernel_printf("%lr", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}} freebsd_kernel_printf("%lr", l); // no-warning + // h modifier expects a short + freebsd_kernel_printf("%hr", i); // expected-warning{{format specifies type 'short' but the argument has type 'int'}} + freebsd_kernel_printf("%hr", h); // no-warning + freebsd_kernel_printf("%hy", i); // expected-warning{{format specifies type 'short' but the argument has type 'int'}} + freebsd_kernel_printf("%hy", h); // no-warning + // %y expects an int freebsd_kernel_printf("%y", i); // no-warning freebsd_kernel_printf("%y", l); // expected-warning{{format specifies type 'int' but the argument has type 'long'}} diff --git a/test/Sema/format-strings-scanf.c b/test/Sema/format-strings-scanf.c index d3a03adf6195..7a92842b2454 100644 --- a/test/Sema/format-strings-scanf.c +++ b/test/Sema/format-strings-scanf.c @@ -18,7 +18,7 @@ int vfscanf(FILE * restrict, const char * restrict, va_list); int vsscanf(const char * restrict, const char * restrict, va_list); void test(const char *s, int *i) { - scanf(s, i); // expected-warning{{ormat string is not a string literal}} + scanf(s, i); // expected-warning{{format string is not a string literal}} scanf("%0d", i); // expected-warning{{zero field width in scanf format string is unused}} scanf("%00d", i); // expected-warning{{zero field width in scanf format string is unused}} scanf("%d%[asdfasdfd", i, s); // expected-warning{{no closing ']' for '%[' in scanf format string}} @@ -171,3 +171,15 @@ void test_qualifiers(const int *cip, volatile int* vip, scanf("%d", (ip_t)0); // No warning. scanf("%d", (cip_t)0); // expected-warning{{format specifies type 'int *' but the argument has type 'cip_t' (aka 'const int *')}} } + +void check_conditional_literal(char *s, int *i) { + scanf(0 ? "%s" : "%d", i); // no warning + scanf(1 ? "%s" : "%d", i); // expected-warning{{format specifies type 'char *'}} + scanf(0 ? "%d %d" : "%d", i); // no warning + scanf(1 ? "%d %d" : "%d", i); // expected-warning{{more '%' conversions than data arguments}} + scanf(0 ? "%d %d" : "%d", i, s); // expected-warning{{data argument not used}} + scanf(1 ? "%d %s" : "%d", i, s); // no warning + scanf(i ? "%d %s" : "%d", i, s); // no warning + scanf(i ? "%d" : "%d", i, s); // expected-warning{{data argument not used}} + scanf(i ? "%s" : "%d", s); // expected-warning{{format specifies type 'int *'}} +} diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index 0d827e400d7e..5559710c6035 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -29,15 +29,22 @@ void check_string_literal( FILE* fp, const char* s, char *buf, ... ) { va_start(ap,buf); printf(s); // expected-warning {{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} vprintf(s,ap); // expected-warning {{format string is not a string literal}} fprintf(fp,s); // expected-warning {{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} vfprintf(fp,s,ap); // expected-warning {{format string is not a string literal}} asprintf(&b,s); // expected-warning {{format string is not a string lit}} + // expected-note@-1{{treat the string as an argument to avoid this}} vasprintf(&b,s,ap); // expected-warning {{format string is not a string literal}} sprintf(buf,s); // expected-warning {{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} snprintf(buf,2,s); // expected-warning {{format string is not a string lit}} + // expected-note@-1{{treat the string as an argument to avoid this}} __builtin___sprintf_chk(buf,0,-1,s); // expected-warning {{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} __builtin___snprintf_chk(buf,2,0,-1,s); // expected-warning {{format string is not a string lit}} + // expected-note@-1{{treat the string as an argument to avoid this}} vsprintf(buf,s,ap); // expected-warning {{format string is not a string lit}} vsnprintf(buf,2,s,ap); // expected-warning {{format string is not a string lit}} vsnprintf(buf,2,global_fmt,ap); // expected-warning {{format string is not a string literal}} @@ -46,6 +53,9 @@ void check_string_literal( FILE* fp, const char* s, char *buf, ... ) { vscanf(s, ap); // expected-warning {{format string is not a string literal}} + const char *const fmt = "%d"; // FIXME -- defined here + printf(fmt, 1, 2); // expected-warning{{data argument not used}} + // rdar://6079877 printf("abc" "%*d", 1, 1); // no-warning @@ -69,13 +79,18 @@ void check_string_literal2( FILE* fp, const char* s, char *buf, ... ) { va_start(ap,buf); printf(s); // expected-warning {{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} vprintf(s,ap); // no-warning fprintf(fp,s); // expected-warning {{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} vfprintf(fp,s,ap); // no-warning asprintf(&b,s); // expected-warning {{format string is not a string lit}} + // expected-note@-1{{treat the string as an argument to avoid this}} vasprintf(&b,s,ap); // no-warning sprintf(buf,s); // expected-warning {{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} snprintf(buf,2,s); // expected-warning {{format string is not a string lit}} + // expected-note@-1{{treat the string as an argument to avoid this}} __builtin___vsnprintf_chk(buf,2,0,-1,s,ap); // no-warning vscanf(s, ap); // expected-warning {{format string is not a string literal}} @@ -85,7 +100,22 @@ void check_conditional_literal(const char* s, int i) { printf(i == 1 ? "yes" : "no"); // no-warning printf(i == 0 ? (i == 1 ? "yes" : "no") : "dont know"); // no-warning printf(i == 0 ? (i == 1 ? s : "no") : "dont know"); // expected-warning{{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} printf("yes" ?: "no %d", 1); // expected-warning{{data argument not used by format string}} + printf(0 ? "yes %s" : "no %d", 1); // no-warning + printf(0 ? "yes %d" : "no %s", 1); // expected-warning{{format specifies type 'char *'}} + + printf(0 ? "yes" : "no %d", 1); // no-warning + printf(0 ? "yes %d" : "no", 1); // expected-warning{{data argument not used by format string}} + printf(1 ? "yes" : "no %d", 1); // expected-warning{{data argument not used by format string}} + printf(1 ? "yes %d" : "no", 1); // no-warning + printf(i ? "yes" : "no %d", 1); // no-warning + printf(i ? "yes %s" : "no %d", 1); // expected-warning{{format specifies type 'char *'}} + printf(i ? "yes" : "no %d", 1, 2); // expected-warning{{data argument not used by format string}} + + printf(i ? "%*s" : "-", i, s); // no-warning + printf(i ? "yes" : 0 ? "no %*d" : "dont know %d", 1, 2); // expected-warning{{data argument not used by format string}} + printf(i ? "%i\n" : "%i %s %s\n", i, s); // expected-warning{{more '%' conversions than data arguments}} } void check_writeback_specifier() @@ -185,8 +215,11 @@ void test_constant_bindings(void) { printf(s1); // no-warning printf(s2); // no-warning printf(s3); // expected-warning{{not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} printf(s4); // expected-warning{{not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} printf(s5); // expected-warning{{not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} } @@ -197,6 +230,7 @@ void test_constant_bindings(void) { void test9(char *P) { int x; printf(P); // expected-warning {{format string is not a string literal (potentially insecure)}} + // expected-note@-1{{treat the string as an argument to avoid this}} printf(P, 42); } @@ -519,7 +553,7 @@ void pr9751() { // Make sure that the "format string is defined here" note is not emitted // when the original string is within the argument expression. - printf(1 ? "yes %d" : "no %d"); // expected-warning 2{{more '%' conversions than data arguments}} + printf(1 ? "yes %d" : "no %d"); // expected-warning{{more '%' conversions than data arguments}} const char kFormat17[] = "%hu"; // expected-note{{format string is defined here}}} printf(kFormat17, (int[]){0}); // expected-warning{{format specifies type 'unsigned short' but the argument}} @@ -615,5 +649,6 @@ extern void test_format_security_extra_args(const char*, int, ...) __attribute__((__format__(__printf__, 1, 3))); void test_format_security_pos(char* string) { test_format_security_extra_args(string, 5); // expected-warning {{format string is not a string literal (potentially insecure)}} + // expected-note@-1{{treat the string as an argument to avoid this}} } #pragma GCC diagnostic warning "-Wformat-nonliteral" diff --git a/test/Sema/integer-overflow.c b/test/Sema/integer-overflow.c index db5c1f4c7118..e74bc119798b 100644 --- a/test/Sema/integer-overflow.c +++ b/test/Sema/integer-overflow.c @@ -1,6 +1,11 @@ -// RUN: %clang_cc1 %s -verify -fsyntax-only +// RUN: %clang_cc1 %s -verify -fsyntax-only -triple x86_64-pc-linux-gnu typedef unsigned long long uint64_t; -typedef unsigned long long uint32_t; +typedef unsigned int uint32_t; + +// Check integer sizes. +int array64[sizeof(uint64_t) == 8 ? 1 : -1]; +int array32[sizeof(uint32_t) == 4 ? 1 : -1]; +int arrayint[sizeof(int) < sizeof(uint64_t) ? 1 : -1]; uint64_t f0(uint64_t); uint64_t f1(uint64_t, uint32_t); @@ -153,3 +158,23 @@ struct s { .y = 5, .x = 4 * 1024 * 1024 * 1024 // expected-warning {{overflow in expression; result is 0 with type 'int'}} }; + +struct s2 { + unsigned a0; + + struct s3 { + unsigned a2; + + struct s4 { + unsigned a4; + } a3; + } a1; +} s2 = { + .a0 = 4 * 1024 * 1024 * 1024, // expected-warning {{overflow in expression; result is 0 with type 'int'}} + { + .a2 = 4 * 1024 * 1024 * 1024, // expected-warning {{overflow in expression; result is 0 with type 'int'}} + { + .a4 = 4 * 1024 * 1024 * 1024 // expected-warning {{overflow in expression; result is 0 with type 'int'}} + } + } +}; diff --git a/test/Sema/invalid-assignment-constant-address-space.c b/test/Sema/invalid-assignment-constant-address-space.c index de2af64d00ec..77d6b331c201 100644 --- a/test/Sema/invalid-assignment-constant-address-space.c +++ b/test/Sema/invalid-assignment-constant-address-space.c @@ -1,6 +1,6 @@ // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -#define OPENCL_CONSTANT 16776962 +#define OPENCL_CONSTANT 8388354 int __attribute__((address_space(OPENCL_CONSTANT))) c[3] = {0}; void foo() { diff --git a/test/Sema/libbuiltins-ctype-powerpc64.c b/test/Sema/libbuiltins-ctype-powerpc64.c new file mode 100644 index 000000000000..bfd79acb0ab0 --- /dev/null +++ b/test/Sema/libbuiltins-ctype-powerpc64.c @@ -0,0 +1,65 @@ +// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu -emit-llvm < %s | FileCheck %s + +int isalnum(int); +int isalpha(int); +int isblank(int); +int iscntrl(int); +int isdigit(int); +int isgraph(int); +int islower(int); +int isprint(int); +int ispunct(int); +int isspace(int); +int isupper(int); +int isxdigit(int); +int tolower(int); +int toupper(int); + +void test(int x) { + // CHECK: call signext i32 @isalnum(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isalnum(x); + // CHECK: call signext i32 @isalpha(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isalpha(x); + // CHECK: call signext i32 @isblank(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isblank(x); + // CHECK: call signext i32 @iscntrl(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)iscntrl(x); + // CHECK: call signext i32 @isdigit(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isdigit(x); + // CHECK: call signext i32 @isgraph(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isgraph(x); + // CHECK: call signext i32 @islower(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)islower(x); + // CHECK: call signext i32 @isprint(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isprint(x); + // CHECK: call signext i32 @ispunct(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)ispunct(x); + // CHECK: call signext i32 @isspace(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isspace(x); + // CHECK: call signext i32 @isupper(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isupper(x); + // CHECK: call signext i32 @isxdigit(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isxdigit(x); + // CHECK: call signext i32 @tolower(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)tolower(x); + // CHECK: call signext i32 @toupper(i32 signext {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)toupper(x); +} + +// CHECK: declare signext i32 @isalnum(i32 signext) [[NUW_RO:#[0-9]+]] +// CHECK: declare signext i32 @isalpha(i32 signext) [[NUW_RO:#[0-9]+]] +// CHECK: declare signext i32 @isblank(i32 signext) [[NUW_RO:#[0-9]+]] +// CHECK: declare signext i32 @iscntrl(i32 signext) [[NUW_RO:#[0-9]+]] +// CHECK: declare signext i32 @isdigit(i32 signext) [[NUW_RO:#[0-9]+]] +// CHECK: declare signext i32 @isgraph(i32 signext) [[NUW_RO:#[0-9]+]] +// CHECK: declare signext i32 @islower(i32 signext) [[NUW_RO:#[0-9]+]] +// CHECK: declare signext i32 @isprint(i32 signext) [[NUW_RO:#[0-9]+]] +// CHECK: declare signext i32 @ispunct(i32 signext) [[NUW_RO:#[0-9]+]] +// CHECK: declare signext i32 @isspace(i32 signext) [[NUW_RO:#[0-9]+]] +// CHECK: declare signext i32 @isupper(i32 signext) [[NUW_RO:#[0-9]+]] +// CHECK: declare signext i32 @isxdigit(i32 signext) [[NUW_RO:#[0-9]+]] +// CHECK: declare signext i32 @tolower(i32 signext) [[NUW_RO:#[0-9]+]] +// CHECK: declare signext i32 @toupper(i32 signext) [[NUW_RO:#[0-9]+]] + +// CHECK: attributes [[NUW_RO]] = { nounwind readonly{{.*}} } +// CHECK: attributes [[NUW_RO_CALL]] = { nounwind readonly } diff --git a/test/Sema/libbuiltins-ctype-x86_64.c b/test/Sema/libbuiltins-ctype-x86_64.c new file mode 100644 index 000000000000..4934e6f16752 --- /dev/null +++ b/test/Sema/libbuiltins-ctype-x86_64.c @@ -0,0 +1,65 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | FileCheck %s + +int isalnum(int); +int isalpha(int); +int isblank(int); +int iscntrl(int); +int isdigit(int); +int isgraph(int); +int islower(int); +int isprint(int); +int ispunct(int); +int isspace(int); +int isupper(int); +int isxdigit(int); +int tolower(int); +int toupper(int); + +void test(int x) { + // CHECK: call i32 @isalnum(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isalnum(x); + // CHECK: call i32 @isalpha(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isalpha(x); + // CHECK: call i32 @isblank(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isblank(x); + // CHECK: call i32 @iscntrl(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)iscntrl(x); + // CHECK: call i32 @isdigit(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isdigit(x); + // CHECK: call i32 @isgraph(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isgraph(x); + // CHECK: call i32 @islower(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)islower(x); + // CHECK: call i32 @isprint(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isprint(x); + // CHECK: call i32 @ispunct(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)ispunct(x); + // CHECK: call i32 @isspace(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isspace(x); + // CHECK: call i32 @isupper(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isupper(x); + // CHECK: call i32 @isxdigit(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)isxdigit(x); + // CHECK: call i32 @tolower(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)tolower(x); + // CHECK: call i32 @toupper(i32 {{%[0-9]+}}) [[NUW_RO_CALL:#[0-9]+]] + (void)toupper(x); +} + +// CHECK: declare i32 @isalnum(i32) [[NUW_RO:#[0-9]+]] +// CHECK: declare i32 @isalpha(i32) [[NUW_RO:#[0-9]+]] +// CHECK: declare i32 @isblank(i32) [[NUW_RO:#[0-9]+]] +// CHECK: declare i32 @iscntrl(i32) [[NUW_RO:#[0-9]+]] +// CHECK: declare i32 @isdigit(i32) [[NUW_RO:#[0-9]+]] +// CHECK: declare i32 @isgraph(i32) [[NUW_RO:#[0-9]+]] +// CHECK: declare i32 @islower(i32) [[NUW_RO:#[0-9]+]] +// CHECK: declare i32 @isprint(i32) [[NUW_RO:#[0-9]+]] +// CHECK: declare i32 @ispunct(i32) [[NUW_RO:#[0-9]+]] +// CHECK: declare i32 @isspace(i32) [[NUW_RO:#[0-9]+]] +// CHECK: declare i32 @isupper(i32) [[NUW_RO:#[0-9]+]] +// CHECK: declare i32 @isxdigit(i32) [[NUW_RO:#[0-9]+]] +// CHECK: declare i32 @tolower(i32) [[NUW_RO:#[0-9]+]] +// CHECK: declare i32 @toupper(i32) [[NUW_RO:#[0-9]+]] + +// CHECK: attributes [[NUW_RO]] = { nounwind readonly{{.*}} } +// CHECK: attributes [[NUW_RO_CALL]] = { nounwind readonly } diff --git a/test/Sema/nonnull.c b/test/Sema/nonnull.c index 9503e7c32a86..e98a8194dbeb 100644 --- a/test/Sema/nonnull.c +++ b/test/Sema/nonnull.c @@ -86,7 +86,7 @@ void redecl_test(void *p) { // rdar://18712242 #define NULL (void*)0 -__attribute__((__nonnull__)) +__attribute__((__nonnull__)) // expected-note 2{{declared 'nonnull' here}} int evil_nonnull_func(int* pointer, void * pv) { if (pointer == NULL) { // expected-warning {{comparison of nonnull parameter 'pointer' equal to a null pointer is 'false' on first encounter}} @@ -105,7 +105,7 @@ int evil_nonnull_func(int* pointer, void * pv) } void set_param_to_null(int**); -int another_evil_nonnull_func(int* pointer, char ch, void * pv) __attribute__((nonnull(1, 3))); +int another_evil_nonnull_func(int* pointer, char ch, void * pv) __attribute__((nonnull(1, 3))); // expected-note 2{{declared 'nonnull' here}} int another_evil_nonnull_func(int* pointer, char ch, void * pv) { if (pointer == NULL) { // expected-warning {{comparison of nonnull parameter 'pointer' equal to a null pointer is 'false' on first encounter}} return 0; @@ -127,7 +127,7 @@ extern void FOO(); extern void FEE(); extern void *pv; -__attribute__((__nonnull__)) +__attribute__((__nonnull__)) // expected-note {{declared 'nonnull' here}} void yet_another_evil_nonnull_func(int* pointer) { while (pv) { @@ -141,7 +141,7 @@ void yet_another_evil_nonnull_func(int* pointer) } } -void pr21668_1(__attribute__((nonnull)) const char *p, const char *s) { +void pr21668_1(__attribute__((nonnull)) const char *p, const char *s) { // expected-note {{declared 'nonnull' here}} if (p) // expected-warning {{nonnull parameter 'p' will evaluate to 'true' on first encounter}} ; if (s) // No warning @@ -154,7 +154,7 @@ void pr21668_2(__attribute__((nonnull)) const char *p) { ; } -__attribute__((returns_nonnull)) void *returns_nonnull_whee(); +__attribute__((returns_nonnull)) void *returns_nonnull_whee(); // expected-note 6{{declared 'returns_nonnull' here}} void returns_nonnull_warning_tests() { if (returns_nonnull_whee() == NULL) {} // expected-warning {{comparison of nonnull function call 'returns_nonnull_whee()' equal to a null pointer is 'false' on first encounter}} diff --git a/test/Sema/nullability.c b/test/Sema/nullability.c index bbe5cb4143a0..71e12734d1d2 100644 --- a/test/Sema/nullability.c +++ b/test/Sema/nullability.c @@ -8,7 +8,11 @@ typedef int * int_ptr; // Parse nullability type specifiers. -typedef int * _Nonnull nonnull_int_ptr; // expected-note{{'_Nonnull' specified here}} +// This note requires C11. +#if __STDC_VERSION__ > 199901L +// expected-note@+2{{'_Nonnull' specified here}} +#endif +typedef int * _Nonnull nonnull_int_ptr; typedef int * _Nullable nullable_int_ptr; typedef int * _Null_unspecified null_unspecified_int_ptr; @@ -23,9 +27,14 @@ typedef int * _Null_unspecified _Nonnull conflicting_2; // expected-error{{nulla typedef nonnull_int_ptr _Nonnull redundant_okay_1; // Conflicting nullability specifiers via a typedef are not. +// Some of these errors require C11. +#if __STDC_VERSION__ > 199901L typedef nonnull_int_ptr _Nullable conflicting_2; // expected-error{{nullability specifier '_Nullable' conflicts with existing specifier '_Nonnull'}} +#endif typedef nonnull_int_ptr nonnull_int_ptr_typedef; +#if __STDC_VERSION__ > 199901L typedef nonnull_int_ptr_typedef _Nullable conflicting_2; // expected-error{{nullability specifier '_Nullable' conflicts with existing specifier '_Nonnull'}} +#endif typedef nonnull_int_ptr_typedef nonnull_int_ptr_typedef_typedef; typedef nonnull_int_ptr_typedef_typedef _Null_unspecified conflicting_3; // expected-error{{nullability specifier '_Null_unspecified' conflicts with existing specifier '_Nonnull'}} @@ -69,8 +78,11 @@ typedef _Nonnull int * _Nullable * conflict_int_ptr_ptr_2; // expected-error{{n // Nullability is not part of the canonical type. typedef int * _Nonnull ambiguous_int_ptr; +// Redefining a typedef is a C11 feature. +#if __STDC_VERSION__ > 199901L typedef int * ambiguous_int_ptr; typedef int * _Nullable ambiguous_int_ptr; +#endif // Printing of nullability. float f; diff --git a/test/Sema/overloadable.c b/test/Sema/overloadable.c index 3120649dbc02..5d95a317fa38 100644 --- a/test/Sema/overloadable.c +++ b/test/Sema/overloadable.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s -Wincompatible-pointer-types int var __attribute__((overloadable)); // expected-error{{'overloadable' attribute only applies to functions}} void params(void) __attribute__((overloadable(12))); // expected-error {{'overloadable' attribute takes no arguments}} @@ -99,3 +99,26 @@ void conversions() { unsigned char *c; multi_type(c); } + +// Ensure that we allow C-specific type conversions in C +void fn_type_conversions() { + void foo(void *c) __attribute__((overloadable)); + void foo(char *c) __attribute__((overloadable)); + void (*ptr1)(void *) = &foo; + void (*ptr2)(char *) = &foo; + void (*ambiguous)(int *) = &foo; // expected-error{{initializing 'void (*)(int *)' with an expression of incompatible type '<overloaded function type>'}} expected-note@105{{candidate function}} expected-note@106{{candidate function}} + void *vp_ambiguous = &foo; // expected-error{{initializing 'void *' with an expression of incompatible type '<overloaded function type>'}} expected-note@105{{candidate function}} expected-note@106{{candidate function}} + + void (*specific1)(int *) = (void (*)(void *))&foo; // expected-warning{{incompatible pointer types initializing 'void (*)(int *)' with an expression of type 'void (*)(void *)'}} + void *specific2 = (void (*)(void *))&foo; + + void disabled(void *c) __attribute__((overloadable, enable_if(0, ""))); + void disabled(int *c) __attribute__((overloadable, enable_if(c, ""))); + void disabled(char *c) __attribute__((overloadable, enable_if(1, "The function name lies."))); + // To be clear, these should all point to the last overload of 'disabled' + void (*dptr1)(char *c) = &disabled; + void (*dptr2)(void *c) = &disabled; // expected-warning{{incompatible pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'}} expected-note@115{{candidate function made ineligible by enable_if}} expected-note@116{{candidate function made ineligible by enable_if}} expected-note@117{{candidate function has type mismatch at 1st parameter (expected 'void *' but has 'char *')}} + void (*dptr3)(int *c) = &disabled; // expected-warning{{incompatible pointer types initializing 'void (*)(int *)' with an expression of type '<overloaded function type>'}} expected-note@115{{candidate function made ineligible by enable_if}} expected-note@116{{candidate function made ineligible by enable_if}} expected-note@117{{candidate function has type mismatch at 1st parameter (expected 'int *' but has 'char *')}} + + void *specific_disabled = &disabled; +} diff --git a/test/Sema/pass-object-size.c b/test/Sema/pass-object-size.c index 6f375c0e94d5..ddfbbd5fc4e1 100644 --- a/test/Sema/pass-object-size.c +++ b/test/Sema/pass-object-size.c @@ -38,8 +38,8 @@ void FunctionPtrs() { void (*p)(void *) = NotOverloaded; //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}} void (*p2)(void *) = &NotOverloaded; //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}} - void (*p3)(void *) = IsOverloaded; //expected-error{{initializing 'void (*)(void *)' with an expression of incompatible type '<overloaded function type>'}} expected-note@-6{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@-5{{type mismatch}} - void (*p4)(void *) = &IsOverloaded; //expected-error{{initializing 'void (*)(void *)' with an expression of incompatible type '<overloaded function type>'}} expected-note@-7{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@-6{{type mismatch}} + void (*p3)(void *) = IsOverloaded; //expected-warning{{incompatible pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'}} expected-note@-6{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@-5{{type mismatch}} + void (*p4)(void *) = &IsOverloaded; //expected-warning{{incompatible pointer types initializing 'void (*)(void *)' with an expression of type '<overloaded function type>'}} expected-note@-7{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@-6{{type mismatch}} void (*p5)(char *) = IsOverloaded; void (*p6)(char *) = &IsOverloaded; diff --git a/test/Sema/pr25786.c b/test/Sema/pr25786.c new file mode 100644 index 000000000000..2ce65311a24f --- /dev/null +++ b/test/Sema/pr25786.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -DTEST -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fsyntax-only -verify %s + +#if TEST +void (__attribute__((regparm(3), stdcall)) *pf) (); //expected-warning {{calling convention 'stdcall' ignored for this target}} +void (__attribute__((regparm(2), stdcall)) foo)(int a) { //expected-warning {{calling convention 'stdcall' ignored for this target}} +} +#else +//expected-no-diagnostics +void (__attribute__((regparm(3), stdcall)) *pf) (); +void (__attribute__((regparm(2), stdcall)) foo)(int a) {} +#endif diff --git a/test/Sema/predefined-function.c b/test/Sema/predefined-function.c index 1c40b6e8c2c0..aa7b28535bcd 100644 --- a/test/Sema/predefined-function.c +++ b/test/Sema/predefined-function.c @@ -4,14 +4,13 @@ char *funk(int format); enum Test {A=-1}; char *funk(enum Test x); -int eli(float b); // expected-note {{previous declaration is here}} \ -// expected-note{{passing argument to parameter 'b' here}} +int eli(float b); // expected-note {{previous declaration is here}} int b(int c) {return 1;} int foo(); int foo() { int eli(int (int)); // expected-error {{conflicting types for 'eli'}} - eli(b); // expected-error{{passing 'int (int)' to parameter of incompatible type 'float'}} + eli(b); return 0; } diff --git a/test/Sema/preserve-call-conv.c b/test/Sema/preserve-call-conv.c new file mode 100644 index 000000000000..f258f45ac582 --- /dev/null +++ b/test/Sema/preserve-call-conv.c @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 %s -fsyntax-only -triple x86_64-unknown-unknown -verify +// RUN: %clang_cc1 %s -fsyntax-only -triple arm64-unknown-unknown -verify +typedef void typedef_fun_t(int); + +void __attribute__((preserve_most)) foo(void *ptr) { +} + +void __attribute__((preserve_most(1))) foo1(void *ptr) { // expected-error {{'preserve_most' attribute takes no arguments}} +} + +void (__attribute__((preserve_most)) *pfoo1)(void *) = foo; + +void (__attribute__((cdecl)) *pfoo2)(void *) = foo; // expected-warning {{incompatible pointer types initializing 'void (*)(void *) __attribute__((cdecl))' with an expression of type 'void (void *) __attribute__((preserve_most))'}} +void (*pfoo3)(void *) = foo; // expected-warning {{incompatible pointer types initializing 'void (*)(void *)' with an expression of type 'void (void *) __attribute__((preserve_most))'}} + +typedef_fun_t typedef_fun_foo; // expected-note {{previous declaration is here}} +void __attribute__((preserve_most)) typedef_fun_foo(int x) { } // expected-error {{function declared 'preserve_most' here was previously declared without calling convention}} + +struct type_test_foo {} __attribute__((preserve_most)); // expected-warning {{'preserve_most' attribute only applies to functions and methods}} + +void __attribute__((preserve_all)) boo(void *ptr) { +} + +void __attribute__((preserve_all(1))) boo1(void *ptr) { // expected-error {{'preserve_all' attribute takes no arguments}} +} + +void (__attribute__((preserve_all)) *pboo1)(void *) = boo; + +void (__attribute__((cdecl)) *pboo2)(void *) = boo; // expected-warning {{incompatible pointer types initializing 'void (*)(void *) __attribute__((cdecl))' with an expression of type 'void (void *) __attribute__((preserve_all))'}} +void (*pboo3)(void *) = boo; // expected-warning {{incompatible pointer types initializing 'void (*)(void *)' with an expression of type 'void (void *) __attribute__((preserve_all))'}} + +typedef_fun_t typedef_fun_boo; // expected-note {{previous declaration is here}} +void __attribute__((preserve_all)) typedef_fun_boo(int x) { } // expected-error {{function declared 'preserve_all' here was previously declared without calling convention}} + +struct type_test_boo {} __attribute__((preserve_all)); // expected-warning {{'preserve_all' attribute only applies to functions and methods}} diff --git a/test/Sema/renderscript.rs b/test/Sema/renderscript.rs new file mode 100644 index 000000000000..80be5ae424f8 --- /dev/null +++ b/test/Sema/renderscript.rs @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -x renderscript -D__RENDERSCRIPT__ %s +// RUN: %clang_cc1 -fsyntax-only -verify -x c %s + +#ifndef __RENDERSCRIPT__ +// expected-warning@+2 {{'kernel' attribute ignored}} +#endif +void __attribute__((kernel)) kernel() {} + +#ifndef __RENDERSCRIPT__ +// expected-warning@+4 {{'kernel' attribute ignored}} +#else +// expected-warning@+2 {{'kernel' attribute only applies to functions}} +#endif +int __attribute__((kernel)) global; + +#ifndef __RENDERSCRIPT__ +// expected-error@+2 {{function return value cannot have __fp16 type; did you forget * ?}} +#endif +__fp16 fp16_return(); + +#ifndef __RENDERSCRIPT__ +// expected-error@+2 {{parameters cannot have __fp16 type; did you forget * ?}} +#endif +void fp16_arg(__fp16 p); diff --git a/test/Sema/typo-correction.c b/test/Sema/typo-correction.c index 4ef50570899c..a1107a25ee54 100644 --- a/test/Sema/typo-correction.c +++ b/test/Sema/typo-correction.c @@ -55,3 +55,13 @@ void fn2() { f(THIS_IS_AN_ERROR, // expected-error {{use of undeclared identifier 'THIS_IS_AN_ERROR'}} afunction(afunction_)); // expected-error {{use of undeclared identifier 'afunction_'; did you mean 'afunction'?}} } + +int d = X ? d : L; // expected-error 2 {{use of undeclared identifier}} + +int fn_with_ids() { ID = ID == ID >= ID ; } // expected-error 4 {{use of undeclared identifier}} + +int fn_with_rs(int r) { r = TYPO + r * TYPO; } // expected-error 2 {{use of undeclared identifier}} + +void fn_with_unknown(int a, int b) { + fn_with_unknown(unknown, unknown | unknown); // expected-error 3 {{use of undeclared identifier}} +} diff --git a/test/Sema/unused-expr.c b/test/Sema/unused-expr.c index 09359687d532..58ad8278f201 100644 --- a/test/Sema/unused-expr.c +++ b/test/Sema/unused-expr.c @@ -76,7 +76,7 @@ void t4(int a) { // rdar://7186119 int t5f(void) __attribute__((warn_unused_result)); void t5() { - t5f(); // expected-warning {{ignoring return value of function declared with warn_unused_result}} + t5f(); // expected-warning {{ignoring return value of function declared with 'warn_unused_result' attribute}} } @@ -88,11 +88,11 @@ int t6() { if (fn1() < 0 || fn2(2,1) < 0 || fn3(2) < 0) // no warnings return -1; - fn1(); // expected-warning {{ignoring return value of function declared with warn_unused_result attribute}} + fn1(); // expected-warning {{ignoring return value of function declared with 'warn_unused_result' attribute}} fn2(92, 21); // expected-warning {{ignoring return value of function declared with pure attribute}} fn3(42); // expected-warning {{ignoring return value of function declared with const attribute}} __builtin_abs(0); // expected-warning {{ignoring return value of function declared with const attribute}} - (void)0, fn1(); // expected-warning {{ignoring return value of function declared with warn_unused_result attribute}} + (void)0, fn1(); // expected-warning {{ignoring return value of function declared with 'warn_unused_result' attribute}} return 0; } @@ -101,7 +101,7 @@ int t7 __attribute__ ((warn_unused_result)); // expected-warning {{'warn_unused_ // PR4010 int (*fn4)(void) __attribute__ ((warn_unused_result)); void t8() { - fn4(); // expected-warning {{ignoring return value of function declared with warn_unused_result attribute}} + fn4(); // expected-warning {{ignoring return value of function declared with 'warn_unused_result' attribute}} } void t9() __attribute__((warn_unused_result)); // expected-warning {{attribute 'warn_unused_result' cannot be applied to functions without return value}} diff --git a/test/Sema/varargs-x86-64.c b/test/Sema/varargs-x86-64.c index d50dd6a6fc19..0929c0d91478 100644 --- a/test/Sema/varargs-x86-64.c +++ b/test/Sema/varargs-x86-64.c @@ -21,16 +21,16 @@ void __attribute__((ms_abi)) g1(int a) { void __attribute__((ms_abi)) g2(int a, int b, ...) { __builtin_ms_va_list ap; - __builtin_ms_va_start(ap, 10); // expected-warning {{second parameter of 'va_start' not last named argument}} - __builtin_ms_va_start(ap, a); // expected-warning {{second parameter of 'va_start' not last named argument}} + __builtin_ms_va_start(ap, 10); // expected-warning {{second argument to 'va_start' is not the last named parameter}} + __builtin_ms_va_start(ap, a); // expected-warning {{second argument to 'va_start' is not the last named parameter}} __builtin_ms_va_start(ap, b); } -void __attribute__((ms_abi)) g3(float a, ...) { +void __attribute__((ms_abi)) g3(float a, ...) { // expected-note 2{{parameter of type 'float' is declared here}} __builtin_ms_va_list ap; - __builtin_ms_va_start(ap, a); - __builtin_ms_va_start(ap, (a)); + __builtin_ms_va_start(ap, a); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}} + __builtin_ms_va_start(ap, (a)); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}} } void __attribute__((ms_abi)) g5() { diff --git a/test/Sema/varargs.c b/test/Sema/varargs.c index 5329c2e61c98..457d84c212f7 100644 --- a/test/Sema/varargs.c +++ b/test/Sema/varargs.c @@ -4,7 +4,7 @@ void f1(int a) { __builtin_va_list ap; - + __builtin_va_start(ap, a, a); // expected-error {{too many arguments to function}} __builtin_va_start(ap, a); // expected-error {{'va_start' used in function with fixed args}} } @@ -12,18 +12,17 @@ void f1(int a) void f2(int a, int b, ...) { __builtin_va_list ap; - - __builtin_va_start(ap, 10); // expected-warning {{second parameter of 'va_start' not last named argument}} - __builtin_va_start(ap, a); // expected-warning {{second parameter of 'va_start' not last named argument}} + + __builtin_va_start(ap, 10); // expected-warning {{second argument to 'va_start' is not the last named parameter}} + __builtin_va_start(ap, a); // expected-warning {{second argument to 'va_start' is not the last named parameter}} __builtin_va_start(ap, b); } -void f3(float a, ...) -{ +void f3(float a, ...) { // expected-note 2{{parameter of type 'float' is declared here}} __builtin_va_list ap; - - __builtin_va_start(ap, a); - __builtin_va_start(ap, (a)); + + __builtin_va_start(ap, a); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}} + __builtin_va_start(ap, (a)); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}} } @@ -83,3 +82,15 @@ void f10(int a, ...) { i = __builtin_va_start(ap, a); // expected-error {{assigning to 'int' from incompatible type 'void'}} __builtin_va_end(ap); } + +void f11(short s, ...) { // expected-note {{parameter of type 'short' is declared here}} + __builtin_va_list ap; + __builtin_va_start(ap, s); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}} + __builtin_va_end(ap); +} + +void f12(register int i, ...) { // expected-note {{parameter of type 'int' is declared here}} + __builtin_va_list ap; + __builtin_va_start(ap, i); // expected-warning {{passing a parameter declared with the 'register' keyword to 'va_start' has undefined behavior}} + __builtin_va_end(ap); +} diff --git a/test/Sema/varargs.cpp b/test/Sema/varargs.cpp deleted file mode 100644 index 48a7b2fdf103..000000000000 --- a/test/Sema/varargs.cpp +++ /dev/null @@ -1,7 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s - -class string; -void f(const string& s, ...) { // expected-note {{parameter of type 'const string &' is declared here}} - __builtin_va_list ap; - __builtin_va_start(ap, s); // expected-warning {{'va_start' has undefined behavior with reference types}} -} diff --git a/test/Sema/vector-cast.c b/test/Sema/vector-cast.c index 03db5408c458..c0382892b699 100644 --- a/test/Sema/vector-cast.c +++ b/test/Sema/vector-cast.c @@ -45,12 +45,25 @@ void f3(t3 Y) { } typedef float float2 __attribute__ ((vector_size (8))); +typedef __attribute__((vector_size(8))) double float64x1_t; +typedef __attribute__((vector_size(16))) double float64x2_t; +float64x1_t vget_low_f64(float64x2_t __p0); void f4() { float2 f2; - double d; + double d, a, b, c; + float64x2_t v = {0.0, 1.0}; f2 += d; - d += f2; + a = 3.0 + vget_low_f64(v); + b = vget_low_f64(v) + 3.0; + c = vget_low_f64(v); + // LAX conversions within compound assignments are not supported. + // FIXME: This diagnostic is inaccurate. + d += f2; // expected-error {{cannot convert between vector values of different size}} + c -= vget_low_f64(v); // expected-error {{cannot convert between vector values of different size}} + // LAX conversions between scalar and vector types require same size and one element sized vectors. + d = f2; // expected-error {{assigning to 'double' from incompatible type 'float2'}} + d = d + f2; // expected-error {{assigning to 'double' from incompatible type 'float2'}} } // rdar://15931426 diff --git a/test/Sema/warn-double-promotion.c b/test/Sema/warn-double-promotion.c index b6fd0c5ec629..0cf33e84b427 100644 --- a/test/Sema/warn-double-promotion.c +++ b/test/Sema/warn-double-promotion.c @@ -24,7 +24,7 @@ long double ReturnLongDoubleFromDouble(double d) { return d; //expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} } -void Convert(float f, double d, long double ld) { +void Assignment(float f, double d, long double ld) { d = f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} ld = f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} ld = d; //expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} @@ -32,3 +32,43 @@ void Convert(float f, double d, long double ld) { f = ld; d = ld; } + +extern void DoubleParameter(double); +extern void LongDoubleParameter(long double); + +void ArgumentPassing(float f, double d) { + DoubleParameter(f); // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} + LongDoubleParameter(f); // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} + LongDoubleParameter(d); // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} +} + +void BinaryOperator(float f, double d, long double ld) { + f = f * d; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} + f = d * f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} + f = f * ld; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} + f = ld * f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} + d = d * ld; // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} + d = ld * d; // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} +} + +void MultiplicationAssignment(float f, double d, long double ld) { + d *= f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}} + ld *= f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}} + ld *= d; // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}} + + // FIXME: These cases should produce warnings as above. + f *= d; + f *= ld; + d *= ld; +} + +// FIXME: As with a binary operator, the operands to the conditional operator are +// converted to a common type and should produce a warning. +void ConditionalOperator(float f, double d, long double ld, int i) { + f = i ? f : d; + f = i ? d : f; + f = i ? f : ld; + f = i ? ld : f; + d = i ? d : ld; + d = i ? ld : d; +} diff --git a/test/Sema/wchar.c b/test/Sema/wchar.c index 9e41f5329f9a..74151edede03 100644 --- a/test/Sema/wchar.c +++ b/test/Sema/wchar.c @@ -4,7 +4,7 @@ typedef __WCHAR_TYPE__ wchar_t; #if defined(_WIN32) || defined(_M_IX86) || defined(__CYGWIN__) \ - || defined(_M_X64) || defined(__PS4__) || defined(SHORT_WCHAR) + || defined(_M_X64) || defined(__ORBIS__) || defined(SHORT_WCHAR) #define WCHAR_T_TYPE unsigned short #elif defined(__arm) || defined(__aarch64__) #define WCHAR_T_TYPE unsigned int diff --git a/test/Sema/xray-always-instrument-attr.c b/test/Sema/xray-always-instrument-attr.c new file mode 100644 index 000000000000..3c063e21a68f --- /dev/null +++ b/test/Sema/xray-always-instrument-attr.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 +void foo() __attribute__((xray_always_instrument)); + +struct __attribute__((xray_always_instrument)) a { int x; }; // expected-warning {{'xray_always_instrument' attribute only applies to functions and methods}} + +void bar() __attribute__((xray_always_instrument("not-supported"))); // expected-error {{'xray_always_instrument' attribute takes no arguments}} diff --git a/test/Sema/xray-always-instrument-attr.cpp b/test/Sema/xray-always-instrument-attr.cpp new file mode 100644 index 000000000000..8d42837ec6bf --- /dev/null +++ b/test/Sema/xray-always-instrument-attr.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c++11 -x c++ +void foo [[clang::xray_always_instrument]] (); + +struct [[clang::xray_always_instrument]] a { int x; }; // expected-warning {{'xray_always_instrument' attribute only applies to functions and methods}} + +class b { + void c [[clang::xray_always_instrument]] (); +}; + +void baz [[clang::xray_always_instrument("not-supported")]] (); // expected-error {{'xray_always_instrument' attribute takes no arguments}} |
