97 Commits

Author SHA1 Message Date
Vassil Vassilev
96ae7c4f1a
[clang-repl] Implement continuation for preprocessor directives. (#107552) 2024-09-20 10:07:46 +03:00
Jonas Hahnfeld
947b9f55b5
[clang-repl] Fix printing preprocessed tokens and macros (#104964) 2024-08-21 09:09:06 +02:00
Vassil Vassilev
6c62ad446b
[clang-repl] [codegen] Reduce the state in TBAA. NFC for static compilation. (#98138)
In incremental compilation clang works with multiple `llvm::Module`s.
Our current approach is to create a CodeGenModule entity for every new
module request (via StartModule). However, some of the state such as the
mangle context needs to be preserved to keep the original semantics in
the ever-growing TU.

Fixes: llvm/llvm-project#95581.

cc: @jeaye
2024-08-21 07:22:31 +02:00
Jonas Hahnfeld
66bd5d7989
[clang-repl] Fix PCH with delayed template parsing (#103028)
When instantiating a delayed template, the recorded token stream is
passed to `Parser::ParseLateTemplatedFuncDef` which will append the
current token "so it doesn't get lost". With incremental extensions
enabled, this is `repl_input_end` which subsequently needs support for
(de)serialization.
2024-08-14 15:11:04 +02:00
Vitaly Buka
ba400539e2
[Interp] Mark the test unsupported with Asan (#102859)
It's very flaky recently.

10 bulds are OK, then 3 failed:
https://lab.llvm.org/buildbot/#/builders/52/builds/1524
https://lab.llvm.org/buildbot/#/builders/52/builds/1525
https://lab.llvm.org/buildbot/#/builders/52/builds/1526
then 3 OK
https://lab.llvm.org/buildbot/#/builders/52/builds/1531
https://lab.llvm.org/buildbot/#/builders/52/builds/1532
then 2 green again

We need to stop to spam blame list by disabling the test,
and investigate later if Asan is valuable for the test.

Issue #102858
2024-08-13 09:01:06 -07:00
Nico Weber
c63b9a5af7
[clang-interp] Use -fno-sized-deallocation in two tests (#95546)
At least on my Windows machine, these two tests fail due to not being
able to look up `??3@YAXPEAX_K@Z` (which is
`void __cdecl operator delete(void *, unsigned __int64)` in demangled)
after 130e93cc26ca. Since they don't test anything related to sized
deallocation, just disable sized allocation for them.

Possibly fixes #95451.
2024-06-14 15:37:17 -04:00
Vitaly Buka
81e9a3c3fc [clang-repl] Disable new test after #89811 2024-06-06 14:33:49 -07:00
Vassil Vassilev
7091dfc0e4
[clang-repl] Lay the foundation of pretty printing for C. (#89811) 2024-06-06 11:49:10 +03:00
Vassil Vassilev
d999ce0302 Reland "[clang-repl] Extend the C support. (#89804)"
Original commit message:"

[clang-repl] Extend the C support. (#89804)

The IdResolver chain is the main way for C to implement lookup rules.  Every new
partial translation unit caused clang to exit the top-most scope which in turn
cleaned up the IdResolver chain. That was not an issue for C++ because its
lookup is implemented on the level of declaration contexts.

This patch keeps the IdResolver chain across partial translation units
maintaining proper C-style lookup infrastructure.
"

It was reverted in dfdf1c5fe45a82b9c578306f3d7627fd251d63f8 because it broke the
bots of lldb. This failure was subtle to debug but the current model does not
work well with ObjectiveC support in lldb. This patch does cleans up the
partial translation units in ObjectiveC. In future if we want to support
ObjectiveC we need to understand what exactly lldb is doing when recovering from
errors...
2024-06-04 13:55:03 +00:00
Stefan Gränitz
4310988991 [clang-repl] Even more tests create the Interpreter and must check host JIT support 2 (#84758) 2024-05-30 11:52:15 +02:00
Stefan Gränitz
cb7995a130
[clang-repl] Set up executor implicitly to account for init PTUs (#84758)
Until now the IncrExecutor was created lazily on the first execution
request. In order to process the PTUs that come from initialization, we
have to do it upfront implicitly.
2024-05-28 11:22:49 +02:00
Jason Molenda
dfdf1c5fe4 Revert "[clang-repl] Extend the C support. (#89804)"
This reverts commit 253c28fa829cee0104c2fc59ed1a958980b5138c.

This commit is causing failures on the lldb CI bots, e.g.
https://ci.swift.org/view/all/job/llvm.org/view/LLDB/job/as-lldb-cmake/4307/

On my local macOS desktop build,
```
bin/lldb-dotest -p TestImportBuiltinFileID.py
Assertion failed: (D->getLexicalDeclContext() == this && "Decl inserted into wrong lexical context"), function addHiddenDecl, file DeclBase.cpp, line 1692.

6  libsystem_c.dylib        0x0000000185f0b8d0 abort + 128
7  libsystem_c.dylib        0x0000000185f0abc8 err + 0
8  liblldb.19.0.0git.dylib  0x00000001311e5800 clang::DeclContext::addHiddenDecl(clang::Decl*) + 120
9  liblldb.19.0.0git.dylib  0x00000001311e5978 clang::DeclContext::addDecl(clang::Decl*) + 32
10 liblldb.19.0.0git.dylib  0x000000012f617b48 clang::Sema::ActOnStartTopLevelStmtDecl(clang::Scope*) + 64
11 liblldb.19.0.0git.dylib  0x000000012eaf76c8 clang::Parser::ParseTopLevelStmtDecl() + 208
12 liblldb.19.0.0git.dylib  0x000000012ec051fc clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) + 3412
13 liblldb.19.0.0git.dylib  0x000000012ec03274 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) + 2020
14 liblldb.19.0.0git.dylib  0x000000012eaca860 clang::ParseAST(clang::Sema&, bool, bool) + 604
15 liblldb.19.0.0git.dylib  0x000000012e8554c0 clang::ASTFrontendAction::ExecuteAction() + 308
16 liblldb.19.0.0git.dylib  0x000000012e854c78 clang::FrontendAction::Execute() + 124
17 liblldb.19.0.0git.dylib  0x000000012e76dcfc clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 984
18 liblldb.19.0.0git.dylib  0x000000012e784500 compileModuleImpl(clang::CompilerInstance&, clang::SourceLocation, llvm::StringRef, clang::FrontendInputFile, llvm::StringRef, llvm::StringRef, llvm::function_ref<void (clang::CompilerInstance&)>, llvm::function_ref<void (clang::CompilerInstance&)>)::$_1::operator()() const + 52
```
Reverting until Vassil has a chance to look int oit.
2024-05-21 18:04:38 -07:00
Vassil Vassilev
253c28fa82
[clang-repl] Extend the C support. (#89804)
The IdResolver chain is the main way for C to implement lookup rules.
Every new partial translation unit caused clang to exit the top-most
scope which in turn cleaned up the IdResolver chain. That was not an
issue for C++ because its lookup is implemented on the level of
declaration contexts.

This patch keeps the IdResolver chain across partial translation units
maintaining proper C-style lookup infrastructure.
2024-05-21 20:21:32 +03:00
Sean Perry
c9ab1d8905
Mark test cases as unsupported on z/OS (#90990)
These test cases are testing features not available when either
targeting the s390x-ibm-zos target or use tools/features not available
on the z/OS operating system. In a couple cases the lit test had a
number of subtests with one or two that aren't supported on z/OS. Rather
than mark the entire test as unsupported I split out the unsupported
tests into a separate test case.
2024-05-07 15:23:50 -04: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
4b70d17bcf
[clang-repl] Names declared in if conditions and for-init statements are local to the inner context (#84150)
Make TopLevelStmtDecl a DeclContext so that variables defined in statements
are attached to the TopLevelDeclContext. This fixes redefinition errors
from variables declared in if conditions and for-init statements. These
must be local to the inner context (C++ 3.3.2p4), but they had generated
definitions on global scope instead.

This PR makes the TopLevelStmtDecl looking more like a FunctionDecl and
that's fine because the FunctionDecl is very close in terms of semantics.

Additionally, ActOnForStmt() requires a CompoundScope when processing a
NullStmt body.

---------

Co-authored-by: Vassil Vassilev <v.g.vassilev@gmail.com>
2024-03-07 14:27:04 +01:00
Wei Wang
ae931b4703
[Clang][test] Limit library search when linking shared lib (#80253)
Don't search for unnecessary libs when linking the shared lib. This
allows the test to run in chroot environment.
2024-02-01 00:29:59 -08:00
Jinsong Ji
b929be2d12
[Clang][test] Add fPIC when building shared library (#80065)
Fix linking error: "ld: error: can't create dynamic relocation
R_X86_64_64 against local symbol in readonly segment; recompile object
files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in
the output"
2024-01-31 11:51:15 -05:00
Chuanqi Xu
d71831a217 [NFC] [clang-repl] Fix test failures due to incosistent target settings
See https://github.com/llvm/llvm-project/pull/79261 for details.

It shows that clang-repl uses a different target triple with clang so that it
may be problematic if the calng-repl reads the generated BMI from clang
in a different target triple.

While the underlying issue is not easy to fix, this patch tries to make
this test green to not bother developers.
2024-01-31 16:05:15 +08:00
Chuanqi Xu
c1259650e7 [NFC] Add more requirement to clang/test/Interpreter/cxx20-modules.cppm
The previous test can't work on other platforms like PS4.

Address the comments in
https://github.com/llvm/llvm-project/pull/79261#issuecomment-1907589030
2024-01-24 16:10:49 +08:00
Chuanqi Xu
dd3e6c87f3
Support C++20 Modules in clang-repl (#79261)
This comes from when I playing around clang-repl with moduels : )

I succeeded to import std with https://libcxx.llvm.org/Modules.html and
calling `std::printf` after this patch.

I want to put the documentation part to
https://clang.llvm.org/docs/StandardCPlusPlusModules.html in a separate
commit.
2024-01-24 15:45:05 +08:00
kelbon
818de32f31
Warning for incorrect use of 'pure' attribute (#78200)
This adds a warning when applying the `pure` attribute along with the `const` attribute, or when applying the `pure` attribute to a function with a `void` return type (including constructors and destructors).

Fixes https://github.com/llvm/llvm-project/issues/77482
2024-01-20 12:37:35 -05:00
Vassil Vassilev
1566f1ffc6
[clang-repl] Add a interpreter-specific overload of operator new for C++ (#76218)
This patch brings back the basic support for C by inserting the required
for value printing runtime only when we are in C++ mode. Additionally,
it defines a new overload of operator placement new because we can't
really forward declare it in a library-agnostic way.

Fixes the issue described in llvm/llvm-project#69072.
2024-01-18 16:06:04 +02:00
Martin Storsjö
2c4f938f1c
Reapply #2 [clang-repl] [test] Make an XFAIL more precise (#71168)
The const.cpp testcase fails when running in MSVC mode, while it does
succeed in MinGW mode.

In MSVC mode, there are more constructor invocations than expected, as
the printout looks like this:

    A(1), this = 0000025597930000
    A(1), this = 0000025597930000
    f: this = 0000025597930000, val = 1
    A(1), this = 0000025597930000
    f: this = 0000025597930000, val = 1
    ~A, this = 0000025597930000, val = 1
    ~A, this = 0000025597930000, val = 1
    ~A, this = 0000025597930000, val = 1

While the expected printout looks like this:

    A(1), this = 000002C903E10000
    f: this = 000002C903E10000, val = 1
    f: this = 000002C903E10000, val = 1
    ~A, this = 000002C903E10000, val = 1

Reapplying #70991 with the XFAIL changed to check the host triple, not
the target triple. On an MSVC based build of Clang, but with the default
target triple set to PS4/PS5, we will still see the failure. And a Linux
based build of Clang that targets PS4/PS5 won't see the issue.
2023-11-07 11:41:56 +02:00
Martin Storsjö
89a336add7 Revert "Reapply [clang-repl] [test] Make an XFAIL more precise (#70991)"
This reverts commit e9db60c05e2fb96ff40cbb1f78790abc5de9237e.
This was still failing (unexpectedly passing) on some Sony PS
buildbots.

The issue is that the clang-repl testcases don't depend on what
the default target triple is, but what the host triple is,
which is used for JIT purposes.
2023-11-03 11:55:33 +02:00
Martin Storsjö
e9db60c05e Reapply [clang-repl] [test] Make an XFAIL more precise (#70991)
The const.cpp testcase fails when running in MSVC mode, while it does
succeed in MinGW mode.

In MSVC mode, there are more constructor invocations than expected, as
the printout looks like this:

    A(1), this = 0000025597930000
    A(1), this = 0000025597930000
    f: this = 0000025597930000, val = 1
    A(1), this = 0000025597930000
    f: this = 0000025597930000, val = 1
    ~A, this = 0000025597930000, val = 1
    ~A, this = 0000025597930000, val = 1
    ~A, this = 0000025597930000, val = 1

While the expected printout looks like this:

    A(1), this = 000002C903E10000
    f: this = 000002C903E10000, val = 1
    f: this = 000002C903E10000, val = 1
    ~A, this = 000002C903E10000, val = 1

Reapplying with the XFAIL pattern expanded to include PS4/PS5
triples as well, which also seem to have the same behaviour
as MSVC.
2023-11-03 11:30:08 +02:00
Martin Storsjö
b73d739073 Revert "[clang-repl] [test] Make an XFAIL more precise (#70991)"
This reverts commit 3bc056d5f0ebe9e4074afa088c3a0355f9ab901a.

This broke on bots with a target triple of x86_64-sie-ps5,
which also appear to behave like the MSVC case.
2023-11-02 10:49:55 +02:00
Martin Storsjö
3bc056d5f0
[clang-repl] [test] Make an XFAIL more precise (#70991)
The const.cpp testcase fails when running in MSVC mode, while it does
succeed in MinGW mode.

In MSVC mode, there are more constructor invocations than expected, as
the printout looks like this:

    A(1), this = 0000025597930000
    A(1), this = 0000025597930000
    f: this = 0000025597930000, val = 1
    A(1), this = 0000025597930000
    f: this = 0000025597930000, val = 1
    ~A, this = 0000025597930000, val = 1
    ~A, this = 0000025597930000, val = 1
    ~A, this = 0000025597930000, val = 1

While the expected printout looks like this:

    A(1), this = 000002C903E10000
    f: this = 000002C903E10000, val = 1
    f: this = 000002C903E10000, val = 1
    ~A, this = 000002C903E10000, val = 1
2023-11-02 09:51:33 +02:00
Jonas Hahnfeld
4f6757ce4b
[JITLink][RISCV] Implement eh_frame handling (#68253)
This requires adding a `NegDelta32` edge kind that cannot be mapped to
existing relocations.

Co-authored-by: Job Noorman <jnoorman@igalia.com>
2023-10-28 11:30:43 +02:00
Jonas Hahnfeld
4812eecd71 [clang-repl] XFAIL new const.cpp test on Windows
Still failing after the previous commit:
https://lab.llvm.org/buildbot/#/builders/216/builds/28268
2023-10-03 13:30:01 +02:00
Jonas Hahnfeld
b6ee41f83c [clang-repl] Relax regular expression for new const.cpp test
This should fix the failing test on Windows:
https://lab.llvm.org/buildbot/#/builders/216/builds/28266
2023-10-03 13:10:31 +02:00
Jonas Hahnfeld
05137ecfca
[clang-repl] Emit const variables only once (#65257)
Disable internal linkage for const variables if IncrementalExtensions
are enabled. Otherwise the variables are emitted multiple times, with
multiple constructions at unique memory locations, during every PTU.
2023-10-03 11:58:23 +02:00
Jonas Hahnfeld
6c274ba410 [clang-repl] Disambiguate declarations with private typedefs
Member functions and static variable definitions may use typedefs that
are private in the global context, but fine in the class context.

Differential Revision: https://reviews.llvm.org/D157838
2023-08-23 11:29:26 +02:00
Jonas Hahnfeld
c861d32d7c [CodeGen] Keep track of eagerly emitted globals
An inline virtual function must be emitted, but we need to remember
it and emit the same definition again in the future in case later
LLVM optimizations stripped it from the Module. The added test case
shows the problem; before this patch, it would fail with:
    Symbols not found: [ _ZN1AD0Ev, _ZN1AD1Ev ]

This reapplies commit f8dadefd4a, reverted in commit 0e17372b38, but
disables RTTI in the test to avoid problems on Windows.

Differential Revision: https://reviews.llvm.org/D156537
2023-08-18 09:42:28 +02:00
Jonas Hahnfeld
0e17372b38 Revert "[CodeGen] Keep track of eagerly emitted globals"
The added test doesn't work on Windows:
https://lab.llvm.org/buildbot/#/builders/216/builds/25769

This reverts commit f8dadefd4afc8e1b7b9a1e69a0ba8df051e03328.
2023-08-17 14:21:39 +02:00
Jonas Hahnfeld
f8dadefd4a [CodeGen] Keep track of eagerly emitted globals
An inline virtual function must be emitted, but we need to remember
it and emit the same definition again in the future in case later
LLVM optimizations stripped it from the Module. The added test case
shows the problem; before this patch, it would fail with:
    Symbols not found: [ _ZN1AD0Ev, _ZN1AD1Ev ]

Differential Revision: https://reviews.llvm.org/D156537
2023-08-17 13:26:22 +02:00
Jonas Hahnfeld
ba475a4a34 [clang-repl] Disambiguate global namespace identifiers
A double colon starts an identifier name in the global namespace and
must be tentatively parsed as such.

Differential Revision: https://reviews.llvm.org/D157480
2023-08-14 10:11:27 +02:00
Jonas Hahnfeld
da555f750a [clang-repl] Additional test for disambiguation of templates
This test case was fixed in commit 2c4620c1 ("Consider the scope spec
in template lookups for deduction guides."), but it is worth having a
dedicated test case with a templated struct and a using declaration.

Differential Revision: https://reviews.llvm.org/D157477
2023-08-09 16:15:14 +02:00
Jonas Hahnfeld
ac6e9e69ba [clang-repl] Remove redundant tests
They only need to be tested once in execute.cpp and fail.cpp.

Differential Revision: https://reviews.llvm.org/D156425
2023-07-27 16:22:56 +02: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
Tobias Hieta
dd3c26a045
[NFC][Py Reformat] Reformat python files in clang and clang-tools-extra
This is an ongoing series of commits that are reformatting our
Python code.

Reformatting is done with `black`.

If you end up having problems merging this commit because you
have made changes to a python file, the best way to handle that
is to run git checkout --ours <yourfile> and then reformat it
with black.

If you run into any problems, post to discourse about it and
we will try to help.

RFC Thread below:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Reviewed By: MatzeB

Differential Revision: https://reviews.llvm.org/D150761
2023-05-23 08:29:52 +02: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
Vitaly Buka
9e270c64a7 [test][clang-repl] Disable test incompatible with msan 2023-05-18 01:24:03 -07:00
Vassil Vassilev
2c4620c1da [clang-repl] Consider the scope spec in template lookups for deduction guides.
isDeductionGuideName looks up the underlying template and if the template name
is qualified we miss that qualification resulting in an error. This issue
resurfaced in clang-repl where we call isDeductionGuideName more often to
distinguish between if we had a statement or declaration.

This patch passes the CXXScopeSpec information down to LookupTemplateName to
make the lookup more precise.

Differential revision: https://reviews.llvm.org/D147319
2023-05-08 17:54:56 +00:00
Vassil Vassilev
743ff9c8ba [clang-repl] Do not assert if we have weak references left.
Non-incremental Clang can also exit with the WeakRefReferences not empty upon
such example. This patch makes clang-repl consistent to what Clang does.

Differential revision: https://reviews.llvm.org/D148435
2023-05-08 09:13:00 +00:00
Vassil Vassilev
87ae746924 [clang-repl] Add a test coverage for nested out-of-line dtor disambiguation.
This came up as a review comment in https://reviews.llvm.org/D148425
2023-05-02 09:39:48 +00:00
Vassil Vassilev
5a9abe8466 [clang-repl] Correctly disambiguate dtor declarations from statements.
Differential revision: https://reviews.llvm.org/D148425
2023-04-30 19:44:52 +00:00