[lld] r259413 - Use dyn_cast instead of static_cast.
Pete Cooper via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 1 13:42:17 PST 2016
Author: pete
Date: Mon Feb 1 15:42:17 2016
New Revision: 259413
URL: http://llvm.org/viewvc/llvm-project?rev=259413&view=rev
Log:
Use dyn_cast instead of static_cast.
Now that MachoFile has classof(), we can use dyn_cast instead which
is actually the only safe way to handle this.
Turns out this actually manifests as a bug as we were incorrectly
casting instances which weren't MachoFile in to a MachoFile.
Unfortunately, there's no reliable way of checking for this as it
requires that the file we are looking for has a 0 at exactly the byte
we need for the load of subsectionsViaSymbols.
Modified:
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=259413&r1=259412&r2=259413&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Mon Feb 1 15:42:17 2016
@@ -377,11 +377,11 @@ void Util::processDefinedAtoms(const lld
}
void Util::processAtomAttributes(const DefinedAtom *atom) {
- auto *machoFile = static_cast<const mach_o::MachOFile *>(&atom->file());
// If the file doesn't use subsections via symbols, then make sure we don't
// add that flag to the final output file if we have a relocatable file.
- if (!machoFile->subsectionsViaSymbols())
- _subsectionsViaSymbols = false;
+ if (auto *machoFile = dyn_cast<mach_o::MachOFile>(&atom->file()))
+ if (!machoFile->subsectionsViaSymbols())
+ _subsectionsViaSymbols = false;
}
void Util::assignAtomToSection(const DefinedAtom *atom) {
More information about the llvm-commits
mailing list