On Tue, Mar 15, 2022 at 01:32:46PM +0100, Jakub Jelinek via Gcc-patches wrote:
> Another one is whether we shouldn't punt for FIELD_DECLs that don't have
> nicely printable name of its containing scope, something like:
>               if (tree scope = get_containing_scope (field))
>                 if (TYPE_P (scope) && TYPE_NAME (scope) == NULL_TREE)
>                   break;
>               return cop;
> or so.

This seems to work fine, ok if it passes bootstrap/regtest?
No need to do it for C because it doesn't print the contexts (has no syntax
for that even).

2022-03-16  Jakub Jelinek  <ja...@redhat.com>

        PR c++/101515
        * c-pretty-print.cc (c_fold_indirect_ref_for_warn): For C++ don't
        return COMPONENT_REFs with FIELD_DECLs whose containing scope can't
        be printed.

        * g++.dg/warn/pr101515.C: New test.

--- gcc/c-family/c-pretty-print.cc.jj   2022-02-14 13:14:39.037128630 +0100
+++ gcc/c-family/c-pretty-print.cc      2022-03-16 11:16:54.957658064 +0100
@@ -1889,6 +1889,12 @@ c_fold_indirect_ref_for_warn (location_t
              = wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (field)));
            if (upos <= off && off < upos + el_sz)
              {
+               /* The C++ pretty printers print scope of the FIELD_DECLs,
+                  so punt if it is something that can't be printed.  */
+               if (c_dialect_cxx ())
+                 if (tree scope = get_containing_scope (field))
+                   if (TYPE_P (scope) && TYPE_NAME (scope) == NULL_TREE)
+                     break;
                tree cop = build3_loc (loc, COMPONENT_REF, TREE_TYPE (field),
                                       op, field, NULL_TREE);
                off = off - upos;
--- gcc/testsuite/g++.dg/warn/pr101515.C.jj     2022-03-16 11:19:09.004806778 
+0100
+++ gcc/testsuite/g++.dg/warn/pr101515.C        2022-03-16 11:24:35.136302673 
+0100
@@ -0,0 +1,18 @@
+// PR c++/101515
+// { dg-do compile }
+// { dg-options "-O1 -Wuninitialized" }
+
+struct S { int j; };
+struct T : public S { virtual void h () {} };
+struct U { void (*ptr) (); };
+typedef void (S::*sp) ();
+
+int
+main ()
+{
+  T t;
+  sp x;
+  U *xp = (U *) &x;
+  if (xp->ptr != ((void (*) ()) (sizeof (void *))))    // { dg-warning "is 
used uninitialized" }
+    return 1;
+}


        Jakub

Reply via email to