<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57290>57290</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            llvm::CloneModule bug "Referencing global in another module!"
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Hatsunespica
      </td>
    </tr>
</table>

<pre>
    Test case:
```
@i1 = ifunc void (), void ()* ()* @f1

define void ()* @f1() {
  %i1 = bitcast void ()* @i1 to i8*
}

```



Test code:
```
std::shared_ptr<llvm::Module> openInputFile(const string &inputFile,
                                            llvm::LLVMContext &context) {
  llvm::ExitOnError ExitOnErr;
  auto MB =
      ExitOnErr(errorOrToExpected(llvm::MemoryBuffer::getFile(inputFile)));
  llvm::SMDiagnostic Diag;
  auto pm = getLazyIRModule(std::move(MB), Diag, context,
                            /*ShouldLazyLoadMetadata=*/true);
  if (!pm) {
    Diag.print("", llvm::errs(), false);
    return nullptr;
  }
  ExitOnErr(pm->materializeAll());
  return std::move(pm);
}

void handle(std::shared_ptr<llvm::Module> ptr) {
  std::shared_ptr<llvm::Module> newModule=llvm::CloneModule(*ptr,vmap);
  llvm::verifyModule(*newModule,&llvm::errs());
}

void test(){
  llvm::LLVMContext context;
  std::shared_ptr<llvm::Module> pm = openInputFile(testfile, context);
  handle(pm);
}
```

Verifier output:
```
Referencing global in another module!
  %i1 = bitcast void ()* @i1 to i8*
; ModuleID = '/home/spica/test.ll'
void ()* @i1
; ModuleID = '/home/spica/test.ll'
Referencing global in another module!
  %i2 = bitcast void ()* @i2 to i8*
; ModuleID = '/home/spica/test.ll'
void ()* @i2
; ModuleID = '/home/spica/test.ll'
```

Similar to another issue I mentioned before >_<
https://github.com/llvm/llvm-project/issues/55991

cc @regehr 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1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