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

    <tr>
        <th>Summary</th>
        <td>
            ASTImporter going into an infinite loop and consuming increasing amount of memory, when Importing a CallExpr, CompoundStmt
        </td>
    </tr>

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

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

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

<pre>
    I was trying to import a CallExpr using clang::ASTImporter, and realized the program was going into an infinite loop while consuming more and more memory. I had to forcefully kill the program since the memory consumption was continuously increasing.

On performing some further test, I realized the problem also occurs when importing a CompoundStmt, . Here is a few example where the problem occurs.
Example1


```
void foo1()
{
   printf("hello");
}

void foo2()
{
   foo1();// s1
}
```

Example2

```
void foo1()
{
   {// s2
       printf("hello");
       printf("world");
    }
}
```

In example 1 the problem occurs when importing statement s1 and in example 2 the problem occurs when importing CompoundStmt s2.

Can any one else confirm this issue, and is there any solution to this.

I tested this on clang version 19.1.7 and ASTImporter was initialized like this:-
`ASTImporter Importer(astContext1, astContext1.getSourceManager().getFileManager(),astContext2, astContext2.getSourceManager().getFileManager(),false,nullptr);`



On running the same inside gdb the infinite loop looks like this

```
#22 0x00007ffff4da869c in clang::ASTImporter::ImportImpl(clang::Decl*) () from /usr/lib/libclang-cpp.so.19.1
#23 0x00007ffff4d7ab93 in clang::ASTImporter::Import(clang::Decl*) () from /usr/lib/libclang-cpp.so.19.1
#24 0x00007ffff73f1316 in ?? () from /usr/lib/libclang-cpp.so.19.1
#25 0x00007ffff4da8245 in clang::ASTNodeImporter::VisitFunctionDecl(clang::FunctionDecl*) ()
   from /usr/lib/libclang-cpp.so.19.1
#26 0x00007ffff4da869c in clang::ASTImporter::ImportImpl(clang::Decl*) () from /usr/lib/libclang-cpp.so.19.1
#27 0x00007ffff4d7ab93 in clang::ASTImporter::Import(clang::Decl*) () from /usr/lib/libclang-cpp.so.19.1
#28 0x00007ffff73f1316 in ?? () from /usr/lib/libclang-cpp.so.19.1
#29 0x00007ffff4da8245 in clang::ASTNodeImporter::VisitFunctionDecl(clang::FunctionDecl*) ()
   from /usr/lib/libclang-cpp.so.19.1
#30 0x00007ffff4da869c in clang::ASTImporter::ImportImpl(clang::Decl*) () from /usr/lib/libclang-cpp.so.19.1
#31 0x00007ffff4d7ab93 in clang::ASTImporter::Import(clang::Decl*) () from /usr/lib/libclang-cpp.so.19.1
#32 0x00007ffff73f1316 in ?? () from /usr/lib/libclang-cpp.so.19.1
#33 0x00007ffff4da8245 in clang::ASTNodeImporter::VisitFunctionDecl(clang::FunctionDecl*) ()
   from /usr/lib/libclang-cpp.so.19.1
```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUV01v4zYQ_TX0ZRBBIv0hHXRwvGvUh7aHLAr0SEsjiRuKFPhhx_31BSllLSdpuym6QAoItjSceXozekONuLWiVYglWd2T1acF967Tpvzdnwz_-oVL_1hzszjq-lIe4MwtOHMRqgWnQfSDNg447LiUn58GA96GpUpy1RK2JWy7ffhyiF5oCN0BVzUY5FL8gTW4DmEwujW8j8CtDsFCOQ1cgVCNUMIhSK0HOHdCIlRaWd8Hr14bjGjxpMdem0sCB-h4HZg12lTYeCkv8CikvLmVFarCaBnDJtTBCa0ij0orJ5TX3soLCFUZ5CGthKRbkm5_VTCgabSJPKzuERpvXIcGHFoXsjy8yvEosQcurQZdVd5YOHeopvoFGA473Q_aq_rB9REjgZ_QIAgLHBo8Az7xfpAYAg3ewI6Igd3n0ScbiYZjnU5Huj1pUUOjdUZoTmgRVjf3JN0CwGCEck200w6l1ITS4MLuo9enEewZgL4GmMGye0L3hO7BZtfgGY0rTfoujuFkAqajBf6J-Rs-Z21k_dJnIvkW1YP6VvjsjaK_fIzWcYc9Kgc2i-oU13j6HfFzEYClk-J2XAFXF9AKAaWNbdAI04PrhAVhrcfn3hI23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