LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 34249 - Panic when using _addcarryx_u64 with Clang 3.9
Summary: Panic when using _addcarryx_u64 with Clang 3.9
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: Frontend (show other bugs)
Version: 3.9
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-20 17:51 PDT by Jeffrey Walton
Modified: 2019-01-29 12:08 PST (History)
6 users (show)

See Also:
Fixed By Commit(s): r310784


Attachments
preprocessed integer.cpp, integer-05cbef.cpp, and integer-05cbef.sh (999.58 KB, application/zip)
2017-08-20 17:51 PDT, Jeffrey Walton
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jeffrey Walton 2017-08-20 17:51:50 PDT
Created attachment 19014 [details]
preprocessed integer.cpp, integer-05cbef.cpp, and integer-05cbef.sh

I'm testing a patch that uses _addcarryx_u64 intrinsics to speedup some big integer math. The machine is a 6th gen Core i5 (Skylake), so it has the ADX extensions.

Intel ICC generates beautiful code that utilizes adcx. GCC 6.4 still produces the old crappy add/adc code. Clang 3.9 panics.

I have not been able to reduce the crash to a minimal test case. My simple reduced test cases compile fine. The source file in question, integer.cpp, is an awful monstrosity.

**********

skylake:cryptopp-fork$ clang++ -DNDEBUG -g2 -O3 -fPIC -march=native --save-temps integer.cpp
0  libLLVM-3.9.so          0x00007fd07d159338 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 56
1  libLLVM-3.9.so          0x00007fd07d15745e llvm::sys::RunSignalHandlers() + 62
2  libLLVM-3.9.so          0x00007fd07d15759a
3  libpthread.so.0         0x00007fd07b0df5b0
4  libLLVM-3.9.so          0x00007fd07e025ada llvm::X86ATTInstPrinter::getRegisterName(unsigned int) + 10
5  libLLVM-3.9.so          0x00007fd07e025b60 llvm::X86ATTInstPrinter::printRegName(llvm::raw_ostream&, unsigned int) const + 48
6  libLLVM-3.9.so          0x00007fd07e026ba3 llvm::X86ATTInstPrinter::printOperand(llvm::MCInst const*, unsigned int, llvm::raw_ostream&) + 771
7  libLLVM-3.9.so          0x00007fd07e0290d2 llvm::X86ATTInstPrinter::printInstruction(llvm::MCInst const*, llvm::raw_ostream&) + 5730
8  libLLVM-3.9.so          0x00007fd07e02a75e llvm::X86ATTInstPrinter::printInst(llvm::MCInst const*, llvm::raw_ostream&, llvm::StringRef, llvm::MCSubtargetInfo const&) + 302
9  libLLVM-3.9.so          0x00007fd07dd3c7c4
10 libLLVM-3.9.so          0x00007fd07dfd17d0
11 libLLVM-3.9.so          0x00007fd07dfd46f1
12 libLLVM-3.9.so          0x00007fd07d6750d0 llvm::AsmPrinter::EmitFunctionBody() + 992
13 libLLVM-3.9.so          0x00007fd07dec5bac
14 libLLVM-3.9.so          0x00007fd07d36ce51 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 129
15 libLLVM-3.9.so          0x00007fd07d216012 llvm::FPPassManager::runOnFunction(llvm::Function&) + 498
16 libLLVM-3.9.so          0x00007fd07d21639b llvm::FPPassManager::runOnModule(llvm::Module&) + 43
17 libLLVM-3.9.so          0x00007fd07d2166c7 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 775
18 libclangCodeGen.so      0x00007fd07c1e1083 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) + 6787
19 libclangCodeGen.so      0x00007fd07c37489b
20 libclangFrontend.so     0x00007fd07bbcb15e clang::FrontendAction::Execute() + 286
21 libclangFrontend.so     0x00007fd07bb94cd6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 278
22 libclangFrontendTool.so 0x00007fd07b9272c3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 2227
23 clang-3.9               0x0000003c7bfc5c30 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 2336
24 clang-3.9               0x0000003c7bfc2705 main + 6997
25 libc.so.6               0x00007fd07a26a401 __libc_start_main + 241
26 clang-3.9               0x0000003c7bfc3fea _start + 42
Stack dump:
0.      Program arguments: /usr/bin/clang-3.9 -cc1 -triple x86_64-unknown-linux-gnu -S -disable-free -disable-llvm-verifier -discard-value-names -main-file-name integer.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu skylake -target-feature +sse2 -target-feature +cx16 -target-feature -tbm -target-feature -avx512ifma -target-feature -avx512dq -target-feature -fma4 -target-feature +prfchw -target-feature +bmi2 -target-feature +xsavec -target-feature +fsgsbase -target-feature +popcnt -target-feature +aes -target-feature -pcommit -target-feature +xsaves -target-feature -avx512er -target-feature -clwb -target-feature -avx512f -target-feature -pku -target-feature +smap -target-feature +mmx -target-feature -xop -target-feature +rdseed -target-feature -hle -target-feature -sse4a -target-feature -avx512bw -target-feature +clflushopt -target-feature +xsave -target-feature -avx512vl -target-feature +invpcid -target-feature -avx512cd -target-feature +avx -target-feature -rtm -target-feature +fma -target-feature +bmi -target-feature -mwaitx -target-feature +rdrnd -target-feature +sse4.1 -target-feature +sse4.2 -target-feature +avx2 -target-feature +sse -target-feature +lzcnt -target-feature +pclmul -target-feature -prefetchwt1 -target-feature +f16c -target-feature +ssse3 -target-feature +sgx -target-feature +cmov -target-feature -avx512vbmi -target-feature +movbe -target-feature +xsaveopt -target-feature -sha -target-feature +adx -target-feature -avx512pf -target-feature +sse3 -momit-leaf-frame-pointer -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -resource-dir /usr/bin/../lib64/clang/3.9.1 -O3 -fdebug-compilation-dir /home/jwalton/cryptopp-fork -ferror-limit 19 -fmessage-length 80 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o integer.s -x ir integer.bc
1.      Code generation
2.      Running pass 'Function Pass Manager' on module 'integer.bc'.
3.      Running pass 'X86 Assembly / Object Emitter' on function '@_ZN8CryptoPP7ADX_AddEmPmPKmS2_'
clang-3.9: error: unable to execute command: Segmentation fault (core dumped)
clang-3.9: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 3.9.1 (tags/RELEASE_391/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /bin
clang-3.9: note: diagnostic msg: PLEASE submit a bug report to  and include the crash backtrace, preprocessed source, and associated run script.
clang-3.9: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-3.9: note: diagnostic msg: /tmp/integer-05cbef.cpp
clang-3.9: note: diagnostic msg: /tmp/integer-05cbef.sh
clang-3.9: note: diagnostic msg:

********************
skylake:cryptopp-fork$
Comment 1 Jeffrey Walton 2017-08-20 17:55:24 PDT
This should have been included in the report. Sorry about that.

skylake:cryptopp-fork$ clang++ --version
clang version 3.9.1 (tags/RELEASE_391/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /bin

skylake:cryptopp-fork$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: Fedora
Description:    Fedora release 25 (Twenty Five)
Release:        25
Codename:       TwentyFive

k$ dnf info clang
Last metadata expiration check: 0:00:31 ago on Sun Aug 20 20:55:16 2017.
Installed Packages
Name        : clang
Arch        : x86_64
Epoch       : 0
Version     : 3.9.1
Release     : 2.fc25
Size        : 5.9 M
Repo        : @System
From repo   : updates
Summary     : A C language family front-end for LLVM
URL         : http://llvm.org
License     : NCSA
Description : clang: noun
            :     1. A loud, resonant, metallic sound.
            :     2. The strident call of a crane or goose.
            :     3. C-language family front-end toolkit.
            :
            : The goal of the Clang project is to create a new C, C++, Objective
            : C and Objective C++ front-end for the LLVM compiler. Its tools are
            : built as libraries and designed to be loosely-coupled and
            : extensible.
Comment 2 Jeffrey Walton 2017-08-20 17:59:50 PDT
Regarding:

   3. Running pass 'X86 Assembly / Object Emitter' on function 
      @_ZN8CryptoPP7ADX_AddEmPmPKmS2_'

ADX_Add is the new function I am adding/testing. It is the patch that's being tested. (ICC and GCC tested good).

#if CRYPTOPP_INTEGER_ADX
CRYPTOPP_NAKED int CRYPTOPP_FASTCALL ADX_Add(size_t N, word *C, const word *A, const word *B)
{
	long long unsigned int* CC = reinterpret_cast<long long unsigned int*>(C);
	const long long unsigned int* BB = reinterpret_cast<const long long unsigned int*>(B);
	const long long unsigned int* AA = reinterpret_cast<const long long unsigned int*>(A);

	byte carry = 0;
	for (size_t i = 0; i < N; ++i)
		carry = _addcarryx_u64(carry, AA[i], BB[i], &CC[i]);

	return carry;
}
#endif
Comment 3 Craig Topper 2017-08-20 18:02:50 PDT
Can you try the change from this commit?

https://reviews.llvm.org/rL310784
Comment 4 Jeffrey Walton 2017-08-21 01:27:42 PDT
The issue is present with Fedora 26 and Clang 4.0.

********************

$ clang --version
clang version 4.0.0 (tags/RELEASE_400/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /bin

$ dnf info clang
Last metadata expiration check: 0:14:44 ago on Mon 21 Aug 2017 04:13:09 AM EDT.
Installed Packages
Name         : clang
Version      : 4.0.0
Release      : 3.fc26
Arch         : x86_64
Size         : 6.4 M
Source       : clang-4.0.0-3.fc26.src.rpm
Repo         : @System
From repo    : @commandline
Summary      : A C language family front-end for LLVM
URL          : http://llvm.org
License      : NCSA
Description  : clang: noun
             :     1. A loud, resonant, metallic sound.
             :     2. The strident call of a crane or goose.
             :     3. C-language family front-end toolkit.
             :
             : The goal of the Clang project is to create a new C, C++,
             : Objective C and Objective C++ front-end for the LLVM compiler.
             : Its tools are built as libraries and designed to be
             : loosely-coupled and extensible.
Comment 5 Tom Stellard 2017-08-25 19:31:32 PDT
Can you attach the integer.bc file?
Comment 6 Simon Pilgrim 2019-01-26 06:37:52 PST
https://godbolt.org/z/trNlOW

Where are with this? I'm tempted to suggest we close this as, between rL310784 and not emitting ADCX/ADOX any more, we should be ok.
Comment 7 Simon Pilgrim 2019-01-29 12:08:48 PST
Resolving - the crash was fixed by rL310784 and we avoid ADOX/ADCX code generation now.