public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: David Malcolm <dmalcolm@redhat.com>
Cc: Jeff Law <law@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] v4: C++: more location wrapper nodes (PR c++/43064, PR c++/43486)
Date: Thu, 13 Dec 2018 20:38:00 -0000	[thread overview]
Message-ID: <a33a8cfc-c930-5365-0c50-c1ad60267f48@redhat.com> (raw)
In-Reply-To: <1544731967-41493-1-git-send-email-dmalcolm@redhat.com>

On 12/13/18 3:12 PM, David Malcolm wrote:
> On Wed, 2018-12-12 at 15:37 -0500, Jason Merrill wrote:
>> On 12/7/18 3:13 PM, David Malcolm wrote:
>>> On Tue, 2018-12-04 at 18:31 -0500, Jason Merrill wrote:
>>>> On 12/3/18 5:10 PM, Jeff Law wrote:
>>>>> On 11/19/18 9:51 AM, David Malcolm wrote:
>>>
>>> [...]
>>>>> @@ -1058,6 +1058,9 @@ grokbitfield (const cp_declarator
>>>>> *declarator,
>>>>>          return NULL_TREE;
>>>>>        }
>>>>>    
>>>>> +  if (width)
>>>>> +    STRIP_ANY_LOCATION_WRAPPER (width);
>>>>
>>>> Why is this needed?  We should already be reducing width to an
>>>> unwrapped
>>>> constant value somewhere along the line.
>>>
>>> "width" is coming from cp_parser_member_declaration, from:
>>>
>>> 	      /* Get the width of the bitfield.  */
>>> 	      width = cp_parser_constant_expression (parser, false,
>>> NULL,
>>> 						     cxx_dialect >=
>>> cxx11);
>>>
>>> and currently nothing is unwrapping the value.  We presumably need
>>> to
>>> unwrap (or fold?) it before it is stashed in
>>>     DECL_BIT_FIELD_REPRESENTATIVE (value).
>>>
>>> Without stripping (or folding) here, we e.g. lose a warning and get
>>> this:
>>>     FAIL: g++.dg/abi/empty22.C  -std=gnu++98  (test for warnings,
>>> line 15)
>>
>> Why does that happen?  check_bitfield_decl ought to handle the
>> location
>> wrapper fine.  That's where it gets folded.
> 
> The unstripped location wrapper defeats this check for zero in
> check_field_decls within cp/class.c:
> 
> 3555	      if (DECL_C_BIT_FIELD (x)
> 3556		  && integer_zerop (DECL_BIT_FIELD_REPRESENTATIVE (x)))
> 3556		/* We don't treat zero-width bitfields as making a class
> 3557		   non-empty.  */

Aha.  I wonder if integer_zerop should look through location wrappers? 
Or alternately, abort if it gets one?

On a tangent, perhaps we also want a macro like TREE_CODE that looks 
through wrappers.  TREE_CODE_WRAPPED?  _NO_WRAP?  Other name ideas?

> 3558		;
> 3559	      else
> 
> leading it to erroneously use the "else" clause, which thus erroneously
> clears CLASSTYPE_EMPTY_P, leading to the loss of:
> 
> g++.dg/abi/empty22.C:15:6: warning: empty class 'dummy' parameter passing
>    ABI changes in -fabi-version=12 (GCC 8) [-Wabi]
>     15 |   fun(d, f); // { dg-warning "empty" }
>        |   ~~~^~~~~~
> 
> check_bitfield_decl is called *after* that check, so the folding there
> doesn't help.
> 
>>>>> @@ -656,6 +656,9 @@ add_capture (tree lambda, tree id, tree
>>>>> orig_init, bool by_reference_p,
>>>>>          listmem = make_pack_expansion (member);
>>>>>          initializer = orig_init;
>>>>>        }
>>>>> +
>>>>> +  STRIP_ANY_LOCATION_WRAPPER (initializer);
>>>>
>>>> Why is this needed?  What cares about the tree codes of the
>>>> capture
>>>> initializer?
>>>
>>> This is used to populate LAMBDA_EXPR_CAPTURE_LIST.  Without
>>> stripping,
>>> we end up with wrapped VAR_DECLs, rather than the VAR_DECLs
>>> themselves,
>>
>> Sure, that sounds fine.
>>
>>> and this confuses things later on, for example leading to:
>>>
>>>    PASS -> FAIL : g++.dg/cpp0x/lambda/lambda-type.C  -std=c++14
>>> (test for excess errors)
>>>    PASS -> FAIL : g++.dg/cpp0x/lambda/lambda-type.C  -std=c++17
>>> (test for excess errors)
>>
>> Confuses how?
> 
> Without stripping, we get extra errors for decltype() on identifiers in
> the capture-list, e.g.:
> 
>    [i] {
>      same_type<decltype(i),int>();
>      same_type<decltype((i)),int const&>();
>    };
> 
> cpp0x/lambda/lambda-type.C: In lambda function:
> cpp0x/lambda/lambda-type.C:48:27: error: 'i' is not captured
>     48 |     same_type<decltype((i)),int const&>();
>        |                           ^
> cpp0x/lambda/lambda-type.C:48:39: error: template argument 1 is invalid
>     48 |     same_type<decltype((i)),int const&>();
>        |                                       ^
> 
> These occur because, in capture_decltype, when searching for the decl for
> "i" here:
> 
>    tree cap = value_member (decl, LAMBDA_EXPR_CAPTURE_LIST (lam));
> 
> the LAMBDA_EXPR_CAPTURE_LIST contains a wrapper around "i" rather than "i"
> itself, and so "i" isn't found by value_member; "cap" thus becomes NULL_TREE,
> and thus the error.

Ah.  Just above that I notice,

   /* FIXME do lookup instead of list walk? */

We could make that change, i.e.

tree cap = lookup_name_real (DECL_NAME (decl), /*type*/0, /*nonclass*/1,
                              /*block_p=*/true, /*ns*/0, LOOKUP_HIDDEN);
...
if (cap && is_capture_proxy (cap))

Jason

  reply	other threads:[~2018-12-13 20:38 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-05 19:44 [PATCH 1/2] " David Malcolm
2018-11-05 19:44 ` [PATCH 2/2] C++: improvements to binary operator diagnostics (PR c++/87504) David Malcolm
2018-11-19 16:51 ` [PING] Re: [PATCH 1/2] C++: more location wrapper nodes (PR c++/43064, PR c++/43486) David Malcolm
2018-12-03 22:10   ` Jeff Law
2018-12-04 15:20     ` David Malcolm
2018-12-04 21:48     ` [PATCH 1/2] v2: " David Malcolm
2018-12-04 21:48       ` [PATCH 2/2] v2: C++: improvements to binary operator diagnostics (PR c++/87504) David Malcolm
2018-12-11 19:52         ` PING " David Malcolm
2018-12-12 20:43         ` Jason Merrill
2018-12-19 23:28           ` Aaron Sawdey
2018-12-20  2:13             ` [PATCH] -Wtautological-compare: fix comparison of macro expansions David Malcolm
2018-12-20 14:29               ` David Malcolm
2018-12-20 23:35                 ` Aaron Sawdey
2018-12-04 23:31     ` [PING] Re: [PATCH 1/2] C++: more location wrapper nodes (PR c++/43064, PR c++/43486) Jason Merrill
2018-12-07 19:25       ` [PATCH 1/2] v3: " David Malcolm
2018-12-12 20:37         ` Jason Merrill
2018-12-13 19:24           ` [PATCH] v4: " David Malcolm
2018-12-13 20:38             ` Jason Merrill [this message]
2018-12-14 23:29               ` [PATCH] v5: " David Malcolm
2018-12-17 19:33                 ` Jason Merrill
2018-12-17 23:30                   ` David Malcolm
2018-12-18 20:23                     ` Jason Merrill
2018-12-18 20:34                     ` [PATCH] v6: " David Malcolm
2018-12-18 20:40                       ` Jason Merrill
2018-12-19 15:35                         ` David Malcolm
2018-12-19 19:01 ` [PATCH 1/2] " Thomas Schwinge
2018-12-20  2:29   ` David Malcolm
2020-03-26  5:02   ` [PATCH, OpenACC] Bug fix for processing OpenACC data clauses in C++ Sandra Loosemore
     [not found]     ` <4a68ec90-456a-cf49-036e-471ba275706c@codesourcery.com>
2020-03-26 14:27       ` C++ 'NON_LVALUE_EXPR' in OMP array section handling (was: [PATCH, OpenACC] Bug fix for processing OpenACC data clauses in C++) Thomas Schwinge
2020-03-26 15:09         ` C++ 'NON_LVALUE_EXPR' in OMP array section handling Sandra Loosemore
2020-03-26 20:53           ` Thomas Schwinge
2020-05-25 10:56             ` [WIP] Fold 'NON_LVALUE_EXPR' some more (was: C++ 'NON_LVALUE_EXPR' in OMP array section handling) Thomas Schwinge
2020-11-26  9:36               ` Don't create location wrapper nodes within OpenACC clauses (was: [WIP] Fold 'NON_LVALUE_EXPR' some more (was: C++ 'NON_LVALUE_EXPR' in OMP array section handling)) Thomas Schwinge
2020-11-26 10:02                 ` Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a33a8cfc-c930-5365-0c50-c1ad60267f48@redhat.com \
    --to=jason@redhat.com \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).