Additional tests for generic and no-prototype functions. (#185)

- Test that generic no-prototype functions cannot be declared.
- Test that generic K&R old-style functions cannot be declared.
- Test generic functions applied to an empty type argument list.  Make
  sure an error is emitted if type arguments are expected.
- Stop capitalizing the first word of some error messages for generic
  functions.
- Stop checking notes issued by clang in Checked C language tests.  These
  are implementation-specific details that don't belong in language tests.
- Improve tests that K&R old-style functions can be declared or used within
  checked blocks.  We weren't testing that K&R style functions cannot
  be declared within checked blocks.
This commit is contained in:
David Tarditi 2017-08-02 16:50:22 -07:00 коммит произвёл GitHub
Родитель 72b6ba50b0
Коммит 10da185e53
6 изменённых файлов: 90 добавлений и 42 удалений

Просмотреть файл

@ -1,24 +0,0 @@
// Tests to make sure that it generates errors in the case when generic function
// call does not specify correct number of type arguments.
//
// RUN: %clang_cc1 -fcheckedc-extension -verify %s
_For_any(T) int oneTypeVariable(_Ptr<T> a, _Ptr<T> b) { //expected-note{{Type variable(s) declared here}}
return 0;
}
_For_any(T, S, R, V) int manyTypeVariables(_Ptr<T> t, _Ptr<S> s, _Ptr<R> r, _Ptr<V> v) { //expected-note{{Type variable(s) declared here}}
return 0;
}
void CallGenericFunction() {
int a = 0, b = 0, c = 0, d = 0;
_Ptr<int> ap = &a;
_Ptr<int> bp = &b;
_Ptr<int> cp = &c;
_Ptr<int> dp = &d;
oneTypeVariable<int, int>(ap, bp); //expected-error{{Mismatch between the number of types listed and number of type variables}}
manyTypeVariables<int, int>(ap, bp, cp, dp); //expected-error{{Mismatch between the number of types listed and number of type variables}}
}

Просмотреть файл

@ -1,10 +1,9 @@
// Tests to make sure _For_any errors are produced correctly.
//
// More specifically, we are testing for following errors.
// 1) _For_any() must have type declaration in parenthesis.
// 1) _For_any() must have a list of type variables within the parentheses.
// 2) Make sure type declaration syntax error is caught.
// 3) _For_any scope should be confined within function declaration.
// For this test file, we expect that there are no errors.
//
// RUN: %clang_cc1 -fcheckedc-extension -verify %s
@ -13,4 +12,4 @@ _For_any(R) _Ptr<R> foo(void);
R *thisShouldProduceError; //expected-error{{unknown type name 'R'}}
_For_any() void foo2(void); // expected-error{{expected type variable identifier}}
_For_any(R, ) _Ptr<R> foo3(void); // expected-error{{expected type variable identifier}}
_For_any(R T) _Ptr<R> foo4(void); // expected-error{{expected , or )}}
_For_any(R T) _Ptr<R> foo4(void); // expected-error{{expected , or )}}

Просмотреть файл

@ -1,6 +1,5 @@
// Tests to make sure generic function call errors are parsed correctly.
//
// Make sure that syntatic error in calling generic functions are handled
// Tests to make sure parsing errors for generic function calls are detected
// properly.
//
// RUN: %clang_cc1 -fcheckedc-extension -verify %s

Просмотреть файл

@ -188,33 +188,65 @@ void test_bounds_safe_interface(void) {
array_ptr<int> arr3 = checked_realloc(unchecked_ptr, 20); // expected-error {{cannot use a variable with an unchecked type in a checked scope or function}}
}
// Test for no-prototype function
// Especially, test KNR parameters function, that func(a,b,c) int a,b,c; {...}
// KNR parameter function has valid parameters but declared outside of function
// In function call, it is treated as no-prototype function call
// Therefore, this type of function call SHOULD be prevented in checked scope
// Test that functions declared with old-style K&R parameter lists cannot
// be declared or used in checked scopes. These are no prototype functions,
// so no typechecking of actual arguments against formal argument is done.
// This could lead to uncaught errors at runtime, so we do not allow them
// in checked scopes.
int KNR_func1(a, b, c) int a,b,c; {
// First test declarations.
int KNR_func1(a, b, c) // expected-error {{function without a prototype cannot be used or declared in a checked scope}}
int a, b, c;
{
return 1;
}
int KNR_func2(a, b) ptr<int> a; int b; {
int KNR_func2(a, b) // expected-error {{function without a prototype cannot be used or declared in a checked scope}}
ptr<int> a;
int b;
{
return 1;
}
int KNR_func3(a, b) ptr<char> a; ptr<int> b; {
int KNR_func3(a, b) // expected-error {{function without a prototype cannot be used or declared in a checked scope}}
ptr<char> a;
ptr<int> b;
{
return 1;
}
// Now test uses within checked scopes.
// First we have to declared some K&R style functions.
#pragma BOUNDS_CHECKED OFF
int KNR_func4(a, b, c)
int a, b, c;
{
return 1;
}
int KNR_func5(a, b)
ptr<int> a;
int b;
{
return 1;
}
int KNR_func6(a, b)
ptr<char> a;
ptr<int> b;
{
return 1;
}
#pragma BOUNDS_CHECKED ON
void KNR_test(void) {
ptr<int> px = 0;
ptr<char> py = 0;
int a,b,c;
KNR_func1(a,b,c); // expected-error {{function without a prototype cannot be used or declared in a checked scope}}
KNR_func2(px,a); // expected-error {{function without a prototype cannot be used or declared in a checked scope}}
KNR_func3(py,px); // expected-error {{function without a prototype cannot be used or declared in a checked scope}}
KNR_func4(a,b,c); // expected-error {{function without a prototype cannot be used or declared in a checked scope}}
KNR_func5(px,a); // expected-error {{function without a prototype cannot be used or declared in a checked scope}}
KNR_func6(py,px); // expected-error {{function without a prototype cannot be used or declared in a checked scope}}
}
#pragma BOUNDS_CHECKED OFF
// Test for checked block.

Просмотреть файл

@ -0,0 +1,42 @@
// Test type checking of generic function calls.
//
// RUN: %clang_cc1 -fcheckedc-extension -verify -verify-ignore-unexpected=note %s
//
// Test mismatches between the number of type variables and type arguments.
//
_For_any(T) int oneTypeVariable(_Ptr<T> a, _Ptr<T> b) {
return 0;
}
_For_any(T, S, R, V) int manyTypeVariables(_Ptr<T> t, _Ptr<S> s, _Ptr<R> r, _Ptr<V> v) {
return 0;
}
void CallGenericFunction(void) {
int a = 0, b = 0, c = 0, d = 0;
_Ptr<int> ap = &a;
_Ptr<int> bp = &b;
_Ptr<int> cp = &c;
_Ptr<int> dp = &d;
oneTypeVariable<int, int>(ap, bp); //expected-error {{mismatch between the number of types listed and number of type variables}}
oneTypeVariable<>(ap, bp); //expected-error {{mismatch between the number of types listed and number of type variables}}
manyTypeVariables<int, int>(ap, bp, cp, dp); //expected-error {{mismatch between the number of types listed and number of type variables}}
manyTypeVariables<>(ap, bp, cp, dp); //expected-error {{mismatch between the number of types listed and number of type variables}}
}
//
// Test that generic functions without prototype are not allowed.
//
// Declaration of a generic no-prototype function.
_For_any(T) T *func1(); // expected-error {{expected prototype for a generic function}}
// Declaration of old-style K&R function definition.
_For_any(T) void func2(x, y) // expected-error {{expected prototype for a generic function}}
T *x;
T *y;
{
}