Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
llvmbot opened this issue Apr 11, 2021 · 5 comments
Open

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

llvmbot opened this issue Apr 11, 2021 · 5 comments
Labels
bugzilla Issues migrated from bugzilla

Comments

@llvmbot
Copy link
Member

llvmbot commented Apr 11, 2021

Bugzilla Link 49919
Version trunk
OS Windows NT
Blocks #48246 #48661
Attachments .ll file
Reporter LLVM Bugzilla Contributor
CC @davidbolvansky,@slacka,@tstellar

Extended Description

While testing LLVM 12 RC5+ (fa0971b) 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::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 #&#8203;13 0x00007ff6d3460376 llvm::operator!= C:\LDC\llvm-project\llvm\include\llvm\ADT\ilist_iterator.h:148:0 #&#8203;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_deletellvm::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

@llvmbot
Copy link
Member Author

llvmbot commented Apr 27, 2021

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

@tstellar
Copy link
Collaborator

tstellar commented Jun 4, 2021

Is there a fix for this?

@slacka
Copy link
Mannequin

slacka mannequin commented Jul 10, 2021

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?

@slacka
Copy link
Mannequin

slacka mannequin commented Jul 10, 2021

corrected mangled URL:

if (I.hasAttribute(Attribute::ByVal))
EnumerateType(I.getParamByValType());
else if (I.hasAttribute(Attribute::StructRet))
EnumerateType(I.getParamStructRetType());

@tstellar
Copy link
Collaborator

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

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

2 participants