aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
AgeCommit message (Collapse)AuthorFilesLines
6 daysDaily bump.GCC Administrator1-0/+9
7 daysAda: Make -fdump-ada-spec deal with pointers to anonymous structureEric Botcazou1-3/+23
This is about -fdump-ada-spec not generating the definition of the structure for pointers to anonymous structure as structure elements. gcc/c-family: PR ada/121544 * c-ada-spec.cc (dump_ada_node) <POINTER_TYPE>: Dump the name of anonymous tagged pointed-to types specially. (dump_nested_type) <POINTER_TYPE>: Recurse on anonymous pointed-to types declared in the same file. Set TREE_VISITED on the underlying DECL of the field type, if any.
2025-08-28Daily bump.GCC Administrator1-0/+8
2025-08-27c++: Fix up cpp_warn on __STDCPP_FLOAT*_T__ [PR121520]Jakub Jelinek1-8/+8
I got the cpp_warn on __STDCPP_FLOAT*_T__ if we aren't predefining those wrong, so e.g. on powerpc64le we don't diagnose #undef __STDCPP_FLOAT16_T__. I've added it as else if on the if (c_dialect_cxx () && cxx_dialect > cxx20 && !floatn_nx_types[i].extended) condition, which means cpp_warn is called in case a target supports some extended type like _Float32x, cpp_warn is called on __STDCPP_FLOAT32_T__ (where when it supported _Float32 as well it did cpp_define_warn (pfile, "__STDCPP_FLOAT32_T__=1") earlier). On targets where the types aren't supported the earlier if (FLOATN_NX_TYPE_NODE (i) == NULL_TREE) continue; path is taken. This patch fixes it to cpp_warn on the non-extended types for C++23 if the target doesn't support them and cpp_define_warn as before if it does. 2025-08-27 Jakub Jelinek <jakub@redhat.com> PR target/121520 * c-cppbuiltin.cc (c_cpp_builtins): Properly call cpp_warn for __STDCPP_FLOAT<NN>_T__ if FLOATN_NX_TYPE_NODE (i) is NULL for C++23 for non-extended types and don't call cpp_warn for extended types.
2025-08-19Daily bump.GCC Administrator1-0/+10
2025-08-18opts: use sanitize_code_type for sanitizer flagsIndu Bhagat2-9/+10
Currently, the data type of sanitizer flags is unsigned int, with SANITIZE_SHADOW_CALL_STACK (1UL << 31) being highest individual enumerator for enum sanitize_code. Use 'sanitize_code_type' data type to allow for more distinct instrumentation modes be added when needed. gcc/ChangeLog: * flag-types.h (sanitize_code_type): Define. * asan.h (sanitize_flags_p): Use 'sanitize_code_type' instead of 'unsigned int'. * common.opt: Likewise. * dwarf2asm.cc (dw2_output_indirect_constant_1): Likewise. * opts.cc (find_sanitizer_argument): Likewise. (report_conflicting_sanitizer_options): Likewise. (parse_sanitizer_options): Likewise. (parse_no_sanitize_attribute): Likewise. * opts.h (parse_sanitizer_options): Likewise. (parse_no_sanitize_attribute): Likewise. * tree-cfg.cc (print_no_sanitize_attr_value): Likewise. * tree.cc (tree_fits_sanitize_code_type_p): Define. (tree_to_sanitize_code_type): Likewise. * tree.h (tree_fits_sanitize_code_type_p): Declare. (tree_to_sanitize_code_type): Likewise. gcc/c-family/ChangeLog: * c-attribs.cc (add_no_sanitize_value): Use 'sanitize_code_type' instead of 'unsigned int'. (handle_no_sanitize_attribute): Likewise. (handle_no_sanitize_address_attribute): Likewise. (handle_no_sanitize_thread_attribute): Likewise. (handle_no_address_safety_analysis_attribute): Likewise. * c-common.h (add_no_sanitize_value): Likewise. gcc/c/ChangeLog: * c-parser.cc (c_parser_declaration_or_fndef): Use 'sanitize_code_type' instead of 'unsigned int'. gcc/cp/ChangeLog: * typeck.cc (get_member_function_from_ptrfunc): Use 'sanitize_code_type' instead of 'unsigned int'. gcc/d/ChangeLog: * d-attribs.cc (d_handle_no_sanitize_attribute): Use 'sanitize_code_type' instead of 'unsigned int'. Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
2025-08-16Daily bump.GCC Administrator1-0/+37
2025-08-15c++: Implement C++20 P1766R1 - Mitigating minor modules maladies [PR121552]Jakub Jelinek2-0/+7
The following patch attempts to implement the C++20 P1766R1 - Mitigating minor modules maladies paper. clang++ a few years ago introduced for the diagnostics required in the paper -Wnon-c-typedef-for-linkage pedwarn and the following patch does that too. The paper was accepted as a DR, the patch enables the warning also for C++98, dunno whether it might not be better to do it only for C++11 onwards. The paper is also about differences in default arguments of functions in different TUs and in modules, I think within the same TU we diagnose it correctly (maybe I should add some testcase) and perhaps try something with modules as well. But in different TUs it is IFNDR. 2025-08-15 Jakub Jelinek <jakub@redhat.com> PR c++/121552 gcc/ * doc/invoke.texi (-Wno-non-c-typedef-for-linkage): Document. gcc/c-family/ * c.opt (Wnon-c-typedef-for-linkage): New option. * c.opt.urls: Regenerate. gcc/cp/ * decl.cc: Implement C++20 P1766R1 - Mitigating minor modules maladies. (diagnose_non_c_class_typedef_for_linkage, maybe_diagnose_non_c_class_typedef_for_linkage): New functions. (name_unnamed_type): Call maybe_diagnose_non_c_class_typedef_for_linkage. gcc/testsuite/ * g++.dg/cpp2a/typedef1.C: New test. * g++.dg/debug/dwarf2/typedef5.C: Add -Wno-non-c-typedef-for-linkage to dg-options. * g++.dg/inherit/typeinfo1.C: Add -Wno-non-c-typedef-for-linkage to dg-additional-options. * g++.dg/parse/ctor2.C: Likewise. * g++.dg/ext/anon-struct9.C: Add -Wno-non-c-typedef-for-linkage to dg-options. * g++.dg/ext/visibility/anon11.C: Add -Wno-non-c-typedef-for-linkage to dg-additional-options. * g++.dg/lto/pr69137_0.C: Add -Wno-non-c-typedef-for-linkage to dg-lto-options. * g++.dg/other/anon8.C: Add -Wno-non-c-typedef-for-linkage to dg-additional-options. * g++.dg/template/pr84973.C: Likewise. * g++.dg/template/pr84973-2.C: Likewise. * g++.dg/template/pr84973-3.C: Likewise. * g++.dg/abi/anon2.C: Likewise. * g++.dg/abi/anon3.C: Likewise. * g++.old-deja/g++.oliva/linkage1.C: Likewise.
2025-08-15c++: Warn on #undef/#define of remaining cpp.predefined macros [PR120778]Jakub Jelinek1-10/+60
We already warn on #undef or pedwarn on #define (but not on #define after #undef) of some builtin macros mentioned in cpp.predefined. The C++26 P2843R3 paper changes it from (compile time) undefined behavior to ill-formed. The following patch arranges for warning (for #undef) and pedwarn (on #define) for the remaining cpp.predefined macros. __cpp_* feature test macros only for C++20 which added some of them to cpp.predefined, in earlier C++ versions it was just an extension and for pedantic diagnostic I think we don't need to diagnose anything, __STDCPP_* and __cplusplus macros for all C++ versions where they appeared. Like the earlier posted -Wkeyword-macro diagnostics (which is done regardless whether the identifier is defined as a macro or not, obviously most likely none of the keywords are defined as macros initially), this one also warns on #undef when a macro isn't defined or later #define after #undef. 2025-08-15 Jakub Jelinek <jakub@redhat.com> PR preprocessor/120778 PR target/121520 gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): Implement C++26 DR 2581. Add cpp_define_warn lambda and use it as well as cpp_warn where needed. In the if (c_dialect_cxx ()) block with __cpp_* predefinitions add cpp_define lambda. Formatting fixes. gcc/c/ * c-decl.cc (c_init_decl_processing): Use cpp_warn instead of cpp_lookup and NODE_WARN bit setting. gcc/cp/ * lex.cc (cxx_init): Remove warn_on lambda. Use cpp_warn instead of cpp_lookup and NODE_WARN bit setting or warn_on. gcc/testsuite/ * g++.dg/DRs/dr2581-1.C: New test. * g++.dg/DRs/dr2581-2.C: New test. * c-c++-common/cpp/pr92296-2.c: Expect warnings also on defining special macros after undefining them. libcpp/ * include/cpplib.h (struct cpp_options): Add suppress_builtin_macro_warnings member. (cpp_warn): New inline functions. * init.cc (cpp_create_reader): Clear suppress_builtin_macro_warnings. (cpp_init_builtins): Call cpp_warn on __cplusplus, __STDC__, __STDC_VERSION__, __STDC_MB_MIGHT_NEQ_WC__ and __STDCPP_STRICT_POINTER_SAFETY__ when appropriate. * directives.cc (do_undef): Warn on undefining NODE_WARN macros if not cpp_keyword_p. Don't emit any NODE_WARN related diagnostics if CPP_OPTION (pfile, suppress_builtin_macro_warnings). (cpp_define, _cpp_define_builtin, cpp_undef): Temporarily set CPP_OPTION (pfile, suppress_builtin_macro_warnings) around run_directive calls. * macro.cc (_cpp_create_definition): Warn on defining NODE_WARN macros if they weren't previously defined and not cpp_keyword_p. Ignore NODE_WARN for diagnostics if CPP_OPTION (pfile, suppress_builtin_macro_warnings).
2025-08-15Use the counted_by attribute of pointers in array bound checker.Qing Zhao2-16/+322
Current array bound checker only instruments ARRAY_REF, and the INDEX information is the 2nd operand of the ARRAY_REF. When extending the array bound checker to pointer references with counted_by attributes, the hardest part is to get the INDEX of the corresponding array ref from the offset computation expression of the pointer ref. I.e. Given an OFFSET expression, and the ELEMENT_SIZE, get the index expression from the OFFSET. For example: OFFSET: ((long unsigned int) m * (long unsigned int) SAVE_EXPR <n>) * 4 ELEMENT_SIZE: (sizetype) SAVE_EXPR <n> * 4 get the index as (long unsigned int) m. gcc/c-family/ChangeLog: * c-gimplify.cc (is_address_with_access_with_size): New function. (ubsan_walk_array_refs_r): Instrument an INDIRECT_REF whose base address is .ACCESS_WITH_SIZE or an address computation whose base address is .ACCESS_WITH_SIZE. * c-ubsan.cc (ubsan_instrument_bounds_pointer_address): New function. (struct factor_t): New structure. (get_factors_from_mul_expr): New function. (get_index_from_offset): New function. (get_index_from_pointer_addr_expr): New function. (is_instrumentable_pointer_array_address): New function. (ubsan_array_ref_instrumented_p): Change prototype. Handle MEM_REF in addtional to ARRAY_REF. (ubsan_maybe_instrument_array_ref): Handle MEM_REF in addtional to ARRAY_REF. gcc/testsuite/ChangeLog: * gcc.dg/ubsan/pointer-counted-by-bounds-2.c: New test. * gcc.dg/ubsan/pointer-counted-by-bounds-3.c: New test. * gcc.dg/ubsan/pointer-counted-by-bounds-4.c: New test. * gcc.dg/ubsan/pointer-counted-by-bounds-5.c: New test. * gcc.dg/ubsan/pointer-counted-by-bounds.c: New test.
2025-08-15Extend "counted_by" attribute to pointer fields of structures. Convert a ↵Qing Zhao1-6/+38
pointer reference with counted_by attribute to .ACCESS_WITH_SIZE. Fix PR120929. For example: struct PP { size_t count2; char other1; char *array2 __attribute__ ((counted_by (count2))); int other2; } *pp; specifies that the "array2" is an array that is pointed by the pointer field, and its number of elements is given by the field "count2" in the same structure. In order to fix PR120929, we agreed on the following solution: for a pointer field with counted_by attribute: struct S { int n; int *p __attribute__((counted_by(n))); } *f; when generating call to .ACCESS_WITH_SIZE for f->p, instead of generating *.ACCESS_WITH_SIZE (&f->p, &f->n,...) We should generate .ACCESS_WITH_SIZE (f->p, &f->n,...) i.e., the return type and the type of the first argument of the call is the original pointer type in this version. However, this code generation might bring undefined behavior into the applicaiton if the call to .ACCESS_WITH_SIZE is generated for a pointer field reference when this refernece is written to. For example: f->p = malloc (size); ***** the IL for the above is: tmp1 = f->p; tmp2 = &f->n; tmp3 = .ACCESS_WITH_SIZE (tmp1, tmp2, ...); tmp4 = malloc (size); tmp3 = tmp4; In the above, in order to generate a call to .ACCESS_WITH_SIZE for the pointer reference f->p, the new GIMPLE tmp1 = f->p is necessary to pass the value of the pointer f->p to the call to .ACCESS_WITH_SIZE. However, this new GIMPLE is the one that brings UB into the application since the value of f->p is not initialized yet when it is assigned to "tmp1". the above IL will be expanded to the following when .ACCESS_WITH_SIZE is expanded to its first argument: tmp1 = f->p; tmp2 = &f->n; tmp3 = tmp1; tmp4 = malloc (size); tmp3 = tmp4; the final optimized IL will be: tmp3 = f->p; tmp3 = malloc (size);; As a result, the f->p will NOT be set correctly to the pointer returned by malloc (size). Due to this potential issue, We will need to selectively generate the call to .ACCESS_WITH_SIZE for f->p according to whether it's a read or a write. We will only generate call to .ACCESS_WITH_SIZE for f->p when it's a read in C FE. gcc/c-family/ChangeLog: * c-attribs.cc (handle_counted_by_attribute): Accept counted_by attribute for pointer fields. gcc/c/ChangeLog: * c-decl.cc (verify_counted_by_attribute): Change the 2nd argument to a vector of fields with counted_by attribute. Verify all fields in this vector. (finish_struct): Collect all the fields with counted_by attribute to a vector and pass this vector to verify_counted_by_attribute. * c-tree.h (handle_counted_by_for_component_ref): New prototype of handle_counted_by_form_component_ref. * c-parser.cc (c_parser_postfix_expression): Call the new prototype of handle_counted_by_for_component_ref. * c-typeck.cc (default_function_array_read_conversion): Only generate call to .ACCESS_WITH_SIZE for a pointer field when it's a read. (convert_lvalue_to_rvalue): Likewise. (default_conversion): Likewise. (handle_counted_by_p): New routine. (check_counted_by_attribute): New routine. (build_counted_by_ref): Handle pointers with counted_by. (build_access_with_size_for_counted_by): Handle pointers with counted_by. (handle_counted_by_for_component_ref): Add one more argument. (build_component_ref): Call the new prototype of handle_counted_by_for_component_ref. gcc/ChangeLog: * doc/extend.texi: Extend counted_by attribute to pointer fields in structures. Add one more requirement to pointers with counted_by attribute. gcc/testsuite/ChangeLog: * gcc.dg/flex-array-counted-by.c: Update test. * gcc.dg/pointer-counted-by-1.c: New test. * gcc.dg/pointer-counted-by-2.c: New test. * gcc.dg/pointer-counted-by-3.c: New test. * gcc.dg/pointer-counted-by-8.c: New test. * gcc.dg/pointer-counted-by-9.c: New test. * gcc.dg/pointer-counted-by.c: New test.
2025-08-14Daily bump.GCC Administrator1-0/+6
2025-08-13c++: Implement C++26 P1306R5 - Expansion statements [PR120776]Jakub Jelinek1-0/+1
The following patch implements the C++26 P1306R5 - Expansion statements paper. When expansion statements are used outside of templates, the lowering of the statement uses push_tinst_level_loc and instantiates the body multiple times, otherwise when the new TEMPLATE_FOR_STMT statement is being instantiated and !processing_template_decl, it instantiates the body several times with just local_specialization_stack around each iteration but with the original args. Because the lowering of these statements is mostly about instantiation, I've put the lowering code into pt.cc rather than semantics.cc. Only destructuring expansion statements currently use in the patch temporary lifetime extension which matches the proposed resolution of https://cplusplus.github.io/CWG/issues/3043.html I'm not sure what will CWG decide about that if there will be some temporary lifetime extension for enumerating expansion statements and if yes, under what exact rules (e.g. whether it extends all the temporaries across one iteration of the body, or only if a reference is initialized or nothing at all). And for iterating expansion statements, I think I don't understand the P2686R4 rules well yet, I think if the expansion-initializer is used in static constexpr rvalue reference, then it isn't needed, but not sure if it won't be needed if static would be dropped (whether struct S { constexpr S () : s (0) {} constexpr ~S () {} int s; }; struct T { const S &t, &u; }; void foo () { constexpr T t = { S {}, S {} }; use (t.t, t.u); } is ok under P2686R4; though without constexpr before T I see S::~S () being called after use, not at the end of the t declaration, so maybe it is fine also without static). As per https://cplusplus.github.io/CWG/issues/3044.html the patch uses build_int_cst (ptrdiff_type_node, i) to create second operand of begin + i and doesn't lookup overloaded comma operator (note, I'm actually not even creating a lambda there, just using TARGET_EXPRs). I guess my preference would be dropping those 4 static keywords from [stmt.expand] but the patch does use those for now and it won't be possible to change that until the rest of P2686R4 is implemented. As per https://cplusplus.github.io/CWG/issues/3045.html it treats sk_template_for like sk_for for the purpose of redeclaration of vars in the body but doesn't yet reject [[fallthrough]]; in the expansion stmt body (when not nested in another switch). I'm not sure if cp_perform_range_for_lookup used in the patch is exactly what we want for the https://eel.is/c++draft/stmt.expand#3.2 - it does finish_call_expr on the perform_koenig_lookup as well, shouldn't for the decision whether it is iterating or destructing (i.e. tf_none) just call perform_koenig_lookup and check if it found some FUNCTION_DECL/OVERLOAD/TEMPLATE_DECL? cp_decomp_size in the patch has tsubst_flags_t argument and attempts to be SFINAE friendly, even when it isn't needed strictly for this patch. This is with PR96185 __builtin_structured_binding_size implementation in mind (to follow clang). The new TEMPLATE_FOR_STMT statement is expected to be lowered to something that doesn't use the statement at all, I've implemented break/continue discovery in the body, so all I needed was to punt on TEMPLATE_FOR_STMT in potential_constant_expression_1 so that we don't try to constant evaluate it when it is still dependent (and cxx_eval_constant_expression rejects it without any extra code). I think only enumerating and iterating expansion statements can have zero iteration, because for destructuring ones it doesn't use a structured binding pack and so valid structured binding has to have at least one iteration. Though https://cplusplus.github.io/CWG/issues/3048.html could change that, this patch currently rejects it though. 2025-08-13 Jakub Jelinek <jakub@redhat.com> PR c++/120776 gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): Predefine __cpp_expansion_statements=202506L for C++26. gcc/cp/ * cp-tree.def: Implement C++26 P1306R5 - Expansion statements. (TEMPLATE_FOR_STMT): New tree code. * cp-tree.h (struct saved_scope): Add expansion_stmt. (in_expansion_stmt): Define. (TEMPLATE_FOR_DECL, TEMPLATE_FOR_EXPR, TEMPLATE_FOR_BODY, TEMPLATE_FOR_SCOPE, TEMPLATE_FOR_INIT_STMT): Define. (struct tinst_level): Adjust comment. (cp_decomp_size, finish_expansion_stmt, do_pushlevel, cp_build_range_for_decls, build_range_temp, cp_perform_range_for_lookup, begin_template_for_scope): Declare. (finish_range_for_stmt): Remove declaration. * cp-objcp-common.cc (cp_common_init_ts): Handle TEMPLATE_FOR_STMT. * name-lookup.h (enum scope_kind): Add sk_template_for enumerator. (struct cp_binding_level): Enlarge kind bitfield from 4 to 5 bits. Adjust comment with remaining space bits. * name-lookup.cc (check_local_shadow): Handle sk_template_for like sk_for. (cp_binding_level_descriptor): Add entry for sk_template_for. (begin_scope): Handle sk_template_for. * parser.h (IN_EXPANSION_STMT): Define. * parser.cc (cp_debug_parser): Print IN_EXPANSION_STMT bit. (cp_parser_lambda_expression): Temporarily clear in_expansion_stmt. (cp_parser_statement): Handle RID_TEMPLATE followed by RID_FOR for C++11. (cp_parser_label_for_labeled_statement): Complain about named labels inside of expansion stmt body. (cp_hide_range_decl): New function. (cp_parser_range_for): Use it. Adjust do_range_for_auto_deduction caller. Remove second template argument from auto_vecs bindings and names. (build_range_temp): No longer static. (do_range_for_auto_deduction): Add expansion_stmt argument. (cp_build_range_for_decls): New function. (cp_convert_range_for): Use it. Call cp_perform_range_for_lookup rather than cp_parser_perform_range_for_lookup. (cp_parser_perform_range_for_lookup): Rename to ... (cp_perform_range_for_lookup): ... this. No longer static. Add complain argument and handle it. (cp_parser_range_for_member_function): Rename to ... (cp_range_for_member_function): ... this. (cp_parser_expansion_statement): New function. (cp_parser_jump_statement): Handle IN_EXPANSION_STMT. (cp_convert_omp_range_for): Adjust do_range_for_auto_deduction caller. Call cp_perform_range_for_lookup rather than cp_parser_perform_range_for_lookup. * error.cc (print_instantiation_full_context): Handle tldcl being TEMPLATE_FOR_STMT. (print_instantiation_partial_context_line): Likewise. * constexpr.cc (potential_constant_expression_1): Handle TEMPLATE_FOR_STMT. * decl.cc (poplevel_named_label_1): Use obl instead of bl->level_chain. (finish_case_label): Diagnose case labels inside of template for. (find_decomp_class_base): Add complain argument, don't diagnose anything and just return error_mark_node if tf_none, adjust recursive call. (cp_decomp_size): New function. (cp_finish_decomp): Adjust find_decomp_class_base caller. * semantics.cc (do_pushlevel): No longer static. (begin_template_for_scope): New function. * pt.cc (push_tinst_level_loc): Handle TEMPLATE_FOR_STMT. (reopen_tinst_level): Likewise. (tsubst_stmt): Handle TEMPLATE_FOR_STMT. (struct expansion_stmt_bc): New type. (expansion_stmt_find_bc_r, finish_expansion_stmt): New functions. * decl2.cc (decl_dependent_p): Return true for current function's decl if in_expansion_stmt. * call.cc (extend_ref_init_temps): Don't extend_all_temps if TREE_STATIC (decl). * cxx-pretty-print.cc (cxx_pretty_printer::statement): Handle TEMPLATE_FOR_STMT. gcc/testsuite/ * g++.dg/cpp1z/decomp64.C: New test. * g++.dg/cpp26/expansion-stmt1.C: New test. * g++.dg/cpp26/expansion-stmt2.C: New test. * g++.dg/cpp26/expansion-stmt3.C: New test. * g++.dg/cpp26/expansion-stmt4.C: New test. * g++.dg/cpp26/expansion-stmt5.C: New test. * g++.dg/cpp26/expansion-stmt6.C: New test. * g++.dg/cpp26/expansion-stmt7.C: New test. * g++.dg/cpp26/expansion-stmt8.C: New test. * g++.dg/cpp26/expansion-stmt9.C: New test. * g++.dg/cpp26/expansion-stmt10.C: New test. * g++.dg/cpp26/expansion-stmt11.C: New test. * g++.dg/cpp26/expansion-stmt12.C: New test. * g++.dg/cpp26/expansion-stmt13.C: New test. * g++.dg/cpp26/expansion-stmt14.C: New test. * g++.dg/cpp26/expansion-stmt15.C: New test. * g++.dg/cpp26/expansion-stmt16.C: New test. * g++.dg/cpp26/expansion-stmt17.C: New test. * g++.dg/cpp26/expansion-stmt18.C: New test. * g++.dg/cpp26/expansion-stmt19.C: New test. * g++.dg/cpp26/feat-cxx26.C: Add __cpp_expansion_statements tests.
2025-08-09Daily bump.GCC Administrator1-0/+7
2025-08-08diagnostics: introduce struct column_optionsDavid Malcolm2-2/+2
Consolidate 3 fields in diagnostics::context and diagnostics::column_policy into a new struct diagnostics::column_options. No functional change intended; reduces the number of public fields in diagnostics::context. gcc/c-family/ChangeLog: * c-indentation.cc (should_warn_for_misleading_indentation): Update for moving diagnostics::context::m_tabstop into diagnostics::column_options. * c-opts.cc (c_common_post_options): Likewise. gcc/ChangeLog: * diagnostics/column-options.h: New file, adding struct diagnostics::column_options, taken from fields in diagnostics::context and diagnostics::column_policy. * diagnostics/context.cc (context::initialize): Update for moving fields of diagnostics::context into diagnostics::column_options. (column_policy::column_policy): Likewise. (column_policy::converted_column): Move implementation to... (column_options::convert_column): ...this new function. (context::report_diagnostic): Update for moving fields of diagnostics::context into diagnostics::column_options. (assert_location_text): Likewise. * diagnostics/context.h: Include "diagnostics/column-options.h". (class column_policy): Replace fields m_column_unit, m_column_origin, and m_tabstop with m_column_options. (context::get_column_options): New accessors. (context::m_column_unit): Move to struct column_options and replace with m_column_options. (context::m_column_origin): Likewise. (context::m_tabstop): Likewise. * diagnostics/sarif-sink.cc (sarif_builder::sarif_builder): Update for moving fields of diagnostics::context into diagnostics::column_options. * diagnostics/source-printing.cc: Likewise. * opts.cc (common_handle_option): Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-08Daily bump.GCC Administrator1-0/+15
2025-08-07c++: Implement C++26 P1061R10 - Structured Bindings can introduce a Pack ↵Jakub Jelinek1-1/+1
[PR117783] The following patch implements the C++26 P1061R10 - Structured Bindings can introduce a Pack paper. One thing unresolved in the patch is mangling, I've raised https://github.com/itanium-cxx-abi/cxx-abi/issues/200 for that but no comments there yet. One question is if it is ok not to mention the fact that there is a structured binding pack in the mangling of the structured bindings but more important is in case of std::tuple* we might need to mangle individual structured binding pack elements separately (each might need an exported name for the var itself and perhaps its guard variable as well). The patch just uses the normal mangling for the whole structured bindings and emits sorry if we need to mangle the structured binding pack elements. The patch just marks the structured binding pack specially (considered e.g. using some bit on it, but in the end I'm identifying it using a made up type which causes DECL_PACK_P to be true; it is kind of self-referential solution, because the type on the pack mentions the DECL_DECOMPOSITION_P VAR_DECL on which the type is attached as its pack, so it needs to be handled carefully during instantiation to avoid infinite recursion, but it is the type that should be used if something else actually needs to use the same type as the structured binding pack, e.g. a capture proxy), and stores the pack elements when actually processed through cp_finish_decomp with non-dependent initializer into a TREE_VEC used as DECL_VALUE_EXPR of the pack; though because several spots use the DECL_VALUE_EXPR and assume it is ARRAY_REF from which they can find out the base variable and the index, it stores the base variable and index in the first 2 TREE_VEC elts and has the structured binding elements only after that. https://eel.is/c++draft/temp.dep.expr#3.6 says the packs are type dependent regardless of whether the initializer of the structured binding is type dependent or not, so I hope having a dependent type on the structured binding VAR_DECL is ok. The paper also has an exception for sizeof... which is then not value dependent when the structured bindings are initialized with non-dependent initializer: https://eel.is/c++draft/temp.dep.constexpr#4 The patch special cases that in 3 spots (I've been wondering if e.g. during parsing I couldn't just fold the sizeof... to the INTEGER_CST right away, but guess I'd need to repeat that also during partial instantiation). And one thing still unresolved is debug info, I've just added DECL_IGNORED_P on the structured binding pack VAR_DECL because there were ICEs with -g for now, hope it can be fixed incrementally but am not sure what exactly we should emit in the debug info for that. Speaking of which, I see DW_TAG_GNU_template_parameter_pack DW_TAG_GNU_formal_parameter_pack etc. DIEs emitted regardless of DWARF version, shouldn't we try to upstream those into DWARF 6 or check what other compilers emit for the packs? And bet we'd need DW_TAG_GNU_structured_binding_pack as well. 2025-08-07 Jakub Jelinek <jakub@redhat.com> PR c++/117783 gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): Change __cpp_structured_bindings predefined value for C++26 from 202403L to 202411L. gcc/cp/ * parser.cc: Implement C++26 P1061R10 - Structured Bindings can introduce a Pack. (cp_parser_range_for): Also handle TREE_VEC as DECL_VALUE_EXPR instead of ARRAY_REF. (cp_parser_decomposition_declaration): Use sb-identifier-list instead of identifier-list in comments. Parse structured bindings with structured binding pack. Don't emit pedwarn about structured binding attributes in structured bindings inside of a condition. (cp_convert_omp_range_for): Also handle TREE_VEC as DECL_VALUE_EXPR instead of ARRAY_REF. * decl.cc (get_tuple_element_type): Change i argument type from unsigned to unsigned HOST_WIDE_INT. (get_tuple_decomp_init): Likewise. (set_sb_pack_name): New function. (cp_finish_decomp): Handle structured binding packs. * pt.cc (tsubst_pack_expansion): Handle structured binding packs and capture proxies for them. Formatting fixes. (tsubst_decl): For structured binding packs don't tsubst TREE_TYPE first, instead recreate the type after r is created. (tsubst_omp_for_iterator): Also handle TREE_VEC as DECL_VALUE_EXPR instead of ARRAY_REF. (tsubst_expr): Handle sizeof... on non-dependent structure binding packs. (value_dependent_expression_p): Return false for sizeof... on non-dependent structure binding packs. (instantiation_dependent_r): Don't recurse on sizeof... on non-dependent structure binding packs. * constexpr.cc (potential_constant_expression_1): Also handle TREE_VEC on DECL_VALUE_EXPR of structure binding packs. gcc/testsuite/ * g++.dg/cpp26/decomp13.C: New test. * g++.dg/cpp26/decomp14.C: New test. * g++.dg/cpp26/decomp15.C: New test. * g++.dg/cpp26/decomp16.C: New test. * g++.dg/cpp26/decomp17.C: New test. * g++.dg/cpp26/decomp18.C: New test. * g++.dg/cpp26/decomp19.C: New test. * g++.dg/cpp26/decomp20.C: New test. * g++.dg/cpp26/decomp21.C: New test. * g++.dg/cpp26/feat-cxx26.C (__cpp_structured_bindings): Expect 202411 rather than 202403.
2025-08-07c++, c: Introduce -Wkeyword-macro warning/pedwarn - part of C++26 P2843R3 ↵Jakub Jelinek4-1/+17
[PR120778] The following patch introduces a -Wkeyword-macro warning that clang has since 2014 to implement part of C++26 P2843R3 Preprocessing is never undefined paper. The relevant change in the paper is moving [macro.names]/2 paragraph to https://eel.is/c++draft/cpp.replace.general#9 : "A translation unit shall not #define or #undef names lexically identical to keywords, to the identifiers listed in Table 4, or to the attribute-tokens described in [dcl.attr], except that the names likely and unlikely may be defined as function-like macros." Now, my understanding of the paper is that in [macro.names] and surrounding sections the word shall bears different meaning from [cpp.replace.general], where only the latter location implies ill-formed, diagnostic required. The warning in clang when introduced diagnosed all #define/#undef directives on keywords, but shortly after introduction has been changed not to diagnose #undef at all (with "#undef a keyword is generally harmless but used often in configuration scripts" message) and later on even the #define part tweaked - not warn about say #define inline (or const, extern, static), or #define keyword keyword or #define keyword __keyword or #define keyword __keyword__ Later on the warning has been moved to be only pedantic diagnostic unless requested by users. Clearly some code in the wild does e.g. #define private public and similar games, or e.g. Linux kernel (sure, C) does #define inline __inline__ __attribute__((__always_inline__)) etc. Now, I believe at least with the current C++26 wording such exceptions aren't allowed (unless it is changed to IFNDR). But given that this is just pedantic stuff, the following patch makes the warning off by default for C and C++ before C++26 and even for C++26 it enables it by default only if -pedantic/-pedantic-errors (in that case it pedwarns, otherwise it warns). And it diagnoses both #define and #undef without exceptions. From what I can see, all the current NODE_WARN cases are macros starting with __ with one exception (_Pragma). As the NODE_* flags seem to be a limited resource, I chose to just use NODE_WARN as well and differentiate on the node names (if they don't start with __ or _P, they are considered to be -Wkeyword-macro registered ones, otherwise old NODE_WARN cases, typically builtin macros or __STDC* macros). 2025-08-07 Jakub Jelinek <jakub@redhat.com> PR preprocessor/120778 gcc/ * doc/invoke.texi (Wkeyword-macro): Document. gcc/c-family/ * c.opt (Wkeyword-macro): New option. * c.opt.urls: Regenerate. * c-common.h (cxx_dialect): Comment formatting fix. * c-opts.cc (c_common_post_options): Default to -Wkeyword-macro for C++26 if pedantic. gcc/c/ * c-decl.cc (c_init_decl_processing): Mark cpp nodes corresponding to keywords as NODE_WARN if warn_keyword_macro. gcc/cp/ * lex.cc (cxx_init): Mark cpp nodes corresponding to keywords, identifiers with special meaning and standard attribute identifiers as NODE_WARN if warn_keyword_macro. gcc/testsuite/ * gcc.dg/Wkeyword-macro-1.c: New test. * gcc.dg/Wkeyword-macro-2.c: New test. * gcc.dg/Wkeyword-macro-3.c: New test. * gcc.dg/Wkeyword-macro-4.c: New test. * gcc.dg/Wkeyword-macro-5.c: New test. * gcc.dg/Wkeyword-macro-6.c: New test. * gcc.dg/Wkeyword-macro-7.c: New test. * gcc.dg/Wkeyword-macro-8.c: New test. * gcc.dg/Wkeyword-macro-9.c: New test. * g++.dg/warn/Wkeyword-macro-1.C: New test. * g++.dg/warn/Wkeyword-macro-2.C: New test. * g++.dg/warn/Wkeyword-macro-3.C: New test. * g++.dg/warn/Wkeyword-macro-4.C: New test. * g++.dg/warn/Wkeyword-macro-5.C: New test. * g++.dg/warn/Wkeyword-macro-6.C: New test. * g++.dg/warn/Wkeyword-macro-7.C: New test. * g++.dg/warn/Wkeyword-macro-8.C: New test. * g++.dg/warn/Wkeyword-macro-9.C: New test. * g++.dg/warn/Wkeyword-macro-10.C: New test. * g++.dg/opt/pr82577.C: Don't #define register to nothing for C++17 and later. Instead define reg macro to nothing for C++17 and later or to register and use it instead of register. * g++.dg/modules/atom-preamble-3.C: Add -Wno-keyword-macro to dg-additional-options. * g++.dg/template/sfinae17.C (static_assert): Rename macro to ... (my_static_assert): ... this. (main): Use my_static_assert instead of static_assert. libcpp/ * include/cpplib.h (struct cpp_options): Add cpp_warn_keyword_macro. (enum cpp_warning_reason): Add CPP_W_KEYWORD_MACRO enumerator. (cpp_keyword_p): New inline function. * directives.cc (do_undef): Support -Wkeyword-macro diagnostics. * macro.cc (warn_of_redefinition): Ignore NODE_WARN flag on nodes registered for -Wkeyword-macro. (_cpp_create_definition): Support -Wkeyword-macro diagnostics. Formatting fixes.
2025-08-07Daily bump.GCC Administrator1-0/+6
2025-08-06[hardbool] implement OP=, ++ and --, volatile and atomicsAlexandre Oliva1-4/+15
hardbools didn't behave quite like bools when incremented, decremented, or otherwise modified using their previous value, as in += et al. Fix that. Also fix some checking errors that come up when using qualified base types. for gcc/c-family/ChangeLog * c-attribs.cc (handle_hardbool_attribute): Create distinct enumeration types, with structural equality. Handle base type qualifiers. for gcc/c/ChangeLog * c-tree.h (C_BOOLEAN_TYPE_P): Cover hardbools as well. * c-typeck.cc (convert_lvalue_to_rvalue): New overload and wrapper. (build_atomic_assign, build_modify_expr): Use it. (build_asm_expr, handle_omp-array_sections_1): Simplify with it. (build_unary_op): Handle hardbools. for gcc/testsuite/ChangeLog * gcc.dg/torture/hardbool-ai.c: New. * gcc.dg/torture/hardbool-vi.c: New. * gcc.dg/torture/hardbool.c: Handle NO_BITFIELDS. (add1, preinc, postinc, sub1, predec, postdec): New. (main): Exercise them.
2025-08-03Daily bump.GCC Administrator1-0/+6
2025-08-02c: rewrite implementation of `arg spec' attributeMartin Uecker1-17/+115
Rewrite the implementation of the `arg spec' attribute to pass the the original type of an array parameter instead of passing a string description and a list of bounds. The string and list are then created from this type during the integration of the information of `arg spec' into the access attribute because it still needed later for various warnings. This change makes the implementation simpler and more robust as the declarator is not processed and information that is already encoded in the type is not duplicated. A similar change to the access attribute could then completely remove the string processing. With this change, the original type is now available and can be used for other warnings or for _Countof. The new implementation tries to be faithful to the original, but this is not entirely true as it fixes a bug in the old implementation. gcc/c-family/ChangeLog: * c-attribs.cc (handle_argspec_attribute): Update. (build_arg_spec): New function. (build_attr_access_from_parms): Rewrite `arg spec' handling. gcc/c/ChangeLog: * c-decl.cc (get_parm_array_spec): Remove. (push_parm_decl): Do not add `arg spec` attribute. (build_arg_spec_attribute): New function. (grokdeklarator): Add `arg spec` attribute. gcc/testsuite/ChangeLog: * gcc.dg/Warray-parameter-11.c: Change Warray-parameter to -Wvla-parameter as these are VLAs. * gcc.dg/Warray-parameter.c: Remove xfail.
2025-07-26Daily bump.GCC Administrator1-0/+83
2025-07-25diagnostics: make context::m_source_printing privateDavid Malcolm3-3/+3
No functional change intended. gcc/ada/ChangeLog: * gcc-interface/misc.cc: Make diagnostics::context::m_source_printing private. gcc/analyzer/ChangeLog: * program-point.cc: Make diagnostics::context::m_source_printing private. gcc/c-family/ChangeLog: * c-common.cc: Make diagnostics::context::m_source_printing private. * c-format.cc: Likewise. * c-opts.cc: Likewise. gcc/ChangeLog: * diagnostic.h (diagnostic_set_caret_max_width): Drop forward decl. (diagnostic_same_line): Make diagnostics::context::m_source_printing private. * diagnostics/context.cc (diagnostic_set_caret_max_width): Convert to... (diagnostics::context::set_caret_max_width): ...this. * diagnostics/context.h (diagnostics::context::get_source_printing_options): New accessors. (diagnostics::context::m_source_printing): Make private. * diagnostics/html-sink.cc: Make diagnostics::context::m_source_printing private. * diagnostics/paths-output.cc: Likewise. * diagnostics/sarif-sink.cc: Likewise. * diagnostics/selftest-context.cc: Likewise. * diagnostics/selftest-context.h (diagnostics::selftest::test_context::colorize_source): New. (diagnostics::selftest::test_context::show_labels): New. (diagnostics::selftest::test_context::show_line_numbers): New. (diagnostics::selftest::test_context::show_ruler): New. (diagnostics::selftest::test_context::show_event_links): New. (diagnostics::selftest::test_context::set_caret_char): New. * diagnostics/source-printing.cc: Make diagnostics::context::m_source_printing private. * diagnostics/text-sink.h: Likewise. * libgdiagnostics.cc: Likewise. * opts.cc: Likewise. * toplev.cc: Likewise. gcc/fortran/ChangeLog: * error.cc: Make diagnostics::context::m_source_printing private. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_show_trees.cc: Make diagnostics::context::m_source_printing private. * gcc.dg/plugin/diagnostic_plugin_test_inlining.cc: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_string_literals.cc: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.cc: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_paths.cc: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Likewise. * gcc.dg/plugin/expensive_selftests_plugin.cc: Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: eliminate ::diagnostic_info typedefDavid Malcolm2-2/+2
No functional change intended. gcc/c-family/ChangeLog: * c-common.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". * c-opts.cc: Likewise. gcc/c/ChangeLog: * c-errors.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". gcc/cp/ChangeLog: * constexpr.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". * cp-tree.h: Likewise. * error.cc: Likewise. * module.cc: Likewise. gcc/d/ChangeLog: * d-diagnostic.cc: Likewise. gcc/ChangeLog: * diagnostic.h: Eliminate "diagnostic_info" typedef. * diagnostics/context.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". * langhooks.cc: Likewise. * libgdiagnostics.cc: Likewise. * rtl-error.cc: Likewise. * substring-locations.cc: Likewise. * toplev.cc: Likewise. * tree-diagnostic.cc: Likewise. * tree-diagnostic.h: Likewise. gcc/fortran/ChangeLog: * cpp.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". * error.cc: Likewise. gcc/jit/ChangeLog: * dummy-frontend.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". gcc/m2/ChangeLog: * gm2-gcc/m2linemap.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". * gm2-gcc/rtegraph.cc: Likewise. gcc/rust/ChangeLog: * resolve/rust-ice-finalizer.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". * resolve/rust-ice-finalizer.h: Likewise. gcc/testsuite/ChangeLog: * g++.dg/plugin/show_template_tree_color_plugin.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". * gcc.dg/plugin/diagnostic_group_plugin.cc: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Likewise. * gcc.dg/plugin/location_overflow_plugin.cc: Likewise. libcc1/ChangeLog: * context.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move file_cache from input.{cc,h} to diagnostics/file-cache.{cc,h}David Malcolm2-11/+14
No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Add diagnostics/file-cache.o. * diagnostics/changes.cc: Update for file_cache and char_span moving from input.h to diagnostics/file-cache.h and into the "diagnostics::" namespace. * diagnostics/context.cc: Likewise. * diagnostics/diagnostics-selftests.cc: Likewise. * diagnostics/diagnostics-selftests.h: Likewise. * diagnostics/file-cache.cc: New file, based on the file_cache and file_cache_slot material in input.cc. * diagnostics/file-cache.h: Likewise for input.h. * diagnostics/selftest-source-printing.h: Update for file_cache and char_span moving from input.h to diagnostics/file-cache.h and into the "diagnostics::" namespace. * diagnostics/source-printing.cc: Likewise. * final.cc: Likewise. * gcc-rich-location.cc: Likewise. * input.cc (default_charset_callback): Move to diagnostics/file-cache.cc. (file_cache::initialize_input_context): Likewise. (class file_cache_slot): Likewise. (file_cache::tune): Likewise. (file_cache::lookup_file): Likewise. (file_cache::forcibly_evict_file): Likewise. (file_cache::missing_trailing_newline_p): Likewise. (file_cache::add_buffered_content): Likewise. (file_cache::evicted_cache_tab_entry): Likewise. (file_cache::add_file): Likewise. (file_cache::file_cache): Likewise. (file_cache::dump): Likewise. (file_cache::dump): Likewise. (file_cache::lookup_or_add_file): Likewise. (find_end_of_line): Likewise. (file_cache::get_source_line): Likewise. (check_line): Likewise. (test_replacement): Likewise. (test_reading_source_line): Likewise. (test_reading_source_buffer): Likewise. * input.h (class char_span): Move to diagnostics/file-cache.h and into the "diagnostics::" namespace. (class file_cache_slot): Likewise. (class file_cache): Likewise. * libgdiagnostics.cc: Update for file_cache and char_span moving from input.h to diagnostics/file-cache.h and into the "diagnostics::" namespace. * selftest.cc: Likewise. * selftest.h: Likewise. * substring-locations.h: Likewise. * toplev.cc: Likewise. gcc/c-family/ChangeLog: * c-format.cc: Update for file_cache and char_span moving from input.h to diagnostics/file-cache.h and into the "diagnostics::" namespace. * c-indentation.cc: Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Update for file_cache and char_span moving from input.h to diagnostics/file-cache.h and into the "diagnostics::" namespace. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move diagnostic.c to diagnostics/context.ccDavid Malcolm2-2/+5
No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Replace diagnostic.o with diagnostics/context.o. gcc/c-family/ChangeLog: * c-common.cc (c_family_tests): Add include of "diagnostics/diagnostics-selftests.h". Replace c_diagnostic_cc_tests with diagnostics::selftest::context_cc_tests. * c-common.h: Drop c_diagnostic_cc_tests decl. gcc/ChangeLog: * diagnostic.h (num_digits): Move to... (diagnostics::num_digits): ...here. (get_cwe_url): Move to... (diagnostics::get_cwe_url): ...here. (maybe_line_and_column): Move to... (diagnostics::maybe_line_and_column): ...here. * diagnostic.cc: Move to... * diagnostics/context.cc: ...here. * diagnostics/diagnostics-selftests.cc (run_diagnostics_selftests): Add comment about context_cc_tests. * diagnostics/diagnostics-selftests.h: Add context_cc_tests decl. * diagnostics/sarif-sink.cc: Update for file rename. * diagnostics/source-printing.cc: Update for num_digits moving to diagnostics::num_digits. * errors.cc: Update for file rename. * input.cc: Update for num_digits moving to diagnostics::num_digits. libcpp/ChangeLog: * charset.cc: Update comment for file rename. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: convert diagnostic_t to enum class diagnostics::kindDavid Malcolm6-19/+22
No functional change intended. gcc/ChangeLog: * Makefile.in: Replace diagnostic.def with diagnostics/kinds.def. * config/aarch64/aarch64.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * config/i386/i386-options.cc: Likewise. * config/s390/s390.cc: Likewise. * diagnostic-core.h: Replace typedef diagnostic_t with enum class diagnostics::kind in diagnostics/kinds.h and include it. * diagnostic-global-context.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * diagnostic.cc: Likewise. * diagnostic.h: Likewise. * diagnostics/buffering.cc: Likewise. * diagnostics/buffering.h: Likewise. * diagnostics/context.h: Likewise. * diagnostics/diagnostic-info.h: Likewise. * diagnostics/html-sink.cc: Likewise. * diagnostic.def: Move to... * diagnostics/kinds.def: ...here and update for diagnostic_t becoming enum class diagnostics::kind. * diagnostics/kinds.h: New file, based on material in diagnostic-core.h. * diagnostics/lazy-paths.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * diagnostics/option-classifier.cc: Likewise. * diagnostics/option-classifier.h: Likewise. * diagnostics/output-spec.h: Likewise. * diagnostics/paths-output.cc: Likewise. * diagnostics/sarif-sink.cc: Likewise. * diagnostics/selftest-context.cc: Likewise. * diagnostics/selftest-context.h: Likewise. * diagnostics/sink.h: Likewise. * diagnostics/source-printing.cc: Likewise. * diagnostics/text-sink.cc: Likewise. * diagnostics/text-sink.h: Likewise. * gcc.cc: Likewise. * libgdiagnostics.cc: Likewise. * lto-wrapper.cc: Likewise. * opts-common.cc: Likewise. * opts-diagnostic.h: Likewise. * opts.cc: Likewise. * rtl-error.cc: Likewise. * substring-locations.cc: Likewise. * toplev.cc: Likewise. gcc/ada/ChangeLog: * gcc-interface/trans.cc: Update for diagnostic_t becoming enum class diagnostics::kind. gcc/analyzer/ChangeLog: * pending-diagnostic.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * program-point.cc: Likewise. gcc/c-family/ChangeLog: * c-common.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * c-format.cc: Likewise. * c-lex.cc: Likewise. * c-opts.cc: Likewise. * c-pragma.cc: Likewise. * c-warn.cc: Likewise. gcc/c/ChangeLog: * c-errors.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * c-parser.cc: Likewise. * c-typeck.cc: Likewise. gcc/cobol/ChangeLog: * util.cc: Update for diagnostic_t becoming enum class diagnostics::kind. gcc/cp/ChangeLog: * call.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * constexpr.cc: Likewise. * cp-tree.h: Likewise. * decl.cc: Likewise. * error.cc: Likewise. * init.cc: Likewise. * method.cc: Likewise. * module.cc: Likewise. * parser.cc: Likewise. * pt.cc: Likewise. * semantics.cc: Likewise. * typeck.cc: Likewise. * typeck2.cc: Likewise. gcc/d/ChangeLog: * d-diagnostic.cc: Update for diagnostic_t becoming enum class diagnostics::kind. gcc/fortran/ChangeLog: * cpp.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * error.cc: Likewise. * options.cc: Likewise. gcc/jit/ChangeLog: * dummy-frontend.cc: Update for diagnostic_t becoming enum class diagnostics::kind. gcc/m2/ChangeLog: * gm2-gcc/m2linemap.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * gm2-gcc/rtegraph.cc: Likewise. gcc/rust/ChangeLog: * backend/rust-tree.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * backend/rust-tree.h: Likewise. * resolve/rust-ast-resolve-expr.cc: Likewise. * resolve/rust-ice-finalizer.cc: Likewise. * resolve/rust-ice-finalizer.h: Likewise. * resolve/rust-late-name-resolver-2.0.cc: Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * gcc.dg/plugin/expensive_selftests_plugin.cc: Likewise. * gcc.dg/plugin/location_overflow_plugin.cc: Likewise. * lib/gcc-dg.exp: Likewise. libcpp/ChangeLog: * internal.h: Update comment for diagnostic_t becoming enum class diagnostics::kind. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: rename diagnostic_option_id to diagnostics::option_id and move ↵David Malcolm5-8/+9
to its own header No functional change intended. gcc/c-family/ChangeLog: * c-common.cc: Update for renaming of diagnostic_option_id to diagnostics::option_id. * c-common.h: Likewise. * c-cppbuiltin.cc: Likewise. * known-headers.cc: Likewise. * known-headers.h: Likewise. gcc/c/ChangeLog: * c-decl.cc: Update for renaming of diagnostic_option_id to diagnostics::option_id. * c-errors.cc: Likewise. * c-tree.h: Likewise. gcc/cobol/ChangeLog: * util.cc: Update for renaming of diagnostic_option_id to diagnostics::option_id. gcc/cp/ChangeLog: * cp-tree.h: Update for renaming of diagnostic_option_id to diagnostics::option_id. * decl.cc: Likewise. * error.cc: Likewise. * name-lookup.cc: Likewise. gcc/ChangeLog: * diagnostic-core.h: Include "diagnostics/option-id.h". (struct diagnostic_option_id): Move there, renaming to diagnostics::option_id. * diagnostic-global-context.cc: Update for renaming of diagnostic_option_id to diagnostics::option_id. * diagnostic.cc: Likewise. * diagnostic.h: Likewise. * diagnostics/context.h: Likewise. * diagnostics/diagnostic-info.h: Likewise. * diagnostics/lazy-paths.cc: Likewise. * diagnostics/option-classifier.cc: Likewise. * diagnostics/option-classifier.h: Likewise. * diagnostics/option-id.h: New file, taken from material in diagnostic-core.h. * diagnostics/selftest-context.cc: Update for renaming of diagnostic_option_id to diagnostics::option_id. * diagnostics/selftest-context.h: Likewise. * ipa-pure-const.cc: Likewise. * lto-wrapper.cc: Likewise. * opts-common.cc: Likewise. * opts-diagnostic.h: Likewise. * opts.cc: Likewise. * substring-locations.cc: Likewise. * substring-locations.h: Likewise. gcc/fortran/ChangeLog: * cpp.cc: Update for renaming of diagnostic_option_id to diagnostics::option_id. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move diagnostics::edit_context -> diagnostics::changes::change_setDavid Malcolm1-1/+1
No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Replace diagnostics/changes.o with diagnostics/edit-context.o. * diagnostic.cc: Update for move of diagnostics/edit-context.h to diagnostics/changes.h. (diagnostics::context::initialize): Update for renaming of m_edit_context_ptr to m_fixits_change_set. (diagnostics::context::finish): Likewise. (diagnostics::context::create_edit_context): Rename to... (diagnostics::context::initialize_fixits_change_set): ...this and update for other renamings. (diagnostics::context::report_diagnostic): Update for renaming of m_edit_context_ptr to m_fixits_change_set. * diagnostic.h (diagnostics::edit_context): Drop forward decl * diagnostics/edit-context.cc: Move to... * diagnostics/changes.cc: ...here. Update for move of diagnostics/edit-context.h to diagnostics/changes.h. Rename diagnostics::edit_context to diagnostics::changes::change_set. Rename diagnostics::edited_file to diagnostics::changes::changed_file. Rename diagnostics::edited_line to diagnostics::changes::changed_line. * diagnostics/edit-context.h: Move to... * diagnostics/changes.h: ...here, renaming as above. * diagnostics/context.h (diagnostics::changes::change_set): New forward decl. (diagnostics::context::create_edit_context): Rename to... (diagnostics::context::initialize_fixits_change_set): ...this. (diagnostics::context::get_edit_context): Rename to... (diagnostics::context::get_fixits_change_set): ...this. (diagnostics::context::m_edit_context_ptr): Rename to... (diagnostics::context::m_fixits_change_set): ..this and update type. * diagnostics/diagnostics-selftests.cc: Update for renaming. * diagnostics/diagnostics-selftests.h: Likewise. * diagnostics/html-sink.cc: Update for above changes. * libgdiagnostics.cc: Likewise. * toplev.cc: Likewise. gcc/c-family/ChangeLog: * c-common.cc: Update comment for renaming of edit_context. gcc/testsuite/ChangeLog: * gcc.dg/plugin/expensive_selftests_plugin.cc: Update for change from edit-context.h to changes.h. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: reorganize selftestsDavid Malcolm1-1/+1
No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS): Move diagnostics/lazy-paths.o to... (OBJS-libcommon): ...here. Add diagnostics/diagnostics-selftests.o. * diagnostic.cc: Update for move of selftest::test_diagnostic_context to diagnostics::selftest::test_context. * diagnostics/color.cc: Move selftests from selftest:: to diagnostics::selftest::. * diagnostics/diagnostics-selftests.cc: New file. * diagnostics/diagnostics-selftests.h: New file. * diagnostics/digraphs.cc: Move selftests from selftest:: to diagnostics::selftest::. * diagnostics/edit-context.cc: Likewise. * diagnostics/html-sink.cc: Likewise. * diagnostics/lazy-paths.cc: Likewise. Eliminate use of "tree" by porting selftests from simple-diagnostic-path.h to diagnostics/selftest-paths.h. * diagnostics/output-spec.cc: Move selftests from selftest:: to diagnostics::selftest::. * diagnostics/paths-output.cc: Likewise. * diagnostics/sarif-sink.cc: Likewise. * diagnostics/selftest-context.cc: Move selftest::test_diagnostic_context to diagnostics::selftest::test_context. * diagnostics/selftest-context.h: Likewise. * diagnostics/selftest-logical-locations.cc: Move selftests from selftest:: to diagnostics::logical_locations::selftest::. * diagnostics/selftest-logical-locations.h: Move selftest::logical_location_manager to diagnostics::logical_locations::selftest::logical_location_manager. * diagnostics/selftest-paths.cc: Move selftest::test_diagnostic_path to diagnostics::paths::selftest::test_path. Move selftest::test_diagnostic_event to diagnostics::paths::selftest::test_event. * diagnostics/selftest-paths.h: Likewise, and move selftest::test_diagnostic_thread to diagnostics::paths::selftest::test_thread. * diagnostics/selftest-source-printing.h: Move selftest::diagnostic_show_locus_fixture to diagnostics::selftest::source_printing_fixture. * diagnostics/source-printing.cc: Move selftests from selftest:: to diagnostics::selftest:: and update for renames. * diagnostics/state-graphs.cc: Likewise. * selftest-run-tests.cc: Include "diagnostics/diagnostics-selftests.h". (selftest::run_tests): Replace invocation of the various diagnostics selftests with a call to diagnostics::selftest::run_diagnostics_selftests. * selftest.h: Move decls of the various per-file diagnostics invocation functions to diagnostics/diagnostics-selftests.h, renaming due to diagostics prefix being implied by namespace. gcc/c-family/ChangeLog: * c-format.cc (test_type_mismatch_range_labels): Update for move of selftest::test_diagnostic_context to diagnostics::selftest::test_context. gcc/testsuite/ChangeLog: * gcc.dg/plugin/expensive_selftests_plugin.cc: Update for move of selftest::test_diagnostic_context to diagnostics::selftest::test_context. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move gcc/selftest-diagnostic.{h,cc} -> ↵David Malcolm1-1/+1
gcc/diagnostics/selftest-context.{h,cc} No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Replace selftest-diagnostic.o with diagnostics/selftest-context.o. * diagnostic.cc: Update for move of selftest-diagnostic.h to diagnostics/selftest-context.h. * diagnostics/html-sink.cc: Likewise. * diagnostics/lazy-paths.cc: Likewise. * diagnostics/output-spec.cc: Likewise. * diagnostics/paths-output.cc: Likewise. * diagnostics/sarif-sink.cc: Likewise. * selftest-diagnostic.cc: Move to... * diagnostics/selftest-context.cc: ...here and update for move of header file. * selftest-diagnostic.h: Move to... * diagnostics/selftest-context.h: ...here. * diagnostics/source-printing.cc: Update for move of selftest-diagnostic.h to diagnostics/selftest-context.h. gcc/c-family/ChangeLog: * c-format.cc: Update for move of selftest-diagnostic.h to diagnostics/selftest-context.h. gcc/testsuite/ChangeLog: * gcc.dg/plugin/expensive_selftests_plugin.cc: Update for move of selftest-diagnostic.h to diagnostics/selftest-context.h. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move diagnostic_context to diagnostics::context in its own headerDavid Malcolm2-3/+3
No functional change intended. gcc/ada/ChangeLog: * gcc-interface/misc.cc: Update for diagnostic_context becoming diagnostics::context. gcc/analyzer/ChangeLog: * program-point.cc: : Update for diagnostic_context becoming diagnostics::context, and for diagnostic_source_print_policy becoming diagnostics::source_print_policy. gcc/c-family/ChangeLog: * c-common.h: Update for diagnostic_context becoming diagnostics::context. * c-opts.cc: Likewise. gcc/c/ChangeLog: * c-objc-common.cc: Update for diagnostic_context becoming diagnostics::context. * c-tree.h: Likewise. gcc/ChangeLog: * coretypes.h: Update for diagnostic_context becoming diagnostics::context. * diagnostic-global-context.cc: Likewise. * diagnostic.cc: Likewise. Also for diagnostic_option_classifier becoming diagnostics::option_classifier. * diagnostic.h (diagnostic_text_starter_fn): Rename to... (diagnostics::text_starter_fn): ...this, and move to diagnostics/context.h. (get_printer): Rename to... (diagnostics::get_printer): ...this, and move to diagnostics/context.h. (class diagnostic_option_manager): Rename to... (class diagnostics::option_manager): ...this, and move to diagnostics/context.h. (class diagnostic_option_classifier): Rename to... (class diagnostics::option_classifier): ...this, and move to diagnostics/context.h. (struct diagnostic_source_printing_options): Rename to... (struct diagnostics::source_printing_options): ...this, and move to diagnostics/context.h. (class diagnostic_column_policy): Rename to... (class diagnostics::column_policy): ...this, and move to diagnostics/context.h. (class diagnostic_location_print_policy): Rename to... (class diagnostics::location_print_policy): ...this, and move to diagnostics/context.h. (class html_label_writer): Rename to... (class diagnostics::html_label_writer): ...this, and move to diagnostics/context.h. (class diagnostic_source_print_policy): Rename to... (class diagnostics::source_print_policy): ...this, and move to diagnostics/context.h. (struct diagnostic_counters): Rename to... (struct diagnostics::counters): ...this, and move to diagnostics/context.h. (class diagnostic_context): Rename to... (class diagnostics::context): ...this, and move to diagnostics/context.h. (diagnostic_text_starter): Rename to... (diagnostics::text_starter): ...this, and move to diagnostics/context.h. (diagnostic_start_span): Rename to... (diagnostics::start_span): ...this, and move to diagnostics/context.h. (diagnostic_text_finalizer): Rename to... (diagnostics::text_finalizer): ...this, and move to diagnostics/context.h. Include "diagnostics/context.h". * diagnostics/buffering.h: Update for diagnostic_context becoming diagnostics::context; similarly for diagnostic_counters. * diagnostics/client-data-hooks.h: Likewise. * diagnostics/context.h: New file, taken from material in diagnostic.h. * diagnostics/html-sink.cc: : Update for diagnostic_context becoming diagnostics::context. * diagnostics/html-sink.h: Likewise. * diagnostics/lazy-paths.cc: Likewise for diagnostic_option_manager. * diagnostics/output-file.h: Likewise for diagnostic_context. * diagnostics/output-spec.cc: Likewise. * diagnostics/output-spec.h: Likewise. * diagnostics/paths-output.cc: Likewise. * diagnostics/sarif-sink.cc: Likewise. * diagnostics/sarif-sink.h: Likewise. * diagnostics/sink.h: Likewise. * diagnostics/source-printing.cc: Likewise. * diagnostics/text-sink.cc: Likewise. * diagnostics/text-sink.h: Likewise. * gcc-rich-location.h: Likewise. * gcc.cc: Likewise. * gdbinit.in: Likewise. * langhooks-def.h: Likewise. * langhooks.cc: Likewise. * langhooks.h: Likewise. * libgdiagnostics.cc: Likewise. * optc-gen.awk: Likewise. * opth-gen.awk: Likewise. * opts-common.cc: Likewise. * opts-diagnostic.cc: Likewise. * opts-diagnostic.h: Likewise. * opts-global.cc: Likewise. * opts.cc: Likewise. * opts.h: Likewise. * selftest-diagnostic.cc: Likewise. * selftest-diagnostic.h: Likewise. * toplev.cc: Likewise. * tree-diagnostic-client-data-hooks.cc: Likewise. * tree-diagnostic.cc: Likewise. * tree-diagnostic.h: Likewise. gcc/cp/ChangeLog: * cp-tree.h: Update for diagnostic_context becoming diagnostics::context. * error.cc: Likewise. * module.cc: Likewise. gcc/fortran/ChangeLog: * error.cc: Update for diagnostic_context becoming diagnostics::context. gcc/jit/ChangeLog: * dummy-frontend.cc: Update for diagnostic_context becoming diagnostics::context. * jit-playback.h: Likewise. gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc: Update for diagnostic_text_finalizer becoming diagnostics::text_finalizer. * resolve/rust-late-name-resolver-2.0.cc: Likewise. gcc/testsuite/ChangeLog: * g++.dg/plugin/show_template_tree_color_plugin.cc: Update for moves to namespace diagnostics. * gcc.dg/plugin/diagnostic_group_plugin.cc: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Likewise. * gcc.dg/plugin/location_overflow_plugin.cc: Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: add m_ prefix to fields of diagnostic_infoDavid Malcolm1-1/+1
No functional change intended. gcc/c-family/ChangeLog: * c-opts.cc (c_diagnostic_text_finalizer): Add "m_" prefix to fields of diagnostic_info. gcc/c/ChangeLog: * c-errors.cc: Update to add "m_" prefix to fields of diagnostic_info throughout. gcc/cp/ChangeLog: * constexpr.cc: Update to add "m_" prefix to fields of diagnostic_info throughout. * error.cc: Likewise. gcc/d/ChangeLog: * d-diagnostic.cc (d_diagnostic_report_diagnostic): Update to add "m_" prefix to fields of diagnostic_info throughout. gcc/ChangeLog: * diagnostic.cc: Update to add "m_" prefix to fields of diagnostic_info throughout. * diagnostic.h: Likewise. * diagnostics/html-sink.cc: Likewise. * diagnostics/sarif-sink.cc: Likewise. * diagnostics/text-sink.cc: Likewise. * libgdiagnostics.cc: Likewise. * substring-locations.cc: Likewise. * tree-diagnostic.cc: Likewise. gcc/fortran/ChangeLog: * error.cc: Update to add "m_" prefix to fields of diagnostic_info throughout. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Update to add "m_" prefix to fields of diagnostic_info throughout. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move diagnostic-macro-unwinding.{cc,h} -> ↵David Malcolm1-2/+2
diagnostics/macro-unwinding.{cc,h} gcc/ChangeLog: * Makefile.in (OBJS): Replace diagnostic-macro-unwinding.o with diagnostics/macro-unwinding.o. * diagnostic-macro-unwinding.cc: Move to... * diagnostics/macro-unwinding.cc: ...here, moving content into namespace diagnostics. * diagnostic-macro-unwinding.h: Move to... * diagnostics/macro-unwinding.h: ...here, moving content into namespace diagnostics. * diagnostics/paths-output.cc: Update for move of "diagnostic-macro-unwinding.h" to "diagnostics/macro-unwinding.h". gcc/c-family/ChangeLog: * c-opts.cc: Update for move of "diagnostic-macro-unwinding.h" to "diagnostics/macro-unwinding.h". Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move/rename output formats to diagnostics as "sinks"David Malcolm1-2/+2
Within gcc/ move diagnostic-buffer.h to diagnostics/buffering.h move diagnostic-format-html.cc to diagnostics/html-sink.cc move diagnostic-format-html.h to diagnostics/html-sink.h move diagnostic-format-sarif.cc to diagnostics/sarif-sink.cc move diagnostic-format-sarif.h to diagnostics/sarif-sink.h move diagnostic-format.h to diagnostics/sink.h move diagnostic-format-text.cc to diagnostics/text-sink.cc move diagnostic-format-text.h to diagnostics/text-sink.h renaming various types including: Old name: New name: diagnostic_output_format diagnostics::sink diagnostic_buffer diagnostics::buffer diagnostic_per_format_buffer diagnostics::per_sink_buffer diagnostic_text_output_format diagnostics::text_sink sarif_output_format diagnostics::sarif_sink diagnostic_sarif_format_buffer diagnostics::sarif_sink_buffer html_output_format diagnostics::html_sink diagnostic_html_format_buffer diagnostics::html_sink_buffer No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS): Replace diagnostic-format-html.o with diagnostics/html-sink.o, diagnostic-format-sarif.o with diagnostics/sarif-sink.o, and diagnostic-format-text.o with diagnostics/text-sink.o. * coretypes.h (class diagnostic_text_output_format): Replace with... (class diagnostics::text_sink): ...this. * diagnostic-global-context.cc: Update for move of diagnostics output formats into namespace "diagnostics", as "sinks". * diagnostic-macro-unwinding.cc: Likewise. * diagnostic-macro-unwinding.h: Likewise. * diagnostic-show-locus.cc: Likewise. * diagnostic.cc: Likewise. * diagnostic.h: Likewise. * diagnostic-buffer.h: Rename to... * diagnostics/buffering.h: ...this, updating for above changes. * diagnostics/client-data-hooks.h: Likewise. * diagnostics/digraphs.cc: Likewise. * diagnostic-format-html.cc: Rename to... * diagnostics/html-sink.cc: ...this, updating for above changes. * diagnostic-format-html.h: Rename to... * diagnostics/html-sink.h: ...this, updating for above changes. * diagnostics/lazy-paths.cc: Likewise. * diagnostics/metadata.h: Likewise. * diagnostics/output-spec.cc: Likewise. * diagnostics/output-spec.h: Likewise. * diagnostics/paths-output.cc: Likewise. * diagnostics/paths.h: Likewise. * diagnostic-format-sarif.cc: Rename to... * diagnostics/sarif-sink.cc: ...this, updating for above changes. * diagnostic-format-sarif.h: Rename to... * diagnostics/sarif-sink.h: ...this, updating for above changes. * diagnostic-format.h: Rename to... * diagnostics/sink.h: ...this, updating for above changes. * diagnostics/state-graphs-to-dot.cc: Likewise. * diagnostic-format-text.cc: Rename to... * diagnostics/text-sink.cc: ...this, updating for above changes. * diagnostic-format-text.h: Rename to... * diagnostics/text-sink.h: ...this, updating for above changes. * gcc.cc: Likewise. * langhooks-def.h: Likewise. * langhooks.cc: Likewise. * langhooks.h: Likewise. * libgdiagnostics.cc: Likewise. * opts-diagnostic.cc: Likewise. * opts.cc: Likewise. * selftest-diagnostic.cc: Likewise. * selftest-run-tests.cc: Likewise. * selftest.h: Likewise. * tree-diagnostic-client-data-hooks.cc: Likewise. * tree-diagnostic.cc: Likewise. gcc/analyzer/ChangeLog: * ana-state-to-diagnostic-state.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * bounds-checking.cc: Likewise. * call-details.cc: Likewise. * checker-event.cc: Likewise. * checker-event.h: Likewise. * diagnostic-manager.cc: Likewise. * diagnostic-manager.h: Likewise. * infinite-loop.cc: Likewise. * infinite-recursion.cc: Likewise. * pending-diagnostic.h: Likewise. * region-model.cc: Likewise. * sm-taint.cc: Likewise. gcc/c-family/ChangeLog: * c-opts.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". gcc/cp/ChangeLog: * cp-tree.h: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * error.cc: Likewise. gcc/fortran/ChangeLog: * error.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * gfortran.h: Likewise. gcc/jit/ChangeLog: * dummy-frontend.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". gcc/rust/ChangeLog: * resolve/rust-ice-finalizer.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * resolve/rust-ice-finalizer.h: Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_group_plugin.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Likewise. * gcc.dg/plugin/location_overflow_plugin.cc: Likewise. libcc1/ChangeLog: * context.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-17Daily bump.GCC Administrator1-0/+16
2025-07-16openmp: Refactor handling of iteratorsKwok Cheung Yeung1-3/+1
Move code to calculate the iteration size and to generate the iterator expansion loop into separate functions. Use OMP_ITERATOR_DECL_P to check for iterators in clause declarations. gcc/c-family/ * c-omp.cc (c_finish_omp_depobj): Use OMP_ITERATOR_DECL_P. gcc/c/ * c-typeck.cc (handle_omp_array_sections): Use OMP_ITERATOR_DECL_P. (c_finish_omp_clauses): Likewise. gcc/cp/ * pt.cc (tsubst_omp_clause_decl): Use OMP_ITERATOR_DECL_P. * semantics.cc (handle_omp_array_sections): Likewise. (finish_omp_clauses): Likewise. gcc/ * gimplify.cc (gimplify_omp_affinity): Use OMP_ITERATOR_DECL_P. (compute_omp_iterator_count): New. (build_omp_iterator_loop): New. (gimplify_omp_depend): Use OMP_ITERATOR_DECL_P, compute_omp_iterator_count and build_omp_iterator_loop. * tree-inline.cc (copy_tree_body_r): Use OMP_ITERATOR_DECL_P. * tree-pretty-print.cc (dump_omp_clause): Likewise. * tree.h (OMP_ITERATOR_DECL_P): New macro.
2025-07-16Add get_clone_versions and get_target_version functions.Alfie Richards1-1/+3
This is a reimplementation of get_target_clone_attr_len, get_attr_str, and separate_attrs using string_slice and auto_vec to make memory management and use simpler. Adds get_target_version helper function to get the target_version string from a decl. gcc/c-family/ChangeLog: * c-attribs.cc (handle_target_clones_attribute): Change to use get_clone_versions. gcc/ChangeLog: * tree.cc (get_clone_versions): New function. (get_clone_attr_versions): New function. (get_version): New function. * tree.h (get_clone_versions): New function. (get_clone_attr_versions): New function. (get_target_version): New function.
2025-07-16Add string_slice class.Alfie Richards2-0/+8
The string_slice inherits from array_slice and is used to refer to a substring of an array that is memory managed elsewhere without modifying the underlying array. For example, this is useful in cases such as when needing to refer to a substring of an attribute in the syntax tree. Adds some minimal helper functions for string_slice, such as a strtok alternative, equality operators, strcmp, and a function to strip whitespace from the beginning and end of a string_slice. gcc/c-family/ChangeLog: * c-format.cc (local_string_slice_node): New node type. (asm_fprintf_char_table): New entry. (init_dynamic_diag_info): Add support for string_slice. * c-format.h (T_STRING_SLICE): New node type. gcc/ChangeLog: * pretty-print.cc (format_phase_2): Add support for string_slice. * vec.cc (string_slice::tokenize): New static method. (string_slice::strcmp): New static method. (string_slice::strip): New method. (test_string_slice_initializers): New test. (test_string_slice_tokenize): Ditto. (test_string_slice_strcmp): Ditto. (test_string_slice_equality): Ditto. (test_string_slice_inequality): Ditto. (test_string_slice_invalid): Ditto. (test_string_slice_strip): Ditto. (vec_cc_tests): Add new tests. * vec.h (class string_slice): New class. gcc/testsuite/ChangeLog * g++.dg/warn/Wformat-gcc_diag-1.C: Add string_slice "%B" format tests.
2025-07-16Daily bump.GCC Administrator1-0/+10
2025-07-15c, c++: Extend -Wunused-but-set-* warnings [PR44677]Jakub Jelinek2-2/+12
The -Wunused-but-set-* warnings work by using 2 bits on VAR_DECLs & PARM_DECLs, TREE_USED and DECL_READ_P. If neither is set, we typically emit -Wunused-variable or -Wunused-parameter warning, that is for variables which are just declared (including initializer) and completely unused. If TREE_USED is set and DECL_READ_P is unset, -Wunused-but-set-* warnings are emitted, i.e. for variables which can appear on the lhs of an assignment expression but aren't actually used elsewhere. The DECL_READ_P marking is done through mark_exp_read called from lots of places (e.g. lvalue to rvalue conversions etc.). LLVM has an extension on top of that in that it doesn't count pre/post inc/decrements as use (i.e. DECL_READ_P for GCC). The following patch does that too, though because we had the current behavior for 11+ years already and lot of people is -Wunused-but-set-* warning free in the current GCC behavior and not in the clang one (including GCC sources), it allows users to choose. Furthermore, it implements another level, where also var @= expr uses of var (except when it is also used in expr) aren't counted as DECL_READ_P. I think it would be nice to also handle var = var @ expr or var = expr @ var but unfortunately mark_exp_read is then done in both FEs during parsing of var @ expr or expr @ var and the code doesn't know it is rhs of an assignment with var as lhs. The patch works mostly by checking if DECL_READ_P is clear at some point and then clearing it again after some operation which might have set it. -Wunused or -Wall or -Wunused -Wextra or -Wall -Wextra turn on the 3 level of the new warning (i.e. the one which ignores also var++, ++var etc. as well as var @= expr), so does -Wunused-but-set-{variable,parameter}, but users can use explicit -Wunused-but-set-{variable,parameter}={1,2} to select a different level. 2025-07-15 Jakub Jelinek <jakub@redhat.com> Jason Merrill <jason@redhat.com> PR c/44677 gcc/ * common.opt (Wunused-but-set-parameter=, Wunused-but-set-variable=): New options. (Wunused-but-set-parameter, Wunused-but-set-variable): Turn into aliases. * common.opt.urls: Regenerate. * diagnostic-spec.cc (nowarn_spec_t::nowarn_spec_t): Use OPT_Wunused_but_set_variable_ instead of OPT_Wunused_but_set_variable and OPT_Wunused_but_set_parameter_ instead of OPT_Wunused_but_set_parameter. * gimple-ssa-store-merging.cc (find_bswap_or_nop_1): Remove unused but set variable tmp. * ipa-strub.cc (pass_ipa_strub::execute): Cast named_args to (void) if ATTR_FNSPEC_DECONST_WATERMARK is not defined. * doc/invoke.texi (Wunused-but-set-parameter=, Wunused-but-set-variable=): Document new options. (Wunused-but-set-parameter, Wunused-but-set-variable): Adjust documentation now that they are just aliases. gcc/c-family/ * c-opts.cc (c_common_post_options): Change warn_unused_but_set_parameter and warn_unused_but_set_variable from 1 to 3 if they were set only implicitly. * c-attribs.cc (build_attr_access_from_parms): Remove unused but set variable nelts. gcc/c/ * c-parser.cc (c_parser_unary_expression): Clear DECL_READ_P after default_function_array_read_conversion for -Wunused-but-set-{parameter,variable}={2,3} on PRE{IN,DE}CREMENT_EXPR argument. (c_parser_postfix_expression_after_primary): Similarly for POST{IN,DE}CREMENT_EXPR. * c-decl.cc (pop_scope): Use OPT_Wunused_but_set_variable_ instead of OPT_Wunused_but_set_variable. (finish_function): Use OPT_Wunused_but_set_parameter_ instead of OPT_Wunused_but_set_parameter. * c-typeck.cc (mark_exp_read): Handle {PRE,POST}{IN,DE}CREMENT_EXPR and don't handle it when cast to void. (build_modify_expr): Clear DECL_READ_P after build_binary_op for -Wunused-but-set-{parameter,variable}=3. gcc/cp/ * cp-gimplify.cc (cp_fold): Clear DECL_READ_P on lhs of MODIFY_EXPR after cp_fold_rvalue if it wasn't set before. * decl.cc (poplevel): Use OPT_Wunused_but_set_variable_ instead of OPT_Wunused_but_set_variable. (finish_function): Use OPT_Wunused_but_set_parameter_ instead of OPT_Wunused_but_set_parameter. * expr.cc (mark_use): Clear read_p for {PRE,POST}{IN,DE}CREMENT_EXPR cast to void on {VAR,PARM}_DECL for -Wunused-but-set-{parameter,variable}={2,3}. (mark_exp_read): Handle {PRE,POST}{IN,DE}CREMENT_EXPR and don't handle it when cast to void. * module.cc (trees_in::fn_parms_fini): Remove unused but set variable ix. * semantics.cc (finish_unary_op_expr): Return early for PRE{IN,DE}CREMENT_EXPR. * typeck.cc (cp_build_unary_op): Clear DECL_READ_P after mark_lvalue_use for -Wunused-but-set-{parameter,variable}={2,3} on PRE{IN,DE}CREMENT_EXPR argument. (cp_build_modify_expr): Clear DECL_READ_P after cp_build_binary_op for -Wunused-but-set-{parameter,variable}=3. gcc/go/ * gofrontend/gogo.cc (Function::export_func_with_type): Remove unused but set variable i. gcc/cobol/ * gcobolspec.cc (lang_specific_driver): Remove unused but set variable n_cobol_files. gcc/testsuite/ * c-c++-common/Wunused-parm-1.c: New test. * c-c++-common/Wunused-parm-2.c: New test. * c-c++-common/Wunused-parm-3.c: New test. * c-c++-common/Wunused-parm-4.c: New test. * c-c++-common/Wunused-parm-5.c: New test. * c-c++-common/Wunused-parm-6.c: New test. * c-c++-common/Wunused-var-7.c (bar, baz): Expect warning on a. * c-c++-common/Wunused-var-19.c: New test. * c-c++-common/Wunused-var-20.c: New test. * c-c++-common/Wunused-var-21.c: New test. * c-c++-common/Wunused-var-22.c: New test. * c-c++-common/Wunused-var-23.c: New test. * c-c++-common/Wunused-var-24.c: New test. * g++.dg/cpp26/name-independent-decl1.C (foo): Expect one set but not used warning. * g++.dg/warn/Wunused-parm-12.C: New test. * g++.dg/warn/Wunused-parm-13.C: New test. * g++.dg/warn/Wunused-var-2.C (f2): Expect set but not used warning on parameter x and variable a. * g++.dg/warn/Wunused-var-40.C: New test. * g++.dg/warn/Wunused-var-41.C: New test. * gcc.dg/memchr-3.c (test_find): Change return type from void to int, and add return n; statement. * gcc.dg/unused-9.c (g): Move dg-bogus to the correct line and expect a warning on i.
2025-07-12Daily bump.GCC Administrator1-0/+10
2025-07-11c++: Implement C++26 P2786R13 - Trivial Relocatability [PR119064]Jakub Jelinek4-0/+11
The following patch implements the compiler side of the C++26 paper. Based on the https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119064#c3 feedback, the patch enables the new conditional keywords trivially_relocatable_if_eligible and replaceable_if_eligible only for C++26, for older versions those conditional keywords yield -Wc++26-compat warning and are treated as normal identifiers. Plus __trivially_relocatable_if_eligible and __replaceable_if_eligible are handled as conditional keywords always without diagnostics (similarly to __final in C++98). The patch uses __builtin_ prefix on the new traits (but unlike clang which for some weird reason chose to name one __builtin_is_replaceable and another __builtin_is_cpp_trivially_relocatable this one uses __builtin_is_replaceable and __builtin_is_trivially_relocatable. I'll try to convince clang to change, they've only implemented it recently. The patch computes these properties on demand, only when something needs them (at the expense of eating 2 more bits per lang_type, but I've recently saved 64 bits and a patch to save another 64 bits is pending; and even 4 bits wouldn't fit). The patch doesn't add __builtin_trivially_relocate builtin that clang has, std::trivially_relocate is not constexpr and I think we don't need it for now at least until we implement some kind of vtable pointer signing __builtin_memmove should do the job. Especially if libstdc++ will for clang compatibility use the builtin if available and __builtin_memmove otherwise, we can switch any time. I've cross-tested all testcases also against the clang++ trunk implementation, and both compilers agreed in everything except for https://github.com/llvm/llvm-project/issues/143599 where clang++ was changed already and https://github.com/llvm/llvm-project/issues/144232 where I believe clang++ got it wrong too. The first testcase comes from https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2786r13.html#simple-worked-examples just tweaked so that the classes are named differently each time and that it compiles. There are 3 differences from the paper vs. the g++ as well as clang++ implementation, I've added comments into trivially-relocatable1.C but I think either that part of the paper wasn't updated through the later changes or it got it wrong. 2025-07-11 Jakub Jelinek <jakub@redhat.com> PR c++/119064 gcc/ * doc/invoke.texi (Wc++26-compat): Document. gcc/c-family/ * c.opt (Wc++26-compat): New option. * c.opt.urls: Regenerate. * c-opts.cc (c_common_post_options): Clear warn_cxx26_compat for C++26 or later. * c-cppbuiltin.cc (c_cpp_builtins): For C++26 predefine __cpp_trivial_relocatability=202502L. gcc/cp/ * cp-tree.h: Implement C++26 P2786R13 - Trivial Relocatability. (struct lang_type): Add trivially_relocatable, trivially_relocatable_computed, replaceable and replaceable_computed bitfields. Change width of dummy from 2 to 30. (CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT, CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED, CLASSTYPE_REPLACEABLE_BIT, CLASSTYPE_REPLACEABLE_COMPUTED): Define. (enum virt_specifier): Add VIRT_SPEC_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE and VIRT_SPEC_REPLACEABLE_IF_ELIGIBLE enumerators. (trivially_relocatable_type_p, replaceable_type_p): Declare. * cp-trait.def (IS_NOTHROW_RELOCATABLE, IS_REPLACEABLE, IS_TRIVIALLY_RELOCATABLE): New traits. * parser.cc (cp_parser_class_property_specifier_seq_opt): Handle trivially_relocatable_if_eligible, __trivially_relocatable_if_eligible, replaceable_if_eligible and __replaceable_if_eligible. (cp_parser_class_head): Set CLASSTYPE_REPLACEABLE_BIT and/or CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT if corresponding conditional keywords were parsed and assert corresponding *_COMPUTED macro is false. * pt.cc (instantiate_class_template): Copy over also CLASSTYPE_TRIVIALLY_RELOCATABLE_{BIT,COMPUTED} and CLASSTYPE_REPLACEABLE_{BIT,COMPUTED} bits. * semantics.cc (referenceable_type_p): Move definition earlier. (trait_expr_value): Handle CPTK_IS_NOTHROW_RELOCATABLE, CPTK_IS_REPLACEABLE and CPTK_IS_TRIVIALLY_RELOCATABLE. (finish_trait_expr): Likewise. * tree.cc (default_movable_type_p): New function. (union_with_no_declared_special_member_fns): Likewise. (trivially_relocatable_type_p): Likewise. (replaceable_type_p): Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_NOTHROW_RELOCATABLE, CPTK_IS_REPLACEABLE and CPTK_IS_TRIVIALLY_RELOCATABLE. gcc/testsuite/ * g++.dg/cpp26/feat-cxx26.C: Add test for __cpp_trivial_relocatability. * g++.dg/cpp26/trivially-relocatable1.C: New test. * g++.dg/cpp26/trivially-relocatable2.C: New test. * g++.dg/cpp26/trivially-relocatable3.C: New test. * g++.dg/cpp26/trivially-relocatable4.C: New test. * g++.dg/cpp26/trivially-relocatable5.C: New test. * g++.dg/cpp26/trivially-relocatable6.C: New test. * g++.dg/cpp26/trivially-relocatable7.C: New test. * g++.dg/cpp26/trivially-relocatable8.C: New test. * g++.dg/cpp26/trivially-relocatable9.C: New test. * g++.dg/cpp26/trivially-relocatable10.C: New test. * g++.dg/cpp26/trivially-relocatable11.C: New test.
2025-07-11Daily bump.GCC Administrator1-0/+11
2025-07-10c++, libstdc++: Implement C++26 P3068R5 - constexpr exceptions [PR117785]Jakub Jelinek1-0/+1
The following patch implements the C++26 P3068R5 - constexpr exceptions paper. As the IL cxx_eval_constant* functions process already contains the low level calls like __cxa_{allocate,free}_exception, __cxa_{,re}throw etc., the patch just makes 10 extern "C" __cxa_* functions magic builtins which during constant evaluation pretend to be constexpr even when not declared so and handle them directly, plus does the same for 3 std namespace functions - std::uncaught_exceptions, std::current_exception and std::rethrow_exception and adds one new FE builtin - __builtin_eh_ptr_adjust_ref which the library can use instead of the _M_addref and _M_release out of line methods (this one instead of recognizing _M_* as magic too because those are clearly specific to libstdc++ and e.g. libc++ could use something else). The patch uses magic VAR_DECLs with heap_{uninit_,,deleted_}identifier DECL_NAME like for operator new/delete for objects allocated with __cxa_allocate_exception, just sets their DECL_LANG_SPECIFIC so that we can track their reference count as well (with std::exception_ptr the same exception object can be referenced multiple times and we want to destruct and free only when it reaches zero refcount). For uncaught exceptions being propagated, the patch uses new kind of *jump_target, which is that magic VAR_DECL described above. The largest change in the patch is making jump_target argument non-optional in cxa_eval_constant_exception and all functions it calls that need it. This is because exceptions can be thrown from pretty much everywhere, e.g. binary expression can throw in either operand. And the patch also adds if (*jump_target) return NULL_TREE; or similar in many spots, so that we don't crash because cxx_eval_constant_expression returned NULL_TREE somewhere before actually trying to use it and so that we don't uselessly dive into other operands etc. Note, with statement expressions actually this was something we just didn't handle correctly before, one can validly have: a = ({ if (x) return 42; 12; }) + b; or in the other operand, or break/continue instead of return if it is somewhere in a loop/switch; and it isn't ok to branch from one operand to another one through some kind of goto. On the potential_constant_expression_1 side, important change was to set *jump_target conservatively on calls that could throw for C++26 (the patch uses magic void_node for potential_constant_expression* instead of VAR_DECL, so that we don't have to create new VAR_DECLs there uselessly). Without that change, several methods in libstdc++ wouldn't work correctly. I'm not sure what exactly potential_constant_expression_1 maps to in the C++26 standard wording now and whether doing that is ok, because basically after the first call to non-noexcept function it stops checking stuff. And, in some spots where I know potential_constant_expression_1 didn't check some subexpressions (e.g. the EH only cleanups or TRY_BLOCK handlers) I've added *potential_constant_expression* calls during cxx_eval_constant*, not sure if I need to do that because potential_constant_expression_1 is very conservative and just doesn't recurse on subexpressions in many cases. 2025-07-10 Jakub Jelinek <jakub@redhat.com> PR c++/117785 gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): Predefine __cpp_constexpr_exceptions=202411L for C++26. gcc/cp/ * constexpr.cc: Implement C++26 P3068R5 - constexpr exceptions. (class constexpr_global_ctx): Add caught_exceptions and uncaught_exceptions members. (constexpr_global_ctx::constexpr_global_ctx): Initialize uncaught_exceptions. (returns, breaks, continues, switches): Move earlier. (throws): New function. (exception_what_str, diagnose_std_terminate, diagnose_uncaught_exception): New functions. (enum cxa_builtin): New type. (cxx_cxa_builtin_fn_p, cxx_eval_cxa_builtin_fn): New functions. (cxx_eval_builtin_function_call): Add jump_target argument. Call cxx_eval_cxa_builtin_fn for __builtin_eh_ptr_adjust_ref. Adjust cxx_eval_constant_expression calls, if it results in jmp_target, set *jump_target to it and return. (cxx_bind_parameters_in_call): Add jump_target argument. Pass it through to cxx_eval_constant_expression. If it sets *jump_target, break. (fold_operand): Adjust cxx_eval_constant_expression caller. (cxx_eval_assert): Likewise. If it set jmp_target, return true. (cxx_eval_internal_function): Add jump_target argument. Pass it through to cxx_eval_constant_expression. Return early if *jump_target after recursing on args. (cxx_eval_dynamic_cast_fn): Likewise. Don't set reference_p for C++26 with -fexceptions. (cxx_eval_thunk_call): Add jump_target argument. Pass it through to cxx_eval_constant_expression. (cxx_set_object_constness): Likewise. Don't set TREE_READONLY if throws (jump_target). (cxx_eval_call_expression): Add jump_target argument. Pass it through to cxx_eval_internal_function, cxx_eval_builtin_function_call, cxx_eval_thunk_call, cxx_eval_dynamic_cast_fn and cxx_set_object_constness. Pass it through also cxx_eval_constant_expression on arguments, cxx_bind_parameters_in_call and cxx_fold_indirect_ref and for those cases return early if *jump_target. Call cxx_eval_cxa_builtin_fn for cxx_cxa_builtin_fn_p functions. For cxx_eval_constant_expression on body, pass address of cleared jmp_target automatic variable, if it throws propagate to *jump_target and make it non-cacheable. For C++26 don't diagnose calls to non-constexpr functions before cxx_bind_parameters_in_call could report some argument throwing an exception. (cxx_eval_unary_expression): Add jump_target argument. Pass it through to cxx_eval_constant_expression and return early if *jump_target after the call. (cxx_fold_pointer_plus_expression): Likewise. (cxx_eval_binary_expression): Likewise and similarly for cxx_fold_pointer_plus_expression call. (cxx_eval_conditional_expression): Pass jump_target to cxx_eval_constant_expression on first operand and return early if *jump_target after the call. (cxx_eval_vector_conditional_expression): Add jump_target argument. Pass it through to cxx_eval_constant_expression for all 3 arguments and return early if *jump_target after any of those calls. (get_array_or_vector_nelts): Add jump_target argument. Pass it through to cxx_eval_constant_expression. (eval_and_check_array_index): Add jump_target argument. Pass it through to cxx_eval_constant_expression calls and return early after each of them if *jump_target. (cxx_eval_array_reference): Likewise. (cxx_eval_component_reference): Likewise. (cxx_eval_bit_field_ref): Likewise. (cxx_eval_bit_cast): Likewise. Assert CHECKING_P call doesn't throw or return. (cxx_eval_logical_expression): Add jump_target argument. Pass it through to cxx_eval_constant_expression calls and return early after each of them if *jump_target. (cxx_eval_bare_aggregate): Likewise. (cxx_eval_vec_init_1): Add jump_target argument. Pass it through to cxx_eval_bare_aggregate and recursive call. Pass it through to get_array_or_vector_nelts and cxx_eval_constant_expression and return early after it if *jump_target. (cxx_eval_vec_init): Add jump_target argument. Pass it through to cxx_eval_constant_expression and cxx_eval_vec_init_1. (cxx_union_active_member): Add jump_target argument. Pass it through to cxx_eval_constant_expression and return early after it if *jump_target. (cxx_fold_indirect_ref_1): Add jump_target argument. Pass it through to cxx_union_active_member and recursive calls. (cxx_eval_indirect_ref): Add jump_target argument. Pass it through to cxx_fold_indirect_ref_1 calls and to recursive call, in which case return early after it if *jump_target. (cxx_fold_indirect_ref): Add jump_target argument. Pass it through to cxx_fold_indirect_ref and cxx_eval_constant_expression calls and return early after those if *jump_target. (cxx_eval_trinary_expression): Add jump_target argument. Pass it through to cxx_eval_constant_expression calls and return early after those if *jump_target. (cxx_eval_store_expression): Add jump_target argument. Pass it through to cxx_eval_constant_expression and eval_and_check_array_index calls and return early after those if *jump_target. (cxx_eval_increment_expression): Add jump_target argument. Pass it through to cxx_eval_constant_expression calls and return early after those if *jump_target. (label_matches): Handle VAR_DECL case. (cxx_eval_statement_list): Remove local_target variable and !jump_target handling. Handle throws (jump_target) like returns or breaks. (cxx_eval_loop_expr): Remove local_target variable and !jump_target handling. Pass it through to cxx_eval_constant_expression. Handle throws (jump_target) like returns. (cxx_eval_switch_expr): Pass jump_target through to cxx_eval_constant_expression on cond, return early after it if *jump_target. (build_new_constexpr_heap_type): Add jump_target argument. Pass it through to cxx_eval_constant_expression calls, return early after those if *jump_target. (merge_jump_target): New function. (cxx_eval_constant_expression): Make jump_target argument no longer defaulted, don't test jump_target for NULL. Pass jump_target through to recursive calls, cxx_eval_call_expression, cxx_eval_store_expression, cxx_eval_indirect_ref, cxx_eval_unary_expression, cxx_eval_binary_expression, cxx_eval_logical_expression, cxx_eval_array_reference, cxx_eval_component_reference, cxx_eval_bit_field_ref, cxx_eval_vector_conditional_expression, cxx_eval_bare_aggregate, cxx_eval_vec_init, cxx_eval_trinary_expression, cxx_fold_indirect_ref, build_new_constexpr_heap_type, cxx_eval_increment_expression, cxx_eval_bit_cast and return earlyu after some of those if *jump_target as needed. (cxx_eval_constant_expression) <case TARGET_EXPR>: For C++26 push also CLEANUP_EH_ONLY cleanups, with NULL_TREE marker after them. (cxx_eval_constant_expression) <case RETURN_EXPR>: Don't override *jump_target if throws (jump_target). (cxx_eval_constant_expression) <case TRY_CATCH_EXPR, case TRY_BLOCK, case MUST_NOT_THROW_EXPR, case TRY_FINALLY_EXPR, case CLEANUP_STMT>: Handle C++26 constant expressions. (cxx_eval_constant_expression) <case CLEANUP_POINT_EXPR>: For C++26 with throws (jump_target) evaluate the CLEANUP_EH_ONLY cleanups as well, and if not throws (jump_target) skip those. Set *jump_target if some of the cleanups threw. (cxx_eval_constant_expression) <case THROW_EXPR>: Recurse on operand for C++26. (cxx_eval_outermost_constant_expr): Diagnose uncaught exceptions both from main expression and cleanups, diagnose also break/continue/returns from the main expression. Handle CLEANUP_EH_ONLY cleanup markers. Don't diagnose mutable poison stuff if non_constant_p. Use different diagnostics for non-deleted heap allocations if they were allocated by __cxa_allocate_exception. (callee_might_throw): New function. (struct check_for_return_continue_data): Add could_throw field. (check_for_return_continue): Handle AGGR_INIT_EXPR and CALL_EXPR and set d->could_throw if they could throw. (potential_constant_expression_1): For CALL_EXPR allow cxx_dynamic_cast_fn_p calls. For C++26 set *jump_target to void_node for calls that could throw. For C++26 if call to non-constexpr call is seen, try to evaluate arguments first and if they could throw, don't diagnose call to non-constexpr function nor return false. Adjust check_for_return_continue_data initializers and set *jump_target to void_node if data.could_throw_p. For C++26 recurse on THROW_EXPR argument. Add comment explaining TRY_BLOCK handling with C++26 exceptions. Handle throws like returns in some cases. * cp-tree.h (MUST_NOT_THROW_NOEXCEPT_P, MUST_NOT_THROW_THROW_P, MUST_NOT_THROW_CATCH_P, DECL_EXCEPTION_REFCOUNT): Define. (DECL_LOCAL_DECL_P): Fix comment typo, VARIABLE_DECL -> VAR_DECL. (enum cp_built_in_function): Add CP_BUILT_IN_EH_PTR_ADJUST_REF, (handler_match_for_exception_type): Declare. * call.cc (handler_match_for_exception_type): New function. * except.cc (initialize_handler_parm): Set MUST_NOT_THROW_CATCH_P on newly created MUST_NOT_THROW_EXPR. (begin_eh_spec_block): Set MUST_NOT_THROW_NOEXCEPT_P. (wrap_cleanups_r): Set MUST_NOT_THROW_THROW_P. (build_throw): Add another TARGET_EXPR whose scope spans until after the __cxa_throw call and copy pointer value from ptr to it and use it in __cxa_throw argument. * tree.cc (builtin_valid_in_constant_expr_p): Handle CP_BUILT_IN_EH_PTR_ADJUST_REF. * decl.cc (cxx_init_decl_processing): Initialize __builtin_eh_ptr_adjust_ref FE builtin. * pt.cc (tsubst_stmt) <case MUST_NOT_THROW_EXPR>: Copy the MUST_NOT_THROW_NOEXCEPT_P, MUST_NOT_THROW_THROW_P and MUST_NOT_THROW_CATCH_P flags. * cp-gimplify.cc (cp_gimplify_expr) <case CALL_EXPR>: Error on non-folded CP_BUILT_IN_EH_PTR_ADJUST_REF calls. gcc/testsuite/ * g++.dg/cpp0x/constexpr-ellipsis2.C: Expect different diagnostics for C++26. * g++.dg/cpp0x/constexpr-throw.C: Likewise. * g++.dg/cpp1y/constexpr-84192.C: Expect different diagnostics. * g++.dg/cpp1y/constexpr-throw.C: Expect different diagnostics for C++26. * g++.dg/cpp1z/constexpr-asm-5.C: Likewise. * g++.dg/cpp26/constexpr-eh1.C: New test. * g++.dg/cpp26/constexpr-eh2.C: New test. * g++.dg/cpp26/constexpr-eh3.C: New test. * g++.dg/cpp26/constexpr-eh4.C: New test. * g++.dg/cpp26/constexpr-eh5.C: New test. * g++.dg/cpp26/constexpr-eh6.C: New test. * g++.dg/cpp26/constexpr-eh7.C: New test. * g++.dg/cpp26/constexpr-eh8.C: New test. * g++.dg/cpp26/constexpr-eh9.C: New test. * g++.dg/cpp26/constexpr-eh10.C: New test. * g++.dg/cpp26/constexpr-eh11.C: New test. * g++.dg/cpp26/constexpr-eh12.C: New test. * g++.dg/cpp26/constexpr-eh13.C: New test. * g++.dg/cpp26/constexpr-eh14.C: New test. * g++.dg/cpp26/constexpr-eh15.C: New test. * g++.dg/cpp26/feat-cxx26.C: Change formatting in __cpp_pack_indexing and __cpp_pp_embed test. Add __cpp_constexpr_exceptions test. * g++.dg/cpp26/static_assert1.C: Expect different diagnostics for C++26. * g++.dg/cpp2a/consteval34.C: Likewise. * g++.dg/cpp2a/consteval-memfn1.C: Likewise. * g++.dg/cpp2a/constexpr-dynamic4.C: For C++26 add std::exception and std::bad_cast definitions and expect different diagnostics. * g++.dg/cpp2a/constexpr-dynamic6.C: Likewise. * g++.dg/cpp2a/constexpr-dynamic7.C: Likewise. * g++.dg/cpp2a/constexpr-dynamic8.C: Likewise. * g++.dg/cpp2a/constexpr-dynamic9.C: Likewise. * g++.dg/cpp2a/constexpr-dynamic11.C: Likewise. * g++.dg/cpp2a/constexpr-dynamic14.C: Likewise. * g++.dg/cpp2a/constexpr-dynamic18.C: Likewise. * g++.dg/cpp2a/constexpr-new27.C: New test. * g++.dg/cpp2a/constexpr-typeid5.C: New test. libstdc++-v3/ * include/bits/version.def (constexpr_exceptions): New. * include/bits/version.h: Regenerate. * libsupc++/exception (std::bad_exception::bad_exception): Add _GLIBCXX26_CONSTEXPR. (std::bad_exception::~bad_exception, std::bad_exception::what): For C++26 add constexpr and define inline. * libsupc++/exception.h (std::exception::exception, std::exception::operator=): Add _GLIBCXX26_CONSTEXPR. (std::exception::~exception, std::exception::what): For C++26 add constexpr and define inline. * libsupc++/exception_ptr.h (std::make_exception_ptr): Add _GLIBCXX26_CONSTEXPR. For if consteval use just throw with current_exception() in catch. (std::exception_ptr::exception_ptr(void*)): For C++26 add constexpr and define inline. (std::exception_ptr::exception_ptr()): Add _GLIBCXX26_CONSTEXPR. (std::exception_ptr::exception_ptr(const exception_ptr&)): Likewise. Use __builtin_eh_ptr_adjust_ref if consteval and compiler has it instead of _M_addref. (std::exception_ptr::exception_ptr(nullptr_t)): Add _GLIBCXX26_CONSTEXPR. (std::exception_ptr::exception_ptr(exception_ptr&&)): Likewise. (std::exception_ptr::operator=): Likewise. (std::exception_ptr::~exception_ptr): Likewise. Use __builtin_eh_ptr_adjust_ref if consteval and compiler has it instead of _M_release. (std::exception_ptr::swap): Add _GLIBCXX26_CONSTEXPR. (std::exception_ptr::operator bool): Likewise. (std::exception_ptr::operator==): Likewise. * libsupc++/nested_exception.h (std::nested_exception::nested_exception): Add _GLIBCXX26_CONSTEXPR. (std::nested_exception::operator=): Likewise. (std::nested_exception::~nested_exception): For C++26 add constexpr and define inline. (std::nested_exception::rethrow_if_nested): Add _GLIBCXX26_CONSTEXPR. (std::nested_exception::nested_ptr): Likewise. (std::_Nested_exception::_Nested_exception): Likewise. (std::throw_with_nested, std::rethrow_if_nested): Likewise. * libsupc++/new (std::bad_alloc::bad_alloc): Likewise. (std::bad_alloc::operator=): Likewise. (std::bad_alloc::~bad_alloc): For C++26 add constexpr and define inline. (std::bad_alloc::what): Likewise. (std::bad_array_new_length::bad_array_new_length): Add _GLIBCXX26_CONSTEXPR. (std::bad_array_new_length::~bad_array_new_length): For C++26 add constexpr and define inline. (std::bad_array_new_length::what): Likewise. * libsupc++/typeinfo (std::bad_cast::bad_cast): Add _GLIBCXX26_CONSTEXPR. (std::bad_cast::~bad_cast): For C++26 add constexpr and define inline. (std::bad_cast::what): Likewise. (std::bad_typeid::bad_typeid): Add _GLIBCXX26_CONSTEXPR. (std::bad_typeid::~bad_typeid): For C++26 add constexpr and define inline. (std::bad_typeid::what): Likewise.
2025-07-10Reduce the # of arguments of .ACCESS_WITH_SIZE from 6 to 4.Qing Zhao1-8/+2
This is an improvement to the design of internal function .ACCESS_WITH_SIZE. Currently, the .ACCESS_WITH_SIZE is designed as: ACCESS_WITH_SIZE (REF_TO_OBJ, REF_TO_SIZE, CLASS_OF_SIZE, TYPE_OF_SIZE, ACCESS_MODE, TYPE_SIZE_UNIT for element) which returns the REF_TO_OBJ same as the 1st argument; 1st argument REF_TO_OBJ: The reference to the object; 2nd argument REF_TO_SIZE: The reference to the size of the object, 3rd argument CLASS_OF_SIZE: The size referenced by the REF_TO_SIZE represents 0: the number of bytes. 1: the number of the elements of the object type; 4th argument TYPE_OF_SIZE: A constant 0 with its TYPE being the same as the TYPE of the object referenced by REF_TO_SIZE 5th argument ACCESS_MODE: -1: Unknown access semantics 0: none 1: read_only 2: write_only 3: read_write 6th argument: The TYPE_SIZE_UNIT of the element TYPE of the FAM when 3rd argument is 1. NULL when 3rd argument is 0. Among the 6 arguments: A. The 3rd argument CLASS_OF_SIZE is not needed. If the REF_TO_SIZE represents the number of bytes, simply pass 1 to the TYPE_SIZE_UNIT argument. B. The 4th and the 5th arguments can be combined into 1 argument, whose TYPE represents the TYPE_OF_SIZE, and the constant value represents the ACCESS_MODE. As a result, the new design of the .ACCESS_WITH_SIZE is: ACCESS_WITH_SIZE (REF_TO_OBJ, REF_TO_SIZE, TYPE_OF_SIZE + ACCESS_MODE, TYPE_SIZE_UNIT for element) which returns the REF_TO_OBJ same as the 1st argument; 1st argument REF_TO_OBJ: The reference to the object; 2nd argument REF_TO_SIZE: The reference to the size of the object, 3rd argument TYPE_OF_SIZE + ACCESS_MODE: An integer constant with a pointer TYPE. The pointee TYPE of the pointer TYPE is the TYPE of the object referenced by REF_TO_SIZE. The integer constant value represents the ACCESS_MODE: 0: none 1: read_only 2: write_only 3: read_write 4th argument: The TYPE_SIZE_UNIT of the element TYPE of the array. gcc/c-family/ChangeLog: * c-ubsan.cc (get_bound_from_access_with_size): Adjust the position of the arguments per the new design. gcc/c/ChangeLog: * c-typeck.cc (build_access_with_size_for_counted_by): Update comments. Adjust the arguments per the new design. gcc/ChangeLog: * internal-fn.cc (expand_ACCESS_WITH_SIZE): Update comments. * internal-fn.def (ACCESS_WITH_SIZE): Update comments. * tree-object-size.cc (access_with_size_object_size): Update comments. Adjust the arguments per the new design.
2025-07-08Daily bump.GCC Administrator1-0/+34
2025-07-07Revert "Extend "counted_by" attribute to pointer fields of structures. ↵Qing Zhao1-38/+6
Convert a pointer reference with counted_by attribute to .ACCESS_WITH_SIZE." due to PR120929. This reverts commit 687727375769dd41971bad369f3553f1163b3e7a.
2025-07-07Revert "Use the counted_by attribute of pointers in array bound checker." ↵Qing Zhao2-328/+16
due to PR120929 This reverts commit 9d579c522d551eaa807e438206e19a91a3def67f.