Skip to content

Commit e2d6462

Browse files
committed
Re-apply "[ORC] Add optional context string to duplicate symbol definition..."
This reapplies b0979b8, which was reverted in 370aecb due to bot failures. The failures were caused by typos in the testcase that are fixed in this patch.
1 parent 892bfa9 commit e2d6462

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcError.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ class DuplicateDefinition : public ErrorInfo<DuplicateDefinition> {
4848
public:
4949
static char ID;
5050

51-
DuplicateDefinition(std::string SymbolName);
51+
DuplicateDefinition(std::string SymbolName,
52+
std::optional<std::string> Context = {});
5253
std::error_code convertToErrorCode() const override;
5354
void log(raw_ostream &OS) const override;
5455
const std::string &getSymbolName() const;
56+
const std::optional<std::string> &getContext() const;
57+
5558
private:
5659
std::string SymbolName;
60+
std::optional<std::string> Context;
5761
};
5862

5963
class JITSymbolNotFound : public ErrorInfo<JITSymbolNotFound> {

llvm/lib/ExecutionEngine/Orc/Core.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,8 @@ JITDylib::defineMaterializing(MaterializationResponsibility &FromMR,
731731
Symbols.erase(Symbols.find_as(S));
732732

733733
// FIXME: Return all duplicates.
734-
return make_error<DuplicateDefinition>(std::string(*Name));
734+
return make_error<DuplicateDefinition>(
735+
std::string(*Name), "defineMaterializing operation");
735736
}
736737

737738
// Otherwise just make a note to discard this symbol after the loop.
@@ -1424,7 +1425,8 @@ Error JITDylib::defineImpl(MaterializationUnit &MU) {
14241425
if (!Duplicates.empty()) {
14251426
LLVM_DEBUG(
14261427
{ dbgs() << " Error: Duplicate symbols " << Duplicates << "\n"; });
1427-
return make_error<DuplicateDefinition>(std::string(**Duplicates.begin()));
1428+
return make_error<DuplicateDefinition>(std::string(**Duplicates.begin()),
1429+
MU.getName().str());
14281430
}
14291431

14301432
// Discard any overridden defs in this MU.

llvm/lib/ExecutionEngine/Orc/Shared/OrcError.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,28 @@ std::error_code orcError(OrcErrorCode ErrCode) {
8686
return std::error_code(static_cast<UT>(ErrCode), getOrcErrCat());
8787
}
8888

89-
DuplicateDefinition::DuplicateDefinition(std::string SymbolName)
90-
: SymbolName(std::move(SymbolName)) {}
89+
DuplicateDefinition::DuplicateDefinition(std::string SymbolName,
90+
std::optional<std::string> Context)
91+
: SymbolName(std::move(SymbolName)), Context(std::move(Context)) {}
9192

9293
std::error_code DuplicateDefinition::convertToErrorCode() const {
9394
return orcError(OrcErrorCode::DuplicateDefinition);
9495
}
9596

9697
void DuplicateDefinition::log(raw_ostream &OS) const {
97-
OS << "Duplicate definition of symbol '" << SymbolName << "'";
98+
if (Context)
99+
OS << "In " << *Context << ", ";
100+
OS << "duplicate definition of symbol '" << SymbolName << "'";
98101
}
99102

100103
const std::string &DuplicateDefinition::getSymbolName() const {
101104
return SymbolName;
102105
}
103106

107+
const std::optional<std::string> &DuplicateDefinition::getContext() const {
108+
return Context;
109+
}
110+
104111
JITSymbolNotFound::JITSymbolNotFound(std::string SymbolName)
105112
: SymbolName(std::move(SymbolName)) {}
106113

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
define i32 @main(i32 %argc, i8** %argv) {
2+
entry:
3+
ret i32 42
4+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: rm -rf %t && mkdir %t
2+
# RUN: llc -filetype=obj -o %t/main-ret-0.o %S/Inputs/main-ret-0.ll
3+
# RUN: llc -filetype=obj -o %t/main-ret-42.o %S/Inputs/main-ret-42.ll
4+
# RUN: not llvm-jitlink -noexec %t/main-ret-0.o %t/main-ret-42.o 2>&1 \
5+
# RUN: | FileCheck %s
6+
#
7+
# Trigger a duplicate definition error by trying to link two main functions,
8+
# check that the error message includes the file that introduced the duplicate.
9+
#
10+
# CHECK: In {{.*}}main-ret-42.o, duplicate definition of {{.*}}main

0 commit comments

Comments
 (0)