Re: [PATCH][CilkPlus] Allow parenthesized initialization in for-loops
On 05/10/2016 03:28 PM, Ilya Verbin wrote: What about (some_class i { 0 }; some_class < ...; some_class++) and similar syntax? It's allowed, thanks, I missed this in the initial patch. The testsuite coverage is insufficient (nothing e.g. tests templates or #pragma simd). Patch is updated. Is it sufficient now? - if (!CLASS_TYPE_P (TREE_TYPE (decl)) - && !type_dependent_expression_p (decl)) + if (!is_class && !type_dependent_expression_p (decl)) goto non_class; } - + cp_finish_decl (decl, init, !is_non_constant_init, asm_specification, LOOKUP_ONLYCONVERTING); orig_init = init; - if (CLASS_TYPE_P (TREE_TYPE (decl))) + if (is_class) This change is wrong; do_auto_deduction will have changed TREE_TYPE (decl), so it could be a class now. + else if (is_cilk && next_is_op_paren) + { + cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN); + init = cp_parser_assignment_expression (parser); + cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN); + goto non_class; + } + else if (is_cilk && next_is_eq) + { + bool braced = false; + cp_parser_require (parser, CPP_EQ, RT_EQ); + if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE)) + { + braced = true; + cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE); + } + init = cp_parser_assignment_expression (parser); + if (braced) + cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE); + goto non_class; + } + else if (is_cilk && next_is_op_brace) + { + cp_lexer_set_source_position (parser->lexer); + maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS); + cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE); + init = cp_parser_assignment_expression (parser); + cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE); + goto non_class; + } Why not use cp_parser_initializer for scalars? Jason
Re: [PATCH][CilkPlus] Allow parenthesized initialization in for-loops
On Fri, Mar 25, 2016 at 18:23:23 +0300, Ilya Verbin wrote: > On Mon, Mar 21, 2016 at 15:58:18 +0100, Jakub Jelinek wrote: > > On Mon, Mar 21, 2016 at 05:45:52PM +0300, Ilya Verbin wrote: > > > www.cilkplus.org/sites/default/files/open_specifications/Intel_Cilk_plus_lang_spec_1.2.htm > > > says: > > > In C++, the control variable shall be declared and initialized within > > > the > > > initialization clause of the _Cilk_for loop. The variable shall have > > > automatic > > > storage duration. The variable shall be initialized. Initialization may > > > be > > > explicit, using assignment or constructor syntax, or implicit via a > > > nontrivial > > > default constructor. > > > > > > This patch enables constructor-syntax initialization. > > > Bootstraped and regtested on x86_64-linux. OK for stage1? > > > > Does this affect just _Cilk_for or also #pragma simd? > > It affects both. > > > What about (some_class i { 0 }; some_class < ...; some_class++) > > and similar syntax? > > It's allowed, thanks, I missed this in the initial patch. > > > The testsuite coverage is insufficient (nothing e.g. > > tests templates or #pragma simd). > > Patch is updated. Is it sufficient now? > > > gcc/cp/ > * parser.c (cp_parser_omp_for_loop_init): Allow constructor syntax in > Cilk Plus for-loop initialization. > gcc/testsuite/ > * g++.dg/cilk-plus/CK/for2.cc: New test. > * g++.dg/cilk-plus/for5.C: New test. Ping. -- Ilya
Re: [PATCH][CilkPlus] Allow parenthesized initialization in for-loops
On Mon, Mar 21, 2016 at 15:58:18 +0100, Jakub Jelinek wrote: > On Mon, Mar 21, 2016 at 05:45:52PM +0300, Ilya Verbin wrote: > > www.cilkplus.org/sites/default/files/open_specifications/Intel_Cilk_plus_lang_spec_1.2.htm > > says: > > In C++, the control variable shall be declared and initialized within the > > initialization clause of the _Cilk_for loop. The variable shall have > > automatic > > storage duration. The variable shall be initialized. Initialization may be > > explicit, using assignment or constructor syntax, or implicit via a > > nontrivial > > default constructor. > > > > This patch enables constructor-syntax initialization. > > Bootstraped and regtested on x86_64-linux. OK for stage1? > > Does this affect just _Cilk_for or also #pragma simd? It affects both. > What about (some_class i { 0 }; some_class < ...; some_class++) > and similar syntax? It's allowed, thanks, I missed this in the initial patch. > The testsuite coverage is insufficient (nothing e.g. > tests templates or #pragma simd). Patch is updated. Is it sufficient now? gcc/cp/ * parser.c (cp_parser_omp_for_loop_init): Allow constructor syntax in Cilk Plus for-loop initialization. gcc/testsuite/ * g++.dg/cilk-plus/CK/for2.cc: New test. * g++.dg/cilk-plus/for5.C: New test. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index cd09de6..e481c0c 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -33284,62 +33284,74 @@ cp_parser_omp_for_loop_init (cp_parser *parser, if (declarator == cp_error_declarator) cp_parser_skip_to_end_of_statement (parser); - else { tree pushed_scope, auto_node; + bool is_cilk, is_class, next_is_semicol, next_is_eq, next_is_op_paren, + next_is_op_brace; decl = start_decl (declarator, _specifiers, SD_INITIALIZED, attributes, /*prefix_attributes=*/NULL_TREE, _scope); + is_class = CLASS_TYPE_P (TREE_TYPE (decl)); auto_node = type_uses_auto (TREE_TYPE (decl)); - if (cp_lexer_next_token_is_not (parser->lexer, CPP_EQ)) + is_cilk = code == CILK_SIMD || code == CILK_FOR; + next_is_semicol + = cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON); + next_is_op_paren + = cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN); + next_is_op_brace + = cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE); + next_is_eq = cp_lexer_next_token_is (parser->lexer, CPP_EQ); + + if (!is_cilk && next_is_op_paren) { - if (cp_lexer_next_token_is (parser->lexer, - CPP_OPEN_PAREN)) - { - if (code != CILK_SIMD && code != CILK_FOR) - error ("parenthesized initialization is not allowed in " - "OpenMP %loop"); - else - error ("parenthesized initialization is " - "not allowed in for-loop"); - } - else - /* Trigger an error. */ - cp_parser_require (parser, CPP_EQ, RT_EQ); - + error ("parenthesized initialization is not allowed in " +"OpenMP % loop"); init = error_mark_node; cp_parser_skip_to_end_of_statement (parser); } - else if (CLASS_TYPE_P (TREE_TYPE (decl)) - || type_dependent_expression_p (decl) - || auto_node) + else if (!is_cilk && !next_is_eq) + { + /* Trigger an error. */ + cp_parser_require (parser, CPP_EQ, RT_EQ); + init = error_mark_node; + cp_parser_skip_to_end_of_statement (parser); + } + else if (is_cilk && !(next_is_eq || next_is_op_paren + || next_is_op_brace || next_is_semicol)) + { + cp_parser_error (parser, "expected %<=%>, %<(%>, %<{%> or %<;%>"); + init = error_mark_node; + cp_parser_skip_to_end_of_statement (parser); + } + else if (is_class || type_dependent_expression_p (decl) || auto_node) { bool is_direct_init, is_non_constant_init; - init = cp_parser_initializer (parser, - _direct_init, - _non_constant_init); - + if (is_cilk && next_is_semicol) + init = NULL_TREE; + else + init = cp_parser_initializer (parser, + _direct_init, + _non_constant_init); if (auto_node) { TREE_TYPE (decl) = do_auto_deduction (TREE_TYPE
Re: [PATCH][CilkPlus] Allow parenthesized initialization in for-loops
On Mon, Mar 21, 2016 at 05:45:52PM +0300, Ilya Verbin wrote: > www.cilkplus.org/sites/default/files/open_specifications/Intel_Cilk_plus_lang_spec_1.2.htm > says: > In C++, the control variable shall be declared and initialized within the > initialization clause of the _Cilk_for loop. The variable shall have > automatic > storage duration. The variable shall be initialized. Initialization may be > explicit, using assignment or constructor syntax, or implicit via a > nontrivial > default constructor. > > This patch enables constructor-syntax initialization. > Bootstraped and regtested on x86_64-linux. OK for stage1? Does this affect just _Cilk_for or also #pragma simd? What about (some_class i { 0 }; some_class < ...; some_class++) and similar syntax? The testsuite coverage is insufficient (nothing e.g. tests templates or #pragma simd). Jakub