[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-07-02 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

Oh, understood. Perhaps would be better if you move it. I am currently on 
vacation for a while…

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-07-02 Thread Balazs Benics via cfe-commits

steakhal wrote:

> Do you mean the documentation? If so, yes, that’s probably not the right 
> place. I am on my phone but can you suggest a place where we should move this 
> or just move it? I think that was an oversight.

Thanks. There is nothing urgent. I was just preparing a PR for syncing the 
release notes with what we actually did in CSA, so I realized this.

I wanted to check first if you already have a well established place/section 
where you would prefer to have this, as I couldn't find one in 3 seconds.
You can move it, or alternatively I can also move it.
It's up to you. :)

(The release branch is 
[supposed](https://discourse.llvm.org/t/llvm-19-release-schedule-and-planning/79828?u=steakhal)
 to branch off on the 23rd of July)

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-07-02 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

Do you mean the documentation? If so, yes, that’s probably not the right place. 
I am on my phone but can you suggest a place where we should move this or just 
move it? I think that was an oversight. 

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-07-02 Thread Balazs Benics via cfe-commits

steakhal wrote:

@vgvassilev It appears that this PR added an entry to the Static Analyzer 
section, and I'm not sure if that's the right one.
Could you please suggest an alternative section where I should move it?

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Nathan Chancellor via cfe-commits


@@ -0,0 +1,31 @@
+// UNSUPPORTED: system-aix
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/mod.cppm --precompile \
+// RUN: -o %t/mod.pcm
+// RUN: %clang %t/mod.pcm -c -o %t/mod.o
+// RUN: %clang -shared %t/mod.o -o %t/libmod.so
+//
+// RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
+// RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \
+// RUN: | FileCheck %t/import.cpp

nathanchance wrote:

You can land it, thanks for continuing to chase this!

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,31 @@
+// UNSUPPORTED: system-aix
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/mod.cppm --precompile \
+// RUN: -o %t/mod.pcm
+// RUN: %clang %t/mod.pcm -c -o %t/mod.o
+// RUN: %clang -shared %t/mod.o -o %t/libmod.so
+//
+// RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
+// RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \
+// RUN: | FileCheck %t/import.cpp

ChuanqiXu9 wrote:

Good, would you like to land it? Or I will do it.

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Nathan Chancellor via cfe-commits


@@ -0,0 +1,31 @@
+// UNSUPPORTED: system-aix
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/mod.cppm --precompile \
+// RUN: -o %t/mod.pcm
+// RUN: %clang %t/mod.pcm -c -o %t/mod.o
+// RUN: %clang -shared %t/mod.o -o %t/libmod.so
+//
+// RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
+// RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \
+// RUN: | FileCheck %t/import.cpp

nathanchance wrote:

```diff
diff --git a/clang/test/Interpreter/cxx20-modules.cppm 
b/clang/test/Interpreter/cxx20-modules.cppm
index 2c6eba525519..cd2b04fdc547 100644
--- a/clang/test/Interpreter/cxx20-modules.cppm
+++ b/clang/test/Interpreter/cxx20-modules.cppm
@@ -6,13 +6,13 @@
 // RUN: split-file %s %t
 //
 // RUN: %clang -std=c++20 %t/mod.cppm --precompile \
-// RUN: -o %t/mod.pcm
-// RUN: %clang %t/mod.pcm -c -o %t/mod.o
-// RUN: %clang -shared %t/mod.o -o %t/libmod.so
+// RUN: -o %t/mod.pcm --target=x86_64-linux-gnu
+// RUN: %clang %t/mod.pcm -c -o %t/mod.o --target=x86_64-linux-gnu
+// RUN: %clang -shared %t/mod.o -o %t/libmod.so --target=x86_64-linux-gnu
 //
 // RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
 // RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \
-// RUN: | FileCheck %t/import.cpp
+// RUN: -Xcc=--target=x86_64-linux-gnu | FileCheck %t/import.cpp
 
 //--- mod.cppm
 export module M;
```

appears to work for me.

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,31 @@
+// UNSUPPORTED: system-aix
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/mod.cppm --precompile \
+// RUN: -o %t/mod.pcm
+// RUN: %clang %t/mod.pcm -c -o %t/mod.o
+// RUN: %clang -shared %t/mod.o -o %t/libmod.so
+//
+// RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
+// RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \
+// RUN: | FileCheck %t/import.cpp

ChuanqiXu9 wrote:

@nathanchance this is what I expected to test

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,31 @@
+// UNSUPPORTED: system-aix
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/mod.cppm --precompile \
+// RUN: -o %t/mod.pcm
+// RUN: %clang %t/mod.pcm -c -o %t/mod.o
+// RUN: %clang -shared %t/mod.o -o %t/libmod.so
+//
+// RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
+// RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \
+// RUN: | FileCheck %t/import.cpp

ChuanqiXu9 wrote:

// RUN: %clang -std=c++20 %t/mod.cppm --precompile \
// RUN: -o %t/mod.pcm -triple=x86_64-linux-gnu
// RUN: %clang %t/mod.pcm -c -o %t/mod.o -triple=x86_64-linux-gnu
// RUN: %clang -shared %t/mod.o -o %t/libmod.so -triple=x86_64-linux-gnu
//
// RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
// RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \
// RUN: -Xcc=-triple=x86_64-linux-gnu | FileCheck %t/import.cpp

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 commented:

This is what I had in mind

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 edited 
https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Nathan Chancellor via cfe-commits

nathanchance wrote:

> But due to I can't reproduce the failure, @nathanchance would you like to 
> make this? I don't want to make something that I can't test.

I don't mind submitting something if I have some guidance around how this 
should be handled (I am a little lost in this thread at the moment). 
Alternatively, I am able to reproduce this with:

(`/usr/bin/clang -print-target-triple` is `x86_64-pc-linux-gnu`, if you'd 
rather use it directly)

```sh
$ cmake \
-B build \
-G Ninja \
-S llvm \
-Wno-dev \
--log-level=NOTICE \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DLLVM_DEFAULT_TARGET_TRIPLE=$(/usr/bin/clang -print-target-triple) \
-DLLVM_ENABLE_PROJECTS=clang \
-DLLVM_USE_LINKER=lld

$ ninja -C build check-clang
...
error: PCH file was compiled for the target 'x86_64-pc-linux-gnu' but the 
current translation unit is being compiled for target 'x86_64-unknown-linux-gnu'
error: module file 
.../tools/clang/test/Interpreter/Output/cxx20-modules.cppm.tmp/mod.pcm cannot 
be loaded due to a configuration mismatch with the current compilation 
[-Wmodule-file-config-mismatch]
error: Parsing failed.
...
```

so it should be easy to test and verify the fix.

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> > > > IncrementalExtensions
> > > 
> > > 
> > > But the change itself is to make `IncrementalExtensions` a compatible 
> > > lang options. So that we don't need to specify it when generating the 
> > > modules.
> > 
> > 
> > I mean conditionally if `IncrementalExtensions` is set we change the target 
> > triple in the clang fork of the C++ module build.
> 
> I am not sure if it is possible since we don't know the clang fork before we 
> see the import. Even if we can, it is more or less problematic if there are 
> multiple imported module from different fork.

I can find arguments in changing the clang-repl target triple to match the 
loaded module… That would have some reasoning but maybe we won’t be able to 
start the jit if the triples are too different. 


https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> > > IncrementalExtensions
> > 
> > 
> > But the change itself is to make `IncrementalExtensions` a compatible lang 
> > options. So that we don't need to specify it when generating the modules.
> 
> I mean conditionally if `IncrementalExtensions` is set we change the target 
> triple in the clang fork of the C++ module build.

I am not sure if it is possible since we don't know the clang fork before we 
see the import. Even if we can, it is more or less problematic if there are 
multiple imported module from different fork.

> 
> > I am wondering if it helps if we specify the target triple in the test, 
> > then it won't be so troublesome.
> 
> I was wondering that too. Can we express that in lit?

For `%clang_cc1`, we can use `%clang_cc1 -triple=x86_64-linux-gnu`. I am not 
sure about clang-repl. It may be possible by `-Xcc=`.

But due to I can't reproduce the failure, @nathanchance would you like to make 
this? I don't want to make something that I can't test.

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> > IncrementalExtensions
> 
> But the change itself is to make `IncrementalExtensions` a compatible lang 
> options. So that we don't need to specify it when generating the modules.

I mean conditionally if `IncrementalExtensions` is set we change the target 
triple in the clang fork of the C++ module build.

> I am wondering if it helps if we specify the target triple in the test, then 
> it won't be so troublesome.

I was wondering that too. Can we express that in lit?

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

I am wondering if it helps if we specify the target triple in the test, then it 
won't be so troublesome.

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> IncrementalExtensions

But the change itself is to make `IncrementalExtensions` a compatible lang 
options. So that we don't need to specify it when generating the modules.

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

We have a `LangOption` called `IncrementalExtensions`. We might be able to use 
it there.

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-30 Thread Nikita Popov via cfe-commits

nikic wrote:

> Until this change we sailed fairly well. It seems that the pcm rigorously 
> records the clang notion of the triple which is probably what we want. 
> However, if we are building a pcm in the context of `clang-repl` would it 
> make sense to use the `getProcessTriple` notion for that pcm -- that'd be the 
> behavior if we used header files instead of a module.

The pcm here is being generated by clang, not by clang-repl, so I'm not sure 
how we would know that we need to switch the triple.

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-29 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

@nikic, thanks for the details! 

Until this change we sailed fairly well with that change. It seems that the pcm 
rigorously records the clang notion of the triple which is probably what we 
want. However, if we are building a pcm in the context of `clang-repl` would it 
make sense to use the `getProcessTriple` notion for that pcm -- that'd be the 
behavior if we used header files instead of a module.

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-29 Thread Nikita Popov via cfe-commits

nikic wrote:

Normal clang creates a driver using the default target triple here: 
https://github.com/llvm/llvm-project/blob/754a8add57098ef71e4a51a9caa0cc175e94377d/clang/tools/driver/driver.cpp#L485

clang-repl appears to use IncrementalCompilerBuilder, which uses 
`getProcessTriple()` here: 
https://github.com/llvm/llvm-project/blob/754a8add57098ef71e4a51a9caa0cc175e94377d/clang/lib/Interpreter/Interpreter.cpp#L165-L166

getProcessTriple() is based on LLVM_HOST_TRIPLE with some fixups.

I'm not really sure what the right fix here is. It makes sense that an 
interpreter uses the host triple by default, but it's also a problem that clang 
and clang-repl use different default triples.

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-26 Thread Nathan Chancellor via cfe-commits

nathanchance wrote:

@vgvassilev Yes, it appears so, I tried one of the examples from [the 
documentation](https://clang.llvm.org/docs/ClangRepl.html) since I have no 
prior experience with `clang-repl`.

```
$ clang-repl --version
LLVM (http://llvm.org/):
  LLVM version 19.0.0git
  Optimized build with assertions.

$ clang-repl
clang-repl> #include 
clang-repl> int sum(int a, int b){ return a+b; };
clang-repl> int c = sum(9,10);
clang-repl> std::cout << c << std::endl;
19
clang-repl> ^D
```

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-25 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

We pass the CompilerInstance's notion of the target triple this commit explains 
it: 
https://github.com/llvm/llvm-project/commit/49f9532165f0cc0485a7da84662ebf63d155652c

@nathanchance, can `clang-repl` be run on your setup? If the Jit is happy about 
the target triple and we can jit code that'd probably mean that the modules 
infrastructure gets confused about the target triple and build a C++ module for 
the wrong configuration.

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-25 Thread Nathan Chancellor via cfe-commits

nathanchance wrote:

This is out of my wheelhouse to debug to be honest but it seems to me that 
`clang-repl` does not respect `LLVM_DEFAULT_TARGET_TRIPLE` somehow? This test 
does the same thing as other tests to build modules but this appears to be the 
only one that uses `clang-repl` to consume the `.pcm`.

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-24 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

It looks true but the test does the same thing as other tests to build modules

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-24 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

Perhaps we are not propagating the correct triple down to the module build 
action?

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-24 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> For what it's worth, this test appears to fail when 
> `LLVM_DEFAULT_TARGET_TRIPLE` is changed (my script sets it to the output of 
> my Linux distribution's `clang -print-target-triple`)
> 
> ```
> error: PCH file was compiled for the target 'x86_64-pc-linux-gnu' but the 
> current translation unit is being compiled for target 
> 'x86_64-unknown-linux-gnu'
> error: module file 
> .../tools/clang/test/Interpreter/Output/cxx20-modules.cppm.tmp/mod.pcm cannot 
> be loaded due to a configuration mismatch with the current compilation 
> [-Wmodule-file-config-mismatch]
> error: Parsing failed.
> ```

Thanks. But I am not sure how should I change the test. Do you have any idea or 
suggestion? 

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-24 Thread Nathan Chancellor via cfe-commits

nathanchance wrote:

For what it's worth, this test appears to fail when 
`LLVM_DEFAULT_TARGET_TRIPLE` is changed (my script sets it to the output of my 
Linux distribution's `clang -print-target-triple`)

```
error: PCH file was compiled for the target 'x86_64-pc-linux-gnu' but the 
current translation unit is being compiled for target 'x86_64-unknown-linux-gnu'
error: module file 
.../tools/clang/test/Interpreter/Output/cxx20-modules.cppm.tmp/mod.pcm cannot 
be loaded due to a configuration mismatch with the current compilation 
[-Wmodule-file-config-mismatch]
error: Parsing failed.
```

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-24 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> Hi @ChuanqiXu9, the test you added is failing on the PS4 bot because for the 
> PS4 target, it requires an external linker which is not present/available. 
> Can the test be rewritten to not require linking?
> 
> https://lab.llvm.org/buildbot/#/builders/139/builds/57928
> 
> ```
> clang: error: unable to execute command: Executable "orbis-ld" doesn't exist!
> clang: error: linker command failed with exit code 1 (use -v to see 
> invocation)
> ```

Oh, maybe I need to add more requires to the test.

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-23 Thread via cfe-commits

dyung wrote:

Hi @ChuanqiXu9, the test you added is failing on the PS4 bot because for the 
PS4 target, it requires an external linker which is not present/available. Can 
the test be rewritten to not require linking?

https://lab.llvm.org/buildbot/#/builders/139/builds/57928
```
clang: error: unable to execute command: Executable "orbis-ld" doesn't exist!
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-23 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 closed 
https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-23 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev approved this pull request.

Lgtm! Thank you @ChuanqiXu9!

https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-23 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Chuanqi Xu (ChuanqiXu9)


Changes

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/79261.diff


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Basic/LangOptions.def (+1-1) 
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+3-3) 
- (added) clang/test/Interpreter/cxx20-modules.cppm (+31) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc7511e9136734..db3d74e124e7d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -191,6 +191,8 @@ Crash and bug fixes
 Improvements
 
 
+- Support importing C++20 modules in clang-repl.
+
 Moved checkers
 ^^
 
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 8fc75e1cca0399..1e671a7c460163 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -485,7 +485,7 @@ VALUE_LANGOPT(FuchsiaAPILevel, 32, 0, "Fuchsia API level")
 // on large _BitInts.
 BENIGN_VALUE_LANGOPT(MaxBitIntWidth, 32, 128, "Maximum width of a _BitInt")
 
-LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process statements"
+COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process 
statements"
 "on the global scope, ignore EOF token and continue later on (thus "
 "avoid tearing the Lexer and etc. down). Controlled by "
 "-fincremental-extensions.")
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index a149d82153037f..867f4c47eaeceb 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -3286,10 +3286,10 @@ DeclContext 
*ASTDeclReader::getPrimaryContextForMerging(ASTReader ,
   if (auto *OID = dyn_cast(DC))
 return OID->getDefinition();
 
-  // We can see the TU here only if we have no Sema object. In that case,
-  // there's no TU scope to look in, so using the DC alone is sufficient.
+  // We can see the TU here only if we have no Sema object. It is possible
+  // we're in clang-repl so we still need to get the primary context.
   if (auto *TU = dyn_cast(DC))
-return TU;
+return TU->getPrimaryContext();
 
   return nullptr;
 }
diff --git a/clang/test/Interpreter/cxx20-modules.cppm 
b/clang/test/Interpreter/cxx20-modules.cppm
new file mode 100644
index 00..bc2b722f6b5197
--- /dev/null
+++ b/clang/test/Interpreter/cxx20-modules.cppm
@@ -0,0 +1,31 @@
+// UNSUPPORTED: system-aix
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/mod.cppm --precompile \
+// RUN: -o %t/mod.pcm
+// RUN: %clang %t/mod.pcm -c -o %t/mod.o
+// RUN: %clang -shared %t/mod.o -o %t/libmod.so
+//
+// RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
+// RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \
+// RUN: | FileCheck %t/import.cpp
+
+//--- mod.cppm
+export module M;
+export const char* Hello() {
+return "Hello Interpreter for Modules!";
+}
+
+//--- import.cpp
+
+%lib libmod.so
+
+import M;
+
+extern "C" int printf(const char *, ...);
+printf("%s\n", Hello());
+
+// CHECK: Hello Interpreter for Modules!

``




https://github.com/llvm/llvm-project/pull/79261
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Support C++20 Modules in clang-repl (PR #79261)

2024-01-23 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 created 
https://github.com/llvm/llvm-project/pull/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.

>From 70cb9ac882605c3557dc41ea13a4b8945c59e9c2 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 24 Jan 2024 14:21:25 +0800
Subject: [PATCH] Support C++20 Modules in clang-repl

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/Basic/LangOptions.def |  2 +-
 clang/lib/Serialization/ASTReaderDecl.cpp |  6 ++---
 clang/test/Interpreter/cxx20-modules.cppm | 31 +++
 4 files changed, 37 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Interpreter/cxx20-modules.cppm

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fc7511e9136734..db3d74e124e7d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -191,6 +191,8 @@ Crash and bug fixes
 Improvements
 
 
+- Support importing C++20 modules in clang-repl.
+
 Moved checkers
 ^^
 
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 8fc75e1cca0399..1e671a7c460163 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -485,7 +485,7 @@ VALUE_LANGOPT(FuchsiaAPILevel, 32, 0, "Fuchsia API level")
 // on large _BitInts.
 BENIGN_VALUE_LANGOPT(MaxBitIntWidth, 32, 128, "Maximum width of a _BitInt")
 
-LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process statements"
+COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process 
statements"
 "on the global scope, ignore EOF token and continue later on (thus "
 "avoid tearing the Lexer and etc. down). Controlled by "
 "-fincremental-extensions.")
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index a149d82153037f..867f4c47eaeceb 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -3286,10 +3286,10 @@ DeclContext 
*ASTDeclReader::getPrimaryContextForMerging(ASTReader ,
   if (auto *OID = dyn_cast(DC))
 return OID->getDefinition();
 
-  // We can see the TU here only if we have no Sema object. In that case,
-  // there's no TU scope to look in, so using the DC alone is sufficient.
+  // We can see the TU here only if we have no Sema object. It is possible
+  // we're in clang-repl so we still need to get the primary context.
   if (auto *TU = dyn_cast(DC))
-return TU;
+return TU->getPrimaryContext();
 
   return nullptr;
 }
diff --git a/clang/test/Interpreter/cxx20-modules.cppm 
b/clang/test/Interpreter/cxx20-modules.cppm
new file mode 100644
index 00..bc2b722f6b5197
--- /dev/null
+++ b/clang/test/Interpreter/cxx20-modules.cppm
@@ -0,0 +1,31 @@
+// UNSUPPORTED: system-aix
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/mod.cppm --precompile \
+// RUN: -o %t/mod.pcm
+// RUN: %clang %t/mod.pcm -c -o %t/mod.o
+// RUN: %clang -shared %t/mod.o -o %t/libmod.so
+//
+// RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
+// RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \
+// RUN: | FileCheck %t/import.cpp
+
+//--- mod.cppm
+export module M;
+export const char* Hello() {
+return "Hello Interpreter for Modules!";
+}
+
+//--- import.cpp
+
+%lib libmod.so
+
+import M;
+
+extern "C" int printf(const char *, ...);
+printf("%s\n", Hello());
+
+// CHECK: Hello Interpreter for Modules!

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits