74 Commits

Author SHA1 Message Date
Mészáros Gergely
3b0cb89796
[clang-repl][CMake][MSVC] Use LINKER: instead of -Wl (#118518)
This should be more portable, and avoids passing the option to
`clang-cl` when linking, because `clang-cl` accepts any `-W` flags
(normally warning flags) during linking (#118516).
2024-12-04 09:54:21 +01:00
Mészáros Gergely
8358437bbb
[clang-repl]: Print stack-trace on crash (#117896)
Call `llvm::sys::PrintStackTraceOnErrorSignal` at the start of main to
1. Print a strack trace on crash
2. Disable the assertion failed popup in Windows Debug Builds

Other tools (for example clang-check or clang-query) already do this.

This fixes debug build bots on windows hanging (waiting for the popup to
be dismissed) and ultimately getting terminated due to timeout.
2024-11-27 17:42:17 +01:00
SahilPatidar
ebb3508899
Revert "[Clang-Repl] Add support for out-of-process execution." (#115854)
Reverts llvm/llvm-project#110418

Buildbot encountered a failure.
2024-11-12 16:51:25 +05:30
SahilPatidar
3183b3aad1
[Clang-Repl] Add support for out-of-process execution. (#110418)
This PR introduces out-of-process (OOP) execution support for
Clang-Repl. With this enhancement, two new flags, `oop-executor` and
`oop-executor-connect`, are added to the Clang-Repl interface. These
flags enable the launch of an external executor
(`llvm-jitlink-executor`), which handles code execution in a separate
process.
2024-11-12 14:39:30 +05:30
Mészáros Gergely
eb9af19fbf
[clang-repl][CMake][MSVC] Wrap /EXPORT linker option for ICX (#112867)
The Intel C++ Compiler (ICX) passes linker flags through the driver
unlike MSVC and clang-cl, and therefore needs them to be prefixed with
`/Qoption,link` (the equivalent of -Wl, for gcc on *nix).

Use the `LINKER:` prefix for the `/EXPORT:` options in clang-repl, this
expands to the correct flag for ICX and nothing for MSVC / clang-cl.

RFC:
https://discourse.llvm.org/t/rfc-cmake-linker-flags-need-wl-equivalent-for-intel-c-icx-on-windows/82446
2024-10-23 14:33:43 +02:00
Vassil Vassilev
96ae7c4f1a
[clang-repl] Implement continuation for preprocessor directives. (#107552) 2024-09-20 10:07:46 +03:00
Lang Hames
e5b55e6067 [clang-repl] Fix clang-repl for LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES=Off.
clang-repl should stil work when LLVM is built with
-DLLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES=Off.

This fix uses the approach implemented in
https://github.com/llvm/llvm-project/pull/101741.

rdar://134910110
2024-08-29 17:50:49 +10:00
Steven Wu
b8c560f159
[CMake] Remove EXPORT_SYMBOLS_FOR_PLUGINS from #102138 (#102396)
Partially remove some of the changes from #102138 as
EXPORT_SYMBOLS_FOR_PLUGINS doesn't work on all the configurations.
2024-08-08 06:00:11 -07:00
Steven Wu
01b488faab
Reapply "[CMake] Fold export_executable_symbols_* into function args. (#101741)" (#102138)
Fix the builds with LLVM_TOOL_LLVM_DRIVER_BUILD enabled.

LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES is not completely
compatible with export_executable_symbols as the later will be ignored
if the previous is set to NO.

Fix the issue by passing if symbols need to be exported to
llvm_add_exectuable so the link flag can be determined directly
without calling export_executable_symbols_* later.
2024-08-07 09:12:15 -07:00
Steven Wu
f9b69a378c Revert "[CMake] Fold export_executable_symbols_* into function args. (#101741)"
This reverts commit 5c56b46a32a8856a022a54291bc9294068f7ddbd. This break
lld build when using GENERATE_DRIVER.
2024-08-06 06:08:16 -07:00
Steven Wu
5c56b46a32
[CMake] Fold export_executable_symbols_* into function args. (#101741)
`LLVM_ENABLE_EXPORTED_SYMBOLS_IN_EXECUTABLES` is not completely
compatible with `export_executable_symbols` as the later will be ignored
if the previous is set to NO.

 Fix the issue by passing if symbols need to be exported to
`llvm_add_exectuable` so the link flag can be determined directly
without calling `export_executable_symbols_*` later.
2024-08-05 19:08:27 -07:00
h-vetinari
89946bda5e
[cmake] switch to CMake's native check_{compiler,linker}_flag (#96171)
Broken out from #93429

Somewhat closing the loop opened by 7017e6c9cfd2de.

Co-authored-by: Ryan Prichard <rprichard@google.com>
2024-07-31 10:31:13 -04:00
Hans Wennborg
a30ef38cd4 [clang-repl] Always do export_executable_symbols_for_plugins(clang-repl)
It's needed to make clang-repl work in -DCLANG_PLUGIN_SUPPORT=OFF
configured builds (at least on mac). See discussion on
https://github.com/llvm/llvm-project/pull/89811
2024-06-10 18:43:58 +02:00
Pengcheng Wang
130e93cc26
Reland "[clang] Enable sized deallocation by default in C++14 onwards" (#90373)
Since C++14 has been released for about nine years and most standard
libraries have implemented sized deallocation functions, it's time to
make this feature default again.

This is another try of https://reviews.llvm.org/D112921.

The original commit cf5a8b4 was reverted by 2e5035a due to some
failures (see #83774).

Fixes #60061
2024-05-22 12:37:27 +08:00
Vitaly Buka
2e5035aeed
Revert "[clang] Enable sized deallocation by default in C++14 onwards (#83774)" (#90299)
https://lab.llvm.org/buildbot/#/builders/168/builds/20063 (should be
fixed with #90292)

More details in #83774

This reverts commit cf5a8b489464d09dfdd7a48ce7c8b41d3c9bf819.
2024-04-26 17:14:43 -07:00
Pengcheng Wang
cf5a8b4894
[clang] Enable sized deallocation by default in C++14 onwards (#83774)
Since C++14 has been released for about nine years and most standard
libraries have implemented sized deallocation functions, it's time to
make this feature default again.

This is another try of https://reviews.llvm.org/D112921.

Fixes #60061
2024-04-26 16:59:12 +08:00
Vassil Vassilev
fd5f06eb6d
[clang-repl] Fix the process return code if diagnostics occurred. (#89879)
Should fix the failure seen in the pre-merge infrastructure of #89804.
2024-04-25 08:46:04 +03:00
Andrew V. Teylu
cbdc86e46c
[clang-repl] Add call to 'InitializeAllAsmParsers' (#86727)
This PR fixes the following issue when working with `clang-repl`:

```
fatal error: error in backend: Inline asm not supported by this streamer because we don't have an asm parser for this target
```

When working with the following input (named "unit.cpp"):

```cpp
__asm(".globl _ZSt21ios_base_library_initv");
int x;
```

and then in `clang-repl`:

```
#include "unit.cpp"
x = 10;
```

Signed-off-by: Andrew V. Teylu <andrew.teylu@vector.com>
2024-04-04 18:10:23 +08:00
Stefan Gränitz
fb9a82b023 [clang-repl] Refine fix for linker error: PLT offset too large
This is a follow-up improvement after the discussion in #78959
2024-01-24 11:45:04 +01:00
Martin Storsjö
e3d73ad58c [clang-repl] Fix CMake errors when cross compiling
These stem from 4821c90c24d52d4a42990fd9371caedb157bc58b.

When cross compiling, CMAKE_SYSTEM_PROCESSOR is empty, if the
target processor hasn't been set when setting up the cross
compilation. Ideally, when setting up cross compilation with
CMake, the user is supposed to set CMAKE_SYSTEM_PROCESSOR, but
so far, compilation has worked just fine even without it.

Quote the string where CMAKE_SYSTEM_PROCESSOR is expanded, to
avoid argument errors when it expands to an empty string.
2024-01-23 13:42:24 +02:00
Stefan Gränitz
2bb6d7b8a4 [clang-repl] Limit use of PLT offset flag to linkers that support it
Follow-up fix from https://github.com/llvm/llvm-project/pull/78959
2024-01-22 17:16:52 +01:00
Stefan Gränitz
4821c90c24
[clang-repl] Fix PLT offset too large linker error on ARM (#78959)
I cross-compile clang-repl with GCC-10 on Ubuntu 20.04 and get this
error when linking with gold: PLT offset too large, try linking with
--long-plt
2024-01-22 13:56:44 +01:00
Fred Fu
35b366ace7
[ClangRepl] Reland Semanic Code Completion (#75556)
This patch contains changes from
002d471a4a3cd8b429e4ca7c84fd54a642e50e4c, in
addition to a bug fix that added a virtual destructor to
`CompletionContextHandler`

The original changes in the orginal commit piggybacks on clang's
semantic modules to enable semantic completion.  In particular, we use
`CodeCompletionContext` to differentiate two types of code completion.
We also
extract the relevant type information from it.
2023-12-19 22:53:02 +02:00
Kazu Hirata
f3dcc2351c
[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-13 08:54:13 -08:00
Fred Fu
9ebe6e28cd
Revert "[ClangRepl] Type Directed Code Completion" (#73259)
Reverts llvm/llvm-project#67349

There are some issues with the sanitizers. We will reland once that's fixed.
2023-11-23 21:07:51 +02:00
Fred Fu
002d471a4a
[ClangRepl] Type Directed Code Completion (#67349)
Differential Revision: https://reviews.llvm.org/D159128
2023-11-23 19:56:35 +02:00
Lang Hames
53a87b4a69 [clang-repl] Disable LSan in clang-repl.
https://llvm.org/github.com/llvm/llvm-project/issues/67586.
2023-09-27 21:39:48 -07:00
Lang Hames
61b0f12d6b Re-apply "[ORC][LLJIT] Move enable-debugger-support utility out of..."
This re-applies e1a5bb59b91, which was reverted in e5f169f91a8 due to LSan
failures on some bots (see https://github.com/llvm/llvm-project/issues/67586).
The LSan failures were not caused by this patch (just exposed by it), so LSan
was disabled for the failing test in 47625fea5e3. This should be safe to
re-land now.
2023-09-27 13:24:02 -07:00
Lang Hames
e5f169f91a Revert "[ORC][LLJIT] Move enable-debugger-support utility out of LLJITBuilder."
This reverts commit e1a5bb59b91d60c0d87feb78f0e0614589a4c927 while I
investigate the bot failure at
https://lab.llvm.org/buildbot/#/builders/168/builds/15831
2023-09-22 21:43:41 -07:00
Lang Hames
e1a5bb59b9 [ORC][LLJIT] Move enable-debugger-support utility out of LLJITBuilder.
This change means that debugger support only needs to be linked in if it's
used. The code size of debugger support is expected to increase as we improve
it (e.g. pulling in DWARF parsing), so making it an optional extra is useful
for controlling final binary sizes.
2023-09-22 16:18:20 -07:00
Fred Fu
79af92bb99 Reland "[clang-repl] support code completion at a REPL."
Original commit message:
"
This patch enabled code completion for ClangREPL. The feature was built upon
three existing Clang components: a list completer for LineEditor, a
CompletionConsumer from SemaCodeCompletion, and the ASTUnit::codeComplete method.
The first component serves as the main entry point of handling interactive inputs.

Because a completion point for a compiler instance has to be unchanged once it
is set, an incremental compiler instance is created for each code
completion. Such a compiler instance carries over AST context source from the
main interpreter compiler in order to obtain declarations or bindings from
previous input in the same REPL session.

The most important API codeComplete in Interpreter/CodeCompletion is a thin
wrapper that calls with ASTUnit::codeComplete with necessary arguments, such as
a code completion point and a ReplCompletionConsumer, which communicates
completion results from SemaCodeCompletion back to the list completer for the
REPL.

In addition, PCC_TopLevelOrExpression and CCC_TopLevelOrExpression` top levels
were added so that SemaCodeCompletion can treat top level statements like
expression statements at the REPL. For example,

clang-repl> int foo = 42;
clang-repl> f<tab>

From a parser's persective, the cursor is at a top level. If we used code
completion without any changes, PCC_Namespace would be supplied to
Sema::CodeCompleteOrdinaryName, and thus the completion results would not
include foo.

Currently, the way we use PCC_TopLevelOrExpression and
CCC_TopLevelOrExpression is no different from the way we use PCC_Statement
and CCC_Statement respectively.

Differential revision: https://reviews.llvm.org/D154382
"

The new patch also fixes clangd and several memory issues that the bots reported
and upload the missing files.
2023-08-28 20:09:03 +00:00
Vassil Vassilev
752f87cd6a Revert "Reland "[clang-repl] support code completion at a REPL.""
This reverts commit 5ab25a42ba70c4b50214b0e78eaaccd30696fa09 due to forgotten
files.
2023-08-28 20:05:14 +00:00
Fred Fu
5ab25a42ba Reland "[clang-repl] support code completion at a REPL."
Original commit message:
"
This patch enabled code completion for ClangREPL. The feature was built upon
three existing Clang components: a list completer for LineEditor, a
CompletionConsumer from SemaCodeCompletion, and the ASTUnit::codeComplete method.
The first component serves as the main entry point of handling interactive inputs.

Because a completion point for a compiler instance has to be unchanged once it
is set, an incremental compiler instance is created for each code
completion. Such a compiler instance carries over AST context source from the
main interpreter compiler in order to obtain declarations or bindings from
previous input in the same REPL session.

The most important API codeComplete in Interpreter/CodeCompletion is a thin
wrapper that calls with ASTUnit::codeComplete with necessary arguments, such as
a code completion point and a ReplCompletionConsumer, which communicates
completion results from SemaCodeCompletion back to the list completer for the
REPL.

In addition, PCC_TopLevelOrExpression and CCC_TopLevelOrExpression` top levels
were added so that SemaCodeCompletion can treat top level statements like
expression statements at the REPL. For example,

clang-repl> int foo = 42;
clang-repl> f<tab>

From a parser's persective, the cursor is at a top level. If we used code
completion without any changes, PCC_Namespace would be supplied to
Sema::CodeCompleteOrdinaryName, and thus the completion results would not
include foo.

Currently, the way we use PCC_TopLevelOrExpression and
CCC_TopLevelOrExpression is no different from the way we use PCC_Statement
and CCC_Statement respectively.

Differential revision: https://reviews.llvm.org/D154382
"

The new patch also fixes clangd and several memory issues that the bots reported.
2023-08-28 19:59:56 +00:00
Lang Hames
f2b8666531 [ORC][clang-repl] Fix clang-repl -host-supports-jit option after 122ebe3b500.
Same fix as 8a62d6ba7e: We need to make sure that the supports-JIT check uses
the same JIT config that will be used by the clang-repl tool.
2023-08-26 19:46:33 -07:00
Vassil Vassilev
f94a937cb3 Revert "[clang-repl] support code completion at a REPL."
This reverts commit eb0e6c3134ef6deafe0a4958e9e1a1214b3c2f14 due to failures in
clangd such as https://lab.llvm.org/buildbot/#/builders/57/builds/29377
2023-08-23 14:46:15 +00:00
Fred Fu
eb0e6c3134 [clang-repl] support code completion at a REPL.
This patch enabled code completion for ClangREPL. The feature was built upon
three existing Clang components: a list completer for LineEditor, a
CompletionConsumer from SemaCodeCompletion, and the ASTUnit::codeComplete method.
The first component serves as the main entry point of handling interactive inputs.

Because a completion point for a compiler instance has to be unchanged once it
is set, an incremental compiler instance is created for each code
completion. Such a compiler instance carries over AST context source from the
main interpreter compiler in order to obtain declarations or bindings from
previous input in the same REPL session.

The most important API codeComplete in Interpreter/CodeCompletion is a thin
wrapper that calls with ASTUnit::codeComplete with necessary arguments, such as
a code completion point and a ReplCompletionConsumer, which communicates
completion results from SemaCodeCompletion back to the list completer for the
REPL.

In addition, PCC_TopLevelOrExpression and CCC_TopLevelOrExpression` top levels
were added so that SemaCodeCompletion can treat top level statements like
expression statements at the REPL. For example,

clang-repl> int foo = 42;
clang-repl> f<tab>

From a parser's persective, the cursor is at a top level. If we used code
completion without any changes, PCC_Namespace would be supplied to
Sema::CodeCompleteOrdinaryName, and thus the completion results would not
include foo.

Currently, the way we use PCC_TopLevelOrExpression and
CCC_TopLevelOrExpression is no different from the way we use PCC_Statement
and CCC_Statement respectively.

Differential revision: https://reviews.llvm.org/D154382
2023-08-23 14:00:59 +00:00
Anubhab Ghosh
ddeab07ca6 [clang-repl][CUDA] Re-land: Initial interactive CUDA support for clang-repl
CUDA support can be enabled in clang-repl with --cuda flag.
Device code linking is not yet supported. inline must be used with all
__device__ functions.

Differential Revision: https://reviews.llvm.org/D146389
2023-05-27 13:54:42 +05:30
Jun Zhang
5111286f06
Reland "Reland [clang-repl] Introduce Value to capture expression results"
This reverts commit 094ab4781262b6cb49d57b0ecdf84b047c879295.

Reland with changing `ParseAndExecute` to `Parse` in
`Interpreter::create`. This avoid creating JIT instance everytime even
if we don't really need them.

This should fixes failures like https://lab.llvm.org/buildbot/#/builders/38/builds/11955

The original reverted patch also causes GN bot fails on M1. (https://lab.llvm.org/buildbot/#/builders/38/builds/11955)
However, we can't reproduce it so let's reland it and see what happens.
See discussions here: https://reviews.llvm.org/rGd71a4e02277a64a9dece591cdf2b34f15c3b19a0
2023-05-23 19:32:31 +08:00
Vassil Vassilev
c96c5edb58 [clang-repl] Enable basic multiline support.
This patch allows the users to use backslash to tell clang-repl that more input
is coming. This would help support OpenMP directives which generally require to
be in separate lines.
2023-05-20 14:40:58 +00:00
Anubhab Ghosh
0929f5b903 Revert "[clang-repl][CUDA] Initial interactive CUDA support for clang-repl"
This reverts commit 80e7eed6a610ab3c7289e6f9b7ec006bc7d7ae31.
2023-05-20 14:40:04 +05:30
Anubhab Ghosh
80e7eed6a6 [clang-repl][CUDA] Initial interactive CUDA support for clang-repl
CUDA support can be enabled in clang-repl with --cuda flag.
Device code linking is not yet supported. inline must be used with all
__device__ functions.

Differential Revision: https://reviews.llvm.org/D146389
2023-05-20 14:00:48 +05:30
Jun Zhang
094ab47812
Revert "Reland [clang-repl] Introduce Value to capture expression results"
This reverts commit d71a4e02277a64a9dece591cdf2b34f15c3b19a0.
See http://45.33.8.238/macm1/61024/step_7.txt
2023-05-19 20:56:21 +08:00
Jun Zhang
d71a4e0227
Reland [clang-repl] Introduce Value to capture expression results
This reverts commit 7158fd381a0bc0222195d6a07ebb42ea57957bda.
* Fixes endianness issue on big endian machines like PowerPC-bl
* Disable tests on platforms that having trouble to support JIT

Signed-off-by: Jun Zhang <jun@junz.org>
2023-05-19 13:40:44 +08:00
Jun Zhang
7158fd381a
Revert "[clang-repl] Introduce Value to capture expression results"
This reverts commit a423b7f1d7ca8b263af85944f57a69aa08fc942c.
See https://lab.llvm.org/buildbot/#/changes/95083
2023-05-16 21:21:52 +08:00
Jun Zhang
a423b7f1d7
[clang-repl] Introduce Value to capture expression results
This is the second part of the below RFC:
https://discourse.llvm.org/t/rfc-handle-execution-results-in-clang-repl/68493

This patch implements a Value class that can be used to carry expression
results in clang-repl. In other words, when we see a top expression
without semi, it will be captured and stored to a Value object. You can
explicitly specify where you want to store the object, like:

```
Value V;
llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
llvm::cantFail(Interp->ParseAndExecute("x", &V));
```

`V` now stores some useful infomation about `x`, you can get its real
value (42), it's `clang::QualType` or anything interesting.

However, if you don't specify the optional argument, it will be captured
to a local variable, and automatically called `Value::dump`, which is
not implemented yet in this patch.

Signed-off-by: Jun Zhang <jun@junz.org>
2023-05-16 20:10:49 +08:00
NAKAMURA Takumi
077a2a4bcd [CMake] Cleanup deps 2023-04-17 00:38:49 +09:00
Anubhab Ghosh
d978730d8e [clang-repl] Add a command to load dynamic libraries
This commit adds the %lib <file> command to load a dynamic library to be
used by the currently running interpreted code.
For example `%lib libSDL2.so`.

Differential Revision: https://reviews.llvm.org/D141824
2023-03-29 08:04:50 +05:30
Kazu Hirata
6ad0788c33 [clang] Use std::optional instead of llvm::Optional (NFC)
This patch replaces (llvm::|)Optional< with std::optional<.  I'll post
a separate patch to remove #include "llvm/ADT/Optional.h".

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14 12:31:01 -08:00
Kazu Hirata
a1580d7b59 [clang] Add #include <optional> (NFC)
This patch adds #include <optional> to those files containing
llvm::Optional<...> or Optional<...>.

I'll post a separate patch to actually replace llvm::Optional with
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14 11:07:21 -08:00
Jun Zhang
9caee577ef
[clang-repl] Fix incorrect return code
Without this patch, clang-repl incorrectly pass some tests when there's
error occured.

Signed-off-by: Jun Zhang <jun@junz.org>

Differential Revision: https://reviews.llvm.org/D130422
2022-07-31 19:07:05 +08:00