[lld] [LLD] [COFF] Fix handling of comdat .drectve sections (PR #68116)
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 3 09:44:20 PDT 2023
================
@@ -660,10 +660,15 @@ std::optional<Symbol *> ObjFile::createDefined(
if (prevailing) {
SectionChunk *c = readSection(sectionNumber, def, getName());
- sparseChunks[sectionNumber] = c;
- c->sym = cast<DefinedRegular>(leader);
- c->selection = selection;
- cast<DefinedRegular>(leader)->data = &c->repl;
+ if (c) {
+ sparseChunks[sectionNumber] = c;
+ c->sym = cast<DefinedRegular>(leader);
+ c->selection = selection;
+ cast<DefinedRegular>(leader)->data = &c->repl;
+ } else {
+ sparseChunks[sectionNumber] = nullptr;
+ return nullptr;
+ }
} else {
sparseChunks[sectionNumber] = nullptr;
----------------
rnk wrote:
I see three assignments to `sparseChunks[sectionNumber]`, can we reduce nesting and arrange the code so that we store a variable which is sometimes null?
For your code change, essentially wrap the `c->` expressions in the `if (c)` check.
Is the `return nullptr` necessary, or can we return `leader`?
https://github.com/llvm/llvm-project/pull/68116
More information about the llvm-commits
mailing list