<?xml version="1.0" encoding="UTF-8" ?>

<bugzilla version="5.2"
          urlbase="https://bugzilla.altlinux.org/"
          
          maintainer="jenya@basealt.ru"
>

    <bug>
          <bug_id>39798</bug_id>
          
          <creation_ts>2021-03-14 04:13:03 +0300</creation_ts>
          <short_desc>aarch64-alt-linux-gcc-10 produces incorrect code (caught by strace test suite)</short_desc>
          <delta_ts>2021-03-15 17:03:38 +0300</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>4</classification_id>
          <classification>Development</classification>
          <product>Sisyphus</product>
          <component>gcc10</component>
          <version>unstable</version>
          <rep_platform>aarch64</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98853</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P5</priority>
          <bug_severity>major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Dmitry V. Levin">ldv</reporter>
          <assigned_to name="Gleb F-Malinovskiy">glebfm</assigned_to>
          <cc>glebfm</cc>
    
    <cc>ldv</cc>
          
          <qa_contact>qa-sisyphus</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>196955</commentid>
    <comment_count>0</comment_count>
    <who name="Dmitry V. Levin">ldv</who>
    <bug_when>2021-03-14 04:13:03 +0300</bug_when>
    <thetext>aarch64-alt-linux-gcc-10 from gcc10-10.2.1-alt2.aarch64 miscompiles the following innocent example (a simplification of strace/src/print_dev_t.c):

$ cat arm64.c 
#define _GNU_SOURCE
#include &lt;assert.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;sys/sysmacros.h&gt;
int main(int ac, const char **av)
{
	assert(ac == 2);
	const unsigned long long dev = strtoull(av[1], 0, 0);
	const unsigned long dev_major = major(dev);
	printf(&quot;%#lx\n&quot;, dev_major);
	const unsigned long dev_minor = minor(dev);
	printf(&quot;%#lx\n&quot;, dev_minor);
	return 0;
}

$ aarch64-alt-linux-gcc-10 -Wall -Werror -O2 arm64.c 
$ ./a.out 0x123456789abcdef0
0x12345cde
0x123456789abf0

Also reproducible with &quot;gcc (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9)&quot; from f33,
apparently fixed in &quot;gcc (GCC) 11.0.0 20210210 (Red Hat 11.0.0-0)&quot; from f34.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>196956</commentid>
    <comment_count>1</comment_count>
    <who name="Dmitry V. Levin">ldv</who>
    <bug_when>2021-03-14 05:41:49 +0300</bug_when>
    <thetext>Further simplified example:

$ cat a.c 
#include &lt;stdio.h&gt;
int main(void)
{
	const unsigned long in = (unsigned long) main;
	unsigned int val = (in &amp; 0xffU) | ((in &gt;&gt; 8) &amp; 0xffffff00U);
	printf(&quot;%#lx %#lx\n&quot;, in, (unsigned long) val);
	return 0;
}
$ gcc -Wall -Werror a.c &amp;&amp; ./a.out
0xaaaab463d794 0xaab46394
$ gcc -Wall -Werror -O1 a.c &amp;&amp; ./a.out
0xaaaabd4cb794 0xaaaabd4c94
$ gcc -Wall -Werror -O2 a.c &amp;&amp; ./a.out 
0xaaaace920680 0xaaaace9280</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>196957</commentid>
    <comment_count>2</comment_count>
    <who name="Dmitry V. Levin">ldv</who>
    <bug_when>2021-03-14 07:44:47 +0300</bug_when>
    <thetext>The last example:

$ cat a.c
__attribute__((noipa)) unsigned long f(unsigned long x)
{
	return (unsigned int) ((x &amp; 0xffU) | ((x &gt;&gt; 8) &amp; 0xffffff00U));
}
int main(void)
{
	unsigned long v = f(-1UL);
	if (v != (unsigned int) v) __builtin_abort();
	return 0;
}
$ for i in 0 1 s 2; do printf &apos;%s &apos; &quot;-O$i&quot; &amp;&amp; gcc -Wall -Werror -O$i a.c &amp;&amp; ./a.out &amp;&amp; echo OK; done
-O0 OK
-O1 Aborted
-Os Aborted
-O2 Aborted</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>196975</commentid>
    <comment_count>3</comment_count>
    <who name="Repository Robot">repository-robot</who>
    <bug_when>2021-03-15 17:03:38 +0300</bug_when>
    <thetext>gcc10-10.2.1-alt3 -&gt; sisyphus:

 Mon Mar 15 2021 Gleb F-Malinovskiy &lt;glebfm@altlinux&gt; 10.2.1-alt3
 - Updated to merged branches from git://gcc.gnu.org/git/gcc.git (ALT#39798):
   + vendors/redhat/heads/gcc-10-branch
   commit 966e4575ccd8b618811b4871e44c31bb2d11a82a;
   + origin/releases/gcc-10
   commit a07015ad4dc18a1167720aece205deca702a1ab1.
 - gcc10-plugin-devel: added R: libgmp-devel.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>