Disable function call inside function parameter declaration (#144)

This change is to syntactically check function declarations inside a function parameter.
Note that in vanilla clang they allow this to pass in a function to a function (c99, 6.9.1). So this check should be changed once we support function pointers in HLSL.
This commit is contained in:
Young Kim 2017-03-16 13:21:47 -07:00 коммит произвёл GitHub
Родитель 29a09802e3
Коммит 2f3a28076c
3 изменённых файлов: 13 добавлений и 0 удалений

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

@ -7639,6 +7639,8 @@ def warn_hlsl_unused_call : Warning<
"ignoring return value of function that only reads data">,
InGroup<UnusedValue>;
}
def err_hlsl_func_in_func_decl : Error<
"function declaration is not allowed in function parameters">;
// HLSL Change Ends
let CategoryName = "OpenMP Issue" in {

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

@ -9975,6 +9975,14 @@ bool Sema::DiagnoseHLSLDecl(Declarator &D, DeclContext *DC,
bool hasSignSpec = D.getDeclSpec().getTypeSpecSign() != DeclSpec::TSS::TSS_unspecified;
// Function declarations are not allowed in parameter declaration
// TODO : Remove this check once we support function declarations/pointers in HLSL
if (isParameter && isFunction) {
Diag(D.getLocStart(), diag::err_hlsl_func_in_func_decl);
D.setInvalidType();
return false;
}
assert(
(1 == (isLocalVar ? 1 : 0) + (isGlobal ? 1 : 0) + (isField ? 1 : 0) +
(isTypedef ? 1 : 0) + (isFunction ? 1 : 0) + (isMethod ? 1 : 0) +

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

@ -10,6 +10,9 @@
void fn_params_complete(int a = 0, int b = 0);
void fn_params_last(int a, int b = 0);
void fn_params_wrong(int a = 0, int b); // expected-error {{missing default argument on parameter 'b'}} fxc-error {{X3044: 'fn_params_wrong': missing default value for parameter 'b'}}
void fn_params_fn_declaration(int fn(), int b); /* expected-error {{function declaration is not allowed in function parameters}} fxc-error {{X3000: syntax error: unexpected token '('}} fxc-error {{X3000: syntax error: unexpected token ','}} */
void fn_params_fn_declaration(fn()); /* expected-error {{HLSL requires a type specifier for all declarations}} expected-error {{function declaration is not allowed in function parameters}} fxc-error {{X3000: unrecognized identifier 'fn'}} */
void fn_params_fn_pointer(int (*fn)(), int b); /* expected-error {{pointers are unsupported in HLSL}} fxc-error {{X3000: syntax error: unexpected token '('}} */
// Look at the 'mul' issues.
void fn_mul_test() {