diff options
author | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
---|---|---|
committer | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
commit | be1de4be954c80875ad4108e0a33e8e131b2f2c0 (patch) | |
tree | 1fbbecf276bf7c7bdcbb4dd446099d6d90eaa516 /clang/test/Misc | |
parent | c4626a62754862d20b41e8a46a3574264ea80e6d (diff) | |
parent | f1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff) |
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/test/Misc')
40 files changed, 1197 insertions, 0 deletions
diff --git a/clang/test/Misc/Inputs/include.h b/clang/test/Misc/Inputs/include.h new file mode 100644 index 0000000..72835e9 --- /dev/null +++ b/clang/test/Misc/Inputs/include.h @@ -0,0 +1,3 @@ +#define EQUALS(a,b) a == b + +int foo(int x) { return x; } diff --git a/clang/test/Misc/Inputs/remapped-file b/clang/test/Misc/Inputs/remapped-file new file mode 100644 index 0000000..657613e --- /dev/null +++ b/clang/test/Misc/Inputs/remapped-file @@ -0,0 +1 @@ +int *f(float *fp) { return fp; } diff --git a/clang/test/Misc/Inputs/remapped-file-2 b/clang/test/Misc/Inputs/remapped-file-2 new file mode 100644 index 0000000..9ac034a --- /dev/null +++ b/clang/test/Misc/Inputs/remapped-file-2 @@ -0,0 +1,3 @@ +#include "nonexistent.h" + +int *f() { return fp; } diff --git a/clang/test/Misc/Inputs/remapped-file-3 b/clang/test/Misc/Inputs/remapped-file-3 new file mode 100644 index 0000000..b7ab613 --- /dev/null +++ b/clang/test/Misc/Inputs/remapped-file-3 @@ -0,0 +1,2 @@ +extern float *fp; + diff --git a/clang/test/Misc/Inputs/working-directory.h b/clang/test/Misc/Inputs/working-directory.h new file mode 100644 index 0000000..061df62 --- /dev/null +++ b/clang/test/Misc/Inputs/working-directory.h @@ -0,0 +1 @@ +typedef int Foo; diff --git a/clang/test/Misc/ast-dump-templates.cpp b/clang/test/Misc/ast-dump-templates.cpp new file mode 100644 index 0000000..7d56e7b --- /dev/null +++ b/clang/test/Misc/ast-dump-templates.cpp @@ -0,0 +1,39 @@ +// RUN: %clang_cc1 -ast-dump %s > %t +// RUN: FileCheck < %t %s -check-prefix=CHECK1 +// RUN: FileCheck < %t %s -check-prefix=CHECK2 + +template <int X, typename Y, int Z = 5> +struct foo { + int constant; + foo() {} + Y getSum() { return Y(X + Z); } +}; + +template <int A, typename B> +B bar() { + return B(A); +} + +void baz() { + int x = bar<5, int>(); + int y = foo<5, int>().getSum(); + double z = foo<2, double, 3>().getSum(); +} + +// Template instantiation - foo +// Since the order of instantiation may vary during runs, run FileCheck twice +// to make sure each instantiation is in the correct spot. +// CHECK1: template <int X = 5, typename Y = int, int Z = 5> struct foo { +// CHECK2: template <int X = 2, typename Y = double, int Z = 3> struct foo { + +// Template definition - foo +// CHECK1: template <int X, typename Y, int Z = (IntegerLiteral {{.*}} 'int' 5) +// CHECK2: template <int X, typename Y, int Z = (IntegerLiteral {{.*}} 'int' 5) + +// Template instantiation - bar +// CHECK1: template <int A = 5, typename B = int> int bar() +// CHECK2: template <int A = 5, typename B = int> int bar() + +// Template definition - bar +// CHECK1: template <int A, typename B> B bar() +// CHECK2: template <int A, typename B> B bar() diff --git a/clang/test/Misc/caret-diags-macros.c b/clang/test/Misc/caret-diags-macros.c new file mode 100644 index 0000000..de1ee76 --- /dev/null +++ b/clang/test/Misc/caret-diags-macros.c @@ -0,0 +1,120 @@ +// RUN: %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck %s + +#define M1(x) x +#define M2 1; +void foo() { + M1( + M2); + // CHECK: :7:{{[0-9]+}}: warning: expression result unused + // CHECK: :4:{{[0-9]+}}: note: expanded from macro 'M2' + // CHECK: :3:{{[0-9]+}}: note: expanded from macro 'M1' +} + +#define A 1 +#define B A +#define C B +void bar() { + C; + // CHECK: :17:3: warning: expression result unused + // CHECK: :15:11: note: expanded from macro 'C' + // CHECK: :14:11: note: expanded from macro 'B' + // CHECK: :13:11: note: expanded from macro 'A' +} + +// rdar://7597492 +#define sprintf(str, A, B) \ +__builtin___sprintf_chk (str, 0, 42, A, B) + +void baz(char *Msg) { + sprintf(Msg, " sizeof FoooLib : =%3u\n", 12LL); +} + + +// PR9279: comprehensive tests for multi-level macro back traces +#define macro_args1(x) x +#define macro_args2(x) macro_args1(x) +#define macro_args3(x) macro_args2(x) + +#define macro_many_args1(x, y, z) y +#define macro_many_args2(x, y, z) macro_many_args1(x, y, z) +#define macro_many_args3(x, y, z) macro_many_args2(x, y, z) + +void test() { + macro_args3(1); + // CHECK: {{.*}}:43:15: warning: expression result unused + // Also check that the 'caret' printing agrees with the location here where + // its easy to FileCheck. + // CHECK-NEXT: macro_args3(1); + // CHECK-NEXT: ~~~~~~~~~~~~^~ + // CHECK: {{.*}}:36:36: note: expanded from macro 'macro_args3' + // CHECK: {{.*}}:35:36: note: expanded from macro 'macro_args2' + // CHECK: {{.*}}:34:24: note: expanded from macro 'macro_args1' + + macro_many_args3( + 1, + 2, + 3); + // CHECK: {{.*}}:55:5: warning: expression result unused + // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' + + macro_many_args3( + 1, + M2, + 3); + // CHECK: {{.*}}:64:5: warning: expression result unused + // CHECK: {{.*}}:4:12: note: expanded from macro 'M2' + // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' + + macro_many_args3( + 1, + macro_args2(2), + 3); + // CHECK: {{.*}}:74:17: warning: expression result unused + // This caret location needs to be printed *inside* a different macro's + // arguments. + // CHECK-NEXT: macro_args2(2), + // CHECK-NEXT: ~~~~~~~~~~~~^~~ + // CHECK: {{.*}}:35:36: note: expanded from macro 'macro_args2' + // CHECK: {{.*}}:34:24: note: expanded from macro 'macro_args1' + // CHECK: {{.*}}:40:55: note: expanded from macro 'macro_many_args3' + // CHECK: {{.*}}:39:55: note: expanded from macro 'macro_many_args2' + // CHECK: {{.*}}:38:35: note: expanded from macro 'macro_many_args1' +} + +#define variadic_args1(x, y, ...) y +#define variadic_args2(x, ...) variadic_args1(x, __VA_ARGS__) +#define variadic_args3(x, y, ...) variadic_args2(x, y, __VA_ARGS__) + +void test2() { + variadic_args3(1, 2, 3, 4); + // CHECK: {{.*}}:93:21: warning: expression result unused + // CHECK-NEXT: variadic_args3(1, 2, 3, 4); + // CHECK-NEXT: ~~~~~~~~~~~~~~~~~~^~~~~~~~ + // CHECK: {{.*}}:90:53: note: expanded from macro 'variadic_args3' + // CHECK: {{.*}}:89:50: note: expanded from macro 'variadic_args2' + // CHECK: {{.*}}:88:35: note: expanded from macro 'variadic_args1' +} + +#define variadic_pasting_args1(x, y, z) y +#define variadic_pasting_args2(x, ...) variadic_pasting_args1(x ## __VA_ARGS__) +#define variadic_pasting_args2a(x, y, ...) variadic_pasting_args1(x, y ## __VA_ARGS__) +#define variadic_pasting_args3(x, y, ...) variadic_pasting_args2(x, y, __VA_ARGS__) +#define variadic_pasting_args3a(x, y, ...) variadic_pasting_args2a(x, y, __VA_ARGS__) + +void test3() { + variadic_pasting_args3(1, 2, 3, 4); + // CHECK: {{.*}}:109:32: warning: expression result unused + // CHECK: {{.*}}:105:72: note: expanded from macro 'variadic_pasting_args3' + // CHECK: {{.*}}:103:68: note: expanded from macro 'variadic_pasting_args2' + // CHECK: {{.*}}:102:41: note: expanded from macro 'variadic_pasting_args1' + + variadic_pasting_args3a(1, 2, 3, 4); + // CHECK: {{.*}}:115:30: warning: expression result unused + // CHECK: {{.*}}:106:71: note: expanded from macro 'variadic_pasting_args3a' + // CHECK: {{.*}}:104:70: note: expanded from macro 'variadic_pasting_args2a' + // CHECK: {{.*}}:102:41: note: expanded from macro 'variadic_pasting_args1' +} diff --git a/clang/test/Misc/caret-diags-scratch-buffer.c b/clang/test/Misc/caret-diags-scratch-buffer.c new file mode 100644 index 0000000..883c68e --- /dev/null +++ b/clang/test/Misc/caret-diags-scratch-buffer.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only %s 2>&1 | not grep keyXXXX +// This should not show keyXXXX in the caret diag output. This once +// happened because the two tokens ended up in the scratch buffer and +// the caret diag from the scratch buffer included the previous token. +#define M(name) \ + if (name ## XXXX != name ## _sb); + +void foo() { + int keyXXXX; + M(key); +} + diff --git a/clang/test/Misc/diag-aka-types.cpp b/clang/test/Misc/diag-aka-types.cpp new file mode 100644 index 0000000..4c9a731 --- /dev/null +++ b/clang/test/Misc/diag-aka-types.cpp @@ -0,0 +1,68 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++11 + +struct X {}; +typedef X foo_t; + +foo_t *ptr; +char c1 = ptr; // expected-error{{'foo_t *' (aka 'X *')}} + +const foo_t &ref = foo_t(); +char c2 = ref; // expected-error{{'const foo_t' (aka 'const X')}} + +// deduced auto should not produce an aka. +auto aut = X(); +char c3 = aut; // expected-error{{from 'X' to 'char'}} + +// There are two classes named Foo::foo here. Make sure the message gives +// a way to them apart. +namespace Foo { + class foo {}; +} + +namespace bar { + namespace Foo { + class foo; + } + void f(Foo::foo* x); // expected-note{{passing argument to parameter 'x' here}} +} + +void test(Foo::foo* x) { + bar::f(x); // expected-error{{cannot initialize a parameter of type 'Foo::foo *' (aka 'bar::Foo::foo *') with an lvalue of type 'Foo::foo *'}} +} + +// PR9548 - "no known conversion from 'vector<string>' to 'vector<string>'" +// vector<string> refers to two different types here. Make sure the message +// gives a way to tell them apart. +class versa_string; +typedef versa_string string; + +namespace std {template <typename T> class vector;} +using std::vector; + +void f(vector<string> v); // expected-note {{candidate function not viable: no known conversion from 'vector<string>' (aka 'std::vector<std::basic_string>') to 'vector<string>' (aka 'std::vector<versa_string>') for 1st argument}} + +namespace std { + class basic_string; + typedef basic_string string; + template <typename T> class vector {}; + void g() { + vector<string> v; + f(v); // expected-error{{no matching function for call to 'f'}} + } +} + +namespace ns { + struct str { + static void method(struct data *) {} + }; +} + +struct data { int i; }; + +typedef void (*callback)(struct data *); + +void helper(callback cb) {} // expected-note{{candidate function not viable: no known conversion from 'void (*)(struct data *)' (aka 'void (*)(ns::data *)') to 'callback' (aka 'void (*)(struct data *)') for 1st argument;}} + +void test() { + helper(&ns::str::method); // expected-error{{no matching function for call to 'helper'}} +} diff --git a/clang/test/Misc/diag-format.c b/clang/test/Misc/diag-format.c new file mode 100644 index 0000000..959177b --- /dev/null +++ b/clang/test/Misc/diag-format.c @@ -0,0 +1,34 @@ +// RUN: %clang -fsyntax-only %s 2>&1 | FileCheck %s -check-prefix=DEFAULT +// RUN: %clang -fsyntax-only -fdiagnostics-format=clang %s 2>&1 | FileCheck %s -check-prefix=DEFAULT +// RUN: %clang -fsyntax-only -fdiagnostics-format=clang -target x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=DEFAULT +// +// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc %s 2>&1 | FileCheck %s -check-prefix=MSVC +// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -target x86_64-pc-win32 %s 2>&1 | FileCheck %s -check-prefix=MSVC +// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s -check-prefix=MSVC +// +// RUN: %clang -fsyntax-only -fdiagnostics-format=vi %s 2>&1 | FileCheck %s -check-prefix=VI +// +// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fno-show-column %s 2>&1 | FileCheck %s -check-prefix=MSVC_ORIG +// +// RUN: %clang -fsyntax-only -fno-show-column %s 2>&1 | FileCheck %s -check-prefix=NO_COLUMN +// + + + + + + + + + + + + +#ifdef foo +#endif bad // extension! +// DEFAULT: {{.*}}:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens] +// MSVC: {{.*}}(28,7) : warning: extra tokens at end of #endif directive [-Wextra-tokens] +// VI: {{.*}} +28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens] +// MSVC_ORIG: {{.*}}(28) : warning: extra tokens at end of #endif directive [-Wextra-tokens] +// NO_COLUMN: {{.*}}:28: warning: extra tokens at end of #endif directive [-Wextra-tokens] +int x; diff --git a/clang/test/Misc/diag-line-wrapping.cpp b/clang/test/Misc/diag-line-wrapping.cpp new file mode 100644 index 0000000..830aa13 --- /dev/null +++ b/clang/test/Misc/diag-line-wrapping.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -fmessage-length 60 %s 2>&1 | FileCheck %s + +struct B { void f(); }; +struct D1 : B {}; +struct D2 : B {}; +struct DD : D1, D2 { + void g() { f(); } + // Ensure that after line-wrapping takes place, we preserve artificial + // newlines introduced to manually format a section of the diagnostic text. + // CHECK: {{.*}}: error: + // CHECK: struct DD -> struct D1 -> struct B + // CHECK: struct DD -> struct D2 -> struct B +} diff --git a/clang/test/Misc/diag-macro-backtrace.c b/clang/test/Misc/diag-macro-backtrace.c new file mode 100644 index 0000000..ea40cbe --- /dev/null +++ b/clang/test/Misc/diag-macro-backtrace.c @@ -0,0 +1,53 @@ +// RUN: %clang -fsyntax-only -fmacro-backtrace-limit=0 %s 2>&1 | FileCheck %s + +#define FOO 1+"hi" +#define BAR FOO +#define BAZ BAR +#define QUZ BAZ +#define TAZ QUZ +#define ABA TAZ +#define BAB ABA +#define ZAZ BAB +#define WAZ ZAZ +#define DROOL WAZ +#define FOOL DROOL + +FOOL + +// CHECK: :15:1: error: expected identifier or '(' +// CHECK: FOOL +// CHECK: ^ +// CHECK: :13:14: note: expanded from macro 'FOOL' +// CHECK: #define FOOL DROOL +// CHECK: ^ +// CHECK: :12:15: note: expanded from macro 'DROOL' +// CHECK: #define DROOL WAZ +// CHECK: ^ +// CHECK: :11:13: note: expanded from macro 'WAZ' +// CHECK: #define WAZ ZAZ +// CHECK: ^ +// CHECK: :10:13: note: expanded from macro 'ZAZ' +// CHECK: #define ZAZ BAB +// CHECK: ^ +// CHECK: :9:13: note: expanded from macro 'BAB' +// CHECK: #define BAB ABA +// CHECK: ^ +// CHECK: :8:13: note: expanded from macro 'ABA' +// CHECK: #define ABA TAZ +// CHECK: ^ +// CHECK: :7:13: note: expanded from macro 'TAZ' +// CHECK: #define TAZ QUZ +// CHECK: ^ +// CHECK: :6:13: note: expanded from macro 'QUZ' +// CHECK: #define QUZ BAZ +// CHECK: ^ +// CHECK: :5:13: note: expanded from macro 'BAZ' +// CHECK: #define BAZ BAR +// CHECK: ^ +// CHECK: :4:13: note: expanded from macro 'BAR' +// CHECK: #define BAR FOO +// CHECK: ^ +// CHECK: :3:13: note: expanded from macro 'FOO' +// CHECK: #define FOO 1+"hi" +// CHECK: ^ +// CHECK: 1 error generated. diff --git a/clang/test/Misc/diag-mapping.c b/clang/test/Misc/diag-mapping.c new file mode 100644 index 0000000..75b49ef --- /dev/null +++ b/clang/test/Misc/diag-mapping.c @@ -0,0 +1,30 @@ +// This should warn by default. +// RUN: %clang_cc1 %s 2>&1 | grep "warning:" +// This should not emit anything. +// RUN: %clang_cc1 %s -Wno-extra-tokens 2>&1 | not grep diagnostic + +// -Werror can map all warnings to error. +// RUN: %clang_cc1 %s -Werror 2>&1 | grep "error:" + +// -Werror can map this one warning to error. +// RUN: %clang_cc1 %s -Werror=extra-tokens 2>&1 | grep "error:" + +// Mapping unrelated diags to errors doesn't affect this one. +// RUN: %clang_cc1 %s -Werror=trigraphs 2>&1 | grep "warning:" + +// This should stay a warning with -pedantic. +// RUN: %clang_cc1 %s -pedantic 2>&1 | grep "warning:" + +// This should emit an error with -pedantic-errors. +// RUN: %clang_cc1 %s -pedantic-errors 2>&1 | grep "error:" + +// This should emit a warning, because -Wfoo overrides -pedantic*. +// RUN: %clang_cc1 %s -pedantic-errors -Wextra-tokens 2>&1 | grep "warning:" + +// This should emit nothing, because -Wno-extra-tokens overrides -pedantic* +// RUN: %clang_cc1 %s -pedantic-errors -Wno-extra-tokens 2>&1 | not grep diagnostic + +#ifdef foo +#endif bad // extension! + +int x; diff --git a/clang/test/Misc/diag-mapping2.c b/clang/test/Misc/diag-mapping2.c new file mode 100644 index 0000000..bc5a087 --- /dev/null +++ b/clang/test/Misc/diag-mapping2.c @@ -0,0 +1,22 @@ +// This should warn by default. +// RUN: %clang_cc1 %s 2>&1 | grep "warning:" + +// This should not emit anything. +// RUN: %clang_cc1 %s -w 2>&1 | not grep diagnostic +// RUN: %clang_cc1 %s -Wno-#warnings 2>&1 | not grep diagnostic + +// -Werror can map all warnings to error. +// RUN: %clang_cc1 %s -Werror 2>&1 | grep "error:" + +// -Werror can map this one warning to error. +// RUN: %clang_cc1 %s -Werror=#warnings 2>&1 | grep "error:" + +// -Wno-error= overrides -Werror. rdar://3158301 +// RUN: %clang_cc1 %s -Werror -Wno-error=#warnings 2>&1 | grep "warning:" + +// -Wno-error overrides -Werror. PR4715 +// RUN: %clang_cc1 %s -Werror -Wno-error 2>&1 | grep "warning:" + +#warning foo + + diff --git a/clang/test/Misc/diag-verify.cpp b/clang/test/Misc/diag-verify.cpp new file mode 100644 index 0000000..895bc3f --- /dev/null +++ b/clang/test/Misc/diag-verify.cpp @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s 2>&1 | FileCheck %s + +// Test the -verify flag. Each of the "x = y;" lines will produce a +// "use of undeclared identifier 'y'" error message. + +void test() { + int x; + // Proper matches here. + x = y; // expected-error{{use of undeclared identifier 'y'}} + x = y; // expected-error{{use of undeclared identifier}} + x = y; // expected-error{{undeclared identifier 'y'}} + x = y; // expected-error{{use of}} + x = y; // expected-error{{undeclared identifier}} + x = y; // expected-error{{'y'}} + + // Bad matches here. + x = y; // expected-error{{use of undeclared identifier 'y' is fine}} + x = y; // expected-error{{abuse of undeclared identifier 'y'}} + x = y; // expected-error{{good use of undeclared identifier 'y' in code}} + x = y; // expected-error{{ use of undeclared identifier 'y' }} + x = y; // expected-error{{use of undeclared identifier 'y' is disallowed}} + x = y; // expected-error{{please don't use of undeclared identifier 'y'}} + x = y; // expected-error{{use of undeclared identifier 'y'; please declare y before use}} + x = y; // expected-error{{use of use of undeclared identifier 'y'}} + x = y; // expected-error{{use of undeclared identifier 'y' identifier 'y'}} +} + +//CHECK: error: 'error' diagnostics expected but not seen: +//CHECK: Line 17: use of undeclared identifier 'y' is fine +//CHECK: Line 18: abuse of undeclared identifier 'y' +//CHECK: Line 19: good use of undeclared identifier 'y' in code +//CHECK: Line 20: use of undeclared identifier 'y' +//CHECK: Line 21: use of undeclared identifier 'y' is disallowed +//CHECK: Line 22: please don't use of undeclared identifier 'y' +//CHECK: Line 23: use of undeclared identifier 'y'; please declare y before use +//CHECK: Line 24: use of use of undeclared identifier 'y' +//CHECK: Line 25: use of undeclared identifier 'y' identifier 'y' +//CHECK: error: 'error' diagnostics seen but not expected: +//CHECK: Line 17: use of undeclared identifier 'y' +//CHECK: Line 18: use of undeclared identifier 'y' +//CHECK: Line 19: use of undeclared identifier 'y' +//CHECK: Line 20: use of undeclared identifier 'y' +//CHECK: Line 21: use of undeclared identifier 'y' +//CHECK: Line 22: use of undeclared identifier 'y' +//CHECK: Line 23: use of undeclared identifier 'y' +//CHECK: Line 24: use of undeclared identifier 'y' +//CHECK: Line 25: use of undeclared identifier 'y' +//CHECK: 18 errors generated. diff --git a/clang/test/Misc/emit-html-insert.c b/clang/test/Misc/emit-html-insert.c new file mode 100644 index 0000000..289c28a --- /dev/null +++ b/clang/test/Misc/emit-html-insert.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 %s -emit-html -o - | grep ">< 10; }" + +int a(int x) { return x +< 10; } diff --git a/clang/test/Misc/emit-html.c b/clang/test/Misc/emit-html.c new file mode 100644 index 0000000..48c8b61 --- /dev/null +++ b/clang/test/Misc/emit-html.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 %s -emit-html -o - + +// rdar://6562329 +#line 42 "foo.c" + +// PR3635 +#define F(fmt, ...) fmt, ## __VA_ARGS__ +int main(int argc, char **argv) { + return F(argc, 1); +} + +// PR3798 +#define FOR_ALL_FILES(f,i) i + +#if 0 + FOR_ALL_FILES(f) { } +#endif + diff --git a/clang/test/Misc/error-limit-multiple-notes.cpp b/clang/test/Misc/error-limit-multiple-notes.cpp new file mode 100644 index 0000000..019b4dd --- /dev/null +++ b/clang/test/Misc/error-limit-multiple-notes.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -ferror-limit 1 -fsyntax-only %s 2>&1 | FileCheck %s + +// error and three notes emitted +void foo(int); +void foo(double); +void foo(int, int); + +int main() +{ + foo(); +} + +// error and note suppressed by error-limit +struct s1{}; +struct s1{}; + +// CHECK: 10:5: error: no matching function for call to 'foo' +// CHECK: 6:6: note: candidate function not viable: requires 2 arguments, but 0 were provided +// CHECK: 5:6: note: candidate function not viable: requires 1 argument, but 0 were provided +// CHECK: 4:6: note: candidate function not viable: requires 1 argument, but 0 were provided +// CHECK: fatal error: too many errors emitted, stopping now +// CHECK-NOT: 15:8: error: redefinition of 's1' +// CHECK-NOT: 14:8: note: previous definition is here diff --git a/clang/test/Misc/error-limit.c b/clang/test/Misc/error-limit.c new file mode 100644 index 0000000..26f4ac1 --- /dev/null +++ b/clang/test/Misc/error-limit.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -ferror-limit 1 -fsyntax-only %s 2>&1 | FileCheck %s + +// error and note emitted +struct s1{}; +struct s1{}; + +// error and note suppressed by error-limit +struct s2{}; +struct s2{}; + +// CHECK: 5:8: error: redefinition of 's1' +// CHECK: 4:8: note: previous definition is here +// CHECK: fatal error: too many errors emitted, stopping now +// CHECK-NOT: 9:8: error: redefinition of 's2' +// CHECK-NOT: 8:8: note: previous definition is here diff --git a/clang/test/Misc/include-stack-for-note-flag.cpp b/clang/test/Misc/include-stack-for-note-flag.cpp new file mode 100644 index 0000000..b41284f --- /dev/null +++ b/clang/test/Misc/include-stack-for-note-flag.cpp @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack %s 2>&1 | FileCheck %s -check-prefix=STACK +// RUN: %clang_cc1 -fsyntax-only -fno-diagnostics-show-note-include-stack %s 2>&1 | FileCheck %s -check-prefix=STACKLESS +// RUN: %clang_cc1 -fsyntax-only -fno-diagnostics-show-note-include-stack -fdiagnostics-show-note-include-stack %s 2>&1 | FileCheck %s -check-prefix=STACK +// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -fno-diagnostics-show-note-include-stack %s 2>&1 | FileCheck %s -check-prefix=STACKLESS +// RUN: %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck %s -check-prefix=STACKLESS + +#include "Inputs/include.h" +int test() { + return foo(1, 1); +} + +bool macro(int x, int y) { + return EQUALS(&x, y); +} + +// STACK: error: no matching function for call to 'foo' +// STACK: In file included from +// STACK: note: candidate function not viable +// STACK: error: comparison between pointer and integer +// STACK: In file included from +// STACK: note: expanded from macro + +// STACKLESS: error: no matching function for call to 'foo' +// STACKLESS-NOT: In file included from +// STACKLESS: note: candidate function not viable +// STACKLESS: error: comparison between pointer and integer +// STACKLESS-NOT: In file included from +// STACKLESS: note: expanded from macro diff --git a/clang/test/Misc/integer-literal-printing.cpp b/clang/test/Misc/integer-literal-printing.cpp new file mode 100644 index 0000000..d751730 --- /dev/null +++ b/clang/test/Misc/integer-literal-printing.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify + +// PR11179 +template <short T> class Type1 {}; +template <short T> void Function1(Type1<T>& x) {} // expected-note{{candidate function [with T = -42] not viable: no known conversion from 'Type1<-42>' to 'Type1<-42> &' for 1st argument;}} + +template <unsigned short T> class Type2 {}; +template <unsigned short T> void Function2(Type2<T>& x) {} // expected-note{{candidate function [with T = 42] not viable: no known conversion from 'Type2<42>' to 'Type2<42> &' for 1st argument;}} + +void Function() { + Function1(Type1<-42>()); // expected-error{{no matching function for call to 'Function1'}} + Function2(Type2<42>()); // expected-error{{no matching function for call to 'Function2'}} +} diff --git a/clang/test/Misc/macro-backtrace.c b/clang/test/Misc/macro-backtrace.c new file mode 100644 index 0000000..7aeaf21 --- /dev/null +++ b/clang/test/Misc/macro-backtrace.c @@ -0,0 +1,57 @@ +// Tests for macro expansion backtraces. The RUN and CHECK lines are grouped +// below the test code to reduce noise when updating them. + +#define M1(A, B) ((A) < (B)) +#define M2(A, B) M1(A, B) +#define M3(A, B) M2(A, B) +#define M4(A, B) M3(A, B) +#define M5(A, B) M4(A, B) +#define M6(A, B) M5(A, B) +#define M7(A, B) M6(A, B) +#define M8(A, B) M7(A, B) +#define M9(A, B) M8(A, B) +#define M10(A, B) M9(A, B) +#define M11(A, B) M10(A, B) +#define M12(A, B) M11(A, B) + +void f(int *ip, float *fp) { + if (M12(ip, fp)) { } + // RUN: %clang_cc1 -fsyntax-only -fmacro-backtrace-limit 5 %s 2>&1 \ + // RUN: | FileCheck %s -check-prefix=CHECK-LIMIT + // CHECK-LIMIT: macro-backtrace.c:18:7: warning: comparison of distinct pointer types ('int *' and 'float *') + // CHECK-LIMIT: if (M12(ip, fp)) { } + // CHECK-LIMIT: macro-backtrace.c:15:19: note: expanded from macro 'M12' + // CHECK-LIMIT: #define M12(A, B) M11(A, B) + // CHECK-LIMIT: macro-backtrace.c:14:19: note: expanded from macro 'M11' + // CHECK-LIMIT: #define M11(A, B) M10(A, B) + // CHECK-LIMIT: note: (skipping 7 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all) + // CHECK-LIMIT: macro-backtrace.c:6:18: note: expanded from macro 'M3' + // CHECK-LIMIT: #define M3(A, B) M2(A, B) + // CHECK-LIMIT: macro-backtrace.c:5:18: note: expanded from macro 'M2' + // CHECK-LIMIT: #define M2(A, B) M1(A, B) + // CHECK-LIMIT: macro-backtrace.c:4:23: note: expanded from macro 'M1' + // CHECK-LIMIT: #define M1(A, B) ((A) < (B)) + + // RUN: %clang_cc1 -fsyntax-only -fno-caret-diagnostics %s 2>&1 \ + // RUN: | FileCheck %s -check-prefix=CHECK-NO-CARETS + // CHECK-NO-CARETS: macro-backtrace.c:18:7: warning: comparison of distinct pointer types ('int *' and 'float *') + // CHECK-NO-CARETS-NEXT: macro-backtrace.c:15:19: note: expanded from macro 'M12' + // CHECK-NO-CARETS-NEXT: macro-backtrace.c:14:19: note: expanded from macro 'M11' + // CHECK-NO-CARETS-NEXT: macro-backtrace.c:13:19: note: expanded from macro 'M10' + // CHECK-NO-CARETS-NEXT: note: (skipping 6 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all) + // CHECK-NO-CARETS-NEXT: macro-backtrace.c:6:18: note: expanded from macro 'M3' + // CHECK-NO-CARETS-NEXT: macro-backtrace.c:5:18: note: expanded from macro 'M2' + // CHECK-NO-CARETS-NEXT: macro-backtrace.c:4:23: note: expanded from macro 'M1' + + // Check that the expansion notes respect the same formatting options as + // other diagnostics. + // RUN: %clang_cc1 -fsyntax-only -fdiagnostics-format vi %s 2>&1 \ + // RUN: | FileCheck %s -check-prefix=CHECK-NOTE-FORMAT + // CHECK-NOTE-FORMAT: macro-backtrace.c +18:7: warning: + // CHECK-NOTE-FORMAT: macro-backtrace.c +15:19: note: + // CHECK-NOTE-FORMAT: macro-backtrace.c +14:19: note: + // CHECK-NOTE-FORMAT: note: + // CHECK-NOTE-FORMAT: macro-backtrace.c +6:18: note: + // CHECK-NOTE-FORMAT: macro-backtrace.c +5:18: note: + // CHECK-NOTE-FORMAT: macro-backtrace.c +4:23: note: +} diff --git a/clang/test/Misc/message-length.c b/clang/test/Misc/message-length.c new file mode 100644 index 0000000..a6f4f44 --- /dev/null +++ b/clang/test/Misc/message-length.c @@ -0,0 +1,41 @@ +// RUN: not %clang_cc1 -fmessage-length 72 %s 2>&1 | FileCheck -strict-whitespace %s +// RUN: not %clang_cc1 -fmessage-length 1 %s +// RUN: not %clang_cc1 -fmessage-length 8 %s 2>&1 | FileCheck -check-prefix=CHECK-DOT %s +// Hack so we can check things better, force the file name and line. +# 1 "FILE" 1 + +/* It's tough to verify the results of this test mechanically, since + the length of the filename (and, therefore, how the word-wrapping + behaves) changes depending on where the test-suite resides in the + file system. */ +void f(int, float, char, float); + +void g() { + int (*fp1)(int, float, short, float) = f; + + int (*fp2)(int, float, short, float) = f; +} + +void a_func_to_call(int, int, int); + +void a_very_long_line(int *ip, float *FloatPointer) { + for (int ALongIndexName = 0; ALongIndexName < 100; ALongIndexName++) if (ip[ALongIndexName] == 17) a_func_to_call(ip == FloatPointer, ip[ALongIndexName], FloatPointer[ALongIndexName]); + + + int array0[] = { [3] 3, 5, 7, 4, 2, 7, 6, 3, 4, 5, 6, 7, 8, 9, 12, 345, 14, 345, 789, 234, 678, 345, 123, 765, 234 }; +} + +#pragma STDC CX_LIMITED_RANGE // some long comment text and a brace, eh {} + +// CHECK: FILE:23:78 +// CHECK: {{^ ...// some long comment text and a brace, eh {}}} + +struct A { int x; }; +void h(struct A *a) { + // CHECK-DOT: member + // CHECK-DOT: reference + // CHECK-DOT: type + (void)a + . + x; +} diff --git a/clang/test/Misc/predefines.c b/clang/test/Misc/predefines.c new file mode 100644 index 0000000..87f676e --- /dev/null +++ b/clang/test/Misc/predefines.c @@ -0,0 +1,5 @@ +/* RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -ffreestanding -pedantic-errors %s + * rdar://6814950 + */ +#include <stdint.h> + diff --git a/clang/test/Misc/remap-file.c b/clang/test/Misc/remap-file.c new file mode 100644 index 0000000..003cd2e --- /dev/null +++ b/clang/test/Misc/remap-file.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -remap-file "%s;%S/Inputs/remapped-file" -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-EXIST %s +// RUN: %clang_cc1 -remap-file "%S/nonexistent.c;%S/Inputs/remapped-file" -fsyntax-only %S/nonexistent.c 2>&1 | FileCheck -check-prefix=CHECK-NONEXIST %s +// RUN: %clang_cc1 -remap-file "%S/nonexistent.c;%S/Inputs/remapped-file-2" -remap-file "%S/nonexistent.h;%S/Inputs/remapped-file-3" -fsyntax-only %S/nonexistent.c 2>&1 | FileCheck -check-prefix=CHECK-HEADER %s + +// CHECK-EXIST: remap-file.c:1:28: warning: incompatible pointer types +// CHECK-NONEXIST: nonexistent.c:1:28: warning: incompatible pointer types +// CHECK-HEADER: nonexistent.c:3:19: warning: incompatible pointer types +int diff --git a/clang/test/Misc/serialized-diags-no-category.c b/clang/test/Misc/serialized-diags-no-category.c new file mode 100644 index 0000000..3074892 --- /dev/null +++ b/clang/test/Misc/serialized-diags-no-category.c @@ -0,0 +1,12 @@ +#error foo +#error bar + +// RUN: rm -f %t +// RUN: %clang -ferror-limit=1 -fsyntax-only %s --serialize-diagnostics %t > /dev/null 2>&1 || true +// RUN: c-index-test -read-diagnostics %t 2>&1 | FileCheck %s + +// This test case tests that we can handle both fatal errors and errors without categories. + +// CHECK: {{.*[/\\]}}serialized-diags-no-category.c:1:2: error: foo [] +// CHECK: Number of diagnostics: 2 + diff --git a/clang/test/Misc/serialized-diags-no-issue.c b/clang/test/Misc/serialized-diags-no-issue.c new file mode 100644 index 0000000..5c7da82 --- /dev/null +++ b/clang/test/Misc/serialized-diags-no-issue.c @@ -0,0 +1,10 @@ +void foo(); + +// RUN: %clang -Wall -fsyntax-only %s --serialize-diagnostics %t +// RUN: c-index-test -read-diagnostics %t 2>&1 | FileCheck %s +// RUN: rm -f %t + +// NOTE: it is important that this test case contains no issues. It tests +// that serialize diagnostics work in the absence of any issues. + +// CHECK: Number of diagnostics: 0 diff --git a/clang/test/Misc/serialized-diags-single-issue.c b/clang/test/Misc/serialized-diags-single-issue.c new file mode 100644 index 0000000..938dda3 --- /dev/null +++ b/clang/test/Misc/serialized-diags-single-issue.c @@ -0,0 +1,36 @@ +void foo() { + int voodoo; + voodoo = voodoo + 1; +} + +// RUN: %clang -Wall -fsyntax-only %s --serialize-diagnostics %t +// RUN: c-index-test -read-diagnostics %t 2>&1 | FileCheck %s +// RUN: rm -f %t + +// NOTE: it is important that this test case only contain a single issue. This test case checks +// if we can handle serialized diagnostics that contain only one diagnostic. + +// CHECK: {{.*}}serialized-diags-single-issue.c:3:12: warning: variable 'voodoo' is uninitialized when used here [-Wuninitialized] [Semantic Issue] +// CHECK: Range: {{.*}}serialized-diags-single-issue.c:3:12 {{.*}}serialized-diags-single-issue.c:3:18 +// CHECK: +-{{.*}}serialized-diags-single-issue.c:2:13: note: initialize the variable 'voodoo' to silence this warning [] +// CHECK: +-Range: {{.*}}serialized-diags-single-issue.c:2:13 {{.*}}serialized-diags-single-issue.c:2:13 +// CHECK: +-FIXIT: ({{.*}}serialized-diags-single-issue.c:2:13 - {{.*}}serialized-diags-single-issue.c:2:13): " = 0" + +// Test that we handle serializing diagnostics for multiple source files +// RUN: %clang_cc1 -Wall -fsyntax-only %s %s -serialize-diagnostic-file %t +// RUN: c-index-test -read-diagnostics %t 2>&1 | FileCheck -check-prefix=CHECK-MULT %s +// RUN: rm -f %t + +// CHECK-MULT: {{.*}}serialized-diags-single-issue.c:3:12: warning: variable 'voodoo' is uninitialized when used here [-Wuninitialized] +// CHECK-MULT: Range: {{.*}}serialized-diags-single-issue.c:3:12 {{.*}}serialized-diags-single-issue.c:3:18 +// CHECK-MULT: +-{{.*}}serialized-diags-single-issue.c:2:13: note: initialize the variable 'voodoo' to silence this warning [] +// CHECK-MULT: +-Range: {{.*}}serialized-diags-single-issue.c:2:13 {{.*}}serialized-diags-single-issue.c:2:13 +// CHECK-MULT: +-FIXIT: ({{.*}}serialized-diags-single-issue.c:2:13 - {{.*}}serialized-diags-single-issue.c:2:13): " = 0" + +// CHECK-MULT: {{.*}}serialized-diags-single-issue.c:3:12: warning: variable 'voodoo' is uninitialized when used here [-Wuninitialized] +// CHECK-MULT: Range: {{.*}}serialized-diags-single-issue.c:3:12 {{.*}}serialized-diags-single-issue.c:3:18 +// CHECK-MULT: +-{{.*}}serialized-diags-single-issue.c:2:13: note: initialize the variable 'voodoo' to silence this warning [] +// CHECK-MULT: +-Range: {{.*}}serialized-diags-single-issue.c:2:13 {{.*}}serialized-diags-single-issue.c:2:13 +// CHECK-MULT: +-FIXIT: ({{.*}}serialized-diags-single-issue.c:2:13 - {{.*}}serialized-diags-single-issue.c:2:13): " = 0" + +// CHECK-MULT: Number of diagnostics: 2 diff --git a/clang/test/Misc/serialized-diags.c b/clang/test/Misc/serialized-diags.c new file mode 100644 index 0000000..ae4611b --- /dev/null +++ b/clang/test/Misc/serialized-diags.c @@ -0,0 +1,67 @@ +void foo() { + int voodoo; + voodoo = voodoo + 1; +} + +void bar() { + int dragon; + dragon = dragon + 1 +} + +// Test handling of FixIts that only remove text. +int baz(); +void qux(int x) { + if ((x == baz())) + return; +} + +// Test handling of macros. +void taz(int x, int y); +#define false 0 +void testMacro() { + taz(0, 0, false); +} + +// Test handling of issues from #includes. +#include "serialized-diags.h" + +// Test handling of warnings that have empty fixits. +void rdar11040133() { + unsigned x; +} + +// RUN: rm -f %t +// RUN: %clang -Wall -fsyntax-only %s --serialize-diagnostics %t.diag > /dev/null 2>&1 || true +// RUN: c-index-test -read-diagnostics %t.diag > %t 2>&1 +// RUN: FileCheck --input-file=%t %s + +// This test case tests that we can handle multiple diagnostics which contain +// FIXITs at different levels (one at the note, another at the main diagnostic). + +// CHECK: {{.*[/\\]}}serialized-diags.c:3:12: warning: variable 'voodoo' is uninitialized when used here [-Wuninitialized] +// CHECK: Range: {{.*[/\\]}}serialized-diags.c:3:12 {{.*[/\\]}}serialized-diags.c:3:18 +// CHECK: +-{{.*[/\\]}}serialized-diags.c:2:13: note: initialize the variable 'voodoo' to silence this warning [] +// CHECK: +-FIXIT: ({{.*[/\\]}}serialized-diags.c:2:13 - {{.*[/\\]}}serialized-diags.c:2:13): " = 0" +// CHECK: {{.*[/\\]}}serialized-diags.c:8:22: error: expected ';' after expression [] +// CHECK: FIXIT: ({{.*[/\\]}}serialized-diags.c:8:22 - {{.*[/\\]}}serialized-diags.c:8:22): ";" +// CHECK: {{.*[/\\]}}serialized-diags.c:14:10: warning: equality comparison with extraneous parentheses [-Wparentheses-equality] +// CHECK: Range: {{.*[/\\]}}serialized-diags.c:14:8 {{.*[/\\]}}serialized-diags.c:14:18 +// CHECK: +-{{.*[/\\]}}serialized-diags.c:14:10: note: remove extraneous parentheses around the comparison to silence this warning [] +// CHECK: +-FIXIT: ({{.*[/\\]}}serialized-diags.c:14:7 - {{.*[/\\]}}serialized-diags.c:14:8): "" +// CHECK: +-FIXIT: ({{.*[/\\]}}serialized-diags.c:14:18 - {{.*[/\\]}}serialized-diags.c:14:19): "" +// CHECK: +-{{.*[/\\]}}serialized-diags.c:14:10: note: use '=' to turn this equality comparison into an assignment [] +// CHECK: +-FIXIT: ({{.*[/\\]}}serialized-diags.c:14:10 - {{.*[/\\]}}serialized-diags.c:14:12): "=" +// CHECK: {{.*[/\\]}}serialized-diags.c:22:13: error: too many arguments to function call, expected 2, have 3 [] +// CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 +// CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:13 {{.*[/\\]}}serialized-diags.c:22:18 +// CHECK: +-{{.*[/\\]}}serialized-diags.c:20:15: note: expanded from macro 'false' [] +// CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:22:3 {{.*[/\\]}}serialized-diags.c:22:6 +// CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:20:15 {{.*[/\\]}}serialized-diags.c:20:16 +// CHECK: +-{{.*[/\\]}}serialized-diags.c:19:1: note: 'taz' declared here [] +// CHECK: {{.*[/\\]}}serialized-diags.h:5:7: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion] +// CHECK: Range: {{.*[/\\]}}serialized-diags.h:5:16 {{.*[/\\]}}serialized-diags.h:5:17 +// CHECK: +-{{.*[/\\]}}serialized-diags.c:26:10: note: in file included from {{.*[/\\]}}serialized-diags.c:26: [] +// CHECK: Number FIXITs = 0 +// CHECK: {{.*[/\\]}}serialized-diags.c:30:12: warning: unused variable 'x' +// CHECK: Number FIXITs = 0 +// CHECK: Number of diagnostics: 6 diff --git a/clang/test/Misc/serialized-diags.h b/clang/test/Misc/serialized-diags.h new file mode 100644 index 0000000..d38a352 --- /dev/null +++ b/clang/test/Misc/serialized-diags.h @@ -0,0 +1,5 @@ +// This file intentionally has a bug. It is intended +// to be used with serialized-diagnostics.c to show +// how errors are handled with #includes in serialized +// diagnostics. +char *badStr = 1; diff --git a/clang/test/Misc/show-diag-options.c b/clang/test/Misc/show-diag-options.c new file mode 100644 index 0000000..f0404a8 --- /dev/null +++ b/clang/test/Misc/show-diag-options.c @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -fsyntax-only %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=BASE +// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=OPTION +// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -Werror %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=OPTION_ERROR +// RUN: %clang_cc1 -fsyntax-only -std=c89 -pedantic -fdiagnostics-show-option %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=OPTION_PEDANTIC +// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-category id %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=CATEGORY_ID +// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-category name %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=CATEGORY_NAME +// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -fdiagnostics-show-category name -Werror %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=OPTION_ERROR_CATEGORY + +void test(int x, int y) { + if (x = y) ++x; + // BASE: {{.*}}: warning: {{[a-z ]+$}} + // OPTION: {{.*}}: warning: {{[a-z ]+}} [-Wparentheses] + // OPTION_ERROR: {{.*}}: error: {{[a-z ]+}} [-Werror,-Wparentheses] + // CATEGORY_ID: {{.*}}: warning: {{[a-z ]+}} [2] + // CATEGORY_NAME: {{.*}}: warning: {{[a-z ]+}} [Semantic Issue] + // OPTION_ERROR_CATEGORY: {{.*}}: error: {{[a-z ]+}} [-Werror,-Wparentheses,Semantic Issue] + + // Leverage the fact that all these '//'s get warned about in C89 pedantic. + // OPTION_PEDANTIC: {{.*}}: warning: {{[/a-z ]+}} [-pedantic,-Wcomment] +} diff --git a/clang/test/Misc/tabstop.c b/clang/test/Misc/tabstop.c new file mode 100644 index 0000000..49c4d7b --- /dev/null +++ b/clang/test/Misc/tabstop.c @@ -0,0 +1,47 @@ +// RUN: %clang_cc1 -ftabstop 3 -fsyntax-only %s 2>&1 | FileCheck -check-prefix=3 -strict-whitespace %s +// RUN: %clang_cc1 -ftabstop 4 -fsyntax-only %s 2>&1 | FileCheck -check-prefix=4 -strict-whitespace %s +// RUN: %clang_cc1 -ftabstop 5 -fsyntax-only %s 2>&1 | FileCheck -check-prefix=5 -strict-whitespace %s + +// tab + void* a = 1; + +// tab tab + void* b = 1; + +// 3x space tab + void* c = 1; + +// tab at column 10 +void* d = 1; + +//CHECK-3: {{^ void\* a = 1;}} +//CHECK-3: {{^ void\* b = 1;}} +//CHECK-3: {{^ void\* c = 1;}} +//CHECK-3: {{^void\* d = 1;}} + +//CHECK-4: {{^ void\* a = 1;}} +//CHECK-4: {{^ void\* b = 1;}} +//CHECK-4: {{^ void\* c = 1;}} +//CHECK-4: {{^void\* d = 1;}} + +//CHECK-5: {{^ void\* a = 1;}} +//CHECK-5: {{^ void\* b = 1;}} +//CHECK-5: {{^ void\* c = 1;}} +//CHECK-5: {{^void\* d = 1;}} + +// Test code modification hints + +void f(void) +{ + if (0 & 1 == 1) + {} +} + +// CHECK-3: {{^ }}if (0 & 1 == 1) +// CHECK-3: {{^ }} ( ) + +// CHECK-4: {{^ }}if (0 & 1 == 1) +// CHECK-4: {{^ }} ( ) + +// CHECK-5: {{^ }}if (0 & 1 == 1) +// CHECK-5: {{^ }} ( ) diff --git a/clang/test/Misc/unprintable.c b/clang/test/Misc/unprintable.c new file mode 100644 index 0000000..860503e --- /dev/null +++ b/clang/test/Misc/unprintable.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 %s 2>&1 | FileCheck -strict-whitespace %s + +int main() { + int i; + if((i==/*👿*/1)); + +// CHECK: {{^ if\(\(i==/\*<U\+1F47F>\*/1\)\);}} + +// CHECK: {{^ ~\^~~~~~~~~~~~~~~~}} +// CHECK: {{^ ~ \^ ~}} + + /* 👿 */ "👿berhund"; + +// CHECK: {{^ /\* <U\+1F47F> \*/ "<U\+1F47F>berhund";}} +// CHECK: {{^ \^~~~~~~~~~~~~~~~~~}} +}
\ No newline at end of file diff --git a/clang/test/Misc/verify.c b/clang/test/Misc/verify.c new file mode 100644 index 0000000..85b034e --- /dev/null +++ b/clang/test/Misc/verify.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct s; // expected-note 7 {{forward declaration of 'struct s'}} + +// standard string matching +struct s s1; // expected-error {{tentative definition has type 'struct s' that is never completed}} +struct s s2; // expected-error {{tentative definition has type}} + +// regex matching +struct s r1; // expected-error-re {{tentative definition has type 'struct s' that is never completed}} +struct s r2; // expected-error-re {{tentative definition has type '.*[[:space:]]*.*' that is never completed}} +struct s r3; // expected-error-re {{tentative definition has type '(.*)[[:space:]]*(.*)' that is never completed}} +struct s r4; // expected-error-re {{^tentative}} +struct s r5; // expected-error-re {{completed$}} diff --git a/clang/test/Misc/warn-in-system-header.c b/clang/test/Misc/warn-in-system-header.c new file mode 100644 index 0000000..6e0237d --- /dev/null +++ b/clang/test/Misc/warn-in-system-header.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -isystem %S %s -fsyntax-only -verify + +#include <warn-in-system-header.h> +// expected-warning {{the cake is a lie}} diff --git a/clang/test/Misc/warn-in-system-header.h b/clang/test/Misc/warn-in-system-header.h new file mode 100644 index 0000000..5e127b9 --- /dev/null +++ b/clang/test/Misc/warn-in-system-header.h @@ -0,0 +1,4 @@ + + + +#warning the cake is a lie diff --git a/clang/test/Misc/warning-flags.c b/clang/test/Misc/warning-flags.c new file mode 100644 index 0000000..bc0c941 --- /dev/null +++ b/clang/test/Misc/warning-flags.c @@ -0,0 +1,273 @@ +RUN: diagtool list-warnings 2>&1 | FileCheck %s + +This test serves two purposes: + +(1) It documents all existing warnings that currently have no associated -W flag, + and ensures that the list never grows. + + If take an existing warning and add a flag, this test will fail. To + fix this test, simply remove that warning from the list below. + +(2) It prevents us adding new warnings to Clang that have no -W flag. All + new warnings should have -W flags. + + If you add a new warning without a flag, this test will fail. To fix + this test, simply add a warning group to that warning. + + +The list of warnings below should NEVER grow. It should gradually shrink to 0. + +CHECK: Warnings without flags (253): +CHECK-NEXT: ext_anonymous_struct_union_qualified +CHECK-NEXT: ext_binary_literal +CHECK-NEXT: ext_cast_fn_obj +CHECK-NEXT: ext_delete_void_ptr_operand +CHECK-NEXT: ext_designated_init +CHECK-NEXT: ext_duplicate_declspec +CHECK-NEXT: ext_ellipsis_exception_spec +CHECK-NEXT: ext_empty_fnmacro_arg +CHECK-NEXT: ext_empty_source_file +CHECK-NEXT: ext_enum_friend +CHECK-NEXT: ext_enum_value_not_int +CHECK-NEXT: ext_enumerator_list_comma +CHECK-NEXT: ext_expected_semi_decl_list +CHECK-NEXT: ext_explicit_instantiation_without_qualified_id +CHECK-NEXT: ext_explicit_specialization_storage_class +CHECK-NEXT: ext_extra_ivar_semi +CHECK-NEXT: ext_extra_struct_semi +CHECK-NEXT: ext_forward_ref_enum +CHECK-NEXT: ext_freestanding_complex +CHECK-NEXT: ext_hexconstant_invalid +CHECK-NEXT: ext_ident_list_in_param +CHECK-NEXT: ext_imaginary_constant +CHECK-NEXT: ext_implicit_lib_function_decl +CHECK-NEXT: ext_in_class_initializer_non_constant +CHECK-NEXT: ext_integer_complement_complex +CHECK-NEXT: ext_integer_complex +CHECK-NEXT: ext_integer_increment_complex +CHECK-NEXT: ext_invalid_sign_spec +CHECK-NEXT: ext_missing_declspec +CHECK-NEXT: ext_missing_varargs_arg +CHECK-NEXT: ext_missing_whitespace_after_macro_name +CHECK-NEXT: ext_new_paren_array_nonconst +CHECK-NEXT: ext_nonstandard_escape +CHECK-NEXT: ext_param_not_declared +CHECK-NEXT: ext_paste_comma +CHECK-NEXT: ext_plain_complex +CHECK-NEXT: ext_pp_bad_vaargs_use +CHECK-NEXT: ext_pp_comma_expr +CHECK-NEXT: ext_pp_ident_directive +CHECK-NEXT: ext_pp_include_next_directive +CHECK-NEXT: ext_pp_line_too_big +CHECK-NEXT: ext_pp_macro_redef +CHECK-NEXT: ext_pp_warning_directive +CHECK-NEXT: ext_return_has_void_expr +CHECK-NEXT: ext_subscript_non_lvalue +CHECK-NEXT: ext_template_arg_extra_parens +CHECK-NEXT: ext_thread_before +CHECK-NEXT: ext_top_level_semi +CHECK-NEXT: ext_typecheck_addrof_void +CHECK-NEXT: ext_typecheck_cast_nonscalar +CHECK-NEXT: ext_typecheck_cast_to_union +CHECK-NEXT: ext_typecheck_comparison_of_distinct_pointers +CHECK-NEXT: ext_typecheck_comparison_of_distinct_pointers_nonstandard +CHECK-NEXT: ext_typecheck_comparison_of_fptr_to_void +CHECK-NEXT: ext_typecheck_comparison_of_pointer_integer +CHECK-NEXT: ext_typecheck_cond_incompatible_operands +CHECK-NEXT: ext_typecheck_cond_incompatible_operands_nonstandard +CHECK-NEXT: ext_typecheck_cond_one_void +CHECK-NEXT: ext_typecheck_convert_pointer_void_func +CHECK-NEXT: ext_typecheck_ordered_comparison_of_function_pointers +CHECK-NEXT: ext_typecheck_ordered_comparison_of_pointer_and_zero +CHECK-NEXT: ext_typecheck_ordered_comparison_of_pointer_integer +CHECK-NEXT: ext_typecheck_zero_array_size +CHECK-NEXT: ext_unknown_escape +CHECK-NEXT: ext_using_undefined_std +CHECK-NEXT: ext_vla_folded_to_constant +CHECK-NEXT: pp_include_next_absolute_path +CHECK-NEXT: pp_include_next_in_primary +CHECK-NEXT: pp_invalid_string_literal +CHECK-NEXT: pp_out_of_date_dependency +CHECK-NEXT: pp_poisoning_existing_macro +CHECK-NEXT: pp_pragma_once_in_main_file +CHECK-NEXT: pp_pragma_sysheader_in_main_file +CHECK-NEXT: pp_undef_builtin_macro +CHECK-NEXT: w_asm_qualifier_ignored +CHECK-NEXT: warn_accessor_property_type_mismatch +CHECK-NEXT: warn_anon_bitfield_width_exceeds_type_size +CHECK-NEXT: warn_asm_label_on_auto_decl +CHECK-NEXT: warn_attribute_ibaction +CHECK-NEXT: warn_attribute_iboutlet +CHECK-NEXT: warn_attribute_ignored +CHECK-NEXT: warn_attribute_ignored_for_field_of_type +CHECK-NEXT: warn_attribute_malloc_pointer_only +CHECK-NEXT: warn_attribute_nonnull_no_pointers +CHECK-NEXT: warn_attribute_precede_definition +CHECK-NEXT: warn_attribute_sentinel_named_arguments +CHECK-NEXT: warn_attribute_sentinel_not_variadic +CHECK-NEXT: warn_attribute_type_not_supported +CHECK-NEXT: warn_attribute_unknown_visibility +CHECK-NEXT: warn_attribute_void_function_method +CHECK-NEXT: warn_attribute_weak_import_invalid_on_definition +CHECK-NEXT: warn_attribute_weak_on_field +CHECK-NEXT: warn_attribute_weak_on_local +CHECK-NEXT: warn_attribute_wrong_decl_type +CHECK-NEXT: warn_availability_and_unavailable +CHECK-NEXT: warn_availability_unknown_platform +CHECK-NEXT: warn_availability_version_ordering +CHECK-NEXT: warn_bad_receiver_type +CHECK-NEXT: warn_bitfield_width_exceeds_type_size +CHECK-NEXT: warn_bool_switch_condition +CHECK-NEXT: warn_braces_around_scalar_init +CHECK-NEXT: warn_c_kext +CHECK-NEXT: warn_call_to_pure_virtual_member_function_from_ctor_dtor +CHECK-NEXT: warn_call_wrong_number_of_arguments +CHECK-NEXT: warn_case_empty_range +CHECK-NEXT: warn_char_constant_too_large +CHECK-NEXT: warn_class_method_not_found +CHECK-NEXT: warn_cmdline_missing_macro_defs +CHECK-NEXT: warn_collection_expr_type +CHECK-NEXT: warn_conflicting_param_types +CHECK-NEXT: warn_conflicting_ret_types +CHECK-NEXT: warn_conflicting_variadic +CHECK-NEXT: warn_conv_to_base_not_used +CHECK-NEXT: warn_conv_to_self_not_used +CHECK-NEXT: warn_conv_to_void_not_used +CHECK-NEXT: warn_cxx0x_right_shift_in_template_arg +CHECK-NEXT: warn_delete_array_type +CHECK-NEXT: warn_division_by_zero +CHECK-NEXT: warn_double_const_requires_fp64 +CHECK-NEXT: warn_drv_assuming_mfloat_abi_is +CHECK-NEXT: warn_drv_clang_unsupported +CHECK-NEXT: warn_drv_input_file_unused +CHECK-NEXT: warn_drv_not_using_clang_arch +CHECK-NEXT: warn_drv_not_using_clang_cpp +CHECK-NEXT: warn_drv_not_using_clang_cxx +CHECK-NEXT: warn_drv_objc_gc_unsupported +CHECK-NEXT: warn_drv_pch_not_first_include +CHECK-NEXT: warn_drv_preprocessed_input_file_unused +CHECK-NEXT: warn_dup_category_def +CHECK-NEXT: warn_duplicate_protocol_def +CHECK-NEXT: warn_enum_too_large +CHECK-NEXT: warn_enum_value_overflow +CHECK-NEXT: warn_enumerator_too_large +CHECK-NEXT: warn_exception_caught_by_earlier_handler +CHECK-NEXT: warn_excess_initializers +CHECK-NEXT: warn_excess_initializers_in_char_array_initializer +CHECK-NEXT: warn_expected_qualified_after_typename +CHECK-NEXT: warn_extern_init +CHECK-NEXT: warn_extraneous_char_constant +CHECK-NEXT: warn_fe_cc_log_diagnostics_failure +CHECK-NEXT: warn_fe_cc_print_header_failure +CHECK-NEXT: warn_fe_macro_contains_embedded_newline +CHECK-NEXT: warn_file_asm_volatile +CHECK-NEXT: warn_function_attribute_wrong_type +CHECK-NEXT: warn_gc_attribute_weak_on_local +CHECK-NEXT: warn_gnu_inline_attribute_requires_inline +CHECK-NEXT: warn_hex_escape_too_large +CHECK-NEXT: warn_ignoring_ftabstop_value +CHECK-NEXT: warn_illegal_constant_array_size +CHECK-NEXT: warn_implements_nscopying +CHECK-NEXT: warn_incompatible_qualified_id +CHECK-NEXT: warn_initializer_string_for_char_array_too_long +CHECK-NEXT: warn_inline_namespace_reopened_noninline +CHECK-NEXT: warn_inst_method_not_found +CHECK-NEXT: warn_instance_method_on_class_found +CHECK-NEXT: warn_integer_too_large +CHECK-NEXT: warn_integer_too_large_for_signed +CHECK-NEXT: warn_invalid_asm_cast_lvalue +CHECK-NEXT: warn_many_braces_around_scalar_init +CHECK-NEXT: warn_maynot_respond +CHECK-NEXT: warn_member_extra_qualification +CHECK-NEXT: warn_method_param_redefinition +CHECK-NEXT: warn_mismatched_exception_spec +CHECK-NEXT: warn_missing_case_for_condition +CHECK-NEXT: warn_missing_dependent_template_keyword +CHECK-NEXT: warn_missing_exception_specification +CHECK-NEXT: warn_missing_whitespace_after_macro_name +CHECK-NEXT: warn_multiple_method_decl +CHECK-NEXT: warn_no_constructor_for_refconst +CHECK-NEXT: warn_nonnull_pointers_only +CHECK-NEXT: warn_not_compound_assign +CHECK-NEXT: warn_ns_attribute_wrong_parameter_type +CHECK-NEXT: warn_ns_attribute_wrong_return_type +CHECK-NEXT: warn_objc_object_attribute_wrong_type +CHECK-NEXT: warn_objc_property_copy_missing_on_block +CHECK-NEXT: warn_objc_property_default_assign_on_object +CHECK-NEXT: warn_objc_property_no_assignment_attribute +CHECK-NEXT: warn_objc_protocol_qualifier_missing_id +CHECK-NEXT: warn_octal_escape_too_large +CHECK-NEXT: warn_odr_tag_type_inconsistent +CHECK-NEXT: warn_on_superclass_use +CHECK-NEXT: warn_param_default_argument_redefinition +CHECK-NEXT: warn_partial_specs_not_deducible +CHECK-NEXT: warn_pointer_attribute_wrong_type +CHECK-NEXT: warn_pp_convert_lhs_to_positive +CHECK-NEXT: warn_pp_convert_rhs_to_positive +CHECK-NEXT: warn_pp_expr_overflow +CHECK-NEXT: warn_pp_line_decimal +CHECK-NEXT: warn_pragma_align_expected_equal +CHECK-NEXT: warn_pragma_align_invalid_option +CHECK-NEXT: warn_pragma_debug_unexpected_command +CHECK-NEXT: warn_pragma_expected_colon +CHECK-NEXT: warn_pragma_expected_enable_disable +CHECK-NEXT: warn_pragma_expected_identifier +CHECK-NEXT: warn_pragma_expected_lparen +CHECK-NEXT: warn_pragma_expected_rparen +CHECK-NEXT: warn_pragma_extra_tokens_at_eol +CHECK-NEXT: warn_pragma_ms_struct +CHECK-NEXT: warn_pragma_options_align_reset_failed +CHECK-NEXT: warn_pragma_options_align_unsupported_option +CHECK-NEXT: warn_pragma_options_expected_align +CHECK-NEXT: warn_pragma_pack_invalid_action +CHECK-NEXT: warn_pragma_pack_invalid_alignment +CHECK-NEXT: warn_pragma_pack_malformed +CHECK-NEXT: warn_pragma_pack_pop_failed +CHECK-NEXT: warn_pragma_pack_pop_identifer_and_alignment +CHECK-NEXT: warn_pragma_pack_show +CHECK-NEXT: warn_pragma_pop_macro_no_push +CHECK-NEXT: warn_pragma_unknown_extension +CHECK-NEXT: warn_pragma_unused_expected_punc +CHECK-NEXT: warn_pragma_unused_expected_var +CHECK-NEXT: warn_pragma_unused_expected_var_arg +CHECK-NEXT: warn_pragma_unused_undeclared_var +CHECK-NEXT: warn_previous_alias_decl +CHECK-NEXT: warn_printf_asterisk_missing_arg +CHECK-NEXT: warn_property_attr_mismatch +CHECK-NEXT: warn_property_attribute +CHECK-NEXT: warn_property_getter_owning_mismatch +CHECK-NEXT: warn_property_types_are_incompatible +CHECK-NEXT: warn_readonly_property +CHECK-NEXT: warn_receiver_forward_class +CHECK-NEXT: warn_redecl_library_builtin +CHECK-NEXT: warn_redeclaration_without_attribute_prev_attribute_ignored +CHECK-NEXT: warn_register_objc_catch_parm +CHECK-NEXT: warn_related_result_type_compatibility_class +CHECK-NEXT: warn_related_result_type_compatibility_protocol +CHECK-NEXT: warn_remainder_by_zero +CHECK-NEXT: warn_root_inst_method_not_found +CHECK-NEXT: warn_second_parameter_of_va_start_not_last_named_argument +CHECK-NEXT: warn_second_parameter_to_va_arg_never_compatible +CHECK-NEXT: warn_standalone_specifier +CHECK-NEXT: warn_static_inline_explicit_inst_ignored +CHECK-NEXT: warn_static_non_static +CHECK-NEXT: warn_template_export_unsupported +CHECK-NEXT: warn_template_spec_extra_headers +CHECK-NEXT: warn_tentative_incomplete_array +CHECK-NEXT: warn_transparent_union_attribute_field_size_align +CHECK-NEXT: warn_transparent_union_attribute_floating +CHECK-NEXT: warn_transparent_union_attribute_not_definition +CHECK-NEXT: warn_transparent_union_attribute_zero_fields +CHECK-NEXT: warn_typecheck_function_qualifiers +CHECK-NEXT: warn_unavailable_fwdclass_message +CHECK-NEXT: warn_undef_interface +CHECK-NEXT: warn_undef_interface_suggest +CHECK-NEXT: warn_undef_protocolref +CHECK-NEXT: warn_undefined_internal +CHECK-NEXT: warn_unknown_analyzer_checker +CHECK-NEXT: warn_unknown_method_family +CHECK-NEXT: warn_unterminated_char +CHECK-NEXT: warn_unterminated_string +CHECK-NEXT: warn_use_out_of_scope_declaration +CHECK-NEXT: warn_weak_identifier_undeclared +CHECK-NEXT: warn_weak_import diff --git a/clang/test/Misc/wnull-character.cpp b/clang/test/Misc/wnull-character.cpp Binary files differnew file mode 100644 index 0000000..a618da2 --- /dev/null +++ b/clang/test/Misc/wnull-character.cpp diff --git a/clang/test/Misc/working-directory.c b/clang/test/Misc/working-directory.c new file mode 100644 index 0000000..5c71d9f --- /dev/null +++ b/clang/test/Misc/working-directory.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -working-directory %S working-directory.c -IInputs -fsyntax-only + +#include "working-directory.h" + +Foo bar; diff --git a/clang/test/Misc/wrong-encoding.c b/clang/test/Misc/wrong-encoding.c new file mode 100644 index 0000000..bd1cf3d --- /dev/null +++ b/clang/test/Misc/wrong-encoding.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -strict-whitespace %s + +void foo() { + + "§Ã"; // ø +// CHECK: {{^ "<A7><C3>"; // <F8>}} +// CHECK: {{^ \^}} + + /* þ« */ const char *d = "¥"; + +// CHECK: {{^ /\* <FE><AB> \*/ const char \*d = "<A5>";}} +// CHECK: {{^ \^}} + +// CHECK: {{^ "<A7><C3>"; // <F8>}} +// CHECK: {{^ \^~~~~~~~~~}} +} |