On Mon, Jul 13, 2026 at 01:00:33PM +0200, Jakub Jelinek wrote:
> On Mon, Jul 13, 2026 at 06:23:48PM +0800, H.J. Lu wrote:
> > Have you run your proposed change with the test included in my patch?
> 
> Yes.  It fixed it.

Here is full patch I've bootstrapped/regtested on x86_64-linux and
i686-linux.

I've tweaked the testcase a little bit too, to avoid includes and
more importantly only compile the single function with -march=x86-64-v4,
so that main doesn't try to use any extra insns from that ISA by
accident.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2026-07-14  Jakub Jelinek  <[email protected]>
            H.J. Lu <[email protected]>

        PR tree-optimization/120201
        * cfgexpand.cc (expand_used_vars): Set data.asan_alignb to
        maximum of itself and crtl->stack_alignment_needed
        / BITS_PER_UNIT.

        * g++.dg/asan/pr120201-1.C: New test.

Signed-off-by: H.J. Lu <[email protected]>

--- gcc/cfgexpand.cc.jj 2026-06-25 18:11:41.632407668 +0200
+++ gcc/cfgexpand.cc    2026-07-13 13:00:02.521190628 +0200
@@ -2676,6 +2676,9 @@ expand_used_vars (bitmap forced_stack_va
          HOST_WIDE_INT offset, sz, redzonesz;
          redzonesz = ASAN_RED_ZONE_SIZE;
          sz = data.asan_vec[0] - prev_offset;
+         data.asan_alignb = MAX (data.asan_alignb,
+                                 crtl->stack_alignment_needed
+                                 / BITS_PER_UNIT);
          if (data.asan_alignb > ASAN_RED_ZONE_SIZE
              && data.asan_alignb <= 4096
              && sz + ASAN_RED_ZONE_SIZE >= (int) data.asan_alignb)

--- gcc/testsuite/g++.dg/asan/pr120201-1.C.jj
+++ gcc/testsuite/g++.dg/asan/pr120201-1.C
@@ -0,0 +1,42 @@
+// { dg-do run }
+// { dg-options "-O3 -std=c++23 -fsanitize=address" }
+
+using size_t = decltype (sizeof 0);
+
+float* shaderLightData;
+
+using ShaderShadowTransform = float[4z * 4z * 6z];
+using Transform = float[4 * 4];
+
+__attribute__ ((noipa))
+#if defined(__i386__) || defined(__x86_64__)
+__attribute__ ((target ("arch=x86-64-v4")))
+#endif
+static void
+do_test (void)
+{
+  int lightCount = 3;
+  ShaderShadowTransform* shaderShadowData = new 
ShaderShadowTransform[lightCount];
+  for (int index = 0; index < lightCount; index++)
+    {
+      Transform transforms[6];
+
+      const size_t matSize = 4z * 4z;
+      float* transformBlockStart = shaderShadowData[index];
+      for (int face = 0; face < 6; face++)
+       __builtin_memcpy(transformBlockStart + (matSize * face),
+                        &transforms[face][0], matSize * sizeof(float));
+  }
+
+  delete [] shaderShadowData;
+}
+
+int
+main (void)
+{
+#if defined(__i386__) || defined(__x86_64__)
+  if (__builtin_cpu_supports ("x86-64-v4"))
+#endif
+    do_test ();
+  return 0;
+}


        Jakub

Reply via email to