aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-parser.c
AgeCommit message (Collapse)AuthorFilesLines
2020-12-09OpenMP: C/C++ parse 'omp allocate'Tobias Burnus1-0/+52
gcc/c-family/ChangeLog: * c-pragma.c (omp_pragmas): Add 'allocate'. * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_ALLOCATE. gcc/c/ChangeLog: * c-parser.c (c_parser_omp_allocate): New. (c_parser_omp_construct): Call it. gcc/cp/ChangeLog: * parser.c (cp_parser_omp_allocate): New. (cp_parser_omp_construct, cp_parser_pragma): Call it. gcc/testsuite/ChangeLog: * c-c++-common/gomp/allocate-5.c: New test.
2020-11-26C: Do not drop qualifiers in typeof for _Atomic types. [PR65455,PR92935]Martin Uecker1-9/+0
2020-11-25 Martin Uecker <muecker@gwdg.de> gcc/c/ PR c/65455 PR c/92935 * c-parser.c (c_parser_declaration_or_fndef): Remove redundant code to drop qualifiers of _Atomic types for __auto_type. (c_parser_typeof_specifier): Do not drop qualifiers of _Atomic types for __typeof__. gcc/ PR c/65455 PR c/92935 * ginclude/stdatomic.h: Use comma operator to drop qualifiers. gcc/testsuite/ PR c/65455 PR c/92935 * gcc.dg/typeof-2.c: Adapt test.
2020-11-24openmp: Fix C ICE on OpenMP atomicsJakub Jelinek1-3/+7
c_parser_binary_expression was using build2 to create a temporary holder for binary expression that c_parser_atomic and c_finish_omp_atomic can then handle. The latter performs then all the needed checking. Unfortunately, build2 performs some checking too, e.g. PLUS_EXPR vs. POINTER_PLUS_EXPR or matching types of the arguments, nothing we can guarantee at the parsing time. So we need something like C++ build_min_nt*. This patch implements that inline. 2020-11-24 Jakub Jelinek <jakub@redhat.com> PR c/97958 * c-parser.c (c_parser_binary_expression): For omp atomic binary expressions, use make_node instead of build2 to avoid checking build2 performs. * c-c++-common/gomp/pr97958.c: New test.
2020-11-13[PATCH] Implementation of asm goto outputsVladimir N. Makarov1-4/+1
gcc/ * cfgexpand.c (expand_asm_stmt): Output asm goto with outputs too. Place insns after asm goto on edges. * doc/extend.texi: Reflect the changes in asm goto documentation. * gimple.c (gimple_build_asm_1): Remove an assert checking output absence for asm goto. * gimple.h (gimple_asm_label_op, gimple_asm_set_label_op): Take possible asm goto outputs into account. * ira.c (ira): Remove critical edges for potential asm goto output reloads. (ira_nullify_asm_goto): New function. * ira.h (ira_nullify_asm_goto): New prototype. * lra-assigns.c (lra_split_hard_reg_for): Use ira_nullify_asm_goto. Check that splitting is done inside a basic block. * lra-constraints.c (curr_insn_transform): Permit output reloads for any jump insn. * lra-spills.c (lra_final_code_change): Remove USEs added in ira for asm gotos. * lra.c (lra_process_new_insns): Place output reload insns after jumps in the beginning of destination BBs. * reload.c (find_reloads): Report error for asm gotos with outputs. Modify them to keep CFG consistency to avoid crashes. * tree-into-ssa.c (rewrite_stmt): Don't put debug stmt after asm goto. gcc/c/ * c-parser.c (c_parser_asm_statement): Parse outputs for asm goto too. * c-typeck.c (build_asm_expr): Remove an assert checking output absence for asm goto. gcc/cp * parser.c (cp_parser_asm_definition): Parse outputs for asm goto too. gcc/testsuite/ * c-c++-common/asmgoto-2.c: Permit output in asm goto. * gcc.c-torture/compile/asmgoto-2.c: New. * gcc.c-torture/compile/asmgoto-3.c: New. * gcc.c-torture/compile/asmgoto-4.c: New. * gcc.c-torture/compile/asmgoto-5.c: New.
2020-11-13C-family, Objective-C [1/3] : Implement Wobjc-root-class [PR77404].Iain Sandoe1-1/+2
This warning catches the case that the user has left the superclass specification from a class interface. Root classes are, of course, permitted and an attribute is added to mark these so that the diagnostic is suppressed. The warning and attribute spellings have been kept in sync with the language reference implementation (clang). The diagnostic location information present in the objective-c interface and class definitions is relatively poor. This patch adds a location for the class name to the interface and makes use of it in existing warnings. Part 1 is the changes to code and added tests. Many entries in the testsuite make use of root classes so there are a large number of mechanical changes there adding "-Wno-objc-root-class" to the options. The test changes are parts 2 (objective-c) and 3 (objective-c++) in the patch series. gcc/c-family/ChangeLog: PR objc/77404 * c-attribs.c (handle_objc_root_class_attribute): New * c-objc.h (objc_start_class_interface): Add a location value for the position of the class name. * c.opt: Add Wobjc-root-class. * stub-objc.c (objc_start_class_interface): Add a location value for the position of the class name. gcc/c/ChangeLog: PR objc/77404 * c-parser.c (c_parser_objc_class_definition): Pass the location of the class name to the interface declaration. gcc/cp/ChangeLog: PR objc/77404 * parser.c (cp_parser_objc_class_interface): Pass the location of the class name to the interface declaration. gcc/objc/ChangeLog: PR objc/77404 * objc-act.c (objc_start_class_interface): Accept the location of the class name, use it in existing diagnostic. (start_class): Accept obj_root_class type attributes. Warn when the interface for an implementation does not contain a super class (unless the diagnostic is suppressed by the the command line flag or the objc_root_class type attribute). gcc/testsuite/ChangeLog: PR objc/77404 * objc.dg/attributes/root-class-01.m: New test. * objc.dg/root-class-00.m: New test. * obj-c++.dg/attributes/root-class-01.mm: New test. * obj-c++.dg/root-class-00.mm: New test. gcc/ChangeLog: PR objc/77404 * doc/extend.texi: Document the objc_root_class attribute. * doc/invoke.texi: Document -Wobjc-root-class.
2020-11-10openmp: Implement OpenMP 5.0 base-pointer attachement and clause orderingChung-Lin Tang1-1/+9
This patch implements some parts of the target variable mapping changes specified in OpenMP 5.0, including base-pointer attachment/detachment behavior for array section list-items in map clauses, and ordering of map clauses according to map kind. 2020-11-10 Chung-Lin Tang <cltang@codesourcery.com> gcc/c-family/ChangeLog: * c-common.h (c_omp_adjust_map_clauses): New declaration. * c-omp.c (struct map_clause): Helper type for c_omp_adjust_map_clauses. (c_omp_adjust_map_clauses): New function. gcc/c/ChangeLog: * c-parser.c (c_parser_omp_target_data): Add use of new c_omp_adjust_map_clauses function. Add GOMP_MAP_ATTACH_DETACH as handled map clause kind. (c_parser_omp_target_enter_data): Likewise. (c_parser_omp_target_exit_data): Likewise. (c_parser_omp_target): Likewise. * c-typeck.c (handle_omp_array_sections): Adjust COMPONENT_REF case to use GOMP_MAP_ATTACH_DETACH map kind for C_ORT_OMP region type. (c_finish_omp_clauses): Adjust bitmap checks to allow struct decl and same struct field access to co-exist on OpenMP construct. gcc/cp/ChangeLog: * parser.c (cp_parser_omp_target_data): Add use of new c_omp_adjust_map_clauses function. Add GOMP_MAP_ATTACH_DETACH as handled map clause kind. (cp_parser_omp_target_enter_data): Likewise. (cp_parser_omp_target_exit_data): Likewise. (cp_parser_omp_target): Likewise. * semantics.c (handle_omp_array_sections): Adjust COMPONENT_REF case to use GOMP_MAP_ATTACH_DETACH map kind for C_ORT_OMP region type. Fix interaction between reference case and attach/detach. (finish_omp_clauses): Adjust bitmap checks to allow struct decl and same struct field access to co-exist on OpenMP construct. gcc/ChangeLog: * gimplify.c (is_or_contains_p): New static helper function. (omp_target_reorder_clauses): New function. (gimplify_scan_omp_clauses): Add use of omp_target_reorder_clauses to reorder clause list according to OpenMP 5.0 rules. Add handling of GOMP_MAP_ATTACH_DETACH for OpenMP cases. * omp-low.c (is_omp_target): New static helper function. (scan_sharing_clauses): Add scan phase handling of GOMP_MAP_ATTACH/DETACH for OpenMP cases. (lower_omp_target): Add lowering handling of GOMP_MAP_ATTACH/DETACH for OpenMP cases. gcc/testsuite/ChangeLog: * c-c++-common/gomp/clauses-2.c: Remove dg-error cases now valid. * gfortran.dg/gomp/map-2.f90: Likewise. * c-c++-common/gomp/map-5.c: New testcase. libgomp/ChangeLog: * libgomp.h (enum gomp_map_vars_kind): Adjust enum values to be bit-flag usable. * oacc-mem.c (acc_map_data): Adjust gomp_map_vars argument flags to 'GOMP_MAP_VARS_OPENACC | GOMP_MAP_VARS_ENTER_DATA'. (goacc_enter_datum): Likewise for call to gomp_map_vars_async. (goacc_enter_data_internal): Likewise. * target.c (gomp_map_vars_internal): Change checks of GOMP_MAP_VARS_ENTER_DATA to use bit-and (&). Adjust use of gomp_attach_pointer for OpenMP cases. (gomp_exit_data): Add handling of GOMP_MAP_DETACH. (GOMP_target_enter_exit_data): Add handling of GOMP_MAP_ATTACH. * testsuite/libgomp.c-c++-common/ptr-attach-1.c: New testcase.
2020-11-07C Parser: Implement mixing of labels and code.Martin Uecker1-68/+37
Implement mixing of labels and code as adopted for C2X and process some std-attributes on labels. 2020-11-06 Martin Uecker <muecker@gwdg.de> gcc/ * doc/extend.texi: Document mixing labels and code. * doc/invoke.texi: Likewise. gcc/c/ * c-parser.c (c_parser_label): Implement mixing of labels and code. (c_parser_all_labels): Likewise. gcc/testsuite/ * c-c++-common/attr-fallthrough-2.c: Update compiler flags. * c-c++-common/Wimplicit-fallthrough-20.c: Adapt test. * gcc.dg/20031223-1.c: Update compiler flags and adapt test. * gcc.dg/c11-labels-1.c: New test. * gcc.dg/c11-labels-2.c: New test. * gcc.dg/c11-labels-3.c: New test. * gcc.dg/c2x-attr-syntax-3.c: Adapt test. * gcc.dg/c2x-labels-1.c: New test. * gcc.dg/c2x-labels-2.c: New test. * gcc.dg/c2x-labels-3.c: New test. * gcc.dg/decl-9.c: Update compiler flags and add error. * gcc.dg/gomp/barrier-2.c: Update compiler flags and add warning. * gcc.dg/gomp/declare-simd-5.c: Update compiler flags and adapt test. * gcc.dg/gomp/declare-variant-2.c: Update compiler flags and add error. * gcc.dg/label-compound-stmt-1.c: Update compiler flags. * gcc.dg/parse-decl-after-label.c: Update compiler flags.
2020-11-06Objective-C/C++ (parsers) : Update @property attribute parsing.Iain Sandoe1-121/+159
At present, we are missing parsing and checking for around half of the property attributes in use. The existing ad hoc scheme for the parser's communication with the Objective C validation is not suitable for extending to cover all the missing cases. Additionally: 1/ We were declaring errors in two cases that the reference implementation warns (or is silent). I've elected to warn for both those cases, (Wattributes) it could be that we should implement Wobjc-xxx-property warning masks (TODO). 2/ We were emitting spurious complaints about missing property attributes when these were not being parsed because we gave up on the first syntax error. 3/ The quality of the diagnostic locations was poor (that's true for much of Objective-C, we will have to improve it as we modernise areas). We continue to attempt to keep the code, warning and error output similar (preferably identical output) between the C and C++ front ends. The interface to the Objective-C-specific parts of the parsing is simplified to a vector of parsed (but not fully-checked) property attributes, this will simplify the addition of new attributes. gcc/c-family/ChangeLog: * c-objc.h (enum objc_property_attribute_group): New (enum objc_property_attribute_kind): New. (OBJC_PROPATTR_GROUP_MASK): New. (struct property_attribute_info): Small class encapsulating parser output from property attributes. (objc_prop_attr_kind_for_rid): New (objc_add_property_declaration): Simplify interface. * stub-objc.c (enum rid): Dummy type. (objc_add_property_declaration): Simplify interface. (objc_prop_attr_kind_for_rid): New. gcc/c/ChangeLog: * c-parser.c (c_parser_objc_at_property_declaration): Improve parsing fidelity. Associate better location info with @property attributes. Clean up the interface to objc_add_property_declaration (). gcc/cp/ChangeLog: * parser.c (cp_parser_objc_at_property_declaration): Improve parsing fidelity. Associate better location info with @property attributes. Clean up the interface to objc_add_property_declaration (). gcc/objc/ChangeLog: * objc-act.c (objc_prop_attr_kind_for_rid): New. (objc_add_property_declaration): Adjust to consume the parser output using a vector of parsed attributes. gcc/testsuite/ChangeLog: * obj-c++.dg/property/at-property-1.mm: Adjust expected diagnostics. * obj-c++.dg/property/at-property-29.mm: Likewise. * obj-c++.dg/property/at-property-4.mm: Likewise. * obj-c++.dg/property/property-neg-2.mm: Likewise. * objc.dg/property/at-property-1.m: Likewise. * objc.dg/property/at-property-29.m: Likewise. * objc.dg/property/at-property-4.m: Likewise. * objc.dg/property/at-property-5.m: Likewise. * objc.dg/property/property-neg-2.m: Likewise.
2020-11-06OpenACC (C/C++): Fix 'acc atomic' parsingTobias Burnus1-5/+19
gcc/c/ChangeLog: * c-parser.c (c_parser_omp_atomic): Add openacc parameter and update OpenACC matching. (c_parser_omp_construct): Update call. gcc/cp/ChangeLog: * parser.c (cp_parser_omp_atomic): Add openacc parameter and update OpenACC matching. (cp_parser_omp_construct): Update call. gcc/testsuite/ChangeLog: * c-c++-common/goacc-gomp/atomic.c: New test. * c-c++-common/goacc/atomic.c: New test.
2020-11-04c: Implement C2x nodiscard attributeJoseph Myers1-5/+5
C2x adds the nodiscard standard attribute, with an optional string argument, as in C++; implement it for C. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/c/ 2020-11-04 Joseph Myers <joseph@codesourcery.com> * c-decl.c (handle_nodiscard_attribute): New. (std_attribute_table): Add nodiscard. * c-parser.c (c_parser_std_attribute): Expect argument to nodiscard attribute to be a string. Do not special-case ignoring nodiscard. * c-typeck.c (maybe_warn_nodiscard): New. (build_compound_expr, emit_side_effect_warnings): Call maybe_warn_nodiscard. (c_process_expr_stmt, c_finish_stmt_expr): Also call emit_side_effect_warnings if warn_unused_result. gcc/testsuite/ 2020-11-04 Joseph Myers <joseph@codesourcery.com> * gcc.dg/c2x-attr-nodiscard-1.c, gcc.dg/c2x-attr-nodiscard-2.c, gcc.dg/c2x-attr-nodiscard-3.c, gcc.dg/c2x-attr-nodiscard-4.c: New tests. * gcc.dg/c2x-attr-syntax-5.c: Remove nodiscard test.
2020-10-28openmp: Parsing and some semantic analysis of OpenMP allocate clauseJakub Jelinek1-1/+73
This patch adds parsing of OpenMP allocate clause, but still ignores it during OpenMP lowering where we should for privatized variables with allocate clause use the corresponding allocators rather than allocating them on the stack. 2020-10-28 Jakub Jelinek <jakub@redhat.com> gcc/ * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_ALLOCATE. * tree.h (OMP_CLAUSE_ALLOCATE_ALLOCATOR, OMP_CLAUSE_ALLOCATE_COMBINED): Define. * tree.c (omp_clause_num_ops, omp_clause_code_name): Add allocate clause. (walk_tree_1): Handle OMP_CLAUSE_ALLOCATE. * tree-pretty-print.c (dump_omp_clause): Likewise. * gimplify.c (gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses, gimplify_omp_for): Likewise. * tree-nested.c (convert_nonlocal_omp_clauses, convert_local_omp_clauses): Likewise. * omp-low.c (scan_sharing_clauses): Likewise. gcc/c-family/ * c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_ALLOCATE. * c-omp.c: Include bitmap.h. (c_omp_split_clauses): Handle OMP_CLAUSE_ALLOCATE. gcc/c/ * c-parser.c (c_parser_omp_clause_name): Handle allocate. (c_parser_omp_clause_allocate): New function. (c_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_ALLOCATE. (OMP_FOR_CLAUSE_MASK, OMP_SECTIONS_CLAUSE_MASK, OMP_PARALLEL_CLAUSE_MASK, OMP_SINGLE_CLAUSE_MASK, OMP_TASK_CLAUSE_MASK, OMP_TASKGROUP_CLAUSE_MASK, OMP_DISTRIBUTE_CLAUSE_MASK, OMP_TEAMS_CLAUSE_MASK, OMP_TARGET_CLAUSE_MASK, OMP_TASKLOOP_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_ALLOCATE. * c-typeck.c (c_finish_omp_clauses): Handle OMP_CLAUSE_ALLOCATE. gcc/cp/ * parser.c (cp_parser_omp_clause_name): Handle allocate. (cp_parser_omp_clause_allocate): New function. (cp_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_ALLOCATE. (OMP_FOR_CLAUSE_MASK, OMP_SECTIONS_CLAUSE_MASK, OMP_PARALLEL_CLAUSE_MASK, OMP_SINGLE_CLAUSE_MASK, OMP_TASK_CLAUSE_MASK, OMP_TASKGROUP_CLAUSE_MASK, OMP_DISTRIBUTE_CLAUSE_MASK, OMP_TEAMS_CLAUSE_MASK, OMP_TARGET_CLAUSE_MASK, OMP_TASKLOOP_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_ALLOCATE. * semantics.c (finish_omp_clauses): Handle OMP_CLAUSE_ALLOCATE. * pt.c (tsubst_omp_clauses): Likewise. gcc/testsuite/ * c-c++-common/gomp/allocate-1.c: New test. * c-c++-common/gomp/allocate-2.c: New test. * c-c++-common/gomp/clauses-1.c (omp_allocator_handle_t): New typedef. (foo, bar, baz): Add allocate clauses where allowed.
2020-10-27c: Allow duplicate C2x standard attributesJoseph Myers1-52/+2
N2557, accepted into C2x at the October WG14 meeting, removes the requirement that duplicates of standard attributes cannot appear within an attribute list (so allowing e.g. [[deprecated, deprecated]], where previously that was disallowed but [[deprecated]] [[deprecated]] was OK). Remove the code checking for this (standard attributes aren't in any released version of the C standard) and update tests accordingly. Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c/ 2020-10-27 Joseph Myers <joseph@codesourcery.com> * c-parser.c (c_parser_std_attribute_specifier): Allow duplicate standard attributes. gcc/testsuite/ 2020-10-27 Joseph Myers <joseph@codesourcery.com> * gcc.dg/c2x-attr-deprecated-4.c, gcc.dg/c2x-attr-fallthrough-4.c, gcc.dg/c2x-attr-maybe_unused-4.c: Allow duplicate attributes.
2020-10-23c, c++: Implement -Wsizeof-array-div [PR91741]Marek Polacek1-18/+30
This patch implements a new warning, -Wsizeof-array-div. It warns about code like int arr[10]; sizeof (arr) / sizeof (short); where we have a division of two sizeof expressions, where the first argument is an array, and the second sizeof does not equal the size of the array element. See e.g. <https://www.viva64.com/en/examples/v706/>. Clang makes it possible to suppress the warning by parenthesizing the second sizeof like this: sizeof (arr) / (sizeof (short)); so I followed suit. In the C++ FE this was rather easy, because finish_parenthesized_expr already set TREE_NO_WARNING. In the C FE I've added a new tree code, PAREN_SIZEOF_EXPR, to discern between the non-() and () versions. This warning is enabled by -Wall. An example of the output: x.c:5:23: warning: expression does not compute the number of elements in this array; element type is ‘int’, not ‘short int’ [-Wsizeof-array-div] 5 | return sizeof (arr) / sizeof (short); | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ x.c:5:25: note: add parentheses around ‘sizeof (short int)’ to silence this warning 5 | return sizeof (arr) / sizeof (short); | ^~~~~~~~~~~~~~ | ( ) x.c:4:7: note: array ‘arr’ declared here 4 | int arr[10]; | ^~~ gcc/c-family/ChangeLog: PR c++/91741 * c-common.c (verify_tree): Handle PAREN_SIZEOF_EXPR. (c_common_init_ts): Likewise. * c-common.def (PAREN_SIZEOF_EXPR): New tree code. * c-common.h (maybe_warn_sizeof_array_div): Declare. * c-warn.c (sizeof_pointer_memaccess_warning): Unwrap NOP_EXPRs. (maybe_warn_sizeof_array_div): New function. * c.opt (Wsizeof-array-div): New option. gcc/c/ChangeLog: PR c++/91741 * c-parser.c (c_parser_binary_expression): Implement -Wsizeof-array-div. (c_parser_postfix_expression): Set PAREN_SIZEOF_EXPR. (c_parser_expr_list): Handle PAREN_SIZEOF_EXPR like SIZEOF_EXPR. * c-tree.h (char_type_p): Declare. * c-typeck.c (char_type_p): No longer static. gcc/cp/ChangeLog: PR c++/91741 * typeck.c (cp_build_binary_op): Implement -Wsizeof-array-div. gcc/ChangeLog: PR c++/91741 * doc/invoke.texi: Document -Wsizeof-array-div. gcc/testsuite/ChangeLog: PR c++/91741 * c-c++-common/Wsizeof-pointer-div.c: Add dg-warning. * c-c++-common/Wsizeof-array-div1.c: New test. * g++.dg/warn/Wsizeof-array-div1.C: New test. * g++.dg/warn/Wsizeof-array-div2.C: New test.
2020-09-19Infrastructure & C front end changes for array parameter checking (PR c/50584).Martin Sebor1-10/+17
gcc/ChangeLog: PR c/50584 * attribs.c (decl_attributes): Also pass decl along with type attributes to handlers. (init_attr_rdwr_indices): Change second argument to attribute chain. Handle internal attribute representation in addition to external. (get_parm_access): New function. (attr_access::to_internal_string): Define new member function. (attr_access::to_external_string): Define new member function. (attr_access::vla_bounds): Define new member function. * attribs.h (struct attr_access): Declare new members. (attr_access::from_mode_char): Define new member function. (get_parm_access): Declare new function. * calls.c (initialize_argument_information): Pass function type attributes to init_attr_rdwr_indices. * doc/invoke.texi (-Warray-parameter, -Wvla-parameter): Document. * tree-pretty-print.c (dump_generic_node): Correct handling of qualifiers. * tree-ssa-uninit.c (maybe_warn_pass_by_reference): Same. * tree.h (access_mode): Add new enumerator. gcc/c-family/ChangeLog: PR c/50584 * c-attribs.c (c_common_attribute_table): Add "arg spec" attribute. (handle_argspec_attribute): New function. (get_argument, get_argument_type): New functions. (append_access_attrs): Add overload. Handle internal attribute representation in addition to external. (handle_access_attribute): Handle internal attribute representation in addition to external. (build_attr_access_from_parms): New function. gcc/c-family/ChangeLog: PR c/50584 * c-common.h (warn_parm_array_mismatch): Declare new function. (has_attribute): Move declaration of an existing function. (build_attr_access_from_parms): Declare new function. * c-warn.c (parm_array_as_string): Define new function. (plus_one): Define new function. (warn_parm_ptrarray_mismatch): Define new function. (warn_parm_array_mismatch): Define new function. (vla_bound_parm_decl): New function. * c.opt (-Warray-parameter, -Wvla-parameter): New options. * c-pretty-print.c (pp_c_type_qualifier_list): Don't print array type qualifiers here... (c_pretty_printer::direct_abstract_declarator): ...but instead print them in brackets here. Also print [static]. Strip extraneous expressions from VLA bounds. gcc/c/ChangeLog: PR c/50584 * c-decl.c (lookup_last_decl): Define new function. (c_decl_attributes): Call it. (start_decl): Add argument and use it. (finish_decl): Call build_attr_access_from_parms and decl_attributes. (get_parm_array_spec): Define new function. (push_parm_decl): Call get_parm_array_spec. (start_function): Call warn_parm_array_mismatch. Build attribute access and add it to current function. * c-parser.c (c_parser_declaration_or_fndef): Diagnose mismatches in forms of array parameters. * c-tree.h (start_decl): Add argument. gcc/testsuite/ChangeLog: PR c/50584 * gcc.dg/attr-access-read-write-2.c: Adjust text of expected message. * c-c++-common/Warray-bounds-6.c: Correct C++ declaration, adjust text of expected diagnostics. * gcc.dg/Wbuiltin-declaration-mismatch-9.c: Prune expected warning. * gcc.dg/Warray-parameter-2.c: New test. * gcc.dg/Warray-parameter-3.c: New test. * gcc.dg/Warray-parameter-4.c: New test. * gcc.dg/Warray-parameter-5.c: New test. * gcc.dg/Warray-parameter.c: New test. * gcc.dg/Wvla-parameter-2.c: New test. * gcc.dg/Wvla-parameter-3.c: New test. * gcc.dg/Wvla-parameter.c: New test.
2020-09-19Change C front end to emit structured loop and switch tree nodes.Sandra Loosemore1-65/+60
2020-08-12 Sandra Loosemore <sandra@codesourcery.com> gcc/c * c-decl.c (c_break_label, c_cont_label): Delete, and replace with... (in_statement): New. (start_function): Adjust for above change. (c_push_function_context, c_pop_function_context): Likewise. * c-lang.h (struct language_function): Likewise. * c-objc-common.h (LANG_HOOKS_BLOCK_MAY_FALLTHRU): Define. * c-parser.c (objc_foreach_break_label, objc_foreach_continue_label): New. (c_parser_statement_after_labels): Adjust calls to c_finish_bc_stmt. (c_parser_switch_statement): Adjust break/switch context handling and calls to renamed functions. (c_parser_while_statement): Adjust break/switch context handling and build a WHILE_STMT. (c_parser_do_statement): Ditto, with DO_STMT respectively. (c_parser_for_statement): Ditto, with FOR_STMT respectively. (c_parser_omp_for_loop): Adjust break/switch context handling. * c-tree.h (c_break_label, c_cont_label): Delete. (IN_SWITCH_STMT, IN_ITERATION_STMT): Define. (IN_OMP_BLOCK, IN_OMP_FOR, IN_OBJC_FOREACH): Define. (in_statement, switch_statement_break_seen_p): Declare. (c_start_case, c_finish_case): Renamed to... (c_start_switch, c_finish_switch). (c_finish_bc_stmt): Adjust arguments. * c-typeck.c (build_function_call_vec): Don't try to print statements with %qE format. (struct c_switch): Rename switch_expr field to switch_stmt. Add break_stmt_seen_p field. (c_start_case): Rename to c_start_switch. Build a SWITCH_STMT instead of a SWITCH_EXPR. Update for changes to struct c_switch. (do_case): Update for changes to struct c_switch. (c_finish_case): Rename to c_finish_switch. Update for changes to struct c_switch and change of representation from SWITCH_EXPR to SWITCH_STMT. (c_finish_loop): Delete. (c_finish_bc_stmt): Update to reflect changes to break/continue state representation. Build a BREAK_STMT or CONTINUE_STMT instead of a GOTO_EXPR except for objc foreach loops. gcc/objc * objc-act.c (objc_start_method_definition): Update to reflect changes to break/continue state bookkeeping in C front end. gcc/testsuite/ * gcc.dg/gomp/block-7.c: Update expected error message wording.
2020-08-18c: Fix -Wunused-but-set-* warning with _Generic [PR96571]Jakub Jelinek1-6/+13
The following testcase shows various problems with -Wunused-but-set* warnings and _Generic construct. I think it is best to treat the selector and the ignored expressions as (potentially) read, because when they are parsed, the vars in there are already marked as TREE_USED. 2020-08-18 Jakub Jelinek <jakub@redhat.com> PR c/96571 * c-parser.c (c_parser_generic_selection): Change match_found from bool to int, holding index of the match. Call mark_exp_read on the selector expression and on expressions other than the selected one. * gcc.dg/Wunused-var-4.c: New test.
2020-07-22OpenMP: Fixes for omp critical + hintTobias Burnus1-18/+8
gcc/c-family/ChangeLog: * c-omp.c (c_finish_omp_critical): Check for no name but nonzero hint provided. gcc/c/ChangeLog: * c-parser.c (c_parser_omp_clause_hint): Require nonnegative hint clause. (c_parser_omp_critical): Permit hint(0) clause without named critical. (c_parser_omp_construct): Don't assert if error_mark_node is returned. gcc/cp/ChangeLog: * parser.c (cp_parser_omp_clause_hint): Require nonnegative hint. (cp_parser_omp_critical): Permit hint(0) clause without named critical. * pt.c (tsubst_expr): Re-check the latter for templates. gcc/fortran/ChangeLog: * openmp.c (gfc_match_omp_critical): Fix handling hints; permit hint clause without named critical. (resolve_omp_clauses): Require nonnegative constant integer for the hint clause. (gfc_resolve_omp_directive): Check for no name but nonzero value for hint clause. * parse.c (parse_omp_structured_block): Fix same-name check for critical. * trans-openmp.c (gfc_trans_omp_critical): Handle hint clause properly. libgomp/ChangeLog: * omp_lib.f90.in: Add omp_sync_hint_* and omp_sync_hint_kind. * omp_lib.h.in: Likewise. gcc/testsuite/ChangeLog: * g++.dg/gomp/critical-3.C: Add nameless critical with hint testcase. * c-c++-common/gomp/critical-hint-1.c: New test. * c-c++-common/gomp/critical-hint-2.c: New test. * gfortran.dg/gomp/critical-hint-1.f90: New test. * gfortran.dg/gomp/critical-hint-2.f90: New test.
2020-07-07Pass correct parameters to c_parser_do_statement.Kaipeng Zhou1-1/+1
gcc/c/ChangeLog: * c-parser.c (c_parser_statement_after_labels): Pass correct parameters to c_parser_do_statement.
2020-06-16openmp: Initial part of OpenMP 5.0 non-rectangular loop supportJakub Jelinek1-8/+46
OpenMP 5.0 adds support for non-rectangular loop collapses, e.g. triangular and more complex. This patch deals just with the diagnostics so that they aren't rejected immediately as before. As the spec generally requires as before that the iteration variable initializer and bound in the comparison as invariant vs. the outermost loop, and just add some exceptional forms that can violate that, we need to avoid folding the expressions until we can detect them and in order to avoid folding it later on, I chose to use a TREE_VEC in those expressions to hold the var_outer * expr1 + expr2 triplet, the patch adds pretty-printing of that, gimplification etc. and just sorry_at during omp expansion for now. The next step will be to implement the different cases of that one by one. 2020-06-16 Jakub Jelinek <jakub@redhat.com> gcc/ * tree.h (OMP_FOR_NON_RECTANGULAR): Define. * gimplify.c (gimplify_omp_for): Diagnose schedule, ordered or dist_schedule clause on non-rectangular loops. Handle gimplification of non-rectangular lb/b expressions. When changing iteration variable, adjust also non-rectangular lb/b expressions referencing that. * omp-general.h (struct omp_for_data_loop): Add m1, m2 and outer members. (struct omp_for_data): Add non_rect member. * omp-general.c (omp_extract_for_data): Handle non-rectangular loops. Fill in non_rect, m1, m2 and outer. * omp-low.c (lower_omp_for): Handle non-rectangular lb/b expressions. * omp-expand.c (expand_omp_for): Emit sorry_at for unsupported non-rectangular loop cases and assert for cases that can't be non-rectangular. * tree-pretty-print.c (dump_mem_ref): Formatting fix. (dump_omp_loop_non_rect_expr): New function. (dump_generic_node): Handle non-rectangular OpenMP loops. * tree-pretty-print.h (dump_omp_loop_non_rect_expr): Declare. * gimple-pretty-print.c (dump_gimple_omp_for): Handle non-rectangular OpenMP loops. gcc/c-family/ * c-common.h (c_omp_check_loop_iv_exprs): Add an int argument. * c-omp.c (struct c_omp_check_loop_iv_data): Add maybe_nonrect and idx members. (c_omp_is_loop_iterator): New function. (c_omp_check_loop_iv_r): Use it. Add support for silent scanning if outer loop iterator is present. Perform duplicate checking through hash_set in the function rather than expecting caller to do that. Pass NULL instead of d->ppset to walk_tree_1. (c_omp_check_nonrect_loop_iv): New function. (c_omp_check_loop_iv): Use it. Fill in new members, allow non-rectangular loop forms, diagnose multiple associated loops with the same iterator. Pass NULL instead of &pset to walk_tree_1. (c_omp_check_loop_iv_exprs): Likewise. gcc/c/ * c-parser.c (c_parser_expr_no_commas): Save, clear and restore c_in_omp_for. (c_parser_omp_for_loop): Set c_in_omp_for around some calls to avoid premature c_fully_fold. Defer explicit c_fully_fold calls to after c_finish_omp_for. * c-tree.h (c_in_omp_for): Declare. * c-typeck.c (c_in_omp_for): Define. (build_modify_expr): Avoid c_fully_fold if c_in_omp_for. (digest_init): Likewise. (build_binary_op): Likewise. gcc/cp/ * semantics.c (handle_omp_for_class_iterator): Adjust c_omp_check_loop_iv_exprs caller. (finish_omp_for): Likewise. Don't call fold_build_cleanup_point_expr before calling c_finish_omp_for and c_omp_check_loop_iv, move it after those calls. * pt.c (tsubst_omp_for_iterator): Handle non-rectangular loops. gcc/testsuite/ * c-c++-common/gomp/loop-6.c: New test. * gcc.dg/gomp/loop-1.c: Don't expect diagnostics on valid non-rectangular loops. * gcc.dg/gomp/loop-2.c: New test. * g++.dg/gomp/loop-1.C: Don't expect diagnostics on valid non-rectangular loops. * g++.dg/gomp/loop-2.C: Likewise. * g++.dg/gomp/loop-5.C: New test. * g++.dg/gomp/loop-6.C: New test.
2020-06-16openmp: Diagnose invalid OpenMP schedule(simd, static)Jakub Jelinek1-1/+8
2020-06-16 Jakub Jelinek <jakub@redhat.com> gcc/c/ * c-parser.c (c_parser_omp_clause_schedule): Reject modifier separated from kind by comma rather than colon. gcc/cp/ * parser.c (cp_parser_omp_clause_schedule): Reject modifier separated from kind by comma rather than colon. gcc/testsuite/ * c-c++-common/gomp/schedule-modifiers-2.c: New test.
2020-06-04Provide diagnostic hints for missing C inttypes.h string constants.Mark Wielaard1-0/+29
This adds a flag to c_parser so we know when we were trying to construct a string literal. If there is a parse error and we were constructing a string literal, and the next token is an unknown identifier name, and we know there is a standard header that defines that name as a string literal, then add a missing header hint to the error messsage. The list of macro names are also used when providing a hint for missing identifiers. gcc/c-family/ChangeLog: * known-headers.cc (get_string_macro_hint): New function. (get_stdlib_header_for_name): Use get_string_macro_hint. (get_c_stdlib_header_for_string_macro_name): New function. * known-headers.h (get_c_stdlib_header_for_string_macro_name): New function declaration. gcc/c/ChangeLog: * c-parser.c (struct c_parser): Add seen_string_literal bitfield. (c_parser_consume_token): Reset seen_string_literal. (c_parser_error_richloc): Add name_hint if seen_string_literal and next token is a CPP_NAME and we have a missing header suggestion for the name. (c_parser_string_literal): Set seen_string_literal. gcc/testsuite/ChangeLog: * gcc.dg/spellcheck-inttypes.c: New test. * g++.dg/spellcheck-inttypes.C: Likewise.
2020-06-04diagnostics: Add function call parens matching to c_parser.Mark Wielaard1-15/+17
The C++ parser already tracks function call parens matching, but the C parser doesn't. This adds the same functionality to the C parser and adds a testcase showing the C++ and C parser matching function call parens in an error message. gcc/c/ChangeLog: * c-parser.c (c_parser_postfix_expression_after_primary): Add scope with matching_parens after CPP_OPEN_PAREN. gcc/testsuite/ChangeLog: * c-c++-common/missing-close-func-paren.c: New test.
2020-05-19Fix typo in c-parser.c.Martin Liska1-1/+1
gcc/c/ChangeLog: * c-parser.c: Fix typo.
2020-05-14openmp: Also implicitly mark as declare target to functions mentioned in ↵Jakub Jelinek1-0/+1
target regions OpenMP 5.0 also specifies that functions referenced from target regions (except for target regions with device(ancestor:)) are also implicitly declare target to. This patch implements that. 2020-05-14 Jakub Jelinek <jakub@redhat.com> * function.h (struct function): Add has_omp_target bit. * omp-offload.c (omp_discover_declare_target_fn_r): New function, old renamed to ... (omp_discover_declare_target_tgt_fn_r): ... this. (omp_discover_declare_target_var_r): Call omp_discover_declare_target_tgt_fn_r instead of omp_discover_declare_target_fn_r. (omp_discover_implicit_declare_target): Also queue functions with has_omp_target bit set, for those walk with omp_discover_declare_target_fn_r, for declare target to functions walk with omp_discover_declare_target_tgt_fn_r. gcc/c/ * c-parser.c (c_parser_omp_target): Set cfun->has_omp_target. gcc/cp/ * cp-gimplify.c (cp_genericize_r): Set cfun->has_omp_target. gcc/fortran/ * trans-openmp.c: Include function.h. (gfc_trans_omp_target): Set cfun->has_omp_target. libgomp/ * testsuite/libgomp.c-c++-common/target-40.c: New test.
2020-04-19c, objc: Fix up c_parser_objc_selector_arg after CPP_SCOPE changes [PR94637]Jakub Jelinek1-5/+18
Similarly to inline asm, :: (or any other number of consecutive colons) can appear in ObjC @selector argument and with the introduction of CPP_SCOPE into the C FE, we need to trat CPP_SCOPE as two CPP_COLON tokens. The C++ FE does that already that way. 2020-04-19 Jakub Jelinek <jakub@redhat.com> PR objc/94637 * c-parser.c (c_parser_objc_selector_arg): Handle CPP_SCOPE like two CPP_COLON tokens. * objc.dg/pr94637.m: New test.
2020-04-17c, c++: Fix two redundantAssignment warnings [PR94629]Jakub Jelinek1-1/+0
This change fixes two obvious redundant assignments reported by cppcheck: trunk.git/gcc/c/c-parser.c:16969:2: style: Variable 'data.clauses' is reassigned a value before the old one has been used. [redundantAssignment] trunk.git/gcc/cp/call.c:5116:9: style: Variable 'arg2' is reassigned a value before the old one has been used. [redundantAssignment] 2020-04-17 Jakub Jelinek <jakub@redhat.com> PR other/94629 * c-parser.c (c_parser_oacc_routine): Remove redundant assignment to data.clauses. * call.c (build_conditional_expr_1): Remove redundant assignment to arg2.
2020-04-15openmp: Reject requires directives not at file or namespace scope [PR94593]Jakub Jelinek1-0/+7
This change started with a bugreport about a typo in one requires testcase (diagnosed with -Wunknown-pragmas only), but following discussion lead to noting that we do not diagnose restriction that requires directives in C/C++ may only appear at file or namespace scope; and several our tests violated that. 2020-04-15 Jakub Jelinek <jakub@redhat.com> PR c/94593 * c-parser.c (c_parser_pragma) <case PRAGMA_OMP_REQUIRES>: Reject requires directive when not at file scope. * parser.c (cp_parser_pragma) <case PRAGMA_OMP_REQUIRES>: Reject requires directive when not at file or namespace scope. * c-c++-common/gomp/requires-1.c: Fix a typo, requries -> requires. Move directives to file scope. (i): Remove. * c-c++-common/gomp/requires-2.c: Move directives to file scope. (i, foo): Remove. * c-c++-common/gomp/requires-4.c: Move directives to file scope. * c-c++-common/gomp/atomic-19.c: Move requires directive to file scope. * c-c++-common/gomp/atomic-20.c: Likewise. * c-c++-common/gomp/atomic-21.c: Likewise. * c-c++-common/gomp/atomic-22.c: Likewise. * gcc.dg/gomp/requires-1.c: New test. * g++.dg/gomp/requires-1.C: New test. * g++.dg/gomp/requires-2.C: New test. * g++.dg/gomp/atomic-18.C: Move requires directive to file scope.
2020-04-08[C/C++, OpenACC] Reject vars of different scope in acc declare (PR94120)Tobias Burnus1-0/+9
gcc/c/ PR middle-end/94120 * c-decl.c (c_check_in_current_scope): New function. * c-tree.h (c_check_in_current_scope): Declare it. * c-parser.c (c_parser_oacc_declare): Add check that variables are declared in the same scope as the directive. Fix handling of namespace vars. gcc/cp/ PR middle-end/94120 * paser.c (cp_parser_oacc_declare): Add check that variables are declared in the same scope as the directive. gcc/testsuite/ PR middle-end/94120 * c-c++-common/goacc/declare-pr94120.c: New. * g++.dg/declare-pr94120.C: New. libgomp/testsuite/ PR middle-end/94120 * libgomp.oacc-c++/declare-pr94120.C: New.
2020-04-07openmp: Fix parallel master error recovery [PR94512]Jakub Jelinek1-1/+1
We need to set OMP_PARALLEL_COMBINED only if the parsing of omp_master succeeded, because otherwise there is no nested master construct in the parallel. 2020-04-07 Jakub Jelinek <jakub@redhat.com> PR c++/94512 * c-parser.c (c_parser_omp_parallel): Set OMP_PARALLEL_COMBINED if c_parser_omp_master succeeded. * parser.c (cp_parser_omp_parallel): Set OMP_PARALLEL_COMBINED if cp_parser_omp_master succeeded. * g++.dg/gomp/pr94512.C: New test.
2020-03-23c: Fix up cfun->function_end_locus on invalid function bodies [PR94239]Jakub Jelinek1-4/+3
Unfortunately the patch broke +FAIL: gcc.dg/pr20245-1.c (internal compiler error) +FAIL: gcc.dg/pr20245-1.c (test for excess errors) +FAIL: gcc.dg/pr28419.c (internal compiler error) +FAIL: gcc.dg/pr28419.c (test for excess errors) on some targets (and under valgrind on the rest of them). Those functions don't have the opening { and so c_parser_compound_statement returned error_mark_node before initializing *endlocp. So, either we can initialize it in that case too: --- gcc/c/c-parser.c 2020-03-20 22:09:39.659411721 +0100 +++ gcc/c/c-parser.c 2020-03-21 09:36:44.455705261 +0100 @@ -5611,6 +5611,8 @@ c_parser_compound_statement (c_parser *p if we have just prepared to enter a function body. */ stmt = c_begin_compound_stmt (true); c_end_compound_stmt (brace_loc, stmt, true); + if (endlocp) + *endlocp = brace_loc; return error_mark_node; } stmt = c_begin_compound_stmt (true); or perhaps simpler initialize it to the function_start_locus at the beginning and have those functions without { have function_start_locus == function_end_locus like the __GIMPLE functions (where propagating the closing } seemed too difficult). 2020-03-23 Jakub Jelinek <jakub@redhat.com> PR gcov-profile/94029 PR c/94239 * c-parser.c (c_parser_declaration_or_fndef): Initialize endloc to the function_start_locus location. Don't do that afterwards for the __GIMPLE body parsing.
2020-03-19c: Fix up cfun->function_end_locus from the C FE [PR94029]Jakub Jelinek1-21/+30
On the following testcase we ICE because while DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus = c_parser_peek_token (parser)->location; and similarly DECL_SOURCE_LOCATION (fndecl) is set from some token's location, the end is set as: /* Store the end of the function, so that we get good line number info for the epilogue. */ cfun->function_end_locus = input_location; and the thing is that input_location is only very rarely set in the C FE (the primary spot that changes it is the cb_line_change/fe_file_change). Which means, e.g. for pretty much all C functions that are on a single line, function_start_locus column is > than function_end_locus column, and the testcase even has smaller line in function_end_locus because cb_line_change isn't performed while parsing multi-line arguments of a function-like macro. Attached are two possible fixes to achieve what the C++ FE does, in particular that cfun->function_end_locus is the locus of the closing } of the function. The first one updates input_location when we see a closing } of a compound statement (though any, not just the function body) and thus input_location in the finish_function call is what we need. The second instead propagates the location_t from the parsing of the outermost compound statement (the function body) to finish_function. The second one is this version. 2020-03-19 Jakub Jelinek <jakub@redhat.com> PR gcov-profile/94029 * c-tree.h (finish_function): Add location_t argument defaulted to input_location. * c-parser.c (c_parser_compound_statement): Add endlocp argument and set it to the locus of closing } if non-NULL. (c_parser_compound_statement_nostart): Return locus of closing }. (c_parser_parse_rtl_body): Likewise. (c_parser_declaration_or_fndef): Propagate locus of closing } to finish_function. * c-decl.c (finish_function): Add end_loc argument, use it instead of input_location to set function_end_locus. * gcc.misc-tests/gcov-pr94029.c: New test.
2020-01-30Mark switch expression as used to avoid bogus warningJeff Law1-1/+1
PR c/88660 * c-parser.c (c_parser_switch_statement): Make sure to request marking the switch expr as used. PR c/88660 * gcc.dg/pr88660.c: New test.
2020-01-16Fix ICE caused by swallowing a token in c_parser_consume_tokenKerem Kat1-1/+5
This patch fixes ICE on invalid code, specifically files that have conflict-marker-like signs before EOF. PR c/92833 gcc/c/ * c-parser.c (c_parser_consume_token): Fix peeked token stack pop to support 4 available tokens. gcc/testsuite/ * c-c++-common/pr92833-1.c, c-c++-common/pr92833-2.c, c-c++-common/pr92833-3.c, c-c++-common/pr92833-4.c: New tests.
2020-01-10OpenACC – support "if" + "if_present" clauses with "host_data"Tobias Burnus1-1/+3
2020-01-10 Gergö Barany <gergo@codesourcery.com> Thomas Schwinge <thomas@codesourcery.com> Julian Brown <julian@codesourcery.com> Tobias Burnus <tobias@codesourcery.com> gcc/c/ * c-parser.c (OACC_HOST_DATA_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_IF and PRAGMA_OACC_CLAUSE_IF_PRESENT. gcc/cp/ * parser.c (OACC_HOST_DATA_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_IF and PRAGMA_OACC_CLAUSE_IF_PRESENT. gcc/fortran/ * openmp.c (OACC_HOST_DATA_CLAUSES): Add PRAGMA_OACC_CLAUSE_IF and PRAGMA_OACC_CLAUSE_IF_PRESENT. gcc/ * omp-low.c (lower_omp_target): Use GOMP_MAP_USE_DEVICE_PTR_IF_PRESENT if PRAGMA_OACC_CLAUSE_IF_PRESENT exist. gcc/testsuite/ * c-c++-common/goacc/host_data-1.c: Added tests of if and if_present clauses on host_data. * gfortran.dg/goacc/host_data-tree.f95: Likewise. include/ * gomp-constants.h (enum gomp_map_kind): New enumeration constant GOMP_MAP_USE_DEVICE_PTR_IF_PRESENT. libgomp/ * oacc-parallel.c (GOACC_data_start): Handle GOMP_MAP_USE_DEVICE_PTR_IF_PRESENT. * target.c (gomp_map_vars_async): Likewise. * testsuite/libgomp.oacc-c-c++-common/host_data-7.c: New. * testsuite/libgomp.oacc-fortran/host_data-5.F90: New. From-SVN: r280115
2020-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r279813
2019-12-20OpenACC 2.6 deep copy: C and C++ front-end partsJulian Brown1-9/+44
gcc/c-family/ * c-common.h (c_omp_map_clause_name): Add prototype. * c-omp.c (c_omp_map_clause_name): New function. * c-pragma.h (pragma_omp_clause): Add PRAGMA_OACC_CLAUSE_ATTACH and PRAGMA_OACC_CLAUSE_DETACH. gcc/c/ * c-parser.c (c_parser_omp_clause_name): Add parsing of attach and detach clauses. (c_parser_omp_variable_list): Add ALLOW_DEREF optional parameter. Allow deref (->) in variable lists if true. (c_parser_omp_var_list_parens): Add ALLOW_DEREF optional parameter. Pass to c_parser_omp_variable_list. (c_parser_oacc_data_clause): Support attach and detach clauses. Update call to c_parser_omp_variable_list. (c_parser_oacc_all_clauses): Support attach and detach clauses. (OACC_DATA_CLAUSE_MASK, OACC_ENTER_DATA_CLAUSE_MASK, OACC_KERNELS_CLAUSE_MASK, OACC_PARALLEL_CLAUSE_MASK, OACC_SERIAL_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_ATTACH. (OACC_EXIT_DATA_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_DETACH. * c-typeck.c (handle_omp_array_sections_1): Reject subarrays for attach and detach. Support deref. (handle_omp_array_sections): Use GOMP_MAP_ATTACH_DETACH instead of GOMP_MAP_ALWAYS_POINTER for OpenACC. (c_oacc_check_attachments): New function. (c_finish_omp_clauses): Check attach/detach arguments for being pointers using above. Support deref. gcc/cp/ * parser.c (cp_parser_omp_clause_name): Support attach and detach clauses. (cp_parser_omp_var_list_no_open): Add ALLOW_DEREF optional parameter. Parse deref if true. (cp_parser_omp_var_list): Add ALLOW_DEREF optional parameter. Pass to cp_parser_omp_var_list_no_open. (cp_parser_oacc_data_clause): Support attach and detach clauses. Update call to cp_parser_omp_var_list_no_open. (cp_parser_oacc_all_clauses): Support attach and detach. (OACC_DATA_CLAUSE_MASK, OACC_ENTER_DATA_CLAUSE_MASK, OACC_KERNELS_CLAUSE_MASK, OACC_PARALLEL_CLAUSE_MASK, OACC_SERIAL_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_ATTACH. (OACC_EXIT_DATA_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_DETACH. * semantics.c (handle_omp_array_sections_1): Reject subarrays for attach and detach. (handle_omp_array_sections): Use GOMP_MAP_ATTACH_DETACH instead of GOMP_MAP_ALWAYS_POINTER for OpenACC. (cp_oacc_check_attachments): New function. (finish_omp_clauses): Use above function. Allow structure fields and class members to appear in OpenACC data clauses. Support GOMP_MAP_ATTACH_DETACH. Support deref. gcc/testsuite/ * c-c++-common/goacc/deep-copy-arrayofstruct.c: New test. * c-c++-common/goacc/mdc-1.c: New test. * c-c++-common/goacc/mdc-2.c: New test. * gcc.dg/goacc/mdc.C: New test. Co-Authored-By: Cesar Philippidis <cesar@codesourcery.com> From-SVN: r279627
2019-12-19Add OpenACC 2.6's no_createJulian Brown1-2/+18
The clause makes any device code use the local memory address for each of the variables specified unless the given variable is already present on the current device. 2019-12-19 Julian Brown <julian@codesourcery.com> Maciej W. Rozycki <macro@codesourcery.com> Tobias Burnus <tobias@codesourcery.com> Thomas Schwinge <thomas@codesourcery.com> gcc/ * omp-low.c (lower_omp_target): Support GOMP_MAP_NO_ALLOC. * tree-pretty-print.c (dump_omp_clause): Likewise. gcc/c-family/ * c-pragma.h (pragma_omp_clause): Add PRAGMA_OACC_CLAUSE_NO_CREATE. gcc/c/ * c-parser.c (c_parser_omp_clause_name): Support no_create. (c_parser_oacc_data_clause): Likewise. (c_parser_oacc_all_clauses): Likewise. (OACC_DATA_CLAUSE_MASK, OACC_KERNELS_CLAUSE_MASK) (OACC_PARALLEL_CLAUSE_MASK, OACC_SERIAL_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_NO_CREATE. * c-typeck.c (handle_omp_array_sections): Support GOMP_MAP_NO_ALLOC. gcc/cp/ * parser.c (cp_parser_omp_clause_name): Support no_create. (cp_parser_oacc_data_clause): Likewise. (cp_parser_oacc_all_clauses): Likewise. (OACC_DATA_CLAUSE_MASK, OACC_KERNELS_CLAUSE_MASK) (OACC_PARALLEL_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_NO_CREATE. * semantics.c (handle_omp_array_sections): Support no_create. gcc/fortran/ * gfortran.h (gfc_omp_map_op): Add OMP_MAP_NO_ALLOC. * openmp.c (omp_mask2): Add OMP_CLAUSE_NO_CREATE. (gfc_match_omp_clauses): Support no_create. (OACC_PARALLEL_CLAUSES, OACC_KERNELS_CLAUSES) (OACC_DATA_CLAUSES): Add OMP_CLAUSE_NO_CREATE. * trans-openmp.c (gfc_trans_omp_clauses_1): Support OMP_MAP_NO_ALLOC. gcc/testsuite/ * gfortran.dg/goacc/common-block-1.f90: Add no_create-clause tests. * gfortran.dg/goacc/common-block-1.f90: Likewise. * gfortran.dg/goacc/data-clauses.f95: Likewise. * gfortran.dg/goacc/data-tree.f95: Likewise. * gfortran.dg/goacc/kernels-tree.f95: Likewise. * gfortran.dg/goacc/parallel-tree.f95: Likewise. include/ * gomp-constants.h (gomp_map_kind): Support GOMP_MAP_NO_ALLOC. libgomp/ * target.c (gomp_map_vars_async): Support GOMP_MAP_NO_ALLOC. * testsuite/libgomp.oacc-c-c++-common/no_create-1.c: New test. * testsuite/libgomp.oacc-c-c++-common/no_create-2.c: New test. * testsuite/libgomp.oacc-c-c++-common/no_create-3.c: New test. * testsuite/libgomp.oacc-c-c++-common/no_create-4.c: New test. * testsuite/libgomp.oacc-c-c++-common/no_create-5.c: New test. * testsuite/libgomp.oacc-fortran/no_create-1.f90: New test. * testsuite/libgomp.oacc-fortran/no_create-2.f90: New test. * testsuite/libgomp.oacc-fortran/no_create-3.F90: New test. Reviewed-by: Thomas Schwinge <thomas@codesourcery.com> Co-Authored-By: Maciej W. Rozycki <macro@codesourcery.com> Co-Authored-By: Thomas Schwinge <thomas@codesourcery.com> Co-Authored-By: Tobias Burnus <tobias@codesourcery.com> From-SVN: r279551
2019-11-29Handle C2x attributes in Objective-C.Joseph Myers1-13/+147
When adding the initial support for C2x attributes, I deferred the unbounded lookahead support required to support such attributes in Objective-C (except for the changes to string literal handling, which were the riskier piece of preparation for such lookahead support). This patch adds that remaining ObjC support. For C, the parser continues to work exactly as it did before. For ObjC, however, when checking for whether '[[' starts attributes, it lexes however many tokens are needed to check for a matching ']]', but in a raw mode that omits all the context-sensitive processing that c_lex_with_flags normally does, so that that processing can be done later when the right context-sensitive flags are set. Those tokens are saved in a separate raw_tokens vector in the parser, and normal c_lex_one_token calls will get tokens from there and perform the remaining processing on them, if any tokens are found there, so all parsing not using the new interfaces gets the same tokens as it did before. (For C, this raw lexing never occurs and the vector of raw tokens is always NULL.) Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/c: * c-parser.c (struct c_parser): Add members raw_tokens and raw_tokens_used. (c_lex_one_token): Add argument raw. Handle lexing raw tokens and using previously-lexed raw tokens. (c_parser_peek_nth_token_raw) (c_parser_check_balanced_raw_token_sequence): New functions. (c_parser_nth_token_starts_std_attributes): Use c_parser_check_balanced_raw_token_sequence for Objective-C. gcc/testsuite: * objc.dg/attributes/gnu2x-attr-syntax-1.m: New test. From-SVN: r278827
2019-11-25Properly handle C2x attributes on types.Joseph Myers1-11/+6
attribs.c has code to ignore all scoped attributes appertaining to types except when they are part of the definition of that type. I think the premise of that code is incorrect, and its presence is a bug; such attributes are clearly valid in both C and C++, which explicitly specify that attributes in certain syntactic positions appertain to a particular type, only for that use of that type and not for other uses of the same type specifiers without that attribute specified, and while the standard attributes in C2x aren't relevant in such contexts, some gnu:: attributes certainly are. Where some attributes are invalid on some types in such contexts, that's a matter for the individual attribute handlers to diagnose (or the front end if the requirements on a standard attribute in the standard are more strict than those of a handler shared with a GNU attribute). Thus, this patch removes the bogus code to allow such attributes to be used. Doing so (and adding tests for attributes in such positions) shows up that the logic in the C front end for creating the c_declarator structures for such attributes put them in the wrong place relative to the structures for function and array types, and the logic for postfix attributes on a list of declaration specifiers failed to handle some cases, so those bugs are also fixed in this patch. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc: * attribs.c (decl_attributes): Do not ignore C++11 attributes on types. gcc/c: * c-tree.h (struct c_declarator): Use a structure for id member. * c-decl.c (grokdeclarator): Extract attributes from cdk_id declarators at the start, not when handling individual declarators later. Use u.id.id instead of u.id. (grokfield): Use u.id.id instead of u.id. (build_id_declarator): Set u.id.id and u.id.attrs. (finish_declspecs): Handle postfix attributes in case of typedef name or typeof used. * c-parser.c (c_parser_direct_declarator) (c_parser_direct_declarator_inner): Place declarator for attributes inside that for function or array, not outside. Set u.id.attrs for identifiers. (c_parser_parameter_declaration): Use u.id.id instead of u.id. * gimple-parser.c (c_parser_gimple_declaration): Use u.id.id instead of u.id. gcc/testsuite: * gcc.dg/gnu2x-attrs-1.c: Do not expect message about attributes appertaining to types. * gcc.dg/gnu2x-attrs-2.c: New test. * g++.dg/cpp0x/gen-attrs-1.C, g++.dg/cpp0x/gen-attrs-22.C, g++.dg/cpp0x/gen-attrs-4.C, g++.dg/cpp0x/lambda/lambda-attr1.C: Update expected diagnostics. From-SVN: r278683
2019-11-19Change some bad uses of C2x attributes into pedwarns.Joseph Myers1-32/+46
Certain bad uses of C2x standard attributes (that is, attributes inside [[]] with only a name but no namespace specified) are constraint violations, and so should be diagnosed with a pedwarn (or error) where GCC currently uses a warning. This patch implements this in some cases (not yet for attributes used on types, nor for some bad uses of fallthrough attributes). Specifically, this applies to unknown standard attributes (taking care not to pedwarn for nodiscard, which is known but not implemented for C), and to all currently implemented standard attributes in attribute declarations (including when mixed with fallthrough) and on statements. Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c: * c-decl.c (c_warn_unused_attributes): Use pedwarn not warning for standard attributes. * c-parser.c (c_parser_std_attribute): Take argument for_tm. Use pedwarn for unknown standard attributes and return error_mark_node for them. gcc/c-family: * c-common.c (attribute_fallthrough_p): In C, use pedwarn not warning for standard attributes mixed with fallthrough attributes. gcc/testsuite: * gcc.dg/c2x-attr-fallthrough-5.c, gcc.dg/c2x-attr-syntax-5.c: New tests. * gcc.dg/c2x-attr-deprecated-2.c, gcc.dg/c2x-attr-deprecated-4.c, gcc.dg/c2x-attr-fallthrough-2.c, gcc.dg/c2x-attr-maybe_unused-2.c, gcc.dg/c2x-attr-maybe_unused-4.c: Expect errors in place of some warnings. From-SVN: r278428
2019-11-18[mid-end][__RTL] Clean state despite unspecified __RTL startwith passesMatthew Malcomson1-5/+3
Hi there, When compiling an __RTL function that has an unspecified "startwith" pass we currently don't run the cleanup pass, this means that we ICE on the next function (if it's a basic function). This change ensures that the clean_state pass is run even if the startwith pass is unspecified. We also ensure the name of the startwith pass is always freed correctly. As an example, before this change the following code would ICE when compiling the function `foo_a`. When compiled with ./aarch64-none-linux-gnu-gcc -O0 -S unspecified-pass-error.c -o test.s ``` int __RTL () badfoo () { (function "badfoo" (insn-chain (block 2 (edge-from entry (flags "FALLTHRU")) (cnote 3 [bb 2] NOTE_INSN_BASIC_BLOCK) (cinsn 101 (set (reg:DI x19) (reg:DI x0))) (cinsn 10 (use (reg/i:SI x19))) (edge-to exit (flags "FALLTHRU")) ) ;; block 2 ) ;; insn-chain ) ;; function "foo2" } int foo_a () { return 200; } ``` Now it silently ignores the __RTL function and successfully compiles foo_a. regtest done on aarch64 regtest done on x86_64 OK for trunk? gcc/ChangeLog: 2019-11-18 Matthew Malcomson <matthew.malcomson@arm.com> * run-rtl-passes.c (run_rtl_passes): Accept and handle empty "initial_pass_name" argument -- by running "*clean_state" pass. Also free the "initial_pass_name" when done. gcc/c/ChangeLog: 2019-11-18 Matthew Malcomson <matthew.malcomson@arm.com> * c-parser.c (c_parser_parse_rtl_body): Always call run_rtl_passes, even if startwith pass is not provided. gcc/testsuite/ChangeLog: 2019-11-18 Matthew Malcomson <matthew.malcomson@arm.com> * gcc.dg/rtl/aarch64/unspecified-pass-error.c: New test. From-SVN: r278393
2019-11-15Diagnose duplicate C2x standard attributes.Joseph Myers1-2/+52
For each of the attributes currently included in C2x, it has a constraint that the attribute shall appear at most once in each attribute list (attribute-list being what appear between a single [[ and ]]). This patch implements that check. As the corresponding check in the C++ front end (cp_parser_check_std_attribute) makes violations into errors, I made them into errors, with the same wording, for C as well. There is an existing check in the case of the fallthrough attribute, with a warning rather than an error, in attribute_fallthrough_p. That is more general, as it also covers __attribute__ ((fallthrough)) and the case of [[fallthrough]] [[fallthrough]] (multiple attribute-lists in a single attribute-specifier-sequence), which is not a constraint violation. To avoid some [[fallthrough, fallthrough]] being diagnosed twice, the check I added avoids adding duplicate attributes to the list. Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c: * c-parser.c (c_parser_std_attribute_specifier): Diagnose duplicate standard attributes. gcc/testsuite: * gcc.dg/c2x-attr-deprecated-4.c, gcc.dg/c2x-attr-fallthrough-4.c, gcc.dg/c2x-attr-maybe_unused-4.c: New tests. From-SVN: r278324
2019-11-15Improve checks on C2x fallthrough attribute.Joseph Myers1-3/+9
When adding C2x attribute support, some [[fallthrough]] support appeared as a side-effect because of code for that attribute going through separate paths from the normal attribute handling. However, going through those paths without the normal attribute handlers meant that certain checks, such as for the invalid usage [[fallthrough()]], did not operate. This patch improves checks by adding this attribute to the standard attribute table, so that the parser knows it expects no arguments, along with adding an explicit check for "[[fallthrough]];" attribute-declarations at top level. As with other attributes, there are still cases where warnings should be pedwarns because C2x constraints are violated, but this patch improves the attribute handling. Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c: * c-decl.c (std_attribute_table): Add fallthrough. * c-parser.c (c_parser_declaration_or_fndef): Diagnose fallthrough attribute at top level. gcc/c-family: * c-attribs.c (handle_fallthrough_attribute): Remove static. * c-common.h (handle_fallthrough_attribute): Declare. gcc/testsuite: * gcc.dg/c2x-attr-fallthrough-2.c, gcc.dg/c2x-attr-fallthrough-3.c: New tests. From-SVN: r278273
2019-11-15Support C2x [[deprecated]] attribute.Joseph Myers1-4/+24
This patch adds support for the C2x [[deprecated]] attribute. All the actual logic for generating warnings can be identical to the GNU __attribute__ ((deprecated)), as can the attribute handler, so this is just a matter of wiring things up appropriately and adding the checks specified in the standard. Unlike for C++, this patch gives "deprecated" an entry in a table of standard attributes rather than remapping it internally to the GNU attribute, as that seems a cleaner approach to me. Specifically, the only form of arguments to the attribute permitted in the standard is (string-literal); empty parentheses are not permitted in the case of no arguments, and a string literal (which includes concatenated adjacent string literals, because concatenation is an earlier phase of translation) cannot have further redundant parentheses around it. For the case of empty parentheses, this patch makes the C parser disallow them for all known attributes using the [[]] syntax, as done for C++. For string literals (where the C++ front end is missing the check to avoid redundant parentheses, 92521 filed for that issue), a special case is inserted in the C parser. A known issue that I think can be addressed later as a bug fix is that the warnings for the attribute being ignored in certain cases (attribute declarations, statements, most uses on types) ought to be pedwarns, as those usages are constraint violations. Bad handling of wide string literals with this attribute is also a pre-existing bug (91182 - although that's filed as a C++ bug, the code in question is language-independent, in tree.c). Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c: * c-decl.c (std_attribute_table): New. (c_init_decl_processing): Register attributes from std_attribute_table. * c-parser.c (c_parser_attribute_arguments): Add arguments require_string and allow_empty_args. All callers changed. (c_parser_std_attribute): Set require_string argument for "deprecated" attribute. gcc/c-family: * c-attribs.c (handle_deprecated_attribute): Remove static. * c-common.h (handle_deprecated_attribute): Declare. gcc/testsuite: * gcc.dg/c2x-attr-deprecated-1.c, gcc.dg/c2x-attr-deprecated-2.c, gcc.dg/c2x-attr-deprecated-3.c: New tests. From-SVN: r278268
2019-11-14Support UTF-8 character constants for C2x.Joseph Myers1-0/+2
C2x adds u8'' character constants to C. This patch adds the corresponding GCC support. Most of the support was already present for C++ and just needed enabling for C2x. However, in C2x these constants have type unsigned char, which required corresponding adjustments in the compiler and the preprocessor to give them that type for C. For C, it seems clear to me that having type unsigned char means the constants are unsigned in the preprocessor (and thus treated as having type uintmax_t in #if conditionals), so this patch implements that. I included a conditional in the libcpp change to avoid affecting signedness for C++, but I'm not sure if in fact these constants should also be unsigned in the preprocessor for C++ in which case that !CPP_OPTION (pfile, cplusplus) conditional would not be needed. Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c: * c-parser.c (c_parser_postfix_expression) (c_parser_check_literal_zero): Handle CPP_UTF8CHAR. * gimple-parser.c (c_parser_gimple_postfix_expression): Likewise. gcc/c-family: * c-lex.c (lex_charconst): Make CPP_UTF8CHAR constants unsigned char for C. gcc/testsuite: * gcc.dg/c11-utf8char-1.c, gcc.dg/c2x-utf8char-1.c, gcc.dg/c2x-utf8char-2.c, gcc.dg/c2x-utf8char-3.c, gcc.dg/gnu2x-utf8char-1.c: New tests. libcpp: * charset.c (narrow_str_to_charconst): Make CPP_UTF8CHAR constants unsigned for C. * init.c (lang_defaults): Set utf8_char_literals for GNUC2X and STDC2X. From-SVN: r278265
2019-11-14c-parser.c (c_parser_omp_context_selector): Don't require score argument to ↵Jakub Jelinek1-1/+4
fit into shwi, just to be INTEGER_CST. * c-parser.c (c_parser_omp_context_selector): Don't require score argument to fit into shwi, just to be INTEGER_CST. Diagnose negative score. * parser.c (cp_parser_omp_context_selector): Don't require score argument to fit into shwi, just to be INTEGER_CST. Diagnose negative score. * pt.c (tsubst_attribute): Likewise. * c-c++-common/gomp/declare-variant-2.c: Add test for non-integral score and for negative score. * c-c++-common/gomp/declare-variant-3.c: Add test for zero score. * g++.dg/gomp/declare-variant-8.C: Add test for negative and zero scores. From-SVN: r278204
2019-11-14omp-general.c (omp_context_name_list_prop): New function.Jakub Jelinek1-12/+38
* omp-general.c (omp_context_name_list_prop): New function. (omp_context_selector_matches): Use it. Return 0 if it returns NULL. (omp_context_selector_props_compare): Allow equivalency of an identifier and a string literal containing no embedded zeros. c-family/ * c-omp.c (c_omp_check_context_selector): Handle name lists containing string literals. Don't diagnose atomic_default_mem_order with multiple props. c/ * c-parser.c (c_parser_omp_context_selector): Rename CTX_PROPERTY_IDLIST to CTX_PROPERTY_NAME_LIST, add CTX_PROPERTY_ID. Use CTX_PROPERTY_ID for atomic_default_mem_order, only allow a single identifier in that. For CTX_PROPERTY_NAME_LIST, allow identifiers and string literals. cp/ * parser.c (cp_parser_omp_context_selector): Rename CTX_PROPERTY_IDLIST to CTX_PROPERTY_NAME_LIST, add CTX_PROPERTY_ID. Use CTX_PROPERTY_ID for atomic_default_mem_order, only allow a single identifier in that. For CTX_PROPERTY_NAME_LIST, allow identifiers and string literals. * pt.c (tsubst_attribute): Fix up STRING_CST handling if allow_string. testsuite/ * c-c++-common/gomp/declare-variant-2.c: Adjust expected diagnostics, add a test for atomic_default_mem_order with a string literal. * c-c++-common/gomp/declare-variant-3.c: Use string literal props in a few random places, add a few string literal prop related tests. * c-c++-common/gomp/declare-variant-8.c: Likewise. * c-c++-common/gomp/declare-variant-9.c: Use string literal props in a few random places. * c-c++-common/gomp/declare-variant-10.c: Likewise. * c-c++-common/gomp/declare-variant-11.c: Likewise. * c-c++-common/gomp/declare-variant-12.c: Likewise. * g++.dg/gomp/declare-variant-7.C: Likewise. From-SVN: r278202
2019-11-14Support C2x [[]] attributes for C.Joseph Myers1-99/+328
This patch adds support for the C2x [[]] attribute syntax to the C front end. Support is only added for C at this point, not for Objective-C; I intend to add the unbounded lookahead required to support it for Objective-C in a followup patch, but maybe not in development stage 1. The syntax is supported in all relevant places where the standard says it is supported, but support is not added for the individual attributes specified in C2x (all of which are optional to support). I expect to add support for some of them in followup patches; all except nodiscard can be mapped directly to the semantics of an existing GNU attribute (subject to extra checks for invalid usages such as the same attribute being used more than once inside a single [[]]), and the fallthrough attribute already works after this patch because of existing special-case code handling it (but without some of the checks for invalid usage being present). Note that the four functions c_token_starts_declspecs, c_token_starts_declaration, c_parser_next_token_starts_declspecs and c_parser_next_tokens_start_declaration do *not* accept "[[". This is analogous with the handling of __extension__: both cases have the property that they can start either a declaration or some other statements and so need an unbounded number of tokens to be parsed in the caller before it can find out what kind of syntactic construct follows. Note also that, while I updated all places calling those functions for standard C syntax to handle attributes if applicable, I did not do anything regarding calls to such functions for OpenMP or OpenACC constructs. Thus, if there are such constructs using such functions where "[[" *should* be accepted as a possible start to a declaration, the code for parsing those constructs should be updated accordingly. Although all cases of the syntax are handled, and attributes applied to the constructs the standard says they should be (with less laxity than there is for GNU attributes to allow an attribute applied to one construct to be moved automatically to another one), there is a major limitation in the existing language-independent code in attribs.c preventing most cases of type attributes from working. The following code has been present with minor changes since the first support for [[]] attributes for C++ was added: if (TYPE_P (*node) && cxx11_attr_p && !(flags & ATTR_FLAG_TYPE_IN_PLACE)) { /* This is a c++11 attribute that appertains to a type-specifier, outside of the definition of, a class type. Ignore it. */ auto_diagnostic_group d; if (warning (OPT_Wattributes, "attribute ignored")) inform (input_location, "an attribute that appertains to a type-specifier " "is ignored"); continue; } I see no justification for this in general for either C or C++ and so propose to remove or restrict it in a followup bug-fix patch. Both C and C++ are clear about attributes in certain places (at the end of declaration specifiers, or after function or array declarators) appertaining to a specific type (and explicitly say, in the case of attributes at the end of declaration specifiers, that they only apply for that particular use of that type, not for subsequent uses of the same type without the attributes). Thus it seems clear to me that, for example, int [[gnu::mode(DI)]] x; ought to be accepted as an analogue in [[]] syntax for int __attribute__((mode(DI))) x; (or strictly as an analogue for a version of that with extra parentheses to make the GNU attribute bind properly to the type rather than being automatically moved from the declaration to the type). There are certain cases where an attribute *does* only make sense for the definition of a type (e.g. "packed" on structure types), but those should already be handled in the individual attribute handlers (such as handle_packed_attribute, which already has code to deal with that issue). So my inclination is that the above-quoted check in attribs.c should simply be removed, but failing that it should be restricted to structure and union types (and such a change would be a bug-fix). That would then allow various cases of [[]] attributes on types to work properly. Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c: * c-tree.h (enum c_typespec_kind): Add ctsk_tagref_attrs and ctsk_tagfirstref_attrs. (struct c_declspecs): Update description of attrs. Add postfix_attrs and non_std_attrs_seen_p. Increase size of typespec_kind bit-field. (c_warn_unused_attributes): New declaration. (parser_xref_tag): Update prototype. * c-decl.c (c_warn_unused_attributes): New function. (shadow_tag_warned): Handle ctsk_tagfirstref_attrs and ctsk_tagref_attrs. Handle attribute declarations. (check_compound_literal_type): Handle ctsk_tagfirstref_attrs. (grokdeclarator): Handle standard attributes. (parser_xref_tag): Add arguments have_std_attrs and attrs. Apply attributes to incomplete type reference. (xref_tag): Update call to parser_xref_tag. (declspecs_add_addrspace, declspecs_add_type) (declspecs_add_scspec, declspecs_add_attrs): Set non_std_attrs_seen_p. (finish_declspecs): Apply postfix standard attributes to type. * c-parser.c (c_token_starts_declspecs) (c_token_starts_declaration, c_parser_next_token_starts_declspecs) (c_parser_next_tokens_start_declaration): Update comments. (c_parser_consume_token, c_parser_consume_pragma): Handle moving parser->tokens[2] to parser->tokens[1]. (c_parser_nth_token_starts_std_attributes) (c_parser_std_attribute_specifier_sequence): New functions. (c_parser_declaration_or_fndef): Add arguments have_attrs and attrs. All callers changed. Handle standard attributes. (c_parser_parms_declarator, c_parser_parms_list_declarator) (c_parser_parameter_declaration): Add argument have_gnu_attrs. All callers changed. (c_parser_declspecs): Add arguments start_std_attr_ok and end_std_attr_ok. All callers changed. Handle standard attributes. (c_parser_enum_specifier, c_parser_struct_or_union_specifier) (c_parser_direct_declarator, c_parser_direct_declarator_inner) (c_parser_compound_statement_nostart, c_parser_all_labels) (c_parser_label, c_parser_statement, c_parser_for_statement): Handle standard attributes. * c-parser.h (c_parser_declspecs): Update prototype. * gimple-parser.c (c_parser_gimple_declaration): Update call to c_parser_declspecs. gcc/testsuite: * gcc.dg/c2x-attr-fallthrough-1.c, gcc.dg/c2x-attr-syntax-1.c, gcc.dg/c2x-attr-syntax-2.c, gcc.dg/c2x-attr-syntax-3.c, gcc.dg/gnu2x-attr-syntax-1.c, gcc.dg/gnu2x-attr-syntax-2.c, gcc.dg/gnu2x-attrs-1.c: New tests. From-SVN: r278194
2019-11-12Add OpenACC 2.6 `serial' construct supportMaciej W. Rozycki1-5/+29
The `serial' construct (cf. section 2.5.3 of the OpenACC 2.6 standard) is equivalent to a `parallel' construct with clauses `num_gangs(1) num_workers(1) vector_length(1)' implied. These clauses are therefore not supported with the `serial' construct. All the remaining clauses accepted with `parallel' are also accepted with `serial'. The `serial' construct is implemented like `parallel', except for hardcoding dimensions rather than taking them from the relevant clauses, in `expand_omp_target'. Separate codes are used to denote the `serial' construct throughout the middle end, even though the mapping of `serial' to an equivalent `parallel' construct could have been done in the individual language frontends. In particular, this allows to distinguish between compute constructs in warnings, error messages, dumps etc. 2019-11-12 Maciej W. Rozycki <macro@codesourcery.com> Tobias Burnus <tobias@codesourcery.com> Frederik Harwath <frederik@codesourcery.com> Thomas Schwinge <thomas@codesourcery.com> gcc/ * gimple.h (gf_mask): Add GF_OMP_TARGET_KIND_OACC_SERIAL enumeration constant. (is_gimple_omp_oacc): Handle GF_OMP_TARGET_KIND_OACC_SERIAL. (is_gimple_omp_offloaded): Likewise. * gimplify.c (omp_region_type): Add ORT_ACC_SERIAL enumeration constant. Adjust the value of ORT_NONE accordingly. (is_gimple_stmt): Handle OACC_SERIAL. (oacc_default_clause): Handle ORT_ACC_SERIAL. (gomp_needs_data_present): Likewise. (gimplify_adjust_omp_clauses): Likewise. (gimplify_omp_workshare): Handle OACC_SERIAL. (gimplify_expr): Likewise. * omp-expand.c (expand_omp_target): Handle GF_OMP_TARGET_KIND_OACC_SERIAL. (build_omp_regions_1, omp_make_gimple_edges): Likewise. * omp-low.c (is_oacc_parallel): Rename function to... (is_oacc_parallel_or_serial): ... this. Handle GF_OMP_TARGET_KIND_OACC_SERIAL. (scan_sharing_clauses): Adjust accordingly. (scan_omp_for): Likewise. (lower_oacc_head_mark): Likewise. (convert_from_firstprivate_int): Likewise. (lower_omp_target): Likewise. (check_omp_nesting_restrictions): Handle GF_OMP_TARGET_KIND_OACC_SERIAL. (lower_oacc_reductions): Likewise. (lower_omp_target): Likewise. * tree.def (OACC_SERIAL): New tree code. * tree-pretty-print.c (dump_generic_node): Handle OACC_SERIAL. * doc/generic.texi (OpenACC): Document OACC_SERIAL. gcc/c-family/ * c-pragma.h (pragma_kind): Add PRAGMA_OACC_SERIAL enumeration constant. * c-pragma.c (oacc_pragmas): Add "serial" entry. gcc/c/ * c-parser.c (OACC_SERIAL_CLAUSE_MASK): New macro. (c_parser_oacc_kernels_parallel): Rename function to... (c_parser_oacc_compute): ... this. Handle PRAGMA_OACC_SERIAL. (c_parser_omp_construct): Update accordingly. gcc/cp/ * constexpr.c (potential_constant_expression_1): Handle OACC_SERIAL. * parser.c (OACC_SERIAL_CLAUSE_MASK): New macro. (cp_parser_oacc_kernels_parallel): Rename function to... (cp_parser_oacc_compute): ... this. Handle PRAGMA_OACC_SERIAL. (cp_parser_omp_construct): Update accordingly. (cp_parser_pragma): Handle PRAGMA_OACC_SERIAL. Fix alphabetic order. * pt.c (tsubst_expr): Handle OACC_SERIAL. gcc/fortran/ * gfortran.h (gfc_statement): Add ST_OACC_SERIAL_LOOP, ST_OACC_END_SERIAL_LOOP, ST_OACC_SERIAL and ST_OACC_END_SERIAL enumeration constants. (gfc_exec_op): Add EXEC_OACC_SERIAL_LOOP and EXEC_OACC_SERIAL enumeration constants. * match.h (gfc_match_oacc_serial): New prototype. (gfc_match_oacc_serial_loop): Likewise. * dump-parse-tree.c (show_omp_node, show_code_node): Handle EXEC_OACC_SERIAL_LOOP and EXEC_OACC_SERIAL. * match.c (match_exit_cycle): Handle EXEC_OACC_SERIAL_LOOP. * openmp.c (OACC_SERIAL_CLAUSES): New macro. (gfc_match_oacc_serial_loop): New function. (gfc_match_oacc_serial): Likewise. (oacc_is_loop): Handle EXEC_OACC_SERIAL_LOOP. (resolve_omp_clauses): Handle EXEC_OACC_SERIAL. (oacc_code_to_statement): Handle EXEC_OACC_SERIAL and EXEC_OACC_SERIAL_LOOP. (gfc_resolve_oacc_directive): Likewise. * parse.c (decode_oacc_directive) <'s'>: Add case for "serial" and "serial loop". (next_statement): Handle ST_OACC_SERIAL_LOOP and ST_OACC_SERIAL. (gfc_ascii_statement): Likewise. Handle ST_OACC_END_SERIAL_LOOP and ST_OACC_END_SERIAL. (parse_oacc_structured_block): Handle ST_OACC_SERIAL. (parse_oacc_loop): Handle ST_OACC_SERIAL_LOOP and ST_OACC_END_SERIAL_LOOP. (parse_executable): Handle ST_OACC_SERIAL_LOOP and ST_OACC_SERIAL. (is_oacc): Handle EXEC_OACC_SERIAL_LOOP and EXEC_OACC_SERIAL. * resolve.c (gfc_resolve_blocks, gfc_resolve_code): Likewise. * st.c (gfc_free_statement): Likewise. * trans-openmp.c (gfc_trans_oacc_construct): Handle EXEC_OACC_SERIAL. (gfc_trans_oacc_combined_directive): Handle EXEC_OACC_SERIAL_LOOP. (gfc_trans_oacc_directive): Handle EXEC_OACC_SERIAL_LOOP and EXEC_OACC_SERIAL. * trans.c (trans_code): Likewise. gcc/testsuite/ * c-c++-common/goacc/parallel-dims.c: New test. * gfortran.dg/goacc/parallel-dims.f90: New test. libgomp/ * testsuite/libgomp.oacc-c-c++-common/parallel-dims.c: New test. * testsuite/libgomp.oacc-fortran/parallel-dims-aux.c: New test. * testsuite/libgomp.oacc-fortran/parallel-dims.f89: New test. * testsuite/libgomp.oacc-fortran/parallel-dims-2.f90: New test. Reviewed-by: Thomas Schwinge <thomas@codesourcery.com> Co-Authored-By: Frederik Harwath <frederik@codesourcery.com> Co-Authored-By: Thomas Schwinge <thomas@codesourcery.com> Co-Authored-By: Tobias Burnus <tobias@codesourcery.com> From-SVN: r278082
2019-11-11c-parser.c (c_parser_translation_unit): Diagnose declare target without ↵Jakub Jelinek1-0/+8
corresponding end declare target. * c-parser.c (c_parser_translation_unit): Diagnose declare target without corresponding end declare target. * semantics.c (finish_translation_unit): Diagnose declare target without corresponding end declare target. * c-c++-common/gomp/declare-target-5.c: New test. From-SVN: r278065