[lld] [LLD][COFF][NFC] Create import thunks in ImportFile::parse. (PR #107929)

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 10 11:12:21 PDT 2024


================
@@ -1069,9 +1069,27 @@ void ImportFile::parse() {
   // DLL functions just like regular non-DLL functions.)
   if (hdr->getType() == llvm::COFF::IMPORT_CODE) {
     if (ctx.config.machine != ARM64EC) {
-      thunkSym = ctx.symtab.addImportThunk(name, impSym, hdr->Machine);
+      ImportThunkChunk *chunk;
+      switch (hdr->Machine) {
----------------
rnk wrote:

This is micro code style stuff, but consider moving this switch into a helper function so you can write `return make<Import*>()`. It's not stated explicitly, but it's kind of implied by https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code , and https://llvm.org/docs/CodingStandards.html#don-t-use-default-labels-in-fully-covered-switches-over-enumerations , and it's a common pattern all over LLVM:

```
Type *mapSwitch(stuff) {
  switch (machine) {
  case 1:
    return make<Import1>(stuff);
  case 2:
    return make<Import2>(stuff);
  ...
  } // no default
  llvm_unreachable("unknown machine");
}

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


More information about the llvm-commits mailing list