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: Nathan Sidwell <nathan@acm.org>, Jakub Jelinek <jakub@redhat.com>,
		Richard Biener <richard.guenther@gmail.com>,
	gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] RFC: Preserving locations for variable-uses and constants (PR 43486)
Date: Thu, 02 Nov 2017 14:46:00 -0000	[thread overview]
Message-ID: <CADzB+2kfB26fTGXk2AVWuN1mv641OrcEBze+Lq-KexXHeS=Y9A@mail.gmail.com> (raw)
In-Reply-To: <1509484153.15469.45.camel@redhat.com>

On Tue, Oct 31, 2017 at 5:09 PM, David Malcolm <dmalcolm@redhat.com> wrote:
> On Tue, 2017-10-24 at 09:53 -0400, Jason Merrill wrote:
>> On Fri, Oct 20, 2017 at 5:53 PM, David Malcolm <dmalcolm@redhat.com>
>> wrote:
>> > Design questions:
>> >
>> > * The patch introduces a new kind of tree node, currently called
>> >   DECL_WRAPPER_EXPR (although it's used for wrapping constants as
>> > well
>> >   as decls).  Should wrappers be a new kind of tree node, or should
>> > they
>> >   reuse an existing TREE_CODE? (e.g. NOP_EXPR, CONVERT_EXPR, etc).
>> >     * NOP_EXPR: seems to be for use as an rvalue
>> >     * CONVERT_EXPR: for type conversions
>> >     * NON_LVALUE_EXPR: "Value is same as argument, but guaranteed
>> > not an
>> >       lvalue"
>> >       * but we *do* want to support lvalues here
>>
>> I think using NON_LVALUE_EXPR for constants would be appropriate.
>>
>> >     * VIEW_CONVERT_EXPR: viewing one thing as of a different type
>> >       * can it support lvalues?
>>
>> Yes, the purpose of VIEW_CONVERT_EXPR is to support lvalues, it seems
>> like the right choice.
>>
>> Jason
>
> Thanks.  I've been working on a new version of the patch using those
> tree codes, but have run into an issue.
>
> In g++.dg/conversion/reinterpret1.C:
>
>   // PR c++/15076
>
>   struct Y { Y(int &); };
>
>   int v;
>   Y y1(reinterpret_cast<int>(v));  // { dg-error "" }
>
> With trunk, this successfully generates an error:
>
>   reinterpret1.C:6:6: error: cannot bind non-const lvalue reference of type ‘int&’ to an rvalue of type ‘int’
>    Y y1(reinterpret_cast<int>(v));  // { dg-error "" }
>         ^~~~~~~~~~~~~~~~~~~~~~~~
>   reinterpret1.C:3:12: note:   initializing argument 1 of ‘Y::Y(int&)’
>    struct Y { Y(int &); };
>               ^
>
> where internally there's a NON_LVALUE_EXPR around a VAR_DECL, where
> both have the same type:
>
> (gdb) call debug_tree (expr)
>  <non_lvalue_expr 0x7ffff145f6e0
>     type <integer_type 0x7ffff132e5e8 int public type_6 SI
>         size <integer_cst 0x7ffff1331120 constant 32>
>         unit-size <integer_cst 0x7ffff1331138 constant 4>
>         align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7ffff132e5e8 precision:32 min <integer_cst 0x7ffff13310d8 -2147483648> max <integer_cst 0x7ffff13310f0 2147483647>
>         pointer_to_this <pointer_type 0x7ffff1336a80> reference_to_this <reference_type 0x7ffff144ca80>>
>
>     arg:0 <var_decl 0x7ffff7ffbd80 v type <integer_type 0x7ffff132e5e8 int>
>         used public static tree_1 read SI /home/david/coding-3/gcc-git-expr-vs-decl/src/gcc/testsuite/g++.dg/conversion/reinterpret1.C:5:5 size <integer_cst 0x7ffff1331120 32> unit-size <integer_cst 0x7ffff1331138 4>
>         align:32 warn_if_not_align:0 context <translation_unit_decl 0x7ffff131e168 /home/david/coding-3/gcc-git-expr-vs-decl/src/gcc/testsuite/g++.dg/conversion/reinterpret1.C>
>         chain <type_decl 0x7ffff141a720 Y type <record_type 0x7ffff144c150 Y>
>             public decl_2 VOID /home/david/coding-3/gcc-git-expr-vs-decl/src/gcc/testsuite/g++.dg/conversion/reinterpret1.C:3:8
>             align:8 warn_if_not_align:0 context <translation_unit_decl 0x7ffff131e168 /home/david/coding-3/gcc-git-expr-vs-decl/src/gcc/testsuite/g++.dg/conversion/reinterpret1.C> chain <function_decl 0x7ffff144f800 __cxa_call_unexpected>>>
>     /home/david/coding-3/gcc-git-expr-vs-decl/src/gcc/testsuite/g++.dg/conversion/reinterpret1.C:6:6 start: /home/david/coding-3/gcc-git-expr-vs-decl/src/gcc/testsuite/g++.dg/conversion/reinterpret1.C:6:6 finish: /home/david/coding-3/gcc-git-expr-vs-decl/src/gcc/testsuite/g++.dg/conversion/reinterpret1.C:6:29>
>
> The problem is that this reinterpret cast "looks" just like one of my
> location wrappers.

Your code shouldn't strip a NON_LVALUE_EXPR around a VAR_DECL.

> I see a similar issue with constants, where with:
>
>   struct Y { Y(int &); };
>   Y y1(reinterpret_cast<int>(42));
>
> trunk generates an error like the above, but my code handles the
>   NON_LVALUE_EXPR<int>(INTEGER_CST<int>(42))
> as if it were a location wrapper around the INTEGER_CST, and thus
> doesn't emit the error.

Why doesn't it emit the error?  We should get the same error whether
or not we strip the wrapper.

Jason

  reply	other threads:[~2017-11-02 14:46 UTC|newest]

Thread overview: 111+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-20 22:38 David Malcolm
2017-10-24 14:05 ` Jason Merrill
2017-10-31 21:28   ` David Malcolm
2017-11-02 14:46     ` Jason Merrill [this message]
2017-11-10 21:43       ` [PATCH v2: 00/14] " David Malcolm
2017-11-10 21:43         ` [PATCH 01/14] C++: preserve locations within build_address David Malcolm
2017-12-11 23:25           ` Jason Merrill
2017-11-10 21:43         ` [PATCH 03/14] C++: add location_t wrapper nodes during parsing (minimal impl) David Malcolm
2017-12-12  2:10           ` Jason Merrill
2017-12-14 19:25             ` David Malcolm
2017-12-15 15:02               ` Jason Merrill
2017-12-15 16:35                 ` David Malcolm
2017-12-15 18:59                   ` Jason Merrill
2017-12-15 22:49                     ` David Malcolm
2017-12-29 17:03                     ` [v2 of PATCH " David Malcolm
2018-01-05 20:29                       ` Jason Merrill
2018-01-05 22:20                         ` David Malcolm
2018-01-08 17:10                           ` Location wrappers vs decls that change type (was Re: [v2 of PATCH 03/14] C++: add location_t wrapper nodes during parsing (minimal impl)) David Malcolm
2018-01-08 17:14                             ` Nathan Sidwell
2018-01-08 17:18                               ` Jakub Jelinek
2018-01-08 17:28                                 ` Nathan Sidwell
2018-01-08 18:08                                   ` David Malcolm
2018-01-08 18:23                                     ` Jakub Jelinek
2018-01-09 11:34                                       ` [PATCH v2.4 of 02/14] Support for adding and stripping location_t wrapper nodes David Malcolm
2018-01-09 14:59                                         ` Jason Merrill
2018-01-08 21:48                           ` [v2 of PATCH 03/14] C++: add location_t wrapper nodes during parsing (minimal impl) Jason Merrill
2018-01-08 21:03                         ` David Malcolm
2018-01-08 21:59                           ` Jason Merrill
2018-01-08 22:27                             ` Jason Merrill
2018-01-09 12:03                               ` [PATCH v3 of " David Malcolm
2018-01-09 14:39                                 ` Jason Merrill
2018-01-09 14:39                                   ` Jakub Jelinek
2018-01-09 18:32                                     ` [PATCH v4 " David Malcolm
2018-01-09 19:45                                       ` Jason Merrill
2017-11-10 21:43         ` [PATCH 05/14] tree.c: strip location wrappers from integer_zerop etc David Malcolm
2017-12-11 23:36           ` Jason Merrill
2017-12-16 13:09             ` [PATCH] C++: handle locations wrappers when calling warn_for_memset David Malcolm
2017-12-16 20:01               ` Martin Sebor
2017-12-19 20:02                 ` Jason Merrill
2017-12-20 19:23                   ` [v3 of 05/14] " David Malcolm
2017-12-21  4:58                     ` Jason Merrill
2017-11-10 21:43         ` [PATCH 06/14] Fix Wsizeof-pointer-memaccess*.c David Malcolm
2017-12-11 23:37           ` Jason Merrill
2017-12-18  2:04             ` [v2 of PATCH 06/14] Strip location wrappers in operand_equal_p David Malcolm
2017-12-18  8:00               ` Jakub Jelinek
2017-12-19 20:13               ` Jason Merrill
2017-12-19 20:49                 ` Jakub Jelinek
2017-12-19 21:59                   ` Jason Merrill
2017-12-19 22:03                     ` Jakub Jelinek
2017-12-20  0:41                       ` [PATCH] Eliminate location wrappers in tree_nop_conversion/STRIP_NOPS David Malcolm
2017-12-20  4:27                         ` Jeff Law
2017-11-10 21:43         ` [PATCH 07/14] reject_gcc_builtin: strip any location wrappers David Malcolm
2017-12-11 23:38           ` Jason Merrill
2017-11-10 21:43         ` [PATCH 02/14] Support for adding and stripping location_t wrapper nodes David Malcolm
2017-11-15  6:31           ` Trevor Saunders
2017-11-15 11:23             ` Richard Biener
2017-11-15 15:40               ` David Malcolm
2017-11-16 10:04                 ` Richard Biener
2017-11-30 17:25                   ` [PATCH v2.1] " David Malcolm
2017-11-30 17:46                     ` Jason Merrill
2017-11-30 18:38                       ` [PATCH, v2.2] " David Malcolm
2017-11-30 20:30                         ` Jason Merrill
2017-11-10 21:44         ` [PATCH 10/14] warn_for_memset: handle location wrappers David Malcolm
2017-12-11 23:41           ` Jason Merrill
2017-11-10 21:44         ` [PATCH 04/14] Update testsuite to show improvements David Malcolm
2017-11-10 21:44         ` [PATCH 11/14] Handle location wrappers in string_conv_p David Malcolm
2017-12-11 23:42           ` Jason Merrill
2017-11-10 21:44         ` [PATCH 14/14] pp_c_cast_expression: don't print casts for location wrappers David Malcolm
2017-12-11 23:46           ` Jason Merrill
2017-11-10 21:44         ` [PATCH 13/14] c-format.c: handle " David Malcolm
2017-12-11 23:45           ` Jason Merrill
2017-12-17 16:26             ` [v2 of PATCH " David Malcolm
2017-12-19 19:55               ` Jason Merrill
2017-12-20 17:33                 ` David Malcolm
2017-12-21  5:03                   ` Jason Merrill
2017-12-22 19:07                     ` [v3 " David Malcolm
2018-01-05 17:35                       ` PING " David Malcolm
2018-01-05 17:48                         ` Joseph Myers
2018-01-05 20:21                       ` Jason Merrill
2017-11-10 21:44         ` [PATCH 09/14] Strip location wrappers in null_ptr_cst_p David Malcolm
2017-12-11 23:39           ` Jason Merrill
2017-11-10 21:44         ` [PATCH 08/14] cp/tree.c: strip location wrappers in lvalue_kind David Malcolm
2017-12-11 23:39           ` Jason Merrill
2017-12-20 22:11             ` [v2 of PATCH " David Malcolm
2017-12-21  4:56               ` Jason Merrill
2017-12-21 17:47                 ` [v3 " David Malcolm
2017-12-21 22:44                   ` Jason Merrill
2017-11-10 22:11         ` [PATCH 12/14] C++: introduce null_node_p David Malcolm
2017-12-11 23:42           ` Jason Merrill
2017-11-13 19:20         ` [PATCH v2: 00/14] Preserving locations for variable-uses and constants (PR 43486) David Malcolm
2017-11-18  2:50         ` [RFC v3 00/11] C++: locations for (almost) everything " David Malcolm
2017-11-18  2:50           ` [PATCH 06/11] gcc: Handle location wrappers in operand_equal_p David Malcolm
2017-11-18  2:50           ` [PATCH 02/11] cp_tree::maybe_add_location_wrapper: no-op for template decls David Malcolm
2017-11-18  2:50           ` [PATCH 01/11] C++: Add location wrappers for all constants and decls David Malcolm
2017-11-18  2:50           ` [PATCH 03/11] Implement STRIP_ANY_LOCATION_WRAPPER_SAFE David Malcolm
2017-11-18  2:51           ` [PATCH 05/11] C++: finish_call_expr: strip location wrapper David Malcolm
2017-11-18  2:51           ` [PATCH 08/11] C++: handle location wrappers David Malcolm
2017-11-18  2:51           ` [PATCH 09/11] objc: handle location wrappers in objc_maybe_build_component_ref David Malcolm
2017-11-18  2:51           ` [PATCH 04/11] C++: add cp_expr::strip_any_location_wrapper method David Malcolm
2017-11-18  2:51           ` [PATCH 07/11] c-family: handle location wrappers David Malcolm
2017-11-18  3:23           ` [PATCH 11/11] config: handle location wrappers in various attributes (untested) David Malcolm
2017-11-18  3:54           ` [PATCH 10/11] i386: handle location wrappers in ix86_handle_cconv_attribute David Malcolm
2017-11-30 20:54         ` [PATCH v2: 00/14] Preserving locations for variable-uses and constants (PR 43486) David Malcolm
2017-12-11 16:08           ` [PING ^ 2] " David Malcolm
2017-12-17  1:10         ` [PATCH 15/14] Use fold_for_warn in get_atomic_generic_size David Malcolm
2017-12-19 20:35           ` Jason Merrill
2017-12-20  0:50             ` [v2 of PATCH " David Malcolm
2017-12-20  4:22               ` Jason Merrill
2017-12-20 19:33                 ` [v3 " David Malcolm
2017-12-21  4:57                   ` Jason Merrill
2018-01-10 19:51         ` [committed] Preserving locations for variable-uses and constants (PR c++/43486) David Malcolm

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='CADzB+2kfB26fTGXk2AVWuN1mv641OrcEBze+Lq-KexXHeS=Y9A@mail.gmail.com' \
    --to=jason@redhat.com \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=nathan@acm.org \
    --cc=richard.guenther@gmail.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).