Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Assertion fails in bitcode writer with LLVM 12 RC5+ #48888

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR49919
Status NEW
Importance P release blocker
Reported by Martin Kinkelin (kinke@gmx.net)
Reported on 2021-04-10 17:19:19 -0700
Last modified on 2021-07-12 09:21:09 -0700
Version trunk
Hardware PC Windows NT
CC david.bolvansky@gmail.com, htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, lukebenes@hotmail.com, tstellar@redhat.com
Fixed by commit(s)
Attachments file_49919.txt (1187 bytes, text/plain)
Blocks PR48902, PR49317
Blocked by
See also
Created attachment 24743
.ll file

While testing LLVM 12 RC5+ (fa0971b87f) with LDC, I've hit a bitcode writer
assertion when targeting x86_64-windows-msvc. Creating textual LLVM assembly,
textual machine assembly and machine code works fine, just the bitcode fails -
pretty bad news for LTO. Switching the triple to x86_64-linux-gnu makes it work
as well.

I'm attaching the trivial textual LLVM assembly. The stack trace is:

Assertion failed: Val && "isa<> used on a null pointer", file C:\LDC\llvm-
project\llvm\include\llvm/Support/Casting.h, line 104
 #0 0x00007ff6d3c4bfd6 HandleAbort C:\LDC\llvm-project\llvm\lib\Support\Windows\Signals.inc:408:0
 #1 0x00007ff6d4277cd4 raise minkernel\crts\ucrt\src\appcrt\misc\signal.cpp:547:0
 #2 0x00007ff6d4266708 abort minkernel\crts\ucrt\src\appcrt\startup\abort.cpp:71:0
 #3 0x00007ff6d426d518 common_assert_to_stderr<wchar_t> minkernel\crts\ucrt\src\appcrt\startup\assert.cpp:175:0
 #4 0x00007ff6d426d63a _wassert minkernel\crts\ucrt\src\appcrt\startup\assert.cpp:443:0
 #5 0x00007ff6d349bc1f llvm::ValueEnumerator::EnumerateType(class llvm::Type *) C:\LDC\llvm-project\llvm\lib\Bitcode\Writer\ValueEnumerator.cpp:916:0
 #6 0x00007ff6d349fb90 llvm::ValueEnumerator::incorporateFunction(class llvm::Function const &) C:\LDC\llvm-project\llvm\lib\Bitcode\Writer\ValueEnumerator.cpp:1001:0
 #7 0x00007ff6d346f499 llvm::SmallVectorTemplateCommon<unsigned int,void>::getFirstEl C:\LDC\llvm-project\llvm\include\llvm\ADT\SmallVector.h:114:0
 #8 0x00007ff6d346f499 llvm::SmallVectorTemplateCommon<unsigned int,void>::SmallVectorTemplateCommon C:\LDC\llvm-project\llvm\include\llvm\ADT\SmallVector.h:121:0
 #9 0x00007ff6d346f499 llvm::SmallVectorTemplateBase<unsigned int,1>::SmallVectorTemplateBase C:\LDC\llvm-project\llvm\include\llvm\ADT\SmallVector.h:472:0
#10 0x00007ff6d346f499 llvm::SmallVectorImpl<unsigned int>::SmallVectorImpl
C:\LDC\llvm-project\llvm\include\llvm\ADT\SmallVector.h:573:0
#11 0x00007ff6d346f499 llvm::SmallVector<unsigned int,64>::SmallVector
C:\LDC\llvm-project\llvm\include\llvm\ADT\SmallVector.h:1171:0
#12 0x00007ff6d346f499 `anonymous
namespace'::ModuleBitcodeWriter::writeFunction C:\LDC\llvm-
project\llvm\lib\Bitcode\Writer\BitcodeWriter.cpp:3268:0
#13 0x00007ff6d3460376 llvm::operator!= C:\LDC\llvm-
project\llvm\include\llvm\ADT\ilist_iterator.h:148:0
#14 0x00007ff6d3460376 `anonymous namespace'::ModuleBitcodeWriter::write
C:\LDC\llvm-project\llvm\lib\Bitcode\Writer\BitcodeWriter.cpp:4396:0
#15 0x00007ff6d34601e7 `anonymous
namespace'::ModuleBitcodeWriterBase::~ModuleBitcodeWriterBase C:\LDC\llvm-
project\llvm\lib\Bitcode\Writer\BitcodeWriter.cpp:156:0
#16 0x00007ff6d34601e7 llvm::BitcodeWriter::writeModule(class llvm::Module
const &, bool, class llvm::ModuleSummaryIndex const *, bool, class
std::array<unsigned int, 5> *) C:\LDC\llvm-
project\llvm\lib\Bitcode\Writer\BitcodeWriter.cpp:4576:0
#17 0x00007ff6d3460bd7 llvm::WriteBitcodeToFile(class llvm::Module const &,
class llvm::raw_ostream &, bool, class llvm::ModuleSummaryIndex const *, bool,
class std::array<unsigned int, 5> *) C:\LDC\llvm-
project\llvm\lib\Bitcode\Writer\BitcodeWriter.cpp:4603:0
#18 0x00007ff6d125a498 writeModule(class llvm::Module *, char const *)
C:\LDC\ldc\driver\toobj.cpp:390:0
#19 0x00007ff6d11e55aa
std::unique_ptr<llvm::ToolOutputFile,std::default_delete<llvm::ToolOutputFile>
>::operator bool C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\memory:2672:0
#20 0x00007ff6d11e55aa ldc::CodeGenerator::writeAndFreeLLModule(char const *)
C:\LDC\ldc\driver\codegenerator.cpp:274:0
#21 0x00007ff6d11e611e Logger::enabled C:\LDC\ldc\gen\logger.h:106:0
#22 0x00007ff6d11e611e ldc::CodeGenerator::emit(class Module *)
C:\LDC\ldc\driver\codegenerator.cpp:282:0
#23 0x00007ff6d1176592 llvm::timeTraceProfilerEnabled C:\LDC\LLVM-
x64\include\llvm\Support\TimeProfiler.h:34:0
#24 0x00007ff6d1176592 TimeTraceScope::~TimeTraceScope
C:\LDC\ldc\driver\timetrace.h:56:0
#25 0x00007ff6d1176592 codegenModules(struct Array<class Module *> &)
C:\LDC\ldc\driver\main.cpp:1197:0
#26 0x00007ff6d103ebe9 mars_mainBody(struct Param &, struct Array<char const *>
&, struct Array<char const *> &) C:\LDC\ldc\dmd\mars.d:882:0
#27 0x00007ff6d1174975 cppmain(void) C:\LDC\ldc\driver\main.cpp:1141:0
#28 0x00007ff6d4052cc9 _D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv
(C:\LDC\ninja-ldc\bin\ldc2.exe+0x3102cc9)
#29 0x00007ff6d4052997 _d_run_main2 (C:\LDC\ninja-ldc\bin\ldc2.exe+0x3102997)
#30 0x00007ff6d4052c53 _d_wrun_main (C:\LDC\ninja-ldc\bin\ldc2.exe+0x3102c53)
#31 0x00007ff6d11740a3 wmain C:\LDC\ldc\driver\main.cpp:1007:0
Quuxplusone commented 3 years ago

Attached file_49919.txt (1187 bytes, text/plain): .ll file

Quuxplusone commented 3 years ago

The reason is that ValueEnumerator::incorporateFunction assumes all sret and byval parameters have associated type information.

Quuxplusone commented 3 years ago

Is there a fix for this?

Quuxplusone commented 3 years ago
From separate email from Martin Kinkelin
> it was a regression, and the extra type annotations being mandatory
> (well, for bitcode generation only) not mentioned in the LLVM 12.0.0
> changelog IIRC. I've added them in our frontend in the meantime and
> haven't tested any more recent LLVM versions. I've quickly glanced at
> the code in LLVM 12.0.1, and it still seems to assume the types are
> non-null in
>
https://github.com/llvm/llvmproject/blob/fed41342a82f5a3a9201819a82bf7a48313e296b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp#L1003-L1006.

Tom,
Would it still make sense to backport Martin's fix to the 12.x line?
Quuxplusone commented 3 years ago
corrected mangled URL:
https://github.com/llvm/llvm-project/blob/fed41342a82f5a3a9201819a82bf7a48313e296b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp#L1003-L1006
Quuxplusone commented 3 years ago

It's too late, 12.0.1 has already been released.