[llvm-bugs] [Bug 45967] New: Crash in verifyFunction due to bad use of GlobalVariable
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon May 18 00:38:37 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=45967
Bug ID: 45967
Summary: Crash in verifyFunction due to bad use of
GlobalVariable
Product: new-bugs
Version: 10.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: rarrum at gmail.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org
This is occurring for me on version 10.0.0 (both the downloaded Release and
locally built Debug). From glancing at the code corresponding to the backtrace
below it looks like the master branch has this same problem, though I have not
tried to build it to verify for certain.
--
Backtrace for 10.0.0:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff74d47f0 in std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::length() const () from
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
(gdb) bt
#0 0x00007ffff74d47f0 in std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >::length() const () from
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
#1 0x0000555555834b5f in llvm::raw_ostream::operator<< (this=0x7fffffffd640,
Str=<error reading variable: Cannot access memory at address 0xb8>)
at
/home/luke/code/llvmgit/llvm-project/llvm/include/llvm/Support/raw_ostream.h:205
#2 0x0000555555a27b81 in llvm::VerifierSupport::Write (this=0x7fffffffceb0,
M=0x0)
at /home/luke/code/llvmgit/llvm-project/llvm/lib/IR/Verifier.cpp:141
#3 0x0000555555a446fa in llvm::VerifierSupport::WriteTs<llvm::Module*>
(this=0x7fffffffceb0,
V1=@0x7fffffffcbe0: 0x0)
at /home/luke/code/llvmgit/llvm-project/llvm/lib/IR/Verifier.cpp:204
#4 0x0000555555a426bf in llvm::VerifierSupport::WriteTs<llvm::GlobalValue*,
llvm::Module*> (
this=0x7fffffffceb0, V1=@0x7fffffffcb20: 0x555559076ed8)
at /home/luke/code/llvmgit/llvm-project/llvm/lib/IR/Verifier.cpp:205
#5 0x0000555555a3ecfd in llvm::VerifierSupport::WriteTs<llvm::Module const*,
llvm::GlobalValue*, llvm::Module*> (this=0x7fffffffceb0, V1=@0x7fffffffcb30:
0x555559077a20)
at /home/luke/code/llvmgit/llvm-project/llvm/lib/IR/Verifier.cpp:205
#6 0x0000555555a397de in llvm::VerifierSupport::WriteTs<llvm::Instruction*,
llvm::Module const*, llvm::GlobalValue*, llvm::Module*> (this=0x7fffffffceb0,
V1=@0x7fffffffcb28: 0x55555907b0d8)
at /home/luke/code/llvmgit/llvm-project/llvm/lib/IR/Verifier.cpp:205
#7 0x0000555555a2fd88 in
llvm::VerifierSupport::CheckFailed<llvm::Instruction*, llvm::Module const*,
llvm::GlobalValue*, llvm::Module*> (this=0x7fffffffceb0, Message=...,
V1=@0x7fffffffcb28: 0x55555907b0d8)
at /home/luke/code/llvmgit/llvm-project/llvm/lib/IR/Verifier.cpp:229
#8 0x0000555555a1c2d3 in (anonymous namespace)::Verifier::visitInstruction (
this=0x7fffffffceb0, I=...)
at /home/luke/code/llvmgit/llvm-project/llvm/lib/IR/Verifier.cpp:4170
#9 0x0000555555a17ebd in (anonymous namespace)::Verifier::visitLoadInst
(this=0x7fffffffceb0,
LI=...) at
/home/luke/code/llvmgit/llvm-project/llvm/lib/IR/Verifier.cpp:3429
#10 0x0000555555a24b6b in llvm::InstVisitor<(anonymous namespace)::Verifier,
void>::visitLoad (
this=0x7fffffffceb0, I=...)
at
/home/luke/code/llvmgit/llvm-project/llvm/include/llvm/IR/Instruction.def:172
#11 0x0000555555a23e40 in llvm::InstVisitor<(anonymous namespace)::Verifier,
void>::visit (
this=0x7fffffffceb0, I=...)
at
/home/luke/code/llvmgit/llvm-project/llvm/include/llvm/IR/Instruction.def:172
#12 0x0000555555a05680 in (anonymous namespace)::Verifier::visit
(this=0x7fffffffceb0, I=...)
at /home/luke/code/llvmgit/llvm-project/llvm/lib/IR/Verifier.cpp:550
#13 0x0000555555a25669 in llvm::InstVisitor<(anonymous namespace)::Verifier,
void>::visit<llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction,
true, false, void>, false, false> > (this=0x7fffffffceb0, Start=..., End=...)
at
/home/luke/code/llvmgit/llvm-project/llvm/include/llvm/IR/InstVisitor.h:91
#14 0x0000555555a2529a in llvm::InstVisitor<(anonymous namespace)::Verifier,
void>::visit (
this=0x7fffffffceb0, BB=...)
at
/home/luke/code/llvmgit/llvm-project/llvm/include/llvm/IR/InstVisitor.h:106
#15 0x0000555555a24695 in llvm::InstVisitor<(anonymous namespace)::Verifier,
void>::visit<llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::BasicBlock,
true, false, void>, false, false> > (this=0x7fffffffceb0, Start=..., End=...)
at
/home/luke/code/llvmgit/llvm-project/llvm/include/llvm/IR/InstVisitor.h:91
#16 0x0000555555a23ae2 in llvm::InstVisitor<(anonymous namespace)::Verifier,
void>::visit (
this=0x7fffffffceb0, F=...)
at
/home/luke/code/llvmgit/llvm-project/llvm/include/llvm/IR/InstVisitor.h:102
#17 0x0000555555a05146 in (anonymous namespace)::Verifier::verify
(this=0x7fffffffceb0, F=...)
at /home/luke/code/llvmgit/llvm-project/llvm/lib/IR/Verifier.cpp:353
#18 0x0000555555a21c05 in llvm::verifyFunction (f=..., OS=0x7fffffffd640)
at /home/luke/code/llvmgit/llvm-project/llvm/lib/IR/Verifier.cpp:5103
#19 0x0000555555806384 in (anonymous
namespace)::CompilerData::AddGlobalFunctionBody (
this=0x7fffffffd8b0, fi=..., generalSourceLocation=...)
at /home/luke/code/cbreak/CBreakCompiler/src/IRCompiler.cpp:270
#20 0x0000555555807f81 in CBreakCompiler::GenerateIR (
parsedFragments=std::vector of length 1, capacity 1 = {...})
at /home/luke/code/cbreak/CBreakCompiler/src/IRCompiler.cpp:455
#21 0x00005555557eaf60 in main (argc=6, argv=0x7fffffffdee8)
at /home/luke/code/cbreak/CBreakCompiler/src/main.cpp:137
--
The problem starts with Verifier.cpp - Verifier::visitInstruction (line 4170 in
10.0.0):
Assert(GV->getParent() == &M, "Referencing global in another module!", &I,
&M, GV, GV->getParent());
(gdb) frame 8
#8 0x0000555555a1c2d3 in (anonymous namespace)::Verifier::visitInstruction (
this=0x7fffffffceb0, I=...)
at /home/luke/code/llvmgit/llvm-project/llvm/lib/IR/Verifier.cpp:4170
4170 Assert(GV->getParent() == &M, "Referencing global in another
module!", &I,
(gdb) print &M
$1 = (const llvm::Module *) 0x555559077a20
(gdb) print GV
$2 = (llvm::GlobalValue *) 0x555559076ed8
(gdb) print GV->getParent()
$3 = (llvm::Module *) 0x0
Note that GV->getParent() which is nullptr is passed on as a parameter to stuff
which eventually calls VerifierSupport::WriteTs which eventually calls
VerifierSupport::Write.
(gdb) frame 2
#2 0x0000555555a27b81 in llvm::VerifierSupport::Write (this=0x7fffffffceb0,
M=0x0)
at /home/luke/code/llvmgit/llvm-project/llvm/lib/IR/Verifier.cpp:141
141 *OS << "; ModuleID = '" << M->getModuleIdentifier() << "'\n";
(gdb) print M
$6 = (const llvm::Module *) 0x0
M->getModuleIdentifier() is a nullptr dereference.
--
Some context on how I made this happen: I'm working on adding global variable
support to my compiler, and I suspect I've done something wrong with how I
create the GlobalVariable object. Summary of what my code should be doing
here..
During setup, after creating LLVMContext and such:
GlobalsBlock = llvm::BasicBlock::Create(LLVMContext, "globals");
During an early part of the code where I'm setting up globals:
IRBuilder.SetInsertPoint(GlobalsBlock);
std::make_unique<llvm::GlobalVariable>(type->IRType, false,
llvm::GlobalValue::InternalLinkage, nullptr, vi.Name);
During a later part of the code where I'm filling in function bodies:
llvm::BasicBlock *bbFunction = llvm::BasicBlock::Create(LLVMContext,
"function " + fi.Name, fd.IRFunction);
IRBuilder.SetInsertPoint(bbFunction);
During that while evaluating an expression:
IRBuilder.CreateLoad(gvar->second.IRGlobalVariable.get());
It's that last call to CreateLoad that appears to be triggering the crash in
the verifier.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200518/b0684eac/attachment-0001.html>
More information about the llvm-bugs
mailing list