Re: [PATCH] c++: non-static memfn call dependence cleanup

2023-09-26 Thread Krishna Narayanan
On Tue, Sep 26, 2023, 19:52 Patrick Palka  wrote:

> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?
>
> -- >8 --
>
> In cp_parser_postfix_expression, we essentially repeat the
> type-dependent and COMPONENT_REF callee cases of finish_call_expr.
> This patch deduplicates this logic.
>
> gcc/cp/ChangeLog:
>
> * parser.cc (cp_parser_postfix_expression): Consolidate three
> calls to finish_call_expr, one to build_new_method_call and
> one to build_min_nt_call_vec into one call to finish_call_expr.
> * pt.cc (type_dependent_expression_p): Use t_d_object_e_p
> instead of t_d_e_p for COMPONENT_REF and OFFSET_REF.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/template/crash127.C: Expect additional error due to
> being able to check the member access expression ahead of time.
> Strengthen the test by not instantiating the class template.
> ---
>  gcc/cp/parser.cc | 60 ++--
>  gcc/cp/pt.cc |  2 +-
>  gcc/testsuite/g++.dg/template/crash127.C |  3 +-
>  3 files changed, 16 insertions(+), 49 deletions(-)
>
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index f3abae716fe..78082ee7284 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -8047,54 +8047,12 @@ cp_parser_postfix_expression (cp_parser *parser,
> bool address_p, bool cast_p,
> close_paren_loc);
> iloc_sentinel ils (combined_loc);
>
> -   if (TREE_CODE (postfix_expression) == COMPONENT_REF)
> - {
> -   tree instance = TREE_OPERAND (postfix_expression, 0);
> -   tree fn = TREE_OPERAND (postfix_expression, 1);
> -
> -   if (processing_template_decl
> -   && (type_dependent_object_expression_p (instance)
> -   || (!BASELINK_P (fn)
> -   && TREE_CODE (fn) != FIELD_DECL)
> -   || type_dependent_expression_p (fn)
> -   || any_type_dependent_arguments_p (args)))
> - {
> -   maybe_generic_this_capture (instance, fn);
> -   postfix_expression
> - = build_min_nt_call_vec (postfix_expression, args);
> - }
> -   else if (BASELINK_P (fn))
> - {
> - postfix_expression
> -   = (build_new_method_call
> -  (instance, fn, &args, NULL_TREE,
> -   (idk == CP_ID_KIND_QUALIFIED
> -? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
> -: LOOKUP_NORMAL),
> -   /*fn_p=*/NULL,
> -   complain));
> - }
> -   else
> - postfix_expression
> -   = finish_call_expr (postfix_expression, &args,
> -   /*disallow_virtual=*/false,
> -   /*koenig_p=*/false,
> -   complain);
> - }
> -   else if (TREE_CODE (postfix_expression) == OFFSET_REF
> -|| TREE_CODE (postfix_expression) == MEMBER_REF
> -|| TREE_CODE (postfix_expression) == DOTSTAR_EXPR)
> +   if (TREE_CODE (postfix_expression) == OFFSET_REF
> +   || TREE_CODE (postfix_expression) == MEMBER_REF
> +   || TREE_CODE (postfix_expression) == DOTSTAR_EXPR)
>   postfix_expression = (build_offset_ref_call_from_tree
> (postfix_expression, &args,
>  complain));
> -   else if (idk == CP_ID_KIND_QUALIFIED)
> - /* A call to a static class member, or a namespace-scope
> -function.  */
> - postfix_expression
> -   = finish_call_expr (postfix_expression, &args,
> -   /*disallow_virtual=*/true,
> -   koenig_p,
> -   complain);
> else
>   /* All other function calls.  */
>   {
> @@ -8107,12 +8065,22 @@ cp_parser_postfix_expression (cp_parser *parser,
> bool address_p, bool cast_p,
>"not permitted in intervening code");
> parser->omp_for_parse_state->fail = true;
>   }
> +   bool disallow_virtual = (idk == CP_ID_KIND_QUALIFIED);
> postfix_expression
>   = finish_call_expr (postfix_expression, &args,
> - /*disallow_virtual=*/false,
> + disallow_virtual,
>   koenig_p,
>   complain);
> +
> +   if (type_dependent_expression_p (postfix_expre

[PATCH] c : Changed warning message for -Wstrict-prototypes [PR92209]

2022-03-11 Thread Krishna Narayanan via Gcc-patches
Hello,
The following is a patch for the PR92209,which gives a warning when
the function prototype does not specify its argument type.In this
patch there has been a change in the warning message displayed for
-Wstrict-prototypes to specify its argument types.I have also added
the testcase for it.
Regtested on x86_64,OK for commit? Please do review it.

2022-03-11  Krishna Narayanan  

PR c/92209
gcc/c/
*c-decl.cc (start_function): Fixed the warning message for -Wstrict-prototypes.

gcc/testsuite/Changelog:
*gcc.dg/pr92209.c: New test
*gcc.dg/pr20368-1.c: Updated warning message

---
gcc/c/c-decl.cc | 4 ++--
gcc/testsuite/gcc.dg/pr20368-1.c | 2 +-
gcc/testsuite/gcc.dg/pr92209.c | 6 ++
3 files changed, 9 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/pr92209.c

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index c701f07be..1983ffb23 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -7858,7 +7858,7 @@ grokparms (struct c_arg_info *arg_info, bool funcdef_flag)
if (arg_types == NULL_TREE && !funcdef_flag
&& !in_system_header_at (input_location))
warning (OPT_Wstrict_prototypes,
- "function declaration isn%'t a prototype");
+ "a function prototype must specify the argument types");

if (arg_types == error_mark_node)
/* Don't set TYPE_ARG_TYPES in this case. */
@@ -9625,7 +9625,7 @@ start_function (struct c_declspecs *declspecs,
struct c_declarator *declarator,
&& !prototype_p (TREE_TYPE (decl1))
&& C_DECL_ISNT_PROTOTYPE (old_decl))
warning_at (loc, OPT_Wstrict_prototypes,
- "function declaration isn%'t a prototype");
+ "a function prototype must specify the argument types");
/* Optionally warn of any global def with no previous prototype. */
else if (warn_missing_prototypes
&& old_decl != error_mark_node
diff --git a/gcc/testsuite/gcc.dg/pr20368-1.c b/gcc/testsuite/gcc.dg/pr20368-1.c
index 4140397c1..4b4914aa6 100644
--- a/gcc/testsuite/gcc.dg/pr20368-1.c
+++ b/gcc/testsuite/gcc.dg/pr20368-1.c
@@ -6,7 +6,7 @@
extern __typeof (f) g; /* { dg-error "'f' undeclared here \\(not in a
function\\)" } */

int
-f (x) /* { dg-warning "function declaration isn't a prototype" } */
+f (x) /* { dg-warning "a function prototype must specify the argument
types" } */
float x;
{
}
diff --git a/gcc/testsuite/gcc.dg/pr92209.c b/gcc/testsuite/gcc.dg/pr92209.c
new file mode 100644
index 0..3fae57b49
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr92209.c
@@ -0,0 +1,6 @@
+/*pr92209*/
+/* { dg-do compile } */
+/* { dg-options "-Wstrict-prototypes" } */
+static int func_1(); /* { dg-warning " a function prototype must
specify the argument types" } */
+int func_1(int a)
+ { return a; }
\ No newline at end of file
--
2.25.1


[PATCH] c: Added testcase for already fixed PR [PR93432]

2022-02-23 Thread Krishna Narayanan via Gcc-patches
Hello,

The following patch is a testcase for PR93432,which deals with the
warning for uninitialized variables.The testcase is for the bug
already fixed.

Regtested on x86_64, OK for commit ? Please do review it.

2022-02-23 Krishna Narayanan 

PR c/93432
gcc/testsuite/Changelog:
*gcc.dg/pr93432.c: New test

---
 gcc/testsuite/pr93432.c | 14 ++
 1 file changed, 14 insertions(+)
 create mode 100644 gcc/testsuite/pr93432.c

diff --git a/gcc/testsuite/pr93432.c b/gcc/testsuite/pr93432.c
new file mode 100644
index 0..cd7199a56
--- /dev/null
+++ b/gcc/testsuite/pr93432.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wuninitialized -Wmaybe-uninitialized" } */
+ int test(int y) {
+int z; /* { dg-message "note: 'z' was declared here"  } */
+int x;
+int a; /* { dg-warning "'a' may be used uninitialized" } */
+for (x = 0; x < 10; x = x + 1, y = y + 1,a = a + 1)
+{
+if (y < 10) {
+z = z + 1 + a; /* { dg-warning "'z' may be used uninitialized" } */
+}
+}
+return z;
+}
-- 
2.25.1