<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - OpenMP IRBuilder passes invalid DISubprogram to CodeExtractor"
href="https://bugs.llvm.org/show_bug.cgi?id=44560">44560</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>OpenMP IRBuilder passes invalid DISubprogram to CodeExtractor
</td>
</tr>
<tr>
<th>Product</th>
<td>OpenMP
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Clang Compiler Support
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>vsk@apple.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>OpenMP passes a function with an invalid DISubprogram to CodeExtractor.
(I noticed this while working on a patch that teaches CodeExtractor to transfer
debug info into extracted functions.)
Steps to reproduce:
1) Add the following verification step to CodeExtractor::extractCodeRegion:
```
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -1520,10 +1520,15 @@ CodeExtractor::extractCodeRegion(const
CodeExtractorAnalysisCache &CEAC) {
// Assumption: this is a single-entry code region, and the header is the
first
// block in the region.
BasicBlock *header = *Blocks.begin();
Function *oldFunction = header->getParent();
+ if (verifyFunction(*oldFunction, &errs())) {
+ oldFunction->dump();
+ report_fatal_error("verification of oldFunction failed!");
+ }
+
```
2) Run the clang/test/OpenMP/parallel_codegen.cpp test.
As an alternative to step (1), just add "-mllvm -debug-only=code-extractor" to
the clang invocations in clang/test/OpenMP/parallel_codegen.cpp.
Results:
The IR is invalid before it gets to CodeExtractor (which hasn't
touched/modified it):
```
Expected no forward declarations!
!10 = <temporary!> !{}
```
The problem is that the "retainedNodes" field of a DISubprogram is a temporary
metadata node. This suggests that `DIBuilder::finalizeSubprogram()` has not
been called.
Backtrace:
```
* frame #0: 0x0000000101ec3730 clang`llvm::report_fatal_error(char const*,
bool)
frame #1: 0x0000000101fa32c7
clang`llvm::CodeExtractor::extractCodeRegion(this=0x00007ffeefbfa150,
CEAC=0x00007ffeefbfa1e0) at CodeExtractor.cpp:1527:5
frame #2: 0x0000000103cf1562
clang`llvm::OpenMPIRBuilder::CreateParallel(llvm::OpenMPIRBuilder::LocationDescription
const&, llvm::function_ref<void (llvm::IRBuilderBase::InsertPoint,
llvm::IRBuilderBase::InsertPoint, llvm::BasicBlock&)>,
llvm::function_ref<llvm::IRBuilderBase::InsertPoint (llvm::IRBuilderBase::In
sertPoint, llvm::IRBuilderBase::InsertPoint, llvm::Value&, llvm::Value*&)>,
std::__1::function<void (llvm::IRBuilderBase::InsertPoint)>, llvm::Value*,
llvm::Value*, llvm::omp::ProcBindKind, bool) + 5730
frame #3: 0x000000010249b44d
clang`clang::CodeGen::CodeGenFunction::EmitOMPParallelDirective(clang::OMPParallelDirective
const&) + 653
frame #4: 0x0000000102483a25
clang`clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*,
llvm::ArrayRef<clang::Attr const*>) + 1093
frame #5: 0x000000010248da51
clang`clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
const&, bool, clang::CodeGen::AggValueSlot) + 609
frame #6: 0x00000001024d8bdd
clang`clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&) + 1661
frame #7: 0x00000001024f617e
clang`clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*) + 574
frame #8: 0x00000001024eebd7
clang`clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*) + 423
frame #9: 0x00000001024fa0b6
clang`clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) + 150
frame #10: 0x0000000102583120 clang`(anonymous
namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) + 160
frame #11: 0x00000001024ce1fa
clang`clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) + 186
frame #12: 0x0000000102927cb9
clang`clang::ASTReader::PassInterestingDeclsToConsumer() + 297
frame #13: 0x00000001028bbfef clang`non-virtual thunk to
clang::ASTReader::StartTranslationUnit(clang::ASTConsumer*) + 31
frame #14: 0x0000000102f7f6a2 clang`clang::ParseAST(clang::Sema&, bool,
bool) + 386
frame #15: 0x00000001027f5443 clang`clang::FrontendAction::Execute() + 163
frame #16: 0x00000001027823e3
clang`clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1683
frame #17: 0x000000010286eaa2
clang`clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1458
frame #18: 0x0000000100008044 clang`cc1_main(llvm::ArrayRef<char const*>,
char const*, void*) + 2436
frame #19: 0x0000000100005a8c clang`main + 11964
```</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>