[lld] r194619 - Fix indentation, use early return.
Rui Ueyama
ruiu at google.com
Wed Nov 13 15:22:01 PST 2013
Author: ruiu
Date: Wed Nov 13 17:22:00 2013
New Revision: 194619
URL: http://llvm.org/viewvc/llvm-project?rev=194619&view=rev
Log:
Fix indentation, use early return.
Modified:
lld/trunk/lib/Core/SymbolTable.cpp
Modified: lld/trunk/lib/Core/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/SymbolTable.cpp?rev=194619&r1=194618&r2=194619&view=diff
==============================================================================
--- lld/trunk/lib/Core/SymbolTable.cpp (original)
+++ lld/trunk/lib/Core/SymbolTable.cpp Wed Nov 13 17:22:00 2013
@@ -51,8 +51,7 @@ void SymbolTable::add(const DefinedAtom
assert(atom.merge() != DefinedAtom::mergeByContent);
// Track named atoms that are not scoped to file (static).
this->addByName(atom);
- }
- else if ( atom.merge() == DefinedAtom::mergeByContent ) {
+ } else if (atom.merge() == DefinedAtom::mergeByContent) {
// Named atoms cannot be merged by content.
assert(atom.name().empty());
this->addByContent(atom);
@@ -132,122 +131,118 @@ void SymbolTable::addByName(const Atom &
if (existing == nullptr) {
// Name is not in symbol table yet, add it associate with this atom.
_nameTable[name] = &newAtom;
+ return;
}
- else {
- // Name is already in symbol table and associated with another atom.
- bool useNew = true;
- switch (collide(existing->definition(), newAtom.definition())) {
- case NCR_First:
+
+ // Name is already in symbol table and associated with another atom.
+ bool useNew = true;
+ switch (collide(existing->definition(), newAtom.definition())) {
+ case NCR_First:
+ useNew = false;
+ break;
+ case NCR_Second:
+ useNew = true;
+ break;
+ case NCR_DupDef:
+ assert(existing->definition() == Atom::definitionRegular);
+ assert(newAtom.definition() == Atom::definitionRegular);
+ switch (mergeSelect(((DefinedAtom*)existing)->merge(),
+ ((DefinedAtom*)(&newAtom))->merge())) {
+ case MCR_First:
useNew = false;
break;
- case NCR_Second:
+ case MCR_Second:
useNew = true;
break;
- case NCR_DupDef:
- assert(existing->definition() == Atom::definitionRegular);
- assert(newAtom.definition() == Atom::definitionRegular);
- switch ( mergeSelect(((DefinedAtom*)existing)->merge(),
- ((DefinedAtom*)(&newAtom))->merge()) ) {
- case MCR_First:
- useNew = false;
- break;
- case MCR_Second:
- useNew = true;
- break;
- case MCR_Largest:
- useNew = true;
- break;
- case MCR_Error:
- llvm::errs() << "Duplicate symbols: "
- << existing->name()
- << ":"
- << existing->file().path()
- << " and "
- << newAtom.name()
- << ":"
- << newAtom.file().path()
- << "\n";
- llvm::report_fatal_error("duplicate symbol error");
- break;
- }
- break;
- case NCR_DupUndef: {
- const UndefinedAtom* existingUndef =
- dyn_cast<UndefinedAtom>(existing);
- const UndefinedAtom* newUndef =
- dyn_cast<UndefinedAtom>(&newAtom);
- assert(existingUndef != nullptr);
- assert(newUndef != nullptr);
- if ( existingUndef->canBeNull() == newUndef->canBeNull() ) {
- useNew = false;
- }
- else {
- if (_context.warnIfCoalesableAtomsHaveDifferentCanBeNull()) {
- // FIXME: need diagonstics interface for writing warning messages
- llvm::errs() << "lld warning: undefined symbol "
- << existingUndef->name()
- << " has different weakness in "
- << existingUndef->file().path()
- << " and in "
- << newUndef->file().path();
- }
- useNew = (newUndef->canBeNull() < existingUndef->canBeNull());
- }
- }
+ case MCR_Largest:
+ useNew = true;
break;
- case NCR_DupShLib: {
- const SharedLibraryAtom* curShLib =
- dyn_cast<SharedLibraryAtom>(existing);
- const SharedLibraryAtom* newShLib =
- dyn_cast<SharedLibraryAtom>(&newAtom);
- assert(curShLib != nullptr);
- assert(newShLib != nullptr);
- bool sameNullness = (curShLib->canBeNullAtRuntime()
- == newShLib->canBeNullAtRuntime());
- bool sameName = curShLib->loadName().equals(newShLib->loadName());
- if ( !sameName ) {
- useNew = false;
- if (_context.warnIfCoalesableAtomsHaveDifferentLoadName()) {
- // FIXME: need diagonstics interface for writing warning messages
- llvm::errs() << "lld warning: shared library symbol "
- << curShLib->name()
- << " has different load path in "
- << curShLib->file().path()
- << " and in "
- << newShLib->file().path();
- }
- }
- else if ( ! sameNullness ) {
- useNew = false;
- if (_context.warnIfCoalesableAtomsHaveDifferentCanBeNull()) {
- // FIXME: need diagonstics interface for writing warning messages
- llvm::errs() << "lld warning: shared library symbol "
- << curShLib->name()
- << " has different weakness in "
- << curShLib->file().path()
- << " and in "
- << newShLib->file().path();
- }
- }
- else {
- // Both shlib atoms are identical and can be coalesced.
- useNew = false;
- }
- }
+ case MCR_Error:
+ llvm::errs() << "Duplicate symbols: "
+ << existing->name()
+ << ":"
+ << existing->file().path()
+ << " and "
+ << newAtom.name()
+ << ":"
+ << newAtom.file().path()
+ << "\n";
+ llvm::report_fatal_error("duplicate symbol error");
break;
- default:
- llvm::report_fatal_error("SymbolTable::addByName(): unhandled switch clause");
}
- if ( useNew ) {
- // Update name table to use new atom.
- _nameTable[name] = &newAtom;
- // Add existing atom to replacement table.
- _replacedAtoms[existing] = &newAtom;
+ break;
+ case NCR_DupUndef: {
+ const UndefinedAtom* existingUndef =
+ dyn_cast<UndefinedAtom>(existing);
+ const UndefinedAtom* newUndef =
+ dyn_cast<UndefinedAtom>(&newAtom);
+ assert(existingUndef != nullptr);
+ assert(newUndef != nullptr);
+ if (existingUndef->canBeNull() == newUndef->canBeNull()) {
+ useNew = false;
+ } else {
+ if (_context.warnIfCoalesableAtomsHaveDifferentCanBeNull()) {
+ // FIXME: need diagonstics interface for writing warning messages
+ llvm::errs() << "lld warning: undefined symbol "
+ << existingUndef->name()
+ << " has different weakness in "
+ << existingUndef->file().path()
+ << " and in "
+ << newUndef->file().path();
+ }
+ useNew = (newUndef->canBeNull() < existingUndef->canBeNull());
+ }
}
- else {
- // New atom is not being used. Add it to replacement table.
- _replacedAtoms[&newAtom] = existing;
+ break;
+ case NCR_DupShLib: {
+ const SharedLibraryAtom* curShLib =
+ dyn_cast<SharedLibraryAtom>(existing);
+ const SharedLibraryAtom* newShLib =
+ dyn_cast<SharedLibraryAtom>(&newAtom);
+ assert(curShLib != nullptr);
+ assert(newShLib != nullptr);
+ bool sameNullness = (curShLib->canBeNullAtRuntime()
+ == newShLib->canBeNullAtRuntime());
+ bool sameName = curShLib->loadName().equals(newShLib->loadName());
+ if (!sameName) {
+ useNew = false;
+ if (_context.warnIfCoalesableAtomsHaveDifferentLoadName()) {
+ // FIXME: need diagonstics interface for writing warning messages
+ llvm::errs() << "lld warning: shared library symbol "
+ << curShLib->name()
+ << " has different load path in "
+ << curShLib->file().path()
+ << " and in "
+ << newShLib->file().path();
+ }
+ } else if (!sameNullness) {
+ useNew = false;
+ if (_context.warnIfCoalesableAtomsHaveDifferentCanBeNull()) {
+ // FIXME: need diagonstics interface for writing warning messages
+ llvm::errs() << "lld warning: shared library symbol "
+ << curShLib->name()
+ << " has different weakness in "
+ << curShLib->file().path()
+ << " and in "
+ << newShLib->file().path();
+ }
+ } else {
+ // Both shlib atoms are identical and can be coalesced.
+ useNew = false;
+ }
}
+ break;
+ default:
+ llvm::report_fatal_error("SymbolTable::addByName(): unhandled switch clause");
+ }
+ if (useNew) {
+ // Update name table to use new atom.
+ _nameTable[name] = &newAtom;
+ // Add existing atom to replacement table.
+ _replacedAtoms[existing] = &newAtom;
+ } else {
+ // New atom is not being used. Add it to replacement table.
+ _replacedAtoms[&newAtom] = existing;
}
}
@@ -261,20 +256,20 @@ unsigned SymbolTable::AtomMappingInfo::g
bool SymbolTable::AtomMappingInfo::isEqual(const DefinedAtom * const l,
const DefinedAtom * const r) {
- if ( l == r )
+ if (l == r)
return true;
- if ( l == getEmptyKey() )
+ if (l == getEmptyKey())
return false;
- if ( r == getEmptyKey() )
+ if (r == getEmptyKey())
return false;
- if ( l == getTombstoneKey() )
+ if (l == getTombstoneKey())
return false;
- if ( r == getTombstoneKey() )
+ if (r == getTombstoneKey())
return false;
- if ( l->contentType() != r->contentType() )
+ if (l->contentType() != r->contentType())
return false;
- if ( l->size() != r->size() )
+ if (l->size() != r->size())
return false;
ArrayRef<uint8_t> lc = l->rawContent();
ArrayRef<uint8_t> rc = r->rawContent();
@@ -285,13 +280,13 @@ void SymbolTable::addByContent(const Def
// Currently only read-only constants can be merged.
assert(newAtom.permissions() == DefinedAtom::permR__);
AtomContentSet::iterator pos = _contentTable.find(&newAtom);
- if ( pos == _contentTable.end() ) {
+ if (pos == _contentTable.end()) {
_contentTable.insert(&newAtom);
return;
}
const Atom* existing = *pos;
- // New atom is not being used. Add it to replacement table.
- _replacedAtoms[&newAtom] = existing;
+ // New atom is not being used. Add it to replacement table.
+ _replacedAtoms[&newAtom] = existing;
}
const Atom *SymbolTable::findByName(StringRef sym) {
@@ -346,10 +341,9 @@ void SymbolTable::tentativeDefinitions(s
const Atom *atom = entry.second;
StringRef name = entry.first;
assert(atom != nullptr);
- if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(atom) ) {
- if ( defAtom->merge() == DefinedAtom::mergeAsTentative )
+ if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(atom))
+ if (defAtom->merge() == DefinedAtom::mergeAsTentative)
names.push_back(name);
- }
}
}
} // namespace lld
More information about the llvm-commits
mailing list