[clang] [clang][repl] fix `new` on Mac M1 (PR #69072)

Maksim Levental via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 15 08:52:07 PDT 2023


================
@@ -275,7 +274,14 @@ Interpreter::create(std::unique_ptr<CompilerInstance> CI) {
   if (Err)
     return std::move(Err);
 
-  auto PTU = Interp->Parse(Runtimes);
+  std::string runtimes = "";
+  if (llvm::Triple(llvm::sys::getProcessTriple()).isOSDarwin())
+    runtimes += "#include <new>\n";
----------------
makslevental wrote:

Okay let me try to explain the bug again:

In Interpreter.cpp you have a series of decls and a define **are always parsed at interpreter startup** in `const char *const Runtimes`:

https://github.com/llvm/llvm-project/blob/6dfea561ba96974b205c31546c5e2069429c75b1/clang/lib/Interpreter/Interpreter.cpp#L250-L268

Currently there's a forward decl for `new` _and_ a subsequent use of placement `new` (in `__clang_Interpreter_SetValueCopyArr`). I don't know why because I am not yet familiar with the codebase - @junaire added the code. The comment above suggests it might be for the sake of enabling unittests?

On Linux and Windows this seems to work (I'm guessing since none of the tests fail) but on Mac (at least M1), this leads to the error mentioned above if the user ever loads `<new>`, e.g., as a transivitive include from somewhere else, because the forward decl in `Runtimes` clashes with what the sysroot has.

I tried your suggestion to just remove any forward decl to `new` and [it didn't work](https://buildkite.com/llvm-project/github-pull-requests/builds/7769). Removing it just for Mac (if that's what you meant since you highlighted only that case) seems like really bad UX.

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


More information about the cfe-commits mailing list