c++: another build_new_1 folding fix [PR111929]
Checks
Commit Message
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
OK for trunk?
-- >8 --
We also need to avoid folding 'outer_nelts_check' when in a template
context to prevent an ICE on the below testcase. This patch achieves
this by replacing the fold_build2 call with build2 (cp_fully_fold will
later fold the overall expression if appropriate).
In passing, this patch removes an unnecessary call to convert on 'nelts'
since it should always already be a size_t (and 'convert' isn't the best
conversion entry point to use anyway since it doesn't take a complain
parameter.)
PR c++/111929
gcc/cp/ChangeLog:
* init.cc (build_new_1): Remove unnecessary call to convert
on 'nelts'. Use build2 instead of fold_build2 for
'outer_nelts_checks'.
gcc/testsuite/ChangeLog:
* g++.dg/template/non-dependent28a.C: New test.
---
gcc/cp/init.cc | 8 ++++----
gcc/testsuite/g++.dg/template/non-dependent28a.C | 8 ++++++++
2 files changed, 12 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/template/non-dependent28a.C
Comments
On 10/25/23 12:03, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
> OK for trunk?
>
> -- >8 --
>
> We also need to avoid folding 'outer_nelts_check' when in a template
> context to prevent an ICE on the below testcase. This patch achieves
> this by replacing the fold_build2 call with build2 (cp_fully_fold will
> later fold the overall expression if appropriate).
>
> In passing, this patch removes an unnecessary call to convert on 'nelts'
> since it should always already be a size_t (and 'convert' isn't the best
> conversion entry point to use anyway since it doesn't take a complain
> parameter.)
>
> PR c++/111929
>
> gcc/cp/ChangeLog:
>
> * init.cc (build_new_1): Remove unnecessary call to convert
> on 'nelts'.
OK.
> Use build2 instead of fold_build2 for 'outer_nelts_checks'.
Also OK, but can we skip that whole block when processing_template_decl?
Seems no point to build runtime checks.
Jason
@@ -3261,7 +3261,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
max_outer_nelts = wi::udiv_trunc (max_size, inner_size);
max_outer_nelts_tree = wide_int_to_tree (sizetype, max_outer_nelts);
- size = build2 (MULT_EXPR, sizetype, size, convert (sizetype, nelts));
+ size = build2 (MULT_EXPR, sizetype, size, nelts);
if (TREE_CODE (cst_outer_nelts) == INTEGER_CST)
{
@@ -3293,9 +3293,9 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
- wi::clz (max_outer_nelts);
max_outer_nelts = (max_outer_nelts >> shift) << shift;
- outer_nelts_check = fold_build2 (LE_EXPR, boolean_type_node,
- outer_nelts,
- max_outer_nelts_tree);
+ outer_nelts_check = build2 (LE_EXPR, boolean_type_node,
+ outer_nelts,
+ max_outer_nelts_tree);
}
}
new file mode 100644
@@ -0,0 +1,8 @@
+// PR c++/111929
+
+struct A { operator int(); };
+
+template<class>
+void f() {
+ new int[A()];
+}