[llvm] [SystemZ][z/OS] yaml2obj GOFF symbols (PR #75971)

Kai Nacke via llvm-commits llvm-commits at lists.llvm.org
Thu May 2 13:20:44 PDT 2024


================
@@ -308,11 +308,14 @@ bool GOFFState::writeObject() {
   if (HasError)
     return false;
   // Iterate over all records.
-  for (const std::unique_ptr<llvm::GOFFYAML::RecordBase> &Rec : Doc.Records)
+  unsigned RecordNum = 0;
+  for (const std::unique_ptr<llvm::GOFFYAML::RecordBase> &Rec : Doc.Records) {
     if (const auto *Sym = dyn_cast<GOFFYAML::Symbol>(Rec.get()))
       writeSymbol(*Sym);
     else
-      reportError("unknown record type");
+      reportError("unknown record type on record index" + Twine(RecordNum));
----------------
redstar wrote:

That is running in the wrong direction. The `if` is over the discriminator used for the inheritance hierarchy. There is no user input involved. The error message made no sense in the first place. The whole loop should be:

```
  for (const auto &Rec: Doc.Records) {
    GOFFYAML::RecordBase *RecBase = Rec.get();
    switch (RecBase->getKind()) {
      case GOFFYAML::RecordBase::RBK_Symbol:
        writeSymbol(*static_cast<GOFFYAML::Symbol *>(RecBase));
    }
  }
```

There is no `default` case because the `switch` covers all cases. I put this into the updated PR.

https://github.com/llvm/llvm-project/pull/75971


More information about the llvm-commits mailing list