[PATCH] D99565: [X86] Support replacing aligned vector moves with unaligned moves when avx is enabled.

2021-04-13 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 updated this revision to Diff 337057.
LiuChen3 added a comment.

1. Rebase;
2. Emit unaligned move in ISEL;
3. Only do the conversion on AVX machine.

I am still working on fast-isel.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99565/new/

https://reviews.llvm.org/D99565

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/test/Driver/x86-unaligned-vector-move.c
  llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
  llvm/lib/Target/X86/X86InstrFragmentsSIMD.td
  llvm/test/CodeGen/X86/avx-unaligned-load-store.ll
  llvm/test/CodeGen/X86/avx512-unaligned-load-store.ll
  llvm/test/CodeGen/X86/avx512vl-unaligned-load-store.ll

Index: llvm/test/CodeGen/X86/avx512vl-unaligned-load-store.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/avx512vl-unaligned-load-store.ll
@@ -0,0 +1,747 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=avx512f -mattr=avx512vl -x86-enable-unaligned-vector-move | FileCheck %s -check-prefix=X64
+; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=avx512f -mattr=avx512vl -x86-enable-unaligned-vector-move | FileCheck %s -check-prefix=X86
+
+define <8 x i32> @test_256_1(i8 * %addr) {
+; CHECK-LABEL: test_256_1:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vmovups (%rdi), %ymm0
+; CHECK-NEXT:retq
+; X64-LABEL: test_256_1:
+; X64:   # %bb.0:
+; X64-NEXT:vmovups (%rdi), %ymm0
+; X64-NEXT:retq
+;
+; X86-LABEL: test_256_1:
+; X86:   # %bb.0:
+; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:vmovups (%eax), %ymm0
+; X86-NEXT:retl
+  %vaddr = bitcast i8* %addr to <8 x i32>*
+  %res = load <8 x i32>, <8 x i32>* %vaddr, align 1
+  ret <8 x i32>%res
+}
+
+define <8 x i32> @test_256_2(i8 * %addr) {
+; CHECK-LABEL: test_256_2:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vmovups (%rdi), %ymm0
+; CHECK-NEXT:retq
+; X64-LABEL: test_256_2:
+; X64:   # %bb.0:
+; X64-NEXT:vmovups (%rdi), %ymm0
+; X64-NEXT:retq
+;
+; X86-LABEL: test_256_2:
+; X86:   # %bb.0:
+; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:vmovups (%eax), %ymm0
+; X86-NEXT:retl
+  %vaddr = bitcast i8* %addr to <8 x i32>*
+  %res = load <8 x i32>, <8 x i32>* %vaddr, align 32
+  ret <8 x i32>%res
+}
+
+define void @test_256_3(i8 * %addr, <4 x i64> %data) {
+; CHECK-LABEL: test_256_3:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vmovups %ymm0, (%rdi)
+; CHECK-NEXT:vzeroupper
+; CHECK-NEXT:retq
+; X64-LABEL: test_256_3:
+; X64:   # %bb.0:
+; X64-NEXT:vmovups %ymm0, (%rdi)
+; X64-NEXT:vzeroupper
+; X64-NEXT:retq
+;
+; X86-LABEL: test_256_3:
+; X86:   # %bb.0:
+; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:vmovups %ymm0, (%eax)
+; X86-NEXT:vzeroupper
+; X86-NEXT:retl
+  %vaddr = bitcast i8* %addr to <4 x i64>*
+  store <4 x i64>%data, <4 x i64>* %vaddr, align 32
+  ret void
+}
+
+define void @test_256_4(i8 * %addr, <8 x i32> %data) {
+; CHECK-LABEL: test_256_4:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vmovups %ymm0, (%rdi)
+; CHECK-NEXT:vzeroupper
+; CHECK-NEXT:retq
+; X64-LABEL: test_256_4:
+; X64:   # %bb.0:
+; X64-NEXT:vmovups %ymm0, (%rdi)
+; X64-NEXT:vzeroupper
+; X64-NEXT:retq
+;
+; X86-LABEL: test_256_4:
+; X86:   # %bb.0:
+; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:vmovups %ymm0, (%eax)
+; X86-NEXT:vzeroupper
+; X86-NEXT:retl
+  %vaddr = bitcast i8* %addr to <8 x i32>*
+  store <8 x i32>%data, <8 x i32>* %vaddr, align 1
+  ret void
+}
+
+define void @test_256_5(i8 * %addr, <8 x i32> %data) {
+; CHECK-LABEL: test_256_5:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vmovups %ymm0, (%rdi)
+; CHECK-NEXT:vzeroupper
+; CHECK-NEXT:retq
+; X64-LABEL: test_256_5:
+; X64:   # %bb.0:
+; X64-NEXT:vmovups %ymm0, (%rdi)
+; X64-NEXT:vzeroupper
+; X64-NEXT:retq
+;
+; X86-LABEL: test_256_5:
+; X86:   # %bb.0:
+; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:vmovups %ymm0, (%eax)
+; X86-NEXT:vzeroupper
+; X86-NEXT:retl
+  %vaddr = bitcast i8* %addr to <8 x i32>*
+  store <8 x i32>%data, <8 x i32>* %vaddr, align 32
+  ret void
+}
+
+define  <4 x i64> @test_256_6(i8 * %addr) {
+; CHECK-LABEL: test_256_6:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vmovups (%rdi), %ymm0
+; CHECK-NEXT:retq
+; X64-LABEL: test_256_6:
+; X64:   # %bb.0:
+; X64-NEXT:vmovups (%rdi), %ymm0
+; X64-NEXT:retq
+;
+; X86-LABEL: test_256_6:
+; X86:   # %bb.0:
+; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:vmovups (%eax), %ymm0
+; X86-NEXT:retl
+  %vaddr = bitcast i8* %addr to <4 x i64>*
+  %res = load <4 x i64>, <4 x i64>* %vaddr, align 32
+  ret <4 x i64>%res
+}
+
+define void @test_256_7(i8 * %addr, <4 x i64> %data) {
+; 

[PATCH] D99565: [X86] Support replacing aligned vector moves with unaligned moves when avx is enabled.

2021-04-13 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 added a comment.

In D99565#2682809 , @lebedev.ri wrote:

> I'm still uncomfortable with changing current status quo, even though i 
> obviously don't get to cast the final vote here.
>
> One should not use aligned loads in hope that they will cause an exception to 
> detect address misalignment.
> That's UBSan's job. `-fsanitize=undefined`/`-fsanitize=aligment` *should* 
> catch it.
> If it does not do so in your particular case, please file a bug, i would like 
> to take a look.
>
> Likewise, i don't think one should do overaligned loads and hope that they 
> will just work.
> UB is UB. The code will still be miscompiled, but you've just hidden your 
> warning.
>
> Likewise, even if unaligned loads can be always used, i would personally find 
> it pretty surprising
> to suddenly see unaliged loads instead of aligned ones.
> Also, isn't that only possible/so when AVX is available?
> Also, doesn't that cause compiler lock-in?
> What happens without AVX? Do so anyways at the perfomance's cost?
> Or back to exceptions?
>
> Should this process in any form other than the UBSan changes,
> i would like to first see a RFC on llvm-dev.
> Sorry about being uneasy about this. :S

We are happy to hear your voice. We will discuss this on llvm-dev later after 
confirming Craigs's opinion.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99565/new/

https://reviews.llvm.org/D99565

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


[PATCH] D99565: [X86] Support replacing aligned vector moves with unaligned moves when avx is enabled.

2021-04-13 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 added a comment.

In D99565#2678073 , @craig.topper 
wrote:

> I think I wouldn't mind if we just didn't emit aligned loads/store 
> instructions for AVX/AVX512 from isel and other places in the compiler in the 
> first place. As noted, if the load gets folded the alignment check doesn't 
> happen. That would reduce the size of the isel tables and remove branches, 
> reducing complexity of the compiler. Adding a new step and a command line to 
> undo the earlier decision increases complexity.
>
> The counter argument to that is that the alignment check has found bugs in 
> the vectorizer on more than one occasion that I know of.

Hi, @craig.topper. I'm not sure if I understand what you mean correctly. Do you 
mean we can remove the alignload/alignstore pattern match so that we can reduce 
the size of the isel tables? But this means that there is no option to control 
this behavior.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99565/new/

https://reviews.llvm.org/D99565

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


[PATCH] D99565: [X86] Support replacing aligned vector moves with unaligned moves when avx is enabled.

2021-04-13 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1649
+Group,  Flags<[CoreOption, HelpHidden]>,
+HelpText<"Do not emit unaligned move instructions unless users explicitly 
uses.">;
 def fassociative_math : Flag<["-"], "fassociative-math">, Group;

This makes it sound like unaligned moves would never be used even if it 
unaligned.



Comment at: llvm/lib/Target/X86/X86InstrFragmentsSIMD.td:834
+  if (EnableX86UnalignedVecMove)
+return !Subtarget->hasAVX();
   auto *St = cast(N);

Won’t this make this return true for any load when only SSE is enabled. So SSE 
will use an aligned load instruction for an unaligned address.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99565/new/

https://reviews.llvm.org/D99565

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


[clang] 95c614a - [NFC][SYCL] Drop idle triple component from regression tests.

2021-04-13 Thread Alexey Bader via cfe-commits

Author: Alexey Bader
Date: 2021-04-13T08:00:21+03:00
New Revision: 95c614afcd4de71d00a240d6a4a02c036c972ed0

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

LOG: [NFC][SYCL] Drop idle triple component from regression tests.

Added: 


Modified: 
clang/test/CodeGenSYCL/convergent.cpp
clang/test/CodeGenSYCL/filescope_asm.c

Removed: 




diff  --git a/clang/test/CodeGenSYCL/convergent.cpp 
b/clang/test/CodeGenSYCL/convergent.cpp
index 58be1b153c937..779f1592da0e0 100644
--- a/clang/test/CodeGenSYCL/convergent.cpp
+++ b/clang/test/CodeGenSYCL/convergent.cpp
@@ -1,6 +1,5 @@
 // RUN: %clang_cc1 -fsycl-is-device -emit-llvm -disable-llvm-passes \
-// RUN:  -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | \
-// RUN:   FileCheck %s
+// RUN:  -triple spir64 -emit-llvm %s -o - | FileCheck %s
 
 // CHECK-DAG: Function Attrs:
 // CHECK-DAG-SAME: convergent

diff  --git a/clang/test/CodeGenSYCL/filescope_asm.c 
b/clang/test/CodeGenSYCL/filescope_asm.c
index 3c1c12fd589a6..9c0d088ec0a2d 100644
--- a/clang/test/CodeGenSYCL/filescope_asm.c
+++ b/clang/test/CodeGenSYCL/filescope_asm.c
@@ -1,4 +1,4 @@
-// RUN:  %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice 
-emit-llvm %s -o - | FileCheck %s
+// RUN:  %clang_cc1 -fsycl-is-device -triple spir64 -emit-llvm %s -o - | 
FileCheck %s
 //
 // Check that file-scope asm is ignored during device-side SYCL compilation.
 //



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


[PATCH] D100161: Redistribute energy for Corpus

2021-04-13 Thread taotao gu via Phabricator via cfe-commits
gtt1995 added a comment.

If not sorted by size ,  Just a simple grouping of corpus, the effect is 
similar to entropic.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100161/new/

https://reviews.llvm.org/D100161

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


[PATCH] D99565: [X86] Support replacing aligned vector moves with unaligned moves when avx is enabled.

2021-04-13 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 updated this revision to Diff 337064.
LiuChen3 added a comment.

Address Craig's comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99565/new/

https://reviews.llvm.org/D99565

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/test/Driver/x86-unaligned-vector-move.c
  llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
  llvm/lib/Target/X86/X86InstrFragmentsSIMD.td
  llvm/test/CodeGen/X86/avx-unaligned-load-store.ll
  llvm/test/CodeGen/X86/avx512-unaligned-load-store.ll
  llvm/test/CodeGen/X86/avx512vl-unaligned-load-store.ll

Index: llvm/test/CodeGen/X86/avx512vl-unaligned-load-store.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/avx512vl-unaligned-load-store.ll
@@ -0,0 +1,747 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=avx512f -mattr=avx512vl -x86-enable-unaligned-vector-move | FileCheck %s -check-prefix=X64
+; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=avx512f -mattr=avx512vl -x86-enable-unaligned-vector-move | FileCheck %s -check-prefix=X86
+
+define <8 x i32> @test_256_1(i8 * %addr) {
+; CHECK-LABEL: test_256_1:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vmovups (%rdi), %ymm0
+; CHECK-NEXT:retq
+; X64-LABEL: test_256_1:
+; X64:   # %bb.0:
+; X64-NEXT:vmovups (%rdi), %ymm0
+; X64-NEXT:retq
+;
+; X86-LABEL: test_256_1:
+; X86:   # %bb.0:
+; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:vmovups (%eax), %ymm0
+; X86-NEXT:retl
+  %vaddr = bitcast i8* %addr to <8 x i32>*
+  %res = load <8 x i32>, <8 x i32>* %vaddr, align 1
+  ret <8 x i32>%res
+}
+
+define <8 x i32> @test_256_2(i8 * %addr) {
+; CHECK-LABEL: test_256_2:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vmovups (%rdi), %ymm0
+; CHECK-NEXT:retq
+; X64-LABEL: test_256_2:
+; X64:   # %bb.0:
+; X64-NEXT:vmovups (%rdi), %ymm0
+; X64-NEXT:retq
+;
+; X86-LABEL: test_256_2:
+; X86:   # %bb.0:
+; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:vmovups (%eax), %ymm0
+; X86-NEXT:retl
+  %vaddr = bitcast i8* %addr to <8 x i32>*
+  %res = load <8 x i32>, <8 x i32>* %vaddr, align 32
+  ret <8 x i32>%res
+}
+
+define void @test_256_3(i8 * %addr, <4 x i64> %data) {
+; CHECK-LABEL: test_256_3:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vmovups %ymm0, (%rdi)
+; CHECK-NEXT:vzeroupper
+; CHECK-NEXT:retq
+; X64-LABEL: test_256_3:
+; X64:   # %bb.0:
+; X64-NEXT:vmovups %ymm0, (%rdi)
+; X64-NEXT:vzeroupper
+; X64-NEXT:retq
+;
+; X86-LABEL: test_256_3:
+; X86:   # %bb.0:
+; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:vmovups %ymm0, (%eax)
+; X86-NEXT:vzeroupper
+; X86-NEXT:retl
+  %vaddr = bitcast i8* %addr to <4 x i64>*
+  store <4 x i64>%data, <4 x i64>* %vaddr, align 32
+  ret void
+}
+
+define void @test_256_4(i8 * %addr, <8 x i32> %data) {
+; CHECK-LABEL: test_256_4:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vmovups %ymm0, (%rdi)
+; CHECK-NEXT:vzeroupper
+; CHECK-NEXT:retq
+; X64-LABEL: test_256_4:
+; X64:   # %bb.0:
+; X64-NEXT:vmovups %ymm0, (%rdi)
+; X64-NEXT:vzeroupper
+; X64-NEXT:retq
+;
+; X86-LABEL: test_256_4:
+; X86:   # %bb.0:
+; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:vmovups %ymm0, (%eax)
+; X86-NEXT:vzeroupper
+; X86-NEXT:retl
+  %vaddr = bitcast i8* %addr to <8 x i32>*
+  store <8 x i32>%data, <8 x i32>* %vaddr, align 1
+  ret void
+}
+
+define void @test_256_5(i8 * %addr, <8 x i32> %data) {
+; CHECK-LABEL: test_256_5:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vmovups %ymm0, (%rdi)
+; CHECK-NEXT:vzeroupper
+; CHECK-NEXT:retq
+; X64-LABEL: test_256_5:
+; X64:   # %bb.0:
+; X64-NEXT:vmovups %ymm0, (%rdi)
+; X64-NEXT:vzeroupper
+; X64-NEXT:retq
+;
+; X86-LABEL: test_256_5:
+; X86:   # %bb.0:
+; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:vmovups %ymm0, (%eax)
+; X86-NEXT:vzeroupper
+; X86-NEXT:retl
+  %vaddr = bitcast i8* %addr to <8 x i32>*
+  store <8 x i32>%data, <8 x i32>* %vaddr, align 32
+  ret void
+}
+
+define  <4 x i64> @test_256_6(i8 * %addr) {
+; CHECK-LABEL: test_256_6:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vmovups (%rdi), %ymm0
+; CHECK-NEXT:retq
+; X64-LABEL: test_256_6:
+; X64:   # %bb.0:
+; X64-NEXT:vmovups (%rdi), %ymm0
+; X64-NEXT:retq
+;
+; X86-LABEL: test_256_6:
+; X86:   # %bb.0:
+; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:vmovups (%eax), %ymm0
+; X86-NEXT:retl
+  %vaddr = bitcast i8* %addr to <4 x i64>*
+  %res = load <4 x i64>, <4 x i64>* %vaddr, align 32
+  ret <4 x i64>%res
+}
+
+define void @test_256_7(i8 * %addr, <4 x i64> %data) {
+; CHECK-LABEL: test_256_7:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vmovups %ymm0, (%rdi)
+; C

[PATCH] D100368: [X86] Support some missing intrinsics

2021-04-13 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 created this revision.
Herald added a subscriber: pengfei.
LiuChen3 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Support for _mm512_i32logather_pd, _mm512_mask_i32logather_pd,
_mm512_i32logather_epi64, _mm512_mask_i32logather_epi64, _mm512_i32loscatter_pd,
_mm512_mask_i32loscatter_pd.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100368

Files:
  clang/lib/Headers/avx512fintrin.h
  clang/test/CodeGen/X86/avx512f-builtins.c

Index: clang/test/CodeGen/X86/avx512f-builtins.c
===
--- clang/test/CodeGen/X86/avx512f-builtins.c
+++ clang/test/CodeGen/X86/avx512f-builtins.c
@@ -10819,3 +10819,39 @@
   // CHECK: shufflevector <4 x i64> %{{.*}}, <4 x i64> %{{.*}}, <8 x i32> 
   return _mm512_zextsi256_si512(A);
 }
+
+__m512d test_mm512_i32logather_pd(__m512i __index, void const *__addr) {
+  // CHECK-LABEL: @test_mm512_i32logather_pd
+  // CHECK: @llvm.x86.avx512.mask.gather.dpd.512
+  return _mm512_i32logather_pd(__index, __addr, 2);
+}
+
+__m512d test_mm512_mask_i32logather_pd(__m512d __v1_old, __mmask8 __mask, __m512i __index, void const *__addr) {
+  // CHECK-LABEL: @test_mm512_mask_i32logather_pd
+  // CHECK: @llvm.x86.avx512.mask.gather.dpd.512
+  return _mm512_mask_i32logather_pd(__v1_old, __mask, __index, __addr, 2);
+}
+
+void test_mm512_i32loscatter_pd(void *__addr, __m512i __index, __m512d __v1) {
+  // CHECK-LABEL: @test_mm512_i32loscatter_pd
+  // CHECK: @llvm.x86.avx512.mask.scatter.dpd.512
+  return _mm512_i32loscatter_pd(__addr, __index, __v1, 2);
+}
+
+void test_mm512_mask_i32loscatter_pd(void *__addr, __mmask8 __mask, __m512i __index, __m512d __v1) {
+  // CHECK-LABEL: @test_mm512_mask_i32loscatter_pd
+  // CHECK: @llvm.x86.avx512.mask.scatter.dpd.512
+  return _mm512_mask_i32loscatter_pd(__addr, __mask, __index, __v1, 2);
+}
+
+__m512i test_mm512_i32logather_epi64(__m512i __index, void const *__addr) {
+  // CHECK-LABEL: @test_mm512_i32logather_epi64
+  // CHECK: @llvm.x86.avx512.mask.gather.dpq.512
+  return _mm512_i32logather_epi64(__index, __addr, 2);
+}
+
+__m512i test_mm512_mask_i32logather_epi64(__m512i __v1_old, __mmask8 __mask, __m512i __index, void const *__addr) {
+  // CHECK-LABEL: @test_mm512_mask_i32logather_epi64
+  // CHECK: @llvm.x86.avx512.mask.gather.dpq.512
+  return _mm512_mask_i32logather_epi64(__v1_old, __mask, __index, __addr, 2);
+}
Index: clang/lib/Headers/avx512fintrin.h
===
--- clang/lib/Headers/avx512fintrin.h
+++ clang/lib/Headers/avx512fintrin.h
@@ -9588,6 +9588,129 @@
   return __b[0];
 }
 
+/// Loads 8 double-precision (64-bit) floating-point elements stored at memory
+/// locations starting at location \a base_addr at packed 32-bit integer indices
+/// stored in the lower half of \a vindex scaled by \a scale them in dst.
+///
+/// This intrinsic corresponds to the  VGATHERDPD  instructions.
+///
+/// \operation
+/// FOR j := 0 to 7
+///   i := j*64
+///   m := j*32
+///   addr := base_addr + SignExtend64(vindex[m+31:m]) * ZeroExtend64(scale) * 8
+///   dst[i+63:i] := MEM[addr+63:addr]
+/// ENDFOR
+/// dst[MAX:512] := 0
+/// \endoperation
+#define _mm512_i32logather_pd(vindex, base_addr, scale)\
+  _mm512_i32gather_pd(_mm512_castsi512_si256(vindex), (base_addr), (scale))
+
+/// Loads 8 double-precision (64-bit) floating-point elements from memory
+/// starting at location \a base_addr at packed 32-bit integer indices stored in
+/// the lower half of \a vindex scaled by \a scale into dst using writemask
+/// \a mask (elements are copied from \a src when the corresponding mask bit is
+/// not set).
+///
+/// This intrinsic corresponds to the  VGATHERDPD  instructions.
+///
+/// \operation
+/// FOR j := 0 to 7
+///   i := j*64
+///   m := j*32
+///   IF mask[j]
+/// addr := base_addr + SignExtend64(vindex[m+31:m]) * ZeroExtend64(scale) * 8
+/// dst[i+63:i] := MEM[addr+63:addr]
+///   ELSE
+/// dst[i+63:i] := src[i+63:i]
+///   FI
+/// ENDFOR
+/// dst[MAX:512] := 0
+/// \endoperation
+#define _mm512_mask_i32logather_pd(src, mask, vindex, base_addr, scale)\
+  _mm512_mask_i32gather_pd((src), (mask), _mm512_castsi512_si256(vindex),  \
+   (base_addr), (scale))
+/// Loads 8 64-bit integer elements from memory starting at location \a base_addr
+/// at packed 32-bit integer indices stored in the lower half of \a vindex
+/// scaled by \a scale and stores them in dst.
+///
+/// This intrinsic corresponds to the  VPGATHERDQ  instructions.
+///
+/// \operation
+/// FOR j := 0 to 7
+///   i := j*64
+///   m := j*32
+///   addr := base_addr + SignExtend64(vindex[m+31:m]) * ZeroExtend64(scale) * 8
+///   dst[i+63:i] := MEM[addr+63:addr]
+/// ENDFOR
+/// dst[MAX:512] := 0
+/// \endoperation
+#define _mm512_i32logather_epi64(vindex, base_addr, scale) \
+  _mm512_i32gather_epi64

[PATCH] D100057: Remove warning "suggest braces" for aggregate initialization of an empty class with an aggregate base class.

2021-04-13 Thread Hana Dusíková via Phabricator via cfe-commits
hankadusikova updated this revision to Diff 337067.
hankadusikova marked 3 inline comments as done.
hankadusikova added a comment.

changes suggested by @rsmith


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100057/new/

https://reviews.llvm.org/D100057

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/aggregate-initialization.cpp


Index: clang/test/SemaCXX/aggregate-initialization.cpp
===
--- clang/test/SemaCXX/aggregate-initialization.cpp
+++ clang/test/SemaCXX/aggregate-initialization.cpp
@@ -172,11 +172,20 @@
   };
   ArrayAndBaseClass z = {1, 2, 3}; // expected-warning {{suggest 
braces}}
 
-  // It's not clear whether we should be warning in this case. If this
-  // pattern becomes idiomatic, it would be reasonable to suppress the
-  // warning here too.
+  // This pattern is used for tagged aggregates and must not warn
   template struct JustABaseClass : StdArray {};
-  JustABaseClass w = {1, 2, 3}; // expected-warning {{suggest braces}}
+  JustABaseClass w = {1, 2, 3};
+  // but this should be also ok
+  JustABaseClass v = {{1, 2, 3}};
+
+  template  struct OnionBaseClass : JustABaseClass {};
+  OnionBaseClass u = {1, 2, 3};
+  OnionBaseClass t = {{{1, 2, 3}}};
+
+  struct EmptyBase {};
+
+  template  struct AggregateAndEmpty : StdArray, 
EmptyBase {};
+  AggregateAndEmpty p = {1, 2, 3}; // expected-warning {{suggest 
braces}}
 #endif
 
 #pragma clang diagnostic pop
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -1007,21 +1007,33 @@
   //
   // (where std::array is an aggregate struct containing a single array field.
 
-  // FIXME: Should aggregate initialization of a struct with a single
-  // base class and no members also suppress the warning?
-  if (Entity.getKind() != InitializedEntity::EK_Member || !Entity.getParent())
+  if (!Entity.getParent())
 return false;
 
-  auto *ParentRD =
-  Entity.getParent()->getType()->castAs()->getDecl();
-  if (CXXRecordDecl *CXXRD = dyn_cast(ParentRD))
-if (CXXRD->getNumBases())
-  return false;
+  // Allows elide brace initialization for aggregates with empty base.
+  if (Entity.getKind() == InitializedEntity::EK_Base) {
+auto *ParentRD =
+Entity.getParent()->getType()->castAs()->getDecl();
+CXXRecordDecl *CXXRD = cast(ParentRD);
+return CXXRD->getNumBases() == 1 && CXXRD->field_empty();
+  }
+
+  // Allow brace elision if the only subobject is a field.
+  if (Entity.getKind() == InitializedEntity::EK_Member) {
+auto *ParentRD =
+Entity.getParent()->getType()->castAs()->getDecl();
+if (CXXRecordDecl *CXXRD = dyn_cast(ParentRD)) {
+  if (CXXRD->getNumBases()) {
+return false;
+  }
+}
+auto FieldIt = ParentRD->field_begin();
+assert(FieldIt != ParentRD->field_end() &&
+   "no fields but have initializer for member?");
+return ++FieldIt == ParentRD->field_end();
+  }
 
-  auto FieldIt = ParentRD->field_begin();
-  assert(FieldIt != ParentRD->field_end() &&
- "no fields but have initializer for member?");
-  return ++FieldIt == ParentRD->field_end();
+  return false;
 }
 
 /// Check whether the range of the initializer \p ParentIList from element


Index: clang/test/SemaCXX/aggregate-initialization.cpp
===
--- clang/test/SemaCXX/aggregate-initialization.cpp
+++ clang/test/SemaCXX/aggregate-initialization.cpp
@@ -172,11 +172,20 @@
   };
   ArrayAndBaseClass z = {1, 2, 3}; // expected-warning {{suggest braces}}
 
-  // It's not clear whether we should be warning in this case. If this
-  // pattern becomes idiomatic, it would be reasonable to suppress the
-  // warning here too.
+  // This pattern is used for tagged aggregates and must not warn
   template struct JustABaseClass : StdArray {};
-  JustABaseClass w = {1, 2, 3}; // expected-warning {{suggest braces}}
+  JustABaseClass w = {1, 2, 3};
+  // but this should be also ok
+  JustABaseClass v = {{1, 2, 3}};
+
+  template  struct OnionBaseClass : JustABaseClass {};
+  OnionBaseClass u = {1, 2, 3};
+  OnionBaseClass t = {{{1, 2, 3}}};
+
+  struct EmptyBase {};
+
+  template  struct AggregateAndEmpty : StdArray, EmptyBase {};
+  AggregateAndEmpty p = {1, 2, 3}; // expected-warning {{suggest braces}}
 #endif
 
 #pragma clang diagnostic pop
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -1007,21 +1007,33 @@
   //
   // (where std::array is an aggregate struct containing a single array field.
 
-  // FIXME: Should aggregate initialization of a struct with a single
-  // base class and no members also suppress the warning?
-  if (Entity.getKind() != InitializedEntity::EK_Member || !Entity.getPar

[PATCH] D100372: [Clang][ARM] Define __VFP_FP__ macro unconditionally

2021-04-13 Thread Victor Campos via Phabricator via cfe-commits
vhscampos created this revision.
Herald added subscribers: danielkiss, kristof.beyls.
vhscampos requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang only defines __VFP_FP__ when the FPU is enabled. However, gcc
defines it unconditionally.

This patch aligns Clang with gcc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100372

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/test/Preprocessor/arm-target-features.c


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -141,6 +141,11 @@
 // CHECK-V7S-NOT: __ARM_FEATURE_DIRECTED_ROUNDING
 // CHECK-V7S: #define __ARM_FP 0xe
 
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m -mfloat-abi=soft -x c 
-E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-VFP-FP %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m -mfloat-abi=softfp -x 
c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-VFP-FP %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m -mfloat-abi=hard -x c 
-E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-VFP-FP %s
+// CHECK-VFP-FP: #define __VFP_FP__ 1
+
 // RUN: %clang -target armv8a -mfloat-abi=hard -x c -E -dM %s | FileCheck 
-match-full-lines --check-prefix=CHECK-V8-BAREHF %s
 // CHECK-V8-BAREHF: #define __ARMEL__ 1
 // CHECK-V8-BAREHF: #define __ARM_ARCH 8
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -755,8 +755,9 @@
   // Note, this is always on in gcc, even though it doesn't make sense.
   Builder.defineMacro("__APCS_32__");
 
+  Builder.defineMacro("__VFP_FP__");
+
   if (FPUModeIsVFP((FPUMode)FPU)) {
-Builder.defineMacro("__VFP_FP__");
 if (FPU & VFP2FPU)
   Builder.defineMacro("__ARM_VFPV2__");
 if (FPU & VFP3FPU)


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -141,6 +141,11 @@
 // CHECK-V7S-NOT: __ARM_FEATURE_DIRECTED_ROUNDING
 // CHECK-V7S: #define __ARM_FP 0xe
 
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m -mfloat-abi=soft -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-VFP-FP %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m -mfloat-abi=softfp -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-VFP-FP %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m -mfloat-abi=hard -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-VFP-FP %s
+// CHECK-VFP-FP: #define __VFP_FP__ 1
+
 // RUN: %clang -target armv8a -mfloat-abi=hard -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-BAREHF %s
 // CHECK-V8-BAREHF: #define __ARMEL__ 1
 // CHECK-V8-BAREHF: #define __ARM_ARCH 8
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -755,8 +755,9 @@
   // Note, this is always on in gcc, even though it doesn't make sense.
   Builder.defineMacro("__APCS_32__");
 
+  Builder.defineMacro("__VFP_FP__");
+
   if (FPUModeIsVFP((FPUMode)FPU)) {
-Builder.defineMacro("__VFP_FP__");
 if (FPU & VFP2FPU)
   Builder.defineMacro("__ARM_VFPV2__");
 if (FPU & VFP3FPU)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] ecc6965 - Revert "Revert "[clangd] Provide a way to disable external index""

2021-04-13 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-04-13T11:24:32+02:00
New Revision: ecc6965b2342397a215b00e8e476d8d37d080322

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

LOG: Revert "Revert "[clangd] Provide a way to disable external index""

This reverts commit c2ad7c23707cece995ee9070283a72c4afc8c0fe while
adding the handling for the new enum value into the switch statement.

Added: 


Modified: 
clang-tools-extra/clangd/Config.h
clang-tools-extra/clangd/ConfigCompile.cpp
clang-tools-extra/clangd/ConfigFragment.h
clang-tools-extra/clangd/ConfigYAML.cpp
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Config.h 
b/clang-tools-extra/clangd/Config.h
index 7064edd76b8f..fe6f4d7fa6e8 100644
--- a/clang-tools-extra/clangd/Config.h
+++ b/clang-tools-extra/clangd/Config.h
@@ -70,7 +70,7 @@ struct Config {
   enum class BackgroundPolicy { Build, Skip };
   /// Describes an external index configuration.
   struct ExternalIndexSpec {
-enum { File, Server } Kind;
+enum { None, File, Server } Kind;
 /// This is one of:
 /// - Address of a clangd-index-server, in the form of "ip:port".
 /// - Absolute path to an index produced by clangd-indexer.

diff  --git a/clang-tools-extra/clangd/ConfigCompile.cpp 
b/clang-tools-extra/clangd/ConfigCompile.cpp
index 1185eb7255b4..a5745727dca7 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -329,10 +329,11 @@ struct FragmentCompiler {
 }
 #endif
 // Make sure exactly one of the Sources is set.
-unsigned SourceCount =
-External.File.hasValue() + External.Server.hasValue();
+unsigned SourceCount = External.File.hasValue() +
+   External.Server.hasValue() + *External.IsNone;
 if (SourceCount != 1) {
-  diag(Error, "Exactly one of File or Server must be set.", BlockRange);
+  diag(Error, "Exactly one of File, Server or None must be set.",
+   BlockRange);
   return;
 }
 Config::ExternalIndexSpec Spec;
@@ -346,20 +347,29 @@ struct FragmentCompiler {
   if (!AbsPath)
 return;
   Spec.Location = std::move(*AbsPath);
+} else {
+  assert(*External.IsNone);
+  Spec.Kind = Config::ExternalIndexSpec::None;
 }
-// Make sure MountPoint is an absolute path with forward slashes.
-if (!External.MountPoint)
-  External.MountPoint.emplace(FragmentDirectory);
-if ((**External.MountPoint).empty()) {
-  diag(Error, "A mountpoint is required.", BlockRange);
-  return;
+if (Spec.Kind != Config::ExternalIndexSpec::None) {
+  // Make sure MountPoint is an absolute path with forward slashes.
+  if (!External.MountPoint)
+External.MountPoint.emplace(FragmentDirectory);
+  if ((**External.MountPoint).empty()) {
+diag(Error, "A mountpoint is required.", BlockRange);
+return;
+  }
+  auto AbsPath = makeAbsolute(std::move(*External.MountPoint), 
"MountPoint",
+  llvm::sys::path::Style::posix);
+  if (!AbsPath)
+return;
+  Spec.MountPoint = std::move(*AbsPath);
 }
-auto AbsPath = makeAbsolute(std::move(*External.MountPoint), "MountPoint",
-llvm::sys::path::Style::posix);
-if (!AbsPath)
-  return;
-Spec.MountPoint = std::move(*AbsPath);
 Out.Apply.push_back([Spec(std::move(Spec))](const Params &P, Config &C) {
+  if (Spec.Kind == Config::ExternalIndexSpec::None) {
+C.Index.External.reset();
+return;
+  }
   if (P.Path.empty() || !pathStartsWith(Spec.MountPoint, P.Path,
 llvm::sys::path::Style::posix))
 return;

diff  --git a/clang-tools-extra/clangd/ConfigFragment.h 
b/clang-tools-extra/clangd/ConfigFragment.h
index 1365ed4c1037..6b58b88dfd49 100644
--- a/clang-tools-extra/clangd/ConfigFragment.h
+++ b/clang-tools-extra/clangd/ConfigFragment.h
@@ -173,6 +173,9 @@ struct Fragment {
 /// usually prepared using clangd-indexer.
 /// Exactly one source (File/Server) should be configured.
 struct ExternalBlock {
+  /// Whether the block is explicitly set to `None`. Can be used to clear
+  /// any external index specified before.
+  Located IsNone = false;
   /// Path to an index file generated by clangd-indexer. Relative paths may
   /// be used, if config fragment is associated with a directory.
   llvm::Optional> File;

diff  --git a/clang-tools-extra/clangd/ConfigYAML.cpp 
b/clang-tools-extra/clangd/ConfigYAML.cpp
index d50c01168a8d..f5739de

[clang] b757bc1 - [OpenCL][NFC] Rename isOpenCLVersionContainedInMask

2021-04-13 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-04-13T10:27:37+01:00
New Revision: b757bc14e673c8f8b987cadfe165853fb3de10f1

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

LOG: [OpenCL][NFC] Rename isOpenCLVersionContainedInMask

Drop the double occurrence of "is".

Added: 


Modified: 
clang/include/clang/Basic/OpenCLOptions.h

Removed: 




diff  --git a/clang/include/clang/Basic/OpenCLOptions.h 
b/clang/include/clang/Basic/OpenCLOptions.h
index 9ad3a5681054..703b5ac48094 100644
--- a/clang/include/clang/Basic/OpenCLOptions.h
+++ b/clang/include/clang/Basic/OpenCLOptions.h
@@ -51,10 +51,10 @@ static inline OpenCLVersionID encodeOpenCLVersion(unsigned 
OpenCLVersion) {
   }
 }
 
-// Simple helper to check if OpenCL C version is contained in a given encoded
-// OpenCL C version mask
-static inline bool isOpenCLVersionIsContainedInMask(const LangOptions &LO,
-unsigned Mask) {
+// Check if OpenCL C version is contained in a given encoded OpenCL C version
+// mask.
+static inline bool isOpenCLVersionContainedInMask(const LangOptions &LO,
+  unsigned Mask) {
   auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
   OpenCLVersionID Code = encodeOpenCLVersion(CLVer);
   return Mask & Code;
@@ -101,12 +101,12 @@ class OpenCLOptions {
 
 // Is core option in OpenCL version \p LO.
 bool isCoreIn(const LangOptions &LO) const {
-  return isAvailableIn(LO) && isOpenCLVersionIsContainedInMask(LO, Core);
+  return isAvailableIn(LO) && isOpenCLVersionContainedInMask(LO, Core);
 }
 
 // Is optional core option in OpenCL version \p LO.
 bool isOptionalCoreIn(const LangOptions &LO) const {
-  return isAvailableIn(LO) && isOpenCLVersionIsContainedInMask(LO, Opt);
+  return isAvailableIn(LO) && isOpenCLVersionContainedInMask(LO, Opt);
 }
   };
 



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


[PATCH] D100124: [Clang][NVPTX] Add NVPTX intrinsics and builtins for CUDA PTX redux.sync instructions

2021-04-13 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen added a comment.

In D100124#2684303 , @JonChesterfield 
wrote:

> Interesting. Reduction across lanes in warp? If so, this is probably a way to 
> handle the last step reduction for openmp reductions

It is! I can imagine that it would be useful for OpenMP reductions, though it 
is limited to few, albeit common, operators on 32-bit integers.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100124/new/

https://reviews.llvm.org/D100124

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


[PATCH] D100368: [X86] Support some missing intrinsics

2021-04-13 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

Add _mm512_i32loscatter_epi64  and _mm512_mask_i32loscatter_epi64 for 
completeness?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100368/new/

https://reviews.llvm.org/D100368

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


[PATCH] D97196: [clang-tidy] Add new check 'bugprone-unhandled-exception-at-new'.

2021-04-13 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 337078.
balazske marked 8 inline comments as done.
balazske added a comment.

Rebase, changed documentation, small fix in the code, more tests added.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97196/new/

https://reviews.llvm.org/D97196

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp
@@ -0,0 +1,196 @@
+// RUN: %check_clang_tidy -std=c++14 %s bugprone-unhandled-exception-at-new %t
+
+namespace std {
+typedef __typeof__(sizeof(0)) size_t;
+enum class align_val_t : std::size_t {};
+class exception {};
+class bad_alloc : public exception {};
+class bad_array_new_length : public bad_alloc {};
+struct nothrow_t {};
+extern const nothrow_t nothrow;
+} // namespace std
+
+void *operator new(std::size_t, const std::nothrow_t &) noexcept;
+void *operator new(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept;
+void *operator new(std::size_t, void *) noexcept;
+
+class A {};
+typedef std::bad_alloc badalloc1;
+using badalloc2 = std::bad_alloc;
+using badalloc3 = std::bad_alloc &;
+
+void *operator new(std::size_t, int, int);
+void *operator new(std::size_t, int, int, int) noexcept;
+
+struct ClassSpecificNew {
+  void *operator new(std::size_t);
+  void *operator new(std::size_t, std::align_val_t);
+  void *operator new(std::size_t, int, int) noexcept;
+  void *operator new(std::size_t, int, int, int);
+};
+
+void f1() noexcept {
+  int *I1 = new int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: missing exception handler for allocation failure at 'new'
+  try {
+int *I2 = new int;
+try {
+  int *I3 = new int;
+} catch (A) {
+}
+  } catch (std::bad_alloc) {
+  }
+
+  try {
+int *I = new int;
+  } catch (std::bad_alloc &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (const std::bad_alloc &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc1) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc1 &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (const badalloc1 &) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc2) {
+  }
+
+  try {
+int *I = new int;
+  } catch (badalloc3) {
+  }
+
+  try {
+int *I = new int;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: missing exception handler for allocation failure at 'new'
+  } catch (std::bad_alloc *) {
+  }
+
+  try {
+int *I = new int;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: missing exception handler for allocation failure at 'new'
+  } catch (A) {
+  }
+}
+
+void f2() noexcept {
+  try {
+int *I = new int;
+  } catch (A) {
+  } catch (std::bad_alloc) {
+  }
+
+  try {
+int *I = new int;
+  } catch (...) {
+  }
+
+  try {
+int *I = new int;
+  } catch (const std::exception &) {
+  }
+
+  try {
+int *I = new int;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: missing exception handler for allocation failure at 'new'
+  } catch (const std::bad_array_new_length &) {
+  }
+}
+
+void f_new_nothrow() noexcept {
+  int *I1 = new (std::nothrow) int;
+  int *I2 = new (static_cast(1), std::nothrow) int;
+}
+
+void f_new_placement() noexcept {
+  char buf[100];
+  int *I = new (buf) int;
+}
+
+void f_new_user_defined() noexcept {
+  int *I1 = new (1, 2) int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: missing exception handler for allocation failure at 'new'
+  int *I2 = new (1, 2, 3) int;
+}
+
+void f_class_specific() noexcept {
+  ClassSpecificNew *N1 = new ClassSpecificNew;
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: missing exception handler for allocation failure at 'new'
+  ClassSpecificNew *N2 = new (static_cast(1)) ClassSpecificNew;
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: missing exception handler for allocation failure at 'new'
+  ClassSpecificNew *N3 = new (1, 2) ClassSpecificNew;
+  ClassSpecificNew *N4 = new (1, 2, 3) ClassSpecificNew;
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: missing exception handler for allocation failure at 'new'
+}
+
+void f_est_none() {
+  int *I = new int;
+}
+
+void f_est_noexcept_false() noexcept(false) {
+  int *I = new int;
+}
+
+void f_est_noexcept_true() noexcept(true) {
+  int *I = new int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: missing exception handler for allocatio

[PATCH] D97196: [clang-tidy] Add new check 'bugprone-unhandled-exception-at-new'.

2021-04-13 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst:7
+Finds calls to ``new`` that may throw ``std::bad_alloc`` exception and
+the exception handler is missing.
+

aaron.ballman wrote:
> This isn't quite accurate -- if the exception handler is missing or doesn't 
> handle either `std::bad_alloc` or `std::exception`.
I restructure the text, but do not want to mention `std::exception` because it 
is a base class (handling of `std::exception` means handling of 
`std::bad_alloc`), and then why not mention generic exception handler 
(`catch(...)`). I think this text is for introduction only, should not be 
totally precise.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97196/new/

https://reviews.llvm.org/D97196

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


[PATCH] D100374: [clang] [AArch64] Fix Windows va_arg handling for larger structs

2021-04-13 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added reviewers: rnk, efriedma, TomTan, maxim-kuvyrkov.
Herald added subscribers: danielkiss, pengfei, kristof.beyls.
mstorsjo requested review of this revision.
Herald added a project: clang.

Aggregate types over 16 bytes are passed by reference.

Contrary to the x86_64 ABI, smaller structs with an odd (non power
of two) are padded and passed in registers.

I noted that I could clean up the rest of the test, sharing check patterns
that are identical, in a separate patch later.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100374

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/ms_abi_aarch64.c


Index: clang/test/CodeGen/ms_abi_aarch64.c
===
--- clang/test/CodeGen/ms_abi_aarch64.c
+++ clang/test/CodeGen/ms_abi_aarch64.c
@@ -1,5 +1,13 @@
-// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm < %s | FileCheck 
-check-prefix=LINUX %s
-// RUN: %clang_cc1 -triple aarch64-pc-win32 -emit-llvm < %s | FileCheck 
-check-prefix=WIN64 %s
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm < %s | FileCheck 
-check-prefixes=LINUX,COMMON %s
+// RUN: %clang_cc1 -triple aarch64-pc-win32 -emit-llvm < %s | FileCheck 
-check-prefixes=WIN64,COMMON %s
+
+struct small_odd {
+  char a, b, c;
+};
+
+struct larger {
+  int a, b, c, d, e;
+};
 
 void __attribute__((ms_abi)) f1(void);
 void f2(void);
@@ -48,6 +56,26 @@
   // WIN64: call void @llvm.va_end
 }
 
+void __attribute__((ms_abi)) f4_2(int a, ...) {
+  // LINUX-LABEL: define{{.*}} win64cc void @f4_2
+  // WIN64-LABEL: define dso_local void @f4_2
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap, a);
+  // COMMON: %[[AP:.*]] = alloca i8*
+  // COMMON: call void @llvm.va_start
+  struct small_odd s1 = __builtin_va_arg(ap, struct small_odd);
+  // COMMON: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
+  // COMMON-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* 
%[[AP_CUR]], i64 8
+  // COMMON-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
+  // COMMON-NEXT: bitcast i8* %[[AP_CUR]] to %struct.small_odd*
+  struct larger s2 = __builtin_va_arg(ap, struct larger);
+  // COMMON: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
+  // COMMON-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* 
%[[AP_CUR2]], i64 8
+  // COMMON-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
+  // COMMON-NEXT: bitcast i8* %[[AP_CUR2]] to %struct.larger**
+  __builtin_ms_va_end(ap);
+}
+
 // Let's verify that normal va_lists work right on Win64, too.
 void f5(int a, ...) {
   // WIN64-LABEL: define dso_local void @f5
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -6112,7 +6112,13 @@
 
 Address AArch64ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType Ty) const {
-  return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*indirect*/ false,
+  bool IsIndirect = false;
+
+  // Composites larger than 16 bytes are passed by reference.
+  if (isAggregateTypeForABI(Ty) && getContext().getTypeSize(Ty) > 128)
+IsIndirect = true;
+
+  return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect,
   CGF.getContext().getTypeInfoInChars(Ty),
   CharUnits::fromQuantity(8),
   /*allowHigherAlign*/ false);


Index: clang/test/CodeGen/ms_abi_aarch64.c
===
--- clang/test/CodeGen/ms_abi_aarch64.c
+++ clang/test/CodeGen/ms_abi_aarch64.c
@@ -1,5 +1,13 @@
-// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm < %s | FileCheck -check-prefix=LINUX %s
-// RUN: %clang_cc1 -triple aarch64-pc-win32 -emit-llvm < %s | FileCheck -check-prefix=WIN64 %s
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm < %s | FileCheck -check-prefixes=LINUX,COMMON %s
+// RUN: %clang_cc1 -triple aarch64-pc-win32 -emit-llvm < %s | FileCheck -check-prefixes=WIN64,COMMON %s
+
+struct small_odd {
+  char a, b, c;
+};
+
+struct larger {
+  int a, b, c, d, e;
+};
 
 void __attribute__((ms_abi)) f1(void);
 void f2(void);
@@ -48,6 +56,26 @@
   // WIN64: call void @llvm.va_end
 }
 
+void __attribute__((ms_abi)) f4_2(int a, ...) {
+  // LINUX-LABEL: define{{.*}} win64cc void @f4_2
+  // WIN64-LABEL: define dso_local void @f4_2
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap, a);
+  // COMMON: %[[AP:.*]] = alloca i8*
+  // COMMON: call void @llvm.va_start
+  struct small_odd s1 = __builtin_va_arg(ap, struct small_odd);
+  // COMMON: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
+  // COMMON-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
+  // COMMON-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
+  // COMMON-NEXT: bitcast i8* %[[AP_CUR]] to %struct.small_odd*
+  struct larger s2 = __builtin_va_arg(ap, struct larger);
+  // COMMON: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
+  /

[PATCH] D100294: [AArch64][SVE] Fix dup/dupq intrinsics for C++.

2021-04-13 Thread Sander de Smalen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfa936b610fd0: [AArch64][SVE] Fix dup/dupq intrinsics for 
C++. (authored by sdesmalen).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100294/new/

https://reviews.llvm.org/D100294

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dup.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
  clang/utils/TableGen/SveEmitter.cpp


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -362,6 +362,9 @@
   if (isVoid())
 return "v";
 
+  if (isScalarPredicate())
+return "b";
+
   if (isVoidPointer())
 S += "v";
   else if (!isFloatingPoint())
Index: clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
===
--- clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
+++ clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
@@ -1,6 +1,8 @@
 // REQUIRES: aarch64-registered-target
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - -x c++ 
%s | FileCheck %s
 // RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall 
-emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall 
-emit-llvm -o - -x c++ %s | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -S -O1 -Werror -o - %s >/dev/null
 #include 
 
Index: clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dup.c
===
--- clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dup.c
+++ clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dup.c
@@ -1,6 +1,8 @@
 // REQUIRES: aarch64-registered-target
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - -x c++ 
%s | FileCheck %s
 // RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall 
-emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall 
-emit-llvm -o - -x c++ %s | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -S -O1 -Werror -o - %s >/dev/null
 #include 
 
Index: clang/include/clang/Basic/arm_sve.td
===
--- clang/include/clang/Basic/arm_sve.td
+++ clang/include/clang/Basic/arm_sve.td
@@ -2073,7 +2073,7 @@
 def SVSM4EKEY : SInst<"svsm4ekey[_{d}]", "ddd", "Ui", MergeNone, 
"aarch64_sve_sm4ekey", [IsOverloadNone]>;
 }
 
-let ArchGuard = "__ARM_FEATURE_SVE2_BITPERM" in {
+let ArchGuard = "defined (__ARM_FEATURE_SVE2_BITPERM)" in {
 def SVBDEP   : SInst<"svbdep[_{d}]",   "ddd", "UcUsUiUl", MergeNone, 
"aarch64_sve_bdep_x">;
 def SVBDEP_N : SInst<"svbdep[_n_{d}]", "dda", "UcUsUiUl", MergeNone, 
"aarch64_sve_bdep_x">;
 def SVBEXT   : SInst<"svbext[_{d}]",   "ddd", "UcUsUiUl", MergeNone, 
"aarch64_sve_bext_x">;


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -362,6 +362,9 @@
   if (isVoid())
 return "v";
 
+  if (isScalarPredicate())
+return "b";
+
   if (isVoidPointer())
 S += "v";
   else if (!isFloatingPoint())
Index: clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
===
--- clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
+++ clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
@@ -1,6 +1,8 @@
 // REQUIRES: aarch64-registered-target
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s
 // RUN

[clang] fa936b6 - [AArch64][SVE] Fix dup/dupq intrinsics for C++.

2021-04-13 Thread Sander de Smalen via cfe-commits

Author: Sander de Smalen
Date: 2021-04-13T10:55:20+01:00
New Revision: fa936b610fd019b73de82f61de83bae553251fdb

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

LOG: [AArch64][SVE] Fix dup/dupq intrinsics for C++.

This patch changes the builtin prototype to use 'b' (boolean) instead
of the default integer element type. That fixes the dup/dupq intrinsics
when compiling with C++.

This patch also fixes one of the defines for __ARM_FEATURE_SVE2_BITPERM.

Reviewed By: kmclaughlin

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

Added: 


Modified: 
clang/include/clang/Basic/arm_sve.td
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dup.c
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
clang/utils/TableGen/SveEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index a073a8bab28e..5e9d1c96558b 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2073,7 +2073,7 @@ def SVSM4E: SInst<"svsm4e[_{d}]","ddd", "Ui", 
MergeNone, "aarch64_sve_sm
 def SVSM4EKEY : SInst<"svsm4ekey[_{d}]", "ddd", "Ui", MergeNone, 
"aarch64_sve_sm4ekey", [IsOverloadNone]>;
 }
 
-let ArchGuard = "__ARM_FEATURE_SVE2_BITPERM" in {
+let ArchGuard = "defined (__ARM_FEATURE_SVE2_BITPERM)" in {
 def SVBDEP   : SInst<"svbdep[_{d}]",   "ddd", "UcUsUiUl", MergeNone, 
"aarch64_sve_bdep_x">;
 def SVBDEP_N : SInst<"svbdep[_n_{d}]", "dda", "UcUsUiUl", MergeNone, 
"aarch64_sve_bdep_x">;
 def SVBEXT   : SInst<"svbext[_{d}]",   "ddd", "UcUsUiUl", MergeNone, 
"aarch64_sve_bext_x">;

diff  --git a/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dup.c 
b/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dup.c
index 412734b08d79..f632be7b8598 100644
--- a/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dup.c
+++ b/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dup.c
@@ -1,6 +1,8 @@
 // REQUIRES: aarch64-registered-target
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - -x c++ 
%s | FileCheck %s
 // RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall 
-emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall 
-emit-llvm -o - -x c++ %s | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -S -O1 -Werror -o - %s >/dev/null
 #include 
 

diff  --git a/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c 
b/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
index c38195388d56..50337643b757 100644
--- a/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
+++ b/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
@@ -1,6 +1,8 @@
 // REQUIRES: aarch64-registered-target
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - -x c++ 
%s | FileCheck %s
 // RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall 
-emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -fallow-half-arguments-and-returns -S -O1 -Werror -Wall 
-emit-llvm -o - -x c++ %s | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -S -O1 -Werror -o - %s >/dev/null
 #include 
 

diff  --git a/clang/utils/TableGen/SveEmitter.cpp 
b/clang/utils/TableGen/SveEmitter.cpp
index fe369e9d9408..46966d4d9feb 100644
--- a/clang/utils/TableGen/SveEmitter.cpp
+++ b/clang/utils/TableGen/SveEmitter.cpp
@@ -362,6 +362,9 @@ std::string SVEType::builtin_str() const {
   if (isVoid())
 return "v";
 
+  if (isScalarPredicate())
+return "b";
+
   if (isVoidPointer())
 S += "v";
   else if (!isFloatingPoint())



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


[PATCH] D100297: [AArch64][SVE] Always use overloaded methods instead of preprocessor macro.

2021-04-13 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes accepted this revision.
c-rhodes added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100297/new/

https://reviews.llvm.org/D100297

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


[clang] eae2d4b - [Windows Itanium][PS4] handle dllimport/export w.r.t vtables/rtti

2021-04-13 Thread Ben Dunbobbin via cfe-commits

Author: Ben Dunbobbin
Date: 2021-04-13T11:41:10+01:00
New Revision: eae2d4b8520c768291dcff2169b78486af324d17

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

LOG: [Windows Itanium][PS4] handle dllimport/export w.r.t vtables/rtti

The existing Windows Itanium patches for dllimport/export
behaviour w.r.t vtables/rtti can't be adopted for PS4 due to
backwards compatibility reasons (see comments on
https://reviews.llvm.org/D90299).

This commit adds our PS4 scheme for this to Clang.

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

Added: 
clang/test/CodeGenCXX/ps4-dllstorage-vtable-rtti.cpp

Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 3ddb706dcf52..3bcaaceb63d8 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1130,6 +1130,15 @@ class TargetInfo : public virtual 
TransferrableTargetInfo,
getTriple().isWindowsItaniumEnvironment() || getTriple().isPS4CPU();
   }
 
+  // Does this target have PS4 specific dllimport/export handling?
+  virtual bool hasPS4DLLImportExport() const {
+return getTriple().isPS4CPU() ||
+   // Windows Itanium support allows for testing the SCEI flavour of
+   // dllimport/export handling on a Windows system.
+   (getTriple().isWindowsItaniumEnvironment() &&
+getTriple().getVendor() == llvm::Triple::SCEI);
+  }
+
   /// An optional hook that targets can implement to perform semantic
   /// checking on attribute((section("foo"))) specifiers.
   ///

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index eb9bfc20342f..8a25b5cbd84a 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2293,7 +2293,8 @@ static const CXXMethodDecl *computeKeyFunction(ASTContext 
&Context,
 // If the key function is dllimport but the class isn't, then the class has
 // no key function. The DLL that exports the key function won't export the
 // vtable in this case.
-if (MD->hasAttr() && !RD->hasAttr())
+if (MD->hasAttr() && !RD->hasAttr() &&
+!Context.getTargetInfo().hasPS4DLLImportExport())
   return nullptr;
 
 // We found it.

diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index c10ee0446912..93500cb62359 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1835,6 +1835,29 @@ ItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base,
   /*InRangeIndex=*/1);
 }
 
+// Check whether all the non-inline virtual methods for the class have the
+// specified attribute.
+template 
+static bool CXXRecordAllNonInlineVirtualsHaveAttr(const CXXRecordDecl *RD) {
+  bool FoundNonInlineVirtualMethodWithAttr = false;
+  for (const auto *D : RD->noload_decls()) {
+if (const auto *FD = dyn_cast(D)) {
+  if (!FD->isVirtualAsWritten() || FD->isInlineSpecified() ||
+  FD->doesThisDeclarationHaveABody())
+continue;
+  if (!D->hasAttr())
+return false;
+  FoundNonInlineVirtualMethodWithAttr = true;
+}
+  }
+
+  // We didn't find any non-inline virtual methods missing the attribute.  We
+  // will return true when we found at least one non-inline virtual with the
+  // attribute.  (This lets our caller know that the attribute needs to be
+  // propagated up to the vtable.)
+  return FoundNonInlineVirtualMethodWithAttr;
+}
+
 llvm::Value *ItaniumCXXABI::getVTableAddressPointInStructorWithVTT(
 CodeGenFunction &CGF, const CXXRecordDecl *VTableClass, BaseSubobject Base,
 const CXXRecordDecl *NearestVBase) {
@@ -1891,6 +1914,24 @@ llvm::GlobalVariable 
*ItaniumCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
   getContext().toCharUnitsFromBits(PAlign).getQuantity());
   VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 
+  // In MS C++ if you have a class with virtual functions in which you are 
using
+  // selective member import/export, then all virtual functions must be 
exported
+  // unless they are inline, otherwise a link error will result. To match this
+  // behavior, for such classes, we dllimport the vtable if it is defined
+  // externally and all the non-inline virtual methods are marked dllimport, 
and
+  // we dllexport the vtable if it is defined in this TU and all the non-inline
+  // virtual methods are marked dllexport.
+  if (CGM.getTarget().hasPS4DLLImportExport()) {
+if ((!RD->hasAttr()) && (!RD->hasAttr())) {
+  if (CGM.getVTables().isVTableExternal(RD)

[PATCH] D93203: [PS4] handle dllimport/export w.r.t vtables/rtti

2021-04-13 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeae2d4b8520c: [Windows Itanium][PS4] handle dllimport/export 
w.r.t vtables/rtti (authored by Ben Dunbobbin ).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D93203?vs=318527&id=337091#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93203/new/

https://reviews.llvm.org/D93203

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/ps4-dllstorage-vtable-rtti.cpp

Index: clang/test/CodeGenCXX/ps4-dllstorage-vtable-rtti.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/ps4-dllstorage-vtable-rtti.cpp
@@ -0,0 +1,210 @@
+// For a class that has a vtable (and hence, also has a typeinfo symbol for
+// RTTI), if a user marks either:
+//
+//  (a) the entire class as dllexport (dllimport), or
+//  (b) all non-inline virtual methods of the class as dllexport (dllimport)
+//
+// then Clang must export the vtable and typeinfo symbol from the TU where they
+// are defined (the TU containing the definition of the Itanium C++ ABI "key
+// function"), and must import them in other modules where they are referenced.
+//
+// Conversely to point (b), if some (but not all) of the non-inline virtual
+// methods of a class are marked as dllexport (dllimport), then the vtable and
+// typeinfo symbols must not be exported (imported).  This will result in a
+// link-time failure when linking the importing module.  This link-time failure
+// is the desired behavior, because the Microsoft toolchain also gets a
+// link-time failure in these cases (and since __declspec(dllexport)
+// (__declspec(dllimport)) is a Microsoft extension, our intention is to mimic
+// that Microsoft behavior).
+//
+// Side note: It is within the bodies of constructors (and in some cases,
+// destructors) that the vtable is explicitly referenced.  In case (a) above,
+// where the entire class is exported (imported), then all constructors (among
+// other things) are exported (imported).  So for that situation, an importing
+// module for a well-formed program will not actually reference the vtable,
+// since constructor calls will all be to functions external to that module
+// (and imported into it, from the exporting module).  I.e., all vtable
+// references will be in that module where the constructor and destructor
+// bodies are, therefore, there will not be a need to import the vtable in
+// that case.
+//
+// This test contains 6 test classes:
+//   2 for point (a),
+//   2 for point (b),
+//   and 2 negative tests for the converse of point (b).
+//
+// The two tests for each of these points are one for importing, and one for
+// exporting.
+
+// RUN: %clang_cc1 -I%S -fdeclspec -triple x86_64-unknown-windows-itanium -emit-llvm -o - %s -fhalf-no-semantic-interposition | FileCheck %s -check-prefix=WI
+// RUN: %clang_cc1 -I%S -fdeclspec -triple x86_64-scei-windows-itanium -emit-llvm -o - %s -fhalf-no-semantic-interposition | FileCheck %s --check-prefixes=PS4,SCEI_WI
+// RUN: %clang_cc1 -I%S -fdeclspec -triple x86_64-scei-ps4 -emit-llvm -o - %s -fhalf-no-semantic-interposition | FileCheck %s --check-prefixes=PS4,SCEI_PS4
+
+#include 
+
+// Case (a) -- Import Aspect
+// The entire class is imported.  The typeinfo symbol must also be imported,
+// but the vtable will not be referenced, and so does not need to be imported
+// (as described in the "Side note", above).
+//
+// PS4-DAG: @_ZTI10FullImport = {{.*}}dllimport
+// WI-DAG: @_ZTI10FullImport = external dllimport constant i8*
+struct __declspec(dllimport) FullImport
+{
+  virtual void getId() {}
+  virtual void Bump();
+  virtual void Decrement();
+};
+
+// 'FullImport::Bump()' is the key function, so the vtable and typeinfo symbol
+// of 'FullImport' will be defined in the TU that contains the definition of
+// 'Bump()' (and they must be exported from there).
+void FullImportTest()
+{
+  typeid(FullImport).name();
+}
+
+///
+
+// Case (a) -- Export Aspect
+// The entire class is exported.  The vtable and typeinfo symbols must also be
+// exported,
+//
+// PS4-DAG: @_ZTV10FullExport ={{.*}}dllexport
+// WI-DAG: @_ZTV10FullExport ={{.*}}dllexport
+// PS4-DAG: @_ZTI10FullExport ={{.*}}dllexport
+// WI-DAG: @_ZTI10FullExport = dso_local dllexport constant {
+struct __declspec(dllexport) FullExport // Easy case: Entire class is exported.
+{
+  virtual void getId() {}
+  virtual void Bump();
+  virtual void Decrement();
+};
+
+// This is the key function of the class 'FullExport', so the vtable and
+// typeinfo symbols of 'FullExport' will be defined in this TU, and so they
+// must be exported from this TU.
+void FullExport::Bump()
+{
+  typeid(FullEx

[clang] 5ad15f4 - Require commas between double square bracket attributes.

2021-04-13 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-04-13T06:43:01-04:00
New Revision: 5ad15f4d1c6f56d25904265023d123a7d0b9d59d

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

LOG: Require commas between double square bracket attributes.

Clang currently has a bug where it allows you to write [[foo bar]] and
both attributes are silently accepted. This patch corrects the comma
parsing rules for such attributes and handles the test case fallout, as
a few tests were accidentally doing this.

Added: 


Modified: 
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p1.cpp
clang/test/Parser/c2x-attributes.c
clang/test/Parser/cxx-attributes.cpp
clang/test/Parser/pragma-attribute.cpp
clang/test/Sema/c2x-maybe_unused-errors.c
clang/test/Sema/c2x-nodiscard.c

Removed: 




diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 498036368c19..e1d29f555f42 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -4213,10 +4213,21 @@ void 
Parser::ParseCXX11AttributeSpecifier(ParsedAttributes &attrs,
 
   llvm::SmallDenseMap SeenAttrs;
 
+  bool AttrParsed = false;
   while (Tok.isNot(tok::r_square)) {
-// attribute not present
-if (TryConsumeToken(tok::comma))
-  continue;
+if (AttrParsed) {
+  // If we parsed an attribute, a comma is required before parsing any
+  // additional attributes.
+  if (ExpectAndConsume(tok::comma)) {
+SkipUntil(tok::r_square, StopAtSemi | StopBeforeMatch);
+continue;
+  }
+  AttrParsed = false;
+}
+
+// Eat all remaining superfluous commas before parsing the next attribute.
+while (TryConsumeToken(tok::comma))
+  ;
 
 SourceLocation ScopeLoc, AttrLoc;
 IdentifierInfo *ScopeName = nullptr, *AttrName = nullptr;
@@ -4250,7 +4261,6 @@ void 
Parser::ParseCXX11AttributeSpecifier(ParsedAttributes &attrs,
 }
 
 bool StandardAttr = IsBuiltInOrStandardCXX11Attribute(AttrName, ScopeName);
-bool AttrParsed = false;
 
 if (StandardAttr &&
 !SeenAttrs.insert(std::make_pair(AttrName, AttrLoc)).second)
@@ -4262,12 +4272,14 @@ void 
Parser::ParseCXX11AttributeSpecifier(ParsedAttributes &attrs,
   AttrParsed = ParseCXX11AttributeArgs(AttrName, AttrLoc, attrs, endLoc,
ScopeName, ScopeLoc);
 
-if (!AttrParsed)
+if (!AttrParsed) {
   attrs.addNew(
   AttrName,
   SourceRange(ScopeLoc.isValid() ? ScopeLoc : AttrLoc, AttrLoc),
   ScopeName, ScopeLoc, nullptr, 0,
   getLangOpts().CPlusPlus ? ParsedAttr::AS_CXX11 : ParsedAttr::AS_C2x);
+  AttrParsed = true;
+}
 
 if (TryConsumeToken(tok::ellipsis))
   Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis)

diff  --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
index 45911958af74..982f18f1e8cd 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c++2a -verify %s
 
 struct [[nodiscard]] S1 {}; // ok
-struct [[nodiscard nodiscard]] S2 {}; // expected-error {{attribute 
'nodiscard' cannot appear multiple times in an attribute specifier}}
+struct [[nodiscard, nodiscard]] S2 {}; // expected-error {{attribute 
'nodiscard' cannot appear multiple times in an attribute specifier}}
 struct [[nodiscard("Wrong")]] S3 {};
 
 [[nodiscard]] int f();

diff  --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p1.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p1.cpp
index 8da2ca7d6d86..6c9b8a75cb04 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p1.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p1.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wunused -std=c++1z -verify %s
 
 struct [[maybe_unused]] S1 {}; // ok
-struct [[maybe_unused maybe_unused]] S2 {}; // expected-error {{attribute 
'maybe_unused' cannot appear multiple times in an attribute specifier}}
+struct [[maybe_unused, maybe_unused]] S2 {}; // expected-error {{attribute 
'maybe_unused' cannot appear multiple times in an attribute specifier}}
 struct [[maybe_unused("Wrong")]] S3 {}; // expected-error {{'maybe_unused' 
cannot have an argument list}}

diff  --git a/clang/test/Parser/c2x-attributes.c 
b/clang/test/Parser/c2x-attributes.c
index 393506e867fe..48bb19707dd1 100644
--- a/clang/test/Parser/c2x-attributes.c
+++ b/clang/test/Parser/c2x-attributes.c
@@ -16,6 +16,13 @@ enum { [[]] Six }; // expected-error {{expected identifier}}
 // FIXME: this diagnostic can be improved.
 

[PATCH] D97196: [clang-tidy] Add new check 'bugprone-unhandled-exception-at-new'.

2021-04-13 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-unhandled-exception-at-new.cpp:20
+using badalloc3 = std::bad_alloc &;
+
+void *operator new(std::size_t, int, int);

aaron.ballman wrote:
> Another interesting test case would be when the user subclasses 
> `std::bad_alloc` and throws errors of the subclass type from the allocation 
> function which are in/correctly caught.
In this case the check must find every (visible) subclass of `std::bad_alloc` 
check if there is a catch block for every case. Even then a custom allocation 
function may throw other classes (not derived from `std::bad_alloc`) or classes 
(may be inherited from `std::bad_alloc` but not visible in the TU) that are not 
checked. So this is still a partial solution, probably not better than the rule 
that a handler for `bad_alloc` (or more generic) should exist.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97196/new/

https://reviews.llvm.org/D97196

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


[PATCH] D98499: [clangd] Introduce ASTHooks to FeatureModules

2021-04-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 337101.
kadircet marked 7 inline comments as done.
kadircet added a comment.

- Pass FeatureModuleSet rather than astListeners in ParseInputs.
- Create listeners only when building ASTs.
- Use a callback function in StoreDiags to notify about diagnostics.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98499/new/

https://reviews.llvm.org/D98499

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/FeatureModule.cpp
  clang-tools-extra/clangd/FeatureModule.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h

Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -19,12 +19,14 @@
 
 #include "../TidyProvider.h"
 #include "Compiler.h"
+#include "FeatureModule.h"
 #include "ParsedAST.h"
 #include "TestFS.h"
 #include "index/Index.h"
 #include "support/Path.h"
 #include "llvm/ADT/StringMap.h"
 #include "gtest/gtest.h"
+#include 
 #include 
 #include 
 #include 
@@ -76,6 +78,8 @@
   // to eliminate this option some day.
   bool OverlayRealFileSystemForModules = false;
 
+  FeatureModuleSet *FeatureModules = nullptr;
+
   // By default, build() will report Error diagnostics as GTest errors.
   // Suppress this behavior by adding an 'error-ok' comment to the code.
   // The result will always have getDiagnostics() populated.
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -36,6 +36,7 @@
   FS.Files[ImportThunk] = ThunkContents;
 
   ParseInputs Inputs;
+  Inputs.FeatureModules = FeatureModules;
   auto &Argv = Inputs.CompileCommand.CommandLine;
   Argv = {"clang"};
   // FIXME: this shouldn't need to be conditional, but it breaks a
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -9,6 +9,7 @@
 #include "Annotations.h"
 #include "Config.h"
 #include "Diagnostics.h"
+#include "FeatureModule.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "SourceCode.h"
@@ -26,6 +27,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -1346,6 +1348,31 @@
  });
 }
 
+TEST(ParsedASTTest, ModuleSawDiag) {
+  static constexpr const llvm::StringLiteral KDiagMsg = "StampedDiag";
+  struct DiagModifierModule final : public FeatureModule {
+struct Listener : public FeatureModule::ASTListener {
+  void sawDiagnostic(const clang::Diagnostic &Info,
+ clangd::Diag &Diag) override {
+Diag.Message = KDiagMsg.str();
+  }
+};
+std::unique_ptr astListeners() override {
+  return std::make_unique();
+};
+  };
+  FeatureModuleSet FMS;
+  FMS.add(std::make_unique());
+
+  Annotations Code("[[test]]; /* error-ok */");
+  TestTU TU;
+  TU.Code = Code.code().str();
+  TU.FeatureModules = &FMS;
+
+  auto AST = TU.build();
+  EXPECT_THAT(*AST.getDiagnostics(),
+  testing::Contains(Diag(Code.range(), KDiagMsg.str(;
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
@@ -365,6 +365,27 @@
   // And immediately shut down. FeatureModule destructor verifies we blocked.
 }
 
+TEST_F(LSPTest, DiagModuleTest) {
+  static constexpr llvm::StringLiteral DiagMsg = "DiagMsg";
+  class DiagModule final : public FeatureModule {
+struct DiagHooks : public ASTListener {
+  void sawDiagnostic(const clang::Diagnostic &, clangd::Diag &D) override {
+D.Message = DiagMsg.str();
+  }
+};
+
+  public:
+std::unique_ptr astListeners() override {
+  return std::make_unique();
+}
+  };
+  FeatureModules.add(std::make_unique());
+
+  auto &Client = start();
+  Client.didOpen("foo.cpp", "test;");
+  EXPECT_THAT(Client.diagnostics("foo.cpp"),
+  llvm::ValueIs(testing::ElementsAre(DiagMessage(DiagMsg;
+}
 } // namespace
 } // namespace clangd
 } // namespace 

[PATCH] D100378: [AST] Use IntrusiveRefCntPtr for Introspection LocationCall.

2021-04-13 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added a reviewer: steveire.
njames93 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100378

Files:
  clang/include/clang/Tooling/NodeIntrospection.h
  clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
  clang/lib/Tooling/NodeIntrospection.cpp

Index: clang/lib/Tooling/NodeIntrospection.cpp
===
--- clang/lib/Tooling/NodeIntrospection.cpp
+++ clang/lib/Tooling/NodeIntrospection.cpp
@@ -36,8 +36,8 @@
 
 namespace internal {
 bool RangeLessThan::operator()(
-std::pair> const &LHS,
-std::pair> const &RHS) const {
+std::pair const &LHS,
+std::pair const &RHS) const {
   if (!LHS.first.isValid() || !RHS.first.isValid())
 return false;
 
@@ -53,6 +53,13 @@
 
   return LHS.second->name() < RHS.second->name();
 }
+bool RangeLessThan::operator()(
+std::pair const &LHS,
+std::pair const &RHS) const {
+  if (LHS.first == RHS.first)
+return LHS.second->name() < RHS.second->name();
+  return LHS.first < RHS.first;
+}
 } // namespace internal
 
 } // namespace tooling
Index: clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
===
--- clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
+++ clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
@@ -33,7 +33,7 @@
 def GenerateBaseGetLocationsDeclaration(self, CladeName):
 self.implementationContent += \
 """
-void GetLocationsImpl(std::shared_ptr const& Prefix,
+void GetLocationsImpl(SharedLocationCall const& Prefix,
 clang::{0} const *Object, SourceLocationMap &Locs,
 SourceRangeMap &Rngs);
 """.format(CladeName)
@@ -42,7 +42,7 @@
 
 self.implementationContent += \
 """
-static void GetLocations{0}(std::shared_ptr const& Prefix,
+static void GetLocations{0}(SharedLocationCall const& Prefix,
 clang::{0} const &Object,
 SourceLocationMap &Locs, SourceRangeMap &Rngs)
 {{
@@ -53,7 +53,7 @@
 self.implementationContent += \
 """
   Locs.insert(LocationAndString(Object.{0}(),
-std::make_shared(Prefix, "{0}")));
+llvm::makeIntrusiveRefCnt(Prefix, "{0}")));
 """.format(locName)
 
 self.implementationContent += '\n'
@@ -63,7 +63,7 @@
 self.implementationContent += \
 """
   Rngs.insert(RangeAndString(Object.{0}(),
-std::make_shared(Prefix, "{0}")));
+llvm::makeIntrusiveRefCnt(Prefix, "{0}")));
 """.format(rngName)
 
 self.implementationContent += '\n'
@@ -83,7 +83,7 @@
 'GetLocations(clang::{0} const *Object)'.format(CladeName)
 ImplSignature = \
 """
-GetLocationsImpl(std::shared_ptr const& Prefix,
+GetLocationsImpl(SharedLocationCall const& Prefix,
 clang::{0} const *Object, SourceLocationMap &Locs,
 SourceRangeMap &Rngs)
 """.format(CladeName)
@@ -108,7 +108,7 @@
 """
 {0} NodeIntrospection::{1} {{
   NodeLocationAccessors Result;
-  std::shared_ptr Prefix;
+  SharedLocationCall Prefix;
 
   GetLocationsImpl(Prefix, Object, Result.LocationAccessors,
Result.RangeAccessors);
Index: clang/include/clang/Tooling/NodeIntrospection.h
===
--- clang/include/clang/Tooling/NodeIntrospection.h
+++ clang/include/clang/Tooling/NodeIntrospection.h
@@ -15,8 +15,7 @@
 
 #include "clang/AST/ASTTypeTraits.h"
 #include "clang/AST/DeclarationName.h"
-
-#include 
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include 
 
 namespace clang {
@@ -26,16 +25,19 @@
 
 namespace tooling {
 
-class LocationCall {
+class LocationCall;
+using SharedLocationCall = llvm::IntrusiveRefCntPtr;
+
+class LocationCall : public llvm::ThreadSafeRefCountedBase {
 public:
   enum LocationCallFlags { NoFlags, ReturnsPointer, IsCast };
-  LocationCall(std::shared_ptr on, std::string name,
+  LocationCall(SharedLocationCall on, std::string name,
LocationCallFlags flags = NoFlags)
-  : m_on(on), m_name(name), m_flags(flags) {}
-  LocationCall(std::shared_ptr on, std::string name,
+  : m_flags(flags), m_on(std::move(on)), m_name(name) {}
+  LocationCall(SharedLocationCall on, std::string name,
std::vector const &args,
LocationCallFlags flags = NoFlags)
-  : m_on(on), m_name(name), m_flags(flags) {}
+  : m_flags(flags), m_on(std::move(on)), m_name(name) {}
 
   LocationCall *on() const { return m_on.get(); }
   StringRef name() const { return m_name; }
@@ -44,10 +46,10 @@
   bool isCast() const { return m_flags & IsCast; }
 
 private:
-  std::shared_ptr m_on;
+  LocationCallFlags m_flags;
+  SharedLocationCall m_on;
   std::string m_name;
   std::vector m_args;
-  LocationCallFlags m_flags;
 };
 
 class LocationCallFormatterCpp {
@@ -57,20 +59,20 @@

[PATCH] D96090: [analyzer] Replace StoreManager::CastRetrievedVal with SValBuilder::evalCast

2021-04-13 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@NoQ 
Many thanks for your evaluation!

> Wait, no, nvm, please disregard this. It wasn't like this forever, i just 
> happened to catch code in an intermediate state after D90157 
> . Either way, it's definitely getting much 
> better, and either way, i'm curious if `dispatchCast` can now be eliminated.

Already approved a month ago D97277  :-) 
That's the next step.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96090/new/

https://reviews.llvm.org/D96090

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


[PATCH] D100346: [Clang] String Literal and Wide String Literal Encoding from the Preprocessor

2021-04-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: rsmith.
aaron.ballman added a comment.

Thank you for this patch, I think this is useful functionality!

In D100346#2684736 , @ThePhD wrote:

> The string literals work for people because, despite not being 
> preprocessor-comparable, they can be manipulated at compile-time and switched 
> on in the usual ways at `constexpr` time. See usages in:
>
> https://github.com/soasis/text/blob/main/include/ztd/text/detail/encoding_name.hpp#L198
> https://github.com/soasis/text/blob/main/include/ztd/text/literal.hpp#L54
>
> , which can be used at compile-time like:
>
> https://github.com/soasis/text/blob/main/tests/basic_compile_time/source/validate_code_points.cpp#L45

What about for folks using this from C where there isn't `constexpr` 
functionality to help them?




Comment at: clang/docs/LanguageExtensions.rst:387
+``__clang_literal_encoding__``
+  Defined to a string that represents the current encoding of string literals,
+  e.g., ``"hello"``. This is typically "UTF-8" (but may change in the future

In both cases, defined to a string *in what encoding* ()? More 
seriously, we should probably be clear that this expands to a narrow string 
literal rather than, say, a `const char *` or `std::string`.



Comment at: clang/docs/LanguageExtensions.rst:388
+  Defined to a string that represents the current encoding of string literals,
+  e.g., ``"hello"``. This is typically "UTF-8" (but may change in the future
+  if the ``-fexec-charset="Encoding-Name"`` option is implemented.)

This is typically -> This macro typically expands to

(same below).



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:781
 
+  // macros to help identify the narrow and wide character sets
+  // NOTE: clang currently ignores -fexec-charset=. If this changes,

macros -> Macros



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:782
+  // macros to help identify the narrow and wide character sets
+  // NOTE: clang currently ignores -fexec-charset=. If this changes,
+  // then this may need to be updated.

NOTE -> FIXME


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100346/new/

https://reviews.llvm.org/D100346

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


[PATCH] D100378: [AST] Use IntrusiveRefCntPtr for Introspection LocationCall.

2021-04-13 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang/lib/Tooling/NodeIntrospection.cpp:60
+  if (LHS.first == RHS.first)
+return LHS.second->name() < RHS.second->name();
+  return LHS.first < RHS.first;

This is a slight change in behaviour, The old implementation used the operator< 
on a `std::shared_ptr`.
That in turns boils down to a comparison on the raw pointer, which is less than 
ideal.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100378/new/

https://reviews.llvm.org/D100378

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


[PATCH] D100368: [X86] Support some missing intrinsics

2021-04-13 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 added a comment.

In D100368#2685189 , @RKSimon wrote:

> Add _mm512_i32loscatter_epi64  and _mm512_mask_i32loscatter_epi64 for 
> completeness?

It seems we doesn't support KNCNI in LLVM. Am I right?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100368/new/

https://reviews.llvm.org/D100368

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


[PATCH] D98499: [clangd] Introduce ASTHooks to FeatureModules

2021-04-13 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/FeatureModule.h:106
+  struct ASTListener {
+virtual ~ASTListener() = default;
+

comment: listeners are destroyed once the AST is built.



Comment at: clang-tools-extra/clangd/FeatureModule.h:181
 
+/// Helper to get all the ast listeners available.
+std::vector>

this seems like a slightly weird thing to have in FeatureModule.h, I'd be 
tempted to inline it in the callsites instead, but up to you.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98499/new/

https://reviews.llvm.org/D98499

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


[PATCH] D100209: [OpenCL] Do not add builtins with unavailable types

2021-04-13 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:54
+// Extension associated to a type.
+class TypeExtension : AbstractExtension<_Ext>;
+

I am trying to understand why would we need a special abstraction for the type? 
Would it not be easier if we just guard the BIFs by the extensions that allow 
the use of the type? 

We would need to separate the definitions of course but this can be more 
helpful in order to understand what overloads are available conditionally?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100209/new/

https://reviews.llvm.org/D100209

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


[PATCH] D97764: [clang][patch] To solve PR26413, x86 interrupt routines may only call routines with no_saved_reg

2021-04-13 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

I received a bug report that this patch creates error diagnostics for calls to 
a builtin, like calling 'abort', 'exit' or one of the target builtins like 
__builtin_ia32_packssw then that call should be allowed without remark but this 
patch causes the compilation to fail.  We could require that all builtin's be 
declared with "no caller saved reg" but that's a big modification. I'm planning 
to make a change which igores builtin calls, but continue to error on any 
implicitly declared or user declared functions without the "no caller saved 
reg" attribute.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97764/new/

https://reviews.llvm.org/D97764

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


[PATCH] D100368: [X86] Support some missing intrinsics

2021-04-13 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D100368#2685559 , @LiuChen3 wrote:

> In D100368#2685189 , @RKSimon wrote:
>
>> Add _mm512_i32loscatter_epi64  and _mm512_mask_i32loscatter_epi64 for 
>> completeness?
>
> It seems we doesn't support KNCNI in LLVM. Am I right?

Correct. We do not support KNCI.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100368/new/

https://reviews.llvm.org/D100368

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


[PATCH] D89909: [SYCL] Implement SYCL address space attributes handling

2021-04-13 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/include/clang/AST/Type.h:488
(A == LangAS::opencl_global && (B == LangAS::opencl_global_device ||
B == LangAS::opencl_global_host)) ||
// Consider pointer size address spaces to be equivalent to default.

bader wrote:
> BTW, we need enable `global_device` and `global_host` attributes from 
> https://reviews.llvm.org/D82174 for SYCL USM feature. I have following 
> question regarding this: should I create a follow-up patch or we can enable 
> all attributes for SYCL at once?
It seems like they would just be extending the existing functionality and not 
redesigning what we do in this patch?

If that's the case let's keep it in a separate patch, but feel free to upload 
it even now.



Comment at: clang/lib/Basic/Targets/SPIR.h:129
+TargetInfo::adjust(Opts);
+setAddressSpaceMap(/*DefaultIsGeneric=*/Opts.SYCLIsDevice);
+  }

Anastasia wrote:
> Ok, do you still plan to add a `FIXME` as mentioned previously explaining why 
> we need to reset the map here?
Btw I was just thinking of another alternative here.

What do you think about just setting a value in `Default` AS entry then we 
wouldn't need any extra map at all in this case? So something like:


```
AddrSpaceMap[LangAS::Default] = AddrSpaceMap[LangAS::opencl_generic];
```
with a good explanation in `FIXME`? :)




Comment at: clang/test/CodeGenSYCL/convergent.cpp:2
 // RUN: %clang_cc1 -fsycl-is-device -emit-llvm -disable-llvm-passes \
-// RUN:  -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | \
 // RUN:   FileCheck %s

bader wrote:
> Anastasia wrote:
> > Is this change related? I thought we are not adding the environment 
> > component after all...
> > 
> >  
> > Is this change related? I thought we are not adding the environment 
> > component after all...
> 
> While I was removing `-sycldevice` environment component from the patch, I 
> noticed that one of the committed tests already uses it.
> https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenSYCL/convergent.cpp#L2
> 
> Do you want to me to create a separate review request for this change?
I see, this looks trivial enough test clean up. You could just commit it 
without any review perhaps?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89909/new/

https://reviews.llvm.org/D89909

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


[PATCH] D97669: [clang][AVR] Add avr-libc/include to clang system include paths

2021-04-13 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D97669#2678460 , @benshi001 wrote:

> In D97669#2676826 , @Anastasia wrote:
>
>> In D97669#2665865 , @benshi001 
>> wrote:
>>
>>> In D97669#2661560 , @Anastasia 
>>> wrote:
>>>
 Is `stdio.h`  used by anything?
>>>
>>> No. `stdio.h` is not used. But if I do `#include `, then 
>>> `-I /usr/lib/avr/include` must be specified in the command line option. 
>>> While avr-gcc does not reqiures that.
>>>
>>> I would like to keep clang & avr-gcc in the behaviour.
>>
>> Ok, do you plan to use it later? Then perhaps you should be adding it in the 
>> subsequent patches?
>
> No. No future pathes are needed. The avr-libc includes standard libc (headers 
> and libs) and avr specific headers and libs. This patch fixes all of these 
> issues. Both standard libc and avr platform specific libs can be used without 
> any explict command line option, just like avr-gcc does.

Ok, so your patch is adding the following file

`clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/include/stdio.h`

But it doesn't seem to be used at present? If you don't need it anywhere it 
should not be added.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97669/new/

https://reviews.llvm.org/D97669

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


[PATCH] D95976: [OpenMP] Simplify offloading parallel call codegen

2021-04-13 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
ggeorgakoudis updated this revision to Diff 337141.
ggeorgakoudis added a comment.
Herald added a subscriber: hiraditya.

Add tests, update OpenMPOpt, rebase to main


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95976/new/

https://reviews.llvm.org/D95976

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/OpenMP/nvptx_allocate_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/remarks_parallel_in_multiple_target_state_machines.c
  clang/test/OpenMP/remarks_parallel_in_target_state_machine.c
  clang/test/OpenMP/target_parallel_debug_codegen.cpp
  clang/test/OpenMP/target_parallel_for_debug_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
  openmp/libomptarget/deviceRTLs/common/src/parallel.cu
  openmp/libomptarget/deviceRTLs/common/src/support.cu
  openmp/libomptarget/deviceRTLs/common/support.h
  openmp/libomptarget/deviceRTLs/interface.h

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


[PATCH] D90157: [analyzer] Rework SValBuilder::evalCast function into maintainable and clear way

2021-04-13 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@NoQ

> Even though NFC commits don't require tests, this doesn't mean they shouldn't 
> add them!

While developing this, I wasn't able to reproduce any regression or unpassed 
cases on the projects from CodeChecker list (//Bitcoin_v0.20.1, 
Curl_curl-7_66_0, Memchached_1.6.8, OpenSSL_openssl-3.0.0-alpha7, etc.//) due 
to my platform. I use Windows and those projects either don't compile or need 
hard effort to set them up.
But anyway I was able to detect some different diagnostics in existing tests 
`casts.cpp` using Z3 refutation option. That actually helped to make 
corrections.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90157/new/

https://reviews.llvm.org/D90157

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


[PATCH] D97764: [clang][patch] To solve PR26413, x86 interrupt routines may only call routines with no_saved_reg

2021-04-13 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D97764#2685655 , @mibintc wrote:

> I received a bug report that this patch creates error diagnostics for calls 
> to a builtin, like calling 'abort', 'exit' or one of the target builtins like 
> __builtin_ia32_packssw then that call should be allowed without remark but 
> this patch causes the compilation to fail.  We could require that all 
> builtin's be declared with "no caller saved reg" but that's a big 
> modification. I'm planning to make a change which igores builtin calls, but 
> continue to error on any implicitly declared or user declared functions 
> without the "no caller saved reg" attribute.

Builtins like __builtin_ia32_packssw aren't usually called directly. The user 
should be calling the always_inline wrapper functions in x86intrin.h. Would 
that also fail?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97764/new/

https://reviews.llvm.org/D97764

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


[PATCH] D100209: [OpenCL] Do not add builtins with unavailable types

2021-04-13 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:54
+// Extension associated to a type.
+class TypeExtension : AbstractExtension<_Ext>;
+

Anastasia wrote:
> I am trying to understand why would we need a special abstraction for the 
> type? Would it not be easier if we just guard the BIFs by the extensions that 
> allow the use of the type? 
> 
> We would need to separate the definitions of course but this can be more 
> helpful in order to understand what overloads are available conditionally?
Yes, it is possible to achieve the same with the current `FunctionExtension` 
class.

However, that would require a lot of duplication in the Builtin descriptions, 
as for example many math builtins have overloads for `half` and `double` that 
will have to be conditionalized.  The purpose of `TypeExtension` is precisely 
to avoid separating and duplicating the definitions.  For example, `acos` is 
currently more or less defined as:

```
def FGenTypeN : GenericType<"FGenTypeN", TypeList<[Float, Double, Half]>, 
VecAndScalar>;
def : Builtin<"acos", [FGenTypeN, FGenTypeN], Attr.Const>;
```
with `double` and `half` conditionalization conveniently handled in a single 
place through a `TypeExtension`.

If we would only use `FunctionExtension`s, the definition would become more 
like the following:
```
def FGenTypeN : GenericType<"FGenTypeN", TypeList<[Float]>, VecAndScalar>;
def : Builtin<"acos", [FGenTypeN, FGenTypeN], Attr.Const>;

let Extension = Fp64 in {
  def DGenTypeN : GenericType<"DGenTypeN", TypeList<[Double]>, VecAndScalar>;
  def : Builtin<"acos", [DGenTypeN, DGenTypeN], Attr.Const>;
}

let Extension = Fp16 in {
  def HGenTypeN : GenericType<"HGenTypeN", TypeList<[Half]>, VecAndScalar>;
  def : Builtin<"acos", [HGenTypeN, HGenTypeN], Attr.Const>;
}
```

I personally don't think there is value in adding these explicit guards for 
every conditional builtin, as the duplication makes the definitions harder to 
maintain.  In addition, I expect it would also increase the size of the 
generated tables, as the `GenericType`s have to be split up (though I have not 
measured this).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100209/new/

https://reviews.llvm.org/D100209

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


[PATCH] D96090: [analyzer] Replace StoreManager::CastRetrievedVal with SValBuilder::evalCast

2021-04-13 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

> Already approved a month ago D97277  :-) 
> That's the next step.

In addition to the above:




Comment at: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:68
 
+// FIXME: This function should be eliminated and replaced with `evalCast`
 SVal SimpleSValBuilder::dispatchCast(SVal Val, QualType CastTy) {

@NoQ 
I've mentioned the need in elimination.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96090/new/

https://reviews.llvm.org/D96090

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


[PATCH] D100347: Fix the const overload of IgnoreExprNodes

2021-04-13 Thread Jesse Zhang via Phabricator via cfe-commits
d added a comment.

In D100347#2684934 , @gribozavr2 
wrote:

> Thanks for the fix! Do you have commit access?

Trying `arc land` I realize I do not...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100347/new/

https://reviews.llvm.org/D100347

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


[PATCH] D100347: Fix the const overload of IgnoreExprNodes

2021-04-13 Thread Jesse Zhang via Phabricator via cfe-commits
d added a comment.

@gribozavr2 it's also unclear to me where the tests for this are so I couldn't 
add a new test, is that OK?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100347/new/

https://reviews.llvm.org/D100347

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


[PATCH] D100368: [X86] Support some missing intrinsics

2021-04-13 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

That's why I said "completeness" :)




Comment at: clang/lib/Headers/avx512fintrin.h:9692
+   (scale))
+/// Stores 8 packed double-precision (64-bit) floating-point elements in \a v1
+/// to memory locations starting at location \a base_addr at packed 32-bit

Newline between instructions


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100368/new/

https://reviews.llvm.org/D100368

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


[PATCH] D100347: Fix the const overload of IgnoreExprNodes

2021-04-13 Thread Jesse Zhang via Phabricator via cfe-commits
d added a comment.

More importantly, the bug exists in LLVM 12, what is the policy of patching the 
back branches in this project?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100347/new/

https://reviews.llvm.org/D100347

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


[PATCH] D100161: Redistribute energy for Corpus

2021-04-13 Thread taotao gu via Phabricator via cfe-commits
gtt1995 added a comment.

Maybe uniform-random approach change efficacy!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100161/new/

https://reviews.llvm.org/D100161

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


[PATCH] D97764: [clang][patch] To solve PR26413, x86 interrupt routines may only call routines with no_saved_reg

2021-04-13 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

In D97764#2685742 , @craig.topper 
wrote:

> In D97764#2685655 , @mibintc wrote:
>
>> I received a bug report that this patch creates error diagnostics for calls 
>> to a builtin, like calling 'abort', 'exit' or one of the target builtins 
>> like __builtin_ia32_packssw then that call should be allowed without remark 
>> but this patch causes the compilation to fail.  We could require that all 
>> builtin's be declared with "no caller saved reg" but that's a big 
>> modification. I'm planning to make a change which igores builtin calls, but 
>> continue to error on any implicitly declared or user declared functions 
>> without the "no caller saved reg" attribute.
>
> Builtins like __builtin_ia32_packssw aren't usually called directly. The user 
> should be calling the always_inline wrapper functions in x86intrin.h. Would 
> that also fail?

Thanks for the suggestion Craig!  I could change the check to look for 
"always_inline" [that means they're always inlined and the call would never be 
created even with optimization disabled right? ] However, I don't see 
_builtin_ia32_packssw declared in .  In immintrin it is declared 
implicitly when the usage is seen for example 
_mm_packs_pi16(__m64 __m1, __m64 __m2)
{

  return (__m64)__builtin_ia32_packsswb((__v4hi)__m1, (__v4hi)__m2);

}

Is it a bug that __builtin_ia32_packsswb is omitted from the x86intrin 
declarations? Is there some tricky reason it's not declared?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97764/new/

https://reviews.llvm.org/D97764

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


[PATCH] D97764: [clang][patch] To solve PR26413, x86 interrupt routines may only call routines with no_saved_reg

2021-04-13 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D97764#2685841 , @mibintc wrote:

> In D97764#2685742 , @craig.topper 
> wrote:
>
>> In D97764#2685655 , @mibintc wrote:
>>
>>> I received a bug report that this patch creates error diagnostics for calls 
>>> to a builtin, like calling 'abort', 'exit' or one of the target builtins 
>>> like __builtin_ia32_packssw then that call should be allowed without remark 
>>> but this patch causes the compilation to fail.  We could require that all 
>>> builtin's be declared with "no caller saved reg" but that's a big 
>>> modification. I'm planning to make a change which igores builtin calls, but 
>>> continue to error on any implicitly declared or user declared functions 
>>> without the "no caller saved reg" attribute.
>>
>> Builtins like __builtin_ia32_packssw aren't usually called directly. The 
>> user should be calling the always_inline wrapper functions in x86intrin.h. 
>> Would that also fail?
>
> Thanks for the suggestion Craig!  I could change the check to look for 
> "always_inline" [that means they're always inlined and the call would never 
> be created even with optimization disabled right? ] However, I don't see 
> _builtin_ia32_packssw declared in .  In immintrin it is declared 
> implicitly when the usage is seen for example 
> _mm_packs_pi16(__m64 __m1, __m64 __m2)
> {
>
>   return (__m64)__builtin_ia32_packsswb((__v4hi)__m1, (__v4hi)__m2);
>
> }
>
> Is it a bug that __builtin_ia32_packsswb is omitted from the x86intrin 
> declarations? Is there some tricky reason it's not declared?

__builtin_ia32* are always defined for the X86 target as they are part of the 
compiler. They are defined in clang/include/clang/Basic/BuiltinsX86.def and 
clang/include/clang/Basic/BuiltinsX86_64.def


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97764/new/

https://reviews.llvm.org/D97764

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


[PATCH] D100388: [BROKEN][clang] Try to fix thunk function types

2021-04-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri created this revision.
lebedev.ri added a reviewer: rsmith.
lebedev.ri added a project: LLVM.
Herald added subscribers: dexonsmith, cryptoad, mgorny, dschuff.
Herald added a reviewer: alexshap.
lebedev.ri requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1, aheejin.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

@rsmith this seems to work on the two testcases from D99790 
,
but apparently doesn't work on many more tests.
I don't know what i'm doing here.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100388

Files:
  clang/include/clang/AST/GlobalDecl.h
  clang/include/clang/AST/VTableBuilder.h
  clang/include/clang/Basic/ABI.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Mangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/VTableBuilder.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGenCXX/thunk-linkonce-odr.cpp
  clang/test/CodeGenCXX/thunk-returning-memptr.cpp
  clang/test/CodeGenCXX/thunk-wrong-return-type.cpp
  clang/test/CodeGenCXX/thunk-wrong-this.cpp
  llvm/CMakeLists.txt.user.WORKING

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


[PATCH] D96090: [analyzer] Replace StoreManager::CastRetrievedVal with SValBuilder::evalCast

2021-04-13 Thread Denys Petrov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7736b08c2872: [analyzer] Replace 
StoreManager::CastRetrievedVal with SValBuilder::evalCast (authored by 
ASDenysPetrov).

Changed prior to commit:
  https://reviews.llvm.org/D96090?vs=329982&id=337153#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96090/new/

https://reviews.llvm.org/D96090

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/Store.cpp

Index: clang/lib/StaticAnalyzer/Core/Store.cpp
===
--- clang/lib/StaticAnalyzer/Core/Store.cpp
+++ clang/lib/StaticAnalyzer/Core/Store.cpp
@@ -394,48 +394,6 @@
   return UnknownVal();
 }
 
-static bool hasSameUnqualifiedPointeeType(QualType ty1, QualType ty2) {
-  return ty1->getPointeeType().getCanonicalType().getTypePtr() ==
- ty2->getPointeeType().getCanonicalType().getTypePtr();
-}
-
-/// CastRetrievedVal - Used by subclasses of StoreManager to implement
-///  implicit casts that arise from loads from regions that are reinterpreted
-///  as another region.
-SVal StoreManager::CastRetrievedVal(SVal V, const TypedValueRegion *R,
-QualType castTy) {
-  if (castTy.isNull() || V.isUnknownOrUndef())
-return V;
-
-  // The dispatchCast() call below would convert the int into a float.
-  // What we want, however, is a bit-by-bit reinterpretation of the int
-  // as a float, which usually yields nothing garbage. For now skip casts
-  // from ints to floats.
-  // TODO: What other combinations of types are affected?
-  if (castTy->isFloatingType()) {
-SymbolRef Sym = V.getAsSymbol();
-if (Sym && !Sym->getType()->isFloatingType())
-  return UnknownVal();
-  }
-
-  // When retrieving symbolic pointer and expecting a non-void pointer,
-  // wrap them into element regions of the expected type if necessary.
-  // SValBuilder::dispatchCast() doesn't do that, but it is necessary to
-  // make sure that the retrieved value makes sense, because there's no other
-  // cast in the AST that would tell us to cast it to the correct pointer type.
-  // We might need to do that for non-void pointers as well.
-  // FIXME: We really need a single good function to perform casts for us
-  // correctly every time we need it.
-  if (castTy->isPointerType() && !castTy->isVoidPointerType())
-if (const auto *SR = dyn_cast_or_null(V.getAsRegion())) {
-  QualType sr = SR->getSymbol()->getType();
-  if (!hasSameUnqualifiedPointeeType(sr, castTy))
-  return loc::MemRegionVal(castRegion(SR, castTy));
-}
-
-  return svalBuilder.dispatchCast(V, castTy);
-}
-
 SVal StoreManager::getLValueFieldOrIvar(const Decl *D, SVal Base) {
   if (Base.isUnknownOrUndef())
 return Base;
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -65,12 +65,12 @@
 // Transfer function for Casts.
 //===--===//
 
+// FIXME: This function should be eliminated and replaced with `evalCast`
 SVal SimpleSValBuilder::dispatchCast(SVal Val, QualType CastTy) {
-  assert(Val.getAs() || Val.getAs());
-  return Val.getAs() ? evalCastFromLoc(Val.castAs(), CastTy)
-   : evalCastFromNonLoc(Val.castAs(), CastTy);
+  return evalCast(Val, CastTy, QualType{});
 }
 
+// FIXME: This function should be eliminated and replaced with `evalCast`
 SVal SimpleSValBuilder::evalCastFromNonLoc(NonLoc val, QualType castTy) {
   bool isLocType = Loc::isLocType(castTy);
   if (val.getAs())
@@ -127,6 +127,7 @@
 return makeIntVal(i);
 }
 
+// FIXME: This function should be eliminated and replaced with `evalCast`
 SVal SimpleSValBuilder::evalCastFromLoc(Loc val, QualType castTy) {
 
   // Casts from pointers -> pointers, just return the lval.
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -544,20 +544,39 @@
 // `evalCastKind` and `evalCastSubKind` are helpers
 //===--===//
 
+/// Cast a given SVal to another SVal using given QualType's.
+/// \param V -- SVal that should be casted.
+/// \param CastTy -- QualType that V should be casted according to.
+/// \param OriginalTy -- QualType which is associated to V. It provides
+/// additional information about what type the cast performs from.
+/// \returns the most appropriate casted SVal.
+/// Note: Ma

[clang] 7736b08 - [analyzer] Replace StoreManager::CastRetrievedVal with SValBuilder::evalCast

2021-04-13 Thread Denys Petrov via cfe-commits

Author: Denys Petrov
Date: 2021-04-13T18:10:06+03:00
New Revision: 7736b08c287274361f2cdf13512015708af4d335

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

LOG: [analyzer] Replace StoreManager::CastRetrievedVal with 
SValBuilder::evalCast

Summary: Move logic from CastRetrievedVal to evalCast and replace 
CastRetrievedVal with evalCast. Also move guts from 
SimpleSValBuilder::dispatchCast inside evalCast.
evalCast intends to substitute dispatchCast, evalCastFromNonLoc and 
evalCastFromLoc in the future. OriginalTy provides additional information for 
casting, which is useful for some cases and useless for others.  If 
`OriginalTy.isNull()` is true, then cast performs based on CastTy only. Now 
evalCast operates in two ways. It retains all previous behavior and take over 
dispatchCast behavior. dispatchCast, evalCastFromNonLoc and evalCastFromLoc is 
considered as buggy since it doesn't take into account OriginalTy of the SVal 
and should be improved.

>From this patch use evalCast instead of dispatchCast, evalCastFromNonLoc and 
>evalCastFromLoc functions. dispatchCast redirects to evalCast.

This patch shall not change any behavior.

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
clang/lib/StaticAnalyzer/Core/RegionStore.cpp
clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
clang/lib/StaticAnalyzer/Core/Store.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
index c3b590e4784e4..947913ae4eee9 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
@@ -280,12 +280,6 @@ class StoreManager {
  QualType pointeeTy,
  uint64_t index = 0);
 
-  /// CastRetrievedVal - Used by subclasses of StoreManager to implement
-  ///  implicit casts that arise from loads from regions that are reinterpreted
-  ///  as another region.
-  SVal CastRetrievedVal(SVal val, const TypedValueRegion *region,
-QualType castTy);
-
 private:
   SVal getLValueFieldOrIvar(const Decl *decl, SVal base);
 };

diff  --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp 
b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index 5acc51674e9a6..4ffa1aacb41fa 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -1478,7 +1478,7 @@ SVal 
RegionStoreManager::getBinding(RegionBindingsConstRef B, Loc L, QualType T)
 return UnknownVal();
 
   if (const FieldRegion* FR = dyn_cast(R))
-return CastRetrievedVal(getBindingForField(B, FR), FR, T);
+return svalBuilder.evalCast(getBindingForField(B, FR), T, QualType{});
 
   if (const ElementRegion* ER = dyn_cast(R)) {
 // FIXME: Here we actually perform an implicit conversion from the loaded
@@ -1486,7 +1486,7 @@ SVal 
RegionStoreManager::getBinding(RegionBindingsConstRef B, Loc L, QualType T)
 // more intelligently.  For example, an 'element' can encompass multiple
 // bound regions (e.g., several bound bytes), or could be a subset of
 // a larger value.
-return CastRetrievedVal(getBindingForElement(B, ER), ER, T);
+return svalBuilder.evalCast(getBindingForElement(B, ER), T, QualType{});
   }
 
   if (const ObjCIvarRegion *IVR = dyn_cast(R)) {
@@ -1496,7 +1496,7 @@ SVal 
RegionStoreManager::getBinding(RegionBindingsConstRef B, Loc L, QualType T)
 // reinterpretted, it is possible we stored a 
diff erent value that could
 // fit within the ivar.  Either we need to cast these when storing them
 // or reinterpret them lazily (as we do here).
-return CastRetrievedVal(getBindingForObjCIvar(B, IVR), IVR, T);
+return svalBuilder.evalCast(getBindingForObjCIvar(B, IVR), T, QualType{});
   }
 
   if (const VarRegion *VR = dyn_cast(R)) {
@@ -1506,7 +1506,7 @@ SVal 
RegionStoreManager::getBinding(RegionBindingsConstRef B, Loc L, QualType T)
 // variable is reinterpretted, it is possible we stored a 
diff erent value
 // that could fit within the variable.  Either we need to cast these when
 // storing them or reinterpret them lazily (as we do here).
-return CastRetrievedVal(getBindingForVar(B, VR), VR, T);
+return svalBuilder.evalCast(getBindingForVar(B, VR), T, QualType{});
   }
 
   const SVal *V = B.lookup(R, BindingKey::Direct);

diff  --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
index 9942b7e1423cf..9a9edb25f2d77 100644
--- a/clang/lib/StaticAnalyzer

[PATCH] D99568: [clang][invocation] Fix copy constructor, add copy assignment to CompilerInvocation

2021-04-13 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 337155.
jansvoboda11 added a comment.

Remove copy-assignment changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99568/new/

https://reviews.llvm.org/D99568

Files:
  clang/include/clang/Frontend/CompilerInvocation.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/unittests/Frontend/CompilerInvocationTest.cpp


Index: clang/unittests/Frontend/CompilerInvocationTest.cpp
===
--- clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -97,6 +97,18 @@
   ASSERT_THAT(Array, ContainsN(StrEq("x"), 2));
 }
 
+// Copy constructor performs a deep copy of reference-counted pointers.
+
+TEST(CompilerInvocationTest, DeepCopyConstructor) {
+  CompilerInvocation A;
+  A.getAnalyzerOpts()->Config["Key"] = "Old";
+
+  CompilerInvocation B(A);
+  B.getAnalyzerOpts()->Config["Key"] = "New";
+
+  ASSERT_EQ(A.getAnalyzerOpts()->Config["Key"], "Old");
+}
+
 // Boolean option with a keypath that defaults to true.
 // The only flag with a negative spelling can set the keypath to false.
 
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -113,14 +113,16 @@
 : LangOpts(new LangOptions()), TargetOpts(new TargetOptions()),
   DiagnosticOpts(new DiagnosticOptions()),
   HeaderSearchOpts(new HeaderSearchOptions()),
-  PreprocessorOpts(new PreprocessorOptions()) {}
+  PreprocessorOpts(new PreprocessorOptions()),
+  AnalyzerOpts(new AnalyzerOptions()) {}
 
 CompilerInvocationBase::CompilerInvocationBase(const CompilerInvocationBase &X)
 : LangOpts(new LangOptions(*X.getLangOpts())),
   TargetOpts(new TargetOptions(X.getTargetOpts())),
   DiagnosticOpts(new DiagnosticOptions(X.getDiagnosticOpts())),
   HeaderSearchOpts(new HeaderSearchOptions(X.getHeaderSearchOpts())),
-  PreprocessorOpts(new PreprocessorOptions(X.getPreprocessorOpts())) {}
+  PreprocessorOpts(new PreprocessorOptions(X.getPreprocessorOpts())),
+  AnalyzerOpts(new AnalyzerOptions(*X.getAnalyzerOpts())) {}
 
 CompilerInvocationBase::~CompilerInvocationBase() = default;
 
Index: clang/include/clang/Frontend/CompilerInvocation.h
===
--- clang/include/clang/Frontend/CompilerInvocation.h
+++ clang/include/clang/Frontend/CompilerInvocation.h
@@ -78,6 +78,9 @@
   /// Options controlling the preprocessor (aside from \#include handling).
   std::shared_ptr PreprocessorOpts;
 
+  /// Options controlling the static analyzer.
+  AnalyzerOptionsRef AnalyzerOpts;
+
   CompilerInvocationBase();
   CompilerInvocationBase(const CompilerInvocationBase &X);
   CompilerInvocationBase &operator=(const CompilerInvocationBase &) = delete;
@@ -110,6 +113,8 @@
   const PreprocessorOptions &getPreprocessorOpts() const {
 return *PreprocessorOpts;
   }
+
+  AnalyzerOptionsRef getAnalyzerOpts() const { return AnalyzerOpts; }
 };
 
 /// Helper class for holding the data necessary to invoke the compiler.
@@ -118,9 +123,6 @@
 /// compiler, including data such as the include paths, the code generation
 /// options, the warning flags, and so on.
 class CompilerInvocation : public CompilerInvocationBase {
-  /// Options controlling the static analyzer.
-  AnalyzerOptionsRef AnalyzerOpts;
-
   MigratorOptions MigratorOpts;
 
   /// Options controlling IRgen and the backend.
@@ -139,8 +141,6 @@
   PreprocessorOutputOptions PreprocessorOutputOpts;
 
 public:
-  CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {}
-
   /// @name Utility Methods
   /// @{
 
@@ -203,8 +203,6 @@
   /// @name Option Subgroups
   /// @{
 
-  AnalyzerOptionsRef getAnalyzerOpts() const { return AnalyzerOpts; }
-
   MigratorOptions &getMigratorOpts() { return MigratorOpts; }
   const MigratorOptions &getMigratorOpts() const { return MigratorOpts; }
 


Index: clang/unittests/Frontend/CompilerInvocationTest.cpp
===
--- clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -97,6 +97,18 @@
   ASSERT_THAT(Array, ContainsN(StrEq("x"), 2));
 }
 
+// Copy constructor performs a deep copy of reference-counted pointers.
+
+TEST(CompilerInvocationTest, DeepCopyConstructor) {
+  CompilerInvocation A;
+  A.getAnalyzerOpts()->Config["Key"] = "Old";
+
+  CompilerInvocation B(A);
+  B.getAnalyzerOpts()->Config["Key"] = "New";
+
+  ASSERT_EQ(A.getAnalyzerOpts()->Config["Key"], "Old");
+}
+
 // Boolean option with a keypath that defaults to true.
 // The only flag with a negative spelling can set the keypath to false.
 
Index: clang/lib/Frontend/CompilerInvocation.cpp
==

[PATCH] D100346: [Clang] String Literal and Wide String Literal Encoding from the Preprocessor

2021-04-13 Thread ThePhD via Phabricator via cfe-commits
ThePhD updated this revision to Diff 337158.
ThePhD added a comment.

Change `NOTE:` to `FIXME:`.

Update the text for the documentation to be more explicit.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100346/new/

https://reviews.llvm.org/D100346

Files:
  clang/docs/LanguageExtensions.rst
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/init-x86.c
  clang/test/Preprocessor/init.c


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -115,10 +115,12 @@
 // COMMON:#define __STDC__ 1
 // COMMON:#define __VERSION__ {{.*}}
 // COMMON:#define __clang__ 1
+// COMMON:#define __clang_literal_encoding__ {{.*}}
 // COMMON:#define __clang_major__ {{[0-9]+}}
 // COMMON:#define __clang_minor__ {{[0-9]+}}
 // COMMON:#define __clang_patchlevel__ {{[0-9]+}}
 // COMMON:#define __clang_version__ {{.*}}
+// COMMON:#define __clang_wide_literal_encoding__ {{.*}}
 // COMMON:#define __llvm__ 1
 //
 // RUN: %clang_cc1 -E -dM -triple=x86_64-pc-win32 < /dev/null | FileCheck 
-match-full-lines -check-prefix C-DEFAULT %s
@@ -1844,10 +1846,12 @@
 // WEBASSEMBLY-NOT:#define __WINT_UNSIGNED__
 // WEBASSEMBLY-NEXT:#define __WINT_WIDTH__ 32
 // WEBASSEMBLY-NEXT:#define __clang__ 1
+// WEBASSEMBLY-NEXT:#define __clang_literal_encoding__ {{.*}}
 // WEBASSEMBLY-NEXT:#define __clang_major__ {{.*}}
 // WEBASSEMBLY-NEXT:#define __clang_minor__ {{.*}}
 // WEBASSEMBLY-NEXT:#define __clang_patchlevel__ {{.*}}
 // WEBASSEMBLY-NEXT:#define __clang_version__ "{{.*}}"
+// WEBASSEMBLY-NEXT:#define __clang_wide_literal_encoding__ {{.*}}
 // WEBASSEMBLY-NEXT:#define __llvm__ 1
 // WEBASSEMBLY-NOT:#define __unix
 // WEBASSEMBLY-NOT:#define __unix__
Index: clang/test/Preprocessor/init-x86.c
===
--- clang/test/Preprocessor/init-x86.c
+++ clang/test/Preprocessor/init-x86.c
@@ -1306,10 +1306,12 @@
 // X86_64-CLOUDABI:#define __amd64 1
 // X86_64-CLOUDABI:#define __amd64__ 1
 // X86_64-CLOUDABI:#define __clang__ 1
+// X86_64-CLOUDABI:#define __clang_literal_encoding__ {{.*}}
 // X86_64-CLOUDABI:#define __clang_major__ {{.*}}
 // X86_64-CLOUDABI:#define __clang_minor__ {{.*}}
 // X86_64-CLOUDABI:#define __clang_patchlevel__ {{.*}}
 // X86_64-CLOUDABI:#define __clang_version__ {{.*}}
+// X86_64-CLOUDABI:#define __clang_wide_literal_encoding__ {{.*}}
 // X86_64-CLOUDABI:#define __llvm__ 1
 // X86_64-CLOUDABI:#define __x86_64 1
 // X86_64-CLOUDABI:#define __x86_64__ 1
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -778,6 +778,21 @@
 }
   }
 
+  // Macros to help identify the narrow and wide character sets
+  // FIXME: clang currently ignores -fexec-charset=. If this changes,
+  // then this may need to be updated.
+  Builder.defineMacro("__clang_literal_encoding__", "\"UTF-8\"");
+  if (TI.getTypeWidth(TI.getWCharType()) >= 32) {
+// FIXME: 32-bit wchar_t signals UTF-32. This may change
+// if -fwide-exec-charset= is ever supported.
+Builder.defineMacro("__clang_wide_literal_encoding__", "\"UTF-32\"");
+  } else {
+// FIXME: Less-than 32-bit wchar_t generally means UTF-16
+// (e.g., Windows, 32-bit IBM). This may need to be
+// updated if -fwide-exec-charset= is ever supported.
+Builder.defineMacro("__clang_wide_literal_encoding__", "\"UTF-16\"");
+  }
+
   if (LangOpts.Optimize)
 Builder.defineMacro("__OPTIMIZE__");
   if (LangOpts.OptimizeSize)
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -383,6 +383,18 @@
   Defined to a string that captures the Clang marketing version, including the
   Subversion tag or revision number, e.g., "``1.5 (trunk 102332)``".
 
+``__clang_literal_encoding__``
+  Defined to a narrow string literal that represents the current encoding of
+  narrow string literals, e.g., ``"hello"``. This macro typically expands to
+  "UTF-8" (but may change in the future if the
+  ``-fexec-charset="Encoding-Name"`` option is implemented.)
+
+``__clang_wide_literal_encoding__``
+  Defined to a narrow string literal that represents the current encoding of
+  wide string literals, e.g., ``L"hello"``. This is typically "UTF-16" or
+  "UTF-32" (but may change in the future if the
+  ``-fwide-exec-charset="Encoding-Name"`` option is implemented.)
+
 .. _langext-vectors:
 
 Vectors and Extended Vectors


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -115,10 +115,12 @@
 // COMMON:#define __STDC__ 1
 // COMMON:#define __VERSION__ {{.*}}
 // COMMON:#define __clang__ 1
+// COMMON:#de

[PATCH] D89013: [libcxx] Support per-target __config_site in per-target runtime build

2021-04-13 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 337166.
phosek edited the summary of this revision.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89013/new/

https://reviews.llvm.org/D89013

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  
clang/test/Driver/Inputs/basic_fuchsia_tree/include/aarch64-unknown-fuchsia/c++/v1/.keep
  
clang/test/Driver/Inputs/basic_fuchsia_tree/include/riscv64-unknown-fuchsia/c++/v1/.keep
  
clang/test/Driver/Inputs/basic_fuchsia_tree/include/x86_64-unknown-fuchsia/c++/v1/.keep
  
clang/test/Driver/Inputs/basic_linux_libcxx_tree/usr/include/x86_64-linux-gnu/c++/v1/.keep
  
clang/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/include/x86_64-linux-gnu/c++/v2/.keep
  
clang/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/x86_64-linux-gnu/c++/v2/.keep
  clang/test/Driver/fuchsia.cpp
  clang/test/Driver/linux-header-search.cpp
  libcxx/CMakeLists.txt
  libcxx/benchmarks/CMakeLists.txt
  libcxx/include/CMakeLists.txt

Index: libcxx/include/CMakeLists.txt
===
--- libcxx/include/CMakeLists.txt
+++ libcxx/include/CMakeLists.txt
@@ -200,9 +200,9 @@
   wctype.h
   )
 
-configure_file("__config_site.in" "${LIBCXX_GENERATED_INCLUDE_DIR}/__config_site" @ONLY)
+configure_file("__config_site.in" "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site" @ONLY)
 
-set(_all_includes "${LIBCXX_GENERATED_INCLUDE_DIR}/__config_site")
+set(_all_includes "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site")
 foreach(f ${files})
   set(src "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
   set(dst "${LIBCXX_GENERATED_INCLUDE_DIR}/${f}")
@@ -219,24 +219,26 @@
 add_dependencies(cxx-headers generate-cxx-headers ${LIBCXX_CXX_ABI_HEADER_TARGET})
 # TODO: Use target_include_directories once we figure out why that breaks the runtimes build
 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
-  target_compile_options(cxx-headers INTERFACE /I "${LIBCXX_GENERATED_INCLUDE_DIR}")
+  target_compile_options(cxx-headers INTERFACE /I "${LIBCXX_GENERATED_INCLUDE_DIR}"
+ INTERFACE /I "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}")
 else()
-  target_compile_options(cxx-headers INTERFACE -I "${LIBCXX_GENERATED_INCLUDE_DIR}")
+  target_compile_options(cxx-headers INTERFACE -I${LIBCXX_GENERATED_INCLUDE_DIR}
+ INTERFACE -I${LIBCXX_GENERATED_INCLUDE_TARGET_DIR})
 endif()
 
 if (LIBCXX_INSTALL_HEADERS)
   foreach(file ${files})
 get_filename_component(dir ${file} DIRECTORY)
 install(FILES ${file}
-  DESTINATION include/c++/v1/${dir}
+  DESTINATION ${LIBCXX_INSTALL_INCLUDE_DIR}/${dir}
   COMPONENT cxx-headers
   PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
 )
   endforeach()
 
   # Install the generated __config_site.
-  install(FILES ${LIBCXX_GENERATED_INCLUDE_DIR}/__config_site
-DESTINATION include/c++/v1
+  install(FILES ${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site
+DESTINATION ${LIBCXX_INSTALL_INCLUDE_TARGET_DIR}
 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
 COMPONENT cxx-headers)
 
Index: libcxx/benchmarks/CMakeLists.txt
===
--- libcxx/benchmarks/CMakeLists.txt
+++ libcxx/benchmarks/CMakeLists.txt
@@ -15,6 +15,10 @@
 -Wl,-rpath,${LIBCXX_LIBRARY_DIR}
 ${SANITIZER_FLAGS}
 )
+if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+  list(APPEND BENCHMARK_LIBCXX_COMPILE_FLAGS
+-isystem "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}")
+endif()
 if (DEFINED LIBCXX_CXX_ABI_LIBRARY_PATH)
   list(APPEND BENCHMARK_LIBCXX_COMPILE_FLAGS
   -L${LIBCXX_CXX_ABI_LIBRARY_PATH}
Index: libcxx/CMakeLists.txt
===
--- libcxx/CMakeLists.txt
+++ libcxx/CMakeLists.txt
@@ -408,7 +408,10 @@
 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
   set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
   set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
+  set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
   set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
+  set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1")
+  set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
   if(LIBCXX_LIBDIR_SUBDIR)
 string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
 string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR})
@@ -416,11 +419,17 @@
 elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
   set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
   set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
+  set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}")
   set(LIBCXX_IN

[PATCH] D98499: [clangd] Introduce ASTHooks to FeatureModules

2021-04-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 337168.
kadircet marked 2 inline comments as done.
kadircet added a comment.

- Inline helper to call-sites
- Add comments about destruction of ast listeners.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98499/new/

https://reviews.llvm.org/D98499

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/FeatureModule.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h

Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -19,12 +19,14 @@
 
 #include "../TidyProvider.h"
 #include "Compiler.h"
+#include "FeatureModule.h"
 #include "ParsedAST.h"
 #include "TestFS.h"
 #include "index/Index.h"
 #include "support/Path.h"
 #include "llvm/ADT/StringMap.h"
 #include "gtest/gtest.h"
+#include 
 #include 
 #include 
 #include 
@@ -76,6 +78,8 @@
   // to eliminate this option some day.
   bool OverlayRealFileSystemForModules = false;
 
+  FeatureModuleSet *FeatureModules = nullptr;
+
   // By default, build() will report Error diagnostics as GTest errors.
   // Suppress this behavior by adding an 'error-ok' comment to the code.
   // The result will always have getDiagnostics() populated.
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -36,6 +36,7 @@
   FS.Files[ImportThunk] = ThunkContents;
 
   ParseInputs Inputs;
+  Inputs.FeatureModules = FeatureModules;
   auto &Argv = Inputs.CompileCommand.CommandLine;
   Argv = {"clang"};
   // FIXME: this shouldn't need to be conditional, but it breaks a
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -9,6 +9,7 @@
 #include "Annotations.h"
 #include "Config.h"
 #include "Diagnostics.h"
+#include "FeatureModule.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "SourceCode.h"
@@ -26,6 +27,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -1346,6 +1348,31 @@
  });
 }
 
+TEST(ParsedASTTest, ModuleSawDiag) {
+  static constexpr const llvm::StringLiteral KDiagMsg = "StampedDiag";
+  struct DiagModifierModule final : public FeatureModule {
+struct Listener : public FeatureModule::ASTListener {
+  void sawDiagnostic(const clang::Diagnostic &Info,
+ clangd::Diag &Diag) override {
+Diag.Message = KDiagMsg.str();
+  }
+};
+std::unique_ptr astListeners() override {
+  return std::make_unique();
+};
+  };
+  FeatureModuleSet FMS;
+  FMS.add(std::make_unique());
+
+  Annotations Code("[[test]]; /* error-ok */");
+  TestTU TU;
+  TU.Code = Code.code().str();
+  TU.FeatureModules = &FMS;
+
+  auto AST = TU.build();
+  EXPECT_THAT(*AST.getDiagnostics(),
+  testing::Contains(Diag(Code.range(), KDiagMsg.str(;
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
@@ -365,6 +365,27 @@
   // And immediately shut down. FeatureModule destructor verifies we blocked.
 }
 
+TEST_F(LSPTest, DiagModuleTest) {
+  static constexpr llvm::StringLiteral DiagMsg = "DiagMsg";
+  class DiagModule final : public FeatureModule {
+struct DiagHooks : public ASTListener {
+  void sawDiagnostic(const clang::Diagnostic &, clangd::Diag &D) override {
+D.Message = DiagMsg.str();
+  }
+};
+
+  public:
+std::unique_ptr astListeners() override {
+  return std::make_unique();
+}
+  };
+  FeatureModules.add(std::make_unique());
+
+  auto &Client = start();
+  Client.didOpen("foo.cpp", "test;");
+  EXPECT_THAT(Client.diagnostics("foo.cpp"),
+  llvm::ValueIs(testing::ElementsAre(DiagMessage(DiagMsg;
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/c

[PATCH] D100209: [OpenCL] Do not add builtins with unavailable types

2021-04-13 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:54
+// Extension associated to a type.
+class TypeExtension : AbstractExtension<_Ext>;
+

svenvh wrote:
> Anastasia wrote:
> > I am trying to understand why would we need a special abstraction for the 
> > type? Would it not be easier if we just guard the BIFs by the extensions 
> > that allow the use of the type? 
> > 
> > We would need to separate the definitions of course but this can be more 
> > helpful in order to understand what overloads are available conditionally?
> Yes, it is possible to achieve the same with the current `FunctionExtension` 
> class.
> 
> However, that would require a lot of duplication in the Builtin descriptions, 
> as for example many math builtins have overloads for `half` and `double` that 
> will have to be conditionalized.  The purpose of `TypeExtension` is precisely 
> to avoid separating and duplicating the definitions.  For example, `acos` is 
> currently more or less defined as:
> 
> ```
> def FGenTypeN : GenericType<"FGenTypeN", TypeList<[Float, Double, Half]>, 
> VecAndScalar>;
> def : Builtin<"acos", [FGenTypeN, FGenTypeN], Attr.Const>;
> ```
> with `double` and `half` conditionalization conveniently handled in a single 
> place through a `TypeExtension`.
> 
> If we would only use `FunctionExtension`s, the definition would become more 
> like the following:
> ```
> def FGenTypeN : GenericType<"FGenTypeN", TypeList<[Float]>, VecAndScalar>;
> def : Builtin<"acos", [FGenTypeN, FGenTypeN], Attr.Const>;
> 
> let Extension = Fp64 in {
>   def DGenTypeN : GenericType<"DGenTypeN", TypeList<[Double]>, VecAndScalar>;
>   def : Builtin<"acos", [DGenTypeN, DGenTypeN], Attr.Const>;
> }
> 
> let Extension = Fp16 in {
>   def HGenTypeN : GenericType<"HGenTypeN", TypeList<[Half]>, VecAndScalar>;
>   def : Builtin<"acos", [HGenTypeN, HGenTypeN], Attr.Const>;
> }
> ```
> 
> I personally don't think there is value in adding these explicit guards for 
> every conditional builtin, as the duplication makes the definitions harder to 
> maintain.  In addition, I expect it would also increase the size of the 
> generated tables, as the `GenericType`s have to be split up (though I have 
> not measured this).
Ok I see. Yeah it looks quite a lot of duplication indeed for some types. 
However, this patch provides extra flexibility and doesn't enforce to use the 
new approach evrywhere so I think it is very reasonable.

Could you just provide a bit more documentation and especially the difference 
to the other approach here?

Do you think it is work extending the online documentation for that too?



Comment at: clang/lib/Sema/SemaLookup.cpp:762
 
+  if (RetTypes.size() == 0)
+return;

This deserved the comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100209/new/

https://reviews.llvm.org/D100209

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


[clang-tools-extra] bce3ac4 - [clangd] Introduce ASTHooks to FeatureModules

2021-04-13 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-04-13T17:45:09+02:00
New Revision: bce3ac4f224aa7da0b253852ce8a28ad5a39c31f

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

LOG: [clangd] Introduce ASTHooks to FeatureModules

These can be invoked at different stages while building an AST to let
FeatureModules implement features on top of it. The patch also
introduces a sawDiagnostic hook, which can mutate the final clangd::Diag
while reading a clang::Diagnostic.

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

Added: 


Modified: 
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/Compiler.h
clang-tools-extra/clangd/Diagnostics.cpp
clang-tools-extra/clangd/Diagnostics.h
clang-tools-extra/clangd/FeatureModule.h
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/Preamble.cpp
clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang-tools-extra/clangd/unittests/TestTU.cpp
clang-tools-extra/clangd/unittests/TestTU.h

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index ec69c6a71a34..f045cd1b4f8d 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -231,6 +231,7 @@ void ClangdServer::addDocument(PathRef File, 
llvm::StringRef Contents,
   Inputs.Opts = std::move(Opts);
   Inputs.Index = Index;
   Inputs.ClangTidyProvider = ClangTidyProvider;
+  Inputs.FeatureModules = FeatureModules;
   bool NewFile = WorkScheduler->update(File, Inputs, WantDiags);
   // If we loaded Foo.h, we want to make sure Foo.cpp is indexed.
   if (NewFile && BackgroundIdx)

diff  --git a/clang-tools-extra/clangd/ClangdServer.h 
b/clang-tools-extra/clangd/ClangdServer.h
index 37ac30f70cb4..2dbf14455272 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -38,6 +38,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include 
+#include 
 #include 
 #include 
 #include 

diff  --git a/clang-tools-extra/clangd/Compiler.h 
b/clang-tools-extra/clangd/Compiler.h
index 13fd4da33e3c..035106968315 100644
--- a/clang-tools-extra/clangd/Compiler.h
+++ b/clang-tools-extra/clangd/Compiler.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
 
+#include "FeatureModule.h"
 #include "GlobalCompilationDatabase.h"
 #include "TidyProvider.h"
 #include "index/Index.h"
@@ -22,6 +23,8 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/PrecompiledPreamble.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -54,6 +57,8 @@ struct ParseInputs {
   const SymbolIndex *Index = nullptr;
   ParseOptions Opts = ParseOptions();
   TidyProviderRef ClangTidyProvider = {};
+  // Used to acquire ASTListeners when parsing files.
+  FeatureModuleSet *FeatureModules = nullptr;
 };
 
 /// Builds compiler invocation that could be used to build AST or preamble.

diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index d2982636c807..49574dc3b2ac 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -744,6 +744,8 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level 
DiagLevel,
   LastDiag->Fixes.insert(LastDiag->Fixes.end(), ExtraFixes.begin(),
  ExtraFixes.end());
 }
+if (DiagCB)
+  DiagCB(Info, *LastDiag);
   } else {
 // Handle a note to an existing diagnostic.
 

diff  --git a/clang-tools-extra/clangd/Diagnostics.h 
b/clang-tools-extra/clangd/Diagnostics.h
index 6a432db23cc2..ea55132a9ca8 100644
--- a/clang-tools-extra/clangd/Diagnostics.h
+++ b/clang-tools-extra/clangd/Diagnostics.h
@@ -22,7 +22,10 @@
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/SourceMgr.h"
 #include 
+#include 
+#include 
 #include 
+#include 
 
 namespace clang {
 namespace tidy {
@@ -136,18 +139,24 @@ class StoreDiags : public DiagnosticConsumer {
const clang::Diagnostic &)>;
   using LevelAdjuster = std::function;
+  using DiagCallback =
+  std::function;
   /// If set, possibly adds fixes for diagnostics using \p Fixer.
   void contributeFixes(DiagFixer Fixer) { this->Fixer = Fixer; }
   /// If set, this allows the client of this class to adjust the level of
   /// diagnostics, such as promoting warnings to errors, or ignoring
   /// diagnostics.
   void setLevelAdjuster(LevelAdjuster Adjuster) { this->Adjuster = Adjuster; }
+  /// Invokes a callback 

[clang-tools-extra] b5b2c81 - [clangd] Propagate data in diagnostics

2021-04-13 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-04-13T17:45:09+02:00
New Revision: b5b2c81055cfd0cc6a2a1d1ff2c8017d422586dc

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

LOG: [clangd] Propagate data in diagnostics

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

Added: 


Modified: 
clang-tools-extra/clangd/Diagnostics.cpp
clang-tools-extra/clangd/Diagnostics.h
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h
clang-tools-extra/clangd/refactor/Tweak.h

Removed: 




diff  --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 49574dc3b2acc..453b5a644d096 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -476,6 +476,10 @@ void toLSPDiags(
   Res.message = noteMessage(D, Note, Opts);
   OutFn(std::move(Res), llvm::ArrayRef());
 }
+
+  // FIXME: Get rid of the copies here by taking in a mutable clangd::Diag.
+  for (auto &Entry : D.OpaqueData)
+Main.data.insert({Entry.first, Entry.second});
 }
 
 int getSeverity(DiagnosticsEngine::Level L) {

diff  --git a/clang-tools-extra/clangd/Diagnostics.h 
b/clang-tools-extra/clangd/Diagnostics.h
index ea55132a9ca89..9c2235dce9a9a 100644
--- a/clang-tools-extra/clangd/Diagnostics.h
+++ b/clang-tools-extra/clangd/Diagnostics.h
@@ -20,12 +20,14 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSet.h"
+#include "llvm/Support/JSON.h"
 #include "llvm/Support/SourceMgr.h"
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace tidy {
@@ -70,6 +72,10 @@ struct DiagBase {
   // diags from the main file.
   bool InsideMainFile = false;
   unsigned ID; // e.g. member of clang::diag, or clang-tidy assigned ID.
+  // Feature modules can make use of this field to propagate data from a
+  // diagnostic to a CodeAction request. Each module should only append to the
+  // list.
+  llvm::json::Object OpaqueData;
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const DiagBase &D);
 

diff  --git a/clang-tools-extra/clangd/Protocol.cpp 
b/clang-tools-extra/clangd/Protocol.cpp
index de2f34c6bd846..3a94b2965a6d7 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -600,6 +600,8 @@ llvm::json::Value toJSON(const Diagnostic &D) {
 Diag["source"] = D.source;
   if (D.relatedInformation)
 Diag["relatedInformation"] = *D.relatedInformation;
+  if (!D.data.empty())
+Diag["data"] = llvm::json::Object(D.data);
   // FIXME: workaround for older gcc/clang
   return std::move(Diag);
 }
@@ -607,7 +609,11 @@ llvm::json::Value toJSON(const Diagnostic &D) {
 bool fromJSON(const llvm::json::Value &Params, Diagnostic &R,
   llvm::json::Path P) {
   llvm::json::ObjectMapper O(Params, P);
-  return O && O.map("range", R.range) && O.map("message", R.message) &&
+  if (!O)
+return false;
+  if (auto *Data = Params.getAsObject()->getObject("data"))
+R.data = *Data;
+  return O.map("range", R.range) && O.map("message", R.message) &&
  mapOptOrNull(Params, "severity", R.severity, P) &&
  mapOptOrNull(Params, "category", R.category, P) &&
  mapOptOrNull(Params, "code", R.code, P) &&

diff  --git a/clang-tools-extra/clangd/Protocol.h 
b/clang-tools-extra/clangd/Protocol.h
index 8e90f1f478314..79c0e0ea15a74 100644
--- a/clang-tools-extra/clangd/Protocol.h
+++ b/clang-tools-extra/clangd/Protocol.h
@@ -844,6 +844,13 @@ struct Diagnostic {
   /// Only with capability textDocument.publishDiagnostics.codeActionsInline.
   /// (These actions can also be obtained using textDocument/codeAction).
   llvm::Optional> codeActions;
+
+  /// A data entry field that is preserved between a
+  /// `textDocument/publishDiagnostics` notification
+  /// and`textDocument/codeAction` request.
+  /// Mutating users should associate their data with a unique key they can use
+  /// to retrieve later on.
+  llvm::json::Object data;
 };
 llvm::json::Value toJSON(const Diagnostic &);
 

diff  --git a/clang-tools-extra/clangd/refactor/Tweak.h 
b/clang-tools-extra/clangd/refactor/Tweak.h
index cc8d12ba2cb85..b381bdb2b799b 100644
--- a/clang-tools-extra/clangd/refactor/Tweak.h
+++ b/clang-tools-extra/clangd/refactor/Tweak.h
@@ -26,6 +26,7 @@
 #include "index/Index.h"
 #include "support/Path.h"
 #include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"



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


[PATCH] D98499: [clangd] Introduce ASTHooks to FeatureModules

2021-04-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbce3ac4f224a: [clangd] Introduce ASTHooks to FeatureModules 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98499/new/

https://reviews.llvm.org/D98499

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/FeatureModule.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h

Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -19,12 +19,14 @@
 
 #include "../TidyProvider.h"
 #include "Compiler.h"
+#include "FeatureModule.h"
 #include "ParsedAST.h"
 #include "TestFS.h"
 #include "index/Index.h"
 #include "support/Path.h"
 #include "llvm/ADT/StringMap.h"
 #include "gtest/gtest.h"
+#include 
 #include 
 #include 
 #include 
@@ -76,6 +78,8 @@
   // to eliminate this option some day.
   bool OverlayRealFileSystemForModules = false;
 
+  FeatureModuleSet *FeatureModules = nullptr;
+
   // By default, build() will report Error diagnostics as GTest errors.
   // Suppress this behavior by adding an 'error-ok' comment to the code.
   // The result will always have getDiagnostics() populated.
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -36,6 +36,7 @@
   FS.Files[ImportThunk] = ThunkContents;
 
   ParseInputs Inputs;
+  Inputs.FeatureModules = FeatureModules;
   auto &Argv = Inputs.CompileCommand.CommandLine;
   Argv = {"clang"};
   // FIXME: this shouldn't need to be conditional, but it breaks a
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -9,6 +9,7 @@
 #include "Annotations.h"
 #include "Config.h"
 #include "Diagnostics.h"
+#include "FeatureModule.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "SourceCode.h"
@@ -26,6 +27,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -1346,6 +1348,31 @@
  });
 }
 
+TEST(ParsedASTTest, ModuleSawDiag) {
+  static constexpr const llvm::StringLiteral KDiagMsg = "StampedDiag";
+  struct DiagModifierModule final : public FeatureModule {
+struct Listener : public FeatureModule::ASTListener {
+  void sawDiagnostic(const clang::Diagnostic &Info,
+ clangd::Diag &Diag) override {
+Diag.Message = KDiagMsg.str();
+  }
+};
+std::unique_ptr astListeners() override {
+  return std::make_unique();
+};
+  };
+  FeatureModuleSet FMS;
+  FMS.add(std::make_unique());
+
+  Annotations Code("[[test]]; /* error-ok */");
+  TestTU TU;
+  TU.Code = Code.code().str();
+  TU.FeatureModules = &FMS;
+
+  auto AST = TU.build();
+  EXPECT_THAT(*AST.getDiagnostics(),
+  testing::Contains(Diag(Code.range(), KDiagMsg.str(;
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
@@ -365,6 +365,27 @@
   // And immediately shut down. FeatureModule destructor verifies we blocked.
 }
 
+TEST_F(LSPTest, DiagModuleTest) {
+  static constexpr llvm::StringLiteral DiagMsg = "DiagMsg";
+  class DiagModule final : public FeatureModule {
+struct DiagHooks : public ASTListener {
+  void sawDiagnostic(const clang::Diagnostic &, clangd::Diag &D) override {
+D.Message = DiagMsg.str();
+  }
+};
+
+  public:
+std::unique_ptr astListeners() override {
+  return std::make_unique();
+}
+  };
+  FeatureModules.add(std::make_unique());
+
+  auto &Client = start();
+  Client.didOpen("foo.cpp", "test;");
+  EXPECT_THAT(Client.diagnostics("foo.cpp"),
+  llvm::ValueIs(testing::ElementsAre(DiagMessage(DiagMsg;
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Preamble.cpp

[PATCH] D98505: [clangd] Propagate data in diagnostics

2021-04-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb5b2c81055cf: [clangd] Propagate data in diagnostics 
(authored by kadircet).

Changed prior to commit:
  https://reviews.llvm.org/D98505?vs=333982&id=337173#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98505/new/

https://reviews.llvm.org/D98505

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/refactor/Tweak.h

Index: clang-tools-extra/clangd/refactor/Tweak.h
===
--- clang-tools-extra/clangd/refactor/Tweak.h
+++ clang-tools-extra/clangd/refactor/Tweak.h
@@ -26,6 +26,7 @@
 #include "index/Index.h"
 #include "support/Path.h"
 #include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -844,6 +844,13 @@
   /// Only with capability textDocument.publishDiagnostics.codeActionsInline.
   /// (These actions can also be obtained using textDocument/codeAction).
   llvm::Optional> codeActions;
+
+  /// A data entry field that is preserved between a
+  /// `textDocument/publishDiagnostics` notification
+  /// and`textDocument/codeAction` request.
+  /// Mutating users should associate their data with a unique key they can use
+  /// to retrieve later on.
+  llvm::json::Object data;
 };
 llvm::json::Value toJSON(const Diagnostic &);
 
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -600,6 +600,8 @@
 Diag["source"] = D.source;
   if (D.relatedInformation)
 Diag["relatedInformation"] = *D.relatedInformation;
+  if (!D.data.empty())
+Diag["data"] = llvm::json::Object(D.data);
   // FIXME: workaround for older gcc/clang
   return std::move(Diag);
 }
@@ -607,7 +609,11 @@
 bool fromJSON(const llvm::json::Value &Params, Diagnostic &R,
   llvm::json::Path P) {
   llvm::json::ObjectMapper O(Params, P);
-  return O && O.map("range", R.range) && O.map("message", R.message) &&
+  if (!O)
+return false;
+  if (auto *Data = Params.getAsObject()->getObject("data"))
+R.data = *Data;
+  return O.map("range", R.range) && O.map("message", R.message) &&
  mapOptOrNull(Params, "severity", R.severity, P) &&
  mapOptOrNull(Params, "category", R.category, P) &&
  mapOptOrNull(Params, "code", R.code, P) &&
Index: clang-tools-extra/clangd/Diagnostics.h
===
--- clang-tools-extra/clangd/Diagnostics.h
+++ clang-tools-extra/clangd/Diagnostics.h
@@ -20,12 +20,14 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSet.h"
+#include "llvm/Support/JSON.h"
 #include "llvm/Support/SourceMgr.h"
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 
 namespace clang {
 namespace tidy {
@@ -70,6 +72,10 @@
   // diags from the main file.
   bool InsideMainFile = false;
   unsigned ID; // e.g. member of clang::diag, or clang-tidy assigned ID.
+  // Feature modules can make use of this field to propagate data from a
+  // diagnostic to a CodeAction request. Each module should only append to the
+  // list.
+  llvm::json::Object OpaqueData;
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const DiagBase &D);
 
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -476,6 +476,10 @@
   Res.message = noteMessage(D, Note, Opts);
   OutFn(std::move(Res), llvm::ArrayRef());
 }
+
+  // FIXME: Get rid of the copies here by taking in a mutable clangd::Diag.
+  for (auto &Entry : D.OpaqueData)
+Main.data.insert({Entry.first, Entry.second});
 }
 
 int getSeverity(DiagnosticsEngine::Level L) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98498: [clangd] Enable modules to contribute tweaks.

2021-04-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbb6d96ced80f: [clangd] Enable modules to contribute tweaks. 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98498/new/

https://reviews.llvm.org/D98498

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/FeatureModule.h
  clang-tools-extra/clangd/refactor/Tweak.cpp
  clang-tools-extra/clangd/refactor/Tweak.h
  clang-tools-extra/clangd/tool/Check.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/FeatureModulesTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp
@@ -75,7 +75,7 @@
 Range.second, [&](SelectionTree ST) {
   Tweak::Selection S(Index, AST, Range.first,
  Range.second, std::move(ST));
-  if (auto T = prepareTweak(TweakID, S)) {
+  if (auto T = prepareTweak(TweakID, S, nullptr)) {
 Result = (*T)->apply(S);
 return true;
   } else {
Index: clang-tools-extra/clangd/unittests/FeatureModulesTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/FeatureModulesTests.cpp
@@ -0,0 +1,55 @@
+//===--- FeatureModulesTests.cpp  ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "FeatureModule.h"
+#include "Selection.h"
+#include "TestTU.h"
+#include "refactor/Tweak.h"
+#include "support/Logger.h"
+#include "llvm/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace clang {
+namespace clangd {
+namespace {
+
+TEST(FeatureModulesTest, ContributesTweak) {
+  static constexpr const char *TweakID = "ModuleTweak";
+  struct TweakContributingModule final : public FeatureModule {
+struct ModuleTweak final : public Tweak {
+  const char *id() const override { return TweakID; }
+  bool prepare(const Selection &Sel) override { return true; }
+  Expected apply(const Selection &Sel) override {
+return error("not implemented");
+  }
+  std::string title() const override { return id(); }
+  llvm::StringLiteral kind() const override { return ""; };
+};
+
+void contributeTweaks(std::vector> &Out) override {
+  Out.emplace_back(new ModuleTweak);
+}
+  };
+
+  FeatureModuleSet Set;
+  Set.add(std::make_unique());
+
+  auto AST = TestTU::withCode("").build();
+  auto Tree =
+  SelectionTree::createRight(AST.getASTContext(), AST.getTokens(), 0, 0);
+  auto Actual = prepareTweak(
+  TweakID, Tweak::Selection(nullptr, AST, 0, 0, std::move(Tree)), &Set);
+  ASSERT_TRUE(bool(Actual));
+  EXPECT_EQ(Actual->get()->id(), TweakID);
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -55,6 +55,7 @@
   DraftStoreTests.cpp
   DumpASTTests.cpp
   ExpectedTypeTest.cpp
+  FeatureModulesTests.cpp
   FileDistanceTests.cpp
   FileIndexTests.cpp
   FindSymbolsTests.cpp
Index: clang-tools-extra/clangd/tool/Check.cpp
===
--- clang-tools-extra/clangd/tool/Check.cpp
+++ clang-tools-extra/clangd/tool/Check.cpp
@@ -211,7 +211,8 @@
   auto Tree = SelectionTree::createRight(AST->getASTContext(),
  AST->getTokens(), Start, End);
   Tweak::Selection Selection(&Index, *AST, Start, End, std::move(Tree));
-  for (const auto &T : prepareTweaks(Selection, Opts.TweakFilter)) {
+  for (const auto &T :
+   prepareTweaks(Selection, Opts.TweakFilter, Opts.FeatureModules)) {
 auto Result = T->apply(Selection);
 if (!Result) {
   elog("tweak: {0} ==> FAIL: {1}", T->id(), Result.takeError());
Index: clang-tools-extra/clangd/refactor/Tweak.h
===
--- clang-tools-extra/clangd/refactor/Tweak.h
+++ clang-tools-extra/clangd/refactor/Tweak.h

[clang-tools-extra] bb6d96c - [clangd] Enable modules to contribute tweaks.

2021-04-13 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-04-13T17:45:08+02:00
New Revision: bb6d96ced80f288475cd374c3c7a25ee8cad2bb2

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

LOG: [clangd] Enable modules to contribute tweaks.

First patch to enable diagnostic fix generation through modules. The
workflow will look like:
- ASTWorker letting modules know about diagnostics while building AST,
modules can read clang::Diagnostic and mutate clangd::Diagnostic through
that hook.
- Modules can implement and expose tweaks to fix diagnostics or act as
general refactorings.
- Tweak::Selection will contain information about the diagnostic
associated with the codeAction request to enable modules to fail their
diagnostic fixing tweakson prepare if need be.

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

Added: 
clang-tools-extra/clangd/unittests/FeatureModulesTests.cpp

Modified: 
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/FeatureModule.h
clang-tools-extra/clangd/refactor/Tweak.cpp
clang-tools-extra/clangd/refactor/Tweak.h
clang-tools-extra/clangd/tool/Check.cpp
clang-tools-extra/clangd/unittests/CMakeLists.txt
clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 557689774b148..ec69c6a71a346 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -573,8 +573,9 @@ void ClangdServer::enumerateTweaks(
   static constexpr trace::Metric TweakAvailable(
   "tweak_available", trace::Metric::Counter, "tweak_id");
   auto Action = [File = File.str(), Sel, CB = std::move(CB),
- Filter =
- std::move(Filter)](Expected InpAST) mutable 
{
+ Filter = std::move(Filter),
+ FeatureModules(this->FeatureModules)](
+Expected InpAST) mutable {
 if (!InpAST)
   return CB(InpAST.takeError());
 auto Selections = tweakSelection(Sel, *InpAST);
@@ -587,7 +588,7 @@ void ClangdServer::enumerateTweaks(
   return Filter(T) && !PreparedTweaks.count(T.id());
 };
 for (const auto &Sel : *Selections) {
-  for (auto &T : prepareTweaks(*Sel, DeduplicatingFilter)) {
+  for (auto &T : prepareTweaks(*Sel, DeduplicatingFilter, FeatureModules)) 
{
 Res.push_back({T->id(), T->title(), T->kind()});
 PreparedTweaks.insert(T->id());
 TweakAvailable.record(1, T->id());
@@ -622,7 +623,7 @@ void ClangdServer::applyTweak(PathRef File, Range Sel, 
StringRef TweakID,
 // Try each selection, take the first one that prepare()s.
 // If they all fail, Effect will hold get the last error.
 for (const auto &Selection : *Selections) {
-  auto T = prepareTweak(TweakID, *Selection);
+  auto T = prepareTweak(TweakID, *Selection, FeatureModules);
   if (T) {
 Effect = (*T)->apply(*Selection);
 break;

diff  --git a/clang-tools-extra/clangd/FeatureModule.h 
b/clang-tools-extra/clangd/FeatureModule.h
index 337fa24e94543..13d7b7711829e 100644
--- a/clang-tools-extra/clangd/FeatureModule.h
+++ b/clang-tools-extra/clangd/FeatureModule.h
@@ -25,6 +25,7 @@ class LSPBinder;
 class SymbolIndex;
 class ThreadsafeFS;
 class TUScheduler;
+class Tweak;
 
 /// A FeatureModule contributes a vertical feature to clangd.
 ///
@@ -91,6 +92,10 @@ class FeatureModule {
   /// Called by the server when shutting down, and also by tests.
   virtual bool blockUntilIdle(Deadline) { return true; }
 
+  /// Tweaks implemented by this module. Can be called asynchronously when
+  /// enumerating or applying code actions.
+  virtual void contributeTweaks(std::vector> &Out) {}
+
 protected:
   /// Accessors for modules to access shared server facilities they depend on.
   Facilities &facilities();

diff  --git a/clang-tools-extra/clangd/refactor/Tweak.cpp 
b/clang-tools-extra/clangd/refactor/Tweak.cpp
index 34b5b2b544dff..8ccb28f236bd1 100644
--- a/clang-tools-extra/clangd/refactor/Tweak.cpp
+++ b/clang-tools-extra/clangd/refactor/Tweak.cpp
@@ -6,6 +6,7 @@
 //
 
//===--===//
 #include "Tweak.h"
+#include "FeatureModule.h"
 #include "SourceCode.h"
 #include "index/Index.h"
 #include "support/Logger.h"
@@ -20,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 LLVM_INSTANTIATE_REGISTRY(llvm::Registry)
 
@@ -43,6 +45,18 @@ void validateRegistry() {
   }
 #endif
 }
+
+std::vector>
+getAllTweaks(const FeatureModuleSet *Modules) {
+  std::vector> All;
+  for (const auto &E : TweakRegistry::entries())
+All.emplace_back(E.instantiate());
+  if (Modules) {
+for (auto &M : *Modules)
+  M.contributeTweaks(All);

[clang] 01ddfa9 - [analyzer] [NFC] Eliminate dispatchCast, evalCastFromNonLoc and evalCastFromLoc functions from SValBuilder

2021-04-13 Thread Denys Petrov via cfe-commits

Author: Denys Petrov
Date: 2021-04-13T18:56:04+03:00
New Revision: 01ddfa95bd14b35c5706cc5d69fe64b4b60526e3

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

LOG: [analyzer] [NFC] Eliminate dispatchCast, evalCastFromNonLoc and 
evalCastFromLoc functions from SValBuilder

Summary: Remove dispatchCast, evalCastFromNonLoc and evalCastFromLoc functions 
since their functionality has been moved to common evalCast function. Use 
evalCast instead.

Post-clean up patch for https://reviews.llvm.org/D96090 patch. The patch shall 
not change any behavior.

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
index 2358d2d66b30..99277e91ed06 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -72,9 +72,6 @@ class SValBuilder {
   /// The width of the scalar type used for array indices.
   const unsigned ArrayIndexWidth;
 
-  virtual SVal evalCastFromNonLoc(NonLoc val, QualType castTy) = 0;
-  virtual SVal evalCastFromLoc(Loc val, QualType castTy) = 0;
-
   SVal evalCastKind(UndefinedVal V, QualType CastTy, QualType OriginalTy);
   SVal evalCastKind(UnknownVal V, QualType CastTy, QualType OriginalTy);
   SVal evalCastKind(Loc V, QualType CastTy, QualType OriginalTy);
@@ -97,11 +94,6 @@ class SValBuilder {
   SVal evalCastSubKind(nonloc::PointerToMember V, QualType CastTy,
QualType OriginalTy);
 
-public:
-  // FIXME: Make these protected again once RegionStoreManager correctly
-  // handles loads from 
diff erent bound value types.
-  virtual SVal dispatchCast(SVal val, QualType castTy) = 0;
-
 public:
   SValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context,
   ProgramStateManager &stateMgr)

diff  --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
index 9a9edb25f2d7..a49099384d2a 100644
--- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -107,7 +107,7 @@ SVal SValBuilder::convertToArrayIndex(SVal val) {
   return val;
   }
 
-  return evalCastFromNonLoc(val.castAs(), ArrayIndexTy);
+  return evalCast(val, ArrayIndexTy, QualType{});
 }
 
 nonloc::ConcreteInt SValBuilder::makeBoolVal(const CXXBoolLiteralExpr 
*boolean){

diff  --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index 7fe2374c9914..e57d92fbcebb 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -22,11 +22,6 @@ using namespace ento;
 
 namespace {
 class SimpleSValBuilder : public SValBuilder {
-protected:
-  SVal dispatchCast(SVal val, QualType castTy) override;
-  SVal evalCastFromNonLoc(NonLoc val, QualType castTy) override;
-  SVal evalCastFromLoc(Loc val, QualType castTy) override;
-
 public:
   SimpleSValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context,
 ProgramStateManager &stateMgr)
@@ -61,134 +56,6 @@ SValBuilder 
*ento::createSimpleSValBuilder(llvm::BumpPtrAllocator &alloc,
   return new SimpleSValBuilder(alloc, context, stateMgr);
 }
 
-//===--===//
-// Transfer function for Casts.
-//===--===//
-
-// FIXME: This function should be eliminated and replaced with `evalCast`
-SVal SimpleSValBuilder::dispatchCast(SVal Val, QualType CastTy) {
-  return evalCast(Val, CastTy, QualType{});
-}
-
-// FIXME: This function should be eliminated and replaced with `evalCast`
-SVal SimpleSValBuilder::evalCastFromNonLoc(NonLoc val, QualType castTy) {
-  bool isLocType = Loc::isLocType(castTy);
-  if (val.getAs())
-return val;
-
-  if (Optional LI = val.getAs()) {
-if (isLocType)
-  return LI->getLoc();
-// FIXME: Correctly support promotions/truncations.
-unsigned castSize = Context.getIntWidth(castTy);
-if (castSize == LI->getNumBits())
-  return val;
-return makeLocAsInteger(LI->getLoc(), castSize);
-  }
-
-  if (SymbolRef se = val.getAsSymbol()) {
-QualType T = Context.getCanonicalType(se->getType());
-// If types are the same or both are integers, ignore the cast.
-// FIXME: Remove this hack when we support symbolic truncation/extension.
-// HACK: If both castTy and 

[PATCH] D97277: [analyzer] [NFC] Eliminate dispatchCast, evalCastFromNonLoc and evalCastFromLoc functions from SValBuilder

2021-04-13 Thread Denys Petrov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG01ddfa95bd14: [analyzer] [NFC] Eliminate dispatchCast, 
evalCastFromNonLoc and evalCastFromLoc… (authored by ASDenysPetrov).

Changed prior to commit:
  https://reviews.llvm.org/D97277?vs=328106&id=337177#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97277/new/

https://reviews.llvm.org/D97277

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -22,11 +22,6 @@
 
 namespace {
 class SimpleSValBuilder : public SValBuilder {
-protected:
-  SVal dispatchCast(SVal val, QualType castTy) override;
-  SVal evalCastFromNonLoc(NonLoc val, QualType castTy) override;
-  SVal evalCastFromLoc(Loc val, QualType castTy) override;
-
 public:
   SimpleSValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context,
 ProgramStateManager &stateMgr)
@@ -61,134 +56,6 @@
   return new SimpleSValBuilder(alloc, context, stateMgr);
 }
 
-//===--===//
-// Transfer function for Casts.
-//===--===//
-
-// FIXME: This function should be eliminated and replaced with `evalCast`
-SVal SimpleSValBuilder::dispatchCast(SVal Val, QualType CastTy) {
-  return evalCast(Val, CastTy, QualType{});
-}
-
-// FIXME: This function should be eliminated and replaced with `evalCast`
-SVal SimpleSValBuilder::evalCastFromNonLoc(NonLoc val, QualType castTy) {
-  bool isLocType = Loc::isLocType(castTy);
-  if (val.getAs())
-return val;
-
-  if (Optional LI = val.getAs()) {
-if (isLocType)
-  return LI->getLoc();
-// FIXME: Correctly support promotions/truncations.
-unsigned castSize = Context.getIntWidth(castTy);
-if (castSize == LI->getNumBits())
-  return val;
-return makeLocAsInteger(LI->getLoc(), castSize);
-  }
-
-  if (SymbolRef se = val.getAsSymbol()) {
-QualType T = Context.getCanonicalType(se->getType());
-// If types are the same or both are integers, ignore the cast.
-// FIXME: Remove this hack when we support symbolic truncation/extension.
-// HACK: If both castTy and T are integers, ignore the cast.  This is
-// not a permanent solution.  Eventually we want to precisely handle
-// extension/truncation of symbolic integers.  This prevents us from losing
-// precision when we assign 'x = y' and 'y' is symbolic and x and y are
-// different integer types.
-   if (haveSameType(T, castTy))
-  return val;
-
-if (!isLocType)
-  return makeNonLoc(se, T, castTy);
-return UnknownVal();
-  }
-
-  // If value is a non-integer constant, produce unknown.
-  if (!val.getAs())
-return UnknownVal();
-
-  // Handle casts to a boolean type.
-  if (castTy->isBooleanType()) {
-bool b = val.castAs().getValue().getBoolValue();
-return makeTruthVal(b, castTy);
-  }
-
-  // Only handle casts from integers to integers - if val is an integer constant
-  // being cast to a non-integer type, produce unknown.
-  if (!isLocType && !castTy->isIntegralOrEnumerationType())
-return UnknownVal();
-
-  llvm::APSInt i = val.castAs().getValue();
-  BasicVals.getAPSIntType(castTy).apply(i);
-
-  if (isLocType)
-return makeIntLocVal(i);
-  else
-return makeIntVal(i);
-}
-
-// FIXME: This function should be eliminated and replaced with `evalCast`
-SVal SimpleSValBuilder::evalCastFromLoc(Loc val, QualType castTy) {
-
-  // Casts from pointers -> pointers, just return the lval.
-  //
-  // Casts from pointers -> references, just return the lval.  These
-  //   can be introduced by the frontend for corner cases, e.g
-  //   casting from va_list* to __builtin_va_list&.
-  //
-  if (Loc::isLocType(castTy) || castTy->isReferenceType())
-return val;
-
-  // FIXME: Handle transparent unions where a value can be "transparently"
-  //  lifted into a union type.
-  if (castTy->isUnionType())
-return UnknownVal();
-
-  // Casting a Loc to a bool will almost always be true,
-  // unless this is a weak function or a symbolic region.
-  if (castTy->isBooleanType()) {
-switch (val.getSubKind()) {
-  case loc::MemRegionValKind: {
-const MemRegion *R = val.castAs().getRegion();
-if (const FunctionCodeRegion *FTR = dyn_cast(R))
-  if (const FunctionDecl *FD = dyn_cast(FTR->getDecl()))
-if (FD->isWeak())
-  // FIXME: Currently we are using an extent symbol here,
-  // because there are no generic region address metadata
-  // symbols to use, only content metad

[PATCH] D100346: [Clang] String Literal and Wide String Literal Encoding from the Preprocessor

2021-04-13 Thread ThePhD via Phabricator via cfe-commits
ThePhD marked 4 inline comments as done.
ThePhD added a comment.

In D100346#2685530 , @aaron.ballman 
wrote:

> ...
>
> What about for folks using this from C where there isn't `constexpr` 
> functionality to help them?

The unfortunate bit is that C won't be able to guarantee compile-time culling 
of branches, even if all values present are `constexpr`. Implementations like 
Clang and GCC have significantly powerful enough optimizers that usage of 
`strcmp` and `memcmp` can be recognized and turned into builtins, before being 
const-folded down. This can provide dead code elimination. But, otherwise, C 
can't **guarantee** elision of the code branches without an integral constant 
identifier in a Macro. This is more or less a deficiency in how weak Constant 
Expressions are in C, leaving most people to rely on implementation-defined 
behavior for constant folding to do anything worthwhile with their toolset.

I think in the future, if we are really invested in this path, we should come 
up with a canonical mapping and a specific way of saying "if this is a 
recognized encoding name it has an Integer Constant Expression of value `X` as 
defined by table `Y` in the documentation". We could provide macros 
`__clang_literal_encoding_id__` and `__clang_wide_literal_encoding_id` that has 
the `X` integer constant expression value. But I think that should be a 
follow-on patch that evaluates the totality of encodings, and also maybe 
contacts some IBM folks who did the `-fexec-charset` patches so they can also 
give over any additional encoding mappings they want.

Because Clang is open, anyone could add to it and that way people could have 
that kind of ability in C. iconv has a very full list of encodings, and you'd 
also need to define a resistant equality function similar to what's implemented 
in soasis/text 
(https://github.com/soasis/text/blob/main/include/ztd/text/detail/encoding_name.hpp#L120)
 or in P1885  (http://wg21.link/p1885) so you 
can compare names in a consistent manner across platforms. After that equality 
you then yield the integer value, and then you'd go from there. It doesn't have 
to be standard, just compiler-specific.

I'm not sure all of that belongs in this patch, though, and I think I'd wait 
for the other patches about `iconv` literal converters to drop before having 
the fullness of that conversation.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100346/new/

https://reviews.llvm.org/D100346

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


[PATCH] D100346: [Clang] String Literal and Wide String Literal Encoding from the Preprocessor

2021-04-13 Thread ThePhD via Phabricator via cfe-commits
ThePhD updated this revision to Diff 337178.
ThePhD set the repository for this revision to rG LLVM Github Monorepo.
ThePhD added a comment.

Oops, almost forgot the doc fixes for the *wide__* macro!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100346/new/

https://reviews.llvm.org/D100346

Files:
  clang/docs/LanguageExtensions.rst
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/init-x86.c
  clang/test/Preprocessor/init.c


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -115,10 +115,12 @@
 // COMMON:#define __STDC__ 1
 // COMMON:#define __VERSION__ {{.*}}
 // COMMON:#define __clang__ 1
+// COMMON:#define __clang_literal_encoding__ {{.*}}
 // COMMON:#define __clang_major__ {{[0-9]+}}
 // COMMON:#define __clang_minor__ {{[0-9]+}}
 // COMMON:#define __clang_patchlevel__ {{[0-9]+}}
 // COMMON:#define __clang_version__ {{.*}}
+// COMMON:#define __clang_wide_literal_encoding__ {{.*}}
 // COMMON:#define __llvm__ 1
 //
 // RUN: %clang_cc1 -E -dM -triple=x86_64-pc-win32 < /dev/null | FileCheck 
-match-full-lines -check-prefix C-DEFAULT %s
@@ -1844,10 +1846,12 @@
 // WEBASSEMBLY-NOT:#define __WINT_UNSIGNED__
 // WEBASSEMBLY-NEXT:#define __WINT_WIDTH__ 32
 // WEBASSEMBLY-NEXT:#define __clang__ 1
+// WEBASSEMBLY-NEXT:#define __clang_literal_encoding__ {{.*}}
 // WEBASSEMBLY-NEXT:#define __clang_major__ {{.*}}
 // WEBASSEMBLY-NEXT:#define __clang_minor__ {{.*}}
 // WEBASSEMBLY-NEXT:#define __clang_patchlevel__ {{.*}}
 // WEBASSEMBLY-NEXT:#define __clang_version__ "{{.*}}"
+// WEBASSEMBLY-NEXT:#define __clang_wide_literal_encoding__ {{.*}}
 // WEBASSEMBLY-NEXT:#define __llvm__ 1
 // WEBASSEMBLY-NOT:#define __unix
 // WEBASSEMBLY-NOT:#define __unix__
Index: clang/test/Preprocessor/init-x86.c
===
--- clang/test/Preprocessor/init-x86.c
+++ clang/test/Preprocessor/init-x86.c
@@ -1306,10 +1306,12 @@
 // X86_64-CLOUDABI:#define __amd64 1
 // X86_64-CLOUDABI:#define __amd64__ 1
 // X86_64-CLOUDABI:#define __clang__ 1
+// X86_64-CLOUDABI:#define __clang_literal_encoding__ {{.*}}
 // X86_64-CLOUDABI:#define __clang_major__ {{.*}}
 // X86_64-CLOUDABI:#define __clang_minor__ {{.*}}
 // X86_64-CLOUDABI:#define __clang_patchlevel__ {{.*}}
 // X86_64-CLOUDABI:#define __clang_version__ {{.*}}
+// X86_64-CLOUDABI:#define __clang_wide_literal_encoding__ {{.*}}
 // X86_64-CLOUDABI:#define __llvm__ 1
 // X86_64-CLOUDABI:#define __x86_64 1
 // X86_64-CLOUDABI:#define __x86_64__ 1
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -778,6 +778,21 @@
 }
   }
 
+  // Macros to help identify the narrow and wide character sets
+  // FIXME: clang currently ignores -fexec-charset=. If this changes,
+  // then this may need to be updated.
+  Builder.defineMacro("__clang_literal_encoding__", "\"UTF-8\"");
+  if (TI.getTypeWidth(TI.getWCharType()) >= 32) {
+// FIXME: 32-bit wchar_t signals UTF-32. This may change
+// if -fwide-exec-charset= is ever supported.
+Builder.defineMacro("__clang_wide_literal_encoding__", "\"UTF-32\"");
+  } else {
+// FIXME: Less-than 32-bit wchar_t generally means UTF-16
+// (e.g., Windows, 32-bit IBM). This may need to be
+// updated if -fwide-exec-charset= is ever supported.
+Builder.defineMacro("__clang_wide_literal_encoding__", "\"UTF-16\"");
+  }
+
   if (LangOpts.Optimize)
 Builder.defineMacro("__OPTIMIZE__");
   if (LangOpts.OptimizeSize)
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -383,6 +383,18 @@
   Defined to a string that captures the Clang marketing version, including the
   Subversion tag or revision number, e.g., "``1.5 (trunk 102332)``".
 
+``__clang_literal_encoding__``
+  Defined to a narrow string literal that represents the current encoding of
+  narrow string literals, e.g., ``"hello"``. This macro typically expands to
+  "UTF-8" (but may change in the future if the
+  ``-fexec-charset="Encoding-Name"`` option is implemented.)
+
+``__clang_wide_literal_encoding__``
+  Defined to a narrow string literal that represents the current encoding of
+  wide string literals, e.g., ``L"hello"``. This macro typically expands to
+  "UTF-16" or "UTF-32" (but may change in the future if the
+  ``-fwide-exec-charset="Encoding-Name"`` option is implemented.)
+
 .. _langext-vectors:
 
 Vectors and Extended Vectors


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -115,10 +115,12 @@
 // COMMON:#define

[PATCH] D89909: [SYCL] Implement SYCL address space attributes handling

2021-04-13 Thread Alexey Bader via Phabricator via cfe-commits
bader updated this revision to Diff 337180.
bader marked 16 inline comments as done.
bader added a comment.

Applied more code review suggestions.

Rebased on ToT.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89909/new/

https://reviews.llvm.org/D89909

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenSYCL/address-space-conversions.cpp
  clang/test/CodeGenSYCL/address-space-deduction.cpp
  clang/test/SemaSYCL/address-space-conversions.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388593)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388590)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x71>();
+  correct<0x7FFFED>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: clang/test/SemaSYCL/address-space-conversions.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/address-space-conversions.cpp
@@ -0,0 +1,64 @@
+// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only %s
+
+void bar(int &Data) {}
+void bar2(int &Data) {}
+void bar(__attribute__((opencl_private)) int &Data) {}
+void foo(int *Data) {}
+void foo2(int *Data) {}
+void foo(__attribute__((opencl_private)) int *Data) {}
+void baz(__attribute__((opencl_private)) int *Data) {} // expected-note {{candidate function not viable: cannot pass pointer to generic address space as a pointer to address space '__private' in 1st argument}}
+
+template 
+void tmpl(T *t) {}
+
+void usages() {
+  __attribute__((opencl_global)) int *GLOB;
+  __attribute__((opencl_private)) int *PRIV;
+  __attribute__((opencl_local)) int *LOC;
+  int *NoAS;
+
+  GLOB = PRIV; // expected-error {{assigning '__private int *' to '__global int *' changes address space of pointer}}
+  GLOB = LOC; // expected-error {{assigning '__local int *' to '__global int *' changes address space of pointer}}
+  PRIV = static_cast<__attribute__((opencl_private)) int *>(GLOB); // expected-error {{static_cast from '__global int *' to '__private int *' is not allowed}}
+  PRIV = static_cast<__attribute__((opencl_private)) int *>(LOC); // expected-error {{static_cast from '__local int *' to '__private int *' is not allowed}}
+  NoAS = GLOB + PRIV; // expected-error {{invalid operands to binary expression ('__global int *' and '__private int *')}}
+  NoAS = GLOB + LOC; // expected-error {{invalid operands to binary expression ('__global int *' and '__local int *')}}
+  NoAS += GLOB; // expected-error {{invalid operands to binary expression ('int *' and '__global int *')}}
+
+  bar(*GLOB);
+  bar2(*GLOB);
+
+  bar(*PRIV);
+  bar2(*PRIV);
+
+  bar(*NoAS);
+  bar2(*NoAS);
+
+  bar(*LOC);
+  bar2(*LOC);
+
+  foo(GLOB);
+  foo2(GLOB);
+  foo(PRIV);
+  foo2(PRIV);
+  foo(NoAS);
+  foo2(NoAS);
+  foo(LOC);
+  foo2(LOC);
+
+  tmpl(GLOB);
+  tmpl(PRIV);
+  tmpl(NoAS);
+  tmpl(LOC);
+
+  // Implicit casts to named address space are disallowed
+  baz(NoAS); // expected-error {{no matching function for call to 'baz'}}
+  __attribute__((opencl_local)) int *l = NoAS; // expected-error {{cannot initialize a variable of type '__local int *' with an lvalue of type 'int *'}}
+
+  (void)static_cast(GLOB);
+  (void)static_cast(GLOB);
+  int *i = GLOB;
+  void *v = GLOB;
+  (void)i;
+  (void)v;
+}
Index: clang/test/CodeGenSYCL/address-space-deduction.cpp
===
--- /dev/null
+++ clang/test/CodeGenSYCL/address-space-deduction.cpp
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -triple spir64 -fsycl-is-device -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
+
+// CHECK:@_ZZ4testvE3foo = internal addrspace(1) constant i32 66, align 4
+// CHECK: @[[STR:[.a

[PATCH] D89909: [SYCL] Implement SYCL address space attributes handling

2021-04-13 Thread Alexey Bader via Phabricator via cfe-commits
bader added inline comments.



Comment at: clang/include/clang/AST/Type.h:493
+   // Default is a superset of SYCL address spaces.
+   (A == LangAS::Default &&
+(B == LangAS::sycl_private || B == LangAS::sycl_local ||

Anastasia wrote:
> bader wrote:
> > Anastasia wrote:
> > > Ok if you allow implicit conversions both ways then this condition should 
> > > be extended to also contain all named address spaces in `A` and `Default` 
> > > in `B`. But actually, could you simplify by checking that you have 
> > > `Default` on either side, so something like 
> > > 
> > > 
> > > ```
> > > (A == LangAS::Default || B == LangAS::Default)
> > > ```
> > > ?
> > > Ok if you allow implicit conversions both ways then this condition should 
> > > be extended to also contain all named address spaces in `A` and `Default` 
> > > in `B`. But actually, could you simplify by checking that you have 
> > > `Default` on either side, so something like 
> > > 
> > > 
> > > ```
> > > (A == LangAS::Default || B == LangAS::Default)
> > > ```
> > > ?
> > 
> > According to the comment above `isAddressSpaceSupersetOf` function 
> > definition.
> > ```
> >   /// Returns true if address space A is equal to or a superset of B.
> > ```
> > 
> > `(A == LangAS::Default || B == LangAS::Default)` <- this change makes 
> > `Default` address space a superset of all address spaces including OpenCL, 
> > which we were trying to avoid with adding SYCL address spaces. Another 
> > problem with this code is that make `Default` a **sub-set** of named 
> > address spaces (like `sycl_local`), which is not right.
> > If I understand it correctly defining "isSupersSetOf" relation is enough 
> > for the rest of framework to enable conversions. Am I right?
> > (A == LangAS::Default || B == LangAS::Default) <- this change makes Default 
> > address space a superset of all address spaces including OpenCL.
> 
> I see, yes this will break pretty much everything unless we guard by SYCL 
> mode. But I don't think it is good to go this route though.
> 
> > Another problem with this code is that make Default a sub-set of named 
> > address spaces (like sycl_local), which is not right.
> 
> Well, if you need implicit conversions to work both ways as you have written 
> in the documentation then you don't really have a true super-/subsets between 
> the named address spaces and the default one. They appear to be equivalent.
> 
> ```
> SYCL mode enables both explicit and implicit conversion to/from the default 
> address space from/to
> the address space-attributed type.
> ```
> 
> So do you actually need something like this to work?
> 
> ```
> int * genptr = ...;
> __private int * privptr = genptr:
> ```
> 
> 
I looked though the code base and I see that explicit cast is used when raw 
pointer is casted to address space annotated type. I think we can always use 
explicit cast from `Default` to named address space instead of implicit cast. 
It might be even useful to avoid unintended implicit casts causing UB.
@keryell, @Naghasan, what do you think if we update 
https://reviews.llvm.org/D99488 to disallow implicit casts from `Default` to 
named address space? I think it should be okay considering that current 
implementation doesn't use this type of casts (and I can't come up with a use 
case for it).

Meanwhile I've added checks for that to 
clang/test/SemaSYCL/address-space-conversions.cpp.



Comment at: clang/lib/AST/ItaniumMangle.cpp:2379
   unsigned TargetAS = Context.getASTContext().getTargetAddressSpace(AS);
-  if (TargetAS != 0)
+  if (TargetAS != 0 || Context.getASTContext().getLangOpts().SYCLIsDevice)
 ASString = "AS" + llvm::utostr(TargetAS);

Anastasia wrote:
> bader wrote:
> > Anastasia wrote:
> > > Any reason not to use OpenCL mangling? If you do then you might be able 
> > > to link against libraries compiled for OpenCL. Also you will get more 
> > > stable naming i.e. it would not differ from target to target. 
> > > Any reason not to use OpenCL mangling? If you do then you might be able 
> > > to link against libraries compiled for OpenCL. Also you will get more 
> > > stable naming i.e. it would not differ from target to target. 
> > 
> > I'm not sure I understand your suggestion. Could you elaborate on "OpenCL 
> > mangling", please?
> > 
> > Let me clarify the problem this change addresses. The test case covering it 
> > is located in 
> > `clang/test/CodeGenSYCL/address-space-parameter-conversions.cpp` lines 
> > 86-91.
> > 
> > ```
> > template 
> > void tmpl(T t) {}
> > 
> > int *NoAS;
> > __attribute__((opencl_private)) int *PRIV;
> > 
> > tmpl(PRIV);
> > // CHECK-DAG: [[PRIV_LOAD5:%[a-zA-Z0-9]+]] = load i32*, i32* addrspace(4)* 
> > [[PRIV]].ascast
> > // CHECK-DAG: call spir_func void [[PRIV_TMPL:@[a-zA-Z0-9_]+]](i32* 
> > [[PRIV_LOAD5]])
> > tmpl(NoAS);
> > // CHECK-DAG: [[NoAS_LOAD5:%[a-zA-Z0-9]+]] = load i32 addrspace(4)*, i32 
> 

[clang] 595c375 - Fix the const overload of IgnoreExprNodes

2021-04-13 Thread Dmitri Gribenko via cfe-commits

Author: Jesse Zhang
Date: 2021-04-13T17:59:59+02:00
New Revision: 595c3758e47042c876e7390d09642ea050ba6dbf

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

LOG: Fix the const overload of IgnoreExprNodes

The existing code causes an infinite recursion. This is likely an
oversight of commit c0e5e3fbfa504c37 [1] where the intent must have been
to call the non-const overload.

[1] https://reviews.llvm.org/D87278

Reviewed By: gribozavr2

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

Added: 


Modified: 
clang/include/clang/AST/IgnoreExpr.h

Removed: 




diff  --git a/clang/include/clang/AST/IgnoreExpr.h 
b/clang/include/clang/AST/IgnoreExpr.h
index 1c2b538e5b635..b2f53d1d2a798 100644
--- a/clang/include/clang/AST/IgnoreExpr.h
+++ b/clang/include/clang/AST/IgnoreExpr.h
@@ -41,7 +41,7 @@ template  Expr *IgnoreExprNodes(Expr *E, 
FnTys &&... Fns) {
 
 template 
 const Expr *IgnoreExprNodes(const Expr *E, FnTys &&...Fns) {
-  return const_cast(IgnoreExprNodes(E, std::forward(Fns)...));
+  return IgnoreExprNodes(const_cast(E), std::forward(Fns)...);
 }
 
 inline Expr *IgnoreImplicitCastsSingleStep(Expr *E) {



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


[PATCH] D100347: Fix the const overload of IgnoreExprNodes

2021-04-13 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG595c3758e470: Fix the const overload of IgnoreExprNodes 
(authored by d, committed by gribozavr).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100347/new/

https://reviews.llvm.org/D100347

Files:
  clang/include/clang/AST/IgnoreExpr.h


Index: clang/include/clang/AST/IgnoreExpr.h
===
--- clang/include/clang/AST/IgnoreExpr.h
+++ clang/include/clang/AST/IgnoreExpr.h
@@ -41,7 +41,7 @@
 
 template 
 const Expr *IgnoreExprNodes(const Expr *E, FnTys &&...Fns) {
-  return const_cast(IgnoreExprNodes(E, std::forward(Fns)...));
+  return IgnoreExprNodes(const_cast(E), std::forward(Fns)...);
 }
 
 inline Expr *IgnoreImplicitCastsSingleStep(Expr *E) {


Index: clang/include/clang/AST/IgnoreExpr.h
===
--- clang/include/clang/AST/IgnoreExpr.h
+++ clang/include/clang/AST/IgnoreExpr.h
@@ -41,7 +41,7 @@
 
 template 
 const Expr *IgnoreExprNodes(const Expr *E, FnTys &&...Fns) {
-  return const_cast(IgnoreExprNodes(E, std::forward(Fns)...));
+  return IgnoreExprNodes(const_cast(E), std::forward(Fns)...);
 }
 
 inline Expr *IgnoreImplicitCastsSingleStep(Expr *E) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D100347: Fix the const overload of IgnoreExprNodes

2021-04-13 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

> Trying arc land I realize I do not...

Pushed as 595c3758e47042c876e7390d09642ea050ba6dbf 
.

> it's also unclear to me where the tests for this are so I couldn't add a new 
> test, is that OK?

Yes, unfortunately we don't have unit tests for the AST.

> More importantly, the bug exists in LLVM 12, what is the policy of patching 
> the back branches in this project?

Please take a look at 
https://llvm.org/docs/HowToReleaseLLVM.html#merge-requests .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100347/new/

https://reviews.llvm.org/D100347

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


[PATCH] D95976: [OpenMP] Simplify offloading parallel call codegen

2021-04-13 Thread Giorgis Georgakoudis via Phabricator via cfe-commits
ggeorgakoudis updated this revision to Diff 337183.
ggeorgakoudis added a comment.

Add aux-triple to one test, check unit test builder on windows


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95976/new/

https://reviews.llvm.org/D95976

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/OpenMP/nvptx_allocate_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/remarks_parallel_in_multiple_target_state_machines.c
  clang/test/OpenMP/remarks_parallel_in_target_state_machine.c
  clang/test/OpenMP/target_parallel_debug_codegen.cpp
  clang/test/OpenMP/target_parallel_for_debug_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
  openmp/libomptarget/deviceRTLs/common/src/parallel.cu
  openmp/libomptarget/deviceRTLs/common/src/support.cu
  openmp/libomptarget/deviceRTLs/common/support.h
  openmp/libomptarget/deviceRTLs/interface.h

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


[clang] 62328f2 - Implement WG21 P2156R1/WG14 N2557 on duplicate attributes

2021-04-13 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-04-13T12:30:04-04:00
New Revision: 62328f2f29b432dadbd327ff91ba3914c478e3fc

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

LOG: Implement WG21 P2156R1/WG14 N2557 on duplicate attributes

These proposals make the same changes to both C++ and C and remove a
restriction on standard attributes appearing multiple times in the same
attribute list.

We could warn on the duplicate attributes, but do not. This is for
consistency as we do not warn on attributes duplicated within the
attribute specifier sequence. If we want to warn on duplicated
standard attributes, we should do so both for both situations:
[[foo, foo]] and [[foo]][[foo]].

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p1.cpp
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p1.cpp
clang/test/Sema/c2x-fallthrough.c
clang/test/Sema/c2x-maybe_unused-errors.c
clang/test/Sema/c2x-nodiscard.c
clang/test/SemaCXX/cxx2a-no-unique-address.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index b0f9b317a020d..8b3da909dd118 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -684,8 +684,6 @@ def err_attribute_requires_arguments : Error<
   "parentheses must be omitted if %0 attribute's argument list is empty">;
 def err_cxx11_attribute_forbids_ellipsis : Error<
   "attribute %0 cannot be used as an attribute pack">;
-def err_cxx11_attribute_repeated : Error<
-  "attribute %0 cannot appear multiple times in an attribute specifier">;
 def warn_cxx14_compat_using_attribute_ns : Warning<
   "default scope specifier for attributes is incompatible with C++ standards "
   "before C++17">, InGroup, DefaultIgnore;

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index e1d29f555f425..bc59b41782577 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -4260,13 +4260,6 @@ void 
Parser::ParseCXX11AttributeSpecifier(ParsedAttributes &attrs,
   }
 }
 
-bool StandardAttr = IsBuiltInOrStandardCXX11Attribute(AttrName, ScopeName);
-
-if (StandardAttr &&
-!SeenAttrs.insert(std::make_pair(AttrName, AttrLoc)).second)
-  Diag(AttrLoc, diag::err_cxx11_attribute_repeated)
-  << AttrName << SourceRange(SeenAttrs[AttrName]);
-
 // Parse attribute arguments
 if (Tok.is(tok::l_paren))
   AttrParsed = ParseCXX11AttributeArgs(AttrName, AttrLoc, attrs, endLoc,

diff  --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p1.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p1.cpp
index 6cf27af3230bd..424b159667c3b 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p1.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p1.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -verify -std=c++11 %s
 
-[[carries_dependency, carries_dependency]] int m1(); // expected-error 
{{attribute 'carries_dependency' cannot appear multiple times in an attribute 
specifier}}
+[[carries_dependency, carries_dependency]] int m1(); // ok
 [[carries_dependency]] [[carries_dependency]] int m2(); // ok
 [[carries_dependency()]] int m3(); // expected-error {{attribute 
'carries_dependency' cannot have an argument list}}
 

diff  --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp
index 22815bbde9db4..675ab3e089b86 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp
@@ -61,7 +61,7 @@ void g() {
 return;
 
   case 0:
-[[fallthrough, fallthrough]]; // expected-error {{multiple times}}
+[[fallthrough, fallthrough]]; // ok
   case 1:
 [[fallthrough(0)]]; // expected-error {{argument list}}
   case 2:

diff  --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
index 982f18f1e8cdf..142d4d6f369f6 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c++2a -verify %s
 
 struct [[nodiscard]] S1 {}; // ok
-struct [[nodiscard, nodiscard]] S2 {}; // expected-error {{attribute 
'nodiscard' cannot appear multiple times in an attribute specifier}}
+struct [[nodiscard, nodiscard]] S2 {}; // ok
 st

[PATCH] D100161: Redistribute energy for Corpus

2021-04-13 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

If the effect is similar to entropic, why do we need this patch as well?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100161/new/

https://reviews.llvm.org/D100161

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


[PATCH] D100396: [SYCL] Enable `opencl_global_[host,device]` attributes for SYCL

2021-04-13 Thread Alexey Bader via Phabricator via cfe-commits
bader created this revision.
Herald added subscribers: Naghasan, ldrumm, dexonsmith, kerbowa, Anastasia, 
ebevhan, yaxunl, nhaehnle, jvesely, jholewinski.
bader requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100396

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/test/CodeGenSYCL/address-space-conversions.cpp
  clang/test/SemaSYCL/address-space-conversions.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388590)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388588)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x7FFFED>();
+  correct<0x7FFFEB>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: clang/test/SemaSYCL/address-space-conversions.cpp
===
--- clang/test/SemaSYCL/address-space-conversions.cpp
+++ clang/test/SemaSYCL/address-space-conversions.cpp
@@ -61,4 +61,15 @@
   void *v = GLOB;
   (void)i;
   (void)v;
+
+  __attribute__((opencl_global_host)) int *GLOB_HOST;
+  bar(*GLOB_HOST);
+  bar2(*GLOB_HOST);
+  GLOB = GLOB_HOST;
+  GLOB_HOST = GLOB; // expected-error {{assigning '__global int *' to '__global_host int *' changes address space of pointer}}
+  __attribute__((opencl_global_device)) int *GLOB_DEVICE;
+  bar(*GLOB_DEVICE);
+  bar2(*GLOB_DEVICE);
+  GLOB = GLOB_DEVICE;
+  GLOB_DEVICE = GLOB; // expected-error {{assigning '__global int *' to '__global_device int *' changes address space of pointer}}
 }
Index: clang/test/CodeGenSYCL/address-space-conversions.cpp
===
--- clang/test/CodeGenSYCL/address-space-conversions.cpp
+++ clang/test/CodeGenSYCL/address-space-conversions.cpp
@@ -29,6 +29,10 @@
   // CHECK-DAG: [[PRIV:%[a-zA-Z0-9]+]] = alloca i32*
   // CHECK-DAG: [[PRIV]].ascast = addrspacecast i32** [[PRIV]] to i32* addrspace(4)*
   __attribute__((opencl_private)) int *PRIV;
+  // CHECK-DAG: [[GLOB_DEVICE:%[a-zA-Z0-9]+]] = alloca i32 addrspace(5)*
+  __attribute__((opencl_global_device)) int *GLOBDEVICE;
+  // CHECK-DAG: [[GLOB_HOST:%[a-zA-Z0-9]+]] = alloca i32 addrspace(6)*
+  __attribute__((opencl_global_host)) int *GLOBHOST;
 
   // Explicit conversions
   // From names address spaces to default address space
Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -36,6 +36,8 @@
 0,   // cuda_constant
 0,   // cuda_shared
 0,   // sycl_global
+0,   // sycl_global_device
+0,   // sycl_global_host
 0,   // sycl_local
 0,   // sycl_private
 270, // ptr32_sptr
Index: clang/lib/Basic/Targets/TCE.h
===
--- clang/lib/Basic/Targets/TCE.h
+++ clang/lib/Basic/Targets/TCE.h
@@ -42,8 +42,10 @@
 0, // cuda_device
 0, // cuda_constant
 0, // cuda_shared
-3, // sycl_global
-4, // sycl_local
+0, // sycl_global
+0, // sycl_global_device
+0, // sycl_global_host
+0, // sycl_local
 0, // sycl_private
 0, // ptr32_sptr
 0, // ptr32_uptr
Index: clang/lib/Basic/Targets/SPIR.h
===
--- clang/lib/Basic/Targets/SPIR.h
+++ clang/lib/Basic/Targets/SPIR.h
@@ -35,6 +35,8 @@
 0, // cuda_shared
 // SYCL address space values for this map are dummy
 0, // sycl_global
+0, // sycl_global_device
+0, // sycl_global_host
 0, // sycl_local
 0, // sycl_private
 0, // ptr32_sptr
@@ -56,6 +58,8 @@
 0, // cuda_constant
 0, // cuda_shared
 1, // sycl_global
+5, // sycl_global_device
+6, // sycl_global_host
 3, //

[PATCH] D89909: [SYCL] Implement SYCL address space attributes handling

2021-04-13 Thread Alexey Bader via Phabricator via cfe-commits
bader marked 2 inline comments as done.
bader added inline comments.



Comment at: clang/include/clang/AST/Type.h:488
(A == LangAS::opencl_global && (B == LangAS::opencl_global_device ||
B == LangAS::opencl_global_host)) ||
// Consider pointer size address spaces to be equivalent to default.

Anastasia wrote:
> bader wrote:
> > BTW, we need enable `global_device` and `global_host` attributes from 
> > https://reviews.llvm.org/D82174 for SYCL USM feature. I have following 
> > question regarding this: should I create a follow-up patch or we can enable 
> > all attributes for SYCL at once?
> It seems like they would just be extending the existing functionality and not 
> redesigning what we do in this patch?
> 
> If that's the case let's keep it in a separate patch, but feel free to upload 
> it even now.
> It seems like they would just be extending the existing functionality and not 
> redesigning what we do in this patch?
> 
> If that's the case let's keep it in a separate patch, but feel free to upload 
> it even now.

Added in https://reviews.llvm.org/D100396.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89909/new/

https://reviews.llvm.org/D89909

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


[PATCH] D98902: [Clang][OpenMP][NVPTX] Fixed failure in openmp-offload-gpu.c if the system has CUDA

2021-04-13 Thread Kelvin Li via Phabricator via cfe-commits
kkwli0 accepted this revision.
kkwli0 added a comment.
This revision is now accepted and ready to land.

No more comments from the community.  I think it is okay to accept this 
revision.  Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98902/new/

https://reviews.llvm.org/D98902

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


[clang] 53d474a - [Clang][OpenMP][NVPTX] Fixed failure in openmp-offload-gpu.c if the system has CUDA

2021-04-13 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2021-04-13T13:22:49-04:00
New Revision: 53d474abc92c42bed5d0cab5c79ee9ea5666aad1

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

LOG: [Clang][OpenMP][NVPTX] Fixed failure in openmp-offload-gpu.c if the system 
has CUDA

https://lists.llvm.org/pipermail/openmp-dev/2021-March/003940.html reports
test failure in `openmp-offload-gpu.c`. The failure is, when using `-S` in the
clang driver, it still reports bitcode library doesn't exist. However, it is not
exposed in my local run and Phabiractor test. The reason it escaped from 
Phabricator
test is, the test machine doesn't have CUDA, so `LibDeviceFile` is empty. In 
this
case, the check of `OPT_S` will be hit, and we get "expected" result. However, 
if
the test machine has CUDA, `LibDeviceFile` will not be empty, then the check 
will
not be done, and it just proceeds, trying to add the bitcode library. The reason
it escaped from my local run is, I didn't build ALL targets, so this case was
marked UNSUPPORTED.

Reviewed By: kkwli0

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index be81d0f26f684..9e2dd515da4d7 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -696,13 +696,12 @@ void CudaToolChain::addClangTargetOptions(
   if (DriverArgs.hasArg(options::OPT_nogpulib))
 return;
 
-  std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
+  if (DeviceOffloadingKind == Action::OFK_OpenMP &&
+  DriverArgs.hasArg(options::OPT_S))
+return;
 
+  std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
   if (LibDeviceFile.empty()) {
-if (DeviceOffloadingKind == Action::OFK_OpenMP &&
-DriverArgs.hasArg(options::OPT_S))
-  return;
-
 getDriver().Diag(diag::err_drv_no_cuda_libdevice) << GpuArch;
 return;
   }



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


[PATCH] D98902: [Clang][OpenMP][NVPTX] Fixed failure in openmp-offload-gpu.c if the system has CUDA

2021-04-13 Thread Shilei Tian via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG53d474abc92c: [Clang][OpenMP][NVPTX] Fixed failure in 
openmp-offload-gpu.c if the system has… (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98902/new/

https://reviews.llvm.org/D98902

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp


Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -696,13 +696,12 @@
   if (DriverArgs.hasArg(options::OPT_nogpulib))
 return;
 
-  std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
+  if (DeviceOffloadingKind == Action::OFK_OpenMP &&
+  DriverArgs.hasArg(options::OPT_S))
+return;
 
+  std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
   if (LibDeviceFile.empty()) {
-if (DeviceOffloadingKind == Action::OFK_OpenMP &&
-DriverArgs.hasArg(options::OPT_S))
-  return;
-
 getDriver().Diag(diag::err_drv_no_cuda_libdevice) << GpuArch;
 return;
   }


Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -696,13 +696,12 @@
   if (DriverArgs.hasArg(options::OPT_nogpulib))
 return;
 
-  std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
+  if (DeviceOffloadingKind == Action::OFK_OpenMP &&
+  DriverArgs.hasArg(options::OPT_S))
+return;
 
+  std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
   if (LibDeviceFile.empty()) {
-if (DeviceOffloadingKind == Action::OFK_OpenMP &&
-DriverArgs.hasArg(options::OPT_S))
-  return;
-
 getDriver().Diag(diag::err_drv_no_cuda_libdevice) << GpuArch;
 return;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99568: [clang][invocation] Fix copy constructor of CompilerInvocation

2021-04-13 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99568/new/

https://reviews.llvm.org/D99568

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


[PATCH] D100346: [Clang] String Literal and Wide String Literal Encoding from the Preprocessor

2021-04-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

In D100346#2686015 , @ThePhD wrote:

> In D100346#2685530 , @aaron.ballman 
> wrote:
>
>> ...
>>
>> What about for folks using this from C where there isn't `constexpr` 
>> functionality to help them?
>
>
>
>> ...
>
> I'm not sure all of that belongs in this patch, though, and I think I'd wait 
> for the other patches about `iconv` literal converters to drop before having 
> the fullness of that conversation.

Okay, I'm sold. Thank you for the detailed explanation! The changes LGTM. Do 
you have commit privileges or would you like me to commit on your behalf? (If 
you'd like me to commit, what email address and name would you like me to use 
for commit attribution?)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100346/new/

https://reviews.llvm.org/D100346

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


[PATCH] D100346: [Clang] String Literal and Wide String Literal Encoding from the Preprocessor

2021-04-13 Thread ThePhD via Phabricator via cfe-commits
ThePhD added a comment.

In D100346#2686342 , @aaron.ballman 
wrote:

> Okay, I'm sold. Thank you for the detailed explanation! The changes LGTM. Do 
> you have commit privileges or would you like me to commit on your behalf? (If 
> you'd like me to commit, what email address and name would you like me to use 
> for commit attribution?)

I don't have commit privileges! You should use `ThePhD 
`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100346/new/

https://reviews.llvm.org/D100346

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


[PATCH] D93822: [clang-tidy] Add check for implicit widening of multiplication result

2021-04-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from some small nits in the documentation.




Comment at: 
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp:130
+  StringRef TyAsString =
+  IndexExprType->isSignedIntegerType() ? "ssize_t" : "size_t";
+

lebedev.ri wrote:
> aaron.ballman wrote:
> > aaron.ballman wrote:
> > > One thing that's awkward about this is that there's no portable `ssize_t` 
> > > type -- that's a POSIX type but it doesn't exist on all platforms (like 
> > > Windows). We shouldn't print out a typecast that's going to cause compile 
> > > errors, but we also shouldn't use the underlying type for `ssize_t` as 
> > > that may be incorrect for other target architectures.
> > I'm still not quite certain what to do about this. Would it make sense to 
> > use the underlying type on platforms that don't have `ssize_t`? Relatedly, 
> > if we're going to suggest this as a replacement, we should also insert an 
> > include for the correct header file.
> I've been thinking about this, and i really can't come up with a better fix 
> than using `ptrdiff_t`.
I'm not super excited about using `ptrdiff_t` as there are not likely to be 
pointer subtractions in the vicinity of the code being diagnosed, but at the 
same time, `ptrdiff_t` is functionally the same as `size_t` except with a sign 
bit, which is what `ssize_t` is. I'll hold my nose for now, but if we get bug 
reports about this use, we may want to investigate more involved solutions.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-implicit-widening-of-multiplication-result.rst:40
+   When suggesting fix-its for C++ code, should C++-style ``static_cast<>()``'s
+   be suggested, or C-style casts.
+

Add info about the default behavior.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-implicit-widening-of-multiplication-result.rst:45
+   When suggesting to include the appropriate header in C++ code,
+   should  header be suggested, or .
+

Same here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93822/new/

https://reviews.llvm.org/D93822

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


[PATCH] D100402: [WebAssembly] Codegen for i64x2.extend_{low,high}_i32x4_{s,u}

2021-04-13 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, dschuff.
Herald added subscribers: wingo, ecnelises, sunfish, hiraditya, 
jgravelle-google, sbc100.
tlively requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Removes the builtins and intrinsics used to opt in to using these instructions
and replaces them with normal ISel patterns now that they are no longer
prototypes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100402

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-extending.ll
  llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll

Index: llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -553,46 +553,6 @@
 ; ==
 ; 2 x i64
 ; ==
-; CHECK-LABEL: extend_low_s_v2i64:
-; CHECK-NEXT: .functype extend_low_s_v2i64 (v128) -> (v128){{$}}
-; CHECK-NEXT: i64x2.extend_low_i32x4_s $push[[R:[0-9]+]]=, $0{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <2 x i64> @llvm.wasm.extend.low.signed(<4 x i32>)
-define <2 x i64> @extend_low_s_v2i64(<4 x i32> %x) {
-  %a = call <2 x i64> @llvm.wasm.extend.low.signed(<4 x i32> %x)
-  ret <2 x i64> %a
-}
-
-; CHECK-LABEL: extend_high_s_v2i64:
-; CHECK-NEXT: .functype extend_high_s_v2i64 (v128) -> (v128){{$}}
-; CHECK-NEXT: i64x2.extend_high_i32x4_s $push[[R:[0-9]+]]=, $0{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <2 x i64> @llvm.wasm.extend.high.signed(<4 x i32>)
-define <2 x i64> @extend_high_s_v2i64(<4 x i32> %x) {
-  %a = call <2 x i64> @llvm.wasm.extend.high.signed(<4 x i32> %x)
-  ret <2 x i64> %a
-}
-
-; CHECK-LABEL: extend_low_u_v2i64:
-; CHECK-NEXT: .functype extend_low_u_v2i64 (v128) -> (v128){{$}}
-; CHECK-NEXT: i64x2.extend_low_i32x4_u $push[[R:[0-9]+]]=, $0{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <2 x i64> @llvm.wasm.extend.low.unsigned(<4 x i32>)
-define <2 x i64> @extend_low_u_v2i64(<4 x i32> %x) {
-  %a = call <2 x i64> @llvm.wasm.extend.low.unsigned(<4 x i32> %x)
-  ret <2 x i64> %a
-}
-
-; CHECK-LABEL: extend_high_u_v2i64:
-; CHECK-NEXT: .functype extend_high_u_v2i64 (v128) -> (v128){{$}}
-; CHECK-NEXT: i64x2.extend_high_i32x4_u $push[[R:[0-9]+]]=, $0{{$}}
-; CHECK-NEXT: return $pop[[R]]{{$}}
-declare <2 x i64> @llvm.wasm.extend.high.unsigned(<4 x i32>)
-define <2 x i64> @extend_high_u_v2i64(<4 x i32> %x) {
-  %a = call <2 x i64> @llvm.wasm.extend.high.unsigned(<4 x i32> %x)
-  ret <2 x i64> %a
-}
-
 ; CHECK-LABEL: extmul_low_s_v2i64:
 ; CHECK-NEXT: .functype extmul_low_s_v2i64 (v128, v128) -> (v128){{$}}
 ; CHECK-NEXT: i64x2.extmul_low_i32x4_s $push[[R:[0-9]+]]=, $0, $1{{$}}
Index: llvm/test/CodeGen/WebAssembly/simd-extending.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-extending.ll
+++ llvm/test/CodeGen/WebAssembly/simd-extending.ll
@@ -110,6 +110,58 @@
   ret <4 x i32> %extended
 }
 
+define <2 x i64> @extend_low_i32x4_s(<4 x i32> %v) {
+; CHECK-LABEL: extend_low_i32x4_s:
+; CHECK: .functype extend_low_i32x4_s (v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:i64x2.extend_low_i32x4_s
+; CHECK-NEXT:# fallthrough-return
+  %low = shufflevector <4 x i32> %v, <4 x i32> undef,
+   <2 x i32> 
+  %extended = sext <2 x i32> %low to <2 x i64>
+  ret <2 x i64> %extended
+}
+
+define <2 x i64> @extend_low_i32x4_u(<4 x i32> %v) {
+; CHECK-LABEL: extend_low_i32x4_u:
+; CHECK: .functype extend_low_i32x4_u (v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:i64x2.extend_low_i32x4_u
+; CHECK-NEXT:# fallthrough-return
+  %low = shufflevector <4 x i32> %v, <4 x i32> undef,
+   <2 x i32> 
+  %extended = zext <2 x i32> %low to <2 x i64>
+  ret <2 x i64> %extended
+}
+
+define <2 x i64> @extend_high_i32x4_s(<4 x i32> %v) {
+; CHECK-LABEL: extend_high_i32x4_s:
+; CHECK: .functype extend_high_i32x4_s (v128) -> (v128)
+; CHECK-NEXT:  # %bb.0:
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:i64x2.extend_high_i32x4_s
+; CHECK-NEXT:# fallthrough-return
+  %low = shufflevector <4 x i32> %v, <4 x i32> undef,
+   <2 x i32> 
+  %extended = sext <2 x i32> %low to <2 x i64>
+  ret <2 x i64> %extended
+}
+
+define <2 x i64> @extend_high_i32x4_u(<4 x i32> %v) {
+; CHECK-LABEL: extend_high_i32x4_u:
+; CHECK: .functype extend_high_i32x4_u (v128) -> (v128)
+; CHECK-NEXT

[PATCH] D100346: [Clang] String Literal and Wide String Literal Encoding from the Preprocessor

2021-04-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

In D100346#2686407 , @ThePhD wrote:

> In D100346#2686342 , @aaron.ballman 
> wrote:
>
>> Okay, I'm sold. Thank you for the detailed explanation! The changes LGTM. Do 
>> you have commit privileges or would you like me to commit on your behalf? 
>> (If you'd like me to commit, what email address and name would you like me 
>> to use for commit attribution?)
>
> I don't have commit privileges! You should use `ThePhD 
> `.

Thank you for the contribution! I've commit it on your behalf in 
701d70d4c25c4e02b303ba6dee1495708496f615 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100346/new/

https://reviews.llvm.org/D100346

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


[clang] 701d70d - String Literal and Wide String Literal Encoding from the Preprocessor

2021-04-13 Thread Aaron Ballman via cfe-commits

Author: ThePhD
Date: 2021-04-13T14:18:07-04:00
New Revision: 701d70d4c25c4e02b303ba6dee1495708496f615

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

LOG: String Literal and Wide String Literal Encoding from the Preprocessor

Adds the __clang_literal_encoding__ and __clang_wide_literal_encoding__
predefined macros to expose the encoding used for string literals to
the preprocessor.

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Preprocessor/init-x86.c
clang/test/Preprocessor/init.c

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index a906dc79e03bc..00759113775d4 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -383,6 +383,18 @@ Builtin Macros
   Defined to a string that captures the Clang marketing version, including the
   Subversion tag or revision number, e.g., "``1.5 (trunk 102332)``".
 
+``__clang_literal_encoding__``
+  Defined to a narrow string literal that represents the current encoding of
+  narrow string literals, e.g., ``"hello"``. This macro typically expands to
+  "UTF-8" (but may change in the future if the
+  ``-fexec-charset="Encoding-Name"`` option is implemented.)
+
+``__clang_wide_literal_encoding__``
+  Defined to a narrow string literal that represents the current encoding of
+  wide string literals, e.g., ``L"hello"``. This macro typically expands to
+  "UTF-16" or "UTF-32" (but may change in the future if the
+  ``-fwide-exec-charset="Encoding-Name"`` option is implemented.)
+
 .. _langext-vectors:
 
 Vectors and Extended Vectors

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 3d69c59d166d0..7876a36034071 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -778,6 +778,21 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
 }
   }
 
+  // Macros to help identify the narrow and wide character sets
+  // FIXME: clang currently ignores -fexec-charset=. If this changes,
+  // then this may need to be updated.
+  Builder.defineMacro("__clang_literal_encoding__", "\"UTF-8\"");
+  if (TI.getTypeWidth(TI.getWCharType()) >= 32) {
+// FIXME: 32-bit wchar_t signals UTF-32. This may change
+// if -fwide-exec-charset= is ever supported.
+Builder.defineMacro("__clang_wide_literal_encoding__", "\"UTF-32\"");
+  } else {
+// FIXME: Less-than 32-bit wchar_t generally means UTF-16
+// (e.g., Windows, 32-bit IBM). This may need to be
+// updated if -fwide-exec-charset= is ever supported.
+Builder.defineMacro("__clang_wide_literal_encoding__", "\"UTF-16\"");
+  }
+
   if (LangOpts.Optimize)
 Builder.defineMacro("__OPTIMIZE__");
   if (LangOpts.OptimizeSize)

diff  --git a/clang/test/Preprocessor/init-x86.c 
b/clang/test/Preprocessor/init-x86.c
index d22a2ab6e1188..527cd39508889 100644
--- a/clang/test/Preprocessor/init-x86.c
+++ b/clang/test/Preprocessor/init-x86.c
@@ -1306,10 +1306,12 @@
 // X86_64-CLOUDABI:#define __amd64 1
 // X86_64-CLOUDABI:#define __amd64__ 1
 // X86_64-CLOUDABI:#define __clang__ 1
+// X86_64-CLOUDABI:#define __clang_literal_encoding__ {{.*}}
 // X86_64-CLOUDABI:#define __clang_major__ {{.*}}
 // X86_64-CLOUDABI:#define __clang_minor__ {{.*}}
 // X86_64-CLOUDABI:#define __clang_patchlevel__ {{.*}}
 // X86_64-CLOUDABI:#define __clang_version__ {{.*}}
+// X86_64-CLOUDABI:#define __clang_wide_literal_encoding__ {{.*}}
 // X86_64-CLOUDABI:#define __llvm__ 1
 // X86_64-CLOUDABI:#define __x86_64 1
 // X86_64-CLOUDABI:#define __x86_64__ 1

diff  --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 136200a97840c..0329453c4136b 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -115,10 +115,12 @@
 // COMMON:#define __STDC__ 1
 // COMMON:#define __VERSION__ {{.*}}
 // COMMON:#define __clang__ 1
+// COMMON:#define __clang_literal_encoding__ {{.*}}
 // COMMON:#define __clang_major__ {{[0-9]+}}
 // COMMON:#define __clang_minor__ {{[0-9]+}}
 // COMMON:#define __clang_patchlevel__ {{[0-9]+}}
 // COMMON:#define __clang_version__ {{.*}}
+// COMMON:#define __clang_wide_literal_encoding__ {{.*}}
 // COMMON:#define __llvm__ 1
 //
 // RUN: %clang_cc1 -E -dM -triple=x86_64-pc-win32 < /dev/null | FileCheck 
-match-full-lines -check-prefix C-DEFAULT %s
@@ -1844,10 +1846,12 @@
 // WEBASSEMBLY-NOT:#define __WINT_UNSIGNED__
 // WEBASSEMBLY-NEXT:#define __WINT_WIDTH__ 32
 // WEBASSEMBLY-NEXT:#define __clang__ 1
+// WEBASSEMBLY-NEXT:#define __clang_literal_encoding__ {{.*}}
 // WEBASSEMBLY-NEXT:#define __clang_major__ {{.*}}
 // WEBASSEMBLY-NEXT:#define __clang_minor__ {{.*}}
 // WEBASSEMBLY-NEXT:#define _

[PATCH] D93822: [clang-tidy] Add check for implicit widening of multiplication result

2021-04-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 337214.
lebedev.ri marked 2 inline comments as done.
lebedev.ri added a comment.

Address final nits.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93822/new/

https://reviews.llvm.org/D93822

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
  
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-implicit-widening-of-multiplication-result.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-array-subscript-expression.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-char.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-extint.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-int.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-pointer-offset.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-short.cpp
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp

Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -10097,7 +10097,12 @@
 return getVectorType(getCorrespondingUnsignedType(VTy->getElementType()),
  VTy->getNumElements(), VTy->getVectorKind());
 
-  // For enums, we return the unsigned version of the base type.
+  // For _ExtInt, return an unsigned _ExtInt with same width.
+  if (const auto *EITy = T->getAs())
+return getExtIntType(/*IsUnsigned=*/true, EITy->getNumBits());
+
+  // For enums, get the underlying integer type of the enum, and let the general
+  // integer type signchanging code handle it.
   if (const auto *ETy = T->getAs())
 T = ETy->getDecl()->getIntegerType();
 
@@ -10150,6 +10155,74 @@
   }
 }
 
+QualType ASTContext::getCorrespondingSignedType(QualType T) const {
+  assert((T->hasUnsignedIntegerRepresentation() ||
+  T->isUnsignedFixedPointType()) &&
+ "Unexpected type");
+
+  // Turn <4 x unsigned int> -> <4 x signed int>
+  if (const auto *VTy = T->getAs())
+return getVectorType(getCorrespondingSignedType(VTy->getElementType()),
+ VTy->getNumElements(), VTy->getVectorKind());
+
+  // For _ExtInt, return a signed _ExtInt with same width.
+  if (const auto *EITy = T->getAs())
+return getExtIntType(/*IsUnsigned=*/false, EITy->getNumBits());
+
+  // For enums, get the underlying integer type of the enum, and let the general
+  // integer type signchanging code handle it.
+  if (const auto *ETy = T->getAs())
+T = ETy->getDecl()->getIntegerType();
+
+  switch (T->castAs()->getKind()) {
+  case BuiltinType::Char_U:
+  case BuiltinType::UChar:
+return SignedCharTy;
+  case BuiltinType::UShort:
+return ShortTy;
+  case BuiltinType::UInt:
+return IntTy;
+  case BuiltinType::ULong:
+return LongTy;
+  case BuiltinType::ULongLong:
+return LongLongTy;
+  case BuiltinType::UInt128:
+return Int128Ty;
+  // wchar_t is special. It is either unsigned or not, but when it's unsigned,
+  // there's no matching "signed wchar_t". Therefore we return the signed
+  // version of it's underlying type instead.
+  case BuiltinType::WChar_U:
+return getSignedWCharType();
+
+  case BuiltinType::UShortAccum:
+return ShortAccumTy;
+  case BuiltinType::UAccum:
+return AccumTy;
+  case BuiltinType::ULongAccum:
+return LongAccumTy;
+  case BuiltinType::SatUShortAccum:
+return SatShortAccumTy;
+  case BuiltinType::SatUAccum:
+return SatAccumTy;
+  case BuiltinType::SatULongAccum:
+return SatLongAccumTy;
+  case BuiltinType::UShortFract:
+return ShortFractTy;
+  case BuiltinType::UFract:
+return FractTy;
+  case BuiltinType::ULongFract:
+return LongFractTy;
+  case BuiltinType::SatUShortFract:
+return SatShortFractTy;
+  case BuiltinType::SatUFract:
+return SatFractTy;
+  case BuiltinType::SatULongFract:
+return SatLongFractTy;
+  default:
+llvm_unreachable("Unexpected unsigned integer or fixed point type");
+  }
+}
+
 ASTMutationListener::~ASTMutationListener() = default;
 
 void ASTMutationListener::DeducedReturnType(const FunctionDecl *FD,
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -2748,6 +2748,14 @@
   // a given fixed point type.
   Qu

[PATCH] D93822: [clang-tidy] Add check for implicit widening of multiplication result

2021-04-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

@aaron.ballman thank you so much for the review!




Comment at: 
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp:130
+  StringRef TyAsString =
+  IndexExprType->isSignedIntegerType() ? "ssize_t" : "size_t";
+

aaron.ballman wrote:
> lebedev.ri wrote:
> > aaron.ballman wrote:
> > > aaron.ballman wrote:
> > > > One thing that's awkward about this is that there's no portable 
> > > > `ssize_t` type -- that's a POSIX type but it doesn't exist on all 
> > > > platforms (like Windows). We shouldn't print out a typecast that's 
> > > > going to cause compile errors, but we also shouldn't use the underlying 
> > > > type for `ssize_t` as that may be incorrect for other target 
> > > > architectures.
> > > I'm still not quite certain what to do about this. Would it make sense to 
> > > use the underlying type on platforms that don't have `ssize_t`? 
> > > Relatedly, if we're going to suggest this as a replacement, we should 
> > > also insert an include for the correct header file.
> > I've been thinking about this, and i really can't come up with a better fix 
> > than using `ptrdiff_t`.
> I'm not super excited about using `ptrdiff_t` as there are not likely to be 
> pointer subtractions in the vicinity of the code being diagnosed, but at the 
> same time, `ptrdiff_t` is functionally the same as `size_t` except with a 
> sign bit, which is what `ssize_t` is. I'll hold my nose for now, but if we 
> get bug reports about this use, we may want to investigate more involved 
> solutions.
Yep. `signed size_t` isn't a valid type, so at best i guess we could avoid 
emitting such a fixit.
In C++, `std::make_signed::type` is valid, but it's kinda mouthful.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93822/new/

https://reviews.llvm.org/D93822

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


[clang-tools-extra] 46b8ea2 - [clang-tidy] Add check for implicit widening of multiplication result

2021-04-13 Thread Roman Lebedev via cfe-commits

Author: Roman Lebedev
Date: 2021-04-13T21:41:22+03:00
New Revision: 46b8ea2fff90b44b7ae558999721cf30f9b83aa9

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

LOG: [clang-tidy] Add check for implicit widening of multiplication result

Overflows are never fun.
In most cases (in most of the code), they are rare,
because usually you e.g. don't have as many elements.

However, it's exceptionally easy to fall into this pitfail
in code that deals with images, because, assuming 4-channel 32-bit FP data,
you need *just* ~269 megapixel image to case an overflow
when computing at least the total byte count.

In [[ https://github.com/darktable-org/darktable | darktable ]], there is a 
*long*, painful history of dealing with such bugs:
* https://github.com/darktable-org/darktable/pull/7740
* https://github.com/darktable-org/darktable/pull/7419
* 
https://github.com/darktable-org/darktable/commit/eea1989f2c9fa76710db07baaec4c19c1e40e81c
* 
https://github.com/darktable-org/darktable/commit/70626dd95bf0fab36f2d011dab075e3ebbf7aa28
* https://github.com/darktable-org/darktable/pull/670
* 
https://github.com/darktable-org/darktable/commit/38c69fb1b2bc90057c569242cb9945a10be0b583

and yet they clearly keep resurfacing still.

It would be immensely helpful to have a diagnostic for those patterns,
which is what this change proposes.

Currently, i only diagnose the most obvious case, where multiplication
is directly widened with no other expressions inbetween,
(i.e. `long r = (int)a * (int)b` but not even e.g. `long r = ((int)a * (int)b)`)
however that might be worth relaxing later.

Reviewed By: aaron.ballman

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

Added: 

clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp

clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.h

clang-tools-extra/docs/clang-tidy/checks/bugprone-implicit-widening-of-multiplication-result.rst

clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-array-subscript-expression.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-char.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-extint.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-int.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-pointer-offset.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-short.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst
clang/include/clang/AST/ASTContext.h
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 7f4d40f970117..9cdadf7bf92ba 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -22,6 +22,7 @@
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
 #include "ForwardingReferenceOverloadCheck.h"
+#include "ImplicitWideningOfMultiplicationResultCheck.h"
 #include "InaccurateEraseCheck.h"
 #include "IncorrectRoundingsCheck.h"
 #include "InfiniteLoopCheck.h"
@@ -97,6 +98,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-forward-declaration-namespace");
 CheckFactories.registerCheck(
 "bugprone-forwarding-reference-overload");
+CheckFactories.registerCheck(
+"bugprone-implicit-widening-of-multiplication-result");
 CheckFactories.registerCheck(
 "bugprone-inaccurate-erase");
 CheckFactories.registerCheck(

diff  --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index b3684a5c101b5..b16dbf576c374 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -17,6 +17,7 @@ add_clang_library(clangTidyBugproneModule
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
   ForwardingReferenceOverloadCheck.cpp
+  ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectRoundingsCheck.cpp
   InfiniteLoopCheck.cpp

diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
 
b/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResult

[PATCH] D93822: [clang-tidy] Add check for implicit widening of multiplication result

2021-04-13 Thread Roman Lebedev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG46b8ea2fff90: [clang-tidy] Add check for implicit widening 
of multiplication result (authored by lebedev.ri).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93822/new/

https://reviews.llvm.org/D93822

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
  
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-implicit-widening-of-multiplication-result.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-array-subscript-expression.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-char.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-extint.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-int.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-pointer-offset.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-implicit-widening-of-multiplication-result-short.cpp
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp

Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -10097,7 +10097,12 @@
 return getVectorType(getCorrespondingUnsignedType(VTy->getElementType()),
  VTy->getNumElements(), VTy->getVectorKind());
 
-  // For enums, we return the unsigned version of the base type.
+  // For _ExtInt, return an unsigned _ExtInt with same width.
+  if (const auto *EITy = T->getAs())
+return getExtIntType(/*IsUnsigned=*/true, EITy->getNumBits());
+
+  // For enums, get the underlying integer type of the enum, and let the general
+  // integer type signchanging code handle it.
   if (const auto *ETy = T->getAs())
 T = ETy->getDecl()->getIntegerType();
 
@@ -10150,6 +10155,74 @@
   }
 }
 
+QualType ASTContext::getCorrespondingSignedType(QualType T) const {
+  assert((T->hasUnsignedIntegerRepresentation() ||
+  T->isUnsignedFixedPointType()) &&
+ "Unexpected type");
+
+  // Turn <4 x unsigned int> -> <4 x signed int>
+  if (const auto *VTy = T->getAs())
+return getVectorType(getCorrespondingSignedType(VTy->getElementType()),
+ VTy->getNumElements(), VTy->getVectorKind());
+
+  // For _ExtInt, return a signed _ExtInt with same width.
+  if (const auto *EITy = T->getAs())
+return getExtIntType(/*IsUnsigned=*/false, EITy->getNumBits());
+
+  // For enums, get the underlying integer type of the enum, and let the general
+  // integer type signchanging code handle it.
+  if (const auto *ETy = T->getAs())
+T = ETy->getDecl()->getIntegerType();
+
+  switch (T->castAs()->getKind()) {
+  case BuiltinType::Char_U:
+  case BuiltinType::UChar:
+return SignedCharTy;
+  case BuiltinType::UShort:
+return ShortTy;
+  case BuiltinType::UInt:
+return IntTy;
+  case BuiltinType::ULong:
+return LongTy;
+  case BuiltinType::ULongLong:
+return LongLongTy;
+  case BuiltinType::UInt128:
+return Int128Ty;
+  // wchar_t is special. It is either unsigned or not, but when it's unsigned,
+  // there's no matching "signed wchar_t". Therefore we return the signed
+  // version of it's underlying type instead.
+  case BuiltinType::WChar_U:
+return getSignedWCharType();
+
+  case BuiltinType::UShortAccum:
+return ShortAccumTy;
+  case BuiltinType::UAccum:
+return AccumTy;
+  case BuiltinType::ULongAccum:
+return LongAccumTy;
+  case BuiltinType::SatUShortAccum:
+return SatShortAccumTy;
+  case BuiltinType::SatUAccum:
+return SatAccumTy;
+  case BuiltinType::SatULongAccum:
+return SatLongAccumTy;
+  case BuiltinType::UShortFract:
+return ShortFractTy;
+  case BuiltinType::UFract:
+return FractTy;
+  case BuiltinType::ULongFract:
+return LongFractTy;
+  case BuiltinType::SatUShortFract:
+return SatShortFractTy;
+  case BuiltinType::SatUFract:
+return SatFractTy;
+  case BuiltinType::SatULongFract:
+return SatLongFractTy;
+  default:
+llvm_unreachable("Unexpected unsigned integer or fixed point type");
+  }
+}
+
 ASTMutationListener::~ASTMutationListener() = default;
 
 void ASTMutationListener::DeducedReturnType(const FunctionDecl *FD,
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AS

[PATCH] D99812: [PowerPC] [GlobalISel] Implementation of formal arguments lowering in the IRTranslator for the PPC backend

2021-04-13 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 marked 2 inline comments as done.
gandhi21299 added a comment.

I am looking towards more feedback on this patch, please do follow up at your 
convenience.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99812/new/

https://reviews.llvm.org/D99812

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


[PATCH] D100057: Remove warning "suggest braces" for aggregate initialization of an empty class with an aggregate base class.

2021-04-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Do you need someone to commit this on your behalf? If so, what email address 
and name would you like me to use for commit attribution?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100057/new/

https://reviews.llvm.org/D100057

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


[PATCH] D100405: Ship `llvm-cxxfilt` in the toolchain.

2021-04-13 Thread Dan Liew via Phabricator via cfe-commits
delcypher created this revision.
delcypher added reviewers: steven_wu, arphaman, dexonsmith.
Herald added subscribers: yaxunl, mgorny.
delcypher requested review of this revision.
Herald added a project: clang.

Originally done for rdar://problem/57155465.

rdar://76602859


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100405

Files:
  clang/cmake/caches/Apple-stage2.cmake


Index: clang/cmake/caches/Apple-stage2.cmake
===
--- clang/cmake/caches/Apple-stage2.cmake
+++ clang/cmake/caches/Apple-stage2.cmake
@@ -56,6 +56,7 @@
   llvm-objdump
   llvm-nm
   llvm-size
+  llvm-cxxfilt
   llvm-config
   CACHE STRING "")
 


Index: clang/cmake/caches/Apple-stage2.cmake
===
--- clang/cmake/caches/Apple-stage2.cmake
+++ clang/cmake/caches/Apple-stage2.cmake
@@ -56,6 +56,7 @@
   llvm-objdump
   llvm-nm
   llvm-size
+  llvm-cxxfilt
   llvm-config
   CACHE STRING "")
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D100405: Ship `llvm-cxxfilt` in the toolchain.

2021-04-13 Thread Steven Wu via Phabricator via cfe-commits
steven_wu accepted this revision.
steven_wu added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100405/new/

https://reviews.llvm.org/D100405

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


[clang] 4c0bc69 - Ship `llvm-cxxfilt` in the toolchain.

2021-04-13 Thread Dan Liew via cfe-commits

Author: Dan Liew
Date: 2021-04-13T11:58:33-07:00
New Revision: 4c0bc69490a57f2f8f9ede948e6d66cc0900879a

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

LOG: Ship `llvm-cxxfilt` in the toolchain.

Originally done for rdar://problem/57155465.

rdar://76602859

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

Added: 


Modified: 
clang/cmake/caches/Apple-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Apple-stage2.cmake 
b/clang/cmake/caches/Apple-stage2.cmake
index d347ffcd0f4ff..a2eb42efbaf67 100644
--- a/clang/cmake/caches/Apple-stage2.cmake
+++ b/clang/cmake/caches/Apple-stage2.cmake
@@ -56,6 +56,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-objdump
   llvm-nm
   llvm-size
+  llvm-cxxfilt
   llvm-config
   CACHE STRING "")
 



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


[PATCH] D100405: Ship `llvm-cxxfilt` in the toolchain.

2021-04-13 Thread Dan Liew via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4c0bc69490a5: Ship `llvm-cxxfilt` in the toolchain. 
(authored by delcypher).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100405/new/

https://reviews.llvm.org/D100405

Files:
  clang/cmake/caches/Apple-stage2.cmake


Index: clang/cmake/caches/Apple-stage2.cmake
===
--- clang/cmake/caches/Apple-stage2.cmake
+++ clang/cmake/caches/Apple-stage2.cmake
@@ -56,6 +56,7 @@
   llvm-objdump
   llvm-nm
   llvm-size
+  llvm-cxxfilt
   llvm-config
   CACHE STRING "")
 


Index: clang/cmake/caches/Apple-stage2.cmake
===
--- clang/cmake/caches/Apple-stage2.cmake
+++ clang/cmake/caches/Apple-stage2.cmake
@@ -56,6 +56,7 @@
   llvm-objdump
   llvm-nm
   llvm-size
+  llvm-cxxfilt
   llvm-config
   CACHE STRING "")
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99543: [clang-tidy] Allow opt-in or out of some commonly occuring patterns in NarrowingConversionsCheck.

2021-04-13 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.
This revision is now accepted and ready to land.

But please wait for additional "Accept" from either `hokein` or 
`aaron.ballman`. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99543/new/

https://reviews.llvm.org/D99543

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


[clang] c058a71 - Correct the tablegen for checking mutually exclusive stmt attrs

2021-04-13 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-04-13T15:20:30-04:00
New Revision: c058a7122787c8e503cf6306b8da03c0e56a41a5

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

LOG: Correct the tablegen for checking mutually exclusive stmt attrs

The previous implementation was insufficient for checking statement
attribute mutual exclusion because attributed statements do not collect
their attributes one-at-a-time in the same way that declarations do. So
the design that was attempting to check for mutual exclusion as each
attribute was processed would not ever catch a mutual exclusion in a
statement. This was missed due to insufficient test coverage, which has
now been added for the [[likely]] and [[unlikely]] attributes.

The new approach is to check all of attributes that are to be applied
to the attributed statement in a group. This required generating
another DiagnoseMutualExclusions() function into AttrParsedAttrImpl.inc.

Added: 


Modified: 
clang/include/clang/Sema/ParsedAttr.h
clang/lib/Sema/ParsedAttr.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaStmtAttr.cpp
clang/test/SemaCXX/attr-likelihood.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/ParsedAttr.h 
b/clang/include/clang/Sema/ParsedAttr.h
index 471a1ecfac9b2..e508b4651be1c 100644
--- a/clang/include/clang/Sema/ParsedAttr.h
+++ b/clang/include/clang/Sema/ParsedAttr.h
@@ -92,12 +92,6 @@ struct ParsedAttrInfo {
const Decl *D) const {
 return true;
   }
-  /// Check if the given attribute is mutually exclusive with other attributes
-  /// already applied to the given statement.
-  virtual bool diagMutualExclusion(Sema &S, const ParsedAttr &A,
-   const Stmt *St) const {
-return true;
-  }
   /// Check if this attribute is allowed by the language we are compiling, and
   /// issue a diagnostic if not.
   virtual bool diagLangOpts(Sema &S, const ParsedAttr &Attr) const {
@@ -612,7 +606,12 @@ class ParsedAttr final
   bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const;
   bool diagnoseAppertainsTo(class Sema &S, const Stmt *St) const;
   bool diagnoseMutualExclusion(class Sema &S, const Decl *D) const;
-  bool diagnoseMutualExclusion(class Sema &S, const Stmt *St) const;
+  // This function stub exists for parity with the declaration checking code so
+  // that checkCommonAttributeFeatures() can work generically on declarations
+  // or statements.
+  bool diagnoseMutualExclusion(class Sema &S, const Stmt *St) const {
+return true;
+  }
   bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const;
   void getMatchRules(const LangOptions &LangOpts,
  SmallVectorImpl>

diff  --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index 989db3c2a4064..ed03b0c7f688b 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -167,10 +167,6 @@ bool ParsedAttr::diagnoseMutualExclusion(Sema &S, const 
Decl *D) const {
   return getInfo().diagMutualExclusion(S, *this, D);
 }
 
-bool ParsedAttr::diagnoseMutualExclusion(Sema &S, const Stmt *St) const {
-  return getInfo().diagMutualExclusion(S, *this, St);
-}
-
 bool ParsedAttr::appliesToDecl(const Decl *D,
attr::SubjectMatchRule MatchRule) const {
   return checkAttributeMatchRuleAppliesTo(D, MatchRule);

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ea9f0949eac25..1d57d8e848497 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2540,9 +2540,9 @@ static bool mergeAlignedAttrs(Sema &S, NamedDecl *New, 
Decl *Old) {
   return AnyAdded;
 }
 
-#define WANT_MERGE_LOGIC
+#define WANT_DECL_MERGE_LOGIC
 #include "clang/Sema/AttrParsedAttrImpl.inc"
-#undef WANT_MERGE_LOGIC
+#undef WANT_DECL_MERGE_LOGIC
 
 static bool mergeDeclAttribute(Sema &S, NamedDecl *D,
const InheritableAttr *Attr,

diff  --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index f914f1273f719..763c6b61fbd90 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -227,9 +227,22 @@ static Attr *handleUnlikely(Sema &S, Stmt *St, const 
ParsedAttr &A,
   return ::new (S.Context) UnlikelyAttr(S.Context, A);
 }
 
+#define WANT_STMT_MERGE_LOGIC
+#include "clang/Sema/AttrParsedAttrImpl.inc"
+#undef WANT_STMT_MERGE_LOGIC
+
 static void
 CheckForIncompatibleAttributes(Sema &S,
const SmallVectorImpl &Attrs) {
+  // The vast majority of attributed statements will only have one attribute
+  // on them, so skip all of the checking in the common case.
+  if (Attrs.size() < 2)
+return;
+
+  // First, check

[PATCH] D40660: Enable auto-linking on Windows

2021-04-13 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo edited subscribers, added: libcxx-commits, mstorsjo; removed: 
llvm-commits, cfe-commits.
mstorsjo added a comment.

I see that @smeenai brought up the inconsistency between `_DLL` and 
`_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS` already back when this was reviewed. 
I'm running into problems with this inconsistency in various cases.

`_DLL` is tied to the choice of CRT (compiling with `-MD` defines it, compiling 
with `-MT` doesn't define it), while we might have built and be using either a 
statically linked or dynamically linked libc++. And as @smeenai argued, if 
`_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS` is not defined, then all declarations 
are decorated with dllimport, and there's no doubt about it, we have to use the 
DLL form of the library.

This is noticable today when running the libc++ testsuite (which is hooked up 
in CI these days, so by posting a patch you can get it verified too!); 
currently the CI configuration builds with both shared and static enabled 
(which links and uses the shared library only). If disabling building the 
static library, however, testing fails, as the autolinking tries to pull in the 
static library.

(We could disable autolinking within the test suite altogether, as it 
explicitly links the right library anyway, but I'd rather fix the autolinking 
feature instead of having to disable it because it misbehaves.)

I guess it's possible to set up cases with 
`_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS` disabled but still linking against the 
DLL, that might work at least for some subsets of the library functionality. 
But if manually enabling `_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS` in a DLL 
configuration, then one can also define `_LIBCPP_NO_AUTO_LINK` at the same time 
to opt out of the autolinking.

Therefore, I would like to post a patch that fixes the autolinking mechanism to 
rely on `_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS` which is closely tied to 
whether dllimport is used, and to whether a shared or static library was built. 
(And if both were built, it defaults to the shared one.)

WDYT @smeenai @compnerd?


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D40660/new/

https://reviews.llvm.org/D40660

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


[clang] 64c24f4 - Remove warning "suggest braces" for aggregate initialization of an empty class with an aggregate base class.

2021-04-13 Thread Aaron Ballman via cfe-commits

Author: Hana Dusíková
Date: 2021-04-13T15:45:09-04:00
New Revision: 64c24f493e5f4637ee193f10f469cdd2695b4ba6

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

LOG: Remove warning "suggest braces" for aggregate initialization of an empty 
class with an aggregate base class.

I recently ran into issues with aggregates and inheritance, I'm using
it for creating a type-safe library where most of the types are build
over "tagged" std::array. After bit of cleaning and enabling -Wall
-Wextra -pedantic I noticed clang only in my pipeline gives me warning.
After a bit of focusing on it I found it's not helpful, and contemplate
disabling the warning all together. After a discussion with other
library authors I found it's bothering more people and decided to fix
it.

Removes this warning:

template struct StdArray {
T contents[N];
  };

template struct AggregateAndEmpty : StdArray { };

AggregateAndEmpty p = {1, 2, 3}; // <-- warning here about omitted 
braces

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/aggregate-initialization.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ec7e4722ea4e..c8e8c8696b6a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -1007,21 +1007,33 @@ static bool isIdiomaticBraceElisionEntity(const 
InitializedEntity &Entity) {
   //
   // (where std::array is an aggregate struct containing a single array field.
 
-  // FIXME: Should aggregate initialization of a struct with a single
-  // base class and no members also suppress the warning?
-  if (Entity.getKind() != InitializedEntity::EK_Member || !Entity.getParent())
+  if (!Entity.getParent())
 return false;
 
-  auto *ParentRD =
-  Entity.getParent()->getType()->castAs()->getDecl();
-  if (CXXRecordDecl *CXXRD = dyn_cast(ParentRD))
-if (CXXRD->getNumBases())
-  return false;
+  // Allows elide brace initialization for aggregates with empty base.
+  if (Entity.getKind() == InitializedEntity::EK_Base) {
+auto *ParentRD =
+Entity.getParent()->getType()->castAs()->getDecl();
+CXXRecordDecl *CXXRD = cast(ParentRD);
+return CXXRD->getNumBases() == 1 && CXXRD->field_empty();
+  }
+
+  // Allow brace elision if the only subobject is a field.
+  if (Entity.getKind() == InitializedEntity::EK_Member) {
+auto *ParentRD =
+Entity.getParent()->getType()->castAs()->getDecl();
+if (CXXRecordDecl *CXXRD = dyn_cast(ParentRD)) {
+  if (CXXRD->getNumBases()) {
+return false;
+  }
+}
+auto FieldIt = ParentRD->field_begin();
+assert(FieldIt != ParentRD->field_end() &&
+   "no fields but have initializer for member?");
+return ++FieldIt == ParentRD->field_end();
+  }
 
-  auto FieldIt = ParentRD->field_begin();
-  assert(FieldIt != ParentRD->field_end() &&
- "no fields but have initializer for member?");
-  return ++FieldIt == ParentRD->field_end();
+  return false;
 }
 
 /// Check whether the range of the initializer \p ParentIList from element

diff  --git a/clang/test/SemaCXX/aggregate-initialization.cpp 
b/clang/test/SemaCXX/aggregate-initialization.cpp
index c71a7449d31d..3c12aca12d21 100644
--- a/clang/test/SemaCXX/aggregate-initialization.cpp
+++ b/clang/test/SemaCXX/aggregate-initialization.cpp
@@ -172,11 +172,20 @@ namespace IdiomaticStdArrayInitDoesNotWarn {
   };
   ArrayAndBaseClass z = {1, 2, 3}; // expected-warning {{suggest 
braces}}
 
-  // It's not clear whether we should be warning in this case. If this
-  // pattern becomes idiomatic, it would be reasonable to suppress the
-  // warning here too.
+  // This pattern is used for tagged aggregates and must not warn
   template struct JustABaseClass : StdArray {};
-  JustABaseClass w = {1, 2, 3}; // expected-warning {{suggest braces}}
+  JustABaseClass w = {1, 2, 3};
+  // but this should be also ok
+  JustABaseClass v = {{1, 2, 3}};
+
+  template  struct OnionBaseClass : JustABaseClass {};
+  OnionBaseClass u = {1, 2, 3};
+  OnionBaseClass t = {{{1, 2, 3}}};
+
+  struct EmptyBase {};
+
+  template  struct AggregateAndEmpty : StdArray, 
EmptyBase {};
+  AggregateAndEmpty p = {1, 2, 3}; // expected-warning {{suggest 
braces}}
 #endif
 
 #pragma clang diagnostic pop



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


  1   2   >