[PATCH] D59411: [LLD][COFF] Improve checkFailIfMismatch
Alexandre Ganea via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 15 06:07:29 PDT 2019
aganea created this revision.
aganea added reviewers: rnk, ruiu.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
As suggested here <https://reviews.llvm.org/D58910#1425484>, defer a call to `toString(File)` until it's really needed (if there's an error)
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D59411
Files:
COFF/Config.h
COFF/Driver.cpp
COFF/Driver.h
COFF/DriverUtils.cpp
Index: COFF/DriverUtils.cpp
===================================================================
--- COFF/DriverUtils.cpp
+++ COFF/DriverUtils.cpp
@@ -698,16 +698,20 @@
// Parses a string in the form of "key=value" and check
// if value matches previous values for the same key.
-void checkFailIfMismatch(StringRef Arg, StringRef Source) {
+void checkFailIfMismatch(StringRef Arg, InputFile *Source) {
StringRef K, V;
std::tie(K, V) = Arg.split('=');
if (K.empty() || V.empty())
fatal("/failifmismatch: invalid argument: " + Arg);
- std::pair<StringRef, StringRef> Existing = Config->MustMatch[K];
+ std::pair<StringRef, InputFile *> Existing = Config->MustMatch[K];
if (!Existing.first.empty() && V != Existing.first) {
+ StringRef CmdLine = "cmd-line";
+ std::string SourceStr = Source ? toString(Source) : CmdLine;
+ std::string ExistingStr =
+ Existing.second ? toString(Existing.second) : CmdLine;
fatal("/failifmismatch: mismatch detected for '" + K + "':\n>>> " +
- Existing.second + " has value " + Existing.first + "\n>>> " +
- Source + " has value " + V);
+ ExistingStr + " has value " + Existing.first + "\n>>> " +
+ SourceStr + " has value " + V);
}
Config->MustMatch[K] = {V, Source};
}
Index: COFF/Driver.h
===================================================================
--- COFF/Driver.h
+++ COFF/Driver.h
@@ -180,7 +180,7 @@
// if value matches previous values for the key.
// This feature used in the directive section to reject
// incompatible objects.
-void checkFailIfMismatch(StringRef Arg, StringRef Source);
+void checkFailIfMismatch(StringRef Arg, InputFile *Source);
// Convert Windows resource files (.res files) to a .obj file.
MemoryBufferRef convertResToCOFF(ArrayRef<MemoryBufferRef> MBs);
Index: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ COFF/Driver.cpp
@@ -314,7 +314,7 @@
Config->Entry = addUndefined(mangle(Arg->getValue()));
break;
case OPT_failifmismatch:
- checkFailIfMismatch(Arg->getValue(), toString(File));
+ checkFailIfMismatch(Arg->getValue(), File);
break;
case OPT_incl:
addUndefined(Arg->getValue());
@@ -1283,7 +1283,7 @@
// Handle /failifmismatch
for (auto *Arg : Args.filtered(OPT_failifmismatch))
- checkFailIfMismatch(Arg->getValue(), "cmd-line");
+ checkFailIfMismatch(Arg->getValue(), nullptr);
// Handle /merge
for (auto *Arg : Args.filtered(OPT_merge))
Index: COFF/Config.h
===================================================================
--- COFF/Config.h
+++ COFF/Config.h
@@ -28,6 +28,7 @@
class DefinedRelative;
class StringChunk;
class Symbol;
+class InputFile;
// Short aliases.
static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
@@ -166,7 +167,7 @@
std::map<std::string, int> AlignComm;
// Used for /failifmismatch.
- std::map<StringRef, std::pair<StringRef, std::string>> MustMatch;
+ std::map<StringRef, std::pair<StringRef, InputFile *>> MustMatch;
// Used for /alternatename.
std::map<StringRef, StringRef> AlternateNames;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59411.190814.patch
Type: text/x-patch
Size: 3163 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190315/1e6271c4/attachment.bin>
More information about the llvm-commits
mailing list