This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Confused about code/comment in tree.c:build2
- From: Richard Biener <rguenther at suse dot de>
- To: "Bin.Cheng" <amker dot cheng at gmail dot com>
- Cc: GCC Development <gcc at gcc dot gnu dot org>
- Date: Fri, 31 Jan 2020 08:37:53 +0100 (CET)
- Subject: Re: Confused about code/comment in tree.c:build2
- References: <CAHFci2_iBDtz1AF61XbTrfe_SMdY2JsKZebdNAza_zCjHjrhzA@mail.gmail.com>
On Fri, 31 Jan 2020, Bin.Cheng wrote:
> Hi,
> In tree.c:build2 there is following code/comment:
>
> if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
> && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
> /* When sizetype precision doesn't match that of pointers
> we need to be able to build explicit extensions or truncations
> of the offset argument. */
> && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
> gcc_assert (TREE_CODE (arg0) == INTEGER_CST
> && TREE_CODE (arg1) == INTEGER_CST);
>
> The comment says specific condition needs to be satisfied if sizetype
> precision doesn't match that of pointers, while the code is checking
> "==" of precisions? Any explanation?
On targets where sizetype mode != ptr_mode the assert fires for reasons
I do not remember. The comment is a bit confusing since we're
dealing with plus/minus/mult here, not truncations or extensions
also the assert will still allow to-be-constant-folded values
(guess fold-const.c doesn't honor the restrictions).
In reality minus/plus/mult should never be used on pointers.
Richard.