[clang] [clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (PR #89031)

2024-04-19 Thread Jonas Hahnfeld via cfe-commits


@@ -364,6 +365,19 @@ IncrementalParser::Parse(llvm::StringRef input) {
 std::unique_ptr IncrementalParser::GenModule() {
   static unsigned ID = 0;
   if (CodeGenerator *CG = getCodeGen()) {
+// Clang's CodeGen is designed to work with a single llvm::Module. In many
+// cases for convenience various CodeGen parts have a reference to the
+// llvm::Module (TheModule or Module) which does not change when a new
+// module is pushed. However, the execution engine wants to take ownership
+// of the module which does not map well to CodeGen's design. To work this
+// around we clone the module and pass it down.

hahnjo wrote:

I believe this comment needs an update?

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


[clang] [clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (PR #89031)

2024-04-19 Thread Jonas Hahnfeld via cfe-commits


@@ -224,11 +228,8 @@ IncrementalParser::IncrementalParser(Interpreter ,
 return; // PTU.takeError();
   }
 
-  if (CodeGenerator *CG = getCodeGen()) {
-std::unique_ptr M(CG->ReleaseModule());
-CG->StartModule("incr_module_" + std::to_string(PTUs.size()),
-M->getContext());
-PTU->TheModule = std::move(M);
+  if (getCodeGen()) {
+PTU->TheModule = std::move(GenModule());

hahnjo wrote:

Just to confirm my understanding of the change: this is an independent 
deduplication cleanup, right? 

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


[clang] [clang-repl] Set up executor implicitly to account for init PTUs (PR #84758)

2024-04-15 Thread Jonas Hahnfeld via cfe-commits
Stefan =?utf-8?q?Gr=C3=A4nitz?= 
Message-ID:
In-Reply-To: 



@@ -14,7 +14,7 @@ struct A { int a; A(int a) : a(a) {} virtual ~A(); };
 // PartialTranslationUnit.
 inline A::~A() { printf("~A(%d)\n", a); }
 
-// Create one instance with new and delete it.
+// Create one instance with new and delete it. We crash here now:
 A *a1 = new A(1);

hahnjo wrote:

That is with this patch or just current `main`?

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


[clang] [clang-repl] Set up executor implicitly to account for init PTUs (PR #84758)

2024-03-19 Thread Jonas Hahnfeld via cfe-commits
Stefan =?utf-8?q?Gränitz?= 
Message-ID:
In-Reply-To: 



@@ -14,7 +14,7 @@ struct A { int a; A(int a) : a(a) {} virtual ~A(); };
 // PartialTranslationUnit.
 inline A::~A() { printf("~A(%d)\n", a); }
 
-// Create one instance with new and delete it.
+// Create one instance with new and delete it. We crash here now:
 A *a1 = new A(1);

hahnjo wrote:

I had a quick look here and got the same backtraces on Linux as 
@weliveindetail. From the debugger, it seems to fail because the DataLayout is 
not properly initialized? This could mean that executing the initial, empty PTU 
causes some damage in the internal data structures, but not sure...

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


[clang] [clang-repl] Set up executor implicitly to account for init PTUs (PR #84758)

2024-03-11 Thread Jonas Hahnfeld via cfe-commits
Stefan =?utf-8?q?Gränitz?= 
Message-ID:
In-Reply-To: 



@@ -14,7 +14,7 @@ struct A { int a; A(int a) : a(a) {} virtual ~A(); };
 // PartialTranslationUnit.
 inline A::~A() { printf("~A(%d)\n", a); }
 
-// Create one instance with new and delete it.
+// Create one instance with new and delete it. We crash here now:
 A *a1 = new A(1);

hahnjo wrote:

Do we even have initial PTUs in the default case? Also the minimal reproducer 
shows a more general version where the `virtual` destructor is actually defined 
inline (c861d32d7c2791bdc058d9d9fbaecc1c2f07b8c7 addresses the case where it is 
out-of-line, which is special due to key `virtual` functions). So if that 
breaks entirely (which is critical for us), I'm personally not ok with just 
`XFAIL`ing it to land another change...

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


[clang] [CUDA] Correctly set CUDA default architecture (PR #84017)

2024-03-06 Thread Jonas Hahnfeld via cfe-commits


@@ -2,56 +2,56 @@
 // REQUIRES: nvptx-registered-target
 // REQUIRES: zlib
 
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -g -gz 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -g -gz 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf 
-fdebug-info-for-profiling 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf -fdebug-info-for-profiling 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf-2 
-gsplit-dwarf 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf-2 -gsplit-dwarf 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf-3 -glldb 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf-3 -glldb 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf-4 -gcodeview 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf-4 -gcodeview 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf-5 -gmodules 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf-5 -gmodules 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -ggdb1 -fdebug-macro 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -ggdb1 -fdebug-macro 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -ggdb2 -ggnu-pubnames 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -ggdb2 -ggnu-pubnames 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -ggdb3 -gdwarf-aranges 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -ggdb3 -gdwarf-aranges 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -g -gcolumn-info 
-fdebug-types-section 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -g -gcolumn-info -fdebug-types-section 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
 
 // Same tests for OpenMP
-// RUN: not %clang -### --target=x86_64-linux-gnu -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -fopenmp=libomp -c %s \

hahnjo wrote:

Sure, but this one is explicitly testing the (in)compatibility of debug options 
and these run lines are supposed to test them together with OpenMP offloading. 
Now they don't anymore...

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


[clang] [clang] Add cuda-path arguments to failing test (PR #84008)

2024-03-06 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

https://github.com/llvm/llvm-project/pull/84017 changed the test in ways that 
this isn't needed anymore.

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


[clang] [clang] Add cuda-path arguments to failing test (PR #84008)

2024-03-06 Thread Jonas Hahnfeld via cfe-commits

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


[clang] [CUDA] Correctly set CUDA default architecture (PR #84017)

2024-03-05 Thread Jonas Hahnfeld via cfe-commits


@@ -2,56 +2,56 @@
 // REQUIRES: nvptx-registered-target
 // REQUIRES: zlib
 
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -g -gz 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -g -gz 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf 
-fdebug-info-for-profiling 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf -fdebug-info-for-profiling 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf-2 
-gsplit-dwarf 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf-2 -gsplit-dwarf 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf-3 -glldb 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf-3 -glldb 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf-4 -gcodeview 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf-4 -gcodeview 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -gdwarf-5 -gmodules 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -gdwarf-5 -gmodules 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -ggdb1 -fdebug-macro 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -ggdb1 -fdebug-macro 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -ggdb2 -ggnu-pubnames 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -ggdb2 -ggnu-pubnames 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -ggdb3 -gdwarf-aranges 
2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -ggdb3 -gdwarf-aranges 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
-// RUN: not %clang -### --target=x86_64-linux-gnu -c %s -g -gcolumn-info 
-fdebug-types-section 2>&1 \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -c %s -g -gcolumn-info -fdebug-types-section 2>&1 \
 // RUN: | FileCheck %s --check-prefixes WARN,COMMON
 
 // Same tests for OpenMP
-// RUN: not %clang -### --target=x86_64-linux-gnu -fopenmp=libomp 
-fopenmp-targets=nvptx64-nvidia-cuda -c %s \
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=sm_52 -nogpulib 
-nogpuinc -fopenmp=libomp -c %s \

hahnjo wrote:

Please note that this completely dropped 
`-fopenmp-targets=nvptx64-nvidia-cuda`, so the test likely lost coverage...

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


[clang] [clang] Add cuda-path arguments to failing test (PR #84008)

2024-03-05 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

Ok, but that still doesn't change the fact that the Clang driver will search 
for a system-wide CUDA installation unless passed `--cuda-path`...

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


[clang] [clang] Add cuda-path arguments to failing test (PR #84008)

2024-03-05 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

> > > Might need `-nogpulib -nogpuinc` in those cases, we do that in other 
> > > `.cu` files in the test suite.
> > 
> > 
> > No, I already tried that, it doesn't work for me. All 
> > `clang/test/Driver/*.cu` that supply `-nocudainc` also pass `--cuda-path`...
> 
> The only reason it will fail without a CUDA installation if you pass both 
> `-nogpulib` and `-nogpuinc` is if you need to use `ptxas`, which shouldn't be 
> the case if you're using options like `-###`. Tested it out by moving my CUDA 
> installation and the following works as I expect.
> 
> ```
> > cat /dev/null | clang -x cuda - --offload-arch=sm_52 -nogpulib -nogpuinc 
> > -emit-llvm -c && echo $?
> 0
> > cat /dev/null | clang -x cuda - --offload-arch=sm_52
> >   
> clang: error: cannot find libdevice for sm_52; provide path to different CUDA 
> installation via '--cuda-path', or pass '-nocudalib' to build without linking 
> with libdevice
> clang: error: cannot find CUDA installation; provide its path via 
> '--cuda-path', or pass '-nocudainc' to build without CUDA includes
> clang: error: cannot find CUDA installation; provide its path via 
> '--cuda-path', or pass '-nocudainc' to build without CUDA includes
> ```
> 
> Which tests aren't working in your case?

The invocations in `clang/test/Driver/cuda-omp-unsupported-debug-options.cu` 
don't pass `-emit-llvm` but `-###`.
```
 > cat /dev/null | ./bin/clang -### -x cuda - -nogpulib -nogpuinc -c && echo $?
```
should error with recent CUDA installations because of `sm_35`.

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


[clang] [clang] Add cuda-path arguments to failing test (PR #84008)

2024-03-05 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

> > It definitely doesn't work for the "pure" CUDA invocations, it still finds 
> > my local installation and complains. It might work for the OpenMP 
> > invocations, but hard to tell for me on a system with CUDA installed. As 
> > it's a `.cu` test after all, I think I would prefer the uniformity of 
> > passing `--cuda-path` everywhere and be safe from any weird interaction.
> 
> Might need `-nogpulib -nogpuinc` in those cases, we do that in other `.cu` 
> files in the test suite.

No, I already tried that, it doesn't work for me. All `clang/test/Driver/*.cu` 
that supply `-nocudainc` also pass `--cuda-path`...

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


[clang] [clang] Add cuda-path arguments to failing test (PR #84008)

2024-03-05 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

> We had a lot that were like this previously. Guessing this one slipped 
> through because of the `zlib` requirement.

I actually think there are some more left; for example 
`clang/test/Driver/cuda-dwarf-2.cu` has many `not %clang` invocations that 
don't specify `--cuda-path`. This happens to work on my system because my CUDA 
installation is too recent to support `sm_20`, but I suspect it would actually 
fail with an older CUDA installed...

> Does this work with `-nogpulib` instead? Usually easier than passing the 
> dummy CUDA path.

It definitely doesn't work for the "pure" CUDA invocations, it still finds my 
local installation and complains. It might work for the OpenMP invocations, but 
hard to tell for me on a system with CUDA installed. As it's a `.cu` test after 
all, I think I would prefer the uniformity of passing `--cuda-path` everywhere 
and be safe from any weird interaction.

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-02-18 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

> But my point is that we can't land that if we don't understand what's going 
> wrong without that patch.

We understand that very well and it's described in 
https://reviews.llvm.org/D153003 as well as the surrounding discussions: 
because of the way that `ODRHash` works, template template arguments `A` and 
`B` will hash to different values, even if `using A = B`. However, for template 
specializations, we require them to hash to the same value (with some form of 
normalization) or we won't find nor load the right specializations. That's why 
I said that IMHO `ODRHash` is not the right tool for the job here, which 
follows directly from an old comment of yours: 
https://reviews.llvm.org/D153003#4427412

> An important node here is that ODRHash is used to check the AST Nodes are 
> keeping the same across compilations. There is gap to use ODRHash to check 
> the semantical equality.

(and IIRC that's the same direction that Richard was going)

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-29 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

As far as I can tell from 
https://github.com/llvm/llvm-project/pull/76774#issuecomment-1914177330 above, 
the last push only changed the default value of 
`LoadExternalSpecializationsLazily`. In that case, my test results from 
https://github.com/llvm/llvm-project/pull/76774#issuecomment-1912182171 remain 
fully valid, especially

> Switching the new `LoadExternalSpecializationsLazily` to disabled by default 
> (somehow the argument didn't work on its own) instead crashes, most of the 
> cases involving `MultiOnDiskHashTable`. I suspect some kind of memory error 
> maybe?

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-26 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

The newest version of this patch still doesn't work correctly. Switching the 
new `LoadExternalSpecializationsLazily` to disabled by default (somehow the 
argument didn't work on its own) instead crashes, most of the cases involving 
`MultiOnDiskHashTable`. I suspect some kind of memory error maybe? Sorry to not 
be more helpful at the moment...

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-22 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

> Would you like to give an reproducer so that I can debug?

Not easily at the moment, unless you want to go through building the entirety 
of ROOT :-/

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-21 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

> > > I tried applying this patch to ROOT/Cling and it fails to build because 
> > > something is of the opinion that `std::is_integral::value` is not 
> > > true. I don't have time right now to investigate further, but since this 
> > > is the only change I did it is highly likely that it's caused by this...
> > 
> > 
> > In that case we need to understand how this patch differs from the one I 
> > pasted in phabricator since the one there works for that case I assume.
> 
> I had a guess. `{ClassTemplateDecl, VarTemplateDecl, 
> FunctionTemplateDecl}::specializations()` will iterate all the 
> specializations. However, after this patch, there are maybe some 
> specializations not loaded at the time of invocation. Then during the process 
> of iterating `specializations()`, it may require to complete the redecl chain 
> to trigger the process of loading specializations. Then boom!

This is also the case with https://reviews.llvm.org/D41416 and we have 
machinery to deal with that (including https://reviews.llvm.org/D154328)

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


[clang] [llvm] [JITLink][RISCV] Implement eh_frame handling (PR #68253)

2024-01-20 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

> It seems after this change we started to fail on `LLVM :: 
> ExecutionEngine/JITLink/RISCV/ELF_ehframe.s` when using debug libgcxx.

First, sorry for the slow response and breaking the builds with expensive 
checks in the first place. I believe the report is actually fully correct and 
we cannot assume the edges are ordered by their offset. The problem should be 
fixed by https://github.com/llvm/llvm-project/pull/78849

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-19 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

I tried applying this patch to ROOT/Cling and it fails to build because 
something is of the opinion that `std::is_integral::value` is not true. I 
don't have time right now to investigate further, but since this is the only 
change I did it is highly likely that it's caused by this...

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


[clang] [clang-repl] Add a interpreter-specific overload of operator new for C++ (PR #76218)

2024-01-17 Thread Jonas Hahnfeld via cfe-commits

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

Looks good (sorry, this fell through)

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2024-01-14 Thread Jonas Hahnfeld via cfe-commits

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2024-01-09 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

> Please add a release note

> This change needs a release note. Please add an entry to 
> `clang/docs/ReleaseNotes.rst` in the section the most adapted to the change, 
> and referencing any Github issue this change fixes. Thanks!

Done.

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2024-01-09 Thread Jonas Hahnfeld via cfe-commits


@@ -15754,10 +15754,18 @@ bool Expr::EvaluateAsInitializer(APValue , 
const ASTContext ,
 LValue LVal;
 LVal.set(VD);
 
-if (!EvaluateInPlace(Value, Info, LVal, this,
- /*AllowNonLiteralTypes=*/true) ||
-EStatus.HasSideEffects)
-  return false;
+{
+  // C++23 [intro.execution]/p5
+  // A full-expression is ... an init-declarator ([dcl.decl]) or a
+  // mem-initializer.
+  // So we need to make sure temporary objects are destroyed after having
+  // evaluated the expression (per C++23 [class.temporary]/p4).

hahnjo wrote:

Done.

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2024-01-09 Thread Jonas Hahnfeld via cfe-commits

https://github.com/hahnjo updated 
https://github.com/llvm/llvm-project/pull/69076

>From a55ca99a373b17501d56d18af9e8aa2dc2cbcea0 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Sat, 14 Oct 2023 20:10:28 +0200
Subject: [PATCH 1/3] Fix crash with modules and constexpr destructor

With modules, serialization might omit the outer ExprWithCleanups
as it calls ParmVarDecl::getDefaultArg(). Complementary to fixing
this in a separate change, make the code more robust by adding a
FullExpressionRAII and avoid the llvm_unreachable in the added test
clang/test/Modules/pr68702.cpp.

Closes https://github.com/llvm/llvm-project/issues/68702
---
 clang/lib/AST/ExprConstant.cpp | 16 ++---
 clang/test/Modules/pr68702.cpp | 65 ++
 2 files changed, 77 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Modules/pr68702.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f6aeee1a4e935d..416d48ae82933f 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15754,10 +15754,18 @@ bool Expr::EvaluateAsInitializer(APValue , 
const ASTContext ,
 LValue LVal;
 LVal.set(VD);
 
-if (!EvaluateInPlace(Value, Info, LVal, this,
- /*AllowNonLiteralTypes=*/true) ||
-EStatus.HasSideEffects)
-  return false;
+{
+  // C++23 [intro.execution]/p5
+  // A full-expression is ... an init-declarator ([dcl.decl]) or a
+  // mem-initializer.
+  // So we need to make sure temporary objects are destroyed after having
+  // evaluated the expression (per C++23 [class.temporary]/p4).
+  FullExpressionRAII Scope(Info);
+  if (!EvaluateInPlace(Value, Info, LVal, this,
+   /*AllowNonLiteralTypes=*/true) ||
+  EStatus.HasSideEffects)
+return false;
+}
 
 // At this point, any lifetime-extended temporaries are completely
 // initialized.
diff --git a/clang/test/Modules/pr68702.cpp b/clang/test/Modules/pr68702.cpp
new file mode 100644
index 00..d32f946910f4fb
--- /dev/null
+++ b/clang/test/Modules/pr68702.cpp
@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+
+//--- V.h
+#ifndef V_H
+#define V_H
+
+class A {
+public:
+  constexpr A() { }
+  constexpr ~A() { }
+};
+
+template 
+class V {
+public:
+  V() = default;
+
+  constexpr V(int n, const A& a = A()) {}
+};
+
+#endif
+
+//--- inst1.h
+#include "V.h"
+
+static void inst1() {
+  V v;
+}
+
+//--- inst2.h
+#include "V.h"
+
+static void inst2() {
+  V v(100);
+}
+
+//--- module.modulemap
+module "M" {
+  export *
+  module "V.h" {
+export *
+header "V.h"
+  }
+  module "inst1.h" {
+export *
+header "inst1.h"
+  }
+}
+
+module "inst2.h" {
+  export *
+  header "inst2.h"
+}
+
+//--- main.cpp
+#include "V.h"
+#include "inst2.h"
+
+static void m() {
+  static V v(100);
+}

>From 8381d35fc3e1dd57ba0dd2a76aea2931c659e419 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Wed, 10 Jan 2024 08:41:59 +0100
Subject: [PATCH 2/3] Expand comment

---
 clang/lib/AST/ExprConstant.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 416d48ae82933f..f20850d14c0c86 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15760,6 +15760,10 @@ bool Expr::EvaluateAsInitializer(APValue , const 
ASTContext ,
   // mem-initializer.
   // So we need to make sure temporary objects are destroyed after having
   // evaluated the expression (per C++23 [class.temporary]/p4).
+  //
+  // FIXME: Otherwise this may break test/Modules/pr68702.cpp because the
+  // serialization code calls ParmVarDecl::getDefaultArg() which strips the
+  // outermost FullExpr, such as ExprWithCleanups.
   FullExpressionRAII Scope(Info);
   if (!EvaluateInPlace(Value, Info, LVal, this,
/*AllowNonLiteralTypes=*/true) ||

>From 676c7ea4ad35ae9114023573d5698a22adeb1460 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Wed, 10 Jan 2024 08:47:50 +0100
Subject: [PATCH 3/3] Add a release note

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ee211c16a48ac8..aa3252b1d4f5f4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -877,6 +877,8 @@ Miscellaneous Clang Crashes Fixed
 - Fixed a crash when a lambda marked as ``static`` referenced a captured
   variable in an expression.
   `Issue 74608 `_
+- Fixed a crash with modules and a ``constexpr`` destructor.
+  `Issue 68702 `_
 
 
 OpenACC Specific Changes

___

[clang] Fix crash with modules and constexpr destructor (PR #69076)

2024-01-09 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

> address my previous comment: [#69076 
> (comment)](https://github.com/llvm/llvm-project/pull/69076#issuecomment-1780327252)

I had already expanded the commit message with the full details, now also 
copied to the PR summary. Is that sufficient to address the comment?

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2024-01-09 Thread Jonas Hahnfeld via cfe-commits

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


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-07 Thread Jonas Hahnfeld via cfe-commits


@@ -1249,3 +1249,5 @@ void ODRHash::AddQualType(QualType T) {
 void ODRHash::AddBoolean(bool Value) {
   Bools.push_back(Value);
 }
+
+void ODRHash::AddInteger(unsigned Value) { ID.AddInteger(Value); }

hahnjo wrote:

That test does not exercise an alias argument to a template template argument. 
IIRC the code you code is only active for typenames. Also see the test in 
https://reviews.llvm.org/D153003 that exercises different spellings of the 
semantically equivalent type `NS::A` inside a namespace.

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2024-01-07 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

Well, this patch is up since almost three months now (!). Sure, we can keep 
carrying a similar fix downstream, but ideally I would really like to get rid 
of as many local changes as possible. That's not possible without proper 
review, but the current situation is quite unsatisfactory...

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2024-01-07 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

Ping, is this ok to be accepted and landed?

> So personally I am fine with the current workaround with a `FIXME`.

You mean next to the comment I already added referring to the C++ standard? Can 
you formulate what I should put there?

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


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-05 Thread Jonas Hahnfeld via cfe-commits


@@ -1249,3 +1249,5 @@ void ODRHash::AddQualType(QualType T) {
 void ODRHash::AddBoolean(bool Value) {
   Bools.push_back(Value);
 }
+
+void ODRHash::AddInteger(unsigned Value) { ID.AddInteger(Value); }

hahnjo wrote:

The review related to `ODRHash` is this one: https://reviews.llvm.org/D153003

In short, my understanding is that `ODRHash` gives the following guarantee: If 
the hashes are different, there is guaranteed to be a ODR violation. In the 
other direction, if two hashes are the same, the declarations have to be 
compared in more detail, ie there may or may not be an ODR violation.

For the specializations, we need the opposite: If two template arguments are 
semantically the same (*), they *must* hash to the same value or otherwise we 
will not find the correct bucket. On the other hand, two different 
specialization arguments may have the same hash, that's fine for the map data 
structure.

Now the additional caveat (*) is that "semantically the same" is not the same 
congruence as "no ODR violation". In https://reviews.llvm.org/D153003 we 
discuss `using` declarations, but IIRC it's also possible to construct 
problematic cases with (nested) namespaces, top-level `::` prefixes, and 
template template parameters. Taken together, my conclusion from the discussion 
above is that `ODRHash` is simply not the right method to find template 
specialization parameters in a map.

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-12-27 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

I finally had time to debug this: The reason for modules being involved here is 
because the serialization code calls `ParmVarDecl::getDefaultArg()` which 
strips the outermost `FullExpr`, such as `ExprWithCleanups`. A potential fix is 
in https://github.com/llvm/llvm-project/pull/76473 though I'm not really 
convinced by this asymmetry between `getInit()` but calling `setDefaultArg()`. 
However, removing the handling of `FullExpr` in `setDefaultArg()` causes a 
total 29 test failures, so that's not an (easy) option...

Personally, I would argue that adding `FullExpressionRAII` makes the code more 
robust against the absence of `ExprWithCleanups` so that's maybe a good thing 
to have regardless of fixing the serialization code.

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-12-27 Thread Jonas Hahnfeld via cfe-commits

https://github.com/hahnjo updated 
https://github.com/llvm/llvm-project/pull/69076

>From a55ca99a373b17501d56d18af9e8aa2dc2cbcea0 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Sat, 14 Oct 2023 20:10:28 +0200
Subject: [PATCH] Fix crash with modules and constexpr destructor

With modules, serialization might omit the outer ExprWithCleanups
as it calls ParmVarDecl::getDefaultArg(). Complementary to fixing
this in a separate change, make the code more robust by adding a
FullExpressionRAII and avoid the llvm_unreachable in the added test
clang/test/Modules/pr68702.cpp.

Closes https://github.com/llvm/llvm-project/issues/68702
---
 clang/lib/AST/ExprConstant.cpp | 16 ++---
 clang/test/Modules/pr68702.cpp | 65 ++
 2 files changed, 77 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Modules/pr68702.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f6aeee1a4e935d..416d48ae82933f 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15754,10 +15754,18 @@ bool Expr::EvaluateAsInitializer(APValue , 
const ASTContext ,
 LValue LVal;
 LVal.set(VD);
 
-if (!EvaluateInPlace(Value, Info, LVal, this,
- /*AllowNonLiteralTypes=*/true) ||
-EStatus.HasSideEffects)
-  return false;
+{
+  // C++23 [intro.execution]/p5
+  // A full-expression is ... an init-declarator ([dcl.decl]) or a
+  // mem-initializer.
+  // So we need to make sure temporary objects are destroyed after having
+  // evaluated the expression (per C++23 [class.temporary]/p4).
+  FullExpressionRAII Scope(Info);
+  if (!EvaluateInPlace(Value, Info, LVal, this,
+   /*AllowNonLiteralTypes=*/true) ||
+  EStatus.HasSideEffects)
+return false;
+}
 
 // At this point, any lifetime-extended temporaries are completely
 // initialized.
diff --git a/clang/test/Modules/pr68702.cpp b/clang/test/Modules/pr68702.cpp
new file mode 100644
index 00..d32f946910f4fb
--- /dev/null
+++ b/clang/test/Modules/pr68702.cpp
@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+
+//--- V.h
+#ifndef V_H
+#define V_H
+
+class A {
+public:
+  constexpr A() { }
+  constexpr ~A() { }
+};
+
+template 
+class V {
+public:
+  V() = default;
+
+  constexpr V(int n, const A& a = A()) {}
+};
+
+#endif
+
+//--- inst1.h
+#include "V.h"
+
+static void inst1() {
+  V v;
+}
+
+//--- inst2.h
+#include "V.h"
+
+static void inst2() {
+  V v(100);
+}
+
+//--- module.modulemap
+module "M" {
+  export *
+  module "V.h" {
+export *
+header "V.h"
+  }
+  module "inst1.h" {
+export *
+header "inst1.h"
+  }
+}
+
+module "inst2.h" {
+  export *
+  header "inst2.h"
+}
+
+//--- main.cpp
+#include "V.h"
+#include "inst2.h"
+
+static void m() {
+  static V v(100);
+}

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


[clang] [Serialization] Fix instantiated default arguments (PR #76473)

2023-12-27 Thread Jonas Hahnfeld via cfe-commits

https://github.com/hahnjo created 
https://github.com/llvm/llvm-project/pull/76473

`ParmVarDecl::getDefaultArg()` strips the outermost `FullExpr`, such as 
`ExprWithCleanups`. This leads to an `llvm_unreachable` being executed with the 
added test `clang/test/Modules/pr68702.cpp`; instead use the more generic 
`VarDecl::getInit()` which also returns `FullExpr`'s.

Closes https://github.com/llvm/llvm-project/issues/68702

>From def58be1572162b4862e37ba983793e422208d38 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Wed, 27 Dec 2023 23:10:13 +0100
Subject: [PATCH] [Serialization] Fix instantiated default arguments

ParmVarDecl::getDefaultArg() strips the outermost FullExpr, such as
ExprWithCleanups. This leads to an llvm_unreachable being executed
with the added test clang/test/Modules/pr68702.cpp; instead use the
more generic VarDecl::getInit() which also returns FullExpr's.

Closes https://github.com/llvm/llvm-project/issues/68702
---
 clang/lib/Serialization/ASTWriter.cpp |  6 ++-
 clang/test/Modules/pr68702.cpp| 65 +++
 2 files changed, 69 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Modules/pr68702.cpp

diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 78939bfd533ffa..b9f65dc6d452fc 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5293,8 +5293,10 @@ void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl 
) {
 break;
 
   case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT:
-Record.AddStmt(const_cast(
-cast(Update.getDecl())->getDefaultArg()));
+// Do not use ParmVarDecl::getDefaultArg(): It strips the outermost
+// FullExpr, such as ExprWithCleanups.
+Record.AddStmt(
+const_cast(cast(Update.getDecl())->getInit()));
 break;
 
   case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER:
diff --git a/clang/test/Modules/pr68702.cpp b/clang/test/Modules/pr68702.cpp
new file mode 100644
index 00..d32f946910f4fb
--- /dev/null
+++ b/clang/test/Modules/pr68702.cpp
@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+
+//--- V.h
+#ifndef V_H
+#define V_H
+
+class A {
+public:
+  constexpr A() { }
+  constexpr ~A() { }
+};
+
+template 
+class V {
+public:
+  V() = default;
+
+  constexpr V(int n, const A& a = A()) {}
+};
+
+#endif
+
+//--- inst1.h
+#include "V.h"
+
+static void inst1() {
+  V v;
+}
+
+//--- inst2.h
+#include "V.h"
+
+static void inst2() {
+  V v(100);
+}
+
+//--- module.modulemap
+module "M" {
+  export *
+  module "V.h" {
+export *
+header "V.h"
+  }
+  module "inst1.h" {
+export *
+header "inst1.h"
+  }
+}
+
+module "inst2.h" {
+  export *
+  header "inst2.h"
+}
+
+//--- main.cpp
+#include "V.h"
+#include "inst2.h"
+
+static void m() {
+  static V v(100);
+}

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


[clang] [clang][Sema] Always clear UndefinedButUsed (PR #73955)

2023-12-12 Thread Jonas Hahnfeld via cfe-commits

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


[clang] [clang][Sema] Always clear UndefinedButUsed (PR #73955)

2023-12-12 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

I tried to craft a test here, but declaration unloading in `clang-repl` is not 
powerful enough (yet) to show a (user-visible) consequence of the problem.

On a high level, the problem should be triggered by:
```
clang-repl> template  struct A { void f() { } };
clang-repl> A().f();
clang-repl> %undo
clang-repl> A().f();
```
In principle, the `%undo` should remove the implicit template instantiation of 
`f` which is then subsequently re-instantiated. This is currently not 
implemented in `clang-repl` (we just re-use the first instantiation, which is 
wrong in case there are more lines in between that could influence the 
instantiation). With debug statements, I can verify that `f` is in 
`UndefinedButUsed`, but `getUndefinedButUsed` filters it out.

The slightly more complex
```
clang-repl> template  struct A { void f() { } };
clang-repl> A().f();
clang-repl> %undo
clang-repl> %undo
clang-repl> template  struct A { void f() { } };
clang-repl> A().f();
```
ie unloading the entire class doesn't work either for the same reason, we never 
actually treat the instantiated member function. (Subsequently this leads to 
the entire `clang-repl` crashing after printing `definition with same mangled 
name '_ZN1AIiE1fEv' as another definition`...)

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


[clang] [clang][Sema] Always clear UndefinedButUsed (PR #73955)

2023-11-30 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

I will try, but observing the consequences of this depends on unloading: 
Basically it happens if a declaration in `UndefinedButUsed` thas was previously 
defined is unloaded, which makes it undefined. For now, it's possible that for 
the upstream cases it's only an optimization because the data structure doesn't 
grow as much.

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


[clang] [clang][Sema] Always clear UndefinedButUsed (PR #73955)

2023-11-30 Thread Jonas Hahnfeld via cfe-commits

https://github.com/hahnjo created 
https://github.com/llvm/llvm-project/pull/73955

Before, it was only cleared if there were undefined entities. This is important 
for Clang's incremental parsing as used by `clang-repl` that might receive 
multiple calls to `Sema.ActOnEndOfTranslationUnit`.

>From 9dd0362e1dcffa5475d9f959ce9bfc6a7e83083b Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Thu, 30 Nov 2023 16:51:23 +0100
Subject: [PATCH] [clang][Sema] Always clear UndefinedButUsed

Before, it was only cleared if there were undefined entities. This
is important for Clang's incremental parsing as used by clang-repl
that might receive multiple calls to Sema.ActOnEndOfTranslationUnit.
---
 clang/lib/Sema/Sema.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 9771aaa2f3b0371..d08f8cd56b39bde 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -870,6 +870,7 @@ static void checkUndefinedButUsed(Sema ) {
   // Collect all the still-undefined entities with internal linkage.
   SmallVector, 16> Undefined;
   S.getUndefinedButUsed(Undefined);
+  S.UndefinedButUsed.clear();
   if (Undefined.empty()) return;
 
   for (const auto  : Undefined) {
@@ -923,8 +924,6 @@ static void checkUndefinedButUsed(Sema ) {
 if (UseLoc.isValid())
   S.Diag(UseLoc, diag::note_used_here);
   }
-
-  S.UndefinedButUsed.clear();
 }
 
 void Sema::LoadExternalWeakUndeclaredIdentifiers() {

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-11-15 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

ping @shafik @cor3ntin @ChuanqiXu9, how can we make progress here?

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


[llvm] [clang] Reapply #2 [clang-repl] [test] Make an XFAIL more precise (#70991) (PR #71168)

2023-11-03 Thread Jonas Hahnfeld via cfe-commits

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

Looks reasonable to me. I know this fixes a test error for MinGW, but if 
possible maybe let it sit until early next week in case somebody else has a 
different opinion on moving `host=` to `lit`.

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


[clang] [clang-repl] [test] Make an XFAIL more precise (PR #70991)

2023-11-01 Thread Jonas Hahnfeld via cfe-commits

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

Very interesting... See also https://github.com/llvm/llvm-project/issues/68092, 
now I understand even less what the problem is...

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-30 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

I can add the comment as requested, but for the other questions related to full 
expressions and modules I'd really need input from experts...

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


[clang] [JITLink][RISCV] Implement eh_frame handling (PR #68253)

2023-10-28 Thread Jonas Hahnfeld via cfe-commits

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-25 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

ping @cor3ntin @shafik, could you have a look here?

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


[clang] [JITLink][RISCV] Implement eh_frame handling (PR #68253)

2023-10-23 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

@mtvec @luxufan ping :)

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


[clang] [JITLink][RISCV] Implement eh_frame handling (PR #68253)

2023-10-23 Thread Jonas Hahnfeld via cfe-commits

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


[clang] [JITLink][RISCV] Implement eh_frame handling (PR #68253)

2023-10-23 Thread Jonas Hahnfeld via cfe-commits

https://github.com/hahnjo updated 
https://github.com/llvm/llvm-project/pull/68253

>From d44b58748bcc815e151b8d99ab5cbae8b86ed056 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Wed, 4 Oct 2023 21:27:14 +0200
Subject: [PATCH 1/3] [JITLink][RISCV] Implement eh_frame handling

This requires adding a NegDelta32 edge kind that cannot be mapped to
existing relocations.

Co-authored-by: Job Noorman 
---
 .../llvm/ExecutionEngine/JITLink/riscv.h  |   6 +
 .../lib/ExecutionEngine/JITLink/ELF_riscv.cpp |  16 +++
 llvm/lib/ExecutionEngine/JITLink/riscv.cpp|   2 +
 .../JITLink/RISCV/ELF_ehframe.s   |  74 +
 .../JITLink/RISCV/ELF_ehframe.test| 104 ++
 5 files changed, 202 insertions(+)
 create mode 100644 llvm/test/ExecutionEngine/JITLink/RISCV/ELF_ehframe.s
 create mode 100644 llvm/test/ExecutionEngine/JITLink/RISCV/ELF_ehframe.test

diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/riscv.h 
b/llvm/include/llvm/ExecutionEngine/JITLink/riscv.h
index cb66289180880ce..a31f7d73b099f45 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/riscv.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/riscv.h
@@ -214,6 +214,12 @@ enum EdgeKind_riscv : Edge::Kind {
   /// Linker relaxation will use this to ensure all code sequences are properly
   /// aligned and then remove these edges from the graph.
   AlignRelaxable,
+
+  /// 32-bit negative delta.
+  ///
+  /// Fixup expression:
+  ///   Fixup <- Fixup - Target + Addend
+  NegDelta32,
 };
 
 /// Returns a string name for the given riscv edge. For debugging purposes
diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp 
b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
index 35816ea66cf9bc3..d0701ba08bd9194 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
@@ -11,10 +11,12 @@
 
//===--===//
 
 #include "llvm/ExecutionEngine/JITLink/ELF_riscv.h"
+#include "EHFrameSupportImpl.h"
 #include "ELFLinkGraphBuilder.h"
 #include "JITLinkGeneric.h"
 #include "PerGraphGOTAndPLTStubsBuilder.h"
 #include "llvm/BinaryFormat/ELF.h"
+#include "llvm/ExecutionEngine/JITLink/DWARFRecordSectionSplitter.h"
 #include "llvm/ExecutionEngine/JITLink/JITLink.h"
 #include "llvm/ExecutionEngine/JITLink/riscv.h"
 #include "llvm/Object/ELF.h"
@@ -456,6 +458,13 @@ class ELFJITLinker_riscv : public 
JITLinker {
 case AlignRelaxable:
   // Ignore when the relaxation pass did not run
   break;
+case NegDelta32: {
+  int64_t Value = FixupAddress - E.getTarget().getAddress() + 
E.getAddend();
+  if (LLVM_UNLIKELY(!isInRangeForImm(Value, 32)))
+return makeTargetOutOfRangeError(G, B, E);
+  *(little32_t *)FixupPtr = static_cast(Value);
+  break;
+}
 }
 return Error::success();
   }
@@ -958,6 +967,13 @@ void link_ELF_riscv(std::unique_ptr G,
   PassConfiguration Config;
   const Triple  = G->getTargetTriple();
   if (Ctx->shouldAddDefaultTargetPasses(TT)) {
+
+Config.PrePrunePasses.push_back(DWARFRecordSectionSplitter(".eh_frame"));
+Config.PrePrunePasses.push_back(EHFrameEdgeFixer(
+".eh_frame", G->getPointerSize(), Edge::Invalid, Edge::Invalid,
+Edge::Invalid, Edge::Invalid, NegDelta32));
+Config.PrePrunePasses.push_back(EHFrameNullTerminator(".eh_frame"));
+
 if (auto MarkLive = Ctx->getMarkLivePass(TT))
   Config.PrePrunePasses.push_back(std::move(MarkLive));
 else
diff --git a/llvm/lib/ExecutionEngine/JITLink/riscv.cpp 
b/llvm/lib/ExecutionEngine/JITLink/riscv.cpp
index a78843b1614795e..a4e4daef97fb5d6 100644
--- a/llvm/lib/ExecutionEngine/JITLink/riscv.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/riscv.cpp
@@ -82,6 +82,8 @@ const char *getEdgeKindName(Edge::Kind K) {
 return "CallRelaxable";
   case AlignRelaxable:
 return "AlignRelaxable";
+  case NegDelta32:
+return "NegDelta32";
   }
   return getGenericEdgeKindName(K);
 }
diff --git a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_ehframe.s 
b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_ehframe.s
new file mode 100644
index 000..9173bf7c3d95e4a
--- /dev/null
+++ b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_ehframe.s
@@ -0,0 +1,74 @@
+# REQUIRES: asserts
+
+# RUN: llvm-mc -triple=riscv32-linux-gnu -mattr=+relax -filetype=obj -o 
%t.32.o %s
+# RUN: llvm-jitlink -noexec -phony-externals -debug-only=jitlink %t.32.o 2>&1 
| \
+# RUN:   FileCheck %s
+
+# RUN: llvm-mc -triple=riscv64-linux-gnu -mattr=+relax -filetype=obj -o 
%t.64.o %s
+# RUN: llvm-jitlink -noexec -phony-externals -debug-only=jitlink %t.64.o 2>&1 
| \
+# RUN:   FileCheck %s
+
+# Check that splitting of eh-frame sections works.
+#
+# CHECK: DWARFRecordSectionSplitter: Processing .eh_frame...
+# CHECK:  Processing block at
+# CHECK:Processing CFI record at
+# CHECK:  Extracted {{.*}} section = .eh_frame
+# CHECK:Processing CFI record at
+# CHECK:  Extracted {{.*}} 

[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-17 Thread Jonas Hahnfeld via cfe-commits


@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o

hahnjo wrote:

No, we don't need it, you are right - the crash happens during parsing / sema

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-17 Thread Jonas Hahnfeld via cfe-commits

https://github.com/hahnjo updated 
https://github.com/llvm/llvm-project/pull/69076

>From d149de4d4e00b63e506441b516f35aeb41786408 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Sat, 14 Oct 2023 20:10:28 +0200
Subject: [PATCH 1/2] Fix crash with modules and constexpr destructor

Closes https://github.com/llvm/llvm-project/issues/68702
---
 clang/lib/AST/ExprConstant.cpp | 11 +++---
 clang/test/Modules/pr68702.cpp | 65 ++
 2 files changed, 72 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Modules/pr68702.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e5539dedec02a4b..a97e7bd8140890e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15604,10 +15604,13 @@ bool Expr::EvaluateAsInitializer(APValue , 
const ASTContext ,
 LValue LVal;
 LVal.set(VD);
 
-if (!EvaluateInPlace(Value, Info, LVal, this,
- /*AllowNonLiteralTypes=*/true) ||
-EStatus.HasSideEffects)
-  return false;
+{
+  FullExpressionRAII Scope(Info);
+  if (!EvaluateInPlace(Value, Info, LVal, this,
+   /*AllowNonLiteralTypes=*/true) ||
+  EStatus.HasSideEffects)
+return false;
+}
 
 // At this point, any lifetime-extended temporaries are completely
 // initialized.
diff --git a/clang/test/Modules/pr68702.cpp b/clang/test/Modules/pr68702.cpp
new file mode 100644
index 000..3f91a1001d1eecc
--- /dev/null
+++ b/clang/test/Modules/pr68702.cpp
@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+
+//--- V.h
+#ifndef V_H
+#define V_H
+
+class A {
+public:
+  constexpr A() { }
+  constexpr ~A() { }
+};
+
+template 
+class V {
+public:
+  V() = default;
+
+  constexpr V(int n, const A& a = A()) {}
+};
+
+#endif
+
+//--- inst1.h
+#include "V.h"
+
+static void inst1() {
+  V v;
+}
+
+//--- inst2.h
+#include "V.h"
+
+static void inst2() {
+  V v(100);
+}
+
+//--- module.modulemap
+module "M" {
+  export *
+  module "V.h" {
+export *
+header "V.h"
+  }
+  module "inst1.h" {
+export *
+header "inst1.h"
+  }
+}
+
+module "inst2.h" {
+  export *
+  header "inst2.h"
+}
+
+//--- main.cpp
+#include "V.h"
+#include "inst2.h"
+
+static void m() {
+  static V v(100);
+}

>From b567f2878b2892c5273596f2b307cf2d1095661f Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Tue, 17 Oct 2023 09:01:59 +0200
Subject: [PATCH 2/2] Remove -emit-obj from test

---
 clang/test/Modules/pr68702.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Modules/pr68702.cpp b/clang/test/Modules/pr68702.cpp
index 3f91a1001d1eecc..d32f946910f4fb8 100644
--- a/clang/test/Modules/pr68702.cpp
+++ b/clang/test/Modules/pr68702.cpp
@@ -2,7 +2,7 @@
 // RUN: mkdir %t
 // RUN: split-file %s %t
 
-// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+// RUN: %clang_cc1 -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
 
 //--- V.h
 #ifndef V_H

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-17 Thread Jonas Hahnfeld via cfe-commits


@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+
+//--- V.h
+#ifndef V_H
+#define V_H
+
+class A {
+public:
+  constexpr A() { }
+  constexpr ~A() { }
+};
+
+template 
+class V {
+public:
+  V() = default;
+
+  constexpr V(int n, const A& a = A()) {}
+};
+
+#endif
+
+//--- inst1.h
+#include "V.h"
+
+static void inst1() {
+  V v;
+}
+
+//--- inst2.h
+#include "V.h"
+
+static void inst2() {
+  V v(100);
+}
+
+//--- module.modulemap
+module "M" {

hahnjo wrote:

`split-file` is how many of the modules tests are written, and I find it very 
handy to reproduce setups with a number of smaller files...

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-14 Thread Jonas Hahnfeld via cfe-commits

https://github.com/hahnjo created 
https://github.com/llvm/llvm-project/pull/69076

Closes https://github.com/llvm/llvm-project/issues/68702

>From d149de4d4e00b63e506441b516f35aeb41786408 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Sat, 14 Oct 2023 20:10:28 +0200
Subject: [PATCH] Fix crash with modules and constexpr destructor

Closes https://github.com/llvm/llvm-project/issues/68702
---
 clang/lib/AST/ExprConstant.cpp | 11 +++---
 clang/test/Modules/pr68702.cpp | 65 ++
 2 files changed, 72 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Modules/pr68702.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e5539dedec02a4b..a97e7bd8140890e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15604,10 +15604,13 @@ bool Expr::EvaluateAsInitializer(APValue , 
const ASTContext ,
 LValue LVal;
 LVal.set(VD);
 
-if (!EvaluateInPlace(Value, Info, LVal, this,
- /*AllowNonLiteralTypes=*/true) ||
-EStatus.HasSideEffects)
-  return false;
+{
+  FullExpressionRAII Scope(Info);
+  if (!EvaluateInPlace(Value, Info, LVal, this,
+   /*AllowNonLiteralTypes=*/true) ||
+  EStatus.HasSideEffects)
+return false;
+}
 
 // At this point, any lifetime-extended temporaries are completely
 // initialized.
diff --git a/clang/test/Modules/pr68702.cpp b/clang/test/Modules/pr68702.cpp
new file mode 100644
index 000..3f91a1001d1eecc
--- /dev/null
+++ b/clang/test/Modules/pr68702.cpp
@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+
+//--- V.h
+#ifndef V_H
+#define V_H
+
+class A {
+public:
+  constexpr A() { }
+  constexpr ~A() { }
+};
+
+template 
+class V {
+public:
+  V() = default;
+
+  constexpr V(int n, const A& a = A()) {}
+};
+
+#endif
+
+//--- inst1.h
+#include "V.h"
+
+static void inst1() {
+  V v;
+}
+
+//--- inst2.h
+#include "V.h"
+
+static void inst2() {
+  V v(100);
+}
+
+//--- module.modulemap
+module "M" {
+  export *
+  module "V.h" {
+export *
+header "V.h"
+  }
+  module "inst1.h" {
+export *
+header "inst1.h"
+  }
+}
+
+module "inst2.h" {
+  export *
+  header "inst2.h"
+}
+
+//--- main.cpp
+#include "V.h"
+#include "inst2.h"
+
+static void m() {
+  static V v(100);
+}

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


[clang] abb9eb2 - [Lex] Handle repl_input_end in Preprocessor::LexTokensUntilEOF()

2023-10-05 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-10-05T12:09:14+02:00
New Revision: abb9eb2778dc68ca3bc2ca786632e65682741469

URL: 
https://github.com/llvm/llvm-project/commit/abb9eb2778dc68ca3bc2ca786632e65682741469
DIFF: 
https://github.com/llvm/llvm-project/commit/abb9eb2778dc68ca3bc2ca786632e65682741469.diff

LOG: [Lex] Handle repl_input_end in Preprocessor::LexTokensUntilEOF()

This fixes many unit tests when trying to enable IncrementalExtensions
by default for testing purposes.

Differential Revision: https://reviews.llvm.org/D158415

Added: 


Modified: 
clang/lib/Lex/Preprocessor.cpp

Removed: 




diff  --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index b82dd1fe49c7040..c16dd75fbbd3f53 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -1002,7 +1002,8 @@ void Preprocessor::LexTokensUntilEOF(std::vector 
*Tokens) {
   while (1) {
 Token Tok;
 Lex(Tok);
-if (Tok.isOneOf(tok::unknown, tok::eof, tok::eod))
+if (Tok.isOneOf(tok::unknown, tok::eof, tok::eod,
+tok::annot_repl_input_end))
   break;
 if (Tokens != nullptr)
   Tokens->push_back(Tok);



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


[clang] 3116d60 - [Lex] Introduce Preprocessor::LexTokensUntilEOF()

2023-10-05 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-10-05T11:04:07+02:00
New Revision: 3116d60494f219bfcb284d05d9ebed5b6c196ca5

URL: 
https://github.com/llvm/llvm-project/commit/3116d60494f219bfcb284d05d9ebed5b6c196ca5
DIFF: 
https://github.com/llvm/llvm-project/commit/3116d60494f219bfcb284d05d9ebed5b6c196ca5.diff

LOG: [Lex] Introduce Preprocessor::LexTokensUntilEOF()

This new method repeatedly calls Lex() until end of file is reached
and optionally fills a std::vector of Tokens. Use it in Clang's unit
tests to avoid quite some code duplication.

Differential Revision: https://reviews.llvm.org/D158413

Added: 


Modified: 
clang/include/clang/Lex/Preprocessor.h
clang/lib/Lex/Preprocessor.cpp
clang/unittests/Analysis/MacroExpansionContextTest.cpp
clang/unittests/Basic/SourceManagerTest.cpp
clang/unittests/Lex/LexerTest.cpp
clang/unittests/Lex/ModuleDeclStateTest.cpp
clang/unittests/Lex/PPCallbacksTest.cpp
clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
clang/unittests/Lex/PPDependencyDirectivesTest.cpp
clang/unittests/Lex/PPMemoryAllocationsTest.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index e88164f196c1f7c..a8d2599d94ebc66 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -1722,6 +1722,9 @@ class Preprocessor {
   /// Lex the next token for this preprocessor.
   void Lex(Token );
 
+  /// Lex all tokens for this preprocessor until (and excluding) end of file.
+  void LexTokensUntilEOF(std::vector *Tokens = nullptr);
+
   /// Lex a token, forming a header-name token if possible.
   bool LexHeaderName(Token , bool AllowMacroExpansion = true);
 

diff  --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 73c37bc5161c4b6..b82dd1fe49c7040 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -998,6 +998,17 @@ void Preprocessor::Lex(Token ) {
   }
 }
 
+void Preprocessor::LexTokensUntilEOF(std::vector *Tokens) {
+  while (1) {
+Token Tok;
+Lex(Tok);
+if (Tok.isOneOf(tok::unknown, tok::eof, tok::eod))
+  break;
+if (Tokens != nullptr)
+  Tokens->push_back(Tok);
+  }
+}
+
 /// Lex a header-name token (including one formed from header-name-tokens if
 /// \p AllowConcatenation is \c true).
 ///

diff  --git a/clang/unittests/Analysis/MacroExpansionContextTest.cpp 
b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
index 5c694c836a48814..54b209e7b28c185 100644
--- a/clang/unittests/Analysis/MacroExpansionContextTest.cpp
+++ b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
@@ -73,12 +73,7 @@ class MacroExpansionContextTest : public ::testing::Test {
 // Lex source text.
 PP.EnterMainSourceFile();
 
-while (true) {
-  Token Tok;
-  PP.Lex(Tok);
-  if (Tok.is(tok::eof))
-break;
-}
+PP.LexTokensUntilEOF();
 
 // Callbacks have been executed at this point.
 return Ctx;

diff  --git a/clang/unittests/Basic/SourceManagerTest.cpp 
b/clang/unittests/Basic/SourceManagerTest.cpp
index f451e43bb53d78e..cd2bd12106b0edb 100644
--- a/clang/unittests/Basic/SourceManagerTest.cpp
+++ b/clang/unittests/Basic/SourceManagerTest.cpp
@@ -138,13 +138,7 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnit) {
   PP.EnterMainSourceFile();
 
   std::vector toks;
-  while (1) {
-Token tok;
-PP.Lex(tok);
-if (tok.is(tok::eof))
-  break;
-toks.push_back(tok);
-  }
+  PP.LexTokensUntilEOF();
 
   // Make sure we got the tokens that we expected.
   ASSERT_EQ(3U, toks.size());
@@ -195,13 +189,7 @@ TEST_F(SourceManagerTest, 
isBeforeInTranslationUnitWithTokenSplit) {
   llvm::SmallString<8> Scratch;
 
   std::vector toks;
-  while (1) {
-Token tok;
-PP.Lex(tok);
-if (tok.is(tok::eof))
-  break;
-toks.push_back(tok);
-  }
+  PP.LexTokensUntilEOF();
 
   // Make sure we got the tokens that we expected.
   ASSERT_EQ(4U, toks.size()) << "a >> b c";
@@ -452,13 +440,7 @@ TEST_F(SourceManagerTest, getMacroArgExpandedLocation) {
   PP.EnterMainSourceFile();
 
   std::vector toks;
-  while (1) {
-Token tok;
-PP.Lex(tok);
-if (tok.is(tok::eof))
-  break;
-toks.push_back(tok);
-  }
+  PP.LexTokensUntilEOF();
 
   // Make sure we got the tokens that we expected.
   ASSERT_EQ(4U, toks.size());
@@ -574,13 +556,7 @@ TEST_F(SourceManagerTest, 
isBeforeInTranslationUnitWithMacroInInclude) {
   PP.EnterMainSourceFile();
 
   std::vector toks;
-  while (1) {
-Token tok;
-PP.Lex(tok);
-if (tok.is(tok::eof))
-  break;
-toks.push_back(tok);
-  }
+  PP.LexTokensUntilEOF();
 
   // Make sure we got the tokens that we expected.
   ASSERT_EQ(0U, toks.size());

diff  --git a/clang/unittests/Lex/LexerTest.cpp 
b/clang/unittests/Lex/LexerTest.cpp
index 8932265674a59a1..47aa2c131a304dd 100644
--- 

[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-10-03 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

Note that this currently doesn't seem to work on Windows: 
https://github.com/llvm/llvm-project/issues/68092

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


[clang] 4812eec - [clang-repl] XFAIL new const.cpp test on Windows

2023-10-03 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-10-03T13:30:01+02:00
New Revision: 4812eecd7106200c0330d6371afbe036f577244a

URL: 
https://github.com/llvm/llvm-project/commit/4812eecd7106200c0330d6371afbe036f577244a
DIFF: 
https://github.com/llvm/llvm-project/commit/4812eecd7106200c0330d6371afbe036f577244a.diff

LOG: [clang-repl] XFAIL new const.cpp test on Windows

Still failing after the previous commit:
https://lab.llvm.org/buildbot/#/builders/216/builds/28268

Added: 


Modified: 
clang/test/Interpreter/const.cpp

Removed: 




diff  --git a/clang/test/Interpreter/const.cpp 
b/clang/test/Interpreter/const.cpp
index b3206f6e3fda96f..4b6ce65e3643e64 100644
--- a/clang/test/Interpreter/const.cpp
+++ b/clang/test/Interpreter/const.cpp
@@ -1,4 +1,7 @@
 // UNSUPPORTED: system-aix
+// see https://github.com/llvm/llvm-project/issues/68092
+// XFAIL: system-windows
+
 // RUN: cat %s | clang-repl | FileCheck %s
 // RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
 



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


[clang] b6ee41f - [clang-repl] Relax regular expression for new const.cpp test

2023-10-03 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-10-03T13:10:31+02:00
New Revision: b6ee41f83c6ea361bfafc2168e9223379b32773f

URL: 
https://github.com/llvm/llvm-project/commit/b6ee41f83c6ea361bfafc2168e9223379b32773f
DIFF: 
https://github.com/llvm/llvm-project/commit/b6ee41f83c6ea361bfafc2168e9223379b32773f.diff

LOG: [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

Added: 


Modified: 
clang/test/Interpreter/const.cpp

Removed: 




diff  --git a/clang/test/Interpreter/const.cpp 
b/clang/test/Interpreter/const.cpp
index a4b610f1a19d842..b3206f6e3fda96f 100644
--- a/clang/test/Interpreter/const.cpp
+++ b/clang/test/Interpreter/const.cpp
@@ -10,7 +10,7 @@ A::~A() { printf("~A, this = %p, val = %d\n", this, val); }
 void A::f() const { printf("f: this = %p, val = %d\n", this, val); }
 
 const A a(1);
-// CHECK: A(1), this = [[THIS:0x[0-9a-f]+]]
+// CHECK: A(1), this = [[THIS:.+]]
 // The constructor must only be called once!
 // CHECK-NOT: A(1)
 



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


[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-10-03 Thread Jonas Hahnfeld via cfe-commits

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


[clang] [clang-repl][CUDA] Move CUDA module registration to beginning of global_ctors (PR #66658)

2023-10-03 Thread Jonas Hahnfeld via cfe-commits


@@ -794,7 +794,7 @@ void CodeGenModule::Release() {
   AddGlobalCtor(ObjCInitFunction);
   if (Context.getLangOpts().CUDA && CUDARuntime) {
 if (llvm::Function *CudaCtorFunction = CUDARuntime->finalizeModule())
-  AddGlobalCtor(CudaCtorFunction);
+  AddGlobalCtor(CudaCtorFunction, /*Priority=*/0);

hahnjo wrote:

I have the same fear as @Artem-B, higher than default priorities are also 
sometimes reserved. We really need to see what `nvcc` does here, but what I 
could imagine (at least how I would solve it) is putting the constructor with 
the same priority before all other constructors.

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


[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-10-03 Thread Jonas Hahnfeld via cfe-commits


@@ -0,0 +1,29 @@
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+
+extern "C" int printf(const char*, ...);
+

hahnjo wrote:

`const A a(1);` is a file-scope constant, no? We don't need it for C because 
the special case in `LinkageComputer::getLVForNamespaceScopeDecl` only applies 
to C++ (my understanding is that `const` variables always have an identity in 
C).

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


[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-09-28 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

ping @vgvassilev 

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


[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-09-18 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

Ping on the updated patch, which is now also passing downstream testing after I 
realized that we were missing a backport of commit 
e451d552348bc714614d294e32dfbe7ec2cd4005, which explains why some constructors 
were wrongly ordered...

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


[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-09-06 Thread Jonas Hahnfeld via cfe-commits

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


[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-09-06 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

The original patch worked for `clang-repl` but results in strong linkage which 
I found to cause problems with modules downstream in ROOT. Instead the latest 
push moves the special case one level higher to `basicGVALinkageForVariable` 
and returns `GVA_DiscardableODR` which fixes that problem as well.

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


[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-09-06 Thread Jonas Hahnfeld via cfe-commits

https://github.com/hahnjo updated 
https://github.com/llvm/llvm-project/pull/65257:

>From 7b52d2ad531286ca3e14c3f05da51c91fd71bd0d Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Wed, 6 Sep 2023 13:11:57 +0200
Subject: [PATCH] [clang-repl] Emit const variables only once

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.
---
 clang/lib/AST/ASTContext.cpp | 10 ++
 clang/test/Interpreter/const.cpp | 29 +
 2 files changed, 39 insertions(+)
 create mode 100644 clang/test/Interpreter/const.cpp

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 4b1d9e86797b77..f7438e9be19ee1 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -11764,6 +11764,16 @@ GVALinkage ASTContext::GetGVALinkageForFunction(const 
FunctionDecl *FD) const {
 
 static GVALinkage basicGVALinkageForVariable(const ASTContext ,
  const VarDecl *VD) {
+  // As an extension for interactive REPLs, make sure constant variables are
+  // only emitted once instead of LinkageComputer::getLVForNamespaceScopeDecl
+  // marking them as internal.
+  if (Context.getLangOpts().CPlusPlus &&
+  Context.getLangOpts().IncrementalExtensions &&
+  VD->getType().isConstQualified() &&
+  !VD->getType().isVolatileQualified() && !VD->isInline() &&
+  !isa(VD) && 
!VD->getDescribedVarTemplate())
+return GVA_DiscardableODR;
+
   if (!VD->isExternallyVisible())
 return GVA_Internal;
 
diff --git a/clang/test/Interpreter/const.cpp b/clang/test/Interpreter/const.cpp
new file mode 100644
index 00..a4b610f1a19d84
--- /dev/null
+++ b/clang/test/Interpreter/const.cpp
@@ -0,0 +1,29 @@
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+
+extern "C" int printf(const char*, ...);
+
+struct A { int val; A(int v); ~A(); void f() const; };
+A::A(int v) : val(v) { printf("A(%d), this = %p\n", val, this); }
+A::~A() { printf("~A, this = %p, val = %d\n", this, val); }
+void A::f() const { printf("f: this = %p, val = %d\n", this, val); }
+
+const A a(1);
+// CHECK: A(1), this = [[THIS:0x[0-9a-f]+]]
+// The constructor must only be called once!
+// CHECK-NOT: A(1)
+
+a.f();
+// CHECK-NEXT: f: this = [[THIS]], val = 1
+a.f();
+// CHECK-NEXT: f: this = [[THIS]], val = 1
+
+%quit
+// There must still be no other constructor!
+// CHECK-NOT: A(1)
+
+// At the end, we expect exactly one destructor call
+// CHECK: ~A
+// CHECK-SAME: this = [[THIS]], val = 1
+// CHECK-NOT: ~A

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


[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-09-04 Thread Jonas Hahnfeld via cfe-commits

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


[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-09-04 Thread Jonas Hahnfeld via cfe-commits

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


[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-09-04 Thread Jonas Hahnfeld via cfe-commits

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


[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-09-04 Thread Jonas Hahnfeld via cfe-commits

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

>From fcea5762fab68459aef3f8e82e98fc52e04e1598 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Mon, 4 Sep 2023 13:56:25 +0200
Subject: [PATCH] [clang-repl] Emit const variables only once

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.
---
 clang/lib/AST/Decl.cpp   |  1 +
 clang/test/Interpreter/const.cpp | 29 +
 2 files changed, 30 insertions(+)
 create mode 100644 clang/test/Interpreter/const.cpp

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 60c80f2b075336..e019e701196a38 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -651,6 +651,7 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl 
*D,
 // internal linkage
 // (There is no equivalent in C99.)
 if (Context.getLangOpts().CPlusPlus && Var->getType().isConstQualified() &&
+!Context.getLangOpts().IncrementalExtensions &&
 !Var->getType().isVolatileQualified() && !Var->isInline() &&
 !isDeclaredInModuleInterfaceOrPartition(Var) &&
 !isa(Var) &&
diff --git a/clang/test/Interpreter/const.cpp b/clang/test/Interpreter/const.cpp
new file mode 100644
index 00..a4b610f1a19d84
--- /dev/null
+++ b/clang/test/Interpreter/const.cpp
@@ -0,0 +1,29 @@
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+
+extern "C" int printf(const char*, ...);
+
+struct A { int val; A(int v); ~A(); void f() const; };
+A::A(int v) : val(v) { printf("A(%d), this = %p\n", val, this); }
+A::~A() { printf("~A, this = %p, val = %d\n", this, val); }
+void A::f() const { printf("f: this = %p, val = %d\n", this, val); }
+
+const A a(1);
+// CHECK: A(1), this = [[THIS:0x[0-9a-f]+]]
+// The constructor must only be called once!
+// CHECK-NOT: A(1)
+
+a.f();
+// CHECK-NEXT: f: this = [[THIS]], val = 1
+a.f();
+// CHECK-NEXT: f: this = [[THIS]], val = 1
+
+%quit
+// There must still be no other constructor!
+// CHECK-NOT: A(1)
+
+// At the end, we expect exactly one destructor call
+// CHECK: ~A
+// CHECK-SAME: this = [[THIS]], val = 1
+// CHECK-NOT: ~A

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


[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-09-04 Thread Jonas Hahnfeld via cfe-commits

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


[clang] 6c274ba - [clang-repl] Disambiguate declarations with private typedefs

2023-08-23 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-23T11:29:26+02:00
New Revision: 6c274ba4108b07358ebd4e8d607c72d6db8c8100

URL: 
https://github.com/llvm/llvm-project/commit/6c274ba4108b07358ebd4e8d607c72d6db8c8100
DIFF: 
https://github.com/llvm/llvm-project/commit/6c274ba4108b07358ebd4e8d607c72d6db8c8100.diff

LOG: [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

Added: 


Modified: 
clang/lib/Parse/ParseTentative.cpp
clang/test/Interpreter/disambiguate-decl-stmt.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseTentative.cpp 
b/clang/lib/Parse/ParseTentative.cpp
index 66433705250010..45e73226d706b8 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -83,6 +83,17 @@ bool Parser::isCXXDeclarationStatement(
   isDeductionGuide,
   DeclSpec::FriendSpecified::No))
 return true;
+} else if (SS.isNotEmpty()) {
+  // If the scope is not empty, it could alternatively be something 
like
+  // a typedef or using declaration. That declaration might be private
+  // in the global context, which would be diagnosed by calling into
+  // isCXXSimpleDeclaration, but may actually be fine in the context of
+  // member functions and static variable definitions. Check if the 
next
+  // token is also an identifier and assume a declaration.
+  // We cannot check if the scopes match because the declarations could
+  // involve namespaces and friend declarations.
+  if (NextToken().is(tok::identifier))
+return true;
 }
 break;
   }

diff  --git a/clang/test/Interpreter/disambiguate-decl-stmt.cpp 
b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
index cbc456da6eb512..a49d7013c540ac 100644
--- a/clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -1,8 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -fincremental-extensions -std=c++20 %s
 // RUN: %clang_cc1 -fsyntax-only -DMS -fms-extensions -verify 
-fincremental-extensions -std=c++20 %s
 
-// expected-no-diagnostics
-
 extern "C" int printf(const char*,...);
 
 // Decls which are hard to disambiguate
@@ -47,6 +45,37 @@ ANestedDtor::A1::A2::~A2() { printf("Dtor 
A::A1::A2::~A2\n"); }
 
 // Ctors
 
+// Private typedefs / using declarations
+class PrivateUsingMember { using T = int; T f(); };
+PrivateUsingMember::T PrivateUsingMember::f() { return 0; }
+
+class PrivateUsingVar { using T = int; static T i; };
+PrivateUsingVar::T PrivateUsingVar::i = 42;
+
+// The same with namespaces
+namespace PrivateUsingNamespace { class Member { using T = int; T f(); }; }
+PrivateUsingNamespace::Member::T PrivateUsingNamespace::Member::f() { return 
0; }
+
+namespace PrivateUsingNamespace { class Var { using T = int; static T i; }; }
+PrivateUsingNamespace::Var::T PrivateUsingNamespace::Var::i = 42;
+
+// The same with friend declarations
+class PrivateUsingFriendMember;
+class PrivateUsingFriendVar;
+class PrivateUsingFriend { friend class PrivateUsingFriendMember; friend class 
PrivateUsingFriendVar; using T = int; };
+class PrivateUsingFriendMember { PrivateUsingFriend::T f(); };
+PrivateUsingFriend::T PrivateUsingFriendMember::f() { return 0; }
+
+class PrivateUsingFriendVar { static PrivateUsingFriend::T i; };
+PrivateUsingFriend::T PrivateUsingFriendVar::i = 42;
+
+// The following should still diagnose (inspired by PR13642)
+// FIXME: Should not be diagnosed twice!
+class PR13642 { class Inner { public: static int i; }; };
+// expected-note@-1 2 {{implicitly declared private here}}
+PR13642::Inner::i = 5;
+// expected-error@-1 2 {{'Inner' is a private member of 'PR13642'}}
+
 // Deduction guide
 template struct A { A(); A(T); };
 A() -> A;



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


[clang] c861d32 - [CodeGen] Keep track of eagerly emitted globals

2023-08-18 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-18T09:42:28+02:00
New Revision: c861d32d7c2791bdc058d9d9fbaecc1c2f07b8c7

URL: 
https://github.com/llvm/llvm-project/commit/c861d32d7c2791bdc058d9d9fbaecc1c2f07b8c7
DIFF: 
https://github.com/llvm/llvm-project/commit/c861d32d7c2791bdc058d9d9fbaecc1c2f07b8c7.diff

LOG: [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

Added: 
clang/test/Interpreter/inline-virtual.cpp

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 517af514d9c998..440fb040a43cc5 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3658,6 +3658,7 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
   if (MustBeEmitted(Global) && MayBeEmittedEagerly(Global)) {
 // Emit the definition if it can't be deferred.
 EmitGlobalDefinition(GD);
+addEmittedDeferredDecl(GD);
 return;
   }
 

diff  --git a/clang/test/Interpreter/inline-virtual.cpp 
b/clang/test/Interpreter/inline-virtual.cpp
new file mode 100644
index 00..79ab8ed337ffea
--- /dev/null
+++ b/clang/test/Interpreter/inline-virtual.cpp
@@ -0,0 +1,24 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+//
+// We disable RTTI to avoid problems on Windows for non-RTTI builds of LLVM
+// where the JIT cannot find ??_7type_info@@6B@.
+// RUN: cat %s | clang-repl -Xcc -fno-rtti | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -fno-rtti -Xcc -O2 | FileCheck %s
+
+extern "C" int printf(const char *, ...);
+
+struct A { int a; A(int a) : a(a) {} virtual ~A(); };
+
+// Then define the virtual destructor as inline out-of-line, in a separate
+// PartialTranslationUnit.
+inline A::~A() { printf("~A(%d)\n", a); }
+
+// Create one instance with new and delete it.
+A *a1 = new A(1);
+delete a1;
+// CHECK: ~A(1)
+
+// Also create one global that will be auto-destructed.
+A a2(2);
+// CHECK: ~A(2)



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


[clang] 0e17372 - Revert "[CodeGen] Keep track of eagerly emitted globals"

2023-08-17 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-17T14:21:39+02:00
New Revision: 0e17372b380467ac8339afdec992fbf887a11feb

URL: 
https://github.com/llvm/llvm-project/commit/0e17372b380467ac8339afdec992fbf887a11feb
DIFF: 
https://github.com/llvm/llvm-project/commit/0e17372b380467ac8339afdec992fbf887a11feb.diff

LOG: 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.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 
clang/test/Interpreter/inline-virtual.cpp



diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 440fb040a43cc5..517af514d9c998 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3658,7 +3658,6 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
   if (MustBeEmitted(Global) && MayBeEmittedEagerly(Global)) {
 // Emit the definition if it can't be deferred.
 EmitGlobalDefinition(GD);
-addEmittedDeferredDecl(GD);
 return;
   }
 

diff  --git a/clang/test/Interpreter/inline-virtual.cpp 
b/clang/test/Interpreter/inline-virtual.cpp
deleted file mode 100644
index ace7a0a73d82a1..00
--- a/clang/test/Interpreter/inline-virtual.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-// REQUIRES: host-supports-jit
-// UNSUPPORTED: system-aix
-// RUN: cat %s | clang-repl | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
-
-extern "C" int printf(const char *, ...);
-
-struct A { int a; A(int a) : a(a) {} virtual ~A(); };
-
-// Then define the virtual destructor as inline out-of-line, in a separate
-// PartialTranslationUnit.
-inline A::~A() { printf("~A(%d)\n", a); }
-
-// Create one instance with new and delete it.
-A *a1 = new A(1);
-delete a1;
-// CHECK: ~A(1)
-
-// Also create one global that will be auto-destructed.
-A a2(2);
-// CHECK: ~A(2)



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


[clang] f8dadef - [CodeGen] Keep track of eagerly emitted globals

2023-08-17 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-17T13:26:22+02:00
New Revision: f8dadefd4afc8e1b7b9a1e69a0ba8df051e03328

URL: 
https://github.com/llvm/llvm-project/commit/f8dadefd4afc8e1b7b9a1e69a0ba8df051e03328
DIFF: 
https://github.com/llvm/llvm-project/commit/f8dadefd4afc8e1b7b9a1e69a0ba8df051e03328.diff

LOG: [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

Added: 
clang/test/Interpreter/inline-virtual.cpp

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 517af514d9c998..440fb040a43cc5 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3658,6 +3658,7 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
   if (MustBeEmitted(Global) && MayBeEmittedEagerly(Global)) {
 // Emit the definition if it can't be deferred.
 EmitGlobalDefinition(GD);
+addEmittedDeferredDecl(GD);
 return;
   }
 

diff  --git a/clang/test/Interpreter/inline-virtual.cpp 
b/clang/test/Interpreter/inline-virtual.cpp
new file mode 100644
index 00..ace7a0a73d82a1
--- /dev/null
+++ b/clang/test/Interpreter/inline-virtual.cpp
@@ -0,0 +1,21 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+
+extern "C" int printf(const char *, ...);
+
+struct A { int a; A(int a) : a(a) {} virtual ~A(); };
+
+// Then define the virtual destructor as inline out-of-line, in a separate
+// PartialTranslationUnit.
+inline A::~A() { printf("~A(%d)\n", a); }
+
+// Create one instance with new and delete it.
+A *a1 = new A(1);
+delete a1;
+// CHECK: ~A(1)
+
+// Also create one global that will be auto-destructed.
+A a2(2);
+// CHECK: ~A(2)



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


[clang] d43a3d6 - [CodeGen] Restrict addEmittedDeferredDecl to incremental extensions

2023-08-17 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-17T11:54:05+02:00
New Revision: d43a3d6346961e639e29b8083b262416889e78ec

URL: 
https://github.com/llvm/llvm-project/commit/d43a3d6346961e639e29b8083b262416889e78ec
DIFF: 
https://github.com/llvm/llvm-project/commit/d43a3d6346961e639e29b8083b262416889e78ec.diff

LOG: [CodeGen] Restrict addEmittedDeferredDecl to incremental extensions

Reemission is only needed in incremental mode. With this early return,
we avoid overhead from addEmittedDeferredDecl in non-incremental mode.

Differential Revision: https://reviews.llvm.org/D157379

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.h

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index 7301109fb04409..c22dd8486270a0 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -361,6 +361,10 @@ class CodeGenModule : public CodeGenTypeCache {
   llvm::DenseMap EmittedDeferredDecls;
 
   void addEmittedDeferredDecl(GlobalDecl GD) {
+// Reemission is only needed in incremental mode.
+if (!Context.getLangOpts().IncrementalExtensions)
+  return;
+
 // Assume a linkage by default that does not need reemission.
 auto L = llvm::GlobalValue::ExternalLinkage;
 if (llvm::isa(GD.getDecl()))



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


[clang] b719e41 - [CodeGen] Clean up access to EmittedDeferredDecls, NFCI.

2023-08-17 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-17T10:39:47+02:00
New Revision: b719e410781ce9f3a2b316afea31c156bf99e036

URL: 
https://github.com/llvm/llvm-project/commit/b719e410781ce9f3a2b316afea31c156bf99e036
DIFF: 
https://github.com/llvm/llvm-project/commit/b719e410781ce9f3a2b316afea31c156bf99e036.diff

LOG: [CodeGen] Clean up access to EmittedDeferredDecls, NFCI.

GlobalDecls should only be added to EmittedDeferredDecls if they
need reemission. This is checked in addEmittedDeferredDecl, which
is called via addDeferredDeclToEmit. Extend these checks to also
handle VarDecls (for lambdas, as tested in Interpreter/lambda.cpp)
and remove the direct access of EmittedDeferredDecls in EmitGlobal
that may actually end up duplicating FunctionDecls.

Differential Revision: https://reviews.llvm.org/D156897

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 2a7a36e53d8189..517af514d9c998 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3677,7 +3677,6 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
 // The value must be emitted, but cannot be emitted eagerly.
 assert(!MayBeEmittedEagerly(Global));
 addDeferredDeclToEmit(GD);
-EmittedDeferredDecls[MangledName] = GD;
   } else {
 // Otherwise, remember that we saw a deferred decl with this name.  The
 // first use of the mangled name will cause it to move into
@@ -4417,7 +4416,6 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
   // DeferredDeclsToEmit list, and remove it from DeferredDecls (since we
   // don't need it anymore).
   addDeferredDeclToEmit(DDI->second);
-  EmittedDeferredDecls[DDI->first] = DDI->second;
   DeferredDecls.erase(DDI);
 
   // Otherwise, there are cases we have to worry about where we're
@@ -4677,7 +4675,6 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName, llvm::Type *Ty,
 // Move the potentially referenced deferred decl to the DeferredDeclsToEmit
 // list, and remove it from DeferredDecls (since we don't need it anymore).
 addDeferredDeclToEmit(DDI->second);
-EmittedDeferredDecls[DDI->first] = DDI->second;
 DeferredDecls.erase(DDI);
   }
 

diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index ef90eaca59a4e0..7301109fb04409 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -361,10 +361,15 @@ class CodeGenModule : public CodeGenTypeCache {
   llvm::DenseMap EmittedDeferredDecls;
 
   void addEmittedDeferredDecl(GlobalDecl GD) {
-if (!llvm::isa(GD.getDecl()))
-  return;
-llvm::GlobalVariable::LinkageTypes L = getFunctionLinkage(GD);
-if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+// Assume a linkage by default that does not need reemission.
+auto L = llvm::GlobalValue::ExternalLinkage;
+if (llvm::isa(GD.getDecl()))
+  L = getFunctionLinkage(GD);
+else if (auto *VD = llvm::dyn_cast(GD.getDecl()))
+  L = getLLVMLinkageVarDefinition(VD);
+
+if (llvm::GlobalValue::isInternalLinkage(L) ||
+llvm::GlobalValue::isLinkOnceLinkage(L) ||
 llvm::GlobalValue::isWeakLinkage(L)) {
   EmittedDeferredDecls[getMangledName(GD)] = GD;
 }



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


[clang] eeac432 - Disable two tests without {arm, aarch64}-registered-target

2023-08-17 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-17T10:04:38+02:00
New Revision: eeac4321c517ee8afc30ebe62c5b1778efc1173d

URL: 
https://github.com/llvm/llvm-project/commit/eeac4321c517ee8afc30ebe62c5b1778efc1173d
DIFF: 
https://github.com/llvm/llvm-project/commit/eeac4321c517ee8afc30ebe62c5b1778efc1173d.diff

LOG: Disable two tests without {arm,aarch64}-registered-target

Added: 


Modified: 
clang/test/Driver/fsplit-machine-functions.c
llvm/test/CodeGen/Generic/machine-function-splitter.ll

Removed: 




diff  --git a/clang/test/Driver/fsplit-machine-functions.c 
b/clang/test/Driver/fsplit-machine-functions.c
index 5ae72acfb04b64..e5f6a74763af23 100644
--- a/clang/test/Driver/fsplit-machine-functions.c
+++ b/clang/test/Driver/fsplit-machine-functions.c
@@ -1,3 +1,5 @@
+// REQUIRES: arm-registered-target
+
 // RUN: %clang -### -target x86_64 -fprofile-use=default.profdata 
-fsplit-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
 // RUN: %clang -### -target x86_64 -fsplit-machine-functions %s -c 2>&1 | 
FileCheck -check-prefix=CHECK-OPT %s
 // RUN: %clang -### -target x86_64 -fprofile-use=default.profdata 
-fsplit-machine-functions -fno-split-machine-functions %s -c 2>&1 | FileCheck 
-check-prefix=CHECK-NOOPT %s

diff  --git a/llvm/test/CodeGen/Generic/machine-function-splitter.ll 
b/llvm/test/CodeGen/Generic/machine-function-splitter.ll
index f9a972c124b129..03934434f3ceb7 100644
--- a/llvm/test/CodeGen/Generic/machine-function-splitter.ll
+++ b/llvm/test/CodeGen/Generic/machine-function-splitter.ll
@@ -1,3 +1,4 @@
+; REQUIRES: aarch64-registered-target
 ; REQUIRES: x86-registered-target
 
 ; COM: Machine function splitting with FDO profiles



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


[clang] 2f3fe3e - [CodeGen] Remove Constant arguments from linkage functions, NFCI.

2023-08-17 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-17T08:28:51+02:00
New Revision: 2f3fe3ed97bcf778d73eda5aae9f166810a4af02

URL: 
https://github.com/llvm/llvm-project/commit/2f3fe3ed97bcf778d73eda5aae9f166810a4af02
DIFF: 
https://github.com/llvm/llvm-project/commit/2f3fe3ed97bcf778d73eda5aae9f166810a4af02.diff

LOG: [CodeGen] Remove Constant arguments from linkage functions, NFCI.

This was unused since commit dd2362a8ba last year.

Differential Revision: https://reviews.llvm.org/D156891

Added: 


Modified: 
clang/lib/CodeGen/CGCXXABI.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprConstant.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCXXABI.cpp b/clang/lib/CodeGen/CGCXXABI.cpp
index 7b77dd7875bc6c..4df6f6505ef667 100644
--- a/clang/lib/CodeGen/CGCXXABI.cpp
+++ b/clang/lib/CodeGen/CGCXXABI.cpp
@@ -312,8 +312,7 @@ void CGCXXABI::setCXXDestructorDLLStorage(llvm::GlobalValue 
*GV,
 llvm::GlobalValue::LinkageTypes CGCXXABI::getCXXDestructorLinkage(
 GVALinkage Linkage, const CXXDestructorDecl *Dtor, CXXDtorType DT) const {
   // Delegate back to CGM by default.
-  return CGM.getLLVMLinkageForDeclarator(Dtor, Linkage,
- /*IsConstantVariable=*/false);
+  return CGM.getLLVMLinkageForDeclarator(Dtor, Linkage);
 }
 
 bool CGCXXABI::NeedsVTTParameter(GlobalDecl GD) {

diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index b68fe3c3c15f81..d8f2fa1f593a60 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -202,7 +202,7 @@ void CodeGenFunction::EmitVarDecl(const VarDecl ) {
   return;
 
 llvm::GlobalValue::LinkageTypes Linkage =
-CGM.getLLVMLinkageVarDefinition(, /*IsConstant=*/false);
+CGM.getLLVMLinkageVarDefinition();
 
 // FIXME: We need to force the emission/use of a guard variable for
 // some variables even if we can constant-evaluate them because

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 31c04255ddcbc0..0f06f3d4089ad8 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2679,8 +2679,7 @@ static LValue EmitGlobalNamedRegister(const VarDecl *VD, 
CodeGenModule ) {
 /// this context.
 static bool canEmitSpuriousReferenceToVariable(CodeGenFunction ,
const DeclRefExpr *E,
-   const VarDecl *VD,
-   bool IsConstant) {
+   const VarDecl *VD) {
   // For a variable declared in an enclosing scope, do not emit a spurious
   // reference even if we have a capture, as that will emit an unwarranted
   // reference to our capture state, and will likely generate worse code than
@@ -2713,7 +2712,7 @@ static bool 
canEmitSpuriousReferenceToVariable(CodeGenFunction ,
   // We can emit a spurious reference only if the linkage implies that we'll
   // be emitting a non-interposable symbol that will be retained until link
   // time.
-  switch (CGF.CGM.getLLVMLinkageVarDefinition(VD, IsConstant)) {
+  switch (CGF.CGM.getLLVMLinkageVarDefinition(VD)) {
   case llvm::GlobalValue::ExternalLinkage:
   case llvm::GlobalValue::LinkOnceODRLinkage:
   case llvm::GlobalValue::WeakODRLinkage:
@@ -2744,7 +2743,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const 
DeclRefExpr *E) {
 // constant value directly instead.
 if (E->isNonOdrUse() == NOUR_Constant &&
 (VD->getType()->isReferenceType() ||
- !canEmitSpuriousReferenceToVariable(*this, E, VD, true))) {
+ !canEmitSpuriousReferenceToVariable(*this, E, VD))) {
   VD->getAnyInitializer(VD);
   llvm::Constant *Val = ConstantEmitter(*this).emitAbstract(
   E->getLocation(), *VD->evaluateValue(), VD->getType());
@@ -2846,7 +2845,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const 
DeclRefExpr *E) {
 // some reason; most likely, because it's in an outer function.
 } else if (VD->isStaticLocal()) {
   llvm::Constant *var = CGM.getOrCreateStaticVarDecl(
-  *VD, CGM.getLLVMLinkageVarDefinition(VD, /*IsConstant=*/false));
+  *VD, CGM.getLLVMLinkageVarDefinition(VD));
   addr = Address(
   var, ConvertTypeForMem(VD->getType()), 
getContext().getDeclAlign(VD));
 

diff  --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 622d586254f336..52d61f1e298087 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1953,7 +1953,7 @@ ConstantLValueEmitter::tryEmitBase(const 
APValue::LValueBase ) {
 
 if (VD->isLocalVarDecl()) {
  

[clang] ba475a4 - [clang-repl] Disambiguate global namespace identifiers

2023-08-14 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-14T10:11:27+02:00
New Revision: ba475a4a3440a21e5de6a39a16215836f2614f04

URL: 
https://github.com/llvm/llvm-project/commit/ba475a4a3440a21e5de6a39a16215836f2614f04
DIFF: 
https://github.com/llvm/llvm-project/commit/ba475a4a3440a21e5de6a39a16215836f2614f04.diff

LOG: [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

Added: 


Modified: 
clang/lib/Parse/ParseTentative.cpp
clang/test/Interpreter/disambiguate-decl-stmt.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseTentative.cpp 
b/clang/lib/Parse/ParseTentative.cpp
index b7c83bbeb82ee7..66433705250010 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -62,6 +62,7 @@ bool Parser::isCXXDeclarationStatement(
   case tok::kw_static_assert:
   case tok::kw__Static_assert:
 return true;
+  case tok::coloncolon:
   case tok::identifier: {
 if (DisambiguatingWithExpression) {
   RevertingTentativeParsingAction TPA(*this);

diff  --git a/clang/test/Interpreter/disambiguate-decl-stmt.cpp 
b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
index 4553a560ee5324..cbc456da6eb512 100644
--- a/clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -38,6 +38,10 @@ struct Dtor1 {~Dtor1();};
 Dtor1::~Dtor1() { printf("Dtor1\n"); }
 Dtor1 d1;
 
+struct Dtor2 { ~Dtor2(); };
+::Dtor2::~Dtor2() { printf("Dtor2\n"); }
+Dtor2 d2;
+
 struct ANestedDtor { struct A1 { struct A2 { ~A2(); }; }; };
 ANestedDtor::A1::A2::~A2() { printf("Dtor A::A1::A2::~A2\n"); }
 



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


[clang] da555f7 - [clang-repl] Additional test for disambiguation of templates

2023-08-09 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-09T16:15:14+02:00
New Revision: da555f750ab21d200ce486b45af75476662ca3b5

URL: 
https://github.com/llvm/llvm-project/commit/da555f750ab21d200ce486b45af75476662ca3b5
DIFF: 
https://github.com/llvm/llvm-project/commit/da555f750ab21d200ce486b45af75476662ca3b5.diff

LOG: [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

Added: 


Modified: 
clang/test/Interpreter/disambiguate-decl-stmt.cpp

Removed: 




diff  --git a/clang/test/Interpreter/disambiguate-decl-stmt.cpp 
b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
index 85160b6d8a9bf6..4553a560ee5324 100644
--- a/clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -11,6 +11,10 @@ extern "C" int printf(const char*,...);
 namespace ns1 { template void tmplt(T &) {}}
 int arg_tmplt = 12; ns1::tmplt(arg_tmplt);
 
+namespace ns2 { template  struct S {}; }
+namespace ns3 { struct A { public: using S = int; }; }
+namespace ns3 { A::S f(A::S a); }
+
 // ParseStatementOrDeclaration returns multiple statements.
 #ifdef MS
 int g_bFlag = 1;



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


[clang] cb3136b - [clang] Pass --cuda-path to fix test/Driver/openmp-offload-jit.c

2023-08-08 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-08T10:21:55+02:00
New Revision: cb3136b0d3596f5c3984e4fb49359e2a1a28a547

URL: 
https://github.com/llvm/llvm-project/commit/cb3136b0d3596f5c3984e4fb49359e2a1a28a547
DIFF: 
https://github.com/llvm/llvm-project/commit/cb3136b0d3596f5c3984e4fb49359e2a1a28a547.diff

LOG: [clang] Pass --cuda-path to fix test/Driver/openmp-offload-jit.c

This test was trying to detect a system installation of CUDA and was
marked as returning exit code 1 as part of D156363. Pass an explicit
CUDA installation to make the test return exit code 0 regardless of
a CUDA being found on the system or not. Also add an explicit -march
to get a stable test.

Added: 


Modified: 
clang/test/Driver/openmp-offload-jit.c

Removed: 




diff  --git a/clang/test/Driver/openmp-offload-jit.c 
b/clang/test/Driver/openmp-offload-jit.c
index d293c72b2ba1d0..6f5ae7ed7365d1 100644
--- a/clang/test/Driver/openmp-offload-jit.c
+++ b/clang/test/Driver/openmp-offload-jit.c
@@ -36,9 +36,10 @@
 // PHASES-JIT-NEXT: 13: clang-linker-wrapper, {12}, image, (host-openmp)
 
 // Check that we add the `--embed-bitcode` flag to the linker wrapper.
-// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp \
-// RUN:   -fopenmp-targets=nvptx64-nvidia-cuda -fopenmp-target-jit %s 2>&1 \
-// RUN: | FileCheck -check-prefix=LINKER %s
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp \
+// RUN:   --cuda-path=%S/Inputs/CUDA_111/usr/local/cuda \
+// RUN:   -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_52 \
+// RUN:   -fopenmp-target-jit %s 2>&1 | FileCheck -check-prefix=LINKER %s
 // LINKER: clang-linker-wrapper"{{.*}}"--embed-bitcode"
 
 // Check for incompatible combinations



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


[clang] 99b5474 - [Modules] Add test for merging of template member parent

2023-08-02 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-08-02T08:16:46+02:00
New Revision: 99b54743106bae89217c3591ec7461266dbd00a4

URL: 
https://github.com/llvm/llvm-project/commit/99b54743106bae89217c3591ec7461266dbd00a4
DIFF: 
https://github.com/llvm/llvm-project/commit/99b54743106bae89217c3591ec7461266dbd00a4.diff

LOG: [Modules] Add test for merging of template member parent

This is a reduced test case originally meant to be addressed by
https://reviews.llvm.org/D137787. It was recently fixed by commit
61c7a9140b ("Commit to a primary definition for a class when we load
its first member."), noting the difficulty to come up with a reduced
test case. This setup with four modules seems to fail consistently
before the fix mentioned above with an assertion in CGExprCXX.cpp,
CodeGenFunction::EmitCXXDestructorCall():
Assertion `ThisTy->getAsCXXRecordDecl() == DtorDecl->getParent() &&
"Pointer/Object mixup"' failed.

Differential Revision: https://reviews.llvm.org/D156806

Added: 
clang/test/Modules/merge-template-members-parent.cpp

Modified: 


Removed: 




diff  --git a/clang/test/Modules/merge-template-members-parent.cpp 
b/clang/test/Modules/merge-template-members-parent.cpp
new file mode 100644
index 00..c51483b8428dd4
--- /dev/null
+++ b/clang/test/Modules/merge-template-members-parent.cpp
@@ -0,0 +1,64 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -emit-obj -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/merge.cpp -o %t/merge.o
+
+//--- V.h
+#ifndef V_H
+#define V_H
+template 
+struct V {
+  ~V() {}
+};
+#endif
+
+//--- A.h
+#include "V.h"
+
+void A(const V );
+
+//--- B.h
+#include "V.h"
+
+inline V B() {
+  return {};
+}
+
+//--- C.h
+#include "V.h"
+
+#include "A.h"
+
+class C {
+public:
+  C(const V ) {
+V v2;
+  }
+};
+
+C GetC() {
+   return {{}};
+}
+
+// This include *MUST* come last.
+#include "B.h"
+
+//--- module.modulemap
+module "V" { header "V.h" export * }
+module "A" { header "A.h" export * }
+module "B" { header "B.h" export * }
+module "C" { header "C.h" export * }
+
+//--- merge.cpp
+#include "C.h"
+
+template 
+C GetC_main() {
+   return {{}};
+}
+
+void f() {
+   GetC_main();
+   GetC();
+}



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


[clang] 5ea647d - [CodeGen] Assert that EmittedDeferredDecls is empty

2023-07-31 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-07-31T13:40:00+02:00
New Revision: 5ea647dea6355304b641bf7bc407db497c6d9d21

URL: 
https://github.com/llvm/llvm-project/commit/5ea647dea6355304b641bf7bc407db497c6d9d21
DIFF: 
https://github.com/llvm/llvm-project/commit/5ea647dea6355304b641bf7bc407db497c6d9d21.diff

LOG: [CodeGen] Assert that EmittedDeferredDecls is empty

Its contents are transferred into DeferredDecls in Release(), so it
should be empty in moveLazyEmissionStates(). This matches the code
downstream in Cling.

Differential Revision: https://reviews.llvm.org/D156660

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 80c7ecedc28755..8d2abc69c330e7 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -7455,6 +7455,8 @@ void CodeGenModule::moveLazyEmissionStates(CodeGenModule 
*NewBuilder) {
   assert(NewBuilder->DeferredDecls.empty() &&
  "Newly created module should not have deferred decls");
   NewBuilder->DeferredDecls = std::move(DeferredDecls);
+  assert(EmittedDeferredDecls.empty() &&
+ "Still have (unmerged) EmittedDeferredDecls deferred decls");
 
   assert(NewBuilder->DeferredVTables.empty() &&
  "Newly created module should not have deferred vtables");
@@ -7470,10 +7472,5 @@ void CodeGenModule::moveLazyEmissionStates(CodeGenModule 
*NewBuilder) {
 
   NewBuilder->TBAA = std::move(TBAA);
 
-  assert(NewBuilder->EmittedDeferredDecls.empty() &&
- "Still have (unmerged) EmittedDeferredDecls deferred decls");
-
-  NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
-
   NewBuilder->ABI->MangleCtx = std::move(ABI->MangleCtx);
 }



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


[clang] ac6e9e6 - [clang-repl] Remove redundant tests

2023-07-27 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-07-27T16:22:56+02:00
New Revision: ac6e9e69bac76be2f05a20cea6ea8d69a0b43d1b

URL: 
https://github.com/llvm/llvm-project/commit/ac6e9e69bac76be2f05a20cea6ea8d69a0b43d1b
DIFF: 
https://github.com/llvm/llvm-project/commit/ac6e9e69bac76be2f05a20cea6ea8d69a0b43d1b.diff

LOG: [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

Added: 


Modified: 
clang/test/Interpreter/code-undo.cpp
clang/test/Interpreter/execute-weak.cpp
clang/test/Interpreter/execute.cpp
clang/test/Interpreter/fail.cpp
clang/test/Interpreter/lambda.cpp

Removed: 




diff  --git a/clang/test/Interpreter/code-undo.cpp 
b/clang/test/Interpreter/code-undo.cpp
index c963e45b9f2247..83ade0ec9158ba 100644
--- a/clang/test/Interpreter/code-undo.cpp
+++ b/clang/test/Interpreter/code-undo.cpp
@@ -1,7 +1,4 @@
-// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
-// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // UNSUPPORTED: system-aix
-// CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
 int x1 = 0;

diff  --git a/clang/test/Interpreter/execute-weak.cpp 
b/clang/test/Interpreter/execute-weak.cpp
index 66f2214ab03c0f..85fa5d276f5f46 100644
--- a/clang/test/Interpreter/execute-weak.cpp
+++ b/clang/test/Interpreter/execute-weak.cpp
@@ -1,8 +1,3 @@
-// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
-// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
-// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
-// CHECK-DRIVER: i = 10
-//
 // UNSUPPORTED: system-aix, system-windows
 // RUN: cat %s | clang-repl | FileCheck %s
 

diff  --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index ce2a5c7d504a59..6e73ed3927e815 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -1,9 +1,10 @@
+// UNSUPPORTED: system-aix
+
 // clang-format off
-// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
-// UNSUPPORTED: system-aix
 // CHECK-DRIVER: i = 10
+
 // RUN: cat %s | clang-repl | FileCheck %s
 // RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
 extern "C" int printf(const char *, ...);

diff  --git a/clang/test/Interpreter/fail.cpp b/clang/test/Interpreter/fail.cpp
index 1f02dc425ece21..4e301f37548f1f 100644
--- a/clang/test/Interpreter/fail.cpp
+++ b/clang/test/Interpreter/fail.cpp
@@ -3,11 +3,8 @@
 // error, and then successfully recovers if we decide it's a success then for
 // the non-interactive mode the exit code should be a failure.
 // RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
-// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
-// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// CHECK-DRIVER: i = 10
 // RUN: cat %s | not clang-repl | FileCheck %s
 BOOM!
 extern "C" int printf(const char *, ...);

diff  --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
index d06009d59fe08a..df75274a050b29 100644
--- a/clang/test/Interpreter/lambda.cpp
+++ b/clang/test/Interpreter/lambda.cpp
@@ -1,9 +1,5 @@
-// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
-// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
-// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 // RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
 extern "C" int printf(const char *, ...);



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


[clang] ce8ff3f - Remove clang/ModuleInfo.txt

2023-06-16 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-06-16T09:11:11+02:00
New Revision: ce8ff3facc637ae116f0d1c560a602b4dc939deb

URL: 
https://github.com/llvm/llvm-project/commit/ce8ff3facc637ae116f0d1c560a602b4dc939deb
DIFF: 
https://github.com/llvm/llvm-project/commit/ce8ff3facc637ae116f0d1c560a602b4dc939deb.diff

LOG: Remove clang/ModuleInfo.txt

The script build-for-llvm-top.sh and LLVM's ModuleInfo.txt are gone
since a long time (commit d20ea7dc59 in November 2011), and llvm-top
itself has even been removed from llvm-archive (it can be found here:
https://github.com/llvm/llvm-archive/tree/cab7f8f160f0bd8d20d9a4036aa4083f2bc2740a/llvm-top
) so delete Clang's ModuleInfo.txt as well.

Differential Revision: https://reviews.llvm.org/D152995

Added: 


Modified: 


Removed: 
clang/ModuleInfo.txt



diff  --git a/clang/ModuleInfo.txt b/clang/ModuleInfo.txt
deleted file mode 100644
index 4368ef067aead..0
--- a/clang/ModuleInfo.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-# This file provides information for llvm-top
-DepModule: llvm 
-ConfigCmd:
-ConfigTest:
-BuildCmd:



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


[clang] 53c03a3 - [clang][modules] Add features for recent C++ versions

2023-05-17 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-05-17T15:18:50+02:00
New Revision: 53c03a3db16cd9b51476ce4b4fb1adc1b58f1ff7

URL: 
https://github.com/llvm/llvm-project/commit/53c03a3db16cd9b51476ce4b4fb1adc1b58f1ff7
DIFF: 
https://github.com/llvm/llvm-project/commit/53c03a3db16cd9b51476ce4b4fb1adc1b58f1ff7.diff

LOG: [clang][modules] Add features for recent C++ versions

Add cplusplus20, cplusplus23, and cplusplus26 (but don't document
the latter, following the current policy).

Differential Revision: https://reviews.llvm.org/D150773

Added: 


Modified: 
clang/docs/Modules.rst
clang/docs/ReleaseNotes.rst
clang/lib/Basic/Module.cpp
clang/test/Modules/Inputs/DependsOnModule.framework/module.map
clang/test/Modules/requires.m

Removed: 




diff  --git a/clang/docs/Modules.rst b/clang/docs/Modules.rst
index 825d8722c4d53..a54850f5457bd 100644
--- a/clang/docs/Modules.rst
+++ b/clang/docs/Modules.rst
@@ -573,6 +573,12 @@ cplusplus14
 cplusplus17
   C++17 support is available.
 
+cplusplus20
+  C++20 support is available.
+
+cplusplus23
+  C++23 support is available.
+
 c99
   C99 support is available.
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2f13ef96ba03f..0059707529e00 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -94,6 +94,7 @@ C++20 Feature Support
 - Clang now implements `[temp.deduct]p9`. Substitution failures inside lambdas 
from
   unevaluated contexts will be surfaced as errors. They were previously 
handled as
   SFINAE.
+- Clang now supports `requires cplusplus20` for module maps.
 
 C++23 Feature Support
 ^
@@ -108,6 +109,7 @@ C++23 Feature Support
   longer have to be constexpr compatible but rather support a less restricted 
requirements for constexpr
   functions. Which include allowing non-literal types as return values and 
parameters, allow calling of
   non-constexpr functions and constructors.
+- Clang now supports `requires cplusplus23` for module maps.
 
 C++2c Feature Support
 ^

diff  --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index e5994a7cc2fad..12ca19d8c6eb8 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -107,6 +107,9 @@ static bool hasFeature(StringRef Feature, const LangOptions 
,
 .Case("cplusplus11", LangOpts.CPlusPlus11)
 .Case("cplusplus14", LangOpts.CPlusPlus14)
 .Case("cplusplus17", LangOpts.CPlusPlus17)
+.Case("cplusplus20", LangOpts.CPlusPlus20)
+.Case("cplusplus23", LangOpts.CPlusPlus23)
+.Case("cplusplus26", LangOpts.CPlusPlus26)
 .Case("c99", LangOpts.C99)
 .Case("c11", LangOpts.C11)
 .Case("c17", LangOpts.C17)

diff  --git a/clang/test/Modules/Inputs/DependsOnModule.framework/module.map 
b/clang/test/Modules/Inputs/DependsOnModule.framework/module.map
index 948a1efd743af..9cede40c45c33 100644
--- a/clang/test/Modules/Inputs/DependsOnModule.framework/module.map
+++ b/clang/test/Modules/Inputs/DependsOnModule.framework/module.map
@@ -46,6 +46,15 @@ framework module DependsOnModule {
   explicit module CXX17 {
 requires cplusplus17
   }
+  explicit module CXX20 {
+requires cplusplus20
+  }
+  explicit module CXX23 {
+requires cplusplus23
+  }
+  explicit module CXX26 {
+requires cplusplus26
+  }
   explicit module C99 {
 requires c99
   }

diff  --git a/clang/test/Modules/requires.m b/clang/test/Modules/requires.m
index 0ba51d4609ce0..b370fa31ee0d9 100644
--- a/clang/test/Modules/requires.m
+++ b/clang/test/Modules/requires.m
@@ -22,11 +22,17 @@
 @import DependsOnModule.CXX14; // expected-note {{module imported here}}
 // expected-error@DependsOnModule.framework/module.map:46 {{module 
'DependsOnModule.CXX17' requires feature 'cplusplus17'}}
 @import DependsOnModule.CXX17; // expected-note {{module imported here}}
+// expected-error@DependsOnModule.framework/module.map:49 {{module 
'DependsOnModule.CXX20' requires feature 'cplusplus20'}}
+@import DependsOnModule.CXX20; // expected-note {{module imported here}}
+// expected-error@DependsOnModule.framework/module.map:52 {{module 
'DependsOnModule.CXX23' requires feature 'cplusplus23'}}
+@import DependsOnModule.CXX23; // expected-note {{module imported here}}
+// expected-error@DependsOnModule.framework/module.map:55 {{module 
'DependsOnModule.CXX26' requires feature 'cplusplus26'}}
+@import DependsOnModule.CXX26; // expected-note {{module imported here}}
 #else
-// expected-error@DependsOnModule.framework/module.map:49 {{module 
'DependsOnModule.C99' requires feature 'c99'}}
+// expected-error@DependsOnModule.framework/module.map:58 {{module 
'DependsOnModule.C99' requires feature 'c99'}}
 @import DependsOnModule.C99; // expected-note 

[clang] 0b3c48d - [cmake] Correct option to LLVM_FORCE_USE_OLD_TOOLCHAIN

2023-05-17 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-05-17T10:35:49+02:00
New Revision: 0b3c48d5722a30e8b052b8d08f6de5afcf2edeb1

URL: 
https://github.com/llvm/llvm-project/commit/0b3c48d5722a30e8b052b8d08f6de5afcf2edeb1
DIFF: 
https://github.com/llvm/llvm-project/commit/0b3c48d5722a30e8b052b8d08f6de5afcf2edeb1.diff

LOG: [cmake] Correct option to LLVM_FORCE_USE_OLD_TOOLCHAIN

This option was renamed a long time ago in commit 388cefa78d.

Added: 


Modified: 
clang/CMakeLists.txt
flang/CMakeLists.txt

Removed: 




diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index bd2ac69c1455..8220a9dbfd4d 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -54,7 +54,7 @@ if(CLANG_BUILT_STANDALONE)
   option(LLVM_INSTALL_TOOLCHAIN_ONLY
 "Only include toolchain files in the 'install' target." OFF)
 
-  option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
+  option(LLVM_FORCE_USE_OLD_TOOLCHAIN
 "Set to ON to force using an old, unsupported host toolchain." OFF)
   option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF)
   option(LLVM_ENABLE_LIBXML2 "Use libxml2 if available." ON)

diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 66a09703c87d..4c0b9a84cc5b 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -125,7 +125,7 @@ if (FLANG_STANDALONE_BUILD)
 
   option(LLVM_INSTALL_TOOLCHAIN_ONLY
 "Only include toolchain files in the 'install' target." OFF)
-  option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
+  option(LLVM_FORCE_USE_OLD_TOOLCHAIN
 "Set to ON to force using an old, unsupported host toolchain." OFF)
 
 



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


[clang] b5ee4f7 - Revert "Lazyly initialize uncommon toolchain detector"

2023-02-06 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-02-06T15:39:33+01:00
New Revision: b5ee4f755fcff56243f6ff0cea9e7a722259304a

URL: 
https://github.com/llvm/llvm-project/commit/b5ee4f755fcff56243f6ff0cea9e7a722259304a
DIFF: 
https://github.com/llvm/llvm-project/commit/b5ee4f755fcff56243f6ff0cea9e7a722259304a.diff

LOG: Revert "Lazyly initialize uncommon toolchain detector"

clang/test/Driver/rocm-detect.hip is failing for a number of
configurations, for example:

clang-x86_64-debian-fast
https://lab.llvm.org/buildbot/#/builders/109/builds/57270

clang-debian-cpp20
https://lab.llvm.org/buildbot/#/builders/249/builds/310

clang-with-lto-ubuntu
https://lab.llvm.org/buildbot/#/builders/124/builds/6693

This reverts commit 6fa2abf90886f18472c87bc9bffbcdf4f73c465e.

Added: 


Modified: 
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Gnu.h
clang/lib/Driver/ToolChains/HIPAMD.cpp
clang/lib/Driver/ToolChains/Linux.cpp

Removed: 
clang/lib/Driver/ToolChains/LazyDetector.h



diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index a25bea951388c..52021901b9bf8 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -701,7 +701,7 @@ bool AMDGPUToolChain::isWave64(const llvm::opt::ArgList 
,
 ROCMToolChain::ROCMToolChain(const Driver , const llvm::Triple ,
  const ArgList )
 : AMDGPUToolChain(D, Triple, Args) {
-  RocmInstallation->detectDeviceLibrary();
+  RocmInstallation.detectDeviceLibrary();
 }
 
 void AMDGPUToolChain::addClangTargetOptions(
@@ -790,11 +790,11 @@ void ROCMToolChain::addClangTargetOptions(
   const StringRef GpuArch = getGPUArch(DriverArgs);
   auto Kind = llvm::AMDGPU::parseArchAMDGCN(GpuArch);
   const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
-  StringRef LibDeviceFile = RocmInstallation->getLibDeviceFile(CanonArch);
+  StringRef LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
   auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion(
   getAMDGPUCodeObjectVersion(getDriver(), DriverArgs));
-  if (!RocmInstallation->checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
-ABIVer))
+  if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
+   ABIVer))
 return;
 
   bool Wave64 = isWave64(DriverArgs, Kind);
@@ -813,10 +813,10 @@ void ROCMToolChain::addClangTargetOptions(
 
   // Add the OpenCL specific bitcode library.
   llvm::SmallVector BCLibs;
-  BCLibs.push_back(RocmInstallation->getOpenCLPath().str());
+  BCLibs.push_back(RocmInstallation.getOpenCLPath().str());
 
   // Add the generic set of libraries.
-  BCLibs.append(RocmInstallation->getCommonBitcodeLibs(
+  BCLibs.append(RocmInstallation.getCommonBitcodeLibs(
   DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
   FastRelaxedMath, CorrectSqrt, ABIVer, false));
 
@@ -875,11 +875,11 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList ,
   auto Kind = llvm::AMDGPU::parseArchAMDGCN(GPUArch);
   const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
 
-  StringRef LibDeviceFile = RocmInstallation->getLibDeviceFile(CanonArch);
+  StringRef LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
   auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion(
   getAMDGPUCodeObjectVersion(getDriver(), DriverArgs));
-  if (!RocmInstallation->checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
-ABIVer))
+  if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
+   ABIVer))
 return {};
 
   // If --hip-device-lib is not set, add the default bitcode libraries.
@@ -900,7 +900,7 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList ,
   options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt, true);
   bool Wave64 = isWave64(DriverArgs, Kind);
 
-  return RocmInstallation->getCommonBitcodeLibs(
+  return RocmInstallation.getCommonBitcodeLibs(
   DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
   FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
 }

diff  --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index b012b7cb72937..68d351af22603 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -160,7 +160,7 @@ AMDGPUOpenMPToolChain::getDeviceLibs(const 
llvm::opt::ArgList ) const {
   if (Args.hasArg(options::OPT_nogpulib))
 return {};
 
-  if (!RocmInstallation->hasDeviceLibrary()) {
+  if (!RocmInstallation.hasDeviceLibrary()) {
 

[clang] 01eb01c - [clang][Lex] Add back PPCallbacks::FileNotFound

2023-01-24 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-01-24T09:52:27+01:00
New Revision: 01eb01c7fd7ad6f569ad4d7bf65b5327ac111955

URL: 
https://github.com/llvm/llvm-project/commit/01eb01c7fd7ad6f569ad4d7bf65b5327ac111955
DIFF: 
https://github.com/llvm/llvm-project/commit/01eb01c7fd7ad6f569ad4d7bf65b5327ac111955.diff

LOG: [clang][Lex] Add back PPCallbacks::FileNotFound

This callback was removed with commit 7a124f4859, but we use it
downstream in ROOT/Cling to implement handling of a special include
syntax. Add back a "safe" version of the callback that only takes
the file name and return a bool to silently skip the file.

Differential Revision: https://reviews.llvm.org/D142196

Added: 


Modified: 
clang/include/clang/Lex/PPCallbacks.h
clang/lib/Lex/PPDirectives.cpp
clang/unittests/Lex/PPCallbacksTest.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/PPCallbacks.h 
b/clang/include/clang/Lex/PPCallbacks.h
index 2e99fd9300362..94f96cf9c5125 100644
--- a/clang/include/clang/Lex/PPCallbacks.h
+++ b/clang/include/clang/Lex/PPCallbacks.h
@@ -83,6 +83,16 @@ class PPCallbacks {
const Token ,
SrcMgr::CharacteristicKind FileType) {}
 
+  /// Callback invoked whenever the preprocessor cannot find a file for an
+  /// inclusion directive.
+  ///
+  /// \param FileName The name of the file being included, as written in the
+  /// source code.
+  ///
+  /// \returns true to indicate that the preprocessor should skip this file
+  /// and not issue any diagnostic.
+  virtual bool FileNotFound(StringRef FileName) { return false; }
+
   /// Callback invoked whenever an inclusion directive of
   /// any kind (\c \#include, \c \#import, etc.) has been processed, regardless
   /// of whether the inclusion will actually result in an inclusion.
@@ -451,6 +461,14 @@ class PPChainedCallbacks : public PPCallbacks {
 Second->FileSkipped(SkippedFile, FilenameTok, FileType);
   }
 
+  bool FileNotFound(StringRef FileName) override {
+bool Skip = First->FileNotFound(FileName);
+// Make sure to invoke the second callback, no matter if the first already
+// returned true to skip the file.
+Skip |= Second->FileNotFound(FileName);
+return Skip;
+  }
+
   void InclusionDirective(SourceLocation HashLoc, const Token ,
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange,

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index f08d5fe2747f7..6ae513dea8782 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -2000,6 +2000,10 @@ OptionalFileEntryRef 
Preprocessor::LookupHeaderIncludeOrImport(
   if (File)
 return File;
 
+  // Give the clients a chance to silently skip this include.
+  if (Callbacks && Callbacks->FileNotFound(Filename))
+return std::nullopt;
+
   if (SuppressIncludeNotFoundError)
 return std::nullopt;
 

diff  --git a/clang/unittests/Lex/PPCallbacksTest.cpp 
b/clang/unittests/Lex/PPCallbacksTest.cpp
index ec719387fa022..b2be40ef3812e 100644
--- a/clang/unittests/Lex/PPCallbacksTest.cpp
+++ b/clang/unittests/Lex/PPCallbacksTest.cpp
@@ -444,6 +444,50 @@ TEST_F(PPCallbacksTest, TrigraphInMacro) {
   ASSERT_EQ("\"tri\?\?-graph.h\"", GetSourceString(Range));
 }
 
+TEST_F(PPCallbacksTest, FileNotFoundSkipped) {
+  const char *SourceText = "#include \"skipped.h\"\n";
+
+  std::unique_ptr SourceBuf =
+  llvm::MemoryBuffer::getMemBuffer(SourceText);
+  SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(SourceBuf)));
+
+  HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,
+  Diags, LangOpts, Target.get());
+  TrivialModuleLoader ModLoader;
+
+  DiagnosticConsumer *DiagConsumer = new DiagnosticConsumer;
+  DiagnosticsEngine FileNotFoundDiags(DiagID, DiagOpts.get(), DiagConsumer);
+  Preprocessor PP(std::make_shared(), FileNotFoundDiags,
+  LangOpts, SourceMgr, HeaderInfo, ModLoader,
+  /*IILookup=*/nullptr,
+  /*OwnsHeaderSearch=*/false);
+  PP.Initialize(*Target);
+
+  class FileNotFoundCallbacks : public PPCallbacks {
+  public:
+unsigned int NumCalls = 0;
+bool FileNotFound(StringRef FileName) override {
+  NumCalls++;
+  return FileName == "skipped.h";
+}
+  };
+
+  auto *Callbacks = new FileNotFoundCallbacks;
+  PP.addPPCallbacks(std::unique_ptr(Callbacks));
+
+  // Lex source text.
+  PP.EnterMainSourceFile();
+  while (true) {
+Token Tok;
+PP.Lex(Tok);
+if (Tok.is(tok::eof))
+  break;
+  }
+
+  ASSERT_EQ(1u, Callbacks->NumCalls);
+  ASSERT_EQ(0u, DiagConsumer->getNumErrors());
+}
+
 TEST_F(PPCallbacksTest, OpenCLExtensionPragmaEnabled) {
   const char* Source =
 "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n";



___
cfe-commits mailing list

[clang] f3c9342 - Fix build of nvptx-arch with CLANG_LINK_CLANG_DYLIB

2022-12-29 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2022-12-29T09:48:05+01:00
New Revision: f3c9342a3d56e1782e3b6db081401af334648492

URL: 
https://github.com/llvm/llvm-project/commit/f3c9342a3d56e1782e3b6db081401af334648492
DIFF: 
https://github.com/llvm/llvm-project/commit/f3c9342a3d56e1782e3b6db081401af334648492.diff

LOG: Fix build of nvptx-arch with CLANG_LINK_CLANG_DYLIB

The function clang_target_link_libraries must only be used with real
Clang libraries; with CLANG_LINK_CLANG_DYLIB, it will instead link in
clang-cpp. We must use the standard CMake target_link_libraries for
the CUDA library.

Added: 


Modified: 
clang/tools/nvptx-arch/CMakeLists.txt

Removed: 




diff  --git a/clang/tools/nvptx-arch/CMakeLists.txt 
b/clang/tools/nvptx-arch/CMakeLists.txt
index 94ef206a3bd75..94f544a01f0e6 100644
--- a/clang/tools/nvptx-arch/CMakeLists.txt
+++ b/clang/tools/nvptx-arch/CMakeLists.txt
@@ -25,4 +25,4 @@ add_clang_tool(nvptx-arch NVPTXArch.cpp)
 set_target_properties(nvptx-arch PROPERTIES INSTALL_RPATH_USE_LINK_PATH ON)
 target_include_directories(nvptx-arch PRIVATE ${CUDA_INCLUDE_DIRS})
 
-clang_target_link_libraries(nvptx-arch PRIVATE ${cuda-library})
+target_link_libraries(nvptx-arch PRIVATE ${cuda-library})



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


[clang] f0403c8 - Fix build of Lex unit test with CLANG_DYLIB

2022-09-12 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2022-09-12T13:49:57+02:00
New Revision: f0403c853bc93fe1127fef7493a4feff1479191e

URL: 
https://github.com/llvm/llvm-project/commit/f0403c853bc93fe1127fef7493a4feff1479191e
DIFF: 
https://github.com/llvm/llvm-project/commit/f0403c853bc93fe1127fef7493a4feff1479191e.diff

LOG: Fix build of Lex unit test with CLANG_DYLIB

If CLANG_LINK_CLANG_DYLIB, clang_target_link_libraries ignores all
indivial libraries and only links clang-cpp. As LLVMTestingSupport
is separate, pass it via target_link_libraries directly.

Added: 


Modified: 
clang/unittests/Lex/CMakeLists.txt

Removed: 




diff  --git a/clang/unittests/Lex/CMakeLists.txt 
b/clang/unittests/Lex/CMakeLists.txt
index 5b498f54fb0af..bed5fd9186f22 100644
--- a/clang/unittests/Lex/CMakeLists.txt
+++ b/clang/unittests/Lex/CMakeLists.txt
@@ -20,6 +20,9 @@ clang_target_link_libraries(LexTests
   clangLex
   clangParse
   clangSema
+  )
 
+target_link_libraries(LexTests
+  PRIVATE
   LLVMTestingSupport
   )



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


[clang] f22795d - [Interpreter] Pass target features to JIT

2022-06-30 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2022-06-30T21:25:14+02:00
New Revision: f22795de683d571bbf7e655a7b4ed5ccda186e66

URL: 
https://github.com/llvm/llvm-project/commit/f22795de683d571bbf7e655a7b4ed5ccda186e66
DIFF: 
https://github.com/llvm/llvm-project/commit/f22795de683d571bbf7e655a7b4ed5ccda186e66.diff

LOG: [Interpreter] Pass target features to JIT

This is required to support RISC-V where the '+d' target feature
indicates the presence of the D instruction set extension, which
changes to the Hard-float 'd' ABI.

Differential Revision: https://reviews.llvm.org/D128853

Added: 


Modified: 
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/lib/Interpreter/IncrementalExecutor.h
clang/lib/Interpreter/Interpreter.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index c055827281b4f..227ab9703dc76 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -12,6 +12,8 @@
 
 #include "IncrementalExecutor.h"
 
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
 #include "clang/Interpreter/PartialTranslationUnit.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
 #include "llvm/ExecutionEngine/Orc/CompileUtils.h"
@@ -28,12 +30,13 @@ namespace clang {
 
 IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext ,
  llvm::Error ,
- const llvm::Triple )
+ const clang::TargetInfo )
 : TSCtx(TSC) {
   using namespace llvm::orc;
   llvm::ErrorAsOutParameter EAO();
 
-  auto JTMB = JITTargetMachineBuilder(Triple);
+  auto JTMB = JITTargetMachineBuilder(TI.getTriple());
+  JTMB.addFeatures(TI.getTargetOpts().Features);
   if (auto JitOrErr = LLJITBuilder().setJITTargetMachineBuilder(JTMB).create())
 Jit = std::move(*JitOrErr);
   else {

diff  --git a/clang/lib/Interpreter/IncrementalExecutor.h 
b/clang/lib/Interpreter/IncrementalExecutor.h
index 580724e1e24e2..f11ec0aa9e758 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.h
+++ b/clang/lib/Interpreter/IncrementalExecutor.h
@@ -15,7 +15,6 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/Triple.h"
 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
 
 #include 
@@ -32,6 +31,7 @@ class ThreadSafeContext;
 namespace clang {
 
 struct PartialTranslationUnit;
+class TargetInfo;
 
 class IncrementalExecutor {
   using CtorDtorIterator = llvm::orc::CtorDtorIterator;
@@ -45,7 +45,7 @@ class IncrementalExecutor {
   enum SymbolNameKind { IRName, LinkerName };
 
   IncrementalExecutor(llvm::orc::ThreadSafeContext , llvm::Error ,
-  const llvm::Triple );
+  const clang::TargetInfo );
   ~IncrementalExecutor();
 
   llvm::Error addModule(PartialTranslationUnit );

diff  --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index a10eb79b413b3..0191ad78581d9 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -213,10 +213,10 @@ Interpreter::Parse(llvm::StringRef Code) {
 llvm::Error Interpreter::Execute(PartialTranslationUnit ) {
   assert(T.TheModule);
   if (!IncrExecutor) {
-const llvm::Triple  =
-getCompilerInstance()->getASTContext().getTargetInfo().getTriple();
+const clang::TargetInfo  =
+getCompilerInstance()->getASTContext().getTargetInfo();
 llvm::Error Err = llvm::Error::success();
-IncrExecutor = std::make_unique(*TSCtx, Err, Triple);
+IncrExecutor = std::make_unique(*TSCtx, Err, TI);
 
 if (Err)
   return Err;



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


[clang] 0d21863 - [Driver] Add multiarch path for RISC-V

2022-06-03 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2022-06-03T09:10:34+02:00
New Revision: 0d2186373f73995cfcc45f445024fbc9841c99d6

URL: 
https://github.com/llvm/llvm-project/commit/0d2186373f73995cfcc45f445024fbc9841c99d6
DIFF: 
https://github.com/llvm/llvm-project/commit/0d2186373f73995cfcc45f445024fbc9841c99d6.diff

LOG: [Driver] Add multiarch path for RISC-V

This is required to find headers on the Debian port for RISC-V.

Differential Revision: https://reviews.llvm.org/D126672

Added: 


Modified: 
clang/lib/Driver/ToolChains/Linux.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 43b2bf06e8b4..4309b1060346 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -124,6 +124,8 @@ std::string Linux::getMultiarchTriple(const Driver ,
 return "powerpc64-linux-gnu";
   case llvm::Triple::ppc64le:
 return "powerpc64le-linux-gnu";
+  case llvm::Triple::riscv64:
+return "riscv64-linux-gnu";
   case llvm::Triple::sparc:
 return "sparc-linux-gnu";
   case llvm::Triple::sparcv9:



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


[clang] e4903d8 - [CUDA/HIP] Remove argument from module ctor/dtor signatures

2022-04-09 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2022-04-09T12:34:41+02:00
New Revision: e4903d8be399864cc978236fc4a28087f91c20fe

URL: 
https://github.com/llvm/llvm-project/commit/e4903d8be399864cc978236fc4a28087f91c20fe
DIFF: 
https://github.com/llvm/llvm-project/commit/e4903d8be399864cc978236fc4a28087f91c20fe.diff

LOG: [CUDA/HIP] Remove argument from module ctor/dtor signatures

In theory, constructors can take arguments when called via .init_array
where at least glibc passes in (argc, argv, envp). This isn't used in
the generated code and if it was, the first argument should be an
integer, not a pointer. For destructors registered via atexit, the
function should never take an argument.

Differential Revision: https://reviews.llvm.org/D123370

Added: 


Modified: 
clang/lib/CodeGen/CGCUDANV.cpp
clang/test/CodeGenCUDA/device-stub.cu

Removed: 




diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 3ae152d743206..187817d0e5059 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -659,7 +659,7 @@ llvm::Function *CGNVCUDARuntime::makeRegisterGlobalsFn() {
 ///
 /// For CUDA:
 /// \code
-/// void __cuda_module_ctor(void*) {
+/// void __cuda_module_ctor() {
 /// Handle = __cudaRegisterFatBinary(GpuBinaryBlob);
 /// __cuda_register_globals(Handle);
 /// }
@@ -667,7 +667,7 @@ llvm::Function *CGNVCUDARuntime::makeRegisterGlobalsFn() {
 ///
 /// For HIP:
 /// \code
-/// void __hip_module_ctor(void*) {
+/// void __hip_module_ctor() {
 /// if (__hip_gpubin_handle == 0) {
 /// __hip_gpubin_handle  = __hipRegisterFatBinary(GpuBinaryBlob);
 /// __hip_register_globals(__hip_gpubin_handle);
@@ -717,7 +717,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
   }
 
   llvm::Function *ModuleCtorFunc = llvm::Function::Create(
-  llvm::FunctionType::get(VoidTy, VoidPtrTy, false),
+  llvm::FunctionType::get(VoidTy, false),
   llvm::GlobalValue::InternalLinkage,
   addUnderscoredPrefixToName("_module_ctor"), );
   llvm::BasicBlock *CtorEntryBB =
@@ -931,14 +931,14 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() 
{
 ///
 /// For CUDA:
 /// \code
-/// void __cuda_module_dtor(void*) {
+/// void __cuda_module_dtor() {
 /// __cudaUnregisterFatBinary(Handle);
 /// }
 /// \endcode
 ///
 /// For HIP:
 /// \code
-/// void __hip_module_dtor(void*) {
+/// void __hip_module_dtor() {
 /// if (__hip_gpubin_handle) {
 /// __hipUnregisterFatBinary(__hip_gpubin_handle);
 /// __hip_gpubin_handle = 0;
@@ -956,7 +956,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleDtorFunction() {
   addUnderscoredPrefixToName("UnregisterFatBinary"));
 
   llvm::Function *ModuleDtorFunc = llvm::Function::Create(
-  llvm::FunctionType::get(VoidTy, VoidPtrTy, false),
+  llvm::FunctionType::get(VoidTy, false),
   llvm::GlobalValue::InternalLinkage,
   addUnderscoredPrefixToName("_module_dtor"), );
 

diff  --git a/clang/test/CodeGenCUDA/device-stub.cu 
b/clang/test/CodeGenCUDA/device-stub.cu
index aa7211aeaf8e7..0f925a29c215d 100644
--- a/clang/test/CodeGenCUDA/device-stub.cu
+++ b/clang/test/CodeGenCUDA/device-stub.cu
@@ -257,8 +257,8 @@ void hostfunc(void) { kernelfunc<<<1, 1>>>(1, 1, 1); }
 // CUDANORDC-NEXT: call void @__[[PREFIX]]_register_globals
 // HIP-NEXT: call void @__[[PREFIX]]_register_globals
 // * In separate mode we also register a destructor.
-// CUDANORDC-NEXT: call i32 @atexit(void (i8*)* @__[[PREFIX]]_module_dtor)
-// HIP-NEXT: call i32 @atexit(void (i8*)* @__[[PREFIX]]_module_dtor)
+// CUDANORDC-NEXT: call i32 @atexit(void ()* @__[[PREFIX]]_module_dtor)
+// HIP-NEXT: call i32 @atexit(void ()* @__[[PREFIX]]_module_dtor)
 
 // With relocatable device code we call 
__[[PREFIX]]RegisterLinkedBinary%NVModuleID%
 // CUDARDC: call{{.*}}__[[PREFIX]]RegisterLinkedBinary[[MODULE_ID]](



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


[clang] ea08c4c - [CUDA] Fix static device variables with -fgpu-rdc

2021-08-25 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2021-08-25T09:31:22+02:00
New Revision: ea08c4cd1c0869ec5024a8bb3f5cdf06ab03ae83

URL: 
https://github.com/llvm/llvm-project/commit/ea08c4cd1c0869ec5024a8bb3f5cdf06ab03ae83
DIFF: 
https://github.com/llvm/llvm-project/commit/ea08c4cd1c0869ec5024a8bb3f5cdf06ab03ae83.diff

LOG: [CUDA] Fix static device variables with -fgpu-rdc

NVPTX does not allow dots in the identifier, so ptxas errors out with
   fatal   : Parsing error near '.static': syntax error
because it parses .static as a directive. Avoid this problem by using
two underscores, similar to what OpenMP does for outlined functions.

Differential Revision: https://reviews.llvm.org/D108456

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCUDA/device-var-linkage.cu
clang/test/CodeGenCUDA/managed-var.cu
clang/test/CodeGenCUDA/static-device-var-rdc.cu

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 13d7cce880e09..0940980461cd7 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -6444,5 +6444,5 @@ bool CodeGenModule::stopAutoInit() {
 
 void CodeGenModule::printPostfixForExternalizedStaticVar(
 llvm::raw_ostream ) const {
-  OS << ".static." << getContext().getCUIDHash();
+  OS << "__static__" << getContext().getCUIDHash();
 }

diff  --git a/clang/test/CodeGenCUDA/device-var-linkage.cu 
b/clang/test/CodeGenCUDA/device-var-linkage.cu
index d8cd9352e8850..d830802c82061 100644
--- a/clang/test/CodeGenCUDA/device-var-linkage.cu
+++ b/clang/test/CodeGenCUDA/device-var-linkage.cu
@@ -37,15 +37,15 @@ extern __constant__ int ev2;
 extern __managed__ int ev3;
 
 // NORDC-DAG: @_ZL3sv1 = addrspace(1) externally_initialized global i32 0
-// RDC-DAG: @_ZL3sv1.static.[[HASH:.*]] = addrspace(1) externally_initialized 
global i32 0
+// RDC-DAG: @_ZL3sv1__static__[[HASH:.*]] = addrspace(1) 
externally_initialized global i32 0
 // HOST-DAG: @_ZL3sv1 = internal global i32 undef
 static __device__ int sv1;
 // NORDC-DAG: @_ZL3sv2 = addrspace(4) externally_initialized global i32 0
-// RDC-DAG: @_ZL3sv2.static.[[HASH]] = addrspace(4) externally_initialized 
global i32 0
+// RDC-DAG: @_ZL3sv2__static__[[HASH]] = addrspace(4) externally_initialized 
global i32 0
 // HOST-DAG: @_ZL3sv2 = internal global i32 undef
 static __constant__ int sv2;
 // NORDC-DAG: @_ZL3sv3 = addrspace(1) externally_initialized global i32 
addrspace(1)* null
-// RDC-DAG: @_ZL3sv3.static.[[HASH]] = addrspace(1) externally_initialized 
global i32 addrspace(1)* null
+// RDC-DAG: @_ZL3sv3__static__[[HASH]] = addrspace(1) externally_initialized 
global i32 addrspace(1)* null
 // HOST-DAG: @_ZL3sv3 = internal externally_initialized global i32* null
 static __managed__ int sv3;
 

diff  --git a/clang/test/CodeGenCUDA/managed-var.cu 
b/clang/test/CodeGenCUDA/managed-var.cu
index 05a7a69387690..96657f0f7a131 100644
--- a/clang/test/CodeGenCUDA/managed-var.cu
+++ b/clang/test/CodeGenCUDA/managed-var.cu
@@ -52,15 +52,15 @@ extern __managed__ int ex;
 
 // NORDC-D-DAG: @_ZL2sx.managed = addrspace(1) externally_initialized global 
i32 1, align 4
 // NORDC-D-DAG: @_ZL2sx = addrspace(1) externally_initialized global i32 
addrspace(1)* null
-// RDC-D-DAG: @_ZL2sx.static.[[HASH:.*]].managed = addrspace(1) 
externally_initialized global i32 1, align 4
-// RDC-D-DAG: @_ZL2sx.static.[[HASH]] = addrspace(1) externally_initialized 
global i32 addrspace(1)* null
+// RDC-D-DAG: @_ZL2sx__static__[[HASH:.*]].managed = addrspace(1) 
externally_initialized global i32 1, align 4
+// RDC-D-DAG: @_ZL2sx__static__[[HASH]] = addrspace(1) externally_initialized 
global i32 addrspace(1)* null
 // HOST-DAG: @_ZL2sx.managed = internal global i32 1
 // HOST-DAG: @_ZL2sx = internal externally_initialized global i32* null
 // NORDC-DAG: @[[DEVNAMESX:[0-9]+]] = {{.*}}c"_ZL2sx\00"
-// RDC-DAG: @[[DEVNAMESX:[0-9]+]] = {{.*}}c"_ZL2sx.static.[[HASH:.*]]\00"
+// RDC-DAG: @[[DEVNAMESX:[0-9]+]] = {{.*}}c"_ZL2sx__static__[[HASH:.*]]\00"
 
-// POSTFIX:  @_ZL2sx.static.[[HASH:.*]] = addrspace(1) externally_initialized 
global i32 addrspace(1)* null
-// POSTFIX: @[[DEVNAMESX:[0-9]+]] = {{.*}}c"_ZL2sx.static.[[HASH]]\00"
+// POSTFIX:  @_ZL2sx__static__[[HASH:.*]] = addrspace(1) 
externally_initialized global i32 addrspace(1)* null
+// POSTFIX: @[[DEVNAMESX:[0-9]+]] = {{.*}}c"_ZL2sx__static__[[HASH]]\00"
 static __managed__ int sx = 1;
 
 // DEV-DAG: @llvm.compiler.used

diff  --git a/clang/test/CodeGenCUDA/static-device-var-rdc.cu 
b/clang/test/CodeGenCUDA/static-device-var-rdc.cu
index f32e039842990..bb750bd91a928 100644
--- a/clang/test/CodeGenCUDA/static-device-var-rdc.cu
+++ b/clang/test/CodeGenCUDA/static-device-var-rdc.cu
@@ -55,11 +55,11 @@
 // INT-HOST-DAG: @[[DEVNAMEX:[0-9]+]] = {{.*}}c"_ZL1x\00"
 
 // Test externalized static device variables
-// EXT-DEV-DAG: @_ZL1x.static.[[HASH:.*]] 

[clang] ced99a1 - Fix comment for CLANG_SYSTEMZ_DEFAULT_ARCH

2020-03-30 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2020-03-30T21:36:18+02:00
New Revision: ced99a1a6368b117384935957e2329ec4ba7784b

URL: 
https://github.com/llvm/llvm-project/commit/ced99a1a6368b117384935957e2329ec4ba7784b
DIFF: 
https://github.com/llvm/llvm-project/commit/ced99a1a6368b117384935957e2329ec4ba7784b.diff

LOG: Fix comment for CLANG_SYSTEMZ_DEFAULT_ARCH

Also move up, next to the other *_DEFAULT_* configurations.

Added: 


Modified: 
clang/include/clang/Config/config.h.cmake

Removed: 




diff  --git a/clang/include/clang/Config/config.h.cmake 
b/clang/include/clang/Config/config.h.cmake
index a0f8b6b1b0da..26e9d5c4eb4d 100644
--- a/clang/include/clang/Config/config.h.cmake
+++ b/clang/include/clang/Config/config.h.cmake
@@ -35,6 +35,9 @@
 /* Default architecture for OpenMP offloading to Nvidia GPUs. */
 #define CLANG_OPENMP_NVPTX_DEFAULT_ARCH "${CLANG_OPENMP_NVPTX_DEFAULT_ARCH}"
 
+/* Default architecture for SystemZ. */
+#define CLANG_SYSTEMZ_DEFAULT_ARCH "${CLANG_SYSTEMZ_DEFAULT_ARCH}"
+
 /* Multilib suffix for libdir. */
 #define CLANG_LIBDIR_SUFFIX "${CLANG_LIBDIR_SUFFIX}"
 
@@ -83,7 +86,4 @@
 /* Spawn a new process clang.exe for the CC1 tool invocation, when necessary */
 #cmakedefine01 CLANG_SPAWN_CC1
 
-/* Default  to all compiler invocations for --sysroot=. */
-#define CLANG_SYSTEMZ_DEFAULT_ARCH "${CLANG_SYSTEMZ_DEFAULT_ARCH}"
-
 #endif



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


r343617 - [OpenMP] Simplify code for reductions on distribute directives, NFC.

2018-10-02 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Tue Oct  2 12:12:47 2018
New Revision: 343617

URL: http://llvm.org/viewvc/llvm-project?rev=343617=rev
Log:
[OpenMP] Simplify code for reductions on distribute directives, NFC.

Only need to care about the 'distribute simd' case, all other composite
directives are handled elsewhere. This was already reflected in the
outer 'if' condition, so all other inner conditions could never be true.

Differential Revision: https://reviews.llvm.org/D52731

Modified:
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=343617=343616=343617=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Tue Oct  2 12:12:47 2018
@@ -3400,20 +3400,7 @@ void CodeGenFunction::EmitOMPDistributeL
   if (isOpenMPSimdDirective(S.getDirectiveKind()) &&
   !isOpenMPParallelDirective(S.getDirectiveKind()) &&
   !isOpenMPTeamsDirective(S.getDirectiveKind())) {
-OpenMPDirectiveKind ReductionKind = OMPD_unknown;
-if (isOpenMPParallelDirective(S.getDirectiveKind()) &&
-isOpenMPSimdDirective(S.getDirectiveKind())) {
-  ReductionKind = OMPD_parallel_for_simd;
-} else if (isOpenMPParallelDirective(S.getDirectiveKind())) {
-  ReductionKind = OMPD_parallel_for;
-} else if (isOpenMPSimdDirective(S.getDirectiveKind())) {
-  ReductionKind = OMPD_simd;
-} else if (!isOpenMPTeamsDirective(S.getDirectiveKind()) &&
-   S.hasClausesOfKind()) {
-  llvm_unreachable(
-  "No reduction clauses is allowed in distribute directive.");
-}
-EmitOMPReductionClauseFinal(S, ReductionKind);
+EmitOMPReductionClauseFinal(S, OMPD_simd);
 // Emit post-update of the reduction variables if IsLastIter != 0.
 emitPostUpdateForReductionClause(
 *this, S, [IL, ](CodeGenFunction ) {


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


r343618 - [OpenMP][NVPTX] Simplify codegen for orphaned parallel, NFCI.

2018-10-02 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Tue Oct  2 12:12:54 2018
New Revision: 343618

URL: http://llvm.org/viewvc/llvm-project?rev=343618=rev
Log:
[OpenMP][NVPTX] Simplify codegen for orphaned parallel, NFCI.

Worker threads fork off to the compiler generated worker function
directly after entering the kernel function. Hence, there is no
need to check whether the current thread is the master if we are
outside of a parallel region (neither SPMD nor parallel_level > 0).

Differential Revision: https://reviews.llvm.org/D52732

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=343618=343617=343618=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Tue Oct  2 12:12:54 2018
@@ -2233,30 +2233,24 @@ void CGOpenMPRuntimeNVPTX::emitNonSPMDPa
 Work.emplace_back(WFn);
   };
 
-  auto & = [this, Loc, , , ,
-  ](CodeGenFunction ,
- PrePostActionTy ) {
-RegionCodeGenTy RCG(CodeGen);
+  auto & = [this, Loc, , ](
+ CodeGenFunction , PrePostActionTy ) {
 if (IsInParallelRegion) {
   SeqGen(CGF, Action);
 } else if (IsInTargetMasterThreadRegion) {
   L0ParallelGen(CGF, Action);
-} else if (getExecutionMode() == CGOpenMPRuntimeNVPTX::EM_NonSPMD) {
-  RCG(CGF);
 } else {
   // Check for master and then parallelism:
   // if (__kmpc_is_spmd_exec_mode() || __kmpc_parallel_level(loc, gtid)) {
-  //  Serialized execution.
-  // } else if (master) {
-  //   Worker call.
+  //   Serialized execution.
   // } else {
-  //   Outlined function call.
+  //   Worker call.
   // }
   CGBuilderTy  = CGF.Builder;
   llvm::BasicBlock *ExitBB = CGF.createBasicBlock(".exit");
   llvm::BasicBlock *SeqBB = CGF.createBasicBlock(".sequential");
   llvm::BasicBlock *ParallelCheckBB = CGF.createBasicBlock(".parcheck");
-  llvm::BasicBlock *MasterCheckBB = CGF.createBasicBlock(".mastercheck");
+  llvm::BasicBlock *MasterBB = CGF.createBasicBlock(".master");
   llvm::Value *IsSPMD = Bld.CreateIsNotNull(CGF.EmitNounwindRuntimeCall(
   createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_is_spmd_exec_mode)));
   Bld.CreateCondBr(IsSPMD, SeqBB, ParallelCheckBB);
@@ -2269,29 +2263,17 @@ void CGOpenMPRuntimeNVPTX::emitNonSPMDPa
   createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_parallel_level),
   {RTLoc, ThreadID});
   llvm::Value *Res = Bld.CreateIsNotNull(PL);
-  Bld.CreateCondBr(Res, SeqBB, MasterCheckBB);
+  Bld.CreateCondBr(Res, SeqBB, MasterBB);
   CGF.EmitBlock(SeqBB);
   SeqGen(CGF, Action);
   CGF.EmitBranch(ExitBB);
   // There is no need to emit line number for unconditional branch.
   (void)ApplyDebugLocation::CreateEmpty(CGF);
-  CGF.EmitBlock(MasterCheckBB);
-  llvm::BasicBlock *MasterThenBB = CGF.createBasicBlock("master.then");
-  llvm::BasicBlock *ElseBlock = CGF.createBasicBlock("omp_if.else");
-  llvm::Value *IsMaster =
-  Bld.CreateICmpEQ(getNVPTXThreadID(CGF), getMasterThreadID(CGF));
-  Bld.CreateCondBr(IsMaster, MasterThenBB, ElseBlock);
-  CGF.EmitBlock(MasterThenBB);
+  CGF.EmitBlock(MasterBB);
   L0ParallelGen(CGF, Action);
   CGF.EmitBranch(ExitBB);
   // There is no need to emit line number for unconditional branch.
   (void)ApplyDebugLocation::CreateEmpty(CGF);
-  CGF.EmitBlock(ElseBlock);
-  // In the worker need to use the real thread id.
-  ThreadIDAddr = emitThreadIDAddress(CGF, Loc);
-  RCG(CGF);
-  // There is no need to emit line number for unconditional branch.
-  (void)ApplyDebugLocation::CreateEmpty(CGF);
   // Emit the continuation block for code after the if.
   CGF.EmitBlock(ExitBB, /*IsFinished=*/true);
 }

Modified: cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp?rev=343618=343617=343618=diff
==
--- cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_target_codegen.cpp Tue Oct  2 12:12:54 2018
@@ -557,7 +557,6 @@ int baz(int f, double ) {
   // CHECK: [[STACK:%.+]] = alloca [[GLOBAL_ST:%.+]],
   // CHECK: [[ZERO_ADDR:%.+]] = alloca i32,
   // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t*
-  // CHECK: [[GTID_ADDR:%.+]] = alloca i32,
   // CHECK: store i32 0, i32* [[ZERO_ADDR]]
   // CHECK: [[RES:%.+]] = call i8 @__kmpc_is_spmd_exec_mode()
   // CHECK: [[IS_SPMD:%.+]] = icmp ne i8 [[RES]], 0
@@ -583,9 +582,6 @@ int baz(int 

Re: r343492 - [OPENMP][NVPTX] Handle `requires datasharing` flag correctly with

2018-10-01 Thread Jonas Hahnfeld via cfe-commits
Does this fix an issue or is it just 'this looks incorrect'? 
__kmpc_data_sharing_push_stack has an extra case if the runtime is 
uninitialized, so AFAICS the initialization in __kmpc_spmd_kernel_init 
should not be needed.


If the runtime needs to be initialized Clang emits a call to 
__kmpc_data_sharing_init_stack_spmd which should setup the data 
structures.


Jonas

On 2018-10-01 18:20, Alexey Bataev via cfe-commits wrote:

Author: abataev
Date: Mon Oct  1 09:20:57 2018
New Revision: 343492

URL: http://llvm.org/viewvc/llvm-project?rev=343492=rev
Log:
[OPENMP][NVPTX] Handle `requires datasharing` flag correctly with
lightweight runtime.

The datasharing flag must be set to `1` when executing SPMD-mode
compatible directive with reduction|lastprivate clauses.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/test/OpenMP/nvptx_SPMD_codegen.cpp

cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp


cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=343492=343491=343492=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Mon Oct  1 09:20:57 
2018

@@ -1207,6 +1207,10 @@ void CGOpenMPRuntimeNVPTX::emitSPMDKerne
IsOffloadEntry, CodeGen);
 }

+static void
+getDistributeLastprivateVars(const OMPExecutableDirective ,
+ llvm::SmallVectorImpl 
);

+
 void CGOpenMPRuntimeNVPTX::emitSPMDEntryHeader(
 CodeGenFunction , EntryFunctionState ,
 const OMPExecutableDirective ) {
@@ -1219,11 +1223,33 @@ void CGOpenMPRuntimeNVPTX::emitSPMDEntry
   // Initialize the OMP state in the runtime; called by all active 
threads.
   bool RequiresFullRuntime = 
CGM.getLangOpts().OpenMPCUDAForceFullRuntime ||
  
!supportsLightweightRuntime(CGF.getContext(), D);
+  // Check if we have inner distribute + lastprivate|reduction 
clauses.

+  bool RequiresDatasharing = RequiresFullRuntime;
+  if (!RequiresDatasharing) {
+const OMPExecutableDirective *TD = 
+if (!isOpenMPTeamsDirective(TD->getDirectiveKind()) &&
+!isOpenMPParallelDirective(TD->getDirectiveKind())) {
+  const Stmt *S = getSingleCompoundChild(
+  
TD->getInnermostCapturedStmt()->getCapturedStmt()->IgnoreContainers(

+  /*IgnoreCaptured=*/true));
+  TD = cast(S);
+}
+if (!isOpenMPDistributeDirective(TD->getDirectiveKind()) &&
+!isOpenMPParallelDirective(TD->getDirectiveKind())) {
+  const Stmt *S = getSingleCompoundChild(
+  
TD->getInnermostCapturedStmt()->getCapturedStmt()->IgnoreContainers(

+  /*IgnoreCaptured=*/true));
+  TD = cast(S);
+}
+if (isOpenMPDistributeDirective(TD->getDirectiveKind()))
+  RequiresDatasharing = 
TD->hasClausesOfKind() ||
+
TD->hasClausesOfKind();

+  }
   llvm::Value *Args[] = {
   getThreadLimit(CGF, /*IsInSPMDExecutionMode=*/true),
   /*RequiresOMPRuntime=*/
   Bld.getInt16(RequiresFullRuntime ? 1 : 0),
-  /*RequiresDataSharing=*/Bld.getInt16(RequiresFullRuntime ? 1 : 
0)};
+  /*RequiresDataSharing=*/Bld.getInt16(RequiresDatasharing ? 1 : 
0)};

   CGF.EmitRuntimeCall(
   createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_spmd_kernel_init), 
Args);



Modified: cfe/trunk/test/OpenMP/nvptx_SPMD_codegen.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_SPMD_codegen.cpp?rev=343492=343491=343492=diff
==
--- cfe/trunk/test/OpenMP/nvptx_SPMD_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/nvptx_SPMD_codegen.cpp Mon Oct  1 09:20:57 
2018

@@ -40,7 +40,7 @@ void foo() {
   for (int i = 0; i < 10; ++i)
 ;
 int a;
-// CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 0, i16 0)
+// CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 0, i16 1)
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 0, i16 0)
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 0, i16 0)
 // CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 1, i16 
{{.+}})


Modified:
cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp?rev=343492=343491=343492=diff
==
---
cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
(original)
+++
cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
Mon Oct  1 09:20:57 2018
@@ -69,7 +69,7 @@ int bar(int n){

 // CHECK-LABEL: define 

r343240 - Fix greedy FileCheck expression in test/Driver/mips-abi.c

2018-09-27 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Thu Sep 27 10:27:48 2018
New Revision: 343240

URL: http://llvm.org/viewvc/llvm-project?rev=343240=rev
Log:
Fix greedy FileCheck expression in test/Driver/mips-abi.c

'ld{{.*}}"' seems to match the complete line for me which is failing
the test. Only allow an optional '.exe' for Windows systems as most
other tests do.
Another possibility would be to collapse the greedy expression with
the next check to avoid matching the full line.

Differential Revision: https://reviews.llvm.org/D52619

Modified:
cfe/trunk/test/Driver/mips-abi.c

Modified: cfe/trunk/test/Driver/mips-abi.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/mips-abi.c?rev=343240=343239=343240=diff
==
--- cfe/trunk/test/Driver/mips-abi.c (original)
+++ cfe/trunk/test/Driver/mips-abi.c Thu Sep 27 10:27:48 2018
@@ -169,7 +169,7 @@
 // TARGET-O32: "-triple" "mips-unknown-linux-gnu"
 // TARGET-O32: "-target-cpu" "mips32r2"
 // TARGET-O32: "-target-abi" "o32"
-// TARGET-O32: ld{{.*}}"
+// TARGET-O32: ld{{(.exe)?}}"
 // TARGET-O32: "-m" "elf32btsmip"
 
 // RUN: %clang -target mips-linux-gnu -mabi=n32 -### %s 2>&1 \
@@ -177,7 +177,7 @@
 // TARGET-N32: "-triple" "mips64-unknown-linux-gnu"
 // TARGET-N32: "-target-cpu" "mips64r2"
 // TARGET-N32: "-target-abi" "n32"
-// TARGET-N32: ld{{.*}}"
+// TARGET-N32: ld{{(.exe)?}}"
 // TARGET-N32: "-m" "elf32btsmipn32"
 
 // RUN: %clang -target mips-linux-gnu -mabi=64 -### %s 2>&1 \
@@ -185,5 +185,5 @@
 // TARGET-N64: "-triple" "mips64-unknown-linux-gnu"
 // TARGET-N64: "-target-cpu" "mips64r2"
 // TARGET-N64: "-target-abi" "n64"
-// TARGET-N64: ld{{.*}}"
+// TARGET-N64: ld{{(.exe)?}}"
 // TARGET-N64: "-m" "elf64btsmip"


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


r343230 - [OpenMP] Improve search for libomptarget-nvptx

2018-09-27 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Thu Sep 27 09:12:32 2018
New Revision: 343230

URL: http://llvm.org/viewvc/llvm-project?rev=343230=rev
Log:
[OpenMP] Improve search for libomptarget-nvptx

When looking for the bclib Clang considered the default library
path first while it preferred directories in LIBRARY_PATH when
constructing the invocation of nvlink. The latter actually makes
more sense because during development it allows using a non-default
runtime library. So change the search for the bclib to start
looking in directories given by LIBRARY_PATH.
Additionally add a new option --libomptarget-nvptx-path= which
will be searched first. This will be handy for testing purposes.

Differential Revision: https://reviews.llvm.org/D51686

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
cfe/trunk/test/Driver/openmp-offload-gpu.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=343230=343229=343230=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Sep 27 09:12:32 2018
@@ -596,6 +596,8 @@ def hip_device_lib_EQ : Joined<["--"], "
   HelpText<"HIP device library">;
 def fhip_dump_offload_linker_script : Flag<["-"], 
"fhip-dump-offload-linker-script">,
   Group, Flags<[NoArgumentUnused, HelpHidden]>;
+def libomptarget_nvptx_path_EQ : Joined<["--"], "libomptarget-nvptx-path=">, 
Group,
+  HelpText<"Path to libomptarget-nvptx libraries">;
 def dA : Flag<["-"], "dA">, Group;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,
   HelpText<"Print macro definitions in -E mode in addition to normal output">;

Modified: cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Cuda.cpp?rev=343230=343229=343230=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Cuda.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Cuda.cpp Thu Sep 27 09:12:32 2018
@@ -511,6 +511,11 @@ void NVPTX::OpenMPLinker::ConstructJob(C
   CmdArgs.push_back("-arch");
   CmdArgs.push_back(Args.MakeArgString(GPUArch));
 
+  // Assume that the directory specified with --libomptarget_nvptx_path
+  // contains the static library libomptarget-nvptx.a.
+  if (const Arg *A = Args.getLastArg(options::OPT_libomptarget_nvptx_path_EQ))
+CmdArgs.push_back(Args.MakeArgString(Twine("-L") + A->getValue()));
+
   // Add paths specified in LIBRARY_PATH environment variable as -L options.
   addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
 
@@ -647,12 +652,9 @@ void CudaToolChain::addClangTargetOption
 
   if (DeviceOffloadingKind == Action::OFK_OpenMP) {
 SmallVector LibraryPaths;
-// Add path to lib and/or lib64 folders.
-SmallString<256> DefaultLibPath =
-  llvm::sys::path::parent_path(getDriver().Dir);
-llvm::sys::path::append(DefaultLibPath,
-Twine("lib") + CLANG_LIBDIR_SUFFIX);
-LibraryPaths.emplace_back(DefaultLibPath.c_str());
+
+if (const Arg *A = 
DriverArgs.getLastArg(options::OPT_libomptarget_nvptx_path_EQ))
+  LibraryPaths.push_back(A->getValue());
 
 // Add user defined library paths from LIBRARY_PATH.
 llvm::Optional LibPath =
@@ -665,6 +667,12 @@ void CudaToolChain::addClangTargetOption
 LibraryPaths.emplace_back(Path.trim());
 }
 
+// Add path to lib / lib64 folder.
+SmallString<256> DefaultLibPath =
+llvm::sys::path::parent_path(getDriver().Dir);
+llvm::sys::path::append(DefaultLibPath, Twine("lib") + 
CLANG_LIBDIR_SUFFIX);
+LibraryPaths.emplace_back(DefaultLibPath.c_str());
+
 std::string LibOmpTargetName =
   "libomptarget-nvptx-" + GpuArch.str() + ".bc";
 bool FoundBCLibrary = false;

Modified: cfe/trunk/test/Driver/openmp-offload-gpu.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openmp-offload-gpu.c?rev=343230=343229=343230=diff
==
--- cfe/trunk/test/Driver/openmp-offload-gpu.c (original)
+++ cfe/trunk/test/Driver/openmp-offload-gpu.c Thu Sep 27 09:12:32 2018
@@ -30,6 +30,22 @@
 
 /// ###
 
+/// Check that -lomptarget-nvptx is passed to nvlink.
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp \
+// RUN:  -fopenmp-targets=nvptx64-nvidia-cuda %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-NVLINK %s
+/// Check that the value of --libomptarget-nvptx-path is forwarded to nvlink.
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp \
+// RUN:  --libomptarget-nvptx-path=/path/to/libomptarget/ \
+// RUN:  -fopenmp-targets=nvptx64-nvidia-cuda %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=CHK-NVLINK,CHK-LIBOMPTARGET-NVPTX-PATH %s
+
+// 

  1   2   3   >