rustc: Start implementing compat with LLVM 9
This commit doesn't actually migrate to LLVM 9, but it brings our own C++ bindings in line with LLVM 9 and able to compile against tip of tree. The changes made were: * The `MainSubprogram` flag for debuginfo moved between flag types. * Iteration of archive members was tweaked slightly and we have to construct the two iterators before constructing the returned `RustArchiveIterator` value. * The `getOrInsertFunction` binding now returns a wrapper which we use `getCallee()` on to get the value we're interested in.
This commit is contained in:
parent
52980d0fb3
commit
d5985bc9ec
4 changed files with 44 additions and 26 deletions
|
@ -296,12 +296,6 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||||
|
|
||||||
let mut flags = DIFlags::FlagPrototyped;
|
let mut flags = DIFlags::FlagPrototyped;
|
||||||
|
|
||||||
if let Some((id, _)) = self.tcx.entry_fn(LOCAL_CRATE) {
|
|
||||||
if id == def_id {
|
|
||||||
flags |= DIFlags::FlagMainSubprogram;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.layout_of(sig.output()).abi.is_uninhabited() {
|
if self.layout_of(sig.output()).abi.is_uninhabited() {
|
||||||
flags |= DIFlags::FlagNoReturn;
|
flags |= DIFlags::FlagNoReturn;
|
||||||
}
|
}
|
||||||
|
@ -313,6 +307,11 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||||
if self.sess().opts.optimize != config::OptLevel::No {
|
if self.sess().opts.optimize != config::OptLevel::No {
|
||||||
spflags |= DISPFlags::SPFlagOptimized;
|
spflags |= DISPFlags::SPFlagOptimized;
|
||||||
}
|
}
|
||||||
|
if let Some((id, _)) = self.tcx.entry_fn(LOCAL_CRATE) {
|
||||||
|
if id == def_id {
|
||||||
|
spflags |= DISPFlags::SPFlagMainSubprogram;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let fn_metadata = unsafe {
|
let fn_metadata = unsafe {
|
||||||
llvm::LLVMRustDIBuilderCreateFunction(
|
llvm::LLVMRustDIBuilderCreateFunction(
|
||||||
|
|
|
@ -588,7 +588,6 @@ pub mod debuginfo {
|
||||||
const FlagIntroducedVirtual = (1 << 18);
|
const FlagIntroducedVirtual = (1 << 18);
|
||||||
const FlagBitField = (1 << 19);
|
const FlagBitField = (1 << 19);
|
||||||
const FlagNoReturn = (1 << 20);
|
const FlagNoReturn = (1 << 20);
|
||||||
const FlagMainSubprogram = (1 << 21);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -603,6 +602,7 @@ pub mod debuginfo {
|
||||||
const SPFlagLocalToUnit = (1 << 2);
|
const SPFlagLocalToUnit = (1 << 2);
|
||||||
const SPFlagDefinition = (1 << 3);
|
const SPFlagDefinition = (1 << 3);
|
||||||
const SPFlagOptimized = (1 << 4);
|
const SPFlagOptimized = (1 << 4);
|
||||||
|
const SPFlagMainSubprogram = (1 << 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,14 @@ struct RustArchiveIterator {
|
||||||
bool First;
|
bool First;
|
||||||
Archive::child_iterator Cur;
|
Archive::child_iterator Cur;
|
||||||
Archive::child_iterator End;
|
Archive::child_iterator End;
|
||||||
Error Err;
|
std::unique_ptr<Error> Err;
|
||||||
|
|
||||||
RustArchiveIterator() : First(true), Err(Error::success()) {}
|
RustArchiveIterator(Archive::child_iterator Cur, Archive::child_iterator End,
|
||||||
|
std::unique_ptr<Error> Err)
|
||||||
|
: First(true),
|
||||||
|
Cur(Cur),
|
||||||
|
End(End),
|
||||||
|
Err(std::move(Err)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class LLVMRustArchiveKind {
|
enum class LLVMRustArchiveKind {
|
||||||
|
@ -84,15 +89,14 @@ extern "C" void LLVMRustDestroyArchive(LLVMRustArchiveRef RustArchive) {
|
||||||
extern "C" LLVMRustArchiveIteratorRef
|
extern "C" LLVMRustArchiveIteratorRef
|
||||||
LLVMRustArchiveIteratorNew(LLVMRustArchiveRef RustArchive) {
|
LLVMRustArchiveIteratorNew(LLVMRustArchiveRef RustArchive) {
|
||||||
Archive *Archive = RustArchive->getBinary();
|
Archive *Archive = RustArchive->getBinary();
|
||||||
RustArchiveIterator *RAI = new RustArchiveIterator();
|
std::unique_ptr<Error> Err = llvm::make_unique<Error>(Error::success());
|
||||||
RAI->Cur = Archive->child_begin(RAI->Err);
|
auto Cur = Archive->child_begin(*Err);
|
||||||
if (RAI->Err) {
|
if (*Err) {
|
||||||
LLVMRustSetLastError(toString(std::move(RAI->Err)).c_str());
|
LLVMRustSetLastError(toString(std::move(*Err)).c_str());
|
||||||
delete RAI;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
RAI->End = Archive->child_end();
|
auto End = Archive->child_end();
|
||||||
return RAI;
|
return new RustArchiveIterator(Cur, End, std::move(Err));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" LLVMRustArchiveChildConstRef
|
extern "C" LLVMRustArchiveChildConstRef
|
||||||
|
@ -108,8 +112,8 @@ LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef RAI) {
|
||||||
// but instead advance it *before* fetching the child in all later calls.
|
// but instead advance it *before* fetching the child in all later calls.
|
||||||
if (!RAI->First) {
|
if (!RAI->First) {
|
||||||
++RAI->Cur;
|
++RAI->Cur;
|
||||||
if (RAI->Err) {
|
if (*RAI->Err) {
|
||||||
LLVMRustSetLastError(toString(std::move(RAI->Err)).c_str());
|
LLVMRustSetLastError(toString(std::move(*RAI->Err)).c_str());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -117,7 +117,11 @@ extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M,
|
||||||
const char *Name,
|
const char *Name,
|
||||||
LLVMTypeRef FunctionTy) {
|
LLVMTypeRef FunctionTy) {
|
||||||
return wrap(
|
return wrap(
|
||||||
unwrap(M)->getOrInsertFunction(Name, unwrap<FunctionType>(FunctionTy)));
|
unwrap(M)->getOrInsertFunction(Name, unwrap<FunctionType>(FunctionTy))
|
||||||
|
#if LLVM_VERSION_GE(9, 0)
|
||||||
|
.getCallee()
|
||||||
|
#endif
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" LLVMValueRef
|
extern "C" LLVMValueRef
|
||||||
|
@ -417,7 +421,6 @@ enum class LLVMRustDIFlags : uint32_t {
|
||||||
FlagIntroducedVirtual = (1 << 18),
|
FlagIntroducedVirtual = (1 << 18),
|
||||||
FlagBitField = (1 << 19),
|
FlagBitField = (1 << 19),
|
||||||
FlagNoReturn = (1 << 20),
|
FlagNoReturn = (1 << 20),
|
||||||
FlagMainSubprogram = (1 << 21),
|
|
||||||
// Do not add values that are not supported by the minimum LLVM
|
// Do not add values that are not supported by the minimum LLVM
|
||||||
// version we support! see llvm/include/llvm/IR/DebugInfoFlags.def
|
// version we support! see llvm/include/llvm/IR/DebugInfoFlags.def
|
||||||
};
|
};
|
||||||
|
@ -508,9 +511,6 @@ static DINode::DIFlags fromRust(LLVMRustDIFlags Flags) {
|
||||||
if (isSet(Flags & LLVMRustDIFlags::FlagNoReturn)) {
|
if (isSet(Flags & LLVMRustDIFlags::FlagNoReturn)) {
|
||||||
Result |= DINode::DIFlags::FlagNoReturn;
|
Result |= DINode::DIFlags::FlagNoReturn;
|
||||||
}
|
}
|
||||||
if (isSet(Flags & LLVMRustDIFlags::FlagMainSubprogram)) {
|
|
||||||
Result |= DINode::DIFlags::FlagMainSubprogram;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
@ -525,6 +525,7 @@ enum class LLVMRustDISPFlags : uint32_t {
|
||||||
SPFlagLocalToUnit = (1 << 2),
|
SPFlagLocalToUnit = (1 << 2),
|
||||||
SPFlagDefinition = (1 << 3),
|
SPFlagDefinition = (1 << 3),
|
||||||
SPFlagOptimized = (1 << 4),
|
SPFlagOptimized = (1 << 4),
|
||||||
|
SPFlagMainSubprogram = (1 << 5),
|
||||||
// Do not add values that are not supported by the minimum LLVM
|
// Do not add values that are not supported by the minimum LLVM
|
||||||
// version we support! see llvm/include/llvm/IR/DebugInfoFlags.def
|
// version we support! see llvm/include/llvm/IR/DebugInfoFlags.def
|
||||||
// (In LLVM < 8, createFunction supported these as separate bool arguments.)
|
// (In LLVM < 8, createFunction supported these as separate bool arguments.)
|
||||||
|
@ -575,6 +576,11 @@ static DISubprogram::DISPFlags fromRust(LLVMRustDISPFlags SPFlags) {
|
||||||
if (isSet(SPFlags & LLVMRustDISPFlags::SPFlagOptimized)) {
|
if (isSet(SPFlags & LLVMRustDISPFlags::SPFlagOptimized)) {
|
||||||
Result |= DISubprogram::DISPFlags::SPFlagOptimized;
|
Result |= DISubprogram::DISPFlags::SPFlagOptimized;
|
||||||
}
|
}
|
||||||
|
#if LLVM_VERSION_GE(9, 0)
|
||||||
|
if (isSet(SPFlags & LLVMRustDISPFlags::SPFlagMainSubprogram)) {
|
||||||
|
Result |= DISubprogram::DISPFlags::SPFlagMainSubprogram;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
@ -671,18 +677,27 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFunction(
|
||||||
DITemplateParameterArray TParams =
|
DITemplateParameterArray TParams =
|
||||||
DITemplateParameterArray(unwrap<MDTuple>(TParam));
|
DITemplateParameterArray(unwrap<MDTuple>(TParam));
|
||||||
#if LLVM_VERSION_GE(8, 0)
|
#if LLVM_VERSION_GE(8, 0)
|
||||||
|
DISubprogram::DISPFlags llvmSPFlags = fromRust(SPFlags);
|
||||||
|
DINode::DIFlags llvmFlags = fromRust(Flags);
|
||||||
|
#if LLVM_VERSION_LT(9, 0)
|
||||||
|
if (isSet(SPFlags & LLVMRustDISPFlags::SPFlagMainSubprogram))
|
||||||
|
llvmFlags |= DINode::DIFlags::FlagMainSubprogram;
|
||||||
|
#endif
|
||||||
DISubprogram *Sub = Builder->createFunction(
|
DISubprogram *Sub = Builder->createFunction(
|
||||||
unwrapDI<DIScope>(Scope), Name, LinkageName, unwrapDI<DIFile>(File),
|
unwrapDI<DIScope>(Scope), Name, LinkageName, unwrapDI<DIFile>(File),
|
||||||
LineNo, unwrapDI<DISubroutineType>(Ty), ScopeLine, fromRust(Flags),
|
LineNo, unwrapDI<DISubroutineType>(Ty), ScopeLine, llvmFlags,
|
||||||
fromRust(SPFlags), TParams, unwrapDIPtr<DISubprogram>(Decl));
|
llvmSPFlags, TParams, unwrapDIPtr<DISubprogram>(Decl));
|
||||||
#else
|
#else
|
||||||
bool IsLocalToUnit = isSet(SPFlags & LLVMRustDISPFlags::SPFlagLocalToUnit);
|
bool IsLocalToUnit = isSet(SPFlags & LLVMRustDISPFlags::SPFlagLocalToUnit);
|
||||||
bool IsDefinition = isSet(SPFlags & LLVMRustDISPFlags::SPFlagDefinition);
|
bool IsDefinition = isSet(SPFlags & LLVMRustDISPFlags::SPFlagDefinition);
|
||||||
bool IsOptimized = isSet(SPFlags & LLVMRustDISPFlags::SPFlagOptimized);
|
bool IsOptimized = isSet(SPFlags & LLVMRustDISPFlags::SPFlagOptimized);
|
||||||
|
DINode::DIFlags llvmFlags = fromRust(Flags);
|
||||||
|
if (isSet(SPFlags & LLVMRustDISPFlags::SPFlagMainSubprogram))
|
||||||
|
llvmFlags |= DINode::DIFlags::FlagMainSubprogram;
|
||||||
DISubprogram *Sub = Builder->createFunction(
|
DISubprogram *Sub = Builder->createFunction(
|
||||||
unwrapDI<DIScope>(Scope), Name, LinkageName, unwrapDI<DIFile>(File),
|
unwrapDI<DIScope>(Scope), Name, LinkageName, unwrapDI<DIFile>(File),
|
||||||
LineNo, unwrapDI<DISubroutineType>(Ty), IsLocalToUnit, IsDefinition,
|
LineNo, unwrapDI<DISubroutineType>(Ty), IsLocalToUnit, IsDefinition,
|
||||||
ScopeLine, fromRust(Flags), IsOptimized, TParams,
|
ScopeLine, llvmFlags, IsOptimized, TParams,
|
||||||
unwrapDIPtr<DISubprogram>(Decl));
|
unwrapDIPtr<DISubprogram>(Decl));
|
||||||
#endif
|
#endif
|
||||||
unwrap<Function>(Fn)->setSubprogram(Sub);
|
unwrap<Function>(Fn)->setSubprogram(Sub);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue