Unnamed: 0
int64
0
0
repo_id
stringlengths
5
186
file_path
stringlengths
15
223
content
stringlengths
1
32.8M
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/attr-target.c
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify %s int __attribute__((target("avx,sse4.2,arch=ivybridge"))) foo() { return 4; } int __attribute__((target())) bar() { return 4; } //expected-error {{'target' attribute takes one argument}} int __attribute__((target("tune=sandybridge"))) baz() { return 4; } //expected-warning {{Ignoring unsupported 'tune=' in the target attribute string}} int __attribute__((target("fpmath=387"))) walrus() { return 4; } //expected-warning {{Ignoring unsupported 'fpmath=' in the target attribute string}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/warn-documentation-crlf.c
// RUN: %clang_cc1 -fsyntax-only -Wdocumentation %s // The run line does not have '-verify' because we were crashing while printing // the diagnostic. // This file has DOS-style line endings (CR LF). Please don't change it to // Unix-style LF! // PR14591. Check that we don't crash on this. /** * @param abc */ void nocrash1(int qwerty);
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/x86-builtin-palignr.c
// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -target-feature +mmx -verify -triple x86_64-pc-linux-gnu %s // RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -target-feature +mmx -verify -triple i686-apple-darwin10 %s #include <tmmintrin.h> __m64 test1(__m64 a, __m64 b, int c) { // FIXME: The "incompatible result type" error is due to pr10112 and should // be removed when that is fixed. return _mm_alignr_pi8(a, b, c); // expected-error {{argument to '__builtin_ia32_palignr' must be a constant integer}} expected-error {{incompatible result type}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/format-strings-gnu.c
// RUN: %clang_cc1 -fsyntax-only -verify -triple i386-apple-darwin9 %s // RUN: %clang_cc1 -fsyntax-only -verify -triple thumbv6-apple-ios4.0 %s // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-mingw32 -DMS %s // RUN: %clang_cc1 -fsyntax-only -verify -triple i686-pc-win32 -DMS %s // RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-gnu -DALLOWED %s // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd -DALLOWED %s int printf(const char *restrict, ...); int scanf(const char * restrict, ...) ; void test() { long notLongEnough = 1; long long quiteLong = 2; printf("%Ld", notLongEnough); // expected-warning {{format specifies type 'long long' but the argument has type 'long'}} printf("%Ld", quiteLong); #ifndef ALLOWED // expected-warning@-4 {{length modifier 'L' results in undefined behavior or no effect with 'd' conversion specifier}} // expected-note@-5 {{did you mean to use 'll'?}} // expected-warning@-6 {{length modifier 'L' results in undefined behavior or no effect with 'd' conversion specifier}} // expected-note@-7 {{did you mean to use 'll'?}} #endif #ifndef MS printf("%Z\n", quiteLong); // expected-warning{{invalid conversion specifier 'Z'}} #endif } void testAlwaysInvalid() { // We should not suggest 'll' here! printf("%Lc", 'a'); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 'c' conversion specifier}} printf("%Ls", "a"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}} } #ifdef ALLOWED // PR 9466: clang: doesn't know about %Lu, %Ld, and %Lx void printf_longlong(long long x, unsigned long long y) { printf("%Ld", y); // no-warning printf("%Lu", y); // no-warning printf("%Lx", y); // no-warning printf("%Ld", x); // no-warning printf("%Lu", x); // no-warning printf("%Lx", x); // no-warning printf("%Ls", "hello"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}} } void scanf_longlong(long long *x, unsigned long long *y) { scanf("%Ld", y); // no-warning scanf("%Lu", y); // no-warning scanf("%Lx", y); // no-warning scanf("%Ld", x); // no-warning scanf("%Lu", x); // no-warning scanf("%Lx", x); // no-warning scanf("%Ls", "hello"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}} } #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/format-strings-no-fixit.c
// RUN: cp %s %t // RUN: %clang_cc1 -fsyntax-only -fixit %t // RUN: %clang_cc1 -E -o - %t | FileCheck %s /* This is a test of the various code modification hints that are provided as part of warning or extension diagnostics. Only warnings for format strings within the function call will be fixed by -fixit. Other format strings will be left alone. */ int printf(char const *, ...); int scanf(char const *, ...); void pr9751() { const char kFormat1[] = "%s"; printf(kFormat1, 5); printf("%s", 5); const char kFormat2[] = "%.3p"; void *p; printf(kFormat2, p); printf("%.3p", p); const char kFormat3[] = "%0s"; printf(kFormat3, "a"); printf("%0s", "a"); const char kFormat4[] = "%hhs"; printf(kFormat4, "a"); printf("%hhs", "a"); const char kFormat5[] = "%-0d"; printf(kFormat5, 5); printf("%-0d", 5); const char kFormat6[] = "%00d"; int *i; scanf(kFormat6, i); scanf("%00d", i); } // CHECK: const char kFormat1[] = "%s"; // CHECK: printf(kFormat1, 5); // CHECK: printf("%d", 5); // CHECK: const char kFormat2[] = "%.3p"; // CHECK: void *p; // CHECK: printf(kFormat2, p); // CHECK: printf("%p", p); // CHECK: const char kFormat3[] = "%0s"; // CHECK: printf(kFormat3, "a"); // CHECK: printf("%s", "a"); // CHECK: const char kFormat4[] = "%hhs"; // CHECK: printf(kFormat4, "a"); // CHECK: printf("%s", "a"); // CHECK: const char kFormat5[] = "%-0d"; // CHECK: printf(kFormat5, 5); // CHECK: printf("%-d", 5); // CHECK: const char kFormat6[] = "%00d"; // CHECK: int *i; // CHECK: scanf(kFormat6, i); // CHECK: scanf("%d", i);
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/attr-used.c
// RUN: %clang_cc1 -verify -fsyntax-only -Wno-private-extern %s extern int l0 __attribute__((used)); // expected-warning {{'used' attribute ignored}} __private_extern__ int l1 __attribute__((used)); // expected-warning {{'used' attribute ignored}} struct __attribute__((used)) s { // expected-warning {{'used' attribute only applies to variables and functions}} int x; }; int a __attribute__((used)); static void __attribute__((used)) f0(void) { } void f1() { static int a __attribute__((used)); int b __attribute__((used)); // expected-warning {{'used' attribute ignored}} } static void __attribute__((used)) f0(void);
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/implicit-def.c
/* RUN: %clang_cc1 -fsyntax-only %s -std=c89 * RUN: not %clang_cc1 -fsyntax-only %s -std=c99 -pedantic-errors */ int A() { return X(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/incompatible-sign.c
// RUN: %clang_cc1 %s -verify -fsyntax-only int a(int* x); // expected-note{{passing argument to parameter 'x' here}} int b(unsigned* y) { return a(y); } // expected-warning {{passing 'unsigned int *' to parameter of type 'int *' converts between pointers to integer types with different sign}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/expr-comma-c99.c
// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c99 -Wno-sizeof-array-decay // rdar://6095180 struct s { char c[17]; }; extern struct s foo(void); struct s a, b, c; int A[sizeof((foo().c)) == 17 ? 1 : -1]; int B[sizeof((a.c)) == 17 ? 1 : -1]; // comma does array/function promotion in c99. int X[sizeof(0, (foo().c)) == sizeof(char*) ? 1 : -1]; int Y[sizeof(0, (a,b).c) == sizeof(char*) ? 1 : -1]; int Z[sizeof(0, (a=b).c) == sizeof(char*) ? 1 : -1]; // expected-warning {{expression with side effects has no effect in an unevaluated context}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/weak-import-on-enum.c
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin %s // RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s // expected-no-diagnostics // rdar://10277579 enum __attribute__((deprecated)) __attribute__((weak_import)) A { a0 };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/warn-outof-range-assign-enum.c
// RUN: %clang_cc1 -fsyntax-only -verify -Wassign-enum %s // rdar://11824807 typedef enum CCTestEnum { One, Two=4, Three } CCTestEnum; CCTestEnum test = 50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} CCTestEnum test1 = -50; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} // Explicit cast should silence the warning. static const CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} static const CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning static const CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning static const CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning void SilenceWithCastLocalVar() { CCTestEnum SilenceWithCast1 = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} CCTestEnum SilenceWithCast2 = (CCTestEnum) 51; // no-warning CCTestEnum SilenceWithCast3 = (const CCTestEnum) 51; // no-warning CCTestEnum SilenceWithCast4 = (const volatile CCTestEnum) 51; // no-warning const CCTestEnum SilenceWithCast1c = 51; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} const CCTestEnum SilenceWithCast2c = (CCTestEnum) 51; // no-warning const CCTestEnum SilenceWithCast3c = (const CCTestEnum) 51; // no-warning const CCTestEnum SilenceWithCast4c = (const volatile CCTestEnum) 51; // no-warning } CCTestEnum foo(CCTestEnum r) { return 20; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} } enum Test2 { K_zero, K_one }; enum Test2 test2(enum Test2 *t) { *t = 20; // expected-warning {{integer constant not in range of enumerated type 'enum Test2'}} return 10; // expected-warning {{integer constant not in range of enumerated type 'enum Test2'}} } // PR15069 typedef enum { a = 0 } T; void f() { T x = a; x += 1; // expected-warning {{integer constant not in range of enumerated type}} } int main() { CCTestEnum test = 1; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} test = 600; // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} foo(2); // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} foo(-1); // expected-warning {{integer constant not in range of enumerated type 'CCTestEnum'}} foo(4); foo(Two+1); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/align-systemz.c
// RUN: %clang_cc1 -triple s390x-linux-gnu -fsyntax-only -verify %s // expected-no-diagnostics // SystemZ prefers to align all global variables to two bytes, // but this should *not* be reflected in the ABI alignment as // retrieved via __alignof__. struct test { signed char a; }; char c; struct test s; int chk1[__alignof__(c) == 1 ? 1 : -1]; int chk2[__alignof__(s) == 1 ? 1 : -1];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/warn-documentation-almost-trailing.c
// RUN: %clang_cc1 -fsyntax-only -Wdocumentation -verify %s // RUN: %clang_cc1 -fsyntax-only -Wdocumentation -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s // RUN: cp %s %t // RUN: %clang_cc1 -fsyntax-only -Wdocumentation -fixit %t // RUN: %clang_cc1 -fsyntax-only -Wdocumentation -Werror %t struct a { int x; //< comment // expected-warning {{not a Doxygen trailing comment}} int y; /*< comment */ // expected-warning {{not a Doxygen trailing comment}} }; // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:10-[[@LINE-4]]:13}:"///<" // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:10-[[@LINE-4]]:13}:"/**<"
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/implicit-builtin-redecl.c
// RUN: %clang_cc1 -fsyntax-only -verify %s // PR3592 static void* malloc(int); static void* malloc(int size) { return ((void*)0); /*do not use heap in this file*/ } void *calloc(int, int, int); // expected-warning{{incompatible redeclaration of library function 'calloc'}} \ // expected-note{{'calloc' is a builtin with type 'void *}} void f1(void) { calloc(0, 0, 0); } void f2() { int index = 1; } static int index; int f3() { return index << 2; } typedef int rindex;
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/types.c
// RUN: %clang_cc1 %s -fblocks -pedantic -verify -triple=x86_64-apple-darwin9 // RUN: %clang_cc1 %s -fblocks -pedantic -verify -triple=mips64-linux-gnu // RUN: %clang_cc1 %s -fblocks -pedantic -verify -triple=x86_64-unknown-linux // RUN: %clang_cc1 %s -fblocks -pedantic -verify -triple=x86_64-unknown-linux-gnux32 // rdar://6097662 typedef int (*T)[2]; restrict T x; typedef int *S[2]; restrict S y; // expected-error {{restrict requires a pointer or reference ('S' (aka 'int *[2]') is invalid)}} // int128_t is available. int a() { __int128_t s; __uint128_t t; } // but not a keyword int b() { int __int128_t; int __uint128_t; } // __int128 is a keyword int c() { __int128 i; unsigned __int128 j; long unsigned __int128 k; // expected-error {{'long __int128' is invalid}} int __int128; // expected-error {{cannot combine with previous}} expected-warning {{does not declare anything}} } // __int128_t is __int128; __uint128_t is unsigned __int128. typedef __int128 check_int_128; typedef __int128_t check_int_128; // expected-note {{here}} typedef int check_int_128; // expected-error {{different types ('int' vs '__int128_t' (aka '__int128'))}} typedef unsigned __int128 check_uint_128; typedef __uint128_t check_uint_128; // expected-note {{here}} typedef int check_uint_128; // expected-error {{different types ('int' vs '__uint128_t' (aka 'unsigned __int128'))}} // Array type merging should convert array size to whatever matches the target // pointer size. // rdar://6880874 extern int i[1LL]; int i[(short)1]; enum e { e_1 }; extern int j[sizeof(enum e)]; // expected-note {{previous declaration}} int j[42]; // expected-error {{redefinition of 'j' with a different type: 'int [42]' vs 'int [4]'}} // rdar://6880104 _Decimal32 x; // expected-error {{GNU decimal type extension not supported}} // rdar://6880951 int __attribute__ ((vector_size (8), vector_size (8))) v; // expected-error {{invalid vector element type}} void test(int i) { char c = (char __attribute__((aligned(8)))) i; // expected-warning {{'aligned' attribute ignored when parsing type}} } // http://llvm.org/PR11082 // // FIXME: This may or may not be the correct approach (no warning or error), // but large amounts of Linux and FreeBSD code need this attribute to not be // a hard error in order to work correctly. void test2(int i) { char c = (char __attribute__((may_alias))) i; } // vector size too large int __attribute__ ((vector_size(8192))) x1; // expected-error {{vector size too large}} typedef int __attribute__ ((ext_vector_type(8192))) x2; // expected-error {{vector size too large}} // no support for vector enum type enum { e_2 } x3 __attribute__((vector_size(64))); // expected-error {{invalid vector element type}} int x4 __attribute__((ext_vector_type(64))); // expected-error {{'ext_vector_type' attribute only applies to types}} // rdar://16492792 typedef __attribute__ ((ext_vector_type(32),__aligned__(32))) unsigned char uchar32; void convert() { uchar32 r = 0; r.s[ 1234 ] = 1; // expected-error {{illegal vector component name 's'}} } int &*_Atomic null_type_0; // expected-error {{expected identifier or '('}} int &*__restrict__ null_type_1; // expected-error {{expected identifier or '('}} int ^_Atomic null_type_2; // expected-error {{block pointer to non-function type is invalid}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/arg-scope.c
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics void aa(int b, int x[sizeof b]) {} void foo(int i, int A[i]) {}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/mrtd.c
// RUN: %clang_cc1 -DMRTD -mrtd -triple i386-unknown-unknown -verify %s // RUN: %clang_cc1 -triple i386-unknown-unknown -verify %s #ifndef MRTD // expected-note@+5 {{previous declaration is here}} // expected-error@+5 {{function declared 'stdcall' here was previously declared without calling convention}} // expected-note@+5 {{previous declaration is here}} // expected-error@+5 {{function declared 'stdcall' here was previously declared without calling convention}} #endif void nonvariadic1(int a, int b, int c); void __attribute__((stdcall)) nonvariadic1(int a, int b, int c); void nonvariadic2(int a, int b, int c); void __attribute__((stdcall)) nonvariadic2(int a, int b, int c) { } // expected-warning@+2 {{stdcall calling convention ignored on variadic function}} void variadic(int a, ...); void __attribute__((stdcall)) variadic(int a, ...); #ifdef MRTD // expected-note@+3 {{previous declaration is here}} // expected-error@+3 {{redeclaration of 'a' with a different type: 'void ((*))(int, int) __attribute__((cdecl))' vs 'void (*)(int, int) __attribute__((stdcall))'}} #endif extern void (*a)(int, int); __attribute__((cdecl)) extern void (*a)(int, int); extern void (*b)(int, ...); __attribute__((cdecl)) extern void (*b)(int, ...); #ifndef MRTD // expected-note@+3 {{previous declaration is here}} // expected-error@+3 {{redeclaration of 'c' with a different type: 'void ((*))(int, int) __attribute__((stdcall))' vs 'void (*)(int, int)'}} #endif extern void (*c)(int, int); __attribute__((stdcall)) extern void (*c)(int, int); // expected-warning@+2 {{stdcall calling convention ignored on variadic function}} extern void (*d)(int, ...); __attribute__((stdcall)) extern void (*d)(int, ...);
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/vector-init.c
// RUN: %clang_cc1 %s -fsyntax-only -verify //typedef __attribute__(( ext_vector_type(4) )) float float4; typedef float float4 __attribute__((vector_size(16))); float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 }; float4 foo2 = (float4){ 1.0, 2.0, 3.0, 4.0 , 5.0 }; // expected-warning{{excess elements in vector initializer}} float4 array[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; int array_sizecheck[(sizeof(array) / sizeof(float4)) == 3 ? 1 : -1]; float4 array2[2] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 }; // expected-warning {{excess elements in array initializer}} float4 array3[2] = { {1.0, 2.0, 3.0}, 5.0, 6.0, 7.0, 8.0, 9.0 }; // expected-warning {{excess elements in array initializer}} // PR5650 __attribute__((vector_size(16))) float f1(void) { __attribute__((vector_size(16))) float vec = {0.0f, 0.0f, 0.0f}; return(vec); } __attribute__((vector_size(16))) float f2( __attribute__((vector_size(16))) float a1) { return(a1); } // PR5265 typedef float __attribute__((ext_vector_type (3))) float3; int test2[sizeof(float3) == sizeof(float4) ? 1 : -1]; // rdar://problem/8345836 typedef long long __attribute__((vector_size(16))) longlong2; typedef short __attribute__((vector_size(16))) short8; typedef short __attribute__((vector_size(8))) short4; void test3() { extern short8 test3_helper(void); longlong2 arr1[2] = { test3_helper(), test3_helper() }; short4 arr2[2] = { test3_helper(), test3_helper() }; // expected-error 2 {{initializing 'short4' (vector of 4 'short' values) with an expression of incompatible type 'short8' (vector of 8 'short' values)}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/invalid-struct-init.c
// RUN: %clang_cc1 %s -verify -fsyntax-only typedef struct _zend_module_entry zend_module_entry; struct _zend_module_entry { _efree((p)); // expected-error{{type name requires a specifier or qualifier}} \ expected-warning {{type specifier missing, defaults to 'int'}} }; typedef struct _zend_function_entry { } zend_function_entry; typedef struct _zend_pcre_globals { } zend_pcre_globals; zend_pcre_globals pcre_globals; static void zm_globals_ctor_pcre(zend_pcre_globals *pcre_globals ) { } static void zm_globals_dtor_pcre(zend_pcre_globals *pcre_globals ) { } static void zm_info_pcre(zend_module_entry *zend_module ) { } static int zm_startup_pcre(int type, int module_number ) { } static int zm_shutdown_pcre(int type, int module_number ) { zend_function_entry pcre_functions[] = {{ }; // expected-error{{expected '}'}} expected-note {{to match this '{'}} zend_module_entry pcre_module_entry = { sizeof(zend_module_entry), 20071006, 0, 0, ((void *)0), ((void *)0), "pcre", pcre_functions, zm_startup_pcre, zm_shutdown_pcre, ((void *)0), ((void *)0), zm_info_pcre, ((void *)0), sizeof(zend_pcre_globals), &pcre_globals, ((void (*)(void* ))(zm_globals_ctor_pcre)), ((void (*)(void* ))(zm_globals_dtor_pcre)), ((void *)0), 0, 0, ((void *)0), 0 }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/typeof-use-deprecated.c
// RUN: %clang_cc1 %s -verify -fsyntax-only struct s { int a; } __attribute__((deprecated)) x; // expected-warning {{'s' is deprecated}} expected-note 2 {{'s' has been explicitly marked deprecated here}} typeof(x) y; // expected-warning {{'s' is deprecated}} union un{ int a; } __attribute__((deprecated)) u; // expected-warning {{'un' is deprecated}} expected-note 2 {{'un' has been explicitly marked deprecated here}} typeof( u) z; // expected-warning {{'un' is deprecated}} enum E{ one} __attribute__((deprecated)) e; // expected-warning {{'E' is deprecated}} expected-note 2 {{'E' has been explicitly marked deprecated here}} typeof( e) w; // expected-warning {{'E' is deprecated}} struct foo { int x; } __attribute__((deprecated)); // expected-note {{'foo' has been explicitly marked deprecated here}} typedef struct foo bar __attribute__((deprecated)); // expected-note {{'bar' has been explicitly marked deprecated here}} bar x1; // expected-warning {{'bar' is deprecated}} int main() { typeof(x1) y; } // expected-warning {{'foo' is deprecated}} struct gorf { int x; }; typedef struct gorf T __attribute__((deprecated)); // expected-note {{'T' has been explicitly marked deprecated here}} T t; // expected-warning {{'T' is deprecated}} void wee() { typeof(t) y; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/call-with-static-chain.c
// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s void f(); void g() { __builtin_call_with_static_chain(f(), f); __builtin_call_with_static_chain(f, f); // expected-error {{first argument to __builtin_call_with_static_chain must be a non-member call expression}} __builtin_call_with_static_chain(^{}(), f); // expected-error {{first argument to __builtin_call_with_static_chain must not be a block call}} __builtin_call_with_static_chain(__builtin_unreachable(), f); // expected-error {{first argument to __builtin_call_with_static_chain must not be a builtin call}} __builtin_call_with_static_chain(f(), 42); // expected-error {{second argument to __builtin_call_with_static_chain must be of pointer type}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/enable_if.c
// RUN: %clang_cc1 %s -verify // RUN: %clang_cc1 %s -DCODEGEN -emit-llvm -o - | FileCheck %s #define O_CREAT 0x100 typedef int mode_t; typedef unsigned long size_t; int open(const char *pathname, int flags) __attribute__((enable_if(!(flags & O_CREAT), "must specify mode when using O_CREAT"))) __attribute__((overloadable)); // expected-note{{candidate disabled: must specify mode when using O_CREAT}} int open(const char *pathname, int flags, mode_t mode) __attribute__((overloadable)); // expected-note{{candidate function not viable: requires 3 arguments, but 2 were provided}} void test1() { #ifndef CODEGEN open("path", O_CREAT); // expected-error{{no matching function for call to 'open'}} #endif open("path", O_CREAT, 0660); open("path", 0); open("path", 0, 0); } size_t __strnlen_chk(const char *s, size_t requested_amount, size_t s_len); size_t strnlen(const char *s, size_t maxlen) // expected-note{{candidate function}} __attribute__((overloadable)) __asm__("strnlen_real1"); __attribute__((always_inline)) inline size_t strnlen(const char *s, size_t maxlen) // expected-note{{candidate function}} __attribute__((overloadable)) __attribute__((enable_if(__builtin_object_size(s, 0) != -1, "chosen when target buffer size is known"))) { return __strnlen_chk(s, maxlen, __builtin_object_size(s, 0)); } size_t strnlen(const char *s, size_t maxlen) // expected-note{{candidate disabled: chosen when 'maxlen' is known to be less than or equal to the buffer size}} __attribute__((overloadable)) __attribute__((enable_if(__builtin_object_size(s, 0) != -1, "chosen when target buffer size is known"))) __attribute__((enable_if(maxlen <= __builtin_object_size(s, 0), "chosen when 'maxlen' is known to be less than or equal to the buffer size"))) __asm__("strnlen_real2"); size_t strnlen(const char *s, size_t maxlen) // expected-note{{candidate function has been explicitly made unavailable}} __attribute__((overloadable)) __attribute__((enable_if(__builtin_object_size(s, 0) != -1, "chosen when target buffer size is known"))) __attribute__((enable_if(maxlen > __builtin_object_size(s, 0), "chosen when 'maxlen' is larger than the buffer size"))) __attribute__((unavailable("'maxlen' is larger than the buffer size"))); void test2(const char *s, int i) { // CHECK: define {{.*}}void @test2 const char c[123]; strnlen(s, i); // CHECK: call {{.*}}strnlen_real1 strnlen(s, 999); // CHECK: call {{.*}}strnlen_real1 strnlen(c, 1); // CHECK: call {{.*}}strnlen_real2 strnlen(c, i); // CHECK: call {{.*}}strnlen_chk #ifndef CODEGEN strnlen(c, 999); // expected-error{{call to unavailable function 'strnlen': 'maxlen' is larger than the buffer size}} #endif } int isdigit(int c) __attribute__((overloadable)); // expected-note{{candidate function}} int isdigit(int c) __attribute__((overloadable)) // expected-note{{candidate function has been explicitly made unavailable}} __attribute__((enable_if(c <= -1 || c > 255, "'c' must have the value of an unsigned char or EOF"))) __attribute__((unavailable("'c' must have the value of an unsigned char or EOF"))); void test3(int c) { isdigit(c); isdigit(10); #ifndef CODEGEN isdigit(-10); // expected-error{{call to unavailable function 'isdigit': 'c' must have the value of an unsigned char or EOF}} #endif } // Verify that the alternate spelling __enable_if__ works as well. int isdigit2(int c) __attribute__((overloadable)); // expected-note{{candidate function}} int isdigit2(int c) __attribute__((overloadable)) // expected-note{{candidate function has been explicitly made unavailable}} __attribute__((__enable_if__(c <= -1 || c > 255, "'c' must have the value of an unsigned char or EOF"))) __attribute__((unavailable("'c' must have the value of an unsigned char or EOF"))); void test4(int c) { isdigit2(c); isdigit2(10); #ifndef CODEGEN isdigit2(-10); // expected-error{{call to unavailable function 'isdigit2': 'c' must have the value of an unsigned char or EOF}} #endif } #ifndef CODEGEN __attribute__((enable_if(n == 0, "chosen when 'n' is zero"))) void f1(int n); // expected-error{{use of undeclared identifier 'n'}} int n __attribute__((enable_if(1, "always chosen"))); // expected-warning{{'enable_if' attribute only applies to functions}} void f(int n) __attribute__((enable_if("chosen when 'n' is zero", n == 0))); // expected-error{{'enable_if' attribute requires a string}} void f(int n) __attribute__((enable_if())); // expected-error{{'enable_if' attribute requires exactly 2 arguments}} void f(int n) __attribute__((enable_if(unresolvedid, "chosen when 'unresolvedid' is non-zero"))); // expected-error{{use of undeclared identifier 'unresolvedid'}} int global; void f(int n) __attribute__((enable_if(global == 0, "chosen when 'global' is zero"))); // expected-error{{'enable_if' attribute expression never produces a constant expression}} // expected-note{{subexpression not valid in a constant expression}} const int cst = 7; void return_cst(void) __attribute__((overloadable)) __attribute__((enable_if(cst == 7, "chosen when 'cst' is 7"))); void test_return_cst() { return_cst(); } #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/init.c
// RUN: %clang_cc1 %s -verify -fsyntax-only -ffreestanding #include <stddef.h> #include <stdint.h> typedef void (* fp)(void); void foo(void); // PR clang/3377 fp a[(short int)1] = { foo }; int myArray[5] = {1, 2, 3, 4, 5}; int *myPointer2 = myArray; int *myPointer = &(myArray[2]); extern int x; void *g = &x; int *h = &x; struct union_crash { union { }; }; int test() { int a[10]; int b[10] = a; // expected-error {{array initializer must be an initializer list}} int +; // expected-error {{expected identifier or '('}} struct union_crash u = { .d = 1 }; // expected-error {{field designator 'd' does not refer to any field in type 'struct union_crash'}} } // PR2050 struct cdiff_cmd { const char *name; unsigned short argc; int (*handler)(); }; int cdiff_cmd_open(); struct cdiff_cmd commands[] = { {"OPEN", 1, &cdiff_cmd_open } }; // PR2348 static struct { int z; } s[2]; int *t = &(*s).z; // PR2349 short *a2(void) { short int b; static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}} return bp; } int pbool(void) { typedef const _Bool cbool; _Bool pbool1 = (void *) 0; cbool pbool2 = &pbool; return pbool2; } // rdar://5870981 union { float f; unsigned u; } u = { 1.0f }; // rdar://6156694 int f3(int x) { return x; } typedef void (*vfunc)(void); void *bar = (vfunc) f3; // PR2747 struct sym_reg { char nc_gpreg; }; int sym_fw1a_scr[] = { ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0, 8 * ((int)(&((struct sym_reg *)0)->nc_gpreg)) }; // PR3001 struct s1 s2 = { // expected-error {{variable has incomplete type 'struct s1'}} \ // expected-note {{forward declaration of 'struct s1'}} .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \ // expected-note{{forward declaration of 'struct s3'}} .b = bogus // expected-error {{use of undeclared identifier 'bogus'}} } // PR3382 char t[] = ("Hello"); // <rdar://problem/6094855> typedef struct { } empty; typedef struct { empty e; int i2; } st; st st1 = { .i2 = 1 }; // <rdar://problem/6096826> struct { int a; int z[2]; } y = { .z = {} }; int bbb[10]; struct foo2 { uintptr_t a; }; struct foo2 bar2[] = { { (intptr_t)bbb } }; struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}} int* ptest1 = __builtin_choose_expr(1, (int*)0, (int*)0); typedef int32_t ivector4 __attribute((vector_size(16))); ivector4 vtest1 = 1 ? (ivector4){1} : (ivector4){1}; ivector4 vtest2 = __builtin_choose_expr(1, (ivector4){1}, (ivector4){1}); uintptr_t ptrasintadd1 = (uintptr_t)&a - 4; uintptr_t ptrasintadd2 = (uintptr_t)&a + 4; uintptr_t ptrasintadd3 = 4 + (uintptr_t)&a; // PR4285 const wchar_t widestr[] = L"asdf"; // PR5447 const double pr5447 = (0.05 < -1.0) ? -1.0 : 0.0499878; // PR4386 // None of these are constant initializers, but we implement GCC's old // behaviour of accepting bar and zed but not foo. GCC's behaviour was // changed in 2007 (rev 122551), so we should be able to change too one // day. int PR4386_bar(); int PR4386_foo() __attribute((weak)); int PR4386_zed(); int PR4386_a = ((void *) PR4386_bar) != 0; int PR4386_b = ((void *) PR4386_foo) != 0; // expected-error{{initializer element is not a compile-time constant}} int PR4386_c = ((void *) PR4386_zed) != 0; int PR4386_zed() __attribute((weak)); // <rdar://problem/10185490> (derived from SPEC vortex benchmark) typedef char strty[10]; struct vortexstruct { strty s; }; struct vortexstruct vortexvar = { "asdf" }; typedef struct { uintptr_t x : 2; } StructWithBitfield; StructWithBitfield bitfieldvar = { (uintptr_t)&bitfieldvar }; // expected-error {{initializer element is not a compile-time constant}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/2009-03-09-WeakDeclarations-1.c
// RUN: %clang_cc1 -verify %s -triple i686-apple-darwin // Insist upon warnings for inappropriate weak attributes. // O.K. extern int ext_weak_import __attribute__ ((__weak_import__)); // These are inappropriate, and should generate warnings: int decl_weak_import __attribute__ ((__weak_import__)); // expected-warning {{'weak_import' attribute cannot be specified on a definition}} int decl_initialized_weak_import __attribute__ ((__weak_import__)) = 13; // expected-warning {{'weak_import' attribute cannot be specified on a definition}} // O.K. extern int ext_f(void) __attribute__ ((__weak_import__)); // These are inappropriate, and should generate warnings: int def_f(void) __attribute__ ((__weak_import__)); int __attribute__ ((__weak_import__)) decl_f(void) {return 0;};
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/2010-05-31-palignr.c
// RUN: not %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o /dev/null %s #include <tmmintrin.h> extern int i; int main () { #if defined( __SSSE3__ ) typedef int16_t vSInt16 __attribute__ ((__vector_size__ (16))); short dtbl[] = {1,2,3,4,5,6,7,8}; vSInt16 *vdtbl = (vSInt16*) dtbl; vSInt16 v0; v0 = *vdtbl; v0 = _mm_alignr_epi8(v0, v0, i); // expected-error {{argument to '__builtin_ia32_palignr128' must be a constant integer}} return 0; #endif }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/knr-def-call.c
// RUN: %clang_cc1 -Wconversion -Wliteral-conversion -fsyntax-only -verify %s // C DR #316, PR 3626. void f0(a, b, c, d) int a,b,c,d; {} void t0(void) { f0(1); // expected-warning{{too few arguments}} } void f1(a, b) int a, b; {} void t1(void) { f1(1, 2, 3); // expected-warning{{too many arguments}} } void f2(float); // expected-note{{previous declaration is here}} void f2(x) float x; { } // expected-warning{{promoted type 'double' of K&R function parameter is not compatible with the parameter type 'float' declared in a previous prototype}} typedef void (*f3)(void); f3 t3(int b) { return b? f0 : f1; } // okay // <rdar://problem/8193107> void f4() { char *rindex(); } char *rindex(s, c) register char *s, c; // expected-warning{{promoted type 'char *' of K&R function parameter is not compatible with the parameter type 'const char *' declared in a previous prototype}} { return 0; } // PR8314 void proto(int); void proto(x) int x; { } void use_proto() { proto(42.1); // expected-warning{{implicit conversion from 'double' to 'int' changes value from 42.1 to 42}} (&proto)(42.1); // expected-warning{{implicit conversion from 'double' to 'int' changes value from 42.1 to 42}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/stdcall-fastcall-x64.c
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-pc-linux-gnu %s // CC qualifier can be applied only to functions int __attribute__((stdcall)) var1; // expected-warning{{'stdcall' only applies to function types; type here is 'int'}} int __attribute__((fastcall)) var2; // expected-warning{{'fastcall' only applies to function types; type here is 'int'}} // Different CC qualifiers are not compatible void __attribute__((stdcall, fastcall)) foo3(void); // expected-warning{{calling convention 'stdcall' ignored for this target}} expected-warning {{calling convention 'fastcall' ignored for this target}} void __attribute__((stdcall)) foo4(); // expected-warning{{calling convention 'stdcall' ignored for this target}} void __attribute__((fastcall)) foo4(void); // expected-warning {{calling convention 'fastcall' ignored for this target}} // rdar://8876096 void rdar8876096foo1(int i, int j) __attribute__((fastcall, cdecl)); // expected-warning{{calling convention 'fastcall' ignored for this target}} void rdar8876096foo2(int i, int j) __attribute__((fastcall, stdcall)); // expected-warning{{calling convention 'stdcall' ignored for this target}} expected-warning {{calling convention 'fastcall' ignored for this target}} void rdar8876096foo3(int i, int j) __attribute__((fastcall, regparm(2))); // expected-warning {{calling convention 'fastcall' ignored for this target}} void rdar8876096foo4(int i, int j) __attribute__((stdcall, cdecl)); // expected-warning{{calling convention 'stdcall' ignored for this target}} void rdar8876096foo5(int i, int j) __attribute__((stdcall, fastcall)); // expected-warning{{calling convention 'stdcall' ignored for this target}} expected-warning {{calling convention 'fastcall' ignored for this target}} void rdar8876096foo6(int i, int j) __attribute__((cdecl, fastcall)); // expected-warning {{calling convention 'fastcall' ignored for this target}} void rdar8876096foo7(int i, int j) __attribute__((cdecl, stdcall)); // expected-warning{{calling convention 'stdcall' ignored for this target}} void rdar8876096foo8(int i, int j) __attribute__((regparm(2), fastcall)); // expected-warning {{calling convention 'fastcall' ignored for this target}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/pragma-pack-4.c
// RUN: %clang_cc1 -triple i686-apple-darwin9 %s -fsyntax-only -verify // RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -fsyntax-only -verify // expected-no-diagnostics // rdar://problem/7095436 #pragma pack(4) struct s0 { long long a __attribute__((aligned(8))); long long b __attribute__((aligned(8))); unsigned int c __attribute__((aligned(8))); int d[12]; }; struct s1 { int a[15]; struct s0 b; }; int arr0[((sizeof(struct s1) % 64) == 0) ? 1 : -1];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/warn-missing-braces.c
// RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} expected-warning{{suggest braces}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/altivec-init.c
// RUN: %clang_cc1 %s -triple=powerpc-apple-darwin8 -faltivec -verify -pedantic -fsyntax-only typedef int v4 __attribute((vector_size(16))); typedef short v8 __attribute((vector_size(16))); v8 foo(void) { v8 a; v4 b; a = (v8){4, 2}; b = (v4)(5, 6, 7, 8, 9); // expected-warning {{excess elements in vector initializer}} b = (v4)(5, 6, 8, 8.0f); vector int vi; vi = (vector int)(1); vi = (vector int)(1, 2); // expected-error {{number of elements must be either one or match the size of the vector}} vi = (vector int)(1, 2, 3, 4); vi = (vector int)(1, 2, 3, 4, 5); // expected-warning {{excess elements in vector initializer}} vi = (vector int){1}; vi = (vector int){1, 2}; vi = (vector int){1, 2, 3, 4, 5}; // expected-warning {{excess elements in vector initializer}} vector float vf; vf = (vector float)(1.0); return (v8){0, 1, 2, 3, 1, 2, 3, 4}; // FIXME: test that (type)(fn)(args) still works with -faltivec // FIXME: test that c++ overloaded commas still work -faltivec } void __attribute__((__overloadable__)) f(v4 a) { } void __attribute__((__overloadable__)) f(int a) { } void test() { v4 vGCC; vector int vAltiVec; f(vAltiVec); vGCC = vAltiVec; int res = vGCC > vAltiVec; vAltiVec = 0 ? vGCC : vGCC; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/sentinel-attribute.c
// RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: not %clang_cc1 -fsyntax-only %s -fdiagnostics-parseable-fixits 2>&1 | \ // RUN: FileCheck %s --check-prefix=C // RUN: not %clang_cc1 -fsyntax-only %s -fdiagnostics-parseable-fixits -x c++ -std=c++11 2>&1 | \ // RUN: FileCheck %s --check-prefix=CXX11 int x __attribute__((sentinel)); //expected-warning{{'sentinel' attribute only applies to functions, methods and blocks}} void f1(int a, ...) __attribute__ ((sentinel)); // expected-note {{function has been explicitly marked sentinel here}} void f2(int a, ...) __attribute__ ((sentinel(1))); void f3(int a, ...) __attribute__ ((sentinel("hello"))); //expected-error{{'sentinel' attribute requires parameter 1 to be an integer constant}} void f4(int a, ...) __attribute__ ((sentinel(1, 2, 3))); //expected-error{{'sentinel' attribute takes no more than 2 arguments}} void f4(int a, ...) __attribute__ ((sentinel(-1))); //expected-error{{parameter 1 less than zero}} void f4(int a, ...) __attribute__ ((sentinel(0, 2))); // expected-error{{parameter 2 not 0 or 1}} void f5(int a) __attribute__ ((sentinel)); //expected-warning{{'sentinel' attribute only supported for variadic functions}} void f6() __attribute__((__sentinel__)); // expected-warning {{'sentinel' attribute requires named arguments}} void g() { // The integer literal zero is not a sentinel. f1(1, 0); // expected-warning {{missing sentinel in function call}} // C: fix-it:{{.*}}:{23:10-23:10}:", (void*) 0" // CXX11: fix-it:{{.*}}:{23:10-23:10}:", nullptr" }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/format-strings.c
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs %s // RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -fno-signed-char %s #include <stdarg.h> #include <stddef.h> #define __need_wint_t #include <stddef.h> // For wint_t and wchar_t typedef struct _FILE FILE; int fprintf(FILE *, const char *restrict, ...); int printf(const char *restrict, ...); // expected-note{{passing argument to parameter here}} int snprintf(char *restrict, size_t, const char *restrict, ...); int sprintf(char *restrict, const char *restrict, ...); int vasprintf(char **, const char *, va_list); int asprintf(char **, const char *, ...); int vfprintf(FILE *, const char *restrict, va_list); int vprintf(const char *restrict, va_list); int vsnprintf(char *, size_t, const char *, va_list); int vsprintf(char *restrict, const char *restrict, va_list); // expected-note{{passing argument to parameter here}} int vscanf(const char *restrict format, va_list arg); char * global_fmt; void check_string_literal( FILE* fp, const char* s, char *buf, ... ) { char * b; va_list ap; va_start(ap,buf); printf(s); // expected-warning {{format string is not a string literal}} vprintf(s,ap); // expected-warning {{format string is not a string literal}} fprintf(fp,s); // expected-warning {{format string is not a string literal}} 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}} 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}} snprintf(buf,2,s); // expected-warning {{format string is not a string lit}} __builtin___sprintf_chk(buf,0,-1,s); // expected-warning {{format string is not a string literal}} __builtin___snprintf_chk(buf,2,0,-1,s); // expected-warning {{format string is not a string lit}} 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}} __builtin___vsnprintf_chk(buf,2,0,-1,s,ap); // expected-warning {{format string is not a string lit}} __builtin___vsnprintf_chk(buf,2,0,-1,global_fmt,ap); // expected-warning {{format string is not a string literal}} vscanf(s, ap); // expected-warning {{format string is not a string literal}} // rdar://6079877 printf("abc" "%*d", 1, 1); // no-warning printf("abc\ def" "%*d", 1, 1); // no-warning // <rdar://problem/6079850>, allow 'unsigned' (instead of 'int') to be used for both // the field width and precision. This deviates from C99, but is reasonably safe // and is also accepted by GCC. printf("%*d", (unsigned) 1, 1); // no-warning } // When calling a non-variadic format function (vprintf, vscanf, NSLogv, ...), // warn only if the format string argument is a parameter that is not itself // declared as a format string with compatible format. __attribute__((__format__ (__printf__, 2, 4))) void check_string_literal2( FILE* fp, const char* s, char *buf, ... ) { char * b; va_list ap; va_start(ap,buf); printf(s); // expected-warning {{format string is not a string literal}} vprintf(s,ap); // no-warning fprintf(fp,s); // expected-warning {{format string is not a string literal}} vfprintf(fp,s,ap); // no-warning asprintf(&b,s); // expected-warning {{format string is not a string lit}} vasprintf(&b,s,ap); // no-warning sprintf(buf,s); // expected-warning {{format string is not a string literal}} snprintf(buf,2,s); // expected-warning {{format string is not a string lit}} __builtin___vsnprintf_chk(buf,2,0,-1,s,ap); // no-warning vscanf(s, ap); // expected-warning {{format string is not a string literal}} } 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}} printf("yes" ?: "no %d", 1); // expected-warning{{data argument not used by format string}} } void check_writeback_specifier() { int x; char *b; printf("%n", b); // expected-warning{{format specifies type 'int *' but the argument has type 'char *'}} printf("%n", &x); // no-warning printf("%hhn", (signed char*)0); // no-warning printf("%hhn", (char*)0); // no-warning printf("%hhn", (unsigned char*)0); // no-warning printf("%hhn", (int*)0); // expected-warning{{format specifies type 'signed char *' but the argument has type 'int *'}} printf("%hn", (short*)0); // no-warning printf("%hn", (unsigned short*)0); // no-warning printf("%hn", (int*)0); // expected-warning{{format specifies type 'short *' but the argument has type 'int *'}} printf("%n", (int*)0); // no-warning printf("%n", (unsigned int*)0); // no-warning printf("%n", (char*)0); // expected-warning{{format specifies type 'int *' but the argument has type 'char *'}} printf("%ln", (long*)0); // no-warning printf("%ln", (unsigned long*)0); // no-warning printf("%ln", (int*)0); // expected-warning{{format specifies type 'long *' but the argument has type 'int *'}} printf("%lln", (long long*)0); // no-warning printf("%lln", (unsigned long long*)0); // no-warning printf("%lln", (int*)0); // expected-warning{{format specifies type 'long long *' but the argument has type 'int *'}} printf("%qn", (long long*)0); // no-warning printf("%qn", (unsigned long long*)0); // no-warning printf("%qn", (int*)0); // expected-warning{{format specifies type 'long long *' but the argument has type 'int *'}} printf("%Ln", 0); // expected-warning{{length modifier 'L' results in undefined behavior or no effect with 'n' conversion specifier}} // expected-note@-1{{did you mean to use 'll'?}} } void check_invalid_specifier(FILE* fp, char *buf) { printf("%s%lb%d","unix",10,20); // expected-warning {{invalid conversion specifier 'b'}} fprintf(fp,"%%%l"); // expected-warning {{incomplete format specifier}} sprintf(buf,"%%%%%ld%d%d", 1, 2, 3); // expected-warning{{format specifies type 'long' but the argument has type 'int'}} snprintf(buf, 2, "%%%%%ld%;%d", 1, 2, 3); // expected-warning{{format specifies type 'long' but the argument has type 'int'}} expected-warning {{invalid conversion specifier ';'}} } void check_null_char_string(char* b) { printf("\0this is bogus%d",1); // expected-warning {{string contains '\0'}} snprintf(b,10,"%%%%%d\0%d",1,2); // expected-warning {{string contains '\0'}} printf("%\0d",1); // expected-warning {{string contains '\0'}} } void check_empty_format_string(char* buf, ...) { va_list ap; va_start(ap,buf); vprintf("",ap); // expected-warning {{format string is empty}} sprintf(buf, "", 1); // expected-warning {{format string is empty}} // Don't warn about empty format strings when there are no data arguments. // This can arise from macro expansions and non-standard format string // functions. sprintf(buf, ""); // no-warning } void check_wide_string(char* b, ...) { va_list ap; va_start(ap,b); printf(L"foo %d",2); // expected-warning {{incompatible pointer types}}, expected-warning {{should not be a wide string}} vsprintf(b,L"bar %d",ap); // expected-warning {{incompatible pointer types}}, expected-warning {{should not be a wide string}} } void check_asterisk_precision_width(int x) { printf("%*d"); // expected-warning {{'*' specified field width is missing a matching 'int' argument}} printf("%.*d"); // expected-warning {{'.*' specified field precision is missing a matching 'int' argument}} printf("%*d",12,x); // no-warning printf("%*d","foo",x); // expected-warning {{field width should have type 'int', but argument has type 'char *'}} printf("%.*d","foo",x); // expected-warning {{field precision should have type 'int', but argument has type 'char *'}} } void __attribute__((format(printf,1,3))) myprintf(const char*, int blah, ...); void test_myprintf() { myprintf("%d", 17, 18); // okay } void test_constant_bindings(void) { const char * const s1 = "hello"; const char s2[] = "hello"; const char *s3 = "hello"; char * const s4 = "hello"; extern const char s5[]; printf(s1); // no-warning printf(s2); // no-warning printf(s3); // expected-warning{{not a string literal}} printf(s4); // expected-warning{{not a string literal}} printf(s5); // expected-warning{{not a string literal}} } // Test what happens when -Wformat-security only. #pragma GCC diagnostic ignored "-Wformat-nonliteral" #pragma GCC diagnostic warning "-Wformat-security" void test9(char *P) { int x; printf(P); // expected-warning {{format string is not a string literal (potentially insecure)}} printf(P, 42); } void torture(va_list v8) { vprintf ("%*.*d", v8); // no-warning } void test10(int x, float f, int i, long long lli) { printf("%s"); // expected-warning{{more '%' conversions than data arguments}} printf("%@", 12); // expected-warning{{invalid conversion specifier '@'}} printf("\0"); // expected-warning{{format string contains '\0' within the string body}} printf("xs\0"); // expected-warning{{format string contains '\0' within the string body}} printf("%*d\n"); // expected-warning{{'*' specified field width is missing a matching 'int' argument}} printf("%*.*d\n", x); // expected-warning{{'.*' specified field precision is missing a matching 'int' argument}} printf("%*d\n", f, x); // expected-warning{{field width should have type 'int', but argument has type 'double'}} printf("%*.*d\n", x, f, x); // expected-warning{{field precision should have type 'int', but argument has type 'double'}} printf("%**\n"); // expected-warning{{invalid conversion specifier '*'}} printf("%d%d\n", x); // expected-warning{{more '%' conversions than data arguments}} printf("%d\n", x, x); // expected-warning{{data argument not used by format string}} printf("%W%d\n", x, x); // expected-warning{{invalid conversion specifier 'W'}} printf("%"); // expected-warning{{incomplete format specifier}} printf("%.d", x); // no-warning printf("%.", x); // expected-warning{{incomplete format specifier}} printf("%f", 4); // expected-warning{{format specifies type 'double' but the argument has type 'int'}} printf("%qd", lli); // no-warning printf("%qd", x); // expected-warning{{format specifies type 'long long' but the argument has type 'int'}} printf("%qp", (void *)0); // expected-warning{{length modifier 'q' results in undefined behavior or no effect with 'p' conversion specifier}} printf("hhX %hhX", (unsigned char)10); // no-warning printf("llX %llX", (long long) 10); // no-warning // This is fine, because there is an implicit conversion to an int. printf("%d", (unsigned char) 10); // no-warning printf("%d", (long long) 10); // expected-warning{{format specifies type 'int' but the argument has type 'long long'}} printf("%Lf\n", (long double) 1.0); // no-warning printf("%f\n", (long double) 1.0); // expected-warning{{format specifies type 'double' but the argument has type 'long double'}} // The man page says that a zero precision is okay. printf("%.0Lf", (long double) 1.0); // no-warning printf("%c\n", "x"); // expected-warning{{format specifies type 'int' but the argument has type 'char *'}} printf("%c\n", 1.23); // expected-warning{{format specifies type 'int' but the argument has type 'double'}} printf("Format %d, is %! %f", 1, 2, 4.4); // expected-warning{{invalid conversion specifier '!'}} } typedef unsigned char uint8_t; void should_understand_small_integers() { printf("%hhu", (short) 10); // expected-warning{{format specifies type 'unsigned char' but the argument has type 'short'}} printf("%hu\n", (unsigned char) 1); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'unsigned char'}} printf("%hu\n", (uint8_t)1); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'uint8_t'}} } void test11(void *p, char *s) { printf("%p", p); // no-warning printf("%p", 123); // expected-warning{{format specifies type 'void *' but the argument has type 'int'}} printf("%.4p", p); // expected-warning{{precision used with 'p' conversion specifier, resulting in undefined behavior}} printf("%+p", p); // expected-warning{{flag '+' results in undefined behavior with 'p' conversion specifier}} printf("% p", p); // expected-warning{{flag ' ' results in undefined behavior with 'p' conversion specifier}} printf("%0p", p); // expected-warning{{flag '0' results in undefined behavior with 'p' conversion specifier}} printf("%s", s); // no-warning printf("%+s", p); // expected-warning{{flag '+' results in undefined behavior with 's' conversion specifier}} printf("% s", p); // expected-warning{{flag ' ' results in undefined behavior with 's' conversion specifier}} printf("%0s", p); // expected-warning{{flag '0' results in undefined behavior with 's' conversion specifier}} } void test12(char *b) { unsigned char buf[4]; printf ("%.4s\n", buf); // no-warning printf ("%.4s\n", &buf); // expected-warning{{format specifies type 'char *' but the argument has type 'unsigned char (*)[4]'}} // Verify that we are checking asprintf asprintf(&b, "%d", "asprintf"); // expected-warning{{format specifies type 'int' but the argument has type 'char *'}} } void test13(short x) { char bel = 007; printf("bel: '0%hhd'\n", bel); // no-warning printf("x: '0%hhd'\n", x); // expected-warning {{format specifies type 'char' but the argument has type 'short'}} } typedef struct __aslclient *aslclient; typedef struct __aslmsg *aslmsg; int asl_log(aslclient asl, aslmsg msg, int level, const char *format, ...) __attribute__((__format__ (__printf__, 4, 5))); void test_asl(aslclient asl) { // Test case from <rdar://problem/7341605>. asl_log(asl, 0, 3, "Error: %m"); // no-warning asl_log(asl, 0, 3, "Error: %W"); // expected-warning{{invalid conversion specifier 'W'}} } // <rdar://problem/7595366> typedef enum { A } int_t; void f0(int_t x) { printf("%d\n", x); } // Unicode test cases. These are possibly specific to Mac OS X. If so, they should // eventually be moved into a separate test. void test_unicode_conversions(wchar_t *s) { printf("%S", s); // no-warning printf("%s", s); // expected-warning{{format specifies type 'char *' but the argument has type 'wchar_t *'}} printf("%C", s[0]); // no-warning printf("%c", s[0]); // FIXME: This test reports inconsistent results. On Windows, '%C' expects // 'unsigned short'. // printf("%C", 10); printf("%S", "hello"); // expected-warning{{but the argument has type 'char *'}} } // Mac OS X supports positional arguments in format strings. // This is an IEEE extension (IEEE Std 1003.1). // FIXME: This is probably not portable everywhere. void test_positional_arguments() { printf("%0$", (int)2); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}} printf("%1$*0$d", (int) 2); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}} printf("%1$d", (int) 2); // no-warning printf("%1$d", (int) 2, 2); // expected-warning{{data argument not used by format string}} printf("%1$d%1$f", (int) 2); // expected-warning{{format specifies type 'double' but the argument has type 'int'}} printf("%1$2.2d", (int) 2); // no-warning printf("%2$*1$.2d", (int) 2, (int) 3); // no-warning printf("%2$*8$d", (int) 2, (int) 3); // expected-warning{{specified field width is missing a matching 'int' argument}} printf("%%%1$d", (int) 2); // no-warning printf("%1$d%%", (int) 2); // no-warning } // PR 6697 - Handle format strings where the data argument is not adjacent to the format string void myprintf_PR_6697(const char *format, int x, ...) __attribute__((__format__(printf,1, 3))); void test_pr_6697() { myprintf_PR_6697("%s\n", 1, "foo"); // no-warning myprintf_PR_6697("%s\n", 1, (int)0); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}} // FIXME: Not everything should clearly support positional arguments, // but we need a way to identify those cases. myprintf_PR_6697("%1$s\n", 1, "foo"); // no-warning myprintf_PR_6697("%2$s\n", 1, "foo"); // expected-warning{{data argument position '2' exceeds the number of data arguments (1)}} myprintf_PR_6697("%18$s\n", 1, "foo"); // expected-warning{{data argument position '18' exceeds the number of data arguments (1)}} myprintf_PR_6697("%1$s\n", 1, (int) 0); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}} } void rdar8026030(FILE *fp) { fprintf(fp, "\%"); // expected-warning{{incomplete format specifier}} } void bug7377_bad_length_mod_usage() { // Bad length modifiers printf("%hhs", "foo"); // expected-warning{{length modifier 'hh' results in undefined behavior or no effect with 's' conversion specifier}} printf("%1$zp", (void *)0); // expected-warning{{length modifier 'z' results in undefined behavior or no effect with 'p' conversion specifier}} printf("%ls", L"foo"); // no-warning printf("%#.2Lf", (long double)1.234); // no-warning // Bad flag usage printf("%#p", (void *) 0); // expected-warning{{flag '#' results in undefined behavior with 'p' conversion specifier}} printf("%0d", -1); // no-warning printf("%#n", (int *) 0); // expected-warning{{flag '#' results in undefined behavior with 'n' conversion specifier}} printf("%-n", (int *) 0); // expected-warning{{flag '-' results in undefined behavior with 'n' conversion specifier}} printf("%-p", (void *) 0); // no-warning // Bad optional amount use printf("%.2c", 'a'); // expected-warning{{precision used with 'c' conversion specifier, resulting in undefined behavior}} printf("%1n", (int *) 0); // expected-warning{{field width used with 'n' conversion specifier, resulting in undefined behavior}} printf("%.9n", (int *) 0); // expected-warning{{precision used with 'n' conversion specifier, resulting in undefined behavior}} // Ignored flags printf("% +f", 1.23); // expected-warning{{flag ' ' is ignored when flag '+' is present}} printf("%+ f", 1.23); // expected-warning{{flag ' ' is ignored when flag '+' is present}} printf("%0-f", 1.23); // expected-warning{{flag '0' is ignored when flag '-' is present}} printf("%-0f", 1.23); // expected-warning{{flag '0' is ignored when flag '-' is present}} printf("%-+f", 1.23); // no-warning } // PR 7981 - handle '%lc' (wint_t) void pr7981(wint_t c, wchar_t c2) { printf("%lc", c); // no-warning printf("%lc", 1.0); // expected-warning{{the argument has type 'double'}} printf("%lc", (char) 1); // no-warning printf("%lc", &c); // expected-warning{{the argument has type 'wint_t *'}} // If wint_t and wchar_t are the same width and wint_t is signed where // wchar_t is unsigned, an implicit conversion isn't possible. #if defined(__WINT_UNSIGNED__) || !defined(__WCHAR_UNSIGNED__) || \ __WINT_WIDTH__ > __WCHAR_WIDTH__ printf("%lc", c2); // no-warning #endif } // <rdar://problem/8269537> -Wformat-security says NULL is not a string literal void rdar8269537() { // This is likely to crash in most cases, but -Wformat-nonliteral technically // doesn't warn in this case. printf(0); // no-warning } // Handle functions with multiple format attributes. extern void rdar8332221_vprintf_scanf(const char *, va_list, const char *, ...) __attribute__((__format__(__printf__, 1, 0))) __attribute__((__format__(__scanf__, 3, 4))); void rdar8332221(va_list ap, int *x, long *y) { rdar8332221_vprintf_scanf("%", ap, "%d", x); // expected-warning{{incomplete format specifier}} } // PR8641 void pr8641() { printf("%#x\n", 10); printf("%#X\n", 10); } void posix_extensions() { // Test %'d, "thousands grouping". // <rdar://problem/8816343> printf("%'d\n", 123456789); // no-warning printf("%'i\n", 123456789); // no-warning printf("%'f\n", (float) 1.0); // no-warning printf("%'p\n", (void*) 0); // expected-warning{{results in undefined behavior with 'p' conversion specifier}} } // PR8486 // // Test what happens when -Wformat is on, but -Wformat-security is off. #pragma GCC diagnostic warning "-Wformat" #pragma GCC diagnostic ignored "-Wformat-security" void pr8486() { printf("%s", 1); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}} } // PR9314 // Don't warn about string literals that are PreDefinedExprs, e.g. __func__. void pr9314() { printf(__PRETTY_FUNCTION__); // no-warning printf(__func__); // no-warning } int printf(const char * restrict, ...) __attribute__((__format__ (__printf__, 1, 2))); void rdar9612060(void) { printf("%s", 2); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}} } void check_char(unsigned char x, signed char y) { printf("%c", y); // no-warning printf("%hhu", x); // no-warning printf("%hhi", y); // no-warning printf("%hhi", x); // no-warning printf("%c", x); // no-warning printf("%hhu", y); // no-warning } // Test suppression of individual warnings. void test_suppress_invalid_specifier() { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wformat-invalid-specifier" printf("%@", 12); // no-warning #pragma clang diagnostic pop } // Make sure warnings are on for next test. #pragma GCC diagnostic warning "-Wformat" #pragma GCC diagnostic warning "-Wformat-security" // Test that the printf call site is where the warning is attached. If the // format string is somewhere else, point to it in a note. void pr9751() { const char kFormat1[] = "%d %d \n"; // expected-note{{format string is defined here}}} printf(kFormat1, 0); // expected-warning{{more '%' conversions than data arguments}} printf("%d %s\n", 0); // expected-warning{{more '%' conversions than data arguments}} const char kFormat2[] = "%18$s\n"; // expected-note{{format string is defined here}} printf(kFormat2, 1, "foo"); // expected-warning{{data argument position '18' exceeds the number of data arguments (2)}} printf("%18$s\n", 1, "foo"); // expected-warning{{data argument position '18' exceeds the number of data arguments (2)}} const char kFormat4[] = "%y"; // expected-note{{format string is defined here}} printf(kFormat4, 5); // expected-warning{{invalid conversion specifier 'y'}} printf("%y", 5); // expected-warning{{invalid conversion specifier 'y'}} const char kFormat5[] = "%."; // expected-note{{format string is defined here}} printf(kFormat5, 5); // expected-warning{{incomplete format specifier}} printf("%.", 5); // expected-warning{{incomplete format specifier}} const char kFormat6[] = "%s"; // expected-note{{format string is defined here}} printf(kFormat6, 5); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}} printf("%s", 5); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}} const char kFormat7[] = "%0$"; // expected-note{{format string is defined here}} printf(kFormat7, 5); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}} printf("%0$", 5); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}} const char kFormat8[] = "%1$d %d"; // expected-note{{format string is defined here}} printf(kFormat8, 4, 4); // expected-warning{{cannot mix positional and non-positional arguments in format string}} printf("%1$d %d", 4, 4); // expected-warning{{cannot mix positional and non-positional arguments in format string}} const char kFormat9[] = ""; // expected-note{{format string is defined here}} printf(kFormat9, 4, 4); // expected-warning{{format string is empty}} printf("", 4, 4); // expected-warning{{format string is empty}} const char kFormat10[] = "\0%d"; // expected-note{{format string is defined here}} printf(kFormat10, 4); // expected-warning{{format string contains '\0' within the string body}} printf("\0%d", 4); // expected-warning{{format string contains '\0' within the string body}} const char kFormat11[] = "%*d"; // expected-note{{format string is defined here}} printf(kFormat11); // expected-warning{{'*' specified field width is missing a matching 'int' argument}} printf("%*d"); // expected-warning{{'*' specified field width is missing a matching 'int' argument}} const char kFormat12[] = "%*d"; // expected-note{{format string is defined here}} printf(kFormat12, 4.4); // expected-warning{{field width should have type 'int', but argument has type 'double'}} printf("%*d", 4.4); // expected-warning{{field width should have type 'int', but argument has type 'double'}} const char kFormat13[] = "%.3p"; // expected-note{{format string is defined here}} void *p; printf(kFormat13, p); // expected-warning{{precision used with 'p' conversion specifier, resulting in undefined behavior}} printf("%.3p", p); // expected-warning{{precision used with 'p' conversion specifier, resulting in undefined behavior}} const char kFormat14[] = "%0s"; // expected-note{{format string is defined here}} printf(kFormat14, "a"); // expected-warning{{flag '0' results in undefined behavior with 's' conversion specifier}} printf("%0s", "a"); // expected-warning{{flag '0' results in undefined behavior with 's' conversion specifier}} const char kFormat15[] = "%hhs"; // expected-note{{format string is defined here}} printf(kFormat15, "a"); // expected-warning{{length modifier 'hh' results in undefined behavior or no effect with 's' conversion specifier}} printf("%hhs", "a"); // expected-warning{{length modifier 'hh' results in undefined behavior or no effect with 's' conversion specifier}} const char kFormat16[] = "%-0d"; // expected-note{{format string is defined here}} printf(kFormat16, 5); // expected-warning{{flag '0' is ignored when flag '-' is present}} printf("%-0d", 5); // expected-warning{{flag '0' is ignored when flag '-' is present}} // 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}} 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}} printf("%a", (long double)0); // expected-warning{{format specifies type 'double' but the argument has type 'long double'}} // Test braced char[] initializers. const char kFormat18[] = { "%lld" }; // expected-note{{format string is defined here}} printf(kFormat18, 0); // expected-warning{{format specifies type}} // Make sure we point at the offending argument rather than the format string. const char kFormat19[] = "%d"; // expected-note{{format string is defined here}} printf(kFormat19, 0.0); // expected-warning{{format specifies}} } void pr18905() { const char s1[] = "s\0%s"; // expected-note{{format string is defined here}} const char s2[1] = "s"; // expected-note{{format string is defined here}} const char s3[2] = "s\0%s"; // expected-warning{{initializer-string for char array is too long}} const char s4[10] = "s"; const char s5[0] = "%s"; // expected-warning{{initializer-string for char array is too long}} // expected-note@-1{{format string is defined here}} printf(s1); // expected-warning{{format string contains '\0' within the string body}} printf(s2); // expected-warning{{format string is not null-terminated}} printf(s3); // no-warning printf(s4); // no-warning printf(s5); // expected-warning{{format string is not null-terminated}} } void __attribute__((format(strfmon,1,2))) monformat(const char *fmt, ...); void __attribute__((format(strftime,1,0))) dateformat(const char *fmt); // Other formats void test_other_formats() { char *str = ""; monformat("", 1); // expected-warning{{format string is empty}} monformat(str); // expected-warning{{format string is not a string literal (potentially insecure)}} dateformat(""); // expected-warning{{format string is empty}} dateformat(str); // no-warning (using strftime non-literal is not unsafe) } // Do not warn about unused arguments coming from system headers. // <rdar://problem/11317765> #include <format-unused-system-args.h> void test_unused_system_args(int x) { PRINT1("%d\n", x); // no-warning{{extra argument is system header is OK}} } void pr12761(char c) { // This should not warn even with -fno-signed-char. printf("%hhx", c); } // Test that we correctly merge the format in both orders. extern void test14_foo(const char *, const char *, ...) __attribute__((__format__(__printf__, 1, 3))); extern void test14_foo(const char *, const char *, ...) __attribute__((__format__(__scanf__, 2, 3))); extern void test14_bar(const char *, const char *, ...) __attribute__((__format__(__scanf__, 2, 3))); extern void test14_bar(const char *, const char *, ...) __attribute__((__format__(__printf__, 1, 3))); void test14_zed(int *p) { test14_foo("%", "%d", p); // expected-warning{{incomplete format specifier}} test14_bar("%", "%d", p); // expected-warning{{incomplete format specifier}} } void test_qualifiers(volatile int *vip, const int *cip, const volatile int *cvip) { printf("%n", cip); // expected-warning{{format specifies type 'int *' but the argument has type 'const int *'}} printf("%n", cvip); // expected-warning{{format specifies type 'int *' but the argument has type 'const volatile int *'}} printf("%n", vip); // No warning. printf("%p", cip); // No warning. printf("%p", cvip); // No warning. typedef int* ip_t; typedef const int* cip_t; printf("%n", (ip_t)0); // No warning. printf("%n", (cip_t)0); // expected-warning{{format specifies type 'int *' but the argument has type 'cip_t' (aka 'const int *')}} } #pragma GCC diagnostic ignored "-Wformat-nonliteral" #pragma GCC diagnostic warning "-Wformat-security" // <rdar://problem/14178260> 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)}} } #pragma GCC diagnostic warning "-Wformat-nonliteral"
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/arg-scope-c99.c
// RUN: %clang_cc1 -fsyntax-only -std=c99 -verify %s // expected-no-diagnostics void bb(int sz, int ar[sz][sz]) { }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/arm-microsoft-intrinsics.c
// RUN: %clang_cc1 -triple armv7 -fms-extensions -fsyntax-only -ffreestanding -verify %s unsigned int test_MoveFromCoprocessor(const unsigned int value) { return _MoveFromCoprocessor(value, 1, 2, 3, 4); // expected-error-re {{argument to {{.*}} must be a constant integer}} } void test_MoveToCoprocessor(const unsigned int value) { _MoveToCoprocessor(1, 2, value, 3, 4, 5); // expected-error-re {{argument to {{.*}} must be a constant integer}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/arm-layout.c
// RUN: %clang_cc1 -triple armv7-unknown-unknown -target-abi apcs-gnu %s -verify // RUN: %clang_cc1 -triple armv7-unknown-unknown -target-abi aapcs %s -verify // expected-no-diagnostics #define check(name, cond) int _##name##_check[(cond) ? 1 : -1] struct s0 { char field0; double field1; }; #ifdef __ARM_EABI__ check(s0_size, sizeof(struct s0) == 16); #else check(s0_size, sizeof(struct s0) == 12); #endif struct s1 { char field0; long double field1; }; #ifdef __ARM_EABI__ check(s1_size, sizeof(struct s1) == 16); #else check(s1_size, sizeof(struct s1) == 12); #endif struct s2 { short field0; int field1 : 24; char field2; }; #ifdef __ARM_EABI__ check(s2_size, sizeof(struct s2) == 8); check(s2_offset_0, __builtin_offsetof(struct s2, field0) == 0); check(s2_offset_1, __builtin_offsetof(struct s2, field2) == 7); #else check(s2_size, sizeof(struct s2) == 6); check(s2_offset_0, __builtin_offsetof(struct s2, field0) == 0); check(s2_offset_1, __builtin_offsetof(struct s2, field2) == 5); #endif struct s3 { short field0; int field1 : 24 __attribute__((aligned(4))); char field2; }; check(s3_size, sizeof(struct s3) == 8); check(s3_offset_0, __builtin_offsetof(struct s3, field0) == 0); check(s3_offset_1, __builtin_offsetof(struct s3, field2) == 7); struct s4 { int field0 : 4; }; #ifdef __ARM_EABI__ check(s4_size, sizeof(struct s4) == 4); check(s4_align, __alignof(struct s4) == 4); #else check(s4_size, sizeof(struct s4) == 1); check(s4_align, __alignof(struct s4) == 1); #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/format-strings-enum-fixed-type.cpp
// RUN: %clang_cc1 -triple i386-apple-darwin9 -x c++ -std=c++11 -verify %s // RUN: %clang_cc1 -triple i386-apple-darwin9 -x objective-c -verify %s // RUN: %clang_cc1 -triple i386-apple-darwin9 -x objective-c++ -verify %s #ifdef __cplusplus # define EXTERN_C extern "C" #else # define EXTERN_C extern #endif EXTERN_C int printf(const char *,...); typedef enum : short { Constant = 0 } TestEnum; // Note that in C (and Objective-C), the type of 'Constant' is 'short'. // In C++ (and Objective-C++) it is 'TestEnum'. // This is why we don't check for that in the expected output. void test(TestEnum input) { printf("%hhd", input); // expected-warning{{format specifies type 'char' but the argument has underlying type 'short'}} printf("%hhd", Constant); // expected-warning{{format specifies type 'char'}} printf("%hd", input); // no-warning printf("%hd", Constant); // no-warning // While these are less correct, they are still safe. printf("%d", input); // no-warning printf("%d", Constant); // no-warning printf("%lld", input); // expected-warning{{format specifies type 'long long' but the argument has underlying type 'short'}} printf("%lld", Constant); // expected-warning{{format specifies type 'long long'}} } typedef enum : unsigned long { LongConstant = ~0UL } LongEnum; void testLong(LongEnum input) { printf("%u", input); // expected-warning{{format specifies type 'unsigned int' but the argument has underlying type 'unsigned long'}} printf("%u", LongConstant); // expected-warning{{format specifies type 'unsigned int'}} printf("%lu", input); printf("%lu", LongConstant); } typedef short short_t; typedef enum : short_t { ShortConstant = 0 } ShortEnum; void testUnderlyingTypedef(ShortEnum input) { printf("%hhd", input); // expected-warning{{format specifies type 'char' but the argument has underlying type 'short_t' (aka 'short')}} printf("%hhd", ShortConstant); // expected-warning{{format specifies type 'char'}} printf("%hd", input); // no-warning printf("%hd", ShortConstant); // no-warning // While these are less correct, they are still safe. printf("%d", input); // no-warning printf("%d", ShortConstant); // no-warning printf("%lld", input); // expected-warning{{format specifies type 'long long' but the argument has underlying type 'short_t' (aka 'short')}} printf("%lld", ShortConstant); // expected-warning{{format specifies type 'long long'}} } typedef ShortEnum ShortEnum2; void testTypedefChain(ShortEnum2 input) { printf("%hhd", input); // expected-warning{{format specifies type 'char' but the argument has underlying type 'short_t' (aka 'short')}} printf("%hd", input); // no-warning printf("%d", input); // no-warning printf("%lld", input); // expected-warning{{format specifies type 'long long' but the argument has underlying type 'short_t' (aka 'short')}} } typedef enum : char { CharConstant = 'a' } CharEnum; // %hhd is deliberately not required to be signed, because 'char' isn't either. // This is a separate code path in FormatString.cpp. void testChar(CharEnum input) { printf("%hhd", input); // no-warning printf("%hhd", CharConstant); // no-warning // This is not correct but it is safe. We warn because '%hd' shows intent. printf("%hd", input); // expected-warning{{format specifies type 'short' but the argument has underlying type 'char'}} printf("%hd", CharConstant); // expected-warning{{format specifies type 'short'}} // This is not correct but it matches the promotion rules (and is safe). printf("%d", input); // no-warning printf("%d", CharConstant); // no-warning printf("%lld", input); // expected-warning{{format specifies type 'long long' but the argument has underlying type 'char'}} printf("%lld", CharConstant); // expected-warning{{format specifies type 'long long'}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/warn-bad-function-cast.c
// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wbad-function-cast -triple x86_64-unknown-unknown -verify // rdar://9103192 void vf(void); int if1(void); char if2(void); long if3(void); float rf1(void); double rf2(void); _Complex double cf(void); enum e { E1 } ef(void); _Bool bf(void); char *pf1(void); int *pf2(void); void foo(void) { /* Casts to void types are always OK. */ (void)vf(); (void)if1(); (void)cf(); (const void)bf(); /* Casts to the same type or similar types are OK. */ (int)if1(); (long)if2(); (char)if3(); (float)rf1(); (long double)rf2(); (_Complex float)cf(); (enum f { F1 })ef(); (_Bool)bf(); (void *)pf1(); (char *)pf2(); /* All following casts issue warning */ (float)if1(); /* expected-warning {{cast from function call of type 'int' to non-matching type 'float'}} */ (double)if2(); /* expected-warning {{cast from function call of type 'char' to non-matching type 'double'}} */ (_Bool)if3(); /* expected-warning {{cast from function call of type 'long' to non-matching type '_Bool'}} */ (int)rf1(); /* expected-warning {{cast from function call of type 'float' to non-matching type 'int'}} */ (long)rf2(); /* expected-warning {{cast from function call of type 'double' to non-matching type 'long'}} */ (double)cf(); /* expected-warning {{cast from function call of type '_Complex double' to non-matching type 'double'}} */ (int)ef(); /* expected-warning {{cast from function call of type 'enum e' to non-matching type 'int'}} */ (int)bf(); /* expected-warning {{cast from function call of type '_Bool' to non-matching type 'int'}} */ (__SIZE_TYPE__)pf1(); /* expected-warning {{cast from function call of type 'char *' to non-matching type 'unsigned long'}} */ (__PTRDIFF_TYPE__)pf2(); /* expected-warning {{cast from function call of type 'int *' to non-matching type 'long'}} */ }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/redefinition.c
// RUN: %clang_cc1 %s -fsyntax-only -verify int f(int a) { return 0; } // expected-note {{previous definition is here}} int f(int); int f(int a) { return 0; } // expected-error {{redefinition of 'f'}} // <rdar://problem/6097326> int foo(x) { return 0; } int x = 1; // <rdar://problem/6880464> extern inline int g(void) { return 0; } // expected-note{{previous definition}} int g(void) { return 0; } // expected-error{{redefinition of a 'extern inline' function 'g' is not supported in C99 mode}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/MicrosoftCompatibility-x64.c
// RUN: %clang_cc1 %s -Wmicrosoft -verify -fms-compatibility -triple x86_64-pc-win32 // None of these should warn. stdcall is treated as equivalent to cdecl on // x64. // expected-no-diagnostics int __stdcall f(void); int __cdecl f(void) { return 0; } int __stdcall func_std(void); int __thiscall func_this(void); int __fastcall func_fast(void);
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/attr-availability-macosx.c
// RUN: %clang_cc1 "-triple" "x86_64-apple-darwin9.0.0" -fsyntax-only -verify %s 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 test() { f0(0); f1(0); f2(0); // expected-warning{{'f2' is deprecated: first deprecated in OS X 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}} } // rdar://10535640 enum { foo __attribute__((availability(macosx,introduced=8.0,deprecated=9.0))) }; enum { bar __attribute__((availability(macosx,introduced=8.0,deprecated=9.0))) = foo }; enum __attribute__((availability(macosx,introduced=8.0,deprecated=9.0))) { bar1 = foo };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/array-declared-as-incorrect-type.c
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s extern int a1[]; int a1[1]; extern int a2[]; // expected-note {{previous declaration is here}} float a2[1]; // expected-error {{redefinition of 'a2'}} extern int a3[][2]; int a3[1][2]; extern int a4[][2]; // expected-note {{previous declaration is here}} int a4[2]; // expected-error {{redefinition of 'a4'}} extern int a5[1][2][3]; // expected-note {{previous declaration is here}} int a5[3][2][1]; // expected-error {{redefinition of 'a5'}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/builtin-object-size.c
// RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin9 -verify %s int a[10]; int f0() { return __builtin_object_size(&a); // expected-error {{too few arguments to function}} } int f1() { return (__builtin_object_size(&a, 0) + __builtin_object_size(&a, 1) + __builtin_object_size(&a, 2) + __builtin_object_size(&a, 3)); } int f2() { return __builtin_object_size(&a, -1); // expected-error {{argument should be a value from 0 to 3}} } int f3() { return __builtin_object_size(&a, 4); // expected-error {{argument should be a value from 0 to 3}} } // rdar://6252231 - cannot call vsnprintf with va_list on x86_64 void f4(const char *fmt, ...) { __builtin_va_list args; __builtin___vsnprintf_chk (0, 42, 0, 11, fmt, args); // expected-warning {{'__builtin___vsnprintf_chk' will always overflow destination buffer}} } // rdar://18334276 typedef __typeof__(sizeof(int)) size_t; void * memcset(void *restrict dst, int src, size_t n); void * memcpy(void *restrict dst, const void *restrict src, size_t n); #define memset(dest, src, len) __builtin___memset_chk(dest, src, len, __builtin_object_size(dest, 0)) #define memcpy(dest, src, len) __builtin___memcpy_chk(dest, src, len, __builtin_object_size(dest, 0)) #define memcpy1(dest, src, len) __builtin___memcpy_chk(dest, src, len, __builtin_object_size(dest, 4)) #define NULL ((void *)0) void f5(void) { char buf[10]; memset((void *)0x100000000ULL, 0, 0x1000); memcpy((char *)NULL + 0x10000, buf, 0x10); memcpy1((char *)NULL + 0x10000, buf, 0x10); // expected-error {{argument should be a value from 0 to 3}} } // rdar://18431336 void f6(void) { char b[5]; char buf[10]; __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}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/MicrosoftCompatibility-x86.c
// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-compatibility -triple i386-pc-win32 int __stdcall f(void); /* expected-note {{previous declaration is here}} */ int __cdecl f(void) { /* expected-error {{function declared 'cdecl' here was previously declared 'stdcall'}} */ return 0; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/return-silent.c
// RUN: %clang_cc1 %s -Wno-return-type -fsyntax-only -verify // expected-no-diagnostics int t14() { return; } void t15() { return 1; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/ms-inline-asm-invalid-arch.c
// RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -fasm-blocks -verify -fsyntax-only void f() { __asm nop // expected-error {{Unsupported architecture 'powerpc64' for MS-style inline assembly}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/struct-decl.c
// RUN: %clang_cc1 -fsyntax-only -verify %s // PR3459 struct bar { char n[1]; }; struct foo { char name[(int)&((struct bar *)0)->n]; char name2[(int)&((struct bar *)0)->n - 1]; //expected-error{{'name2' declared as an array with a negative size}} }; // PR3430 struct s { struct st { int v; } *ts; }; struct st; int foo() { struct st *f; return f->v + f[0].v; } // PR3642, PR3671 struct pppoe_tag { short tag_type; char tag_data[]; }; struct datatag { struct pppoe_tag hdr; //expected-warning{{field 'hdr' with variable sized type 'struct pppoe_tag' not at the end of a struct or class is a GNU extension}} char data; }; // PR4092 struct s0 { char a; // expected-note {{previous declaration is here}} char a; // expected-error {{duplicate member 'a'}} }; struct s0 f0(void) {} // <rdar://problem/8177927> - This previously triggered an assertion failure. struct x0 { unsigned int x1; }; // rdar://problem/9150338 static struct test1 { // expected-warning {{'static' ignored on this declaration}} int x; }; const struct test2 { // expected-warning {{'const' ignored on this declaration}} int x; }; inline struct test3 { // expected-error {{'inline' can only appear on functions}} int x; }; struct hiding_1 {}; struct hiding_2 {}; void test_hiding() { struct hiding_1 *hiding_1(); extern struct hiding_2 *hiding_2; struct hiding_1 *p = hiding_1(); struct hiding_2 *q = hiding_2; } struct PreserveAttributes {}; typedef struct __attribute__((noreturn)) PreserveAttributes PreserveAttributes_t; // expected-warning {{'noreturn' attribute only applies to functions and methods}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/decl-type-merging.c
// RUN: %clang_cc1 -fsyntax-only -std=c99 -verify -pedantic %s int x[10]; int x[] = {1,2,3}; int testx[(sizeof(x) == sizeof(int) * 10) ? 1 : -1]; int (*a)(int (*x)[10], int (*y)[]); int (*a)(int (*x)[], int (*y)[5]); void b() { int x[10], y[5]; a(&x, &y); a(&y, &y); // expected-warning {{incompatible pointer}} a(&x, &x); // expected-warning {{incompatible pointer}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/overloaded-func-transparent-union.c
// RUN: %clang_cc1 %s -fsyntax-only -verify // expected-no-diagnostics // rdar:// 9129552 // PR9406 typedef struct { char *str; char *str2; } Class; typedef union { Class *object; } Instance __attribute__((transparent_union)); __attribute__((overloadable)) void Class_Init(Instance this, char *str, void *str2) { this.object->str = str; this.object->str2 = str2; } __attribute__((overloadable)) void Class_Init(Instance this, char *str) { this.object->str = str; this.object->str2 = str; } int main(void) { Class obj; Class_Init(&obj, "Hello ", " World"); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/function-ptr.c
// RUN: %clang_cc1 %s -verify -pedantic typedef int unary_int_func(int arg); unary_int_func *func; unary_int_func *set_func(void *p) { func = p; // expected-warning {{converts between void pointer and function pointer}} p = func; // expected-warning {{converts between void pointer and function pointer}} return p; // expected-warning {{converts between void pointer and function pointer}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/warn-cast-align.c
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -Wcast-align -verify %s // Simple casts. void test0(char *P) { char *a = (char*) P; short *b = (short*) P; // expected-warning {{cast from 'char *' to 'short *' increases required alignment from 1 to 2}} int *c = (int*) P; // expected-warning {{cast from 'char *' to 'int *' increases required alignment from 1 to 4}} } // Casts from void* are a special case. void test1(void *P) { char *a = (char*) P; short *b = (short*) P; int *c = (int*) P; const volatile void *P2 = P; char *d = (char*) P2; short *e = (short*) P2; int *f = (int*) P2; const char *g = (const char*) P2; const short *h = (const short*) P2; const int *i = (const int*) P2; const volatile char *j = (const volatile char*) P2; const volatile short *k = (const volatile short*) P2; const volatile int *l = (const volatile int*) P2; } // Aligned struct. struct __attribute__((aligned(16))) A { char buffer[16]; }; void test2(char *P) { struct A *a = (struct A*) P; // expected-warning {{cast from 'char *' to 'struct A *' increases required alignment from 1 to 16}} } // Incomplete type. void test3(char *P) { struct B *b = (struct B*) P; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/typecheck-binop.c
/* RUN: %clang_cc1 %s -fsyntax-only -pedantic -verify */ struct incomplete; // expected-note{{forward declaration of 'struct incomplete'}} int sub1(int *a, double *b) { return a - b; /* expected-error{{not pointers to compatible types}} */ } void *sub2(struct incomplete *P) { return P-4; /* expected-error{{arithmetic on a pointer to an incomplete type 'struct incomplete'}} */ } void *sub3(void *P) { return P-4; /* expected-warning{{arithmetic on a pointer to void is a GNU extension}} */ } int sub4(void *P, void *Q) { return P-Q; /* expected-warning{{arithmetic on pointers to void is a GNU extension}} */ } int sub5(void *P, int *Q) { return P-Q; /* expected-error{{not pointers to compatible types}} */ } int logicaland1(int a) { return a && (void)a; /* expected-error{{invalid operands}} */ }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/conditional-expr.c
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wsign-conversion %s void foo() { *(0 ? (double *)0 : (void *)0) = 0; // FIXME: GCC doesn't consider the following two statements to be errors. *(0 ? (double *)0 : (void *)(int *)0) = 0; // expected-error {{incomplete type 'void' is not assignable}} *(0 ? (double *)0 : (void *)(double *)0) = 0; // expected-error {{incomplete type 'void' is not assignable}} *(0 ? (double *)0 : (int *)(void *)0) = 0; // expected-error {{incomplete type 'void' is not assignable}} expected-warning {{pointer type mismatch ('double *' and 'int *')}} *(0 ? (double *)0 : (double *)(void *)0) = 0; *((void *) 0) = 0; // expected-error {{incomplete type 'void' is not assignable}} double *dp; int *ip; void *vp; dp = vp; vp = dp; ip = dp; // expected-warning {{incompatible pointer types assigning to 'int *' from 'double *'}} dp = ip; // expected-warning {{incompatible pointer types assigning to 'double *' from 'int *'}} dp = 0 ? (double *)0 : (void *)0; vp = 0 ? (double *)0 : (void *)0; ip = 0 ? (double *)0 : (void *)0; // expected-warning {{incompatible pointer types assigning to 'int *' from 'double *'}} const int *cip; vp = (0 ? vp : cip); // expected-warning {{discards qualifiers}} vp = (0 ? cip : vp); // expected-warning {{discards qualifiers}} int i = 2; int (*pf)[2]; int (*pv)[i]; pf = (i ? pf : pv); enum {xxx,yyy,zzz} e, *ee; short x; ee = ee ? &x : ee ? &i : &e; // expected-warning {{pointer type mismatch}} typedef void *asdf; *(0 ? (asdf) 0 : &x) = 10; unsigned long test0 = 5; test0 = test0 ? (long) test0 : test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}} test0 = test0 ? (int) test0 : test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? (short) test0 : test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}} test0 = test0 ? test0 : (long) test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}} test0 = test0 ? test0 : (int) test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? test0 : (short) test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}} test0 = test0 ? test0 : (long) 10; test0 = test0 ? test0 : (int) 10; test0 = test0 ? test0 : (short) 10; test0 = test0 ? (long) 10 : test0; test0 = test0 ? (int) 10 : test0; test0 = test0 ? (short) 10 : test0; int test1; enum Enum { EVal }; test0 = test0 ? EVal : test0; test1 = test0 ? EVal : (int) test0; test0 = test0 ? (unsigned) EVal : (int) test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? EVal : test1; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? test1 : EVal; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} const int *const_int; int *nonconst_int; *(test0 ? const_int : nonconst_int) = 42; // expected-error {{read-only variable is not assignable}} *(test0 ? nonconst_int : const_int) = 42; // expected-error {{read-only variable is not assignable}} // The composite type here should be "int (*)[12]", fine for the sizeof int (*incomplete)[]; int (*complete)[12]; sizeof(*(test0 ? incomplete : complete)); // expected-warning {{expression result unused}} sizeof(*(test0 ? complete : incomplete)); // expected-warning {{expression result unused}} int __attribute__((address_space(2))) *adr2; int __attribute__((address_space(3))) *adr3; test0 ? adr2 : adr3; // expected-warning {{pointer type mismatch}} expected-warning {{expression result unused}} // Make sure address-space mask ends up in the result type (test0 ? (test0 ? adr2 : adr2) : nonconst_int); // expected-warning {{pointer type mismatch}} expected-warning {{expression result unused}} } int Postgresql() { char x; return ((((&x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}} } #define nil ((void*) 0) extern int f1(void); int f0(int a) { // GCC considers this a warning. return a ? f1() : nil; // expected-warning {{pointer/integer type mismatch in conditional expression ('int' and 'void *')}} expected-warning {{incompatible pointer to integer conversion returning 'void *' from a function with result type 'int'}} } int f2(int x) { // We can suppress this because the immediate context wants an int. return (x != 0) ? 0U : x; } #define NULL (void*)0 void PR9236() { struct A {int i;} A1; (void)(1 ? A1 : NULL); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}} (void)(1 ? NULL : A1); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}} (void)(1 ? 0 : A1); // expected-error{{incompatible operand types}} (void)(1 ? (void*)0 : A1); // expected-error{{incompatible operand types}} (void)(1 ? A1: (void*)0); // expected-error{{incompatible operand types}} (void)(1 ? A1 : (NULL)); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/attr-endian.c
// RUN: %clang_cc1 %s -verify -fsyntax-only int p1 __attribute__((endian(host))); // expected-warning {{unknown attribute 'endian' ignored}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/c89.c
/* RUN: %clang_cc1 %s -std=c89 -pedantic -fsyntax-only -verify -Wimplicit-function-declaration */ void test1() { { int i; i = i + 1; int j; /* expected-warning {{mixing declarations and code}} */ } { __extension__ int i; i = i + 1; int j; /* expected-warning {{mixing declarations and code}} */ } { int i; i = i + 1; __extension__ int j; /* expected-warning {{mixing declarations and code}} */ } } long long test2; /* expected-warning {{extension}} */ void test3(int i) { int A[i]; /* expected-warning {{variable length array}} */ } int test4 = 0LL; /* expected-warning {{long long}} */ /* PR1999 */ void test5(register); /* PR2041 */ int *restrict; int *__restrict; /* expected-error {{expected identifier}} */ /* Implicit int, always ok */ test6() { return 0; } /* PR2012 */ test7; /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */ void test8(int, x); /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */ typedef int sometype; int a(sometype, y) {return 0;} /* expected-warning {{declaration specifier missing, defaulting to 'int'}} \ expected-error {{parameter name omitted}}*/ void bar (void *); void f11 (z) /* expected-error {{may not have 'void' type}} */ void z; { bar (&z); } typedef void T; void foo(T); /* typedef for void is allowed */ void foo(void) {} /* PR2759 */ void test10 (int x[*]); /* expected-warning {{variable length arrays are a C99 feature}} */ void test11 (int x[static 4]); /* expected-warning {{static array size is a C99 feature}} */ void test12 (int x[const 4]) { /* expected-warning {{qualifier in array size is a C99 feature}} */ int Y[x[1]]; /* expected-warning {{variable length arrays are a C99 feature}} */ } /* PR4074 */ struct test13 { int X[23]; } test13a(); void test13b() { int a = test13a().X[1]; /* expected-warning {{ISO C90 does not allow subscripting non-lvalue array}} */ int b = 1[test13a().X]; /* expected-warning {{ISO C90 does not allow subscripting non-lvalue array}} */ } /* Make sure we allow *test14 as a "function designator" */ int test14() { return (&*test14)(); } int test15[5] = { [2] = 1 }; /* expected-warning {{designated initializers are a C99 feature}} */ extern int printf(__const char *__restrict __format, ...); /* Warn, but don't suggest typo correction. */ void test16() { printg("Hello, world!\n"); /* expected-warning {{implicit declaration of function 'printg'}} */ } struct x { int x,y[]; }; /* expected-warning {{flexible array members are a C99 feature}} */ /* Duplicated type-qualifiers aren't allowed by C90 */ const const int c_i; /* expected-warning {{duplicate 'const' declaration specifier}} */ typedef volatile int vol_int; volatile vol_int volvol_i; /* expected-warning {{duplicate 'volatile' declaration specifier}} */ typedef volatile vol_int volvol_int; /* expected-warning {{duplicate 'volatile' declaration specifier}} */ const int * const c; typedef const int CI; const CI mine1[5][5]; /* expected-warning {{duplicate 'const' declaration specifier}} */ typedef CI array_of_CI[5]; const array_of_CI mine2; /* expected-warning {{duplicate 'const' declaration specifier}} */ typedef CI *array_of_pointer_to_CI[5]; const array_of_pointer_to_CI mine3; void main() {} /* expected-error {{'main' must return 'int'}} */ const int main() {} /* expected-error {{'main' must return 'int'}} */ long long ll1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */ -42LL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */ unsigned long long ull1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */ 42ULL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */ struct Test17 { int a; }; struct Test17 test17_aux(void); void test17(int v, int w) { int a[2] = { v, w }; /* expected-warning {{initializer for aggregate is not a compile-time constant}} */ struct Test17 t0 = { v }; /* expected-warning {{initializer for aggregate is not a compile-time constant}} */ struct Test17 t1 = test17_aux(); /* this is allowed */ }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/attr-alias.c
// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify %s void g() {} // It is important that the following string be in the error message. The gcc // testsuite looks for it to decide if a target supports aliases. void f() __attribute__((alias("g"))); //expected-error {{only weak aliases are supported}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/unused-expr-system-header.c
// RUN: %clang_cc1 -isystem %S/Inputs -fsyntax-only -verify %s #include <unused-expr-system-header.h> void f(int i1, int i2) { POSSIBLY_BAD_MACRO(5); STATEMENT_EXPR_MACRO(5); COMMA_MACRO_1(i1 == i2, f(i1, i2)); // expected-warning {{comparison result unused}} \ // expected-note {{equality comparison}} COMMA_MACRO_2(i1 == i2, f(i1, i2)); COMMA_MACRO_3(i1 == i2, f(i1, i2)); // expected-warning {{comparison result unused}} \ // expected-note {{equality comparison}} COMMA_MACRO_4(i1 == i2, f(i1, i2)); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/switch-1.c
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin10 %s // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 %s // rdar://11577384 // rdar://13423975 int f(int i) { switch (i) { case 2147483647 + 2: // expected-warning {{overflow in expression; result is -2147483647 with type 'int'}} return 1; case 9223372036854775807L * 4: // expected-warning {{overflow in expression; result is -4 with type 'long'}} return 2; case (123456 *789012) + 1: // expected-warning {{overflow in expression; result is -1375982336 with type 'int'}} return 3; case (2147483647*4)/4: // expected-warning {{overflow in expression; result is -4 with type 'int'}} case (2147483647*4)%4: // expected-warning {{overflow in expression; result is -4 with type 'int'}} return 4; case 2147483647: return 0; } return (i, 65537) * 65537; // expected-warning {{overflow in expression; result is 131073 with type 'int'}} \ // expected-warning {{expression result unused}} } // rdar://18405357 unsigned long long l = 65536 * 65536; // expected-warning {{overflow in expression; result is 0 with type 'int'}} unsigned long long l2 = 65536 * (unsigned)65536; unsigned long long l3 = 65536 * 65536ULL;
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/warn-variable-not-needed.c
// RUN: %clang_cc1 -fsyntax-only -verify -Wall %s // expected-no-diagnostics static int a; int bar() { extern int a; return a; } static int a;
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/warn-unused-parameters.c
// RUN: %clang_cc1 -fblocks -fsyntax-only -Wunused-parameter %s 2>&1 | FileCheck %s // RUN: %clang_cc1 -fblocks -fsyntax-only -Wunused %s 2>&1 | FileCheck -check-prefix=CHECK-unused %s int f0(int x, int y, int z __attribute__((unused))) { return x; } void f1() { (void)^(int x, int y, int z __attribute__((unused))) { return x; }; } // Used when testing '-Wunused' to see that we only emit one diagnostic, and no // warnings for the above cases. static void achor() {}; // CHECK: 5:12: warning: unused parameter 'y' // CHECK: 12:15: warning: unused parameter 'y' // CHECK-unused: 1 warning generated // RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything %s 2>&1 | FileCheck -check-prefix=CHECK-everything %s // RUN: not %clang_cc1 -fblocks -fsyntax-only -Weverything -Werror %s 2>&1 | FileCheck -check-prefix=CHECK-everything-error %s // RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything -Wno-unused %s 2>&1 | FileCheck -check-prefix=CHECK-everything-no-unused %s // CHECK-everything: 6 warnings generated // CHECK-everything-error: 5 errors generated // CHECK-everything-no-unused: 5 warnings generated
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/typedef-redef.c
// RUN: %clang_cc1 -fsyntax-only -verify %s typedef const int x; // expected-note {{previous definition is here}} extern x a; typedef int x; // expected-error {{typedef redefinition with different types}} extern x a; // <rdar://problem/6097585> int y; // expected-note 2 {{previous definition is here}} float y; // expected-error{{redefinition of 'y' with a different type}} double y; // expected-error{{redefinition of 'y' with a different type}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/constant-builtins.c
// RUN: %clang_cc1 -fsyntax-only %s -verify -pedantic // expected-no-diagnostics // Math stuff float g0 = __builtin_huge_val(); double g1 = __builtin_huge_valf(); long double g2 = __builtin_huge_vall(); float g3 = __builtin_inf(); double g4 = __builtin_inff(); long double g5 = __builtin_infl(); // GCC misc stuff extern int f(); int h0 = __builtin_types_compatible_p(int,float); //int h1 = __builtin_choose_expr(1, 10, f()); //int h2 = __builtin_expect(0, 0); int h3 = __builtin_bswap16(0x1234) == 0x3412 ? 1 : f(); int h4 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f(); int h5 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f(); short somefunc(); short t = __builtin_constant_p(5353) ? 42 : somefunc();
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/return-noreturn.c
// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wmissing-noreturn -Wno-unreachable-code int j; void test1() { // expected-warning {{function 'test1' could be declared with attribute 'noreturn'}} ^ (void) { while (1) { } }(); ^ (void) { if (j) while (1) { } }(); while (1) { } } void test2() { if (j) while (1) { } } __attribute__((__noreturn__)) void test2_positive() { if (j) while (1) { } } // expected-warning{{function declared 'noreturn' should not return}} // This test case illustrates that we don't warn about the missing return // because the function is marked noreturn and there is an infinite loop. extern int foo_test_3(); __attribute__((__noreturn__)) void* test3(int arg) { while (1) foo_test_3(); } __attribute__((__noreturn__)) void* test3_positive(int arg) { while (0) foo_test_3(); } // expected-warning{{function declared 'noreturn' should not return}} // PR5298 - -Wmissing-noreturn shouldn't warn if the function is already // declared noreturn. void __attribute__((noreturn)) test4() { test2_positive(); } // Do not warn here. _Noreturn void test5() { test2_positive(); } // rdar://16274746 void test6() { (void)^{ for(;;) ; }; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/asm.c
// RUN: %clang_cc1 %s -Wno-private-extern -triple i386-pc-linux-gnu -verify -fsyntax-only void f() { int i; asm ("foo\n" : : "a" (i + 2)); asm ("foo\n" : : "a" (f())); // expected-error {{invalid type 'void' in asm input}} asm ("foo\n" : "=a" (f())); // expected-error {{invalid lvalue in asm output}} asm ("foo\n" : "=a" (i + 2)); // expected-error {{invalid lvalue in asm output}} asm ("foo\n" : [symbolic_name] "=a" (i) : "[symbolic_name]" (i)); asm ("foo\n" : "=a" (i) : "[" (i)); // expected-error {{invalid input constraint '[' in asm}} asm ("foo\n" : "=a" (i) : "[foo" (i)); // expected-error {{invalid input constraint '[foo' in asm}} asm ("foo\n" : "=a" (i) : "[symbolic_name]" (i)); // expected-error {{invalid input constraint '[symbolic_name]' in asm}} asm ("foo\n" : : "" (i)); // expected-error {{invalid input constraint '' in asm}} asm ("foo\n" : "=a" (i) : "" (i)); // expected-error {{invalid input constraint '' in asm}} } void clobbers() { asm ("nop" : : : "ax", "#ax", "%ax"); asm ("nop" : : : "eax", "rax", "ah", "al"); 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" : : : "-1"); // expected-error {{unknown register name '-1' in asm}} asm ("nop" : : : "+1"); // expected-error {{unknown register name '+1' in asm}} } // rdar://6094010 void test3() { int x; asm(L"foo" : "=r"(x)); // expected-error {{wide string}} asm("foo" : L"=r"(x)); // expected-error {{wide string}} } // <rdar://problem/6156893> void test4(const volatile void *addr) { asm ("nop" : : "r"(*addr)); // expected-error {{invalid type 'const volatile void' in asm input for constraint 'r'}} asm ("nop" : : "m"(*addr)); asm ("nop" : : "r"(test4(addr))); // expected-error {{invalid type 'void' in asm input for constraint 'r'}} asm ("nop" : : "m"(test4(addr))); // expected-error {{invalid lvalue in asm input for constraint 'm'}} asm ("nop" : : "m"(f())); // expected-error {{invalid lvalue in asm input for constraint 'm'}} } // <rdar://problem/6512595> void test5() { asm("nop" : : "X" (8)); } // PR3385 void test6(long i) { asm("nop" : : "er"(i)); } void asm_string_tests(int i) { asm("%!"); // simple asm string, %! is not an error. asm("%!" : ); // expected-error {{invalid % escape in inline assembly string}} asm("xyz %" : ); // expected-error {{invalid % escape in inline assembly string}} asm ("%[somename]" :: [somename] "i"(4)); // ok asm ("%[somename]" :: "i"(4)); // expected-error {{unknown symbolic operand name in inline assembly string}} asm ("%[somename" :: "i"(4)); // expected-error {{unterminated symbolic operand name in inline assembly string}} asm ("%[]" :: "i"(4)); // expected-error {{empty symbolic operand name in inline assembly string}} // PR3258 asm("%9" :: "i"(4)); // expected-error {{invalid operand number in inline asm string}} asm("%1" : "+r"(i)); // ok, referring to input. } // PR4077 int test7(unsigned long long b) { int a; asm volatile("foo %0 %1" : "=a" (a) :"0" (b)); // expected-error {{input with type 'unsigned long long' matching output with type 'int'}} return a; } // <rdar://problem/7574870> asm volatile (""); // expected-warning {{meaningless 'volatile' on asm outside function}} // PR3904 void test8(int i) { // A number in an input constraint can't point to a read-write constraint. asm("" : "+r" (i), "=r"(i) : "0" (i)); // expected-error{{invalid input constraint '0' in asm}} } // PR3905 void test9(int i) { asm("" : [foo] "=r" (i), "=r"(i) : "1[foo]"(i)); // expected-error{{invalid input constraint '1[foo]' in asm}} asm("" : [foo] "=r" (i), "=r"(i) : "[foo]1"(i)); // expected-error{{invalid input constraint '[foo]1' in asm}} } void test10(void){ static int g asm ("g_asm") = 0; extern int gg asm ("gg_asm"); __private_extern__ int ggg asm ("ggg_asm"); int a asm ("a_asm"); // expected-warning{{ignored asm label 'a_asm' on automatic variable}} auto int aa asm ("aa_asm"); // expected-warning{{ignored asm label 'aa_asm' on automatic variable}} register int r asm ("cx"); register int rr asm ("rr_asm"); // expected-error{{unknown register name 'rr_asm' in asm}} register int rrr asm ("%"); // expected-error{{unknown register name '%' in asm}} } // This is just an assert because of the boolean conversion. // Feel free to change the assembly to something sensible if it causes a problem. // rdar://problem/9414925 void test11(void) { _Bool b; asm volatile ("movb %%gs:%P2,%b0" : "=q"(b) : "0"(0), "i"(5L)); } void test12(void) { register int cc __asm ("cc"); // expected-error{{unknown register name 'cc' in asm}} } // PR10223 void test13(void) { void *esp; __asm__ volatile ("mov %%esp, %o" : "=r"(esp) : : ); // expected-error {{invalid % escape in inline assembly string}} } // <rdar://problem/12700799> struct S; // expected-note 2 {{forward declaration of 'struct S'}} void test14(struct S *s) { __asm("": : "a"(*s)); // expected-error {{dereference of pointer to incomplete type 'struct S'}} __asm("": "=a" (*s) :); // expected-error {{dereference of pointer to incomplete type 'struct S'}} } // PR15759. double test15() { double ret = 0; __asm("0.0":"="(ret)); // expected-error {{invalid output constraint '=' in asm}} __asm("0.0":"=&"(ret)); // expected-error {{invalid output constraint '=&' in asm}} __asm("0.0":"+?"(ret)); // expected-error {{invalid output constraint '+?' in asm}} __asm("0.0":"+!"(ret)); // expected-error {{invalid output constraint '+!' in asm}} __asm("0.0":"+#"(ret)); // expected-error {{invalid output constraint '+#' in asm}} __asm("0.0":"+*"(ret)); // expected-error {{invalid output constraint '+*' in asm}} __asm("0.0":"=%"(ret)); // expected-error {{invalid output constraint '=%' in asm}} __asm("0.0":"=,="(ret)); // expected-error {{invalid output constraint '=,=' in asm}} __asm("0.0":"=,g"(ret)); // no-error __asm("0.0":"=g"(ret)); // no-error return ret; } // PR19837 struct foo { int a; char b; }; register struct foo bar asm("sp"); // expected-error {{bad type for named register variable}} register float baz asm("sp"); // expected-error {{bad type for named register variable}} double f_output_constraint(void) { double result; __asm("foo1": "=f" (result)); // expected-error {{invalid output constraint '=f' in asm}} return result; } void fn1() { int l; __asm__("" : [l] "=r"(l) : "[l],m"(l)); // expected-error {{asm constraint has an unexpected number of alternatives: 1 vs 2}} } void fn2() { int l; __asm__("" : "+&m"(l)); // expected-error {{invalid output constraint '+&m' in asm}} } void fn3() { int l; __asm__("" : "+#r"(l)); // expected-error {{invalid output constraint '+#r' in asm}} } void fn4() { int l; __asm__("" : "=r"(l) : "m#"(l)); } void fn5() { int l; __asm__("" : [g] "+r"(l) : "[g]"(l)); // expected-error {{invalid input constraint '[g]' in asm}} } void fn6() { int a; __asm__("" : "=rm"(a), "=rm"(a) : "11m"(a)) // expected-error {{invalid input constraint '11m' in asm}} } // PR14269 typedef struct test16_foo { unsigned int field1 : 1; unsigned int field2 : 2; unsigned int field3 : 3; } test16_foo; test16_foo x; void test16() { __asm__("movl $5, %0" : "=rm" (x.field2)); // expected-error {{reference to a bit-field in asm output with a memory constraint '=rm'}} __asm__("movl $5, %0" : : "m" (x.field3)); // expected-error {{reference to a bit-field in asm input with a memory constraint 'm'}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/merge-decls.c
// RUN: %clang_cc1 %s -verify -fsyntax-only void foo(void); void foo(void) {} void foo(void); void foo(void); // expected-note {{previous declaration is here}} void foo(int); // expected-error {{conflicting types for 'foo'}} int funcdef() { return 0; } int funcdef(); int funcdef2() { return 0; } // expected-note {{previous definition is here}} int funcdef2() { return 0; } // expected-error {{redefinition of 'funcdef2'}} // PR2502 void (*f)(void); void (*f)() = 0; typedef __attribute__(( ext_vector_type(2) )) int Vi2; typedef __attribute__(( ext_vector_type(2) )) float Vf2; Vf2 g0; // expected-note {{previous definition is here}} Vi2 g0; // expected-error {{redefinition of 'g0'}} _Complex int g1; // expected-note {{previous definition is here}} _Complex float g1; // expected-error {{redefinition of 'g1'}} // rdar://6096412 extern char i6096412[10]; extern char i6096412[]; void foo6096412(void) { int x = sizeof(i6096412); } typedef int test1_IA[]; typedef int test1_A10[10]; static test1_A10 *test1_f(void); void test1_g(void) { { extern test1_IA *test1_f(void); } (void)sizeof(*test1_f()); } typedef int test2_IA[]; typedef int test2_A10[10]; static test2_A10 *test2_f(void); static test2_IA *test2_f(void); void test2_g(void) { (void)sizeof(*test2_f()); } int (*test3_f())[10]; int (*test3_f())[]; int test3_k = sizeof(*test3_f()); void test4_f(int); void test4_f(a) char a; { int v[sizeof(a) == 1 ? 1 : -1]; } int test5_f(int (*)[10]); int test5_f(int (*x)[]) { return sizeof(*x); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}} } void test6_f(int (*a)[11]); void test6_f(a) int (*a)[]; {} void test6_g() { int arr[10]; test6_f(&arr); // expected-warning {{incompatible pointer types passing 'int (*)[10]' to parameter of type 'int (*)[11]}} } void test7_f(int (*)[10]); void test7_f(int (*)[]); // expected-note {{passing argument to parameter here}} void test7_g() { int x[5]; test7_f(&x); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[10]}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/typedef-prototype.c
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics typedef int unary_int_func(int arg); unary_int_func add_one; int add_one(int arg) { return arg + 1; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/no-documentation-warn-tagdecl-specifier.c
// RUN: %clang_cc1 -fsyntax-only -Wdocumentation -verify %s // rdar://12390371 /** @return s Test*/ struct s* f(void); struct s; struct s1; /** @return s1 Test 1*/ struct s1* f1(void); struct s2; /** @return s2 Test 2*/ struct s2* f2(void); struct s2; // expected-warning@+1 {{'@return' command used in a comment that is not attached to a function or method declaration}} /** @return s3 Test 3 - expected warning here */ struct s3; struct s3* f3(void); /** @return s4 Test 4 */ struct s4* f4(void); struct s4 { int is; }; // expected-warning@+1 {{'@return' command used in a comment that is not attached to a function or method declaration}} /** @return s5 Test 5 - expected warning here */ struct s5 { int is; }; struct s5* f5(void); // expected-warning@+1 {{'@return' command used in a comment that is not attached to a function or method declaration}} /** @return s6 Test 6 - expected warning here */ struct s6 *ps6; struct s6* f6(void); // expected-warning@+1 {{'@return' command used in a comment that is not attached to a function or method declaration}} /** @return s7 Test 7 - expected warning here */ struct s7; struct s7* f7(void); struct s8 { int is8; }; /** @return s8 Test 8 */ struct s4 *f8(struct s8 *p); /** @return e Test*/ enum e* g(void); enum e; enum e1; /** @return e1 Test 1*/ enum e1* g1(void); enum e2; /** @return e2 Test 2*/ enum e2* g2(void); enum e2; // expected-warning@+1 {{'@return' command used in a comment that is not attached to a function or method declaration}} /** @return e3 Test 3 - expected warning here */ enum e3; enum e3* g3(void); /** @return e4 Test 4 */ enum e4* g4(void); enum e4 { one }; // expected-warning@+1 {{'@return' command used in a comment that is not attached to a function or method declaration}} /** @return e5 Test 5 - expected warning here */ enum e5 { two }; enum e5* g5(void); // expected-warning@+1 {{'@return' command used in a comment that is not attached to a function or method declaration}} /** @return e6 Test 6 - expected warning here */ enum e6 *pe6; enum e6* g6(void); // expected-warning@+1 {{'@return' command used in a comment that is not attached to a function or method declaration}} /** @return e7 Test 7 - expected warning here */ enum e7; enum e7* g7(void); enum e8 { three }; /** @return e8 Test 8 */ enum e4 *g8(enum e8 *p);
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/string-plus-char.c
// RUN: %clang_cc1 -fsyntax-only -verify %s struct AB{const char *a; const char*b;}; const char *foo(const struct AB *ab) { return ab->a + 'b'; // expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}} } void f(const char *s) { char *str = 0; char *str2 = str + 'c'; // expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}} const char *constStr = s + 'c'; // expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}} str = 'c' + str;// expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}} char strArr[] = "foo"; str = strArr + 'c'; // expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}} char *strArr2[] = {"ac","dc"}; str = strArr2[0] + 'c'; // expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}} struct AB ab; constStr = foo(&ab) + 'c'; // expected-warning {{adding 'char' to a string pointer does not append to the string}} expected-note {{use array indexing to silence this warning}} // no-warning char c = 'c'; str = str + c; str = c + str; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/PR2923.c
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics // Test for absence of crash reported in PR 2923: // // http://llvm.org/bugs/show_bug.cgi?id=2923 // // Previously we had a crash when deallocating the FunctionDecl for 'bar' // because FunctionDecl::getNumParams() just used the type of foo to determine // the number of parameters it has. In the case of 'bar' there are no // ParmVarDecls. int foo(int x, int y) { return x + y; } extern typeof(foo) bar;
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/pointer-addition.c
// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -std=c11 typedef struct S S; // expected-note 4 {{forward declaration of 'struct S'}} extern _Atomic(S*) e; void a(S* b, void* c) { void (*fp)(int) = 0; b++; // expected-error {{arithmetic on a pointer to an incomplete type}} b += 1; // expected-error {{arithmetic on a pointer to an incomplete type}} c++; // expected-warning {{arithmetic on a pointer to void is a GNU extension}} c += 1; // expected-warning {{arithmetic on a pointer to void is a GNU extension}} c--; // expected-warning {{arithmetic on a pointer to void is a GNU extension}} c -= 1; // expected-warning {{arithmetic on a pointer to void is a GNU extension}} (void) c[1]; // expected-warning {{subscript of a pointer to void is a GNU extension}} b = 1+b; // expected-error {{arithmetic on a pointer to an incomplete type}} /* The next couple tests are only pedantic warnings in gcc */ void (*d)(S*,void*) = a; d += 1; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} d++; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} d--; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} d -= 1; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} (void)(1 + d); // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} e++; // expected-error {{arithmetic on a pointer to an incomplete type}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/default1.c
// RUN: %clang_cc1 -fsyntax-only -verify %s void f(int i = 0); // expected-error {{C does not support default arguments}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/builtin-cpu-supports.c
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-pc-linux-gnu -verify %s // RUN: %clang_cc1 -fsyntax-only -triple powerpc64le-linux-gnu -verify %s extern void a(const char *); extern const char *str; int main() { #ifdef __x86_64__ if (__builtin_cpu_supports("ss")) // expected-error {{invalid cpu feature string}} a("sse4.2"); if (__builtin_cpu_supports(str)) // expected-error {{expression is not a string literal}} a(str); #else if (__builtin_cpu_supports("vsx")) // expected-error {{use of unknown builtin}} a("vsx"); #endif return 0; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/static-assert.c
// RUN: %clang_cc1 -std=c11 -fsyntax-only -verify %s // RUN: %clang_cc1 -xc++ -std=c++11 -fsyntax-only -verify %s _Static_assert("foo", "string is nonzero"); #ifndef __cplusplus // expected-error@-2 {{static_assert expression is not an integral constant expression}} #endif _Static_assert(1, "1 is nonzero"); _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} void foo(void) { _Static_assert(1, "1 is nonzero"); _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} } _Static_assert(1, invalid); // expected-error {{expected string literal for diagnostic message in static_assert}} struct A { int a; _Static_assert(1, "1 is nonzero"); _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} }; #ifdef __cplusplus #define ASSERT_IS_TYPE(T) __is_same(T, T) #else #define ASSERT_IS_TYPE(T) __builtin_types_compatible_p(T, T) #endif #define UNION(T1, T2) union { \ __typeof__(T1) one; \ __typeof__(T2) two; \ _Static_assert(ASSERT_IS_TYPE(T1), "T1 is not a type"); \ _Static_assert(ASSERT_IS_TYPE(T2), "T2 is not a type"); \ _Static_assert(sizeof(T1) == sizeof(T2), "type size mismatch"); \ } typedef UNION(unsigned, struct A) U1; UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; typedef UNION(char, short) U3; // expected-error {{static_assert failed "type size mismatch"}} typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/pragma-pack-and-options-align.c
// RUN: %clang_cc1 -triple i686-apple-darwin9 %s -fsyntax-only -verify // Check that #pragma pack and #pragma options share the same stack. #pragma pack(push, 1) struct s0 { char c; int x; }; extern int a[sizeof(struct s0) == 5 ? 1 : -1]; #pragma options align=natural struct s1 { char c; int x; }; extern int a[sizeof(struct s1) == 8 ? 1 : -1]; #pragma options align=reset #pragma options align=native struct s1_1 { char c; int x; }; extern int a[sizeof(struct s1_1) == 8 ? 1 : -1]; #pragma pack(pop) struct s2 { char c; int x; }; extern int a[sizeof(struct s2) == 5 ? 1 : -1]; #pragma pack(pop) struct s3 { char c; int x; }; extern int a[sizeof(struct s3) == 8 ? 1 : -1]; #pragma pack(push,2) #pragma options align=power struct s4 { char c; int x; }; #pragma pack(pop) #pragma options align=reset extern int a[sizeof(struct s4) == 8 ? 1 : -1]; /* expected-warning {{#pragma options align=reset failed: stack empty}} */ #pragma options align=reset /* expected-warning {{#pragma pack(pop, ...) failed: stack empty}} */ #pragma pack(pop)
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/format-strings-size_t.c
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s int printf(char const *, ...); void test(void) { // size_t printf("%zu", (double)42); // expected-warning {{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'double'}} // intmax_t / uintmax_t printf("%jd", (double)42); // expected-warning {{format specifies type 'intmax_t' (aka 'long') but the argument has type 'double'}} printf("%ju", (double)42); // expected-warning {{format specifies type 'uintmax_t' (aka 'unsigned long') but the argument has type 'double'}} // ptrdiff_t printf("%td", (double)42); // expected-warning {{format specifies type 'ptrdiff_t' (aka 'long') but the argument has type 'double'}} } void test_writeback(void) { printf("%jn", (long*)0); // no-warning printf("%jn", (unsigned long*)0); // no-warning printf("%jn", (int*)0); // expected-warning{{format specifies type 'intmax_t *' (aka 'long *') but the argument has type 'int *'}} printf("%zn", (long*)0); // no-warning // FIXME: Warn about %zn with non-ssize_t argument. printf("%tn", (long*)0); // no-warning printf("%tn", (unsigned long*)0); // no-warning printf("%tn", (int*)0); // expected-warning{{format specifies type 'ptrdiff_t *' (aka 'long *') but the argument has type 'int *'}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/builtins-aarch64.c
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -fsyntax-only -verify %s // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -DTEST1 -fsyntax-only -verify %s // RUN: %clang_cc1 -triple arm64-none-linux-gnu -fsyntax-only -verify %s // RUN: %clang_cc1 -triple arm64-none-linux-gnu -DTEST1 -fsyntax-only -verify %s #ifdef TEST1 void __clear_cache(void *start, void *end); #endif void test_clear_cache_chars(char *start, char *end) { __clear_cache(start, end); } void test_clear_cache_voids(void *start, void *end) { __clear_cache(start, end); } void test_clear_cache_no_args() { // AArch32 version of this is variadic (at least syntactically). // However, on AArch64 GCC does not permit this call and the // implementation I've seen would go disastrously wrong. __clear_cache(); // expected-error {{too few arguments to function call}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/warn-char-subscripts.c
// RUN: %clang_cc1 -Wchar-subscripts -fsyntax-only -verify %s void t1() { int array[1] = { 0 }; char subscript = 0; int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}} } void t2() { int array[1] = { 0 }; char subscript = 0; int val = subscript[array]; // expected-warning{{array subscript is of type 'char'}} } void t3() { int *array = 0; char subscript = 0; int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}} } void t4() { int *array = 0; char subscript = 0; int val = subscript[array]; // expected-warning{{array subscript is of type 'char'}} } char returnsChar(); void t5() { int *array = 0; int val = array[returnsChar()]; // expected-warning{{array subscript is of type 'char'}} } void t6() { int array[1] = { 0 }; signed char subscript = 0; int val = array[subscript]; // no warning for explicit signed char } void t7() { int array[1] = { 0 }; unsigned char subscript = 0; int val = array[subscript]; // no warning for unsigned char } typedef char CharTy; void t8() { int array[1] = { 0 }; CharTy subscript = 0; int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}} } typedef signed char SignedCharTy; void t9() { int array[1] = { 0 }; SignedCharTy subscript = 0; int val = array[subscript]; // no warning for explicit signed char } typedef unsigned char UnsignedCharTy; void t10() { int array[1] = { 0 }; UnsignedCharTy subscript = 0; int val = array[subscript]; // no warning for unsigned char }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/attr-args.c
// RUN: %clang_cc1 -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -fsyntax-only %s int a; inline __attribute__((noreturn(a))) void *f1(); // expected-error {{'noreturn' attribute takes no arguments}} inline __attribute__((always_inline(a))) void *f2(); // expected-error {{'always_inline' attribute takes no arguments}} inline __attribute__((cdecl(a))) void *f3(); // expected-error {{'cdecl' attribute takes no arguments}} inline __attribute__((const(a))) void *f4(); // expected-error {{'const' attribute takes no arguments}} inline __attribute__((fastcall(a))) void *f5(); // expected-error {{'fastcall' attribute takes no arguments}} inline __attribute__((malloc(a))) void *f5(); // expected-error {{'malloc' attribute takes no arguments}} inline __attribute__((nothrow(a))) void *f7(); // expected-error {{'nothrow' attribute takes no arguments}} inline __attribute__((stdcall(a))) void *f8(); // expected-error {{'stdcall' attribute takes no arguments}} inline __attribute__((used(a))) void *f9(); // expected-error {{'used' attribute takes no arguments}} inline __attribute__((unused(a))) void *f10(); // expected-error {{'unused' attribute takes no arguments}} inline __attribute__((weak(a))) void *f11(); // expected-error {{'weak' attribute takes no arguments}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/struct-packed-align.c
// RUN: %clang_cc1 %s -fsyntax-only -verify // expected-no-diagnostics // Packed structs. struct s { char a; int b __attribute__((packed)); char c; int d; }; extern int a1[sizeof(struct s) == 12 ? 1 : -1]; extern int a2[__alignof(struct s) == 4 ? 1 : -1]; struct __attribute__((packed)) packed_s { char a; int b __attribute__((packed)); char c; int d; }; extern int b1[sizeof(struct packed_s) == 10 ? 1 : -1]; extern int b2[__alignof(struct packed_s) == 1 ? 1 : -1]; struct fas { char a; int b[]; }; extern int c1[sizeof(struct fas) == 4 ? 1 : -1]; extern int c2[__alignof(struct fas) == 4 ? 1 : -1]; struct __attribute__((packed)) packed_fas { char a; int b[]; }; extern int d1[sizeof(struct packed_fas) == 1 ? 1 : -1]; extern int d2[__alignof(struct packed_fas) == 1 ? 1 : -1]; struct packed_after_fas { char a; int b[]; } __attribute__((packed)); extern int d1_2[sizeof(struct packed_after_fas) == 1 ? 1 : -1]; extern int d2_2[__alignof(struct packed_after_fas) == 1 ? 1 : -1]; // Alignment struct __attribute__((aligned(8))) as1 { char c; }; extern int e1[sizeof(struct as1) == 8 ? 1 : -1]; extern int e2[__alignof(struct as1) == 8 ? 1 : -1]; struct __attribute__((aligned)) as1_2 { char c; }; #ifdef __s390x__ extern int e1_2[sizeof(struct as1_2) == 8 ? 1 : -1]; extern int e2_2[__alignof(struct as1_2) == 8 ? 1 : -1]; #else extern int e1_2[sizeof(struct as1_2) == 16 ? 1 : -1]; extern int e2_2[__alignof(struct as1_2) == 16 ? 1 : -1]; #endif struct as2 { char c; int __attribute__((aligned(8))) a; }; extern int f1[sizeof(struct as2) == 16 ? 1 : -1]; extern int f2[__alignof(struct as2) == 8 ? 1 : -1]; struct __attribute__((packed)) as3 { char c; int a; int __attribute__((aligned(8))) b; }; extern int g1[sizeof(struct as3) == 16 ? 1 : -1]; extern int g2[__alignof(struct as3) == 8 ? 1 : -1]; // rdar://5921025 struct packedtest { int ted_likes_cheese; void *args[] __attribute__((packed)); }; // Packed union union __attribute__((packed)) au4 {char c; int x;}; extern int h1[sizeof(union au4) == 4 ? 1 : -1]; extern int h2[__alignof(union au4) == 1 ? 1 : -1]; // Aligned union union au5 {__attribute__((aligned(4))) char c;}; extern int h1[sizeof(union au5) == 4 ? 1 : -1]; extern int h2[__alignof(union au5) == 4 ? 1 : -1]; // Alignment+packed struct as6 {char c; __attribute__((packed, aligned(2))) int x;}; extern int i1[sizeof(struct as6) == 6 ? 1 : -1]; extern int i2[__alignof(struct as6) == 2 ? 1 : -1]; union au6 {char c; __attribute__((packed, aligned(2))) int x;}; extern int k1[sizeof(union au6) == 4 ? 1 : -1]; extern int k2[__alignof(union au6) == 2 ? 1 : -1]; // Check postfix attributes union au7 {char c; int x;} __attribute__((packed)); extern int l1[sizeof(union au7) == 4 ? 1 : -1]; extern int l2[__alignof(union au7) == 1 ? 1 : -1]; struct packed_fas2 { char a; int b[]; } __attribute__((packed)); extern int m1[sizeof(struct packed_fas2) == 1 ? 1 : -1]; extern int m2[__alignof(struct packed_fas2) == 1 ? 1 : -1]; // Attribute aligned can round down typedefs. PR9253 typedef long long __attribute__((aligned(1))) nt; struct nS { char buf_nr; nt start_lba; }; #if defined(_WIN32) && !defined(__declspec) // _MSC_VER is unavailable in cc1. // Alignment doesn't affect packing in MS mode. extern int n1[sizeof(struct nS) == 16 ? 1 : -1]; extern int n2[__alignof(struct nS) == 8 ? 1 : -1]; #else extern int n1[sizeof(struct nS) == 9 ? 1 : -1]; extern int n2[__alignof(struct nS) == 1 ? 1 : -1]; #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/flexible-array-init.c
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s struct one { int a; int values[]; // expected-note 4{{initialized flexible array member 'values' is here}} } x = {5, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}} struct one x2 = { 5, 1, 2, 3 }; // expected-warning{{flexible array initialization is a GNU extension}} void test() { struct one x3 = {5, {1, 2, 3}}; // expected-error{{initialization of flexible array member is not allowed}} struct one x3a = { 5 }; struct one x3b = { .a = 5 }; struct one x3c = { 5, {} }; // expected-warning{{use of GNU empty initializer extension}} \ // expected-warning{{flexible array initialization is a GNU extension}} \ // expected-warning{{zero size arrays are an extension}} } struct foo { int x; int y[]; // expected-note 8 {{initialized flexible array member 'y' is here}} }; struct bar { struct foo z; }; // expected-warning {{'z' may not be nested in a struct due to flexible array member}} struct foo a = { 1, { 2, 3, 4 } }; // expected-warning{{flexible array initialization is a GNU extension}} struct bar b = { { 1, { 2, 3, 4 } } }; // expected-error{{initialization of flexible array member is not allowed}} struct bar c = { { 1, { } } }; // // expected-warning{{flexible array initialization is a GNU extension}} \ // expected-warning{{use of GNU empty initializer extension}} \ // expected-warning{{zero size arrays are an extension}} struct foo d[1] = { { 1, { 2, 3, 4 } } }; // expected-warning{{'struct foo' may not be used as an array element due to flexible array member}} \ // expected-error{{initialization of flexible array member is not allowed}} struct foo desig_foo = { .y = {2, 3, 4} }; // expected-warning{{flexible array initialization is a GNU extension}} struct bar desig_bar = { .z.y = { } }; // expected-warning{{use of GNU empty initializer extension}} \ // expected-warning{{zero size arrays are an extension}} \ // expected-warning{{flexible array initialization is a GNU extension}} struct bar desig_bar2 = { .z.y = { 2, 3, 4} }; // expected-error{{initialization of flexible array member is not allowed}} struct foo design_foo2 = { .y = 2 }; // expected-error{{flexible array requires brace-enclosed initializer}} struct point { int x, y; }; struct polygon { int numpoints; struct point points[]; // expected-note{{initialized flexible array member 'points' is here}} }; struct polygon poly = { .points[2] = { 1, 2} }; // expected-error{{designator into flexible array member subobject}} // PR3540 struct X { int a; int b; char data[]; }; struct Y { int a:4; int b:4; int c; int d; int e; struct X xs[]; // expected-warning{{'struct X' may not be used as an array element due to flexible array member}} }; // PR8217 struct PR8217a { int i; char v[]; // expected-note 2 {{initialized flexible array member 'v' is here}} }; void PR8217() { struct PR8217a foo1 = { .i = 0, .v = "foo" }; // expected-error {{initialization of flexible array member is not allowed}} struct PR8217a foo2 = { .i = 0 }; struct PR8217a foo3 = { .i = 0, .v = { 'b', 'a', 'r', '\0' } }; // expected-error {{initialization of flexible array member is not allowed}} struct PR8217a bar; } typedef struct PR10648 { unsigned long n; int v[]; // expected-note {{initialized flexible array member 'v' is here}} } PR10648; int f10648() { return (PR10648){2, {3, 4}}.v[1]; // expected-error {{initialization of flexible array member is not allowed}} } struct FlexWithUnnamedBitfield { int : 10; int x; int y[]; }; // expected-note {{initialized flexible array member 'y' is here}} void TestFlexWithUnnamedBitfield() { struct FlexWithUnnamedBitfield x = {10, {3}}; // expected-error {{initialization of flexible array member is not allowed}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/warn-absolute-value-header.c
// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s -Wabsolute-value // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only %s -Wabsolute-value -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s int abs(int); // Wrong signature int fabsf(int); // expected-warning@-1{{incompatible redeclaration of library function 'fabsf'}} // expected-note@-2{{'fabsf' is a builtin with type 'float (float)'}} void test_int(int i, unsigned u, long long ll, float f, double d) { (void)abs(i); // Remove abs call (void)abs(u); // expected-warning@-1{{taking the absolute value of unsigned type 'unsigned int' has no effect}} // expected-note@-2{{remove the call to 'abs' since unsigned values cannot be negative}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"" int llabs; (void)llabs; // Conflict in names, no notes (void)abs(ll); // expected-warning@-1{{absolute value function 'abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value}} // Conflict in names, no notes (void)abs(f); // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}} // Suggest header. (void)abs(d); // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}} // expected-note@-2{{use function 'fabs' instead}} // expected-note@-3{{include the header <math.h> or explicitly provide a declaration for 'fabs'}} // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"fabs" }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/pragma-pack-3.c
// RUN: %clang_cc1 -triple i686-apple-darwin9 %s -fsyntax-only -verify // expected-no-diagnostics // Stack: [], Alignment: 8 #pragma pack(push, 1) // Stack: [8], Alignment: 1 #pragma pack(push, 4) // Stack: [8, 1], Alignment: 4 // Note that this differs from gcc; pack() in gcc appears to pop the // top stack entry and resets the current alignment. This is both // inconsistent with MSVC, and the gcc documentation. In other cases, // for example changing this to pack(8), I don't even understand what gcc // is doing. #pragma pack() // Stack: [8, 1], Alignment: 8 #pragma pack(pop) // Stack: [8], Alignment: 1 struct s0 { char f0; short f1; }; int a[sizeof(struct s0) == 3 ? 1 : -1]; #pragma pack(pop) // Stack: [], Alignment: 8 struct s1 { char f0; short f1; }; int b[sizeof(struct s1) == 4 ? 1 : -1];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/decl-in-prototype.c
// RUN: %clang_cc1 -fsyntax-only -verify %s const int AA = 5; int f1(enum {AA,BB} E) { // expected-warning {{will not be visible outside of this function}} return BB; } int f2(enum {AA=7,BB} E) { // expected-warning {{will not be visible outside of this function}} return AA; } struct a { }; int f3(struct a { } *); // expected-warning {{will not be visible outside of this function}} struct A { struct b { int j; } t; }; // expected-note {{previous definition is here}} int f4(struct A { struct b { int j; } t; } *); // expected-warning {{declaration of 'struct A' will not be visible outside of this function}} expected-warning {{redefinition of 'b' will not be visible outside of this function}} struct aA { struct ab { // expected-note {{previous definition is here}} expected-note {{previous definition is here}} int j; } b; }; int f5(struct aA { struct ab { int j; } b; struct ab { char glorx; } glorx; } *); // expected-warning {{declaration of 'struct aA' will not be visible}} expected-warning {{redefinition of 'ab' will not be visible}} expected-warning {{redefinition of 'ab' will not be visible}} void f6(struct z {int b;} c) { // expected-warning {{declaration of 'struct z' will not be visible outside of this function}} struct z d; d.b = 4; } void pr19018_1 (enum e19018 { qq } x); // expected-warning{{declaration of 'enum e19018' will not be visible outside of this function}} enum e19018 qq; //expected-error{{tentative definition has type 'enum e19018' that is never completed}} \ //expected-note{{forward declaration of 'enum e19018'}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/2009-04-22-UnknownSize.c
// RUN: not %clang_cc1 -fsyntax-only -verify %s // PR2958 static struct foo s; // expected-error { tentative definition has type 'struct foo' that is never completed } struct foo *p = &s;
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/mms-bitfields.c
// RUN: %clang_cc1 -mms-bitfields -fsyntax-only -verify -triple x86_64-apple-darwin9 %s // expected-no-diagnostics // The -mms-bitfields commandline parameter should behave the same // as the ms_struct attribute. struct { int a : 1; short b : 1; } t; // MS pads out bitfields between different types. static int arr[(sizeof(t) == 8) ? 1 : -1];
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/unnamed-bitfield-init.c
// RUN: %clang_cc1 -fsyntax-only -verify %s // expected-no-diagnostics typedef struct { int a; int : 24; char b; } S; S a = { 1, 2 };
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/deref.c
/* RUN: %clang_cc1 -fsyntax-only -verify -std=c90 -pedantic %s */ void foo (void) { struct b; struct b* x = 0; struct b* y = &*x; } void foo2 (void) { typedef int (*arrayptr)[]; arrayptr x = 0; arrayptr y = &*x; } void foo3 (void) { void* x = 0; void* y = &*x; /* expected-warning{{address of an expression of type 'void'}} */ } extern const void cv1; const void *foo4 (void) { return &cv1; } extern void cv2; void *foo5 (void) { return &cv2; /* expected-warning{{address of an expression of type 'void'}} */ } typedef const void CVT; extern CVT cv3; const void *foo6 (void) { return &cv3; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/bool-compare.c
// RUN: %clang_cc1 -fsyntax-only -verify %s void f(int x, int y, int z) { int a,b; if ((a > 2) > 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}} if (a > b) {} // no warning if (a < b) {} // no warning if (a >= b) {} // no warning if (a <= b) {} // no warning if (a == b) {} // no warning if (a != b) {} // no warning if (a > 0) {} // no warning if (a > 1) {} // no warning if (a > 2) {} // no warning if (a >= 0) {} // no warning if (a >= 1) {} // no warning if (a >= 2) {} // no warning if (a >= -1) {} // no warning if (a <= 0) {} // no warning if (a <= 1) {} // no warning if (a <= 2) {} // no warning if (a <= -1) {} // no warning if (!a > 0) {} // no warning if (!a > 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}} if (!a > 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}} if (!a > y) {} // no warning if (!a > b) {} // no warning if (!a > -1) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}} if (!a < 0) {} // expected-warning {{comparison of constant 0 with boolean expression is always false}} if (!a < 1) {} // no warning if (!a < 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always true}} if (!a < y) {} // no warning if (!a < b) {} // no warning if (!a < -1) {} // expected-warning {{comparison of constant -1 with boolean expression is always false}} if (!a >= 0) {} // expected-warning {{comparison of constant 0 with boolean expression is always true}} if (!a >= 1) {} // no warning if (!a >= 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}} if (!a >= y) {} // no warning if (!a >= b) {} // no warning if (!a >= -1) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}} if (!a <= 0) {} // no warning if (!a <= 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always true}} if (!a <= 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always true}} if (!a <= y) {} // no warning if (!a <= b) {} // no warning if (!a <= -1) {} // expected-warning {{comparison of constant -1 with boolean expression is always false}} if ((a||b) > 0) {} // no warning if ((a||b) > 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}} if ((a||b) > 4) {} // expected-warning {{comparison of constant 4 with boolean expression is always false}} if ((a||b) > -1) {}// expected-warning {{comparison of constant -1 with boolean expression is always true}} if ((a&&b) > 0) {} // no warning if ((a&&b) > 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}} if ((a&&b) > 4) {} // expected-warning {{comparison of constant 4 with boolean expression is always false}} if ((a<y) > 0) {} // no warning if ((a<y) > 1) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}} if ((a<y) > 4) {} // expected-warning {{comparison of constant 4 with boolean expression is always false}} if ((a<y) > z) {} // no warning if ((a<y) > -1) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}} if ((a<y) == 0) {} // no warning if ((a<y) == 1) {} // no warning if ((a<y) == 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}} if ((a<y) == z) {} // no warning if ((a<y) == -1) {}// expected-warning {{comparison of constant -1 with boolean expression is always false}} if ((a<y) != 0) {} // no warning if ((a<y) != 1) {} // no warning if ((a<y) != 2) {} // expected-warning {{comparison of constant 2 with boolean expression is always true}} if ((a<y) != z) {} // no warning if ((a<y) != -1) {}// expected-warning {{comparison of constant -1 with boolean expression is always true}} if ((a<y) == z) {} // no warning if (a>y<z) {} // no warning if ((a<y) > z) {} // no warning if((a<y)>(z<y)) {} // no warning if((a<y)==(z<y)){} // no warning if((a<y)!=(z<y)){} // no warning if((z==x)<(y==z)){}// no warning if((a<y)!=((z==x)<(y==z))){} //no warning if (0 > !a) {} // expected-warning {{comparison of constant 0 with boolean expression is always false}} if (1 > !a) {} // no warning if (2 > !a) {} // expected-warning {{comparison of constant 2 with boolean expression is always true}} if (y > !a) {} // no warning if (-1 > !a) {} // expected-warning {{comparison of constant -1 with boolean expression is always false}} if (0 < !a) {} // no warning if (1 < !a) {} // expected-warning {{comparison of constant 1 with boolean expression is always false}} if (2 < !a) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}} if (y < !a) {} // no warning if (-1 < !a) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}} if (0 >= !a) {} // no warning if (1 >= !a) {} // expected-warning {{comparison of constant 1 with boolean expression is always true}} if (2 >= !a) {} // expected-warning {{comparison of constant 2 with boolean expression is always true}} if (y >= !a) {} // no warning if (-1 >= !a) {} // expected-warning {{comparison of constant -1 with boolean expression is always false}} if (0 <= !a) {} // expected-warning {{comparison of constant 0 with boolean expression is always true}} if (1 <= !a) {} // no warning if (2 <= !a) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}} if (y <= !a) {} // no warning if (-1 <= !a) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}} if (0 > (a||b)) {} // expected-warning {{comparison of constant 0 with boolean expression is always false}} if (1 > (a||b)) {} // no warning if (4 > (a||b)) {} // expected-warning {{comparison of constant 4 with boolean expression is always true}} if (0 > (a&&b)) {} // expected-warning {{comparison of constant 0 with boolean expression is always false}} if (1 > (a&&b)) {} // no warning if (4 > (a&&b)) {} // expected-warning {{comparison of constant 4 with boolean expression is always true}} if (0 > (a<y)) {} // expected-warning {{comparison of constant 0 with boolean expression is always false}} if (1 > (a<y)) {} // no warning if (4 > (a<y)) {} // expected-warning {{comparison of constant 4 with boolean expression is always true}} if (z > (a<y)) {} // no warning if (-1 > (a<y)) {} // expected-warning {{comparison of constant -1 with boolean expression is always false}} if (0 == (a<y)) {} // no warning if (1 == (a<y)) {} // no warning if (2 == (a<y)) {} // expected-warning {{comparison of constant 2 with boolean expression is always false}} if (z == (a<y)) {} // no warning if (-1 == (a<y)){} // expected-warning {{comparison of constant -1 with boolean expression is always false}} if (0 !=(a<y)) {} // no warning if (1 !=(a<y)) {} // no warning if (2 !=(a<y)) {} // expected-warning {{comparison of constant 2 with boolean expression is always true}} if (z !=(a<y)) {} // no warning if (-1 !=(a<y)) {} // expected-warning {{comparison of constant -1 with boolean expression is always true}} if (z ==(a<y)) {} // no warning if (z<a>y) {} // no warning if (z > (a<y)) {} // no warning if((z<y)>(a<y)) {} // no warning if((z<y)==(a<y)){} // no warning if((z<y)!=(a<y)){} // no warning if((y==z)<(z==x)){} // no warning if(((z==x)<(y==z))!=(a<y)){} // no warning if(((z==x)<(-1==z))!=(a<y)){} // no warning if(((z==x)<(z==-1))!=(a<y)){} // no warning if(((z==x)<-1)!=(a<y)){} // expected-warning {{comparison of constant -1 with boolean expression is always false}} if(((z==x)< 2)!=(a<y)){} // expected-warning {{comparison of constant 2 with boolean expression is always true}} if(((z==x)<(z>2))!=(a<y)){} // no warning }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/warn-main.c
// RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s // RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -x c++ %s 2>&1 | FileCheck %s // expected-note@+1 2{{previous definition is here}} int main() { return 0; } // expected-error@+2 {{static declaration of 'main' follows non-static declaration}} // expected-warning@+1 {{'main' should not be declared static}} static int main() { // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:1-[[@LINE-1]]:8}:"" return 0; } // expected-error@+2 {{redefinition of 'main'}} // expected-error@+1 {{'main' is not allowed to be declared inline}} inline int main() { // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:1-[[@LINE-1]]:8}:"" return 0; } // expected-warning@+5 {{function 'main' declared 'noreturn' should not return}} // expected-warning@+2 {{'main' is not allowed to be declared _Noreturn}} // expected-note@+1 {{remove '_Noreturn'}} _Noreturn int main() { // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:1-[[@LINE-1]]:11}:"" return 0; } // expected-warning@+1 {{'main' is not allowed to be declared variadic}} int main(int argc, char**argv, ...) { return 0; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/inline-asm-validate-tmpl.cpp
// RUN: %clang_cc1 -triple i686 -fsyntax-only -verify %s // RUN: %clang_cc1 -triple x86_64 -fsyntax-only -verify %s // this template, when instantiated with 300, violates the range contraint template <int N> void test(int value) { asm("rol %1, %0" :"=r"(value): "I"(N + 1)); // expected-error{{value '301' out of range for constraint 'I'}} } int main() { test<300>(10); } // expected-note{{in instantiation of function template specialization 'test<300>' requested here}} // this template is not used, but the error is detectable template <int N> void testb(int value) { asm("rol %1, %0" :"=r"(value): "I"(301)); // expected-error{{value '301' out of range for constraint 'I'}} } // these should compile without error template <int N> void testc(int value) { asm("rol %1, %0" :"=r"(value): "I"(N + 1)); } int foo() { testc<2>(10); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/convertvector.c
// RUN: %clang_cc1 -fsyntax-only -verify %s typedef double vector4double __attribute__((__vector_size__(32))); typedef float vector8float __attribute__((__vector_size__(32))); vector8float foo1(vector4double x) { return __builtin_convertvector(x, vector8float); // expected-error {{same number of elements}} } float foo2(vector4double x) { return __builtin_convertvector(x, float); // expected-error {{must be a vector type}} } vector8float foo3(double x) { return __builtin_convertvector(x, vector8float); // expected-error {{must be a vector}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/pragma-align-mac68k.c
// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s // expected-no-diagnostics #include <stddef.h> #pragma options align=mac68k typedef float __attribute__((vector_size (8))) v2f_t; typedef float __attribute__((vector_size (16))) v4f_t; extern int a0_0[__alignof(v2f_t) == 8 ? 1 : -1]; extern int a0_1[__alignof(v4f_t) == 16 ? 1 : -1]; struct s1 { char f0; int f1; }; extern int a1_0[offsetof(struct s1, f0) == 0 ? 1 : -1]; extern int a1_1[offsetof(struct s1, f1) == 2 ? 1 : -1]; extern int a1_2[sizeof(struct s1) == 6 ? 1 : -1]; extern int a1_3[__alignof(struct s1) == 2 ? 1 : -1]; struct s2 { char f0; double f1; }; extern int a2_0[offsetof(struct s2, f0) == 0 ? 1 : -1]; extern int a2_1[offsetof(struct s2, f1) == 2 ? 1 : -1]; extern int a2_2[sizeof(struct s2) == 10 ? 1 : -1]; extern int a2_3[__alignof(struct s2) == 2 ? 1 : -1]; struct s3 { char f0; v4f_t f1; }; extern int a3_0[offsetof(struct s3, f0) == 0 ? 1 : -1]; extern int a3_1[offsetof(struct s3, f1) == 2 ? 1 : -1]; extern int a3_2[sizeof(struct s3) == 18 ? 1 : -1]; extern int a3_3[__alignof(struct s3) == 2 ? 1 : -1]; struct s4 { char f0; char f1; }; extern int a4_0[offsetof(struct s4, f0) == 0 ? 1 : -1]; extern int a4_1[offsetof(struct s4, f1) == 1 ? 1 : -1]; extern int a4_2[sizeof(struct s4) == 2 ? 1 : -1]; extern int a4_3[__alignof(struct s4) == 2 ? 1 : -1]; struct s5 { unsigned f0 : 9; unsigned f1 : 9; }; extern int a5_0[sizeof(struct s5) == 4 ? 1 : -1]; extern int a5_1[__alignof(struct s5) == 2 ? 1 : -1]; struct s6 { unsigned : 0; unsigned : 0; }; extern int a6_0[sizeof(struct s6) == 0 ? 1 : -1]; extern int a6_1[__alignof(struct s6) == 2 ? 1 : -1]; struct s7 { char : 1; unsigned : 1; }; extern int a7_0[sizeof(struct s7) == 2 ? 1 : -1]; extern int a7_1[__alignof(struct s7) == 2 ? 1 : -1]; struct s8 { char f0; unsigned : 1; }; extern int a8_0[sizeof(struct s8) == 2 ? 1 : -1]; extern int a8_1[__alignof(struct s8) == 2 ? 1 : -1]; struct s9 { char f0[3]; unsigned : 0; char f1; }; extern int a9_0[sizeof(struct s9) == 6 ? 1 : -1]; extern int a9_1[__alignof(struct s9) == 2 ? 1 : -1]; struct s10 { char f0; }; extern int a10_0[sizeof(struct s10) == 2 ? 1 : -1]; extern int a10_1[__alignof(struct s10) == 2 ? 1 : -1]; struct s11 { char f0; v2f_t f1; }; extern int a11_0[offsetof(struct s11, f0) == 0 ? 1 : -1]; extern int a11_1[offsetof(struct s11, f1) == 2 ? 1 : -1]; extern int a11_2[sizeof(struct s11) == 10 ? 1 : -1]; extern int a11_3[__alignof(struct s11) == 2 ? 1 : -1]; #pragma options align=reset void f12(void) { #pragma options align=mac68k struct s12 { char f0; int f1; }; #pragma options align=reset extern int a12[sizeof(struct s12) == 6 ? 1 : -1]; }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/attr-unavailable-message.c
// RUN: %clang_cc1 -fsyntax-only -verify %s // rdar: //6734520 int foo(int) __attribute__((__unavailable__("USE IFOO INSTEAD"))); // expected-note {{'foo' has been explicitly marked unavailable here}} double dfoo(double) __attribute__((__unavailable__("NO LONGER"))); // expected-note 2 {{'dfoo' has been explicitly marked unavailable here}} void bar() __attribute__((__unavailable__)); // expected-note {{explicitly marked unavailable}} int quux(void) __attribute__((__unavailable__(12))); // expected-error {{'__unavailable__' attribute requires a string}} #define ACCEPTABLE "Use something else" int quux2(void) __attribute__((__unavailable__(ACCEPTABLE))); void test_foo() { int ir = foo(1); // expected-error {{'foo' is unavailable: USE IFOO INSTEAD}} double dr = dfoo(1.0); // expected-error {{'dfoo' is unavailable: NO LONGER}} void (*fp)() = &bar; // expected-error {{'bar' is unavailable}} double (*fp4)(double) = dfoo; // expected-error {{'dfoo' is unavailable: NO LONGER}} } char test2[__has_feature(attribute_unavailable_with_message) ? 1 : -1]; // rdar://9623855 void unavail(void) __attribute__((__unavailable__)); void unavail(void) { // No complains inside an unavailable function. int ir = foo(1); double dr = dfoo(1.0); void (*fp)() = &bar; double (*fp4)(double) = dfoo; } // rdar://10201690 enum foo { a = 1, // expected-note {{'a' has been explicitly marked deprecated here}} b __attribute__((deprecated())) = 2, // expected-note {{'b' has been explicitly marked deprecated here}} c = 3 }__attribute__((deprecated())); enum fee { // expected-note {{'fee' has been explicitly marked unavailable here}} r = 1, // expected-note {{'r' has been explicitly marked unavailable here}} s = 2, t = 3 }__attribute__((unavailable())); enum fee f() { // expected-error {{'fee' is unavailable}} int i = a; // expected-warning {{'a' is deprecated}} i = b; // expected-warning {{'b' is deprecated}} return r; // expected-error {{'r' is unavailable}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/recover-goto.c
// RUN: %clang_cc1 -fsyntax-only %s -verify void a() { // expected-note {{to match this '{'}} goto A; // expected-error {{use of undeclared label}} // expected-error {{expected '}'}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/vector-assign.c
// RUN: %clang_cc1 %s -verify -fsyntax-only -Wvector-conversion typedef unsigned int v2u __attribute__ ((vector_size (8))); typedef signed int v2s __attribute__ ((vector_size (8))); typedef signed int v1s __attribute__ ((vector_size (4))); typedef float v2f __attribute__ ((vector_size(8))); typedef signed short v4ss __attribute__ ((vector_size (8))); void test1() { v2s v1; v2u v2; v1s v3; v2f v4; v4ss v5; v1 = v2; // expected-warning {{incompatible vector types assigning to 'v2s' (vector of 2 'int' values) from 'v2u' (vector of 2 'unsigned int' values)}} v1 = v3; // expected-error {{assigning to 'v2s' (vector of 2 'int' values) from incompatible type 'v1s' (vector of 1 'int' value)}} v1 = v4; // expected-warning {{incompatible vector types assigning to 'v2s' (vector of 2 'int' values) from 'v2f' (vector of 2 'float' values)}} v1 = v5; // expected-warning {{incompatible vector types assigning to 'v2s' (vector of 2 'int' values) from 'v4ss' (vector of 4 'short' values)}} v2 = v1; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from 'v2s' (vector of 2 'int' values)}} v2 = v3; // expected-error {{assigning to 'v2u' (vector of 2 'unsigned int' values) from incompatible type 'v1s' (vector of 1 'int' value)}} v2 = v4; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from 'v2f' (vector of 2 'float' values)}} v2 = v5; // expected-warning {{incompatible vector types assigning to 'v2u' (vector of 2 'unsigned int' values) from 'v4ss' (vector of 4 'short' values)}} v3 = v1; // expected-error {{assigning to 'v1s' (vector of 1 'int' value) from incompatible type 'v2s' (vector of 2 'int' values)}} v3 = v2; // expected-error {{assigning to 'v1s' (vector of 1 'int' value) from incompatible type 'v2u' (vector of 2 'unsigned int' values)}} v3 = v4; // expected-error {{assigning to 'v1s' (vector of 1 'int' value) from incompatible type 'v2f' (vector of 2 'float' values)}} v3 = v5; // expected-error {{assigning to 'v1s' (vector of 1 'int' value) from incompatible type 'v4ss'}} v4 = v1; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from 'v2s' (vector of 2 'int' values)}} v4 = v2; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from 'v2u' (vector of 2 'unsigned int' values)}} v4 = v3; // expected-error {{assigning to 'v2f' (vector of 2 'float' values) from incompatible type 'v1s' (vector of 1 'int' value)}} v4 = v5; // expected-warning {{incompatible vector types assigning to 'v2f' (vector of 2 'float' values) from 'v4ss' (vector of 4 'short' values)}} v5 = v1; // expected-warning {{incompatible vector types assigning to 'v4ss' (vector of 4 'short' values) from 'v2s' (vector of 2 'int' values)}} v5 = v2; // expected-warning {{incompatible vector types assigning to 'v4ss' (vector of 4 'short' values) from 'v2u' (vector of 2 'unsigned int' values)}} v5 = v3; // expected-error {{assigning to 'v4ss' (vector of 4 'short' values) from incompatible type 'v1s' (vector of 1 'int' value)}} v5 = v4; // expected-warning {{incompatible vector types assigning to 'v4ss' (vector of 4 'short' values) from 'v2f'}} } // PR2263 float test2(__attribute__((vector_size(16))) float a, int b) { return a[b]; } // PR4838 typedef long long __attribute__((__vector_size__(2 * sizeof(long long)))) longlongvec; void test3a(longlongvec *); // expected-note{{passing argument to parameter here}} void test3(const unsigned *src) { test3a(src); // expected-warning {{incompatible pointer types passing 'const unsigned int *' to parameter of type 'longlongvec *'}} }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/attr-declspec-ignored.c
// RUN: %clang_cc1 %s -verify -fsyntax-only __attribute__((visibility("hidden"))) __attribute__((aligned)) struct A; // expected-warning{{attribute 'visibility' is ignored, place it after "struct" to apply attribute to type declaration}} \ // expected-warning{{attribute 'aligned' is ignored, place it after "struct" to apply attribute to type declaration}} __attribute__((visibility("hidden"))) __attribute__((aligned)) union B; // expected-warning{{attribute 'visibility' is ignored, place it after "union" to apply attribute to type declaration}} \ // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}} __attribute__((visibility("hidden"))) __attribute__((aligned)) enum C {C}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \ // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}} __attribute__((visibility("hidden"))) __attribute__((aligned)) struct D {} d; __attribute__((visibility("hidden"))) __attribute__((aligned)) union E {} e; __attribute__((visibility("hidden"))) __attribute__((aligned)) enum F {F} f;
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/aarch64-neon-vector-types.c
// RUN: %clang_cc1 %s -triple aarch64-none-linux-gnu -target-feature +neon -fsyntax-only -verify // RUN: %clang_cc1 %s -triple aarch64-none-linux-gnu -target-feature +neon -DUSE_LONG -fsyntax-only -verify // RUN: %clang_cc1 %s -triple arm64-none-linux-gnu -target-feature +neon -fsyntax-only -verify // RUN: %clang_cc1 %s -triple arm64-none-linux-gnu -target-feature +neon -DUSE_LONG -fsyntax-only -verify typedef float float32_t; typedef unsigned char poly8_t; typedef unsigned short poly16_t; // Both "long" and "long long" should work for 64-bit arch like aarch64. // stdint.h in gnu libc is using "long" for 64-bit arch. #if USE_LONG typedef long int64_t; typedef unsigned long uint64_t; #else typedef long long int64_t; typedef unsigned long long uint64_t; #endif typedef uint64_t poly64_t; // Define some valid Neon types. typedef __attribute__((neon_vector_type(2))) int int32x2_t; typedef __attribute__((neon_vector_type(4))) int int32x4_t; typedef __attribute__((neon_vector_type(1))) int64_t int64x1_t; typedef __attribute__((neon_vector_type(2))) int64_t int64x2_t; typedef __attribute__((neon_vector_type(1))) uint64_t uint64x1_t; typedef __attribute__((neon_vector_type(2))) uint64_t uint64x2_t; typedef __attribute__((neon_vector_type(2))) float32_t float32x2_t; typedef __attribute__((neon_vector_type(4))) float32_t float32x4_t; typedef __attribute__((neon_polyvector_type(16))) poly8_t poly8x16_t; typedef __attribute__((neon_polyvector_type(8))) poly16_t poly16x8_t; typedef __attribute__((neon_polyvector_type(1))) poly64_t poly64x1_t; typedef __attribute__((neon_polyvector_type(2))) poly64_t poly64x2_t; // The attributes must have a single argument. typedef __attribute__((neon_vector_type(2, 4))) int only_one_arg; // expected-error{{attribute takes one argument}} // The number of elements must be an ICE. typedef __attribute__((neon_vector_type(2.0))) int non_int_width; // expected-error{{attribute requires an integer constant}} // Only certain element types are allowed. typedef __attribute__((neon_vector_type(2))) double double_elt; typedef __attribute__((neon_vector_type(4))) void* ptr_elt; // expected-error{{invalid vector element type}} typedef __attribute__((neon_polyvector_type(4))) float32_t bad_poly_elt; // expected-error{{invalid vector element type}} struct aggr { signed char c; }; typedef __attribute__((neon_vector_type(8))) struct aggr aggregate_elt; // expected-error{{invalid vector element type}} // The total vector size must be 64 or 128 bits. typedef __attribute__((neon_vector_type(1))) int int32x1_t; // expected-error{{Neon vector size must be 64 or 128 bits}} typedef __attribute__((neon_vector_type(3))) int int32x3_t; // expected-error{{Neon vector size must be 64 or 128 bits}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/arm-neon-types.c
// RUN: %clang_cc1 -triple thumbv7-apple-darwin10 -target-cpu cortex-a8 -fsyntax-only -Wvector-conversion -ffreestanding -verify %s #ifndef INCLUDE #include <arm_neon.h> // Radar 8228022: Should not report incompatible vector types. int32x2_t test(int32x2_t x) { return vshr_n_s32(x, 31); } // ...but should warn when the types really do not match. float32x2_t test2(uint32x2_t x) { return vcvt_n_f32_s32(x, 9); // expected-warning {{incompatible vector types}} } // Check immediate range for vcvt_n intrinsics is 1 to 32. Radar 9558930. float32x2_t test3(uint32x2_t x) { // FIXME: The "incompatible result type" error is due to pr10112 and should be // removed when that is fixed. return vcvt_n_f32_u32(x, 0); // expected-error {{argument should be a value from 1 to 32}} } typedef signed int vSInt32 __attribute__((__vector_size__(16))); int32x4_t test4(int32x4_t a, vSInt32 b) { a += b; b += a; return b += a; } // Warn for incompatible pointer types used with vld/vst intrinsics. int16x8_t test5(int *p) { return vld1q_s16(p); // expected-warning {{incompatible pointer types}} } void test6(float *p, int32x2_t v) { return vst1_s32(p, v); // expected-warning {{incompatible pointer types}} } #define INCLUDE #include "arm-neon-types.c" #else // Make sure we don't get a warning about using a static function in an // extern inline function from a header. extern inline uint8x8_t test7(uint8x8_t a, uint8x8_t b) { return vadd_u8(a, b); } #endif
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/builtin-longjmp.c
// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm < %s| FileCheck %s // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm < %s| FileCheck %s // 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 arm-unknown-unknown -emit-llvm-only -verify %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 // RUN: %clang_cc1 -triple mips64-unknown-unknown -emit-llvm-only -verify %s // Check that __builtin_longjmp and __builtin_setjmp are lowered into // IR intrinsics on those architectures that can handle them. // Check that an error is created otherwise. typedef void *jmp_buf; jmp_buf buf; // CHECK: define{{.*}} void @do_jump() // CHECK: call{{.*}} void @llvm.eh.sjlj.longjmp // CHECK: define{{.*}} void @do_setjmp() // CHECK: call{{.*}} i32 @llvm.eh.sjlj.setjmp void do_jump(void) { __builtin_longjmp(buf, 1); // expected-error {{__builtin_longjmp is not supported for the current target}} } void f(void); void do_setjmp(void) { if (!__builtin_setjmp(buf)) // expected-error {{__builtin_setjmp is not supported for the current target}} f(); }
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/attr-noreturn.c
// RUN: %clang_cc1 -verify -fsyntax-only %s static void (*fp0)(void) __attribute__((noreturn)); void fatal(); static void __attribute__((noreturn)) f0(void) { fatal(); } // expected-warning {{function declared 'noreturn' should not return}} // On K&R int f1() __attribute__((noreturn)); int g0 __attribute__((noreturn)); // expected-warning {{'noreturn' only applies to function types; type here is 'int'}} int f2() __attribute__((noreturn(1, 2))); // expected-error {{'noreturn' attribute takes no arguments}} void f3() __attribute__((noreturn)); void f3() { return; // expected-warning {{function 'f3' declared 'noreturn' should not return}} } #pragma clang diagnostic error "-Winvalid-noreturn" void f4() __attribute__((noreturn)); void f4() { return; // expected-error {{function 'f4' declared 'noreturn' should not return}} } // PR4685 extern void f5 (unsigned long) __attribute__ ((__noreturn__)); void f5 (unsigned long size) { } // PR2461 __attribute__((noreturn)) void f(__attribute__((noreturn)) void (*x)(void)) { x(); } typedef void (*Fun)(void) __attribute__ ((noreturn(2))); // expected-error {{'noreturn' attribute takes no arguments}}
0
repos/DirectXShaderCompiler/tools/clang/test
repos/DirectXShaderCompiler/tools/clang/test/Sema/attr-unknown.c
// RUN: %clang_cc1 -fsyntax-only -verify -Wattributes %s int x __attribute__((foobar)); // expected-warning {{unknown attribute 'foobar' ignored}} void z() __attribute__((bogusattr)); // expected-warning {{unknown attribute 'bogusattr' ignored}}