Age | Commit message (Collapse) | Author | Files | Lines |
|
|
|
When transitioning gcc.dg/torture/pr84830.c to a GIMPLE testcase to
feed the IL into PRE that caused the original issue (and verify it's
still there with the fix reverted), I noticed we put up SSA operands
before having fully parsed the function and thus with not all
variables having the final TREE_ADDRESSABLE state. The following
fixes this, delaying update_stmt calls to when we create PHI nodes.
It also makes the pr84830.c not rely on the particular fake exit
edge source location by making the loop have an exit.
gcc/c/
* gimple-parser.cc (c_parser_parse_gimple_body): Initialize
SSA operands for each stmt.
(c_parser_gimple_compound_statement): Append stmts without
updating SSA operands.
gcc/testsuite/
* gcc.dg/torture/pr84830.c: Turn into GIMPLE unit test for PRE.
|
|
|
|
These two don't make sense as nested functions as they both don't handle
the unnesting and/or have support for the static chain.
So let's reject them.
Bootstrapped and tested on x86_64-linux-gnu.
PR c/121421
gcc/c/ChangeLog:
* c-parser.cc (c_parser_declaration_or_fndef): Error out for gimple
and rtl functions as nested functions.
gcc/testsuite/ChangeLog:
* gcc.dg/gimplefe-error-16.c: New test.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
|
|
|
|
N3517 (array subscripting without decay) has been added to C2y (via a
remote vote in May, not at a meeting). Implement this in GCC.
The conceptual change, that the array subscripting operator [] no
longer involves an array operand decaying to a pointer, is something
GCC has done for a very long time. The main effect in terms of what
is made possible in the language, subscripting a register array
(undefined behavior in C23 and before), was available as a GNU
extension, but only with constant indices. There is also a new
constraint that array indices must not be negative when they are
integer constant expressions and the array operand has array type
(negative indices are fine with pointers) - an access out of bounds of
an array (even when contained within a larger object) has undefined
behavior at runtime when not a constraint violation.
Thus, the previous GCC extension is adapted to allow the cases of
register arrays not previously allowed, clearing DECL_REGISTER on them
as needed (similar to what is done with register declarations of
structures with volatile members) and restricting the pedwarn to
pedwarn_c23. That pedwarn_c23 is also extended to cover the C23 case
of register compound literals (although not strictly needed since it
was undefined behavior rather than a constraint violation in C23).
The new error is added (only for flag_isoc2y) for negative array
indices with an operand of array type.
N3517 has some specific wording about the type of the result of
non-lvalue array element access. It's unclear what's actually desired
there in the case where the array element is itself of array type; see
C23 issue 1001 regarding types of qualified members of rvalue
structures and unions more generally. Rather than implementing the
specific wording about this in N3517, that is deferred until there's
an accepted resolution to issue 1001 and can be dealt with as part of
implementing such a resolution.
Nothing specific is done about the obsolescence in that paper of
writing index[array] or index[pointer] as opposed to array[index] or
pointer[index], although that seems like a reasonable enough thing to
warn about.
Bootstrapped with no regressions for x86_64-pc-linux-gnu.
gcc/c/
* c-typeck.cc (c_mark_addressable): New parameter
override_register.
(build_array_ref): Update calls to c_mark_addressable. Give error
in C2Y mode for negative array indices when array expression is an
array not a pointer. Use pedwarn_c23 for subscripting register
array; diagnose that also for register compound literal.
* c-tree.h (c_mark_addressable): Update prototype.
gcc/testsuite/
* gcc.dg/c23-array-negative-1.c, gcc.dg/c23-register-array-1.c,
gcc.dg/c23-register-array-2.c, gcc.dg/c23-register-array-3.c,
gcc.dg/c23-register-array-4.c, gcc.dg/c2y-array-negative-1.c,
gcc.dg/c2y-register-array-2.c, gcc.dg/c2y-register-array-3.c: New
tests.
|
|
|
|
This patch adds a mechanism to keep track whether nested functions require
non-local context because they reference a variable of an enclosing
scope. This is used for extending the existing -Wreturn-address warning
to also warn for such nested functions. Certain exceptions are implemented
for functions that do not requite a non-local context, because they reference
only static variables, named constants, non-local variables in unevaluated
sizeof, typeof or countof operators, or typedef. The logic is based on the
existing infrastructure for determining use of undeclared static functions.
Finally, To make sure that no trampolines are generated even when not using
optimization, we mark the exempt functions with TREE_NO_TRAMPOLINE.
gcc/c/ChangeLog:
* c-tree.h: Add new macro C_DECL_NONLOCAL_CONTEXT and prototype
for mark_decl_used.
* c-typeck.cc (mark_decl_used): New function.
(function_to_pointer_conversion): Mark exempt functions.
(record_maybe_used_decl): Add `address' parameter.
(build_external_ref): Change to mark_decl_used.
(pop_maybe_used): Call mark_decl_used.
(c_mark_addressable): Ditto.
(c_finish_goto_label): Ditto.
(c_finish_return): Add warning.
* c-decl.cc (declspecs_add_type): Ditto.
(grokdeclarator): Don't set C_DECL_REGISTER on function
declarators.
gcc/testsuite/ChangeLog:
* gcc.dg/Wreturn-nested-1.c: New test.
* gcc.dg/Wreturn-nested-2.c: New test.
* gcc.dg/Wtrampolines-2.c: New test.
* gcc.dg/Wtrampolines-3.c: New test.
|
|
|
|
Set a tentative TLS model in grokvardecl and update TLS mode with the
default TLS access model after a TLS variable has been fully processed
if the default TLS access model is stronger.
gcc/c/
PR c/107419
* c-decl.cc (c_decl_attributes): Update TLS model with the
default TLS access model if the default TLS access model is
stronger.
(grokdeclarator): Set a tentative TLS model which will be
updated by c_decl_attributes later.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
|
|
|
|
I've noticed a lot of diagnostic messages in the C FE aren't marked
for translation.
The reason is some weird coding style which wraps the string
literals into (), especially when they don't fit on a single line.
With that fixed, there were 83 unique similar messages
"both %<something%> and %<something%> in declaration specifiers"
marked for translation, which is very unfriendly to translators,
the patch brings that down to 4 (if it was ok to change order,
it could be even 3):
msgid "both %qs and %qs in declaration specifiers"
msgid "both %qs and %<__int%d%> in declaration specifiers"
msgid "both %qs and %<_Float%d%s%> in declaration specifiers"
msgid "both %<__int%d%> and %qs in declaration specifiers"
2025-09-05 Jakub Jelinek <jakub@redhat.com>
* c-decl.cc (pushtag): Remove ()s around string literal
in call to diagnostic function.
(diagnose_mismatched_decls): Likewise.
(c_check_switch_jump_warnings): Likewise.
(grokdeclarator): Likewise.
(warn_cxx_compat_finish_struct): Likewise.
(build_enumerator): Formatting fix.
(declspecs_add_type): Remove ()s around string literal
in call to diagnostic function, simplify
"both %<something%> and %<something%>" starting format
strings to "both %qs and %qs" with appropriate arguments.
Formatting fixes.
* c-typeck.cc (build_external_ref): Remove ()s around string
literal in call to diagnostic function.
(build_conditional_expr): Likewise.
* c-parser.cc (c_parser_transaction): Use G_() around string
literals. Formatting fix.
(c_parser_transaction_expression): Likewise.
|
|
|
|
As noted in the issue, the C++ front end has deeper problems: it's
supposed to do the name lookup of the variant at the call site but is
instead doing it when parsing the "declare variant" construct, before
registering the decl for the base function. The C++ part of the
patch is a band-aid to catch the case where there is a previous declaration
of the function and it doesn't give an undefined symbol error instead.
Some real solution ought to be included as part of fixing PR118791.
gcc/c/
PR middle-end/118839
* c-parser.cc (c_finish_omp_declare_variant): Error if variant
is the same as base.
gcc/cp/
PR middle-end/118839
* decl.cc (omp_declare_variant_finalize_one): Error if variant
is the same as base.
gcc/fortran/
PR middle-end/118839
* trans-openmp.cc (gfc_trans_omp_declare_variant): Error if variant
is the same as base.
gcc/testsuite/
PR middle-end/118839
* gcc.dg/gomp/declare-variant-3.c: New.
* gfortran.dg/gomp/declare-variant-22.f90: New.
|
|
This patch fixes a number of problems with parser error checking of
"declare variant", especially in the C front end.
The new C testcase unprototyped-variant.c added by this patch used to
ICE when gimplifying the call site, at least in part because the
variant was being recorded even after it was diagnosed as invalid.
There was also a large block of dead code in the C front end that was
supposed to fix up an unprototyped declaration of a variant function
to match the base function declaration, that was never executed because
it was nested in a conditional that could never be true. I've fixed those
problems by rearranging the code and only recording the variant if it
passes the correctness checks. I also tried to add some comments and
re-work some particularly confusing bits of code, so that it's easier to
understand.
The OpenMP specification doesn't say what the behavior of "declare
variant" with the "append_args" clause should be when the base
function is unprototyped. The additional arguments are supposed to be
inserted between the last fixed argument of the base function and any
varargs, but without a prototype, for any given call we have no idea
which arguments are fixed and which are varargs, and therefore no idea
where to insert the additional arguments. This used to trigger some
other diagnostics (which one depending on whether the variant was also
unprototyped), but I thought it was better to just reject this with an
explicit "sorry".
Finally, I also observed that a missing "match" clause was only
rejected if "append_args" or "adjust_args" was present. Per the spec,
"match" has the "required" property, so if it's missing it should be
diagnosed unconditionally. The C++ and Fortran front ends had the same
issue so I fixed this one there too.
gcc/c/ChangeLog
* c-parser.cc (c_finish_omp_declare_variant): Rework diagnostic
code. Do not record variant if there are errors. Make check for
a missing "match" clause unconditional.
gcc/cp/ChangeLog
* parser.cc (cp_finish_omp_declare_variant): Structure diagnostic
code similarly to C front end. Make check for a missing "match"
clause unconditional.
gcc/fortran/ChangeLog
* openmp.cc (gfc_match_omp_declare_variant): Make check for a
missing "match" clause unconditional.
gcc/testsuite/ChangeLog
* c-c++-common/gomp/append-args-1.c: Adjust expected output.
* g++.dg/gomp/adjust-args-1.C: Likewise.
* g++.dg/gomp/adjust-args-3.C: Likewise.
* gcc.dg/gomp/adjust-args-1.c: Likewise:
* gcc.dg/gomp/append-args-1.c: Likewise.
* gcc.dg/gomp/unprototyped-variant.c: New.
* gfortran.dg/gomp/adjust-args-1.f90: Adjust expected output.
* gfortran.dg/gomp/append_args-1.f90: Likewise.
|
|
|
|
The middle-end does not fully understand NULLPTR_TYPE. So it
gets confused a lot of the time when dealing with it.
This adds the folding that is similarly done in the C++ front-end already.
In some cases it should produce slightly better code as there is no
reason to load from a nullptr_t variable as it is always NULL.
The following is handled:
nullptr_v ==/!= nullptr_v -> true/false
(ptr)nullptr_v -> (ptr)0, nullptr_v
f(nullptr_v) -> f ((nullptr, nullptr_v))
The last one is for conversion inside ... .
Bootstrapped and tested on x86_64-linux-gnu.
PR c/121478
gcc/c/ChangeLog:
* c-fold.cc (c_fully_fold_internal): Fold nullptr_t ==/!= nullptr_t.
* c-typeck.cc (convert_arguments): Handle conversion from nullptr_t
for varargs.
(convert_for_assignment): Handle conversions from nullptr_t to
pointer type specially.
gcc/testsuite/ChangeLog:
* gcc.dg/torture/pr121478-1.c: New test.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
|
|
|
|
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>
|
|
|
|
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).
|
|
only when it's read from.
Currently, we generate a call to a .ACCESS_WITH_SIZE for a FAM with counted_by
attribute for every component_ref that corresponds to such an object.
Actually, such .ACCESS_WITH_SIZE calls are useless when they are generated
for a written site or an address taken site.
In this patch, we only generate a call to .ACCESS_WITH_SIZE for a FAM with
counted_by attribute when it's a read.
gcc/c/ChangeLog:
* c-tree.h (handle_counted_by_for_component_ref): New prototype of
build_component_ref and handle_counted_by_for_component_ref.
* c-parser.cc (c_parser_postfix_expression): Call the new prototypes
of build_component_ref and handle_counted_by_for_component_ref,
update comments.
* c-typeck.cc (default_function_array_read_conversion): Likewise.
(convert_lvalue_to_rvalue): Likewise.
(default_conversion): Likewise.
(handle_counted_by_p): Update comments.
(handle_counted_by_for_component_ref): Delete one argument.
(build_component_ref): Delete one argument. Delete the call to
handle_counted_by_for_component_ref completely.
(build_array_ref): Generate call to .ACCESS_WITH_SIZE for array.
gcc/testsuite/ChangeLog:
* gcc.dg/flex-array-counted-by-2.c: Adjust testing case.
|
|
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.
|
|
|
|
[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.
|
|
|
|
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.
|
|
operator [PR108931]
For size expressions in the branches of the conditional operator should
be evaluated only for the active branch. To achieve this, construct
also the size expressions for the composite type as conditional
expressions depending on the condition of the conditional operator.
The change avoids some undefined behavior removed by N3652, but the
new constraints for C2Y are not yet implemented.
PR c/108931
gcc/c/ChangeLog:
* c-typeck.cc (composite_type_cond): Renamed from
composite_type with argument for condition
(composite_type): New function.
(composite_type_internal): Implement new logic.
(build_conditional_expr): Pass condition.
(common_pointer_type): Adapt.
(pointer_diff): Adapt.
(build_binary_op): Adapt.
gcc/testsuite/ChangeLog:
* gcc.dg/vla-tert-1.c: New test.
|
|
Under some error condition we can end up with NULL_TREEs for
the type of bitfields, which can cause an ICE when testing for
type compatibility. Add the missing check.
PR c/121217
gcc/c/ChangeLog:
* c-typeck.cc (tagged_types_tu_compatible_p): Add check.
gcc/testsuite/ChangeLog:
* gcc.dg/pr121217.c: New test.
|
|
This adds support for iterators in 'to' and 'from' clauses in the
'target update' OpenMP directive.
gcc/c/
* c-parser.cc (c_parser_omp_clause_from_to): Parse 'iterator' modifier.
* c-typeck.cc (c_finish_omp_clauses): Finish iterators for to/from
clauses.
gcc/cp/
* parser.cc (cp_parser_omp_clause_from_to): Parse 'iterator' modifier.
* semantics.cc (finish_omp_clauses): Finish iterators for to/from
clauses.
gcc/
* gimplify.cc (remove_unused_omp_iterator_vars): Display unused
variable warning for 'to' and 'from' clauses.
(gimplify_scan_omp_clauses): Add argument for iterator loop sequence.
Gimplify the clause decl and size into the iterator loop if iterators
are used.
(gimplify_omp_workshare): Add argument for iterator loops sequence
in call to gimplify_scan_omp_clauses.
(gimplify_omp_target_update): Call remove_unused_omp_iterator_vars and
build_omp_iterators_loops. Add loop sequence as argument when calling
gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses and building
the Gimple statement.
* tree-pretty-print.cc (dump_omp_clause): Call dump_omp_iterators
for to/from clauses with iterators.
* tree.cc (omp_clause_num_ops): Add extra operand for OMP_CLAUSE_FROM
and OMP_CLAUSE_TO.
* tree.h (OMP_CLAUSE_HAS_ITERATORS): Add check for OMP_CLAUSE_TO and
OMP_CLAUSE_FROM.
(OMP_CLAUSE_ITERATORS): Likewise.
gcc/testsuite/
* c-c++-common/gomp/target-update-iterators-1.c: New.
* c-c++-common/gomp/target-update-iterators-2.c: New.
* c-c++-common/gomp/target-update-iterators-3.c: New.
libgomp/
* target.c (gomp_update): Call gomp_merge_iterator_maps. Free
allocated variables.
* testsuite/libgomp.c-c++-common/target-update-iterators-1.c: New.
* testsuite/libgomp.c-c++-common/target-update-iterators-2.c: New.
* testsuite/libgomp.c-c++-common/target-update-iterators-3.c: New.
|
|
This adds preliminary support for iterators in map clauses within OpenMP
'target' constructs (which includes constructs such as 'target enter data').
Iterators with non-constant loop bounds are not currently supported.
gcc/c/
* c-parser.cc (c_parser_omp_variable_list): Use location of the
map expression as the clause location.
(c_parser_omp_clause_map): Parse 'iterator' modifier.
* c-typeck.cc (c_finish_omp_clauses): Finish iterators. Apply
iterators to generated clauses.
gcc/cp/
* parser.cc (cp_parser_omp_clause_map): Parse 'iterator' modifier.
* semantics.cc (finish_omp_clauses): Finish iterators. Apply
iterators to generated clauses.
gcc/
* gimple-pretty-print.cc (dump_gimple_omp_target): Print expanded
iterator loops.
* gimple.cc (gimple_build_omp_target): Add argument for iterator
loops sequence. Initialize iterator loops field.
* gimple.def (GIMPLE_OMP_TARGET): Set GSS symbol to GSS_OMP_TARGET.
* gimple.h (gomp_target): Set GSS symbol to GSS_OMP_TARGET. Add extra
field for iterator loops.
(gimple_build_omp_target): Add argument for iterator loops sequence.
(gimple_omp_target_iterator_loops): New.
(gimple_omp_target_iterator_loops_ptr): New.
(gimple_omp_target_set_iterator_loops): New.
* gimplify.cc (find_var_decl): New.
(copy_omp_iterator): New.
(remap_omp_iterator_var_1): New.
(remap_omp_iterator_var): New.
(remove_unused_omp_iterator_vars): New.
(struct iterator_loop_info_t): New type.
(iterator_loop_info_map_t): New type.
(build_omp_iterators_loops): New.
(enter_omp_iterator_loop_context_1): New.
(enter_omp_iterator_loop_context): New.
(enter_omp_iterator_loop_context): New.
(exit_omp_iterator_loop_context): New.
(gimplify_adjust_omp_clauses): Add argument for iterator loop
sequence. Gimplify the clause decl and size into the iterator
loop if iterators are used.
(gimplify_omp_workshare): Call remove_unused_omp_iterator_vars and
build_omp_iterators_loops for OpenMP target expressions. Add
loop sequence as argument when calling gimplify_adjust_omp_clauses
and building the Gimple statement.
* gimplify.h (enter_omp_iterator_loop_context): New prototype.
(exit_omp_iterator_loop_context): New prototype.
* gsstruct.def (GSS_OMP_TARGET): New.
* omp-low.cc (lower_omp_map_iterator_expr): New.
(lower_omp_map_iterator_size): New.
(finish_omp_map_iterators): New.
(lower_omp_target): Add sorry if iterators used with deep mapping.
Call lower_omp_map_iterator_expr before assigning to sender ref.
Call lower_omp_map_iterator_size before setting the size. Insert
iterator loop sequence before the statements for the target clause.
* tree-nested.cc (convert_nonlocal_reference_stmt): Walk the iterator
loop sequence of OpenMP target statements.
(convert_local_reference_stmt): Likewise.
(convert_tramp_reference_stmt): Likewise.
* tree-pretty-print.cc (dump_omp_iterators): Dump extra iterator
information if present.
(dump_omp_clause): Call dump_omp_iterators for iterators in map
clauses.
* tree.cc (omp_clause_num_ops): Add operand for OMP_CLAUSE_MAP.
(walk_tree_1): Do not walk last operand of OMP_CLAUSE_MAP.
* tree.h (OMP_CLAUSE_HAS_ITERATORS): New.
(OMP_CLAUSE_ITERATORS): New.
gcc/testsuite/
* c-c++-common/gomp/map-6.c (foo): Amend expected error message.
* c-c++-common/gomp/target-map-iterators-1.c: New.
* c-c++-common/gomp/target-map-iterators-2.c: New.
* c-c++-common/gomp/target-map-iterators-3.c: New.
* c-c++-common/gomp/target-map-iterators-4.c: New.
libgomp/
* target.c (kind_to_name): New.
(gomp_merge_iterator_maps): New.
(gomp_map_vars_internal): Call gomp_merge_iterator_maps. Copy
address of only the first iteration to target vars. Free allocated
variables.
* testsuite/libgomp.c-c++-common/target-map-iterators-1.c: New.
* testsuite/libgomp.c-c++-common/target-map-iterators-2.c: New.
* testsuite/libgomp.c-c++-common/target-map-iterators-3.c: New.
Co-authored-by: Andrew Stubbs <ams@baylibre.com>
|
|
|
|
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.
|
|
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
|
|
This implements error handling for hard register constraints including
potential conflicts with register asm operands.
In contrast to register asm operands, hard register constraints allow
more than just one register per operand. Even more than just one
register per alternative. For example, a valid constraint for an
operand is "{r0}{r1}m,{r2}". However, this also means that we have to
make sure that each register is used at most once in each alternative
over all outputs and likewise over all inputs. For asm statements this
is done by this patch during gimplification. For hard register
constraints used in machine description, error handling is still a todo
and I haven't investigated this so far and consider this rather a low
priority.
gcc/ada/ChangeLog:
* gcc-interface/trans.cc (gnat_to_gnu): Pass null pointer to
parse_{input,output}_constraint().
gcc/analyzer/ChangeLog:
* region-model-asm.cc (region_model::on_asm_stmt): Pass null
pointer to parse_{input,output}_constraint().
gcc/c/ChangeLog:
* c-typeck.cc (build_asm_expr): Pass null pointer to
parse_{input,output}_constraint().
gcc/ChangeLog:
* cfgexpand.cc (n_occurrences): Move this ...
(check_operand_nalternatives): and this ...
(expand_asm_stmt): and the call to gimplify.cc.
* config/s390/s390.cc (s390_md_asm_adjust): Pass null pointer to
parse_{input,output}_constraint().
* gimple-walk.cc (walk_gimple_asm): Pass null pointer to
parse_{input,output}_constraint().
(walk_stmt_load_store_addr_ops): Ditto.
* gimplify-me.cc (gimple_regimplify_operands): Ditto.
* gimplify.cc (num_occurrences): Moved from cfgexpand.cc.
(num_alternatives): Ditto.
(gimplify_asm_expr): Deal with hard register constraints.
* stmt.cc (eliminable_regno_p): New helper.
(hardreg_ok_p): Perform a similar check as done in
make_decl_rtl().
(parse_output_constraint): Add parameter for gimplify_reg_info
and validate hard register constrained operands.
(parse_input_constraint): Ditto.
* stmt.h (class gimplify_reg_info): Forward declaration.
(parse_output_constraint): Add parameter.
(parse_input_constraint): Ditto.
* tree-ssa-operands.cc
(operands_scanner::get_asm_stmt_operands): Pass null pointer
to parse_{input,output}_constraint().
* tree-ssa-structalias.cc (find_func_aliases): Pass null pointer
to parse_{input,output}_constraint().
* varasm.cc (assemble_asm): Pass null pointer to
parse_{input,output}_constraint().
* gimplify_reg_info.h: New file.
gcc/cp/ChangeLog:
* semantics.cc (finish_asm_stmt): Pass null pointer to
parse_{input,output}_constraint().
gcc/d/ChangeLog:
* toir.cc: Pass null pointer to
parse_{input,output}_constraint().
gcc/testsuite/ChangeLog:
* gcc.dg/pr87600-2.c: Split test into two files since errors for
functions test{0,1} are thrown during expand, and for
test{2,3} during gimplification.
* lib/scanasm.exp: On s390, skip lines beginning with #.
* gcc.dg/asm-hard-reg-error-1.c: New test.
* gcc.dg/asm-hard-reg-error-2.c: New test.
* gcc.dg/asm-hard-reg-error-3.c: New test.
* gcc.dg/asm-hard-reg-error-4.c: New test.
* gcc.dg/asm-hard-reg-error-5.c: New test.
* gcc.dg/pr87600-3.c: New test.
* gcc.target/aarch64/asm-hard-reg-2.c: New test.
* gcc.target/s390/asm-hard-reg-7.c: New test.
|
|
|
|
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.
|
|
|
|
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.
|
|
|
|
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.
|
|
.ACCESS_WITH_SIZE (PR121000)
The size of the element of the FAM _cannot_ reliably depends on the original
TYPE of the FAM that we passed as the 6th parameter to the .ACCESS_WITH_SIZE:
TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (gimple_call_arg (call, 5))))
when the element of the FAM has a variable length type. Since the variable
that represents TYPE_SIZE_UNIT has no explicit usage in the original IL,
compiler transformations (such as DSE) that are applied before object_size
phase might eliminate the whole definition to the variable that represents
the TYPE_SIZE_UNIT of the element of the FAM.
In order to resolve this issue, instead of passing the original TYPE of the
FAM as the 6th argument to .ACCESS_WITH_SIZE, we should explicitly pass the
original TYPE_SIZE_UNIT of the element TYPE of the FAM as the 6th argument
to the call to .ACCESS_WITH_SIZE.
PR middle-end/121000
gcc/c/ChangeLog:
* c-typeck.cc (build_access_with_size_for_counted_by): Update comments.
Pass TYPE_SIZE_UNIT of the element as the 6th argument.
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.
Get the element_size from the 6th argument directly.
gcc/testsuite/ChangeLog:
* gcc.dg/flex-array-counted-by-pr121000.c: New test.
|
|
|
|
Convert a pointer reference with counted_by attribute to .ACCESS_WITH_SIZE." due to PR120929.
This reverts commit 687727375769dd41971bad369f3553f1163b3e7a.
|