Public bug reported:

This GCC bug fix causes certain C code to miscompile
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123002

It was a fixed a few months ago, but the fix backport is missing in
Ubuntu 26.04 LTS.

Reproducer:

```
ubuntu@devbox:~/firedancer$ cat <<EOF > reproducer.c
static unsigned int const enc_table_32[8][3] = {
    {513735U, 77223048U, 437087610U },
    {0U,      78508U,    646269101U },
    {0U,      0U,        11997U,    },
    {0U,      0U,        0U,        },
    {0U,      0U,        0U,        },
    {0U,      0U,        0U,        },
    {0U,      0U,        0U,        },
    {0U,      0U,        0U,        }};

int __attribute__((noipa)) foo()
{
  unsigned long intermediate[3] = {0};

  for (unsigned long i = 0UL; i < 8; i++) {
      intermediate[0] += 2 * (unsigned long)(enc_table_32)[i][0];
      intermediate[1] += 2 * (unsigned long)(enc_table_32)[i][1];
      intermediate[2] += 2 * (unsigned long)(enc_table_32)[i][2];
  }

  if (intermediate[0] == 0xfad8e &&
      intermediate[1] == 0x9370e68 && intermediate[2] == 0x8125ca08) {
      return 0;
  } else {
      return 1;
  }
}
int main()
{
  if (foo ())
    __builtin_abort ();
  return 0;
}
EOF
ubuntu@devbox:~/firedancer$ gcc -O3 -march=native reproducer.c -o reproducer
ubuntu@devbox:~/firedancer$ ./reproducer
Aborted                    (core dumped) ./reproducer
ubuntu@devbox:~/firedancer$ lsb_release -rd
Description:    Ubuntu 26.04 LTS
Release:        26.04
ubuntu@devbox:~/firedancer$ apt-cache policy  gcc-15
gcc-15:
  Installed: 15.2.0-16ubuntu1
  Candidate: 15.2.0-16ubuntu1
  Version table:
 *** 15.2.0-16ubuntu1 500
        500 http://de.archive.ubuntu.com/ubuntu resolute/main amd64v3 Packages
        100 /var/lib/dpkg/status
ubuntu@devbox:~/firedancer$ grep flags /proc/cpuinfo | head -n1
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov 
pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb 
rdtscp lm constant_tsc rep_good amd_lbr_v2 nopl xtopology nonstop_tsc cpuid 
extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 
sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm 
extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce 
topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpuid_fault cpb cat_l3 
cdp_l3 hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp ibrs_enhanced vmmcall 
fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq 
adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt 
xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local 
user_shstk avx_vnni avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd 
amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid 
decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic 
v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq 
avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid bus_lock_detect movdiri 
movdir64b overflow_recov succor smca fsrm avx512_vp2intersect flush_l1d 
debug_swap amd_lbr_pmc_freeze
```

** Affects: gcc
     Importance: Unknown
         Status: Unknown

** Affects: gcc-15 (Ubuntu)
     Importance: Undecided
         Status: New

** Attachment added: "reproducer.c"
   
https://bugs.launchpad.net/bugs/2163070/+attachment/5990403/+files/reproducer.c

** Description changed:

- This GCC bug fix causes certain C code to miscompile and cause U.B.
+ This GCC bug fix causes certain C code to miscompile
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123002
  
  It was a fixed a few months ago, but the fix backport is missing in
  Ubuntu 26.04 LTS.
  
  Reproducer:
  
  ```
  ubuntu@devbox:~/firedancer$ cat <<EOF > reproducer.c
- > static unsigned int const enc_table_32[8][3] = {
-     {513735U, 77223048U, 437087610U },
-     {0U,      78508U,    646269101U },
-     {0U,      0U,        11997U,    },
-     {0U,      0U,        0U,        },
-     {0U,      0U,        0U,        },
-     {0U,      0U,        0U,        },
-     {0U,      0U,        0U,        },
-     {0U,      0U,        0U,        }};
+ static unsigned int const enc_table_32[8][3] = {
+     {513735U, 77223048U, 437087610U },
+     {0U,      78508U,    646269101U },
+     {0U,      0U,        11997U,    },
+     {0U,      0U,        0U,        },
+     {0U,      0U,        0U,        },
+     {0U,      0U,        0U,        },
+     {0U,      0U,        0U,        },
+     {0U,      0U,        0U,        }};
  
  int __attribute__((noipa)) foo()
  {
-   unsigned long intermediate[3] = {0};
+   unsigned long intermediate[3] = {0};
  
-   for (unsigned long i = 0UL; i < 8; i++) {
-       intermediate[0] += 2 * (unsigned long)(enc_table_32)[i][0];
-       intermediate[1] += 2 * (unsigned long)(enc_table_32)[i][1];
-       intermediate[2] += 2 * (unsigned long)(enc_table_32)[i][2];
-   }
+   for (unsigned long i = 0UL; i < 8; i++) {
+       intermediate[0] += 2 * (unsigned long)(enc_table_32)[i][0];
+       intermediate[1] += 2 * (unsigned long)(enc_table_32)[i][1];
+       intermediate[2] += 2 * (unsigned long)(enc_table_32)[i][2];
+   }
  
-   if (intermediate[0] == 0xfad8e &&
-       intermediate[1] == 0x9370e68 && intermediate[2] == 0x8125ca08) {
-       return 0;
-   } else {
-       return 1;
-   }
+   if (intermediate[0] == 0xfad8e &&
+       intermediate[1] == 0x9370e68 && intermediate[2] == 0x8125ca08) {
+       return 0;
+   } else {
+       return 1;
+   }
  }
  int main()
  {
-   if (foo ())
-     __builtin_abort ();
-   return 0;
+   if (foo ())
+     __builtin_abort ();
+   return 0;
  }
- > EOF
+ EOF
  ubuntu@devbox:~/firedancer$ gcc -O3 -march=native reproducer.c -o reproducer
  ubuntu@devbox:~/firedancer$ ./reproducer
  Aborted                    (core dumped) ./reproducer
  ubuntu@devbox:~/firedancer$ lsb_release -rd
  Description:  Ubuntu 26.04 LTS
  Release:      26.04
  ubuntu@devbox:~/firedancer$ apt-cache policy  gcc-15
  gcc-15:
-   Installed: 15.2.0-16ubuntu1
-   Candidate: 15.2.0-16ubuntu1
-   Version table:
-  *** 15.2.0-16ubuntu1 500
-         500 http://de.archive.ubuntu.com/ubuntu resolute/main amd64v3 Packages
-         100 /var/lib/dpkg/status
+   Installed: 15.2.0-16ubuntu1
+   Candidate: 15.2.0-16ubuntu1
+   Version table:
+  *** 15.2.0-16ubuntu1 500
+         500 http://de.archive.ubuntu.com/ubuntu resolute/main amd64v3 Packages
+         100 /var/lib/dpkg/status
  ```

** Bug watch added: GCC Bugzilla #123002
   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123002

** Also affects: gcc via
   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123002
   Importance: Unknown
       Status: Unknown

** Description changed:

  This GCC bug fix causes certain C code to miscompile
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123002
  
  It was a fixed a few months ago, but the fix backport is missing in
  Ubuntu 26.04 LTS.
  
  Reproducer:
  
  ```
  ubuntu@devbox:~/firedancer$ cat <<EOF > reproducer.c
  static unsigned int const enc_table_32[8][3] = {
      {513735U, 77223048U, 437087610U },
      {0U,      78508U,    646269101U },
      {0U,      0U,        11997U,    },
      {0U,      0U,        0U,        },
      {0U,      0U,        0U,        },
      {0U,      0U,        0U,        },
      {0U,      0U,        0U,        },
      {0U,      0U,        0U,        }};
  
  int __attribute__((noipa)) foo()
  {
    unsigned long intermediate[3] = {0};
  
    for (unsigned long i = 0UL; i < 8; i++) {
        intermediate[0] += 2 * (unsigned long)(enc_table_32)[i][0];
        intermediate[1] += 2 * (unsigned long)(enc_table_32)[i][1];
        intermediate[2] += 2 * (unsigned long)(enc_table_32)[i][2];
    }
  
    if (intermediate[0] == 0xfad8e &&
        intermediate[1] == 0x9370e68 && intermediate[2] == 0x8125ca08) {
        return 0;
    } else {
        return 1;
    }
  }
  int main()
  {
    if (foo ())
      __builtin_abort ();
    return 0;
  }
  EOF
  ubuntu@devbox:~/firedancer$ gcc -O3 -march=native reproducer.c -o reproducer
  ubuntu@devbox:~/firedancer$ ./reproducer
  Aborted                    (core dumped) ./reproducer
  ubuntu@devbox:~/firedancer$ lsb_release -rd
  Description:  Ubuntu 26.04 LTS
  Release:      26.04
  ubuntu@devbox:~/firedancer$ apt-cache policy  gcc-15
  gcc-15:
    Installed: 15.2.0-16ubuntu1
    Candidate: 15.2.0-16ubuntu1
    Version table:
   *** 15.2.0-16ubuntu1 500
          500 http://de.archive.ubuntu.com/ubuntu resolute/main amd64v3 Packages
          100 /var/lib/dpkg/status
+ ubuntu@devbox:~/firedancer$ grep flags /proc/cpuinfo | head -n1
+ flags         : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov 
pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb 
rdtscp lm constant_tsc rep_good amd_lbr_v2 nopl xtopology nonstop_tsc cpuid 
extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 
sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm 
extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce 
topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpuid_fault cpb cat_l3 
cdp_l3 hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp ibrs_enhanced vmmcall 
fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq 
adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt 
xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local 
user_shstk avx_vnni avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd 
amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid 
decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic 
v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq 
avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid bus_lock_detect movdiri 
movdir64b overflow_recov succor smca fsrm avx512_vp2intersect flush_l1d 
debug_swap amd_lbr_pmc_freeze
  ```

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2163070

Title:
  Miscompile in GCC 15.2.0 (x86)

To manage notifications about this bug go to:
https://bugs.launchpad.net/gcc/+bug/2163070/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to