From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4DAE0383582A; Thu, 22 Apr 2021 10:54:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4DAE0383582A From: "acoplan at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/100204] New: aarch64: UB evaluating J constraint Date: Thu, 22 Apr 2021 10:54:56 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: acoplan at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Apr 2021 10:54:56 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100204 Bug ID: 100204 Summary: aarch64: UB evaluating J constraint Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: acoplan at gcc dot gnu.org Target Milestone: --- On AArch64 with UBSan, the following testcase (reduced from c-c++-common/torture/builtin-arith-overflow-10.c) shows us invoking UB while evaluating the "J" constraint: $ cat test.c long a(); unsigned b(long); void c() { int d, e; for (d =3D 0;; d++) for (e =3D 0; e < (char)~0; e++) { long f =3D d - 9223372036854775807, g =3D e - 9223372036854775807 - 1; __int128 h =3D f + g; if (a() !=3D h) if (b(g) !=3D h) __builtin_abort(); } } $ gcc/xgcc -B gcc test.c -c -O /home/alecop01/toolchain/src/gcc/gcc/config/aarch64/constraints.md:86:23: runtime error: negation of -9223372036854775808 cannot be represented in ty= pe 'long int'; cast to an unsigned type to negate this value to itself #0 0x434aa1c in insn_const_int_ok_for_constraint(long, constraint_num) /home/alecop01/toolchain/src/gcc/gcc/config/aarch64/constraints.md:86 #1 0x18892ec in process_alt_operands /home/alecop01/toolchain/src/gcc/gcc/lra-constraints.c:2420 #2 0x18892ec in curr_insn_transform /home/alecop01/toolchain/src/gcc/gcc/lra-constraints.c:4108 #3 0x189df28 in lra_constraints(bool) /home/alecop01/toolchain/src/gcc/gcc/lra-constraints.c:5174 #4 0x1832cd4 in lra(_IO_FILE*) /home/alecop01/toolchain/src/gcc/gcc/lra.c:2336 #5 0x16d1784 in do_reload /home/alecop01/toolchain/src/gcc/gcc/ira.c:58= 35 #6 0x16d1784 in execute /home/alecop01/toolchain/src/gcc/gcc/ira.c:6021 #7 0x1b5ec1c in execute_one_pass(opt_pass*) /home/alecop01/toolchain/src/gcc/gcc/passes.c:2567 #8 0x1b623b8 in execute_pass_list_1 /home/alecop01/toolchain/src/gcc/gcc/passes.c:2656 #9 0x1b623f0 in execute_pass_list_1 /home/alecop01/toolchain/src/gcc/gcc/passes.c:2657 #10 0x1b624d4 in execute_pass_list(function*, opt_pass*) /home/alecop01/toolchain/src/gcc/gcc/passes.c:2667 #11 0xc7b2a4 in cgraph_node::expand() /home/alecop01/toolchain/src/gcc/gcc/cgraphunit.c:1830 #12 0xc7ff24 in expand_all_functions /home/alecop01/toolchain/src/gcc/gcc/cgraphunit.c:1994 #13 0xc7ff24 in symbol_table::compile() /home/alecop01/toolchain/src/gcc/gcc/cgraphunit.c:2358 #14 0xc8b81c in symbol_table::compile() /home/alecop01/toolchain/src/gcc/gcc/cgraphunit.c:2271 #15 0xc8b81c in symbol_table::finalize_compilation_unit() /home/alecop01/toolchain/src/gcc/gcc/cgraphunit.c:2539 #16 0x1f97478 in compile_file /home/alecop01/toolchain/src/gcc/gcc/toplev.c:482 #17 0x68d9b0 in do_compile /home/alecop01/toolchain/src/gcc/gcc/toplev.c:2201 #18 0x68d9b0 in toplev::main(int, char**) /home/alecop01/toolchain/src/gcc/gcc/toplev.c:2340 #19 0x6910d0 in main /home/alecop01/toolchain/src/gcc/gcc/main.c:39 #20 0xffffa32db6dc in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x206dc) #21 0x691b2c (/data/alecop01/builds/bstrap-ubsan/gcc/cc1+0x691b2c)=