diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-07-11 17:01:13 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-07-11 17:01:13 +0000 |
commit | 5f016e2cb5d11daeb237544de1c5d59f20fe1a6e (patch) | |
tree | 8b6bfcb8783d16827f896d5facbd4549300e8a1e /test/Parser | |
parent | a5f182095bf2065ca94f1c86957ee91f9068964b (diff) |
Stage two of getting CFE top correct.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39734 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Parser')
-rw-r--r-- | test/Parser/CompoundStmtScope.c | 8 | ||||
-rw-r--r-- | test/Parser/argument_qualified.c | 5 | ||||
-rw-r--r-- | test/Parser/argument_redef.c | 6 | ||||
-rw-r--r-- | test/Parser/argument_scope.c | 6 | ||||
-rw-r--r-- | test/Parser/attributes.c | 6 | ||||
-rw-r--r-- | test/Parser/bad-control.c | 9 | ||||
-rw-r--r-- | test/Parser/c-namespace.c | 6 | ||||
-rw-r--r-- | test/Parser/cxx-bool.cpp | 4 | ||||
-rw-r--r-- | test/Parser/cxx-casting.cpp | 32 | ||||
-rw-r--r-- | test/Parser/cxx-reference.cpp | 17 | ||||
-rw-r--r-- | test/Parser/declarators.c | 28 | ||||
-rw-r--r-- | test/Parser/expressions.c | 30 | ||||
-rw-r--r-- | test/Parser/function-decls.c | 10 | ||||
-rw-r--r-- | test/Parser/portability.c | 5 | ||||
-rw-r--r-- | test/Parser/recovery-1.c | 7 | ||||
-rw-r--r-- | test/Parser/statements.c | 49 | ||||
-rw-r--r-- | test/Parser/struct-recursion.c | 11 | ||||
-rw-r--r-- | test/Parser/types.c | 6 |
18 files changed, 245 insertions, 0 deletions
diff --git a/test/Parser/CompoundStmtScope.c b/test/Parser/CompoundStmtScope.c new file mode 100644 index 0000000000..d6a4730632 --- /dev/null +++ b/test/Parser/CompoundStmtScope.c @@ -0,0 +1,8 @@ +// RUN: clang -parse-ast-check %s + +int foo() { + { + typedef float X; + } + X Y; // expected-error {{use of undeclared identifier}} +} diff --git a/test/Parser/argument_qualified.c b/test/Parser/argument_qualified.c new file mode 100644 index 0000000000..cd92c3258c --- /dev/null +++ b/test/Parser/argument_qualified.c @@ -0,0 +1,5 @@ +// RUN: clang %s +int abc (const float x) { + return 1; +} + diff --git a/test/Parser/argument_redef.c b/test/Parser/argument_redef.c new file mode 100644 index 0000000000..c3dae512a3 --- /dev/null +++ b/test/Parser/argument_redef.c @@ -0,0 +1,6 @@ +/* RUN: clang -parse-ast-check %s +*/ + +int foo(int A) { /* expected-error {{previous definition is here}} */ + int A; /* expected-error {{redefinition of 'A'}} */ +} diff --git a/test/Parser/argument_scope.c b/test/Parser/argument_scope.c new file mode 100644 index 0000000000..8b9f065c82 --- /dev/null +++ b/test/Parser/argument_scope.c @@ -0,0 +1,6 @@ +// RUN: clang -fsyntax-only %s +typedef struct foo foo; + +void blah(int foo) { + foo = 1; +} diff --git a/test/Parser/attributes.c b/test/Parser/attributes.c new file mode 100644 index 0000000000..29e8c81f3b --- /dev/null +++ b/test/Parser/attributes.c @@ -0,0 +1,6 @@ +// RUN: clang -parse-ast-check %s + +static __inline void __attribute__((__always_inline__, __nodebug__)) // expected-warning {{extension used}} +foo (void) +{ +} diff --git a/test/Parser/bad-control.c b/test/Parser/bad-control.c new file mode 100644 index 0000000000..914393461a --- /dev/null +++ b/test/Parser/bad-control.c @@ -0,0 +1,9 @@ +/* RUN: clang -parse-ast-check %s +*/ +int foo() { + break; /* expected-error {{'break' statement not in loop or switch statement}} */ +} + +int foo2() { + continue; /* expected-error {{'continue' statement not in loop statement}} */ +} diff --git a/test/Parser/c-namespace.c b/test/Parser/c-namespace.c new file mode 100644 index 0000000000..2b380503ac --- /dev/null +++ b/test/Parser/c-namespace.c @@ -0,0 +1,6 @@ +// RUN: clang -fsyntax-only %s +void bla1() { + struct XXX; + int XXX; +} + diff --git a/test/Parser/cxx-bool.cpp b/test/Parser/cxx-bool.cpp new file mode 100644 index 0000000000..623dcb2887 --- /dev/null +++ b/test/Parser/cxx-bool.cpp @@ -0,0 +1,4 @@ +// RUN: clang -fsyntax-only %s + +bool a = true; +bool b = false; diff --git a/test/Parser/cxx-casting.cpp b/test/Parser/cxx-casting.cpp new file mode 100644 index 0000000000..638985faf7 --- /dev/null +++ b/test/Parser/cxx-casting.cpp @@ -0,0 +1,32 @@ +// RUN: clang -fsyntax-only %s +// XFAIL: * + +char *const_cast_test(const char *var) +{ + return const_cast<char*>(var); +} + +#if 0 +// FIXME: Uncomment when C++ is supported more. +struct A { + virtual ~A() {} +}; + +struct B : public A { +}; + +struct B *dynamic_cast_test(struct A *a) +{ + return dynamic_cast<struct B*>(a); +} +#endif + +char *reinterpret_cast_test() +{ + return reinterpret_cast<char*>(0xdeadbeef); +} + +double static_cast_test(int i) +{ + return static_cast<double>(i); +} diff --git a/test/Parser/cxx-reference.cpp b/test/Parser/cxx-reference.cpp new file mode 100644 index 0000000000..44a2a03c9c --- /dev/null +++ b/test/Parser/cxx-reference.cpp @@ -0,0 +1,17 @@ +// RUN: clang -parse-ast-check %s + +extern char *bork; +char *& bar = bork; + +void foo(int &a) { +} + +typedef int & A; + +void g(const A aref) { +} + +int & const X; // expected-error {{'const' qualifier may not be applied to a reference}} +int & volatile Y; // expected-error {{'volatile' qualifier may not be applied to a reference}} +int & const volatile Z; /* expected-error {{'const' qualifier may not be applied}} \ + expected-error {{'volatile' qualifier may not be applied}} */ diff --git a/test/Parser/declarators.c b/test/Parser/declarators.c new file mode 100644 index 0000000000..af599f82fe --- /dev/null +++ b/test/Parser/declarators.c @@ -0,0 +1,28 @@ +// RUN: clang %s -fsyntax-only + +extern int a1[]; + +void f0(); +void f1(int [*]); +void f2(int [const *]); +void f3(int [volatile const*]); +int f4(*XX)(void); + +char ((((*X)))); + +void (*signal(int, void (*)(int)))(int); + +int a, ***C, * const D, b(int); + +int *A; + +struct str; + +int test2(int *P, int A) { + struct str; + + // Hard case for array decl, not Array[*]. + int Array[*(int*)P+A]; +} + + diff --git a/test/Parser/expressions.c b/test/Parser/expressions.c new file mode 100644 index 0000000000..77201a80f9 --- /dev/null +++ b/test/Parser/expressions.c @@ -0,0 +1,30 @@ +// RUN: clang -fsyntax-only %s + +void test1() { + if (sizeof (int){ 1}); // sizeof compound literal + if (sizeof (int)); // sizeof type + + (int)4; // cast. + (int){4}; // compound literal. + + // FIXME: change this to the struct version when we can. + //int A = (struct{ int a;}){ 1}.a; + int A = (int){ 1}.a; +} + +int test2(int a, int b) { + return a ? a,b : a; +} + +int test3(int a, int b, int c) { + return a = b = c; +} + +int test4() { + test4(); +} + +int test_offsetof() { + // FIXME: change into something that is semantically correct. + __builtin_offsetof(int, a.b.c[4][5]); +} diff --git a/test/Parser/function-decls.c b/test/Parser/function-decls.c new file mode 100644 index 0000000000..ef93756cc6 --- /dev/null +++ b/test/Parser/function-decls.c @@ -0,0 +1,10 @@ +/* RUN: clang %s -parse-ast-print + */ + +void foo() { + int X; + X = sizeof(void (*(*)())()); + X = sizeof(int(*)(int, float, ...)); + X = sizeof(void (*(int arga, void (*argb)(double Y)))(void* Z)); +} + diff --git a/test/Parser/portability.c b/test/Parser/portability.c new file mode 100644 index 0000000000..a96aee5c65 --- /dev/null +++ b/test/Parser/portability.c @@ -0,0 +1,5 @@ +// RUN: clang -arch ppc -arch linux -fsyntax-only %s 2>&1 | grep note | wc -l | grep 1 + +// wchar_t varies across targets. +void *X = L"foo"; + diff --git a/test/Parser/recovery-1.c b/test/Parser/recovery-1.c new file mode 100644 index 0000000000..4dd1af17f4 --- /dev/null +++ b/test/Parser/recovery-1.c @@ -0,0 +1,7 @@ +// RUN: clang -fsyntax-only -fno-caret-diagnostics -pedantic %s 2>&1 | grep warning | wc -l | grep 1 +// RUN: clang -parse-ast-check %s + +char (((( /* expected-error {{to match this '('}} */ +*X x ] )))); /* expected-error {{expected ')'}} */ + +; // expected-warning {{ISO C does not allow an extra ';' outside of a function}} diff --git a/test/Parser/statements.c b/test/Parser/statements.c new file mode 100644 index 0000000000..b3f043eaaa --- /dev/null +++ b/test/Parser/statements.c @@ -0,0 +1,49 @@ +// RUN: clang -fsyntax-only %s + +int test1() { + { ; { ;;}} ;; +} + +int test2() { + if (0) { if (1) {} } else { } + + do { } while (0); + + while (0) while(0) do ; while(0); + + for (0;0;0) + for (;;) + for (9;0;2) + ; + for (int X = 0; 0; 0); +} + +int test3() { + switch (0) { + + case 4: + if (0) { + case 6: ; + } + default: + ; + } +} + +int test4() { + if (0); + + int X; // declaration in a block. + +foo: if (0); +} + +typedef int t; +void test5() { + if (0); + + //t x = 0; // FIXME: Enable when handling of typedef names is impl. + + if (0); +} + diff --git a/test/Parser/struct-recursion.c b/test/Parser/struct-recursion.c new file mode 100644 index 0000000000..c16f9fc185 --- /dev/null +++ b/test/Parser/struct-recursion.c @@ -0,0 +1,11 @@ +// RUN: clang %s -fsyntax-only + +// C99 6.7.2.3p11 + +// mutually recursive structs +struct s1 { struct s2 *A; }; +struct s2 { struct s1 *B; }; + +// both types are complete now. +struct s1 a; +struct s2 b; diff --git a/test/Parser/types.c b/test/Parser/types.c new file mode 100644 index 0000000000..f1ffb94b98 --- /dev/null +++ b/test/Parser/types.c @@ -0,0 +1,6 @@ +// RUN: clang %s -fsyntax-only + +// Test the X can be overloaded inside the struct. +typedef int X; +struct Y { short X; }; + |