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

    <tr>
        <th>Summary</th>
        <td>
            errors when using `clang-repl` interpreter in project on mac
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    I'm using `clang-repl` to embed a C++ interpreter in a library to enable JIT compilation, and I've been really happy with the results so far. However, when building this project on a mac, the JIT compiler is failing on even trivial programs. For example, creating the interpreter with

```cpp
  std::vector<const char *> flags = {
 "-march=native", "-Xclang", "-emit-llvm-only", 
  };

  auto CI = llvm::cantFail(IncrementalCompilerBuilder::create(flags));
 interpreter = llvm::cantFail(Interpreter::create(std::move(CI)));
```
and using it to compile
```cpp
#include <functional>
```
runs into errors 
```sh
In file included from <<< inputs >>>:1:
In file included from input_line_0:2:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/functional:510:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/__functional/bind.h:17:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/tuple:224:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/iosfwd:99:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/__mbstate_t.h:29:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/wchar.h:123:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/wchar.h:89:10: fatal error: 'stdarg.h' file not found
#include <stdarg.h>
 ^~~~~~~~~~
```
that aren't encountered when compiling with the same file with `clang++` from the same LLVM installation. I've tried comparing the include search paths in each case by adding "-v" to the compilation flags and comparing the results.

clang-repl output when including "-v"
```
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/System/Library/Frameworks (framework directory)
```

clang++ output when including "-v"
```
#include "..." search starts here:
#include <...> search starts here:
/opt/homebrew/opt/llvm/bin/../include/c++/v1
/opt/homebrew/Cellar/llvm/16.0.6/lib/clang/16/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/System/Library/Frameworks (framework directory)
```

The obvious difference was that the first include search paths were different, so I tried manually specifying those paths to the interpreter,
```cpp
  std::vector<const char *> flags = {
    "-march=native", "-Xclang", "-emit-llvm-only", 
 "-isystem", "/opt/homebrew/Cellar/llvm/16.0.6/lib/clang/16/include",
 "-I", "/opt/homebrew/opt/llvm/bin/../include/c++/v1"
 };
```
and that does make the first two paths agree with the ones shown by `clang++ -v ...`:
```
#include "..." search starts here:
#include <...> search starts here:
 /opt/homebrew/opt/llvm/bin/../include/c++/v1
 /opt/homebrew/Cellar/llvm/16.0.6/lib/clang/16/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/System/Library/Frameworks (framework directory)
End of search list.
```
but the `clang-repl` interpreter still emits a long list of errors when trying to compile the `#include <functional>` directive:
```sh
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/functional:503:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__algorithm/search.h:14:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__algorithm/iterator_operations.h:15:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__iterator/advance.h:26:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/cstdlib:87:
/opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:150:34: error: unknown type name 'ldiv_t'
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
 ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:151:12: error: no member named 'ldiv' in the global namespace
  return ::ldiv(__x, __y);
 ~~^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:154:34: error: unknown type name 'lldiv_t'
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
 ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:156:12: error: no member named 'lldiv' in the global namespace
```

There are a handful of similar issues in `xeus-cling`, like
https://github.com/jupyter-xeus/xeus-cling/issues/403
https://github.com/jupyter-xeus/xeus-cling/issues/412

Does anyone know how to configure a `clang-repl` interpreter for use in projects outside of the LLVM source tree, on mac? 

Is it possible to make the default `clang-repl` configuration mimic the implicit assumptions of `clang++` from the same LLVM build?

---------

llvm version 16.0.6 installed with homebrew
m1 mac running 13.4

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