From: Jakub Jelinek Date: Fri, 12 Jan 2024 10:22:04 +0000 (+0100) Subject: sra: Punt for too large _BitInt accesses [PR113330] X-Git-Tag: basepoints/gcc-15~2958 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4c08f0dde4c2a48931a61b84a00d5c16f4b0e291;p=thirdparty%2Fgcc.git sra: Punt for too large _BitInt accesses [PR113330] This is the case I was talking about in https://gcc.gnu.org/pipermail/gcc-patches/2024-January/642423.html and Zdenek kindly found a testcase for it. We can only create BITINT_TYPE with precision at most 65535, not 65536, so need to punt if we'd want to create it. 2024-01-12 Jakub Jelinek PR tree-optimization/113330 * tree-sra.cc (create_access): Punt for BITINT_TYPE accesses with too large size. * gcc.dg/bitint-69.c: New test. --- diff --git a/gcc/testsuite/gcc.dg/bitint-69.c b/gcc/testsuite/gcc.dg/bitint-69.c new file mode 100644 index 000000000000..c225cbdd6f12 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-69.c @@ -0,0 +1,25 @@ +/* PR tree-optimization/113330 */ +/* { dg-do compile { target bitint } } */ +/* { dg-require-stack-check "generic" } */ +/* { dg-options "-std=c23 -O --param=large-stack-frame=131072 -fstack-check=generic --param=sccvn-max-alias-queries-per-access=0" } */ + +_BitInt(8) a; + +static inline __attribute__((__always_inline__)) void +bar (int, int, int, int, int, int, int, int) +{ +#if __BITINT_MAXWIDTH__ >= 65535 + _BitInt(65535) b = 0; + _BitInt(383) c = 0; +#else + _BitInt(63) b = 0; + _BitInt(39) c = 0; +#endif + a = b; +} + +void +foo (void) +{ + bar (0, 0, 0, 0, 0, 0, 0, 0); +} diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc index e786232f6b00..6a1141b73770 100644 --- a/gcc/tree-sra.cc +++ b/gcc/tree-sra.cc @@ -967,6 +967,12 @@ create_access (tree expr, gimple *stmt, bool write) disqualify_candidate (base, "Encountered an access beyond the base."); return NULL; } + if (TREE_CODE (TREE_TYPE (expr)) == BITINT_TYPE + && size > WIDE_INT_MAX_PRECISION - 1) + { + disqualify_candidate (base, "Encountered too large _BitInt access."); + return NULL; + } access = create_access_1 (base, offset, size); access->expr = expr;