Bug 234232 - clang Assertion failed when building the port devel/aws-checksums
Summary: clang Assertion failed when building the port devel/aws-checksums
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-20 22:18 UTC by Danilo Egea Gondolfo
Modified: 2023-10-08 21:34 UTC (History)
4 users (show)

See Also:
koobs: mfc-stable12?
koobs: mfc-stable11?


Attachments
crc32c_sse42_asm-43f9ae.c (86.93 KB, text/plain)
2018-12-20 22:19 UTC, Danilo Egea Gondolfo
no flags Details
crc32c_sse42_asm-43f9ae.sh (2.53 KB, application/x-shellscript)
2018-12-20 22:19 UTC, Danilo Egea Gondolfo
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Danilo Egea Gondolfo freebsd_committer freebsd_triage 2018-12-20 22:18:18 UTC
Clang is segfaulting on CURRENT when building devel/aws-checksums.

It stops at this assertion:

Assertion failed: (i == DstIdx || !MI->getOperand(i).isReg() || MI->getOperand(i).getReg() != RegA), function processTiedPairs, file /usr/src/contrib/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp, line 1544.

TwoAddressInstructionPass.cpp:1544.
#ifndef NDEBUG
    // First, verify that we don't have a use of "a" in the instruction
    // (a = b + a for example) because our transformation will not
    // work. This should never occur because we are in SSA form.
    for (unsigned i = 0; i != MI->getNumOperands(); ++i)
      assert(i == DstIdx ||
             !MI->getOperand(i).isReg() ||
             MI->getOperand(i).getReg() != RegA);
#endif

The target file (source/intel/crc32c_sse42_asm.c) has a lot of assembly inline code.
Comment 1 Danilo Egea Gondolfo freebsd_committer freebsd_triage 2018-12-20 22:19:22 UTC
Created attachment 200322 [details]
crc32c_sse42_asm-43f9ae.c
Comment 2 Danilo Egea Gondolfo freebsd_committer freebsd_triage 2018-12-20 22:19:55 UTC
Created attachment 200323 [details]
crc32c_sse42_asm-43f9ae.sh
Comment 3 Jan Beich freebsd_committer freebsd_triage 2019-03-04 13:37:54 UTC
Also affects Clang 8 (soon to be in -CURRENT).

$ poudriere jail -cj clang8 -v projects/clang800-import -m svn+https
$ poudriere testport -j clang8 devel/aws-checksums
[...]
Assertion failed: (i == DstIdx || !MI->getOperand(i).isReg() || MI->getOperand(i).getReg() != RegA), function processTiedPairs, file /poudriere/jails/headamd64PR236062/usr/src/contrib/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp, line 1547.
cc: error: unable to execute command: Abort trap (core dumped)
cc: error: clang frontend command failed due to signal (use -v to see invocation)
FreeBSD clang version 8.0.0 (branches/release_80 354799) (based on LLVM 8.0.0)
Target: x86_64-unknown-freebsd13.0
Thread model: posix
InstalledDir: /usr/bin

http://package18.nyi.freebsd.org/data/headamd64PR236062-default/2019-03-01_06h42m53s/logs/errors/aws-checksums-0.1.2,1.log
Comment 4 Dimitry Andric freebsd_committer freebsd_triage 2019-03-06 18:32:47 UTC
This reproduces even with very old versions of clang, e.g. it has been in there for a long time; though assertions need to be enabled.

Minimized and submitted upstream here:
https://bugs.llvm.org/show_bug.cgi?id=40985
Comment 5 Baptiste Daroussin freebsd_committer freebsd_triage 2019-09-05 12:07:23 UTC
Remove the blocking against 230355 as llvm/clang 7 has landed already
Comment 6 Alfredo Dal'Ava Junior freebsd_committer freebsd_triage 2020-01-13 14:09:35 UTC
fwiw, this package builds fine on PowerPC64 using base clang 9.0.1.
Comment 7 Dimitry Andric freebsd_committer freebsd_triage 2020-11-08 21:15:19 UTC
(In reply to Alfredo Dal'Ava Junior from comment #6)
It's to be expected, since the failing test case is x86_64 specific. :)

I just re-tested with a very recent llvmorg-12-init-10988-g43df29e2062, and it still asserts. No movement at all from upstream.
Comment 8 Nuno Teixeira freebsd_committer freebsd_triage 2022-09-15 22:56:52 UTC
It builds fine in 13.0.0 and 10.0.1, fails in 14.0.5

Is there a relation between OS version/clang version or something to understand why it works on some clang versions?
Comment 9 Dimitry Andric freebsd_committer freebsd_triage 2022-09-16 07:42:35 UTC
(In reply to Nuno Teixeira from comment #8)
Yes, -CURRENT has llvm/clang assertions enabled, but -STABLE branches do not.

So while the latter can appear to work, note that if assertions are known to be violated, care should be taken with the results...
Comment 10 Nuno Teixeira freebsd_committer freebsd_triage 2023-07-11 06:44:01 UTC
(In reply to Dimitry Andric from comment #9)

It builds fine on CURRENT >=1400091 Clang 16
---
.if (${OSVERSION} >= 1400000 && ${OSVERSION} < 1400091)
USE_GCC=        yes
.endif
---

Should I commit it or wait for an explanation of why build success on clang16?
Comment 11 Dimitry Andric freebsd_committer freebsd_triage 2023-07-11 10:14:27 UTC
(In reply to Nuno Teixeira from comment #10)
This was fixed and/or worked around by aws-checksums upstream in <https://github.com/awslabs/aws-checksums/commit/ad53be196a25bbefa3700a01187fdce573a7d2d0>, where they changed the inline asm constraints. See also <https://github.com/awslabs/aws-checksums/issues/49> and <https://github.com/awslabs/aws-checksums/pull/57>.

Note that the clang bug is still open, and there are even 4 different bug reports for it: <https://github.com/llvm/llvm-project/issues?q=is%3Aissue+is%3Aopen+processTiedPairs> :)

However, the clang assertion is not triggered anymore due to the changes in aws-checksums. So, the whole USE_GCC thing can be deleted now.
Comment 12 commit-hook freebsd_committer freebsd_triage 2023-07-11 13:45:09 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=b8f8609d334536eb49a450cbbb1ce547887c19a0

commit b8f8609d334536eb49a450cbbb1ce547887c19a0
Author:     Nuno Teixeira <eduardo@FreeBSD.org>
AuthorDate: 2023-07-11 13:37:06 +0000
Commit:     Nuno Teixeira <eduardo@FreeBSD.org>
CommitDate: 2023-07-11 13:44:48 +0000

    devel/aws-checksums: Remove USE_GCC

    Clang assertion is not triggered anymore due to the changes in
    aws-checksums 0.1.14, so removing USE_GCC on affected OSVERSION.

    See also:       https://github.com/awslabs/aws-checksums/releases/tag/v0.1.14
    PR:             234232

 devel/aws-checksums/Makefile | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
Comment 13 Nuno Teixeira freebsd_committer freebsd_triage 2023-07-11 13:47:15 UTC
(In reply to Dimitry Andric from comment #11)

Thanks very much Dimitry.
I missed that upstream fix.

Cheers
Comment 14 Gleb Popov freebsd_committer freebsd_triage 2023-10-08 21:34:02 UTC
This can be closed now?