[clang] [clang-repl] Set up executor implicitly to account for init PTUs (PR #84758)

Stefan Gränitz via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 12 04:46:55 PDT 2024


================
@@ -14,7 +14,7 @@ struct A { int a; A(int a) : a(a) {} virtual ~A(); };
 // PartialTranslationUnit.
 inline A::~A() { printf("~A(%d)\n", a); }
 
-// Create one instance with new and delete it.
+// Create one instance with new and delete it. We crash here now:
 A *a1 = new A(1);
----------------
weliveindetail wrote:

Let me share some more observations.

We **execute** the initial PTU and not only parse it. It shouldn't make a difference for the parser right? Still, I wasn't sure, especially since we unusally **only parse** runtime PTUs. So I made some experiments:
```
    Init      Runtime      Dtor-def  |  New     Delete  Automatic
(1) Execute   Execute   Out-of-line  |  fails   -       fails
                             Inline  |  fails   -       once*

(2) Execute   Parse     Out-of-line  |  fails   -       fails
                             Inline  |  once*   fails   once

(3) Parse     Any       Out-of-line  |  works   works   works
                             Inline  |  works   works   works
```

Without `-O2` everything works.
Automatic = `A a1(1);`
`once` = Works exactly once (including shutdown)
`once*` = Same, but only if dtor has side-effects e.g. printf call

(1) is the behavior with this patch. (3) was the status-quo before this patch.

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


More information about the cfe-commits mailing list