[PATCH] D90329: [PowerPC] Fix va_arg in C++, Objective-C on 32-bit ELF targets

2021-01-22 Thread Brad Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG018984ae6833: [PowerPC] Fix va_arg in C++, Objective-C on 
32-bit ELF targets (authored by kernigh, committed by brad).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90329

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGenCXX/ppc32-varargs-method.cpp
  clang/test/CodeGenObjC/ppc32-varargs-id.m


Index: clang/test/CodeGenObjC/ppc32-varargs-id.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/ppc32-varargs-id.m
@@ -0,0 +1,33 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc-unknown-openbsd -fblocks -emit-llvm -o - %s 
| FileCheck %s
+
+#include 
+
+id testObject(va_list ap) {
+  return va_arg(ap, id);
+}
+// CHECK: @testObject
+// CHECK: using_regs:
+// CHECK-NEXT: getelementptr inbounds %struct.__va_list_tag, 
%struct.__va_list_tag* %{{[0-9]+}}, i32 0, i32 4
+// CHECK-NEXT: load i8*, i8** %{{[0-9]+}}, align 4
+// CHECK-NEXT: mul i8 %numUsedRegs, 4
+// CHECK-NEXT: getelementptr inbounds i8, i8* %{{[0-9]+}}, i8 %{{[0-9]+}}
+// CHECK-NEXT: bitcast i8* %{{[0-9]+}} to i8**
+// CHECK-NEXT: add i8 %numUsedRegs, 1
+// CHECK-NEXT: store i8 %{{[0-9]+}}, i8* %gpr, align 4
+// CHECK-NEXT: br label %cont
+
+typedef void (^block)(void);
+block testBlock(va_list ap) {
+  return va_arg(ap, block);
+}
+// CHECK: @testBlock
+// CHECK: using_regs:
+// CHECK-NEXT: getelementptr inbounds %struct.__va_list_tag, 
%struct.__va_list_tag* %{{[0-9]+}}, i32 0, i32 4
+// CHECK-NEXT: load i8*, i8** %{{[0-9]+}}, align 4
+// CHECK-NEXT: mul i8 %numUsedRegs, 4
+// CHECK-NEXT: getelementptr inbounds i8, i8* %{{[0-9]+}}, i8 %{{[0-9]+}}
+// CHECK-NEXT: bitcast i8* %{{[0-9]+}} to void ()**
+// CHECK-NEXT: add i8 %numUsedRegs, 1
+// CHECK-NEXT: store i8 %{{[0-9]+}}, i8* %gpr, align 4
+// CHECK-NEXT: br label %cont
Index: clang/test/CodeGenCXX/ppc32-varargs-method.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/ppc32-varargs-method.cpp
@@ -0,0 +1,20 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc-unknown-openbsd -emit-llvm -o - %s | 
FileCheck %s
+
+#include 
+
+class something;
+typedef void (something::*method)();
+
+method test(va_list ap) {
+  return va_arg(ap, method);
+}
+// CHECK: using_regs:
+// CHECK-NEXT: getelementptr inbounds %struct.__va_list_tag, 
%struct.__va_list_tag* %{{[0-9]+}}, i32 0, i32 4
+// CHECK-NEXT: load i8*, i8** %{{[0-9]+}}, align 4
+// CHECK-NEXT: mul i8 %numUsedRegs, 4
+// CHECK-NEXT: getelementptr inbounds i8, i8* %{{[0-9]+}}, i8 %{{[0-9]+}}
+// CHECK-NEXT: bitcast i8* %{{[0-9]+}} to { i32, i32 }**
+// CHECK-NEXT: add i8 %numUsedRegs, 1
+// CHECK-NEXT: store i8 %{{[0-9]+}}, i8* %gpr, align 4
+// CHECK-NEXT: br label %cont
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -4709,13 +4709,12 @@
   // };
 
   bool isI64 = Ty->isIntegerType() && getContext().getTypeSize(Ty) == 64;
-  bool isInt =
-  Ty->isIntegerType() || Ty->isPointerType() || Ty->isAggregateType();
+  bool isInt = !Ty->isFloatingType();
   bool isF64 = Ty->isFloatingType() && getContext().getTypeSize(Ty) == 64;
 
   // All aggregates are passed indirectly?  That doesn't seem consistent
   // with the argument-lowering code.
-  bool isIndirect = Ty->isAggregateType();
+  bool isIndirect = isAggregateTypeForABI(Ty);
 
   CGBuilderTy  = CGF.Builder;
 


Index: clang/test/CodeGenObjC/ppc32-varargs-id.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/ppc32-varargs-id.m
@@ -0,0 +1,33 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc-unknown-openbsd -fblocks -emit-llvm -o - %s | FileCheck %s
+
+#include 
+
+id testObject(va_list ap) {
+  return va_arg(ap, id);
+}
+// CHECK: @testObject
+// CHECK: using_regs:
+// CHECK-NEXT: getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %{{[0-9]+}}, i32 0, i32 4
+// CHECK-NEXT: load i8*, i8** %{{[0-9]+}}, align 4
+// CHECK-NEXT: mul i8 %numUsedRegs, 4
+// CHECK-NEXT: getelementptr inbounds i8, i8* %{{[0-9]+}}, i8 %{{[0-9]+}}
+// CHECK-NEXT: bitcast i8* %{{[0-9]+}} to i8**
+// CHECK-NEXT: add i8 %numUsedRegs, 1
+// CHECK-NEXT: store i8 %{{[0-9]+}}, i8* %gpr, align 4
+// CHECK-NEXT: br label %cont
+
+typedef void (^block)(void);
+block testBlock(va_list ap) {
+  return va_arg(ap, block);
+}
+// CHECK: @testBlock
+// CHECK: using_regs:
+// CHECK-NEXT: getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %{{[0-9]+}}, i32 0, i32 4
+// CHECK-NEXT: load i8*, i8** %{{[0-9]+}}, align 4
+// CHECK-NEXT: mul i8 %numUsedRegs, 4
+// CHECK-NEXT: getelementptr inbounds i8, i8* %{{[0-9]+}}, i8 %{{[0-9]+}}
+// 

[clang] 018984a - [PowerPC] Fix va_arg in C++, Objective-C on 32-bit ELF targets

2021-01-22 Thread Brad Smith via cfe-commits

Author: George Koehler
Date: 2021-01-23T00:13:36-05:00
New Revision: 018984ae6833fae107aa9c502ab5536efceca88e

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

LOG: [PowerPC] Fix va_arg in C++, Objective-C on 32-bit ELF targets

In the PPC32 SVR4 ABI, a va_list has copies of registers from the function call.
va_arg looked in the wrong registers for (the pointer representation of) an
object in Objective-C, and for some types in C++. Fix va_arg to look in the
general-purpose registers, not the floating-point registers. Also fix va_arg
for some C++ types, like a member function pointer, that are aggregates for
the ABI.

Anthony Richardby found the problem in Objective-C. Eli Friedman suggested
part of this fix.

Fixes https://bugs.llvm.org/show_bug.cgi?id=47921

Reviewed By: efriedma, nemanjai

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

Added: 
clang/test/CodeGenCXX/ppc32-varargs-method.cpp
clang/test/CodeGenObjC/ppc32-varargs-id.m

Modified: 
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 9a11a0720f3c..bcd24292ff41 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -4709,13 +4709,12 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction 
, Address VAList,
   // };
 
   bool isI64 = Ty->isIntegerType() && getContext().getTypeSize(Ty) == 64;
-  bool isInt =
-  Ty->isIntegerType() || Ty->isPointerType() || Ty->isAggregateType();
+  bool isInt = !Ty->isFloatingType();
   bool isF64 = Ty->isFloatingType() && getContext().getTypeSize(Ty) == 64;
 
   // All aggregates are passed indirectly?  That doesn't seem consistent
   // with the argument-lowering code.
-  bool isIndirect = Ty->isAggregateType();
+  bool isIndirect = isAggregateTypeForABI(Ty);
 
   CGBuilderTy  = CGF.Builder;
 

diff  --git a/clang/test/CodeGenCXX/ppc32-varargs-method.cpp 
b/clang/test/CodeGenCXX/ppc32-varargs-method.cpp
new file mode 100644
index ..2295f0125a88
--- /dev/null
+++ b/clang/test/CodeGenCXX/ppc32-varargs-method.cpp
@@ -0,0 +1,20 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc-unknown-openbsd -emit-llvm -o - %s | 
FileCheck %s
+
+#include 
+
+class something;
+typedef void (something::*method)();
+
+method test(va_list ap) {
+  return va_arg(ap, method);
+}
+// CHECK: using_regs:
+// CHECK-NEXT: getelementptr inbounds %struct.__va_list_tag, 
%struct.__va_list_tag* %{{[0-9]+}}, i32 0, i32 4
+// CHECK-NEXT: load i8*, i8** %{{[0-9]+}}, align 4
+// CHECK-NEXT: mul i8 %numUsedRegs, 4
+// CHECK-NEXT: getelementptr inbounds i8, i8* %{{[0-9]+}}, i8 %{{[0-9]+}}
+// CHECK-NEXT: bitcast i8* %{{[0-9]+}} to { i32, i32 }**
+// CHECK-NEXT: add i8 %numUsedRegs, 1
+// CHECK-NEXT: store i8 %{{[0-9]+}}, i8* %gpr, align 4
+// CHECK-NEXT: br label %cont

diff  --git a/clang/test/CodeGenObjC/ppc32-varargs-id.m 
b/clang/test/CodeGenObjC/ppc32-varargs-id.m
new file mode 100644
index ..3730efb02d28
--- /dev/null
+++ b/clang/test/CodeGenObjC/ppc32-varargs-id.m
@@ -0,0 +1,33 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc-unknown-openbsd -fblocks -emit-llvm -o - %s 
| FileCheck %s
+
+#include 
+
+id testObject(va_list ap) {
+  return va_arg(ap, id);
+}
+// CHECK: @testObject
+// CHECK: using_regs:
+// CHECK-NEXT: getelementptr inbounds %struct.__va_list_tag, 
%struct.__va_list_tag* %{{[0-9]+}}, i32 0, i32 4
+// CHECK-NEXT: load i8*, i8** %{{[0-9]+}}, align 4
+// CHECK-NEXT: mul i8 %numUsedRegs, 4
+// CHECK-NEXT: getelementptr inbounds i8, i8* %{{[0-9]+}}, i8 %{{[0-9]+}}
+// CHECK-NEXT: bitcast i8* %{{[0-9]+}} to i8**
+// CHECK-NEXT: add i8 %numUsedRegs, 1
+// CHECK-NEXT: store i8 %{{[0-9]+}}, i8* %gpr, align 4
+// CHECK-NEXT: br label %cont
+
+typedef void (^block)(void);
+block testBlock(va_list ap) {
+  return va_arg(ap, block);
+}
+// CHECK: @testBlock
+// CHECK: using_regs:
+// CHECK-NEXT: getelementptr inbounds %struct.__va_list_tag, 
%struct.__va_list_tag* %{{[0-9]+}}, i32 0, i32 4
+// CHECK-NEXT: load i8*, i8** %{{[0-9]+}}, align 4
+// CHECK-NEXT: mul i8 %numUsedRegs, 4
+// CHECK-NEXT: getelementptr inbounds i8, i8* %{{[0-9]+}}, i8 %{{[0-9]+}}
+// CHECK-NEXT: bitcast i8* %{{[0-9]+}} to void ()**
+// CHECK-NEXT: add i8 %numUsedRegs, 1
+// CHECK-NEXT: store i8 %{{[0-9]+}}, i8* %gpr, align 4
+// CHECK-NEXT: br label %cont



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


[PATCH] D90329: [PowerPC] Fix va_arg in C++, Objective-C on 32-bit ELF targets

2021-01-22 Thread George Koehler via Phabricator via cfe-commits
kernigh added a comment.

I forgot about this diff for a month.




Comment at: clang/lib/CodeGen/TargetInfo.cpp:4722
   bool isI64 = Ty->isIntegerType() && getContext().getTypeSize(Ty) == 64;
-  bool isInt =
-  Ty->isIntegerType() || Ty->isPointerType() || Ty->isAggregateType();
+  bool isInt = !Ty->isFloatingType();
   bool isF64 = Ty->isFloatingType() && getContext().getTypeSize(Ty) == 64;

nemanjai wrote:
> nit (feel free to ignore): seems like a better name might be something like 
> `isSingleGPR` since it would appear that this is for types that go into a 
> (single) general purpose register.
Hi. `isInt` is also true for a 64-bit integer, which goes into a pair of GPRs, 
because each register has 32 bits.



Comment at: clang/test/CodeGenCXX/ppc32-varargs-method.cpp:15
+// CHECK-NEXT: load i8*, i8** %{{[0-9]+}}, align 4
+// CHECK-NEXT: mul i8 %numUsedRegs, 4
+// CHECK-NEXT: getelementptr inbounds i8, i8* %{{[0-9]+}}, i8 %{{[0-9]+}}

efriedma wrote:
> Not sure referring to numUsedRegs like this will work in a non-Asserts build. 
>  Please verify.
I did a build with cmake -DLLVM_ENABLE_ASSERTIONS=OFF and verified that the 
ppc32*varargs* tests still pass. `%numUsedRegs` is still in the llvm output.

`%numUsedRegs` //does not// appear in the output of `clang -S -emit-llvm ...` 
(not cc1), but `%numUsedRegs` //does// appear in the output of `clang -cc1 
...`. The test runs cc1 and sees the `%numUsedRegs`. I am confused by how llvm 
sometimes erases the name of `%numUsedRegs` and sometimes keeps the name, but I 
observe that turning LLVM_ENABLE_ASSERTIONS on or off doesn't affect the test.


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

https://reviews.llvm.org/D90329

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


[PATCH] D95161: [Clang][OpenMP][NVPTX] Replace `libomptarget-nvptx-path` with `libomptarget-nvptx-bc-path`

2021-01-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 318719.
tianshilei1992 added a comment.

Made test more robust


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95161

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/test/Driver/Inputs/libomptarget/libomptarget-nvptx-test.bc
  clang/test/Driver/openmp-offload-gpu.c

Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -34,22 +34,6 @@
 
 /// ###
 
-/// Check that -lomptarget-nvptx is passed to nvlink.
-// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp \
-// RUN:  -fopenmp-targets=nvptx64-nvidia-cuda %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHK-NVLINK %s
-/// Check that the value of --libomptarget-nvptx-path is forwarded to nvlink.
-// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp \
-// RUN:  --libomptarget-nvptx-path=/path/to/libomptarget/ \
-// RUN:  -fopenmp-targets=nvptx64-nvidia-cuda %s 2>&1 \
-// RUN:   | FileCheck -check-prefixes=CHK-NVLINK,CHK-LIBOMPTARGET-NVPTX-PATH %s
-
-// CHK-NVLINK: nvlink
-// CHK-LIBOMPTARGET-NVPTX-PATH-SAME: "-L/path/to/libomptarget/"
-// CHK-NVLINK-SAME: "-lomptarget-nvptx"
-
-/// ###
-
 /// Check cubin file generation and usage by nvlink
 // RUN:   %clang -### -no-canonical-prefixes -target powerpc64le-unknown-linux-gnu -fopenmp=libomp \
 // RUN:  -fopenmp-targets=nvptx64-nvidia-cuda -save-temps %s 2>&1 \
@@ -173,13 +157,14 @@
 // RUN:   -Xopenmp-target -march=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
-/// The user can override default detection using --libomptarget-nvptx-path=.
-// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda --libomptarget-nvptx-path=%S/Inputs/libomptarget \
+/// The user can override default detection using --libomptarget-nvptx-bc-path=.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   --libomptarget-nvptx-bc-path=%S/Inputs/libomptarget/libomptarget-nvptx-test.bc \
 // RUN:   -Xopenmp-target -march=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
 
-// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-sm_20.bc
+// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-test.bc
 // CHK-BCLIB-NOT: {{error:|warning:}}
 
 /// ###
@@ -191,7 +176,18 @@
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-WARN %s
 
-// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the default clang lib directory or in LIBRARY_PATH. Expect degraded performance due to no inlining of runtime functions on target devices.
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.
+
+/// ###
+
+/// Check that the error is thrown when the libomptarget bitcode library does not exist.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   --libomptarget-nvptx-bc-path=not-exist.bc \
+// RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-BCLIB-ERROR %s
+
+// CHK-BCLIB-ERROR: Bitcode library 'not-exist.bc' does not exist.
 
 /// Check that debug info is emitted in dwarf-2
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O1 --no-cuda-noopt-device-debug 2>&1 \
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -600,11 +600,6 @@
   CmdArgs.push_back("-arch");
   CmdArgs.push_back(Args.MakeArgString(GPUArch));
 
-  // Assume that the directory specified with --libomptarget_nvptx_path
-  // contains the static library libomptarget-nvptx.a.
-  

[PATCH] D95161: [Clang][OpenMP][NVPTX] Replace `libomptarget-nvptx-path` with `libomptarget-nvptx-bc-path`

2021-01-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 318717.
tianshilei1992 added a comment.

Fixed the test issue caused by wrong path seperator on Windows and Linux


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95161

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/test/Driver/openmp-offload-gpu.c

Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -34,22 +34,6 @@
 
 /// ###
 
-/// Check that -lomptarget-nvptx is passed to nvlink.
-// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp \
-// RUN:  -fopenmp-targets=nvptx64-nvidia-cuda %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHK-NVLINK %s
-/// Check that the value of --libomptarget-nvptx-path is forwarded to nvlink.
-// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp \
-// RUN:  --libomptarget-nvptx-path=/path/to/libomptarget/ \
-// RUN:  -fopenmp-targets=nvptx64-nvidia-cuda %s 2>&1 \
-// RUN:   | FileCheck -check-prefixes=CHK-NVLINK,CHK-LIBOMPTARGET-NVPTX-PATH %s
-
-// CHK-NVLINK: nvlink
-// CHK-LIBOMPTARGET-NVPTX-PATH-SAME: "-L/path/to/libomptarget/"
-// CHK-NVLINK-SAME: "-lomptarget-nvptx"
-
-/// ###
-
 /// Check cubin file generation and usage by nvlink
 // RUN:   %clang -### -no-canonical-prefixes -target powerpc64le-unknown-linux-gnu -fopenmp=libomp \
 // RUN:  -fopenmp-targets=nvptx64-nvidia-cuda -save-temps %s 2>&1 \
@@ -173,8 +157,9 @@
 // RUN:   -Xopenmp-target -march=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
-/// The user can override default detection using --libomptarget-nvptx-path=.
-// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda --libomptarget-nvptx-path=%S/Inputs/libomptarget \
+/// The user can override default detection using --libomptarget-nvptx-bc-path=.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   --libomptarget-nvptx-bc-path=%S/Inputs/libomptarget/libomptarget-nvptx-sm_20.bc \
 // RUN:   -Xopenmp-target -march=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
@@ -191,7 +176,18 @@
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-WARN %s
 
-// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the default clang lib directory or in LIBRARY_PATH. Expect degraded performance due to no inlining of runtime functions on target devices.
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.
+
+/// ###
+
+/// Check that the error is thrown when the libomptarget bitcode library does not exist.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   --libomptarget-nvptx-bc-path=not-exist.bc \
+// RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-BCLIB-ERROR %s
+
+// CHK-BCLIB-ERROR: Bitcode library 'not-exist.bc' does not exist.
 
 /// Check that debug info is emitted in dwarf-2
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O1 --no-cuda-noopt-device-debug 2>&1 \
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -600,11 +600,6 @@
   CmdArgs.push_back("-arch");
   CmdArgs.push_back(Args.MakeArgString(GPUArch));
 
-  // Assume that the directory specified with --libomptarget_nvptx_path
-  // contains the static library libomptarget-nvptx.a.
-  if (const Arg *A = Args.getLastArg(options::OPT_libomptarget_nvptx_path_EQ))
-CmdArgs.push_back(Args.MakeArgString(Twine("-L") + A->getValue()));
-
   // Add paths specified in LIBRARY_PATH environment variable as -L options.
   addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
 
@@ -614,9 +609,6 @@
   llvm::sys::path::append(DefaultLibPath, "lib" CLANG_LIBDIR_SUFFIX);
 

[PATCH] D95249: [NFC] Disallow unused prefixes in clang/test/Analysis

2021-01-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I added those for consistency but i think your effort is worth it so let's 
ditch them.




Comment at: clang/test/Analysis/exploded-graph-rewriter/trimmers.dot:4
 // RUN: %exploded_graph_rewriter -s %s \
-// RUN: | FileCheck %s -check-prefixes=ONE,TWO,NOTHREE,FOUR
 // RUN: %exploded_graph_rewriter --to=0x2 %s \

Uh-oh, these look like typos as there are lines for `NOTTHREE` and `NOTFOUR`. 
Looks like your effort has paid off and found a real bug in tests! The tests 
seem to be passing just fine after i change to `NOTTHREE` and `NOTFOUR` 
respectively.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95249

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


[PATCH] D95279: Support: Remove duplicated code in {File,clang::ModulesDependency}Collector, NFC

2021-01-22 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for cleaning this up!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95279

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


[PATCH] D94745: [OpenMP][WIP] Build the deviceRTLs with OpenMP instead of target dependent language - NOT FOR REVIEW

2021-01-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added inline comments.



Comment at: openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt:24
+  return()
+endif()
+

JonChesterfield wrote:
> jdoerfert wrote:
> > we need the 32 bit versions as well, I guess?
> We could limit to 64 and see if a feature request for 32 comes in.
I agree.



Comment at: openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h:62
 #else
+#error "Wrong number!"
 #define MAX_SM 16

JonChesterfield wrote:
> Unintended?
Oh, yeah. I was testing whether `__CUDA_ARCH__` can be set by CUDA FE 
automatically but it turns out no.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94745

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


[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-01-22 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 318714.
hoy added a comment.

Fixing test failure on Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95271

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/pseudo-probe-lto.c


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,5 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s
+
+// CHECK: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,10 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasArg(options::OPT_fpseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1221,7 +1221,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultsToFalse,
   ChangedBy, ResetBy,
-  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample 
profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,5 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fpseudo-probe-for-profiling 2>&1 | FileCheck %s
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin -fpseudo-probe-for-profiling 2>&1 | FileCheck %s
+
+// CHECK: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,10 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasArg(options::OPT_fpseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1221,7 +1221,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultsToFalse,
   ChangedBy, ResetBy,
-  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95279: Support: Remove duplicated code in {File,clang::ModulesDependency}Collector, NFC

2021-01-22 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added reviewers: dblaikie, JDevlieghere.
Herald added subscribers: ributzka, hiraditya.
dexonsmith requested review of this revision.
Herald added projects: clang, LLVM.

Refactor the duplicated canonicalize-path logic in `FileCollector` and
`ModulesDependencyCollector` into a new utility called
`PathCanonicalizer` that's shared. This popped up when tracking down a
bug common to both in https://reviews.llvm.org/D95202.

As drive-bys, update a few names and comments to better reflect the
effect of the code, delay removal of `..`s to avoid an unnecessary extra
string copy, and leave behind a couple of FIXMEs for future
consideration.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95279

Files:
  clang/include/clang/Frontend/Utils.h
  clang/lib/Frontend/ModuleDependencyCollector.cpp
  llvm/include/llvm/Support/FileCollector.h
  llvm/lib/Support/FileCollector.cpp

Index: llvm/lib/Support/FileCollector.cpp
===
--- llvm/lib/Support/FileCollector.cpp
+++ llvm/lib/Support/FileCollector.cpp
@@ -53,62 +53,81 @@
 : Root(std::move(Root)), OverlayRoot(std::move(OverlayRoot)) {
 }
 
-bool FileCollector::getRealPath(StringRef SrcPath,
-SmallVectorImpl ) {
-  SmallString<256> RealPath;
+void FileCollector::PathCanonicalizer::updateWithRealPath(
+SmallVectorImpl ) {
+  StringRef SrcPath(Path.begin(), Path.size());
   StringRef FileName = sys::path::filename(SrcPath);
-  std::string Directory = sys::path::parent_path(SrcPath).str();
-  auto DirWithSymlink = SymlinkMap.find(Directory);
+  StringRef Directory = sys::path::parent_path(SrcPath);
 
   // Use real_path to fix any symbolic link component present in a path.
   // Computing the real path is expensive, cache the search through the parent
   // path Directory.
-  if (DirWithSymlink == SymlinkMap.end()) {
-auto EC = sys::fs::real_path(Directory, RealPath);
-if (EC)
-  return false;
-SymlinkMap[Directory] = std::string(RealPath.str());
+  SmallString<256> RealDirectory;
+  auto DirWithSymlink = CachedDirs.find(Directory);
+  if (DirWithSymlink == CachedDirs.end()) {
+// FIXME: Should this be a call to FileSystem::getRealpath(), in some
+// cases? What if there is nothing on disk?
+if (sys::fs::real_path(Directory, RealDirectory))
+  return;
+CachedDirs[Directory] = std::string(RealDirectory.str());
   } else {
-RealPath = DirWithSymlink->second;
+RealDirectory = DirWithSymlink->second;
   }
 
-  sys::path::append(RealPath, FileName);
-  Result.swap(RealPath);
-  return true;
+  // Use the symlink-resolved directory.
+  Path.swap(RealDirectory);
+
+  // Symlinks in the filename don't matter.
+  //
+  // FIXME: If we can cope with this, maybe we can cope without calling
+  // getRealPath() at all when there's no ".." component.
+  sys::path::append(Path, FileName);
 }
 
-void FileCollector::addFileImpl(StringRef SrcPath) {
+/// Make Path absolute.
+static void makeAbsolute(SmallVectorImpl ) {
   // We need an absolute src path to append to the root.
-  SmallString<256> AbsoluteSrc = SrcPath;
-  sys::fs::make_absolute(AbsoluteSrc);
+  sys::fs::make_absolute(Path);
 
   // Canonicalize src to a native path to avoid mixed separator styles.
-  sys::path::native(AbsoluteSrc);
+  sys::path::native(Path);
 
   // Remove redundant leading "./" pieces and consecutive separators.
-  StringRef TrimmedAbsoluteSrc =
-  sys::path::remove_leading_dotslash(AbsoluteSrc);
+  Path.erase(Path.begin(), sys::path::remove_leading_dotslash(
+   StringRef(Path.begin(), Path.size()))
+   .begin());
+}
 
-  // Canonicalize the source path by removing "..", "." components.
-  SmallString<256> VirtualPath = TrimmedAbsoluteSrc;
-  sys::path::remove_dots(VirtualPath, /*remove_dot_dot=*/true);
+FileCollector::PathCanonicalizer::PathStorage
+FileCollector::PathCanonicalizer::canonicalize(StringRef SrcPath) {
+  PathStorage Paths;
+  Paths.VirtualPath = SrcPath;
+  makeAbsolute(Paths.VirtualPath);
 
   // If a ".." component is present after a symlink component, remove_dots may
   // lead to the wrong real destination path. Let the source be canonicalized
   // like that but make sure we always use the real path for the destination.
-  SmallString<256> CopyFrom;
-  if (!getRealPath(TrimmedAbsoluteSrc, CopyFrom))
-CopyFrom = VirtualPath;
+  Paths.CopyFrom = Paths.VirtualPath;
+  updateWithRealPath(Paths.CopyFrom);
+
+  // Canonicalize the virtual path by removing "..", "." components.
+  sys::path::remove_dots(Paths.VirtualPath, /*remove_dot_dot=*/true);
+
+  return Paths;
+}
+
+void FileCollector::addFileImpl(StringRef SrcPath) {
+  PathCanonicalizer::PathStorage Paths = Canonicalizer.canonicalize(SrcPath);
 
   SmallString<256> DstPath = StringRef(Root);
-  sys::path::append(DstPath, sys::path::relative_path(CopyFrom));
+  

[PATCH] D95204: [lld-macho] switch default to new Darwin port

2021-01-22 Thread Greg McGary via Phabricator via cfe-commits
gkm planned changes to this revision.
gkm added a comment.

Pulling this back from review ... Not ready for prime time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95204

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


[PATCH] D95202: ADT: Use 'using' to inherit assign and append in SmallString

2021-01-22 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith marked 2 inline comments as done.
dexonsmith added a comment.

Thanks for the review! Pushed with suggestions applied in 
ba5628f2c2a9de049b80b3e276f7e05f481c49e7 
.




Comment at: llvm/lib/Support/FileCollector.cpp:89-93
+  {
+StringRef DroppedDotSlash = 
sys::path::remove_leading_dotslash(AbsoluteSrc);
+if (DroppedDotSlash.begin() != AbsoluteSrc.begin())
+  AbsoluteSrc.erase(AbsoluteSrc.begin(), DroppedDotSlash.begin());
+  }

dblaikie wrote:
> Similar comment here as with ModuleDependencyCollector (actually there's a 
> bunch of similar code here - perhaps it could be deduplicated in some way)
Yeah, I may follow up to fix that. It looks like a pure copy/paste...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95202

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


[PATCH] D94942: [clangd] Add tweak for implementing abstract class

2021-01-22 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 318678.
njames93 edited the summary of this revision.
njames93 added a comment.

Fix failing tests.
Updated message for tweak from a specified base class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94942

Files:
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ImplementAbstract.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/tweaks/ImplementAbstractTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/ImplementAbstractTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/tweaks/ImplementAbstractTests.cpp
@@ -0,0 +1,393 @@
+//===-- ImplementAbstractTests.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 "TestTU.h"
+#include "TweakTesting.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using ::testing::Not;
+
+namespace clang {
+namespace clangd {
+namespace {
+
+TWEAK_TEST(ImplementAbstract);
+
+TEST_F(ImplementAbstractTest, TestUnavailable) {
+
+  StringRef Cases[]{
+  // Not a pure virtual method.
+  R"cpp(
+  class A {
+virtual void Foo();
+  };
+  class ^B : public A {};
+)cpp",
+  // Pure virtual method overridden in class.
+  R"cpp(
+  class A {
+virtual void Foo() = 0;
+  };
+  class ^B : public A {
+void Foo() override;
+  };
+)cpp",
+  // Pure virtual method overridden in class with virtual keyword
+  R"cpp(
+  class A {
+virtual void Foo() = 0;
+  };
+  class ^B : public A {
+virtual void Foo() override;
+  };
+)cpp",
+  // Pure virtual method overridden in class without override keyword
+  R"cpp(
+  class A {
+virtual void Foo() = 0;
+  };
+  class ^B : public A {
+void Foo();
+  };
+)cpp",
+  // Pure virtual method overriden in base class.
+  R"cpp(
+  class A {
+virtual void Foo() = 0;
+  };
+  class B : public A {
+void Foo() override;
+  };
+  class ^C : public B {
+  };
+)cpp"};
+  for (const auto  : Cases) {
+EXPECT_THAT(Case, Not(isAvailable()));
+  }
+}
+
+TEST_F(ImplementAbstractTest, NormalAvailable) {
+  struct Case {
+llvm::StringRef TestHeader;
+llvm::StringRef TestSource;
+llvm::StringRef ExpectedSource;
+  };
+
+  Case Cases[]{
+  {
+  R"cpp(
+class A {
+  virtual void Foo() = 0;
+};)cpp",
+  R"cpp(
+class B : public A {^};
+  )cpp",
+  R"cpp(
+class B : public A {
+void Foo() override;
+};
+  )cpp",
+  },
+  {
+  R"cpp(
+class A {
+  public:
+  virtual void Foo() = 0;
+};)cpp",
+  R"cpp(
+class ^B : public A {};
+  )cpp",
+  R"cpp(
+class B : public A {
+public:
+
+void Foo() override;
+};
+  )cpp",
+  },
+  {
+  R"cpp(
+class A {
+  virtual void Foo(int Param) = 0;
+};)cpp",
+  R"cpp(
+class ^B : public A {};
+  )cpp",
+  R"cpp(
+class B : public A {
+void Foo(int Param) override;
+};
+  )cpp",
+  },
+  {
+  R"cpp(
+class A {
+  virtual void Foo(int Param) = 0;
+};)cpp",
+  R"cpp(
+struct ^B : public A {};
+  )cpp",
+  R"cpp(
+struct B : public A {
+private:
+
+void Foo(int Param) override;
+};
+  )cpp",
+  },
+  {
+  R"cpp(
+class A {
+  virtual void Foo(int Param) const volatile = 0;
+  public:
+  virtual void Bar(int Param) = 0;
+};)cpp",
+  R"cpp(
+class ^B : public A {
+  void Foo(int Param) const volatile override;
+};
+  )cpp",
+  R"cpp(
+class B : public A {
+  void Foo(int Param) const volatile override;
+
+public:
+
+void Bar(int Param) override;
+};
+  )cpp",
+  },
+  {
+  R"cpp(
+ class A {
+  virtual void Foo() = 0;
+  virtual void Bar() = 0;
+};
+class B : public A {
+  void Foo() override;
+};
+  )cpp",
+  R"cpp(
+class ^C : public B {
+

[PATCH] D95202: ADT: Use 'using' to inherit assign and append in SmallString

2021-01-22 Thread Duncan P. N. Exon Smith 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 rGba5628f2c2a9: ADT: Use using to inherit assign 
and append in SmallString (authored by dexonsmith).

Changed prior to commit:
  https://reviews.llvm.org/D95202?vs=318413=318677#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95202

Files:
  clang/lib/Frontend/ModuleDependencyCollector.cpp
  llvm/include/llvm/ADT/SmallString.h
  llvm/include/llvm/ADT/SmallVector.h
  llvm/lib/Support/FileCollector.cpp
  llvm/unittests/ADT/SmallVectorTest.cpp

Index: llvm/unittests/ADT/SmallVectorTest.cpp
===
--- llvm/unittests/ADT/SmallVectorTest.cpp
+++ llvm/unittests/ADT/SmallVectorTest.cpp
@@ -485,6 +485,15 @@
   this->assertValuesInOrder(this->theVector, 3u, 1, 7, 7);
 }
 
+TYPED_TEST(SmallVectorTest, AppendSmallVector) {
+  SCOPED_TRACE("AppendSmallVector");
+
+  SmallVector otherVector = {7, 7};
+  this->theVector.push_back(Constructable(1));
+  this->theVector.append(otherVector);
+  this->assertValuesInOrder(this->theVector, 3u, 1, 7, 7);
+}
+
 // Assign test
 TYPED_TEST(SmallVectorTest, AssignTest) {
   SCOPED_TRACE("AssignTest");
@@ -513,6 +522,15 @@
   this->assertValuesInOrder(this->theVector, 2u, 7, 7);
 }
 
+TYPED_TEST(SmallVectorTest, AssignSmallVector) {
+  SCOPED_TRACE("AssignSmallVector");
+
+  SmallVector otherVector = {7, 7};
+  this->theVector.push_back(Constructable(1));
+  this->theVector.assign(otherVector);
+  this->assertValuesInOrder(this->theVector, 2u, 7, 7);
+}
+
 // Move-assign test
 TYPED_TEST(SmallVectorTest, MoveAssignTest) {
   SCOPED_TRACE("MoveAssignTest");
Index: llvm/lib/Support/FileCollector.cpp
===
--- llvm/lib/Support/FileCollector.cpp
+++ llvm/lib/Support/FileCollector.cpp
@@ -86,17 +86,18 @@
   sys::path::native(AbsoluteSrc);
 
   // Remove redundant leading "./" pieces and consecutive separators.
-  AbsoluteSrc = sys::path::remove_leading_dotslash(AbsoluteSrc);
+  StringRef TrimmedAbsoluteSrc =
+  sys::path::remove_leading_dotslash(AbsoluteSrc);
 
   // Canonicalize the source path by removing "..", "." components.
-  SmallString<256> VirtualPath = AbsoluteSrc;
+  SmallString<256> VirtualPath = TrimmedAbsoluteSrc;
   sys::path::remove_dots(VirtualPath, /*remove_dot_dot=*/true);
 
   // If a ".." component is present after a symlink component, remove_dots may
   // lead to the wrong real destination path. Let the source be canonicalized
   // like that but make sure we always use the real path for the destination.
   SmallString<256> CopyFrom;
-  if (!getRealPath(AbsoluteSrc, CopyFrom))
+  if (!getRealPath(TrimmedAbsoluteSrc, CopyFrom))
 CopyFrom = VirtualPath;
 
   SmallString<256> DstPath = StringRef(Root);
Index: llvm/include/llvm/ADT/SmallVector.h
===
--- llvm/include/llvm/ADT/SmallVector.h
+++ llvm/include/llvm/ADT/SmallVector.h
@@ -664,6 +664,8 @@
 append(IL.begin(), IL.end());
   }
 
+  void append(const SmallVectorImpl ) { append(RHS.begin(), RHS.end()); }
+
   void assign(size_type NumElts, ValueParamT Elt) {
 // Note that Elt could be an internal reference.
 if (NumElts > this->capacity()) {
@@ -698,6 +700,8 @@
 append(IL);
   }
 
+  void assign(const SmallVectorImpl ) { assign(RHS.begin(), RHS.end()); }
+
   iterator erase(const_iterator CI) {
 // Just cast away constness because this is a non-const member function.
 iterator I = const_cast(CI);
Index: llvm/include/llvm/ADT/SmallString.h
===
--- llvm/include/llvm/ADT/SmallString.h
+++ llvm/include/llvm/ADT/SmallString.h
@@ -40,35 +40,15 @@
   template
   SmallString(ItTy S, ItTy E) : SmallVector(S, E) {}
 
-  // Note that in order to add new overloads for append & assign, we have to
-  // duplicate the inherited versions so as not to inadvertently hide them.
-
   /// @}
   /// @name String Assignment
   /// @{
 
-  /// Assign from a repeated element.
-  void assign(size_t NumElts, char Elt) {
-this->SmallVectorImpl::assign(NumElts, Elt);
-  }
-
-  /// Assign from an iterator pair.
-  template
-  void assign(in_iter S, in_iter E) {
-this->clear();
-SmallVectorImpl::append(S, E);
-  }
+  using SmallVector::assign;
 
   /// Assign from a StringRef.
   void assign(StringRef RHS) {
-this->clear();
-SmallVectorImpl::append(RHS.begin(), RHS.end());
-  }
-
-  /// Assign from a SmallVector.
-  void assign(const SmallVectorImpl ) {
-this->clear();
-SmallVectorImpl::append(RHS.begin(), RHS.end());
+SmallVectorImpl::assign(RHS.begin(), RHS.end());
   }
 
   /// Assign from a list of StringRefs.
@@ -81,26 +61,13 @@
   /// @name String Concatenation
   /// @{
 
-  /// Append from an 

[clang] ba5628f - ADT: Use 'using' to inherit assign and append in SmallString

2021-01-22 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2021-01-22T16:17:58-08:00
New Revision: ba5628f2c2a9de049b80b3e276f7e05f481c49e7

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

LOG: ADT: Use 'using' to inherit assign and append in SmallString

Rather than reimplement, use a `using` declaration to bring in
`SmallVectorImpl`'s assign and append implementations in
`SmallString`.

The `SmallString` versions were missing reference invalidation
assertions from `SmallVector`. This patch also fixes a bug in
`llvm::FileCollector::addFileImpl`, which was a copy/paste from
`clang::ModuleDependencyCollector::copyToRoot`, both caught by the
no-longer-skipped assertions.

As a drive-by, this also sinks the `const SmallVectorImpl&` versions of
these methods down into `SmallVectorImpl`, since I imagine they'd be
useful elsewhere.

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

Added: 


Modified: 
clang/lib/Frontend/ModuleDependencyCollector.cpp
llvm/include/llvm/ADT/SmallString.h
llvm/include/llvm/ADT/SmallVector.h
llvm/lib/Support/FileCollector.cpp
llvm/unittests/ADT/SmallVectorTest.cpp

Removed: 




diff  --git a/clang/lib/Frontend/ModuleDependencyCollector.cpp 
b/clang/lib/Frontend/ModuleDependencyCollector.cpp
index b54eb97d6c47..2b981224c7e0 100644
--- a/clang/lib/Frontend/ModuleDependencyCollector.cpp
+++ b/clang/lib/Frontend/ModuleDependencyCollector.cpp
@@ -190,17 +190,17 @@ std::error_code 
ModuleDependencyCollector::copyToRoot(StringRef Src,
   // Canonicalize src to a native path to avoid mixed separator styles.
   path::native(AbsoluteSrc);
   // Remove redundant leading "./" pieces and consecutive separators.
-  AbsoluteSrc = path::remove_leading_dotslash(AbsoluteSrc);
+  StringRef TrimmedAbsoluteSrc = path::remove_leading_dotslash(AbsoluteSrc);
 
   // Canonicalize the source path by removing "..", "." components.
-  SmallString<256> VirtualPath = AbsoluteSrc;
+  SmallString<256> VirtualPath = TrimmedAbsoluteSrc;
   path::remove_dots(VirtualPath, /*remove_dot_dot=*/true);
 
   // If a ".." component is present after a symlink component, remove_dots may
   // lead to the wrong real destination path. Let the source be canonicalized
   // like that but make sure we always use the real path for the destination.
   SmallString<256> CopyFrom;
-  if (!getRealPath(AbsoluteSrc, CopyFrom))
+  if (!getRealPath(TrimmedAbsoluteSrc, CopyFrom))
 CopyFrom = VirtualPath;
   SmallString<256> CacheDst = getDest();
 

diff  --git a/llvm/include/llvm/ADT/SmallString.h 
b/llvm/include/llvm/ADT/SmallString.h
index c0e8fcd29461..5a56321ae492 100644
--- a/llvm/include/llvm/ADT/SmallString.h
+++ b/llvm/include/llvm/ADT/SmallString.h
@@ -40,35 +40,15 @@ class SmallString : public SmallVector {
   template
   SmallString(ItTy S, ItTy E) : SmallVector(S, E) {}
 
-  // Note that in order to add new overloads for append & assign, we have to
-  // duplicate the inherited versions so as not to inadvertently hide them.
-
   /// @}
   /// @name String Assignment
   /// @{
 
-  /// Assign from a repeated element.
-  void assign(size_t NumElts, char Elt) {
-this->SmallVectorImpl::assign(NumElts, Elt);
-  }
-
-  /// Assign from an iterator pair.
-  template
-  void assign(in_iter S, in_iter E) {
-this->clear();
-SmallVectorImpl::append(S, E);
-  }
+  using SmallVector::assign;
 
   /// Assign from a StringRef.
   void assign(StringRef RHS) {
-this->clear();
-SmallVectorImpl::append(RHS.begin(), RHS.end());
-  }
-
-  /// Assign from a SmallVector.
-  void assign(const SmallVectorImpl ) {
-this->clear();
-SmallVectorImpl::append(RHS.begin(), RHS.end());
+SmallVectorImpl::assign(RHS.begin(), RHS.end());
   }
 
   /// Assign from a list of StringRefs.
@@ -81,26 +61,13 @@ class SmallString : public SmallVector {
   /// @name String Concatenation
   /// @{
 
-  /// Append from an iterator pair.
-  template
-  void append(in_iter S, in_iter E) {
-SmallVectorImpl::append(S, E);
-  }
-
-  void append(size_t NumInputs, char Elt) {
-SmallVectorImpl::append(NumInputs, Elt);
-  }
+  using SmallVector::append;
 
   /// Append from a StringRef.
   void append(StringRef RHS) {
 SmallVectorImpl::append(RHS.begin(), RHS.end());
   }
 
-  /// Append from a SmallVector.
-  void append(const SmallVectorImpl ) {
-SmallVectorImpl::append(RHS.begin(), RHS.end());
-  }
-
   /// Append from a list of StringRefs.
   void append(std::initializer_list Refs) {
 size_t SizeNeeded = this->size();

diff  --git a/llvm/include/llvm/ADT/SmallVector.h 
b/llvm/include/llvm/ADT/SmallVector.h
index dd72937c19e2..e960b272db04 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -664,6 +664,8 @@ class SmallVectorImpl : public 

[PATCH] D95168: [clang-format] Add InsertBraces option

2021-01-22 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:17921
+  "  another_function(arg, arg, arg, arg, arg, arg);";
+  EXPECT_EQ(IfElseSourceLong, format(IfElseSourceLong, Style));
+

can you use verifyFormat() instead of EXPECT_EQ?



Comment at: clang/unittests/Format/FormatTest.cpp:17996
+format(ForSourceLong, Style));
+}
+

are you testing do/while? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95168

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


[PATCH] D95168: [clang-format] Add InsertBraces option

2021-01-22 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a subscriber: djasper.
MyDeveloperDay added a comment.

I think this is one of those reviews that ultimately I think would be useful if 
we could ensure it works 100% correctly, but I think it goes against the 
original ethos of clang-format and I think if @djasper or @klimek the original 
authors were here they'd probably push back.

This reminds me of my own work for a East/West fixer, it proved to be a bit too 
controversial for some, despite being off by default. but I also agree 
clang-format has been inserting and moving code around for some time, so its no 
longer just a whitespace manipulation tool.

I do like this, and I agree clang-tidy is often too heavy weight ( For my 
source tree which is millions of line of code running clang-tidy over the whole 
thing is just not possible). I personally run "clang-format -n" over my entire 
tree every night to sanity check it, this feature would allow me to enforce the 
use of {} without which I've found over the years is often a source of bugs.

lets see if others have an opinion


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95168

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


[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-01-22 Thread Hongtao Yu via Phabricator via cfe-commits
hoy created this revision.
Herald added subscribers: wenlei, dang, steven_wu, hiraditya.
Herald added a reviewer: jansvoboda11.
hoy requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As titled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95271

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/pseudo-probe-lto.c


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,5 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -flto -fpseudo-probe-for-profiling 2>&1 | FileCheck %s
+// RUN: %clang -### %t.o -flto=thin -fpseudo-probe-for-profiling 2>&1 | 
FileCheck %s
+
+// CHECK: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,10 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasArg(options::OPT_fpseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1221,7 +1221,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultsToFalse,
   ChangedBy, ResetBy,
-  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample 
profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,5 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -flto -fpseudo-probe-for-profiling 2>&1 | FileCheck %s
+// RUN: %clang -### %t.o -flto=thin -fpseudo-probe-for-profiling 2>&1 | FileCheck %s
+
+// CHECK: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,10 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasArg(options::OPT_fpseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1221,7 +1221,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultsToFalse,
   ChangedBy, ResetBy,
-  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e92be7c - PR47682: Merge the DeclContext of a merged FunctionDecl before we inherit

2021-01-22 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2021-01-22T15:46:41-08:00
New Revision: e92be7cd9f03ab3eb8c4a21e686743c2575a169a

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

LOG: PR47682: Merge the DeclContext of a merged FunctionDecl before we inherit
default arguments.

When a function is declared with a qualified name, its eventual semantic
DeclContext may differ from the scope specified by the qualifier if it
redeclares a function in an inline namespace. In this case, we need to
update the DeclContext to be that of the previous declaration, and we
need to do so before we decide whether to inherit default arguments from
that previous declaration, because we only inherit default arguments
from declarations in the same scope.

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/default1.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 832fd8384ba8..3ee0c43097d7 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3238,6 +3238,10 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, 
NamedDecl *,
 }
   }
 
+  // If the old declaration was found in an inline namespace and the new
+  // declaration was qualified, update the DeclContext to match.
+  adjustDeclContextForDeclaratorDecl(New, Old);
+
   // If the old declaration is invalid, just give up here.
   if (Old->isInvalidDecl())
 return true;
@@ -4052,6 +4056,10 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult 
) {
 return New->setInvalidDecl();
   }
 
+  // If the old declaration was found in an inline namespace and the new
+  // declaration was qualified, update the DeclContext to match.
+  adjustDeclContextForDeclaratorDecl(New, Old);
+
   // Ensure the template parameters are compatible.
   if (NewTemplate &&
   !TemplateParameterListsAreEqual(NewTemplate->getTemplateParameters(),
@@ -4236,7 +4244,6 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult 
) {
   New->setPreviousDecl(Old);
   if (NewTemplate)
 NewTemplate->setPreviousDecl(OldTemplate);
-  adjustDeclContextForDeclaratorDecl(New, Old);
 
   // Inherit access appropriately.
   New->setAccess(Old->getAccess());
@@ -10788,7 +10795,6 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   NewTemplateDecl->mergePrevDecl(OldTemplateDecl);
 
   NewFD->setPreviousDeclaration(OldFD);
-  adjustDeclContextForDeclaratorDecl(NewFD, OldFD);
   if (NewFD->isCXXClassMember()) {
 NewFD->setAccess(OldTemplateDecl->getAccess());
 NewTemplateDecl->setAccess(OldTemplateDecl->getAccess());
@@ -10815,7 +10821,6 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 auto *OldFD = cast(OldDecl);
 // This needs to happen first so that 'inline' propagates.
 NewFD->setPreviousDeclaration(OldFD);
-adjustDeclContextForDeclaratorDecl(NewFD, OldFD);
 if (NewFD->isCXXClassMember())
   NewFD->setAccess(OldFD->getAccess());
   }

diff  --git a/clang/test/SemaCXX/default1.cpp b/clang/test/SemaCXX/default1.cpp
index 457cada13bda..8345b2433a3f 100644
--- a/clang/test/SemaCXX/default1.cpp
+++ b/clang/test/SemaCXX/default1.cpp
@@ -95,4 +95,12 @@ void g2(int c = f2()) {}
 template int f3() { return T::error; } // expected-error {{no 
members}}
 void g3(int c = f3()) {} // expected-note {{in instantiation of}}
 void use_g3() { g3(); }
+
+namespace PR47682 {
+  inline namespace A {
+void f(int = 0);
+  }
+}
+void PR47682::f(int) {}
+void PR47682_test() { PR47682::f(); }
 #endif



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


[PATCH] D95131: [CodeComplete] Add ranged for loops code pattern.

2021-01-22 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd18c3c7b18e9: [CodeComplete] Add ranged for loops code 
pattern. (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95131

Files:
  clang/lib/Sema/SemaCodeComplete.cpp


Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -2294,6 +2294,29 @@
   Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
   Builder.AddChunk(CodeCompletionString::CK_RightBrace);
   Results.AddResult(Result(Builder.TakeString()));
+
+  if (SemaRef.getLangOpts().CPlusPlus11 || SemaRef.getLangOpts().ObjC) {
+// for ( range_declaration (:|in) range_expression ) { statements }
+Builder.AddTypedTextChunk("for");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftParen);
+Builder.AddPlaceholderChunk("range-declaration");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+if (SemaRef.getLangOpts().ObjC)
+  Builder.AddTextChunk("in");
+else
+  Builder.AddChunk(CodeCompletionString::CK_Colon);
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("range-expression");
+Builder.AddChunk(CodeCompletionString::CK_RightParen);
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddPlaceholderChunk("statements");
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddChunk(CodeCompletionString::CK_RightBrace);
+Results.AddResult(Result(Builder.TakeString()));
+  }
 }
 
 if (S->getContinueParent()) {


Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -2294,6 +2294,29 @@
   Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
   Builder.AddChunk(CodeCompletionString::CK_RightBrace);
   Results.AddResult(Result(Builder.TakeString()));
+
+  if (SemaRef.getLangOpts().CPlusPlus11 || SemaRef.getLangOpts().ObjC) {
+// for ( range_declaration (:|in) range_expression ) { statements }
+Builder.AddTypedTextChunk("for");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftParen);
+Builder.AddPlaceholderChunk("range-declaration");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+if (SemaRef.getLangOpts().ObjC)
+  Builder.AddTextChunk("in");
+else
+  Builder.AddChunk(CodeCompletionString::CK_Colon);
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("range-expression");
+Builder.AddChunk(CodeCompletionString::CK_RightParen);
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddPlaceholderChunk("statements");
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddChunk(CodeCompletionString::CK_RightBrace);
+Results.AddResult(Result(Builder.TakeString()));
+  }
 }
 
 if (S->getContinueParent()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d18c3c7 - [CodeComplete] Add ranged for loops code pattern.

2021-01-22 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2021-01-22T23:40:35Z
New Revision: d18c3c7b18e9e78145d701c4687682848071ab98

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

LOG: [CodeComplete] Add ranged for loops code pattern.

Add code pattersn for c++ `range for` loops and objective c `for...in` loops.

Reviewed By: kadircet

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

Added: 


Modified: 
clang/lib/Sema/SemaCodeComplete.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 243f68d16462..d77c9e43a9bd 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -2294,6 +2294,29 @@ static void 
AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Scope *S,
   Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
   Builder.AddChunk(CodeCompletionString::CK_RightBrace);
   Results.AddResult(Result(Builder.TakeString()));
+
+  if (SemaRef.getLangOpts().CPlusPlus11 || SemaRef.getLangOpts().ObjC) {
+// for ( range_declaration (:|in) range_expression ) { statements }
+Builder.AddTypedTextChunk("for");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftParen);
+Builder.AddPlaceholderChunk("range-declaration");
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+if (SemaRef.getLangOpts().ObjC)
+  Builder.AddTextChunk("in");
+else
+  Builder.AddChunk(CodeCompletionString::CK_Colon);
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddPlaceholderChunk("range-expression");
+Builder.AddChunk(CodeCompletionString::CK_RightParen);
+Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
+Builder.AddChunk(CodeCompletionString::CK_LeftBrace);
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddPlaceholderChunk("statements");
+Builder.AddChunk(CodeCompletionString::CK_VerticalSpace);
+Builder.AddChunk(CodeCompletionString::CK_RightBrace);
+Results.AddResult(Result(Builder.TakeString()));
+  }
 }
 
 if (S->getContinueParent()) {



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


[PATCH] D95270: [clangd][NFC] Simplify handing on methods with no params

2021-01-22 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: sammccall, kadircet.
Herald added subscribers: usaxena95, arphaman.
njames93 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Add bind methods handling the case when a method has an empty params interface 
and when it has no parameters.

Remove ShutdownParams and ExitParams from Protocol, In LSP they aren't defined, 
instead the methods are defined to have void as the params. This signature now 
better reflects that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95270

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/Protocol.h

Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -265,8 +265,6 @@
   return true;
 }
 using InitializedParams = NoParams;
-using ShutdownParams = NoParams;
-using ExitParams = NoParams;
 
 /// Defines how the host (editor) should sync document changes to the language
 /// server.
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -91,8 +91,8 @@
   // Calls have signature void(const Params&, Callback).
   void onInitialize(const InitializeParams &, Callback);
   void onInitialized(const InitializedParams &);
-  void onShutdown(const ShutdownParams &, Callback);
-  void onSync(const NoParams &, Callback);
+  void onShutdown(Callback);
+  void onSync(Callback);
   void onDocumentDidOpen(const DidOpenTextDocumentParams &);
   void onDocumentDidChange(const DidChangeTextDocumentParams &);
   void onDocumentDidClose(const DidCloseTextDocumentParams &);
@@ -159,7 +159,7 @@
  Callback);
   /// This is a clangd extension. Provides a json tree representing memory usage
   /// hierarchy.
-  void onMemoryUsage(const NoParams &, Callback);
+  void onMemoryUsage(Callback);
 
   std::vector getFixes(StringRef File, const clangd::Diagnostic );
 
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -258,6 +258,25 @@
 };
   }
 
+  template 
+  void bind(const char *Method,
+void (ClangdLSPServer::*Handler)(const NoParams &,
+ Callback)) {
+Calls[Method] = [Handler, this](llvm::json::Value RawParams,
+ReplyOnce Reply) {
+  (Server.*Handler)(NoParams{}, std::move(Reply));
+};
+  }
+
+  template 
+  void bind(const char *Method,
+void (ClangdLSPServer::*Handler)(Callback)) {
+Calls[Method] = [Handler, this](llvm::json::Value RawParams,
+ReplyOnce Reply) {
+  (Server.*Handler)(std::move(Reply));
+};
+  }
+
   // Bind a reply callback to a request. The callback will be invoked when
   // clangd receives the reply from the LSP client.
   // Return a call id of the request.
@@ -301,6 +320,20 @@
 };
   }
 
+  void bind(const char *Method, void (ClangdLSPServer::*Handler)()) {
+Notifications[Method] = [Handler, this](llvm::json::Value RawParams) {
+  (Server.*Handler)();
+};
+  }
+
+  template <>
+  void bind(const char *Method,
+  void (ClangdLSPServer::*Handler)(const NoParams &)) {
+Notifications[Method] = [Handler, this](llvm::json::Value RawParams) {
+  (Server.*Handler)(NoParams{});
+};
+  }
+
 private:
   // Function object to reply to an LSP call.
   // Each instance must be called exactly once, otherwise:
@@ -647,8 +680,7 @@
 
 void ClangdLSPServer::onInitialized(const InitializedParams ) {}
 
-void ClangdLSPServer::onShutdown(const ShutdownParams ,
- Callback Reply) {
+void ClangdLSPServer::onShutdown(Callback Reply) {
   // Do essentially nothing, just say we're ready to exit.
   ShutdownRequestReceived = true;
   Reply(nullptr);
@@ -656,8 +688,7 @@
 
 // sync is a clangd extension: it blocks until all background work completes.
 // It blocks the calling thread, so no messages are processed until it returns!
-void ClangdLSPServer::onSync(const NoParams ,
- Callback Reply) {
+void ClangdLSPServer::onSync(Callback Reply) {
   if (Server->blockUntilIdleForTest(/*TimeoutSeconds=*/60))
 Reply(nullptr);
   else
@@ -1445,8 +1476,7 @@
   });
 }
 
-void ClangdLSPServer::onMemoryUsage(const NoParams &,
-Callback Reply) {
+void ClangdLSPServer::onMemoryUsage(Callback Reply) {
   llvm::BumpPtrAllocator DetailAlloc;
   MemoryTree MT();
   profile(MT);

[PATCH] D95187: [DebugInfo][CodeView] Use as the display name for lambdas.

2021-01-22 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 318657.
akhuang added a comment.

-add to comment
-Add externally visible lambda to test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95187

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
  clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Index: clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
===
--- clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
+++ clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
@@ -6,10 +6,15 @@
 namespace NS {
 struct C {
   void m() {}
+  // Test externally visible lambda.
+  void lambda2() { []() {}(); }
 };
 void f() {}
 }
 
+// Test non- externally visible lambda.
+auto lambda1 = []() { return 1; };
+
 NS::C c;
 
 void test() {
@@ -27,4 +32,16 @@
   // CHECK-NOT: identifier
   // CHECK: ![[MTYPE]] = !DISubroutineType(types: !{{.*}})
   c.m();
+
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA1:[0-9]+]]
+  // CHECK: ![[LAMBDA1]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:name: ""
+  // CHECK-SAME:flags: DIFlagFwdDecl
+  lambda1();
+
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA2:[0-9]+]]
+  // CHECK: ![[LAMBDA2]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:name: ""
+  // CHECK-SAME:flags: DIFlagFwdDecl
+  c.lambda2();
 }
Index: clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
===
--- clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
+++ clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
@@ -100,7 +100,7 @@
   // MSVC-SAME:  )
   // MSVC:   [[TYPE_OF_FOUR]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_class_type
-  // MSVC-NOT:   name:
+  // MSVC-SAME:  name: ""
   // MSVC-SAME:  identifier: ".?AV@?0??main@@9@"
   // MSVC-SAME:  )
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -317,8 +317,9 @@
   if (const IdentifierInfo *II = RD->getIdentifier())
 return II->getName();
 
-  // The CodeView printer in LLVM wants to see the names of unnamed types: it is
-  // used to reconstruct the fully qualified type names.
+  // The CodeView printer in LLVM wants to see the names of unnamed types
+  // because they need to have a unique identifier.
+  // These names are used to reconstruct the fully qualified type names.
   if (CGM.getCodeGenOpts().EmitCodeView) {
 if (const TypedefNameDecl *D = RD->getTypedefNameForAnonDecl()) {
   assert(RD->getDeclContext() == D->getDeclContext() &&
@@ -342,6 +343,12 @@
 // associate typedef mangled in if they have one.
 Name = TND->getName();
 
+  // Give lambdas a display name based on their name mangling.
+  if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+if (CXXRD->isLambda())
+  return internString(
+  CGM.getCXXABI().getMangleContext().getLambdaString(CXXRD));
+
   if (!Name.empty()) {
 SmallString<256> UnnamedType("isLambda() && "RD must be a lambda!");
+llvm::SmallString<10> Name("getLambdaContextDecl();
+unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber();
+unsigned LambdaId;
+const ParmVarDecl *Parm = dyn_cast_or_null(LambdaContextDecl);
+const FunctionDecl *Func =
+Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
+
+if (Func) {
+  unsigned DefaultArgNo =
+  Func->getNumParams() - Parm->getFunctionScopeIndex();
+  Name += llvm::utostr(DefaultArgNo);
+  Name += "_";
+}
+
+if (LambdaManglingNumber)
+  LambdaId = LambdaManglingNumber;
+else
+  LambdaId = getLambdaId(Lambda);
+
+Name += llvm::utostr(LambdaId);
+Name += ">";
+return StringRef(Name);
+  }
+
   unsigned getLambdaId(const CXXRecordDecl *RD) {
 assert(RD->isLambda() && "RD must be a lambda!");
 assert(!RD->isExternallyVisible() && "RD must not be visible!");
@@ -972,32 +1000,10 @@
 
   if (const CXXRecordDecl *Record = dyn_cast(TD)) {
 if (Record->isLambda()) {
-  llvm::SmallString<10> Name("getLambdaContextDecl();
   unsigned LambdaManglingNumber = Record->getLambdaManglingNumber();
-  unsigned LambdaId;
-  const ParmVarDecl *Parm =
-  dyn_cast_or_null(LambdaContextDecl);
-  const FunctionDecl *Func =
-  Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
-
-  if (Func) {
-

[PATCH] D94627: [PowerPC][PC Rel] Implement option to omit P10 instructions from stubs

2021-01-22 Thread Amy Kwan via Phabricator via cfe-commits
amyk added a comment.

A few general comments.




Comment at: lld/ELF/Config.h:74
+// For --power10-stub
+enum class P10Stub { Default, No };
+

We have a "yes", but does it need to be here, too?



Comment at: lld/ELF/Driver.cpp:763
 
+static P10Stub getP10StubOpt(opt::InputArgList ) {
+

Add documentation for the function.



Comment at: lld/ELF/Driver.cpp:776
+  }
+
+  return P10Stub::Default;

Do we need to handle `power10_stubs`?



Comment at: lld/ELF/Options.td:450
+def power10_stubs_eq:
+  J<"power10-stubs=">, HelpText<"Enables Power10 instr in all stubs without 
options, "
+ "options override previous flags."

nit: maybe use the full word `instructions` here and in the following lines.



Comment at: lld/ELF/Options.td:452
+ "options override previous flags."
+ "auto: Default"
+ "no:   No Power10 instr in stubs"

Describe the default behaviour?



Comment at: lld/ELF/Thunks.cpp:920
   const int64_t offset = computeOffset();
-  write32(buf + 0, 0xf8410018); // std  r2,24(r1)
+  write32(buf + 0, 0xf8410018);   // std  r2,24(r1)
   // The branch offset needs to fit in 26 bits.

Unrelated change?



Comment at: lld/ELF/Thunks.cpp:925
   } else if (isInt<34>(offset)) {
-const uint64_t paddi = PADDI_R12_NO_DISP |
-   (((offset >> 16) & 0x3) << 32) |
-   (offset & 0x);
-writePrefixedInstruction(buf + 4, paddi); // paddi r12, 0, func@pcrel, 1
-write32(buf + 12, MTCTR_R12); // mtctr r12
-write32(buf + 16, BCTR);  // bctr
+int inst2;
+if (config->Power10Stub == P10Stub::No) {

Can we maybe try to have a more descriptive name than `inst2`? (here and in the 
other places)



Comment at: lld/test/ELF/ppc64-toc-call-to-pcrel.s:23
+
+## The point of this test is to make sure that when a function with TOC access
 # a local function with st_other=1, a TOC save stub is inserted.

No need for the extra `#`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94627

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


[PATCH] D95202: ADT: Use 'using' to inherit assign and append in SmallString

2021-01-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks good - some optional feedback on the code fixes. Please run clang-format 
on the changes here (phab lint picked up some cases in the test code that could 
be cleaned up).




Comment at: clang/lib/Frontend/ModuleDependencyCollector.cpp:196
+if (DroppedDotSlash.begin() != AbsoluteSrc.begin())
+  AbsoluteSrc.erase(AbsoluteSrc.begin(), DroppedDotSlash.begin());
+  }

Maybe just call this inconditionally - it's probably cheap enough when the 
range is zero-length?

Perhaps it'd be more readable if "remove_leading_dotslash" had a version that 
could return the prefix length to remove.

But also, this is ultimately passed to 'getRealPath' which takes a StringRef, 
so there's technically no need to rewrite this SmallString - the StringRef from 
remove_leading_dotslash could be passed instead, something like:
```
StringRef TrimmedAbsoluteSrc = path::remove_leading_dotslash(AbsoluteSrc);
...
if (!getRealPath(AbsoluteSrc, CopyFrom))
...
```



Comment at: llvm/lib/Support/FileCollector.cpp:89-93
+  {
+StringRef DroppedDotSlash = 
sys::path::remove_leading_dotslash(AbsoluteSrc);
+if (DroppedDotSlash.begin() != AbsoluteSrc.begin())
+  AbsoluteSrc.erase(AbsoluteSrc.begin(), DroppedDotSlash.begin());
+  }

Similar comment here as with ModuleDependencyCollector (actually there's a 
bunch of similar code here - perhaps it could be deduplicated in some way)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95202

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


[PATCH] D94624: PATCH] [clang-query] Add a --use-color option to clang-query to allow forcing the behavior

2021-01-22 Thread Tom Ritter via Phabricator via cfe-commits
tomrittervg updated this revision to Diff 318632.
tomrittervg added a comment.

Try rebasing it...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94624

Files:
  clang-tools-extra/clang-query/Query.cpp
  clang-tools-extra/clang-query/tool/ClangQuery.cpp


Index: clang-tools-extra/clang-query/tool/ClangQuery.cpp
===
--- clang-tools-extra/clang-query/tool/ClangQuery.cpp
+++ clang-tools-extra/clang-query/tool/ClangQuery.cpp
@@ -49,6 +49,14 @@
 static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
 static cl::OptionCategory ClangQueryCategory("clang-query options");
 
+static cl::opt
+UseColor("use-color",
+ cl::desc(
+ R"(Use colors in detailed AST output. If not set, colors
+will be used if the terminal connected to
+standard output supports colors.)"),
+ cl::init(false), cl::cat(ClangQueryCategory));
+
 static cl::list Commands("c", cl::desc("Specify command to run"),
   cl::value_desc("command"),
   cl::cat(ClangQueryCategory));
@@ -109,6 +117,19 @@
 
   ClangTool Tool(OptionsParser->getCompilations(),
  OptionsParser->getSourcePathList());
+
+  if (UseColor.getNumOccurrences() > 0) {
+ArgumentsAdjuster colorAdjustor = [](const CommandLineArguments , 
StringRef /*unused*/) {
+  CommandLineArguments AdjustedArgs = Args;
+  if (UseColor)
+AdjustedArgs.push_back("-fdiagnostics-color");
+  else
+AdjustedArgs.push_back("-fno-diagnostics-color");
+  return AdjustedArgs;
+};
+Tool.appendArgumentsAdjuster(colorAdjustor);
+  }
+
   std::vector> ASTs;
   int ASTStatus = 0;
   switch (Tool.buildASTs(ASTs)) {
Index: clang-tools-extra/clang-query/Query.cpp
===
--- clang-tools-extra/clang-query/Query.cpp
+++ clang-tools-extra/clang-query/Query.cpp
@@ -156,8 +156,7 @@
 if (QS.DetailedASTOutput) {
   OS << "Binding for \"" << BI->first << "\":\n";
   const ASTContext  = AST->getASTContext();
-  const SourceManager  = Ctx.getSourceManager();
-  ASTDumper Dumper(OS, Ctx, SM.getDiagnostics().getShowColors());
+  ASTDumper Dumper(OS, Ctx, AST->getDiagnostics().getShowColors());
   Dumper.SetTraversalKind(QS.TK);
   Dumper.Visit(BI->second);
   OS << "\n";


Index: clang-tools-extra/clang-query/tool/ClangQuery.cpp
===
--- clang-tools-extra/clang-query/tool/ClangQuery.cpp
+++ clang-tools-extra/clang-query/tool/ClangQuery.cpp
@@ -49,6 +49,14 @@
 static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
 static cl::OptionCategory ClangQueryCategory("clang-query options");
 
+static cl::opt
+UseColor("use-color",
+ cl::desc(
+ R"(Use colors in detailed AST output. If not set, colors
+will be used if the terminal connected to
+standard output supports colors.)"),
+ cl::init(false), cl::cat(ClangQueryCategory));
+
 static cl::list Commands("c", cl::desc("Specify command to run"),
   cl::value_desc("command"),
   cl::cat(ClangQueryCategory));
@@ -109,6 +117,19 @@
 
   ClangTool Tool(OptionsParser->getCompilations(),
  OptionsParser->getSourcePathList());
+
+  if (UseColor.getNumOccurrences() > 0) {
+ArgumentsAdjuster colorAdjustor = [](const CommandLineArguments , StringRef /*unused*/) {
+  CommandLineArguments AdjustedArgs = Args;
+  if (UseColor)
+AdjustedArgs.push_back("-fdiagnostics-color");
+  else
+AdjustedArgs.push_back("-fno-diagnostics-color");
+  return AdjustedArgs;
+};
+Tool.appendArgumentsAdjuster(colorAdjustor);
+  }
+
   std::vector> ASTs;
   int ASTStatus = 0;
   switch (Tool.buildASTs(ASTs)) {
Index: clang-tools-extra/clang-query/Query.cpp
===
--- clang-tools-extra/clang-query/Query.cpp
+++ clang-tools-extra/clang-query/Query.cpp
@@ -156,8 +156,7 @@
 if (QS.DetailedASTOutput) {
   OS << "Binding for \"" << BI->first << "\":\n";
   const ASTContext  = AST->getASTContext();
-  const SourceManager  = Ctx.getSourceManager();
-  ASTDumper Dumper(OS, Ctx, SM.getDiagnostics().getShowColors());
+  ASTDumper Dumper(OS, Ctx, AST->getDiagnostics().getShowColors());
   Dumper.SetTraversalKind(QS.TK);
   Dumper.Visit(BI->second);
   OS << "\n";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95228: Add swift_async_context parameter attribute mapping to IR equivalent

2021-01-22 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 with a documentation question and a testing request.




Comment at: clang/include/clang/Basic/AttrDocs.td:4404
+
+A context parameter must have pointer or reference type.
+  }];

Should we specify whether pointer to members or ObjC object pointers are fine 
(given that those are both somewhat "odd" pointer types)? Function pointers?

(We may want to clarify this in the other docs in a follow-up if we think this 
is unclear.)



Comment at: clang/test/Sema/attr-swiftcall.c:34
+
+void async_context_okay_for_now(ASYNC_CONTEXT void *context);
+void async_context_bad_type(ASYNC_CONTEXT int context) SWIFTCALL; // 
expected-error {{'swift_async_context' parameter must have pointer type; type 
here is 'int'}}

Can you also add tests that show the attribute doesn't accept any arguments and 
will error when written on the wrong subject (like a function rather than a 
parameter)?


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

https://reviews.llvm.org/D95228

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


[PATCH] D70701: Fix more VFS tests on Windows

2021-01-22 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In D70701#2515934 , @amccarth wrote:

> BTW, I hope I didn't come across as overly negative in my previous
> response.

No, not at all!

> [...] On Windows, a process can have multiple
> current directories:  one for each drive.  And a process has one current
> drive.  So the current working directory is the current directory for the
> current drive.  A Windows path like "D:foo.txt" is a relative path.

Also news to me; thanks for the extra info. Looks like this isn't just a 
problem with `makeAbsolute`; even `sys::fs::make_absolute` is incorrect for 
Windows.

Seems to me like we could:

- Fix the one argument version of `sys::fs::make_absolute` on Windows by 
calling GetFullPathNameW (documented at 
https://en.cppreference.com/w/cpp/filesystem/absolute)
- "Fix" the two argument version of `sys::fs::make_absolute` by returning an 
error if the path and CWD both have drive names and they don't match. (Or leave 
it alone.)

For the VFS, I imagine we could:

- Keep an enum on `FileSystem` that indicates its path style (immutable, set on 
construction).
- Maybe change APIs to support the `windows` idea of a different CWD per drive 
(`getCurrentRootDirectoryFor(...)`), in order to have a correct implementation 
of the one-argument `makeAbsolute` (I assume there's way to get the full 
initial set to support `getPhysicalFileSystem()`?).
- Split `RedirectingFileSystem` implementation in two, between the 
"redirecting" and the "overlay" parts (overlaying being optional, depending on 
`fallthrough:`).
- Add a `WindowsFileSystemAsPOSIX` adaptor/proxy that takes an underlying 
filesystem in `windows` mode and presents it as-if `posix`, given a drive 
mapping in the constructor. This could be implemented using the same guts as 
the "redirecting" part of `RedirectingFileSystem`. (Note also 
https://reviews.llvm.org/D94844, which allows a directory to be 
remapped/redirected wholesale; this could be used for mapping drives to POSIX 
paths.)
- Add a `POSIXFileSystemAsWindows` adaptor/proxy that does the inverse.
- Disallow overlaying `FileSystem`s that have mismatched path styles. E.g., 
`OverlayFileSystem::pushOverlay` would error if a mismatched style is passed 
into it, requiring the caller to first wrap it in an adaptor.
- Maybe add `make{Native,Windows,POSIX}FileSystem` adaptors which return the 
given filesystem directly or add the appropriate adaptor (I'm not sure how 
drive mapping would be handled... maybe there are sane default mappings we 
could use...).
- Maybe make `getVFSFromYAML` add an adaptor to native by default.

I suppose I'm imagining windows mode would remain "hybrid", but I wonder if 
this would model the two worlds, even in the face of a VFS using different path 
styles than `native`. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70701

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


[PATCH] D95002: [RISCV] Update B extension version to 0.93.

2021-01-22 Thread Craig Topper 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 rG20f2e32d2c54: [RISCV] Update B extension version to 0.93. 
(authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95002

Files:
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Target/RISCV/RISCVInstrInfoB.td


Index: llvm/lib/Target/RISCV/RISCVInstrInfoB.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfoB.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfoB.td
@@ -7,7 +7,7 @@
 
//===--===//
 //
 // This file describes the RISC-V instructions from the standard 'B' Bitmanip
-// extension, version 0.92.
+// extension, version 0.93.
 // This version is still experimental as the 'B' extension hasn't been
 // ratified yet.
 //
@@ -734,8 +734,8 @@
   (SROI GPR:$rs1, uimmlog2xlen:$shamt)>;
 } // Predicates = [HasStdExtZbp]
 
-// There's no encoding for roli in the current version of the 'B' extension
-// (v0.92) as it can be implemented with rori by negating the immediate.
+// There's no encoding for roli in the the 'B' extension as it can be
+// implemented with rori by negating the immediate.
 let Predicates = [HasStdExtZbbOrZbp] in {
 def : Pat<(rotr GPR:$rs1, uimmlog2xlen:$shamt),
   (RORI GPR:$rs1, uimmlog2xlen:$shamt)>;
Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -49,9 +49,9 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s
 // CHECK-C-EXT: __riscv_compressed 1
 
-// RUN: %clang -target riscv32-unknown-linux-gnu 
-menable-experimental-extensions -march=rv32ib0p92 -x c -E -dM %s \
+// RUN: %clang -target riscv32-unknown-linux-gnu 
-menable-experimental-extensions -march=rv32ib0p93 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
-// RUN: %clang -target riscv64-unknown-linux-gnu 
-menable-experimental-extensions -march=rv64ib0p92 -x c -E -dM %s \
+// RUN: %clang -target riscv64-unknown-linux-gnu 
-menable-experimental-extensions -march=rv64ib0p93 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
 // CHECK-B-EXT: __riscv_bitmanip 1
 
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -343,7 +343,7 @@
 // RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32ib0p1'
 // RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.1 for experimental 
extension
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32ib0p92 
-menable-experimental-extensions -### %s \
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ib0p93 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-GOODVERS %s
 // RV32-EXPERIMENTAL-GOODVERS: "-target-feature" "+experimental-b"
 
@@ -352,20 +352,20 @@
 // RV32-EXPERIMENTAL-ZBB-NOFLAG: error: invalid arch name 'rv32izbb'
 // RV32-EXPERIMENTAL-ZBB-NOFLAG: requires '-menable-experimental-extensions'
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p92 
-menable-experimental-extensions -### %s \
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p93 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBB %s
 // RV32-EXPERIMENTAL-ZBB: "-target-feature" "+experimental-zbb"
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p92_zbp0p92 
-menable-experimental-extensions -### %s \
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p93_zbp0p93 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP 
%s
 // RV32-EXPERIMENTAL-ZBB-ZBP: "-target-feature" "+experimental-zbb"
 // RV32-EXPERIMENTAL-ZBB-ZBP: "-target-feature" "+experimental-zbp"
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p92zbp0p92 
-menable-experimental-extensions -### %s \
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p93zbp0p93 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE %s
-// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 
'rv32izbb0p92zbp0p92', multi-character extensions must be separated by 
underscores
+// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 
'rv32izbb0p93zbp0p93', multi-character extensions must be separated by 
underscores
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32izba0p92 

[PATCH] D94617: [RISCV] Add Zba feature and move add.uw and slli.uw to it.

2021-01-22 Thread Craig Topper via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4e6ad11bc6f2: [RISCV] Add Zba feature and move add.uw and 
slli.uw to it. (authored by craig.topper).

Changed prior to commit:
  https://reviews.llvm.org/D94617?vs=318217=318616#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94617

Files:
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoB.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/rv64Zba.ll
  llvm/test/CodeGen/RISCV/rv64Zbb.ll
  llvm/test/MC/RISCV/rv64zba-invalid.s
  llvm/test/MC/RISCV/rv64zba-valid.s
  llvm/test/MC/RISCV/rv64zbb-invalid.s
  llvm/test/MC/RISCV/rv64zbb-valid.s

Index: llvm/test/MC/RISCV/rv64zbb-valid.s
===
--- llvm/test/MC/RISCV/rv64zbb-valid.s
+++ llvm/test/MC/RISCV/rv64zbb-valid.s
@@ -12,12 +12,6 @@
 # RUN: | llvm-objdump --mattr=+experimental-zbb -d -r - \
 # RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
 
-# CHECK-ASM-AND-OBJ: slli.uw t0, t1, 0
-# CHECK-ASM: encoding: [0x9b,0x12,0x03,0x08]
-slli.uw t0, t1, 0
-# CHECK-ASM-AND-OBJ: add.uw t0, t1, t2
-# CHECK-ASM: encoding: [0xbb,0x02,0x73,0x08]
-add.uw t0, t1, t2
 # CHECK-ASM-AND-OBJ: slow t0, t1, t2
 # CHECK-ASM: encoding: [0xbb,0x12,0x73,0x20]
 slow t0, t1, t2
Index: llvm/test/MC/RISCV/rv64zbb-invalid.s
===
--- llvm/test/MC/RISCV/rv64zbb-invalid.s
+++ llvm/test/MC/RISCV/rv64zbb-invalid.s
@@ -1,12 +1,5 @@
 # RUN: not llvm-mc -triple riscv64 -mattr=+experimental-b,experimental-zbb < %s 2>&1 | FileCheck %s
 
-# Too few operands
-slli.uw t0, t1 # CHECK: :[[@LINE]]:1: error: too few operands for instruction
-# Immediate operand out of range
-slli.uw t0, t1, 64 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 63]
-slli.uw t0, t1, -1 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 63]
-# Too few operands
-add.uw t0, t1 # CHECK: :[[@LINE]]:1: error: too few operands for instruction
 # Too few operands
 slow t0, t1 # CHECK: :[[@LINE]]:1: error: too few operands for instruction
 # Too few operands
Index: llvm/test/MC/RISCV/rv64zba-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zba-valid.s
@@ -0,0 +1,20 @@
+# With B extension:
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-b -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-b < %s \
+# RUN: | llvm-objdump --mattr=+experimental-b -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# With Bitmanip base extension:
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zba -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zba < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zba -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: slli.uw t0, t1, 0
+# CHECK-ASM: encoding: [0x9b,0x12,0x03,0x08]
+slli.uw t0, t1, 0
+# CHECK-ASM-AND-OBJ: add.uw t0, t1, t2
+# CHECK-ASM: encoding: [0xbb,0x02,0x73,0x08]
+add.uw t0, t1, t2
Index: llvm/test/MC/RISCV/rv64zba-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zba-invalid.s
@@ -0,0 +1,9 @@
+# RUN: not llvm-mc -triple riscv64 -mattr=+experimental-b,experimental-zba < %s 2>&1 | FileCheck %s
+
+# Too few operands
+slli.uw t0, t1 # CHECK: :[[@LINE]]:1: error: too few operands for instruction
+# Immediate operand out of range
+slli.uw t0, t1, 64 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 63]
+slli.uw t0, t1, -1 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 63]
+# Too few operands
+add.uw t0, t1 # CHECK: :[[@LINE]]:1: error: too few operands for instruction
Index: llvm/test/CodeGen/RISCV/rv64Zbb.ll
===
--- llvm/test/CodeGen/RISCV/rv64Zbb.ll
+++ llvm/test/CodeGen/RISCV/rv64Zbb.ll
@@ -987,107 +987,3 @@
   %abs = tail call i64 @llvm.abs.i64(i64 %x, i1 true)
   ret i64 %abs
 }
-
-define i64 @slliuw(i64 %a) nounwind {
-; RV64I-LABEL: slliuw:
-; RV64I:   # %bb.0:
-; RV64I-NEXT:slli a0, a0, 1
-; RV64I-NEXT:addi a1, zero, 1
-; RV64I-NEXT:slli a1, a1, 33
-; RV64I-NEXT:addi a1, a1, -2
-; RV64I-NEXT:and a0, a0, a1
-; RV64I-NEXT:ret
-;
-; RV64IB-LABEL: slliuw:
-; RV64IB:   # %bb.0:
-; RV64IB-NEXT:slli.uw a0, a0, 1
-; RV64IB-NEXT:ret
-;
-; RV64IBB-LABEL: slliuw:
-; RV64IBB:   # %bb.0:
-; RV64IBB-NEXT:slli.uw a0, a0, 1
-; RV64IBB-NEXT: 

[PATCH] D94582: [RISCV] Rename mnemonics slliu.w->slli.uw and addu.w->add.uw to match 0.93 bitmanip spec.

2021-01-22 Thread Craig Topper via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb825278364d9: [RISCV] Rename mnemonics slliu.w-slli.uw 
and addu.w-add.uw to match 0.93… (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94582

Files:
  llvm/lib/Target/RISCV/RISCVInstrInfoB.td
  llvm/test/CodeGen/RISCV/rv64Zbb.ll
  llvm/test/MC/RISCV/rv64zbb-invalid.s
  llvm/test/MC/RISCV/rv64zbb-valid.s

Index: llvm/test/MC/RISCV/rv64zbb-valid.s
===
--- llvm/test/MC/RISCV/rv64zbb-valid.s
+++ llvm/test/MC/RISCV/rv64zbb-valid.s
@@ -12,12 +12,12 @@
 # RUN: | llvm-objdump --mattr=+experimental-zbb -d -r - \
 # RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
 
-# CHECK-ASM-AND-OBJ: slliu.w t0, t1, 0
+# CHECK-ASM-AND-OBJ: slli.uw t0, t1, 0
 # CHECK-ASM: encoding: [0x9b,0x12,0x03,0x08]
-slliu.w t0, t1, 0
-# CHECK-ASM-AND-OBJ: addu.w t0, t1, t2
+slli.uw t0, t1, 0
+# CHECK-ASM-AND-OBJ: add.uw t0, t1, t2
 # CHECK-ASM: encoding: [0xbb,0x02,0x73,0x08]
-addu.w t0, t1, t2
+add.uw t0, t1, t2
 # CHECK-ASM-AND-OBJ: slow t0, t1, t2
 # CHECK-ASM: encoding: [0xbb,0x12,0x73,0x20]
 slow t0, t1, t2
Index: llvm/test/MC/RISCV/rv64zbb-invalid.s
===
--- llvm/test/MC/RISCV/rv64zbb-invalid.s
+++ llvm/test/MC/RISCV/rv64zbb-invalid.s
@@ -1,12 +1,12 @@
 # RUN: not llvm-mc -triple riscv64 -mattr=+experimental-b,experimental-zbb < %s 2>&1 | FileCheck %s
 
 # Too few operands
-slliu.w t0, t1 # CHECK: :[[@LINE]]:1: error: too few operands for instruction
+slli.uw t0, t1 # CHECK: :[[@LINE]]:1: error: too few operands for instruction
 # Immediate operand out of range
-slliu.w t0, t1, 64 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 63]
-slliu.w t0, t1, -1 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 63]
+slli.uw t0, t1, 64 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 63]
+slli.uw t0, t1, -1 # CHECK: :[[@LINE]]:17: error: immediate must be an integer in the range [0, 63]
 # Too few operands
-addu.w t0, t1 # CHECK: :[[@LINE]]:1: error: too few operands for instruction
+add.uw t0, t1 # CHECK: :[[@LINE]]:1: error: too few operands for instruction
 # Too few operands
 slow t0, t1 # CHECK: :[[@LINE]]:1: error: too few operands for instruction
 # Too few operands
Index: llvm/test/CodeGen/RISCV/rv64Zbb.ll
===
--- llvm/test/CodeGen/RISCV/rv64Zbb.ll
+++ llvm/test/CodeGen/RISCV/rv64Zbb.ll
@@ -1000,12 +1000,12 @@
 ;
 ; RV64IB-LABEL: slliuw:
 ; RV64IB:   # %bb.0:
-; RV64IB-NEXT:slliu.w a0, a0, 1
+; RV64IB-NEXT:slli.uw a0, a0, 1
 ; RV64IB-NEXT:ret
 ;
 ; RV64IBB-LABEL: slliuw:
 ; RV64IBB:   # %bb.0:
-; RV64IBB-NEXT:slliu.w a0, a0, 1
+; RV64IBB-NEXT:slli.uw a0, a0, 1
 ; RV64IBB-NEXT:ret
   %conv1 = shl i64 %a, 1
   %shl = and i64 %conv1, 8589934590
@@ -1025,7 +1025,7 @@
 ;
 ; RV64IB-LABEL: slliuw_2:
 ; RV64IB:   # %bb.0:
-; RV64IB-NEXT:slliu.w a0, a0, 4
+; RV64IB-NEXT:slli.uw a0, a0, 4
 ; RV64IB-NEXT:add a1, a1, a0
 ; RV64IB-NEXT:ld a0, 0(a1)
 ; RV64IB-NEXT:ld a1, 8(a1)
@@ -1033,7 +1033,7 @@
 ;
 ; RV64IBB-LABEL: slliuw_2:
 ; RV64IBB:   # %bb.0:
-; RV64IBB-NEXT:slliu.w a0, a0, 4
+; RV64IBB-NEXT:slli.uw a0, a0, 4
 ; RV64IBB-NEXT:add a1, a1, a0
 ; RV64IBB-NEXT:ld a0, 0(a1)
 ; RV64IBB-NEXT:ld a1, 8(a1)
@@ -1054,12 +1054,12 @@
 ;
 ; RV64IB-LABEL: adduw:
 ; RV64IB:   # %bb.0:
-; RV64IB-NEXT:addu.w a0, a0, a1
+; RV64IB-NEXT:add.uw a0, a0, a1
 ; RV64IB-NEXT:ret
 ;
 ; RV64IBB-LABEL: adduw:
 ; RV64IBB:   # %bb.0:
-; RV64IBB-NEXT:addu.w a0, a0, a1
+; RV64IBB-NEXT:add.uw a0, a0, a1
 ; RV64IBB-NEXT:ret
   %and = and i64 %b, 4294967295
   %add = add i64 %and, %a
@@ -1077,13 +1077,13 @@
 ;
 ; RV64IB-LABEL: adduw_2:
 ; RV64IB:   # %bb.0:
-; RV64IB-NEXT:addu.w a0, a1, a0
+; RV64IB-NEXT:add.uw a0, a1, a0
 ; RV64IB-NEXT:lb a0, 0(a0)
 ; RV64IB-NEXT:ret
 ;
 ; RV64IBB-LABEL: adduw_2:
 ; RV64IBB:   # %bb.0:
-; RV64IBB-NEXT:addu.w a0, a1, a0
+; RV64IBB-NEXT:add.uw a0, a1, a0
 ; RV64IBB-NEXT:lb a0, 0(a0)
 ; RV64IBB-NEXT:ret
   %3 = zext i32 %0 to i64
Index: llvm/lib/Target/RISCV/RISCVInstrInfoB.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfoB.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfoB.td
@@ -370,8 +370,8 @@
 } // Predicates = [HasStdExtZbp]
 
 let Predicates = [HasStdExtZbb, IsRV64] in {
-def SLLIUW : RVBShift_ri<0b1, 0b001, OPC_OP_IMM_32, "slliu.w">, Sched<[]>;
-def ADDUW : ALUW_rr<0b100, 0b000, "addu.w">, Sched<[]>;
+def SLLIUW : RVBShift_ri<0b1, 0b001, OPC_OP_IMM_32, "slli.uw">, Sched<[]>;
+def ADDUW : ALUW_rr<0b100, 0b000, "add.uw">, Sched<[]>;
 } // 

[clang] 4e6ad11 - [RISCV] Add Zba feature and move add.uw and slli.uw to it.

2021-01-22 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2021-01-22T12:49:10-08:00
New Revision: 4e6ad11bc6f29eecfbef7f5d5b7e581dd26e2024

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

LOG: [RISCV] Add Zba feature and move add.uw and slli.uw to it.

Still need to add SH*ADD instructions.

Reviewed By: asb, frasercrmck

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

Added: 
llvm/test/CodeGen/RISCV/rv64Zba.ll
llvm/test/MC/RISCV/rv64zba-invalid.s
llvm/test/MC/RISCV/rv64zba-valid.s

Modified: 
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
clang/test/Driver/riscv-arch.c
llvm/lib/Target/RISCV/RISCV.td
llvm/lib/Target/RISCV/RISCVInstrInfoB.td
llvm/lib/Target/RISCV/RISCVSubtarget.h
llvm/test/CodeGen/RISCV/rv64Zbb.ll
llvm/test/MC/RISCV/rv64zbb-invalid.s
llvm/test/MC/RISCV/rv64zbb-valid.s

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index aa1a5d8c803f..22a4625946f8 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -58,9 +58,9 @@ static StringRef getExtensionType(StringRef Ext) {
 // extension that the compiler currently supports.
 static Optional
 isExperimentalExtension(StringRef Ext) {
-  if (Ext == "b" || Ext == "zbb" || Ext == "zbc" || Ext == "zbe" ||
-  Ext == "zbf" || Ext == "zbm" || Ext == "zbp" || Ext == "zbr" ||
-  Ext == "zbs" || Ext == "zbt" || Ext == "zbproposedc")
+  if (Ext == "b" || Ext == "zba" || Ext == "zbb" || Ext == "zbc" ||
+  Ext == "zbe" || Ext == "zbf" || Ext == "zbm" || Ext == "zbp" ||
+  Ext == "zbr" || Ext == "zbs" || Ext == "zbt" || Ext == "zbproposedc")
 return RISCVExtensionVersion{"0", "92"};
   if (Ext == "v")
 return RISCVExtensionVersion{"0", "9"};

diff  --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index 533f1cff42af..58e5eb2c8332 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -365,6 +365,10 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE %s
 // RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 
'rv32izbb0p92zbp0p92', multi-character extensions must be separated by 
underscores
 
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izba0p92 
-menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBA %s
+// RV32-EXPERIMENTAL-ZBA: "-target-feature" "+experimental-zba"
+
 // RUN: %clang -target riscv32-unknown-elf -march=rv32iv -### %s -c 2>&1 | \
 // RUN:   FileCheck -check-prefix=RV32-EXPERIMENTAL-V-NOFLAG %s
 // RV32-EXPERIMENTAL-V-NOFLAG: error: invalid arch name 'rv32iv'

diff  --git a/llvm/lib/Target/RISCV/RISCV.td b/llvm/lib/Target/RISCV/RISCV.td
index 02424f6d86ff..7b0eac7c2f1d 100644
--- a/llvm/lib/Target/RISCV/RISCV.td
+++ b/llvm/lib/Target/RISCV/RISCV.td
@@ -56,6 +56,13 @@ def HasStdExtC : Predicate<"Subtarget->hasStdExtC()">,
AssemblerPredicate<(all_of FeatureStdExtC),
"'C' (Compressed Instructions)">;
 
+def FeatureExtZba
+: SubtargetFeature<"experimental-zba", "HasStdExtZba", "true",
+   "'Zba' (Base 'B' Instructions)">;
+def HasStdExtZba : Predicate<"Subtarget->hasStdExtZba()">,
+ AssemblerPredicate<(all_of FeatureExtZba),
+ "'Zba' (Address calculation 'B' Instructions)">;
+
 def FeatureExtZbb
 : SubtargetFeature<"experimental-zbb", "HasStdExtZbb", "true",
"'Zbb' (Base 'B' Instructions)">;
@@ -137,7 +144,8 @@ def HasStdExtZbproposedc : 
Predicate<"Subtarget->hasStdExtZbproposedc()">,
 def FeatureStdExtB
 : SubtargetFeature<"experimental-b", "HasStdExtB", "true",
"'B' (Bit Manipulation Instructions)",
-   [FeatureExtZbb,
+   [FeatureExtZba,
+FeatureExtZbb,
 FeatureExtZbc,
 FeatureExtZbe,
 FeatureExtZbf,

diff  --git a/llvm/lib/Target/RISCV/RISCVInstrInfoB.td 
b/llvm/lib/Target/RISCV/RISCVInstrInfoB.td
index e68aa90310a0..537fbf9a7676 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoB.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoB.td
@@ -369,7 +369,7 @@ def SHFLI   : RVBShfl_ri<0b10, 0b001, OPC_OP_IMM, 
"shfli">, Sched<[]>;
 def UNSHFLI : RVBShfl_ri<0b10, 0b101, OPC_OP_IMM, "unshfli">, Sched<[]>;
 } // Predicates = [HasStdExtZbp]
 
-let Predicates = [HasStdExtZbb, IsRV64] in {
+let Predicates = [HasStdExtZba, IsRV64] in {
 def SLLIUW : RVBShift_ri<0b1, 0b001, OPC_OP_IMM_32, "slli.uw">, Sched<[]>;
 def ADDUW : ALUW_rr<0b100, 0b000, "add.uw">, Sched<[]>;
 } 

[PATCH] D92808: [ObjC][ARC] Annotate calls with attributes instead of emitting retainRV or claimRV calls in the IR

2021-01-22 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.  I know you mentioned doing this for more targets in follow-up commits.  
It would be good to also do this for `-O0`, so that we have a single correct 
pattern coming out of the frontend in all modes; but that's also okay to do in 
follow-ups.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92808

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


[PATCH] D94979: [CGExpr] Use getCharWidth() more consistently in CCGExprConstant. NFC

2021-01-22 Thread Bjorn Pettersson 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 rGea2cfda386f1: [CGExpr] Use getCharWidth() more consistently 
in CCGExprConstant. NFC (authored by bjope).

Changed prior to commit:
  https://reviews.llvm.org/D94979?vs=318135=318607#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94979

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTypeCache.h


Index: clang/lib/CodeGen/CodeGenTypeCache.h
===
--- clang/lib/CodeGen/CodeGenTypeCache.h
+++ clang/lib/CodeGen/CodeGenTypeCache.h
@@ -41,6 +41,9 @@
   /// int
   llvm::IntegerType *IntTy;
 
+  /// char
+  llvm::IntegerType *CharTy;
+
   /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size.
   union {
 llvm::IntegerType *IntPtrTy;
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -123,6 +123,8 @@
 
C.toCharUnitsFromBits(C.getTargetInfo().getMaxPointerWidth()).getQuantity();
   IntAlignInBytes =
 C.toCharUnitsFromBits(C.getTargetInfo().getIntAlign()).getQuantity();
+  CharTy =
+llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getCharWidth());
   IntTy = llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getIntWidth());
   IntPtrTy = llvm::IntegerType::get(LLVMContext,
 C.getTargetInfo().getMaxPointerWidth());
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -58,14 +58,14 @@
   }
 
   llvm::Constant *getPadding(CharUnits PadSize) const {
-llvm::Type *Ty = CGM.Int8Ty;
+llvm::Type *Ty = CGM.CharTy;
 if (PadSize > CharUnits::One())
   Ty = llvm::ArrayType::get(Ty, PadSize.getQuantity());
 return llvm::UndefValue::get(Ty);
   }
 
   llvm::Constant *getZeroes(CharUnits ZeroSize) const {
-llvm::Type *Ty = llvm::ArrayType::get(CGM.Int8Ty, ZeroSize.getQuantity());
+llvm::Type *Ty = llvm::ArrayType::get(CGM.CharTy, ZeroSize.getQuantity());
 return llvm::ConstantAggregateZero::get(Ty);
   }
 };
@@ -1069,7 +1069,7 @@
 
   assert(CurSize <= TotalSize && "Union size mismatch!");
   if (unsigned NumPadBytes = TotalSize - CurSize) {
-llvm::Type *Ty = CGM.Int8Ty;
+llvm::Type *Ty = CGM.CharTy;
 if (NumPadBytes > 1)
   Ty = llvm::ArrayType::get(Ty, NumPadBytes);
 


Index: clang/lib/CodeGen/CodeGenTypeCache.h
===
--- clang/lib/CodeGen/CodeGenTypeCache.h
+++ clang/lib/CodeGen/CodeGenTypeCache.h
@@ -41,6 +41,9 @@
   /// int
   llvm::IntegerType *IntTy;
 
+  /// char
+  llvm::IntegerType *CharTy;
+
   /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size.
   union {
 llvm::IntegerType *IntPtrTy;
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -123,6 +123,8 @@
 C.toCharUnitsFromBits(C.getTargetInfo().getMaxPointerWidth()).getQuantity();
   IntAlignInBytes =
 C.toCharUnitsFromBits(C.getTargetInfo().getIntAlign()).getQuantity();
+  CharTy =
+llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getCharWidth());
   IntTy = llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getIntWidth());
   IntPtrTy = llvm::IntegerType::get(LLVMContext,
 C.getTargetInfo().getMaxPointerWidth());
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -58,14 +58,14 @@
   }
 
   llvm::Constant *getPadding(CharUnits PadSize) const {
-llvm::Type *Ty = CGM.Int8Ty;
+llvm::Type *Ty = CGM.CharTy;
 if (PadSize > CharUnits::One())
   Ty = llvm::ArrayType::get(Ty, PadSize.getQuantity());
 return llvm::UndefValue::get(Ty);
   }
 
   llvm::Constant *getZeroes(CharUnits ZeroSize) const {
-llvm::Type *Ty = llvm::ArrayType::get(CGM.Int8Ty, ZeroSize.getQuantity());
+llvm::Type *Ty = llvm::ArrayType::get(CGM.CharTy, ZeroSize.getQuantity());
 return llvm::ConstantAggregateZero::get(Ty);
   }
 };
@@ -1069,7 +1069,7 @@
 
   assert(CurSize <= TotalSize && "Union size mismatch!");
   if (unsigned NumPadBytes = TotalSize - CurSize) {
-llvm::Type *Ty = CGM.Int8Ty;
+llvm::Type *Ty = CGM.CharTy;
 if (NumPadBytes > 1)
   Ty = llvm::ArrayType::get(Ty, NumPadBytes);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D94977: [CodeGen] Use getCharWidth() more consistently in CGRecordLowering. NFC

2021-01-22 Thread Bjorn Pettersson 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 rG72f863fd37c3: [CodeGen] Use getCharWidth() more consistently 
in CGRecordLowering. NFC (authored by bjope).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94977

Files:
  clang/lib/CodeGen/CGRecordLayoutBuilder.cpp


Index: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
===
--- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -127,15 +127,20 @@
 
   /// Wraps llvm::Type::getIntNTy with some implicit arguments.
   llvm::Type *getIntNType(uint64_t NumBits) {
+unsigned AlignedBits = llvm::alignTo(NumBits, Context.getCharWidth());
+return llvm::Type::getIntNTy(Types.getLLVMContext(), AlignedBits);
+  }
+  /// Get the LLVM type sized as one character unit.
+  llvm::Type *getCharType() {
 return llvm::Type::getIntNTy(Types.getLLVMContext(),
- (unsigned)llvm::alignTo(NumBits, 8));
+ Context.getCharWidth());
   }
-  /// Gets an llvm type of size NumBytes and alignment 1.
-  llvm::Type *getByteArrayType(CharUnits NumBytes) {
-assert(!NumBytes.isZero() && "Empty byte arrays aren't allowed.");
-llvm::Type *Type = llvm::Type::getInt8Ty(Types.getLLVMContext());
-return NumBytes == CharUnits::One() ? Type :
-(llvm::Type *)llvm::ArrayType::get(Type, NumBytes.getQuantity());
+  /// Gets an llvm type of size NumChars and alignment 1.
+  llvm::Type *getByteArrayType(CharUnits NumChars) {
+assert(!NumChars.isZero() && "Empty byte arrays aren't allowed.");
+llvm::Type *Type = getCharType();
+return NumChars == CharUnits::One() ? Type :
+(llvm::Type *)llvm::ArrayType::get(Type, NumChars.getQuantity());
   }
   /// Gets the storage type for a field decl and handles storage
   /// for itanium bitfields that are smaller than their declared type.


Index: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
===
--- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -127,15 +127,20 @@
 
   /// Wraps llvm::Type::getIntNTy with some implicit arguments.
   llvm::Type *getIntNType(uint64_t NumBits) {
+unsigned AlignedBits = llvm::alignTo(NumBits, Context.getCharWidth());
+return llvm::Type::getIntNTy(Types.getLLVMContext(), AlignedBits);
+  }
+  /// Get the LLVM type sized as one character unit.
+  llvm::Type *getCharType() {
 return llvm::Type::getIntNTy(Types.getLLVMContext(),
- (unsigned)llvm::alignTo(NumBits, 8));
+ Context.getCharWidth());
   }
-  /// Gets an llvm type of size NumBytes and alignment 1.
-  llvm::Type *getByteArrayType(CharUnits NumBytes) {
-assert(!NumBytes.isZero() && "Empty byte arrays aren't allowed.");
-llvm::Type *Type = llvm::Type::getInt8Ty(Types.getLLVMContext());
-return NumBytes == CharUnits::One() ? Type :
-(llvm::Type *)llvm::ArrayType::get(Type, NumBytes.getQuantity());
+  /// Gets an llvm type of size NumChars and alignment 1.
+  llvm::Type *getByteArrayType(CharUnits NumChars) {
+assert(!NumChars.isZero() && "Empty byte arrays aren't allowed.");
+llvm::Type *Type = getCharType();
+return NumChars == CharUnits::One() ? Type :
+(llvm::Type *)llvm::ArrayType::get(Type, NumChars.getQuantity());
   }
   /// Gets the storage type for a field decl and handles storage
   /// for itanium bitfields that are smaller than their declared type.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ea2cfda - [CGExpr] Use getCharWidth() more consistently in CCGExprConstant. NFC

2021-01-22 Thread Bjorn Pettersson via cfe-commits

Author: Bjorn Pettersson
Date: 2021-01-22T21:12:17+01:00
New Revision: ea2cfda386f1a0f0b8cab06a9400bbf4cf7bfbaa

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

LOG: [CGExpr] Use getCharWidth() more consistently in CCGExprConstant. NFC

Most of CGExprConstant.cpp is using the CharUnits abstraction
and is using getCharWidth() (directly of indirectly) when converting
between size of a char and size in bits. This patch is making that
abstraction more consistent by adding CharTy to the CodeGenTypeCache
(honoring getCharWidth() when mapping from char to LLVM IR types,
instead of using Int8Ty directly).

Reviewed By: rjmccall

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

Added: 


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

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index ca1d3a937fa8..497f9c04c9f8 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -58,14 +58,14 @@ struct ConstantAggregateBuilderUtils {
   }
 
   llvm::Constant *getPadding(CharUnits PadSize) const {
-llvm::Type *Ty = CGM.Int8Ty;
+llvm::Type *Ty = CGM.CharTy;
 if (PadSize > CharUnits::One())
   Ty = llvm::ArrayType::get(Ty, PadSize.getQuantity());
 return llvm::UndefValue::get(Ty);
   }
 
   llvm::Constant *getZeroes(CharUnits ZeroSize) const {
-llvm::Type *Ty = llvm::ArrayType::get(CGM.Int8Ty, ZeroSize.getQuantity());
+llvm::Type *Ty = llvm::ArrayType::get(CGM.CharTy, ZeroSize.getQuantity());
 return llvm::ConstantAggregateZero::get(Ty);
   }
 };
@@ -1069,7 +1069,7 @@ class ConstExprEmitter :
 
   assert(CurSize <= TotalSize && "Union size mismatch!");
   if (unsigned NumPadBytes = TotalSize - CurSize) {
-llvm::Type *Ty = CGM.Int8Ty;
+llvm::Type *Ty = CGM.CharTy;
 if (NumPadBytes > 1)
   Ty = llvm::ArrayType::get(Ty, NumPadBytes);
 

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 18d633911f55..d93c9690cfb2 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -123,6 +123,8 @@ CodeGenModule::CodeGenModule(ASTContext , const 
HeaderSearchOptions ,
 
C.toCharUnitsFromBits(C.getTargetInfo().getMaxPointerWidth()).getQuantity();
   IntAlignInBytes =
 C.toCharUnitsFromBits(C.getTargetInfo().getIntAlign()).getQuantity();
+  CharTy =
+llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getCharWidth());
   IntTy = llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getIntWidth());
   IntPtrTy = llvm::IntegerType::get(LLVMContext,
 C.getTargetInfo().getMaxPointerWidth());

diff  --git a/clang/lib/CodeGen/CodeGenTypeCache.h 
b/clang/lib/CodeGen/CodeGenTypeCache.h
index 20a3263c0b1a..f258234fb4d8 100644
--- a/clang/lib/CodeGen/CodeGenTypeCache.h
+++ b/clang/lib/CodeGen/CodeGenTypeCache.h
@@ -41,6 +41,9 @@ struct CodeGenTypeCache {
   /// int
   llvm::IntegerType *IntTy;
 
+  /// char
+  llvm::IntegerType *CharTy;
+
   /// intptr_t, size_t, and ptr
diff _t, which we assume are the same size.
   union {
 llvm::IntegerType *IntPtrTy;



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


[clang] 72f863f - [CodeGen] Use getCharWidth() more consistently in CGRecordLowering. NFC

2021-01-22 Thread Bjorn Pettersson via cfe-commits

Author: Bjorn Pettersson
Date: 2021-01-22T21:12:17+01:00
New Revision: 72f863fd37c3471e7e1b152ac613da00ab6faaba

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

LOG: [CodeGen] Use getCharWidth() more consistently in CGRecordLowering. NFC

When using getByteArrayType the requested size is calculated in
char units, but the type used for the array was hardcoded to the
Int8Ty. This patch is using getCharWIdth a bit more consistently
by using getIntNTy in combination with getCharWidth, instead
of explictly using getInt8Ty.

Reviewed By: rjmccall

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

Added: 


Modified: 
clang/lib/CodeGen/CGRecordLayoutBuilder.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp 
b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
index 880342dfed1f..cf8313f92587 100644
--- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -127,15 +127,20 @@ struct CGRecordLowering {
 
   /// Wraps llvm::Type::getIntNTy with some implicit arguments.
   llvm::Type *getIntNType(uint64_t NumBits) {
+unsigned AlignedBits = llvm::alignTo(NumBits, Context.getCharWidth());
+return llvm::Type::getIntNTy(Types.getLLVMContext(), AlignedBits);
+  }
+  /// Get the LLVM type sized as one character unit.
+  llvm::Type *getCharType() {
 return llvm::Type::getIntNTy(Types.getLLVMContext(),
- (unsigned)llvm::alignTo(NumBits, 8));
+ Context.getCharWidth());
   }
-  /// Gets an llvm type of size NumBytes and alignment 1.
-  llvm::Type *getByteArrayType(CharUnits NumBytes) {
-assert(!NumBytes.isZero() && "Empty byte arrays aren't allowed.");
-llvm::Type *Type = llvm::Type::getInt8Ty(Types.getLLVMContext());
-return NumBytes == CharUnits::One() ? Type :
-(llvm::Type *)llvm::ArrayType::get(Type, NumBytes.getQuantity());
+  /// Gets an llvm type of size NumChars and alignment 1.
+  llvm::Type *getByteArrayType(CharUnits NumChars) {
+assert(!NumChars.isZero() && "Empty byte arrays aren't allowed.");
+llvm::Type *Type = getCharType();
+return NumChars == CharUnits::One() ? Type :
+(llvm::Type *)llvm::ArrayType::get(Type, NumChars.getQuantity());
   }
   /// Gets the storage type for a field decl and handles storage
   /// for itanium bitfields that are smaller than their declared type.



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


[PATCH] D92808: [ObjC][ARC] Annotate calls with attributes instead of emitting retainRV or claimRV calls in the IR

2021-01-22 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 318594.
ahatanak edited the summary of this revision.
ahatanak added a comment.

Stop using `clang.arc.rv_marker` and just use "clang.arc.rv"="retain/claim".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92808

Files:
  clang/lib/CodeGen/CGObjC.cpp
  clang/test/CodeGenObjC/arc-rv-attr.m
  clang/test/CodeGenObjC/arc-unsafeclaim.m
  llvm/include/llvm/Analysis/ObjCARCRVAttr.h
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/Instruction.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
  llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
  llvm/lib/Transforms/ObjCARC/ObjCARC.cpp
  llvm/lib/Transforms/ObjCARC/ObjCARC.h
  llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
  llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
  llvm/lib/Transforms/ObjCARC/PtrState.cpp
  llvm/lib/Transforms/ObjCARC/PtrState.h
  llvm/lib/Transforms/Utils/InlineFunction.cpp
  llvm/test/CodeGen/AArch64/call-rv-marker.ll
  llvm/test/Transforms/DeadArgElim/deadretval.ll
  llvm/test/Transforms/Inline/inline-retainRV-call.ll
  llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
  llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
  llvm/test/Transforms/ObjCARC/rv.ll

Index: llvm/test/Transforms/ObjCARC/rv.ll
===
--- llvm/test/Transforms/ObjCARC/rv.ll
+++ llvm/test/Transforms/ObjCARC/rv.ll
@@ -452,6 +452,28 @@
   ret i8* %v3
 }
 
+; Remove attributes and the autoreleaseRV call if the call is a tail call.
+
+; CHECK-LABEL: define i8* @test31(
+; CHECK: %[[CALL:.*]] = tail call i8* @returner()
+; CHECK: ret i8* %[[CALL]]
+
+define i8* @test31() {
+  %call = tail call "clang.arc.rv"="retain" i8* @returner()
+  %1 = call i8* @llvm.objc.autoreleaseReturnValue(i8* %call)
+  ret i8* %1
+}
+
+; CHECK-LABEL: define i8* @test32(
+; CHECK: %[[CALL:.*]] = call "clang.arc.rv"="retain" i8* @returner()
+; CHECK: call i8* @llvm.objc.autoreleaseReturnValue(i8* %[[CALL]])
+
+define i8* @test32() {
+  %call = call "clang.arc.rv"="retain" i8* @returner()
+  %1 = call i8* @llvm.objc.autoreleaseReturnValue(i8* %call)
+  ret i8* %1
+}
+
 !0 = !{}
 
 ; CHECK: attributes [[NUW]] = { nounwind }
Index: llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
===
--- /dev/null
+++ llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
@@ -0,0 +1,63 @@
+; RUN: opt -objc-arc-contract -S < %s | FileCheck %s
+; RUN: opt -passes=objc-arc-contract -S < %s | FileCheck %s
+
+; CHECK-LABEL: define void @test0() {
+; CHECK: %[[CALL:.*]] = notail call "clang.arc.rv"="retain" i8* @foo()
+; CHECK: call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL]])
+
+define void @test0() {
+  %call1 = call "clang.arc.rv"="retain" i8* @foo()
+  ret void
+}
+
+; CHECK-LABEL: define void @test1() {
+; CHECK: %[[CALL:.*]] = notail call "clang.arc.rv"="claim" i8* @foo()
+; CHECK: call i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %[[CALL]])
+
+define void @test1() {
+  %call1 = call "clang.arc.rv"="claim" i8* @foo()
+  ret void
+}
+
+; CHECK-LABEL:define i8* @test2(
+; CHECK: %[[CALL1:.*]] = invoke "clang.arc.rv"="retain" i8* @foo()
+
+; CHECK: %[[V0:.*]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL1]])
+; CHECK-NEXT: br
+
+; CHECK: %[[CALL3:.*]] = invoke "clang.arc.rv"="retain" i8* @foo()
+
+; CHECK: %[[V2:.*]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL3]])
+; CHECK-NEXT: br
+
+; CHECK: %[[RETVAL:.*]] = phi i8* [ %[[V0]], {{.*}} ], [ %[[V2]], {{.*}} ]
+; CHECK: ret i8* %[[RETVAL]]
+
+define i8* @test2(i1 zeroext %b) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+entry:
+  br i1 %b, label %if.then, label %if.end
+
+if.then:
+  %call1 = invoke "clang.arc.rv"="retain" i8* @foo()
+  to label %cleanup unwind label %lpad
+
+lpad:
+  %0 = landingpad { i8*, i32 }
+  cleanup
+  resume { i8*, i32 } undef
+
+if.end:
+  %call3 = invoke "clang.arc.rv"="retain" i8* @foo()
+  to label %cleanup unwind label %lpad
+
+cleanup:
+  %retval.0 = phi i8* [ %call1, %if.then ], [ %call3, %if.end ]
+  ret i8* %retval.0
+}
+
+declare i8* @foo()
+declare i32 @__gxx_personality_v0(...)
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 1, !"clang.arc.retainAutoreleasedReturnValueMarker", !"mov\09fp, fp\09\09// marker for objc_retainAutoreleaseReturnValue"}
Index: llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
===
--- llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
+++ llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
@@ -10,6 +10,16 @@
 ;   }
 ; }
 
+; CHECK-LABEL: define void @"\01?g@@YAXXZ"()
+; CHECK-LABEL: catch
+; CHECK: call void asm sideeffect "movl{{.*}}%ebp, %ebp{{.*}}", ""() [ "funclet"(token %1) ]
+
+; CHECK-LABEL: catch.1
+; CHECK: call void asm 

[PATCH] D89490: Introduce __attribute__((darwin_abi))

2021-01-22 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D89490#2514695 , @aguinet wrote:

>> I may be over-reacting to the way the patch seemed to be touching on the C++ 
>> ABI in multiple places.  My understanding is that `ms_abi` is just a 
>> calling-convention attribute; it's basically "use the (default) calling 
>> convention that MSVC would use for this function".  If that's all you want, 
>> then this is reasonable, although I am worried about creating a new 
>> attribute for every system that Wine chooses to target.
>
> I literally based this patch on how ms_abi was implemented. It's 
> unfortunately more than just teaching clang to change the calling convention 
> on LLVM IR functions. The fact that ABI implementations are spread all over 
> the place between various places in LLVM is, as far as I remember, a known 
> problem discussed many times on llvm-dev, and looks like a hard one to fix.

Right, I understand that — I've even given an LLVM talk about it.  I was just 
confused about your intent because you made some effort to match other parts of 
the ABI besides what we might traditionally consider the calling convention.  I 
suppose some of those changes could be thought of as feature-specific calling 
conventions, but I don't usually think of them that way.

>> About "darwin": technically, every Apple platform has a different ABI.  Our 
>> current ARM64 platforms do all agree about things like the calling 
>> convention, at least if you count newer watches (which use a 32-on-64 ABI in 
>> userspace) as not ARM64.  That is not true of other architectures, most 
>> notably on ARM32, where the 32-bit iOS ABI is very different from the armv7k 
>> Apple Watch ABI; and it is certainly conceivable that Apple might release a 
>> new ARM64 platform in the future with a different calling convention.  The 
>> more technically correct and future-proof thing would be to use the OS name 
>> (or maybe even the triple!) in the attribute, probably as an argument to the 
>> attribute, like `__attribute__((target_abi("arm64-apple-ios")))`.
>
> I'm a bit afraid that `__attribute__((target_abi(XX)))` would conflict with 
> the existing `__attribute__((ms_abi))`.

They don't *conflict*.  It's a more general scheme than the existing attribute, 
but the existing attribute can be thought of as a shorthand for one case of 
that more general scheme, so I don't see a problem here.  I would like to not 
have to add a new attribute for every OS that Wine decides to support.

> About Apple that would create as much ABIs as products, I guess we have a 
> living example: is the ABI for OSX/ARM64 different than the ABI for 
> iOS/ARM64? I can't seem find any official documentation about this :/ (only 
> talking about arm64 here, but I get your points about armv7 targets).

No, we've used the same basic ABI on iOS, macOS, and tvOS for ARM64.  But 
that's not surprising because those products were all released within a 
relatively short period of time from each other, so we don't have much of a 
laundry list of things we'd like to improve about them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89490

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


[PATCH] D95253: [clang][Fuchsia] Add relative-vtables + asan multilibs

2021-01-22 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr.
leonardchan added a project: clang.
Herald added a subscriber: mgorny.
leonardchan requested review of this revision.

We're choosing to take an opt-in approach for landing Relative VTables, so 
we'll need asan-equivalent multilibs with relative vtables enabled. Afterwards, 
we can just flip the switch in our build.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95253

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  
clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/relative-vtables+asan+noexcept/libc++.so
  
clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia/c++/relative-vtables+asan/libc++.so
  clang/test/Driver/fuchsia.cpp

Index: clang/test/Driver/fuchsia.cpp
===
--- clang/test/Driver/fuchsia.cpp
+++ clang/test/Driver/fuchsia.cpp
@@ -96,10 +96,37 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
 // RUN: -fuse-ld=lld 2>&1\
 // RUN: | FileCheck %s -check-prefixes=CHECK-MULTILIB-X86,CHECK-MULTILIB-RELATIVE-VTABLES-NOEXCEPT-X86
+// RUN: %clangxx %s -### --target=x86_64-fuchsia -fexperimental-relative-c++-abi-vtables -fsanitize=address \
+// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -fuse-ld=lld 2>&1\
+// RUN: | FileCheck %s -check-prefixes=CHECK-MULTILIB-X86,CHECK-MULTILIB-RELATIVE-VTABLES-ASAN-X86
+// RUN: %clangxx %s -### --target=x86_64-fuchsia -fexperimental-relative-c++-abi-vtables -fno-exceptions -fsanitize=address \
+// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -fuse-ld=lld 2>&1\
+// RUN: | FileCheck %s -check-prefixes=CHECK-MULTILIB-X86,CHECK-MULTILIB-RELATIVE-VTABLES-ASAN-NOEXCEPT-X86
+// RUN: %clangxx %s -### --target=x86_64-fuchsia -fno-experimental-relative-c++-abi-vtables \
+// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -fuse-ld=lld 2>&1\
+// RUN: | FileCheck %s -check-prefixes=CHECK-MULTILIB-X86
+// RUN: %clangxx %s -### --target=x86_64-fuchsia -fno-experimental-relative-c++-abi-vtables \
+// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -fuse-ld=lld 2>&1\
+// RUN: | FileCheck %s -check-prefixes=CHECK-MULTILIB-X86
+// RUN: %clangxx %s -### --target=x86_64-fuchsia -fno-experimental-relative-c++-abi-vtables -fexperimental-relative-c++-abi-vtables \
+// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -fuse-ld=lld 2>&1\
+// RUN: | FileCheck %s -check-prefixes=CHECK-MULTILIB-X86
 // CHECK-MULTILIB-X86: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-MULTILIB-ASAN-X86: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}asan"
 // CHECK-MULTILIB-NOEXCEPT-X86: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}noexcept"
 // CHECK-MULTILIB-ASAN-NOEXCEPT-X86: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}asan+noexcept"
 // CHECK-MULTILIB-RELATIVE-VTABLES-X86: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}relative-vtables"
 // CHECK-MULTILIB-RELATIVE-VTABLES-NOEXCEPT-X86: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}relative-vtables+noexcept"
+// CHECK-MULTILIB-RELATIVE-VTABLES-ASAN-X86: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}relative-vtables+asan"
+// CHECK-MULTILIB-RELATIVE-VTABLES-ASAN-NOEXCEPT-X86: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}relative-vtables+asan+noexcept"
 // CHECK-MULTILIB-X86: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -217,6 +217,14 @@
   .flag("+fexperimental-relative-c++-abi-vtables")
   .flag("-fexceptions")
   .flag("+fno-exceptions"));
+  Multilibs.push_back(Multilib("relative-vtables+asan", {}, {}, 6)
+  .flag("+fexperimental-relative-c++-abi-vtables")
+  .flag("+fsanitize=address"));
+  Multilibs.push_back(Multilib("relative-vtables+asan+noexcept", {}, {}, 7)
+  .flag("+fexperimental-relative-c++-abi-vtables")
+  

[PATCH] D95187: [DebugInfo][CodeView] Use as the display name for lambdas.

2021-01-22 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I see a variety of presubmit failures in Harbormaster that seem related, so 
make sure to check those.




Comment at: clang/include/clang/AST/Mangle.h:92
 
+  virtual StringRef getLambdaString(const CXXRecordDecl *Lambda) = 0;
+

I think I would prefer to have this return a number. I think CGDebugInfo should 
be responsible for the formatting of the display names, not the mangler. Both 
the MS and Itanium manglers have private methods for numbering internal linkage 
lambdas, and I think it would be reasonable to hook those up to a public 
virtual method.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:320-321
 
   // The CodeView printer in LLVM wants to see the names of unnamed types: it 
is
   // used to reconstruct the fully qualified type names.
   if (CGM.getCodeGenOpts().EmitCodeView) {

I think this comment could be improved, and I think it would help address some 
of David's concerns in the previous patch about the format requirements of 
codeview.



Comment at: clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp:13
 
+auto lambda1 = []() { return 1; };
+

Please add tests for a lambda in an inline function and one in a non-inline 
function. The inline lambda will be externally visible and have a mangling 
number, and the non-inline one will be internal, and will not have a mangling 
number. They should both get `` names, though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95187

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


[clang] 520b5ec - [SystemZ][z/OS] Fix No such file or directory expression error matching in lit tests - continued

2021-01-22 Thread Abhina Sreeskantharajan via cfe-commits

Author: Abhina Sreeskantharajan
Date: 2021-01-22T13:54:25-05:00
New Revision: 520b5ecf856152f35ee38207eec39f5674dd2bd4

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

LOG: [SystemZ][z/OS] Fix No such file or directory expression error matching in 
lit tests - continued

This is a continuation of https://reviews.llvm.org/D94239. I missed some other 
spellings of the same error.

Reviewed By: muiez

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

Added: 


Modified: 
clang/test/Driver/clang-offload-bundler.c
clang/test/Frontend/output-failures.c
llvm/test/Object/archive-extract-dir.test
llvm/test/Object/archive-extract.test
llvm/test/Object/directory.ll
llvm/test/tools/llvm-ar/error-opening-directory.test
llvm/test/tools/llvm-ar/move.test
llvm/test/tools/llvm-ar/print.test
llvm/test/tools/llvm-ar/quick-append.test
llvm/test/tools/llvm-libtool-darwin/invalid-input-output-args.test
llvm/test/tools/llvm-lipo/create-arch.test
llvm/test/tools/llvm-lipo/replace-invalid-input.test
llvm/test/tools/llvm-lto/error.ll
llvm/test/tools/llvm-objcopy/wasm/dump-section.test
llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test

Removed: 




diff  --git a/clang/test/Driver/clang-offload-bundler.c 
b/clang/test/Driver/clang-offload-bundler.c
index 3e1fab25d754..f7428d7f02f4 100644
--- a/clang/test/Driver/clang-offload-bundler.c
+++ b/clang/test/Driver/clang-offload-bundler.c
@@ -72,7 +72,7 @@
 
 // RUN: not clang-offload-bundler -type=i 
-targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu
 -inputs=%t.i,%t.tgt1,%t.tgt2.notexist -outputs=%t.bundle.i 2>&1 | FileCheck %s 
-DFILE=%t.tgt2.notexist --check-prefix CK-ERR5
 // RUN: not clang-offload-bundler -type=i 
-targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu
 -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i.notexist -unbundle 2>&1 | 
FileCheck %s -DFILE=%t.bundle.i.notexist --check-prefix CK-ERR5
-// CK-ERR5: error: '[[FILE]]': {{N|n}}o such file or directory
+// CK-ERR5: error: '[[FILE]]': {{.*}}{{N|n}}o such file or directory
 
 // RUN: not clang-offload-bundler -type=invalid 
-targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu
 -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s 
-DTYPE=invalid --check-prefix CK-ERR6
 // CK-ERR6: error: '[[TYPE]]': invalid file type specified

diff  --git a/clang/test/Frontend/output-failures.c 
b/clang/test/Frontend/output-failures.c
index 0e9ea63f8067..26d25fdbef36 100644
--- a/clang/test/Frontend/output-failures.c
+++ b/clang/test/Frontend/output-failures.c
@@ -1,4 +1,4 @@
 // RUN: not %clang_cc1 -emit-llvm -o %t.doesnotexist/somename %s 2> %t
 // RUN: FileCheck -check-prefix=OUTPUTFAIL -input-file=%t %s
 
-// OUTPUTFAIL: error: unable to open output file 
'{{.*}}doesnotexist{{.}}somename': '{{[nN]}}o such file or directory'
+// OUTPUTFAIL: error: unable to open output file 
'{{.*}}doesnotexist{{.}}somename': '{{.*}}{{[nN]}}o such file or 
directory{{.*}}'

diff  --git a/llvm/test/Object/archive-extract-dir.test 
b/llvm/test/Object/archive-extract-dir.test
index 5182a2f91411..d6a721c090b3 100644
--- a/llvm/test/Object/archive-extract-dir.test
+++ b/llvm/test/Object/archive-extract-dir.test
@@ -8,4 +8,4 @@ RUN: rm foo
 RUN: mkdir foo
 RUN: not llvm-ar x test.a foo 2>&1 | FileCheck %s
 
-CHECK: foo: {{[Ii]}}s a directory
+CHECK: foo: {{.*}}{{[Ii]}}s a directory{{.*}}

diff  --git a/llvm/test/Object/archive-extract.test 
b/llvm/test/Object/archive-extract.test
index 11ca12e3353b..589e8b8fe856 100644
--- a/llvm/test/Object/archive-extract.test
+++ b/llvm/test/Object/archive-extract.test
@@ -58,4 +58,4 @@ RUN: llvm-ar p %p/Inputs/thin.a evenlen | FileCheck %s 
--check-prefix=EVENLEN
 EVENLEN: evenlen
 
 RUN: not llvm-ar p %p/Inputs/thin-path.a t/test2.o 2>&1 | FileCheck %s 
--check-prefix=MISSING
-MISSING: error: {{N|n}}o such file or directory
+MISSING: error: {{.*}}{{N|n}}o such file or directory

diff  --git a/llvm/test/Object/directory.ll b/llvm/test/Object/directory.ll
index 3e9ac2ce202e..d9e340a587b1 100644
--- a/llvm/test/Object/directory.ll
+++ b/llvm/test/Object/directory.ll
@@ -1,6 +1,6 @@
 ;RUN: rm -rf %t && mkdir -p %t
 ;RUN: not llvm-ar r %t/test.a . 2>&1 | FileCheck %s
-;CHECK: .: {{I|i}}s a directory
+;CHECK: .: {{.*}}{{I|i}}s a directory{{.*}}
 
 ;RUN: rm -f %t/test.a
 ;RUN: touch %t/a-very-long-file-name

diff  --git a/llvm/test/tools/llvm-ar/error-opening-directory.test 
b/llvm/test/tools/llvm-ar/error-opening-directory.test
index c3068871230f..5a6491bd29c8 100644
--- a/llvm/test/tools/llvm-ar/error-opening-directory.test
+++ b/llvm/test/tools/llvm-ar/error-opening-directory.test
@@ -9,4 

[PATCH] D95246: [SystemZ][z/OS] Fix No such file or directory expression error matching in lit tests - continued

2021-01-22 Thread Abhina Sree via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG520b5ecf8561: [SystemZ][z/OS] Fix No such file or directory 
expression error matching in lit… (authored by abhina.sreeskantharajan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95246

Files:
  clang/test/Driver/clang-offload-bundler.c
  clang/test/Frontend/output-failures.c
  llvm/test/Object/archive-extract-dir.test
  llvm/test/Object/archive-extract.test
  llvm/test/Object/directory.ll
  llvm/test/tools/llvm-ar/error-opening-directory.test
  llvm/test/tools/llvm-ar/move.test
  llvm/test/tools/llvm-ar/print.test
  llvm/test/tools/llvm-ar/quick-append.test
  llvm/test/tools/llvm-libtool-darwin/invalid-input-output-args.test
  llvm/test/tools/llvm-lipo/create-arch.test
  llvm/test/tools/llvm-lipo/replace-invalid-input.test
  llvm/test/tools/llvm-lto/error.ll
  llvm/test/tools/llvm-objcopy/wasm/dump-section.test
  llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test

Index: llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test
===
--- llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test
+++ llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test
@@ -4,7 +4,7 @@
 
 llvm-symbolizer should print one error and two unknown line info records.
 
-ERROR: LLVMSymbolizer: error reading file: {{.*}}: {{N|n}}o such file or directory
+ERROR: LLVMSymbolizer: error reading file: {{.*}}: {{.*}}{{N|n}}o such file or directory
 ERROR-NOT: error reading file
 
 CHECK: ??
Index: llvm/test/tools/llvm-objcopy/wasm/dump-section.test
===
--- llvm/test/tools/llvm-objcopy/wasm/dump-section.test
+++ llvm/test/tools/llvm-objcopy/wasm/dump-section.test
@@ -11,7 +11,7 @@
 # CHECK: 020 63 6c 61 6e 67 05 39 2e 30 2e 30
 
 # NONEXISTENT: section 'nonexistent' not found
-# DIROUT: error: {{.*}}/bar': {{[nN]}}o such file or directory
+# DIROUT: error: {{.*}}/bar': {{.*}}{{[nN]}}o such file or directory
 
 ## Check that dumping and removing a section works in the same invocation
 # RUN: llvm-objcopy --dump-section=producers=%t.sec --remove-section=producers %t %t2
Index: llvm/test/tools/llvm-lto/error.ll
===
--- llvm/test/tools/llvm-lto/error.ll
+++ llvm/test/tools/llvm-lto/error.ll
@@ -1,5 +1,5 @@
 ; RUN: not llvm-lto foobar 2>&1 | FileCheck %s
-; CHECK: llvm-lto: error loading file 'foobar': {{N|n}}o such file or directory
+; CHECK: llvm-lto: error loading file 'foobar': {{.*}}{{N|n}}o such file or directory
 
 ; RUN: not llvm-lto --list-symbols-only %S/Inputs/empty.bc 2>&1 | FileCheck %s --check-prefix=CHECK-LIST
 ; CHECK-LIST: llvm-lto: error loading file '{{.*}}/Inputs/empty.bc': The file was not recognized as a valid object file
Index: llvm/test/tools/llvm-lipo/replace-invalid-input.test
===
--- llvm/test/tools/llvm-lipo/replace-invalid-input.test
+++ llvm/test/tools/llvm-lipo/replace-invalid-input.test
@@ -12,7 +12,7 @@
 # INPUT_ARGS: error: replace expects a single input file
 
 # RUN: not llvm-lipo %t-universal.o -replace i386 %t-33.o  -o %t.o 2>&1 | FileCheck --check-prefix=INVALID_FILE %s
-# INVALID_FILE: {{[nN]}}o such file or directory
+# INVALID_FILE: {{.*}}{{[nN]}}o such file or directory
 
 # RUN: not llvm-lipo %t-universal.o -replace i3866 %t-32.o -o %t.o 2>&1 | FileCheck --check-prefix=INVALID_ARCH %s
 # INVALID_ARCH: error: Invalid architecture: i3866
Index: llvm/test/tools/llvm-lipo/create-arch.test
===
--- llvm/test/tools/llvm-lipo/create-arch.test
+++ llvm/test/tools/llvm-lipo/create-arch.test
@@ -14,4 +14,4 @@
 # INVALID_ARCH: error: Invalid architecture: i3866
 #
 # RUN: not llvm-lipo -arch i386 %t-33.o -create -o /dev/null 2>&1 | FileCheck --check-prefix=INVALID_FILE %s
-# INVALID_FILE: {{[nN]}}o such file or directory
+# INVALID_FILE: {{.*}}{{[nN]}}o such file or directory
Index: llvm/test/tools/llvm-libtool-darwin/invalid-input-output-args.test
===
--- llvm/test/tools/llvm-libtool-darwin/invalid-input-output-args.test
+++ llvm/test/tools/llvm-libtool-darwin/invalid-input-output-args.test
@@ -28,7 +28,7 @@
 # RUN: not llvm-libtool-darwin -static -o %t.lib %t.missing 2>&1 | \
 # RUN:   FileCheck %s --check-prefix=NO-FILE -DFILE=%t.missing
 
-# NO-FILE: error: '[[FILE]]': {{[nN]}}o such file or directory
+# NO-FILE: error: '[[FILE]]': {{.*}}{{[nN]}}o such file or directory
 
 ## Input file is not an object file:
 # RUN: touch %t.invalid
Index: llvm/test/tools/llvm-ar/quick-append.test
===
--- llvm/test/tools/llvm-ar/quick-append.test
+++ llvm/test/tools/llvm-ar/quick-append.test
@@ -60,7 +60,7 @@
 # 

[PATCH] D94355: [SimplifyCFG] Add relative switch lookup tables

2021-01-22 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

Almost there! Just a few more comments on my end.




Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:5694
+Constant *CaseRes = Values[I].second;
+if (auto *GlobalVal = dyn_cast(CaseRes))
+  if (!GlobalVal->isDSOLocal())

I think we should also return false if it doesn't turn out to be a GlobalValue 
here.



Comment at: 
llvm/test/Transforms/SimplifyCFG/X86/switch_to_relative_lookup_table.ll:201-203
+; If there is a lookup table, where each element contains the same value,
+; a relative lookup should not be generated
+define void @single_value(i32 %cond)  {

It looks like this might not be testing what the comment says it should. It 
looks like in the phi statements below that each of the cases have different 
values. I think maybe you'll want something like:

```
  %str1.0 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, 
i64 0), %sw.default ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 
0, i64 0), %sw.bb2 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 
0, i64 0), %sw.bb1 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 
0, i64 0), %entry ]
  ret i8* %str1.0  ; instead of `ret void` to ensure the `%str1.0` isn't 
optimized out
```

Then ensure this just lowers directly to a GEP for `@.str` and no lookup table 
is generated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94355

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


[PATCH] D95249: [NFC] Disallow unused prefixes in clang/test/Analysis

2021-01-22 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin created this revision.
mtrofin 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/D95249

Files:
  clang/test/Analysis/auto-obj-dtors-cfg-output.cpp
  clang/test/Analysis/cfg-rich-constructors.cpp
  clang/test/Analysis/cfg-rich-constructors.mm
  clang/test/Analysis/cfg.c
  clang/test/Analysis/exploded-graph-rewriter/trimmers.dot
  clang/test/Analysis/lit.local.cfg

Index: clang/test/Analysis/lit.local.cfg
===
--- clang/test/Analysis/lit.local.cfg
+++ clang/test/Analysis/lit.local.cfg
@@ -1,5 +1,5 @@
 # -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
-
+from lit.llvm.subst import ToolSubst
 import site
 
 # Load the custom analyzer test format, which runs the test again with Z3 if it
@@ -26,3 +26,9 @@
 
 if not config.root.clang_staticanalyzer:
 config.unsupported = True
+
+fc = ToolSubst('FileCheck', unresolved='fatal')
+# Insert this first. Then, we'll first update the blank FileCheck command; then,
+# the default substitution of FileCheck will replace it to its full path.
+config.substitutions.insert(0, (fc.regex,
+'FileCheck --allow-unused-prefixes=false'))
Index: clang/test/Analysis/exploded-graph-rewriter/trimmers.dot
===
--- clang/test/Analysis/exploded-graph-rewriter/trimmers.dot
+++ clang/test/Analysis/exploded-graph-rewriter/trimmers.dot
@@ -1,17 +1,17 @@
 // RUN: %exploded_graph_rewriter %s \
 // RUN: | FileCheck %s -check-prefixes=ONE,TWO,THREE,FOUR
 // RUN: %exploded_graph_rewriter -s %s \
-// RUN: | FileCheck %s -check-prefixes=ONE,TWO,NOTHREE,FOUR
+// RUN: | FileCheck %s -check-prefixes=ONE,TWO,FOUR
 // RUN: %exploded_graph_rewriter --to=0x2 %s \
-// RUN: | FileCheck %s -check-prefixes=ONE,TWO,NOTHREE,NOFOUR
+// RUN: | FileCheck %s -check-prefixes=ONE,TWO
 // RUN: %exploded_graph_rewriter --to 2 %s \
-// RUN: | FileCheck %s -check-prefixes=ONE,TWO,NOTHREE,NOFOUR
+// RUN: | FileCheck %s -check-prefixes=ONE,TWO
 // RUN: %exploded_graph_rewriter --to 2,3 %s \
-// RUN: | FileCheck %s -check-prefixes=ONE,TWO,THREE,NOFOUR
+// RUN: | FileCheck %s -check-prefixes=ONE,TWO,THREE
 // RUN: %exploded_graph_rewriter --to 4 %s \
 // RUN: | FileCheck %s -check-prefixes=ONE,TWO,THREE,FOUR
 // RUN: %exploded_graph_rewriter --to 4 -s %s \
-// RUN: | FileCheck %s -check-prefixes=ONE,TWO,NOTHREE,FOUR
+// RUN: | FileCheck %s -check-prefixes=ONE,TWO,FOUR
 
 Node0x1 [shape=record,label=
  "{{ "state_id": 0, "program_state": null, "program_points": [
Index: clang/test/Analysis/cfg.c
===
--- clang/test/Analysis/cfg.c
+++ clang/test/Analysis/cfg.c
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -fheinous-gnu-extensions %s > %t 2>&1
-// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,WARNINGS %s
+// RUN: FileCheck --input-file=%t --check-prefix=CHECK %s
 
 // This file is the C version of cfg.cpp.
 // Tests that are C-specific should go into this file.
Index: clang/test/Analysis/cfg-rich-constructors.mm
===
--- clang/test/Analysis/cfg-rich-constructors.mm
+++ clang/test/Analysis/cfg-rich-constructors.mm
@@ -1,11 +1,11 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -std=c++11 -w %s > %t 2>&1
-// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX11,ELIDE,CXX11-ELIDE %s
+// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX11,CXX11-ELIDE %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -std=c++17 -w %s > %t 2>&1
-// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX17,ELIDE,CXX17-ELIDE %s
+// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX17 %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -std=c++11 -w -analyzer-config elide-constructors=false %s > %t 2>&1
-// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX11,NOELIDE,CXX11-NOELIDE %s
+// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX11,CXX11-NOELIDE %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -std=c++17 -w -analyzer-config elide-constructors=false %s > %t 2>&1
-// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX17,NOELIDE,CXX17-NOELIDE %s
+// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,CXX17 %s
 
 class D {
 public:
Index: clang/test/Analysis/cfg-rich-constructors.cpp
===
--- clang/test/Analysis/cfg-rich-constructors.cpp
+++ clang/test/Analysis/cfg-rich-constructors.cpp
@@ -1,11 +1,11 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple 

[PATCH] D94942: [clangd] Add tweak for implementing abstract class

2021-01-22 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ImplementAbstract.cpp:354
+  return "Implement pure virtual methods from '" +
+ FromBase->getType().getAsString() + "'";
+}

Maybe this should be changed as it currently prints the fully qualified type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94942

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


[PATCH] D92024: [clang] Implement P0692R1 from C++20 (access checking on specializations and instantiations)

2021-01-22 Thread Alex Orlov via Phabricator via cfe-commits
aorlov added a comment.

Please, look at my solution. Is it worth to be accepted?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92024

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


[PATCH] D94919: [clangd] Fix a crash when indexing invalid ObjC method declaration

2021-01-22 Thread David Goldman via Phabricator via cfe-commits
dgoldman accepted this revision.
dgoldman added a comment.
This revision is now accepted and ready to land.

In D94919#2515987 , @adamcz wrote:

> The crash happens while indexing the file, not during code completion. The 
> code completion tests generally specify a cursor position, but in this case 
> it is not relevant and could confuse the reader. This seemed like a logical 
> place for indexing bug, in the spirit of using minimal repro case (i.e. you 
> don't need to trigger code completion at all)

I see, thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94919

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


[PATCH] D94919: [clangd] Fix a crash when indexing invalid ObjC method declaration

2021-01-22 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added a comment.

The crash happens while indexing the file, not during code completion. The code 
completion tests generally specify a cursor position, but in this case it is 
not relevant and could confuse the reader. This seemed like a logical place for 
indexing bug, in the spirit of using minimal repro case (i.e. you don't need to 
trigger code completion at all)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94919

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


[PATCH] D94614: [FPEnv][X86] Platform builtins edition: clang should get from the AST the metadata for constrained FP builtins

2021-01-22 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn updated this revision to Diff 318567.
kpn added a comment.

Update for review comments: Move uses of CGFPOptionsRAII lower and closer to 
where they are needed. This should be less error prone as well.


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

https://reviews.llvm.org/D94614

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/X86/avx-builtins-constrained-cmp.c
  clang/test/CodeGen/X86/avx512dq-builtins-constrained.c
  clang/test/CodeGen/X86/avx512f-builtins-constrained.c
  clang/test/CodeGen/X86/fma-builtins-constrained.c
  clang/test/CodeGen/X86/sse-builtins-constrained.c

Index: clang/test/CodeGen/X86/sse-builtins-constrained.c
===
--- clang/test/CodeGen/X86/sse-builtins-constrained.c
+++ clang/test/CodeGen/X86/sse-builtins-constrained.c
@@ -1,8 +1,15 @@
 // REQUIRES: x86-registered-target
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-linux-gnu -target-feature +sse -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=UNCONSTRAINED --check-prefix=COMMON --check-prefix=COMMONIR
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-linux-gnu -target-feature +sse -ffp-exception-behavior=strict -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=CONSTRAINED --check-prefix=COMMON --check-prefix=COMMONIR
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-linux-gnu -target-feature +sse -ffp-exception-behavior=maytrap -DSTRICT=1 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=CONSTRAINED --check-prefix=COMMON --check-prefix=COMMONIR
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-linux-gnu -target-feature +sse -S %s -o - -Wall -Werror | FileCheck %s --check-prefix=CHECK-ASM --check-prefix=COMMON
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-linux-gnu -target-feature +sse -ffp-exception-behavior=strict -S %s -o - -Wall -Werror | FileCheck %s --check-prefix=CHECK-ASM --check-prefix=COMMON
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-linux-gnu -target-feature +sse -ffp-exception-behavior=maytrap -DSTRICT=1 -S %s -o - -Wall -Werror | FileCheck %s --check-prefix=CHECK-ASM --check-prefix=COMMON
+
+#ifdef STRICT
+// Test that the constrained intrinsics are picking up the exception
+// metadata from the AST instead of the global default from the command line.
+
+#pragma float_control(except, on)
+#endif
 
 
 #include 
Index: clang/test/CodeGen/X86/fma-builtins-constrained.c
===
--- clang/test/CodeGen/X86/fma-builtins-constrained.c
+++ clang/test/CodeGen/X86/fma-builtins-constrained.c
@@ -1,8 +1,15 @@
 // REQUIRES: x86-registered-target
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-linux-gnu -target-feature +fma -O2 -emit-llvm -o - | FileCheck %s --check-prefixes=COMMON,COMMONIR,UNCONSTRAINED
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-linux-gnu -target-feature +fma -ffp-exception-behavior=strict -O2 -emit-llvm -o - | FileCheck %s --check-prefixes=COMMON,COMMONIR,CONSTRAINED
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-linux-gnu -target-feature +fma -ffp-exception-behavior=maytrap -DSTRICT=1 -O2 -emit-llvm -o - | FileCheck %s --check-prefixes=COMMON,COMMONIR,CONSTRAINED
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-linux-gnu -target-feature +fma -O2 -S -o - | FileCheck %s --check-prefixes=COMMON,CHECK-ASM
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-linux-gnu -target-feature +fma -O2 -ffp-exception-behavior=strict -S -o - | FileCheck %s --check-prefixes=COMMON,CHECK-ASM
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-linux-gnu -target-feature +fma -O2 -ffp-exception-behavior=maytrap -DSTRICT=1 -S -o - | FileCheck %s --check-prefixes=COMMON,CHECK-ASM
+
+#ifdef STRICT
+// Test that the constrained intrinsics are picking up the exception
+// metadata from the AST instead of the global default from the command line.
+
+#pragma float_control(except, on)
+#endif
 
 #include 
 
Index: clang/test/CodeGen/X86/avx512f-builtins-constrained.c
===
--- clang/test/CodeGen/X86/avx512f-builtins-constrained.c
+++ clang/test/CodeGen/X86/avx512f-builtins-constrained.c
@@ -1,10 +1,17 @@
 // REQUIRES: x86-registered-target
 // RUN: %clang_cc1 -fexperimental-new-pass-manager -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux-gnu -target-feature +avx512f -emit-llvm -o - -Wall -Werror | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=UNCONSTRAINED %s
 // RUN: %clang_cc1 -fexperimental-new-pass-manager -flax-vector-conversions=none -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +avx512f -emit-llvm -o - -Wall -Werror | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=UNCONSTRAINED %s
-// RUN: %clang_cc1 

[PATCH] D95168: [clang-format] Add InsertBraces option

2021-01-22 Thread Tiago Macarios via Phabricator via cfe-commits
tiagoma updated this revision to Diff 318563.
tiagoma added a comment.

Update comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95168

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -14749,6 +14749,12 @@
   CHECK_PARSE("IndentExternBlock: false", IndentExternBlock,
   FormatStyle::IEBS_NoIndent);
 
+  Style.InsertBraces = FormatStyle::BIS_Never;
+  CHECK_PARSE("InsertBraces: Always", InsertBraces, FormatStyle::BIS_Always);
+  CHECK_PARSE("InsertBraces: WrapLikely", InsertBraces,
+  FormatStyle::BIS_WrapLikely);
+  CHECK_PARSE("InsertBraces: Never", InsertBraces, FormatStyle::BIS_Never);
+
   Style.BitFieldColonSpacing = FormatStyle::BFCS_None;
   CHECK_PARSE("BitFieldColonSpacing: Both", BitFieldColonSpacing,
   FormatStyle::BFCS_Both);
@@ -17890,6 +17896,105 @@
 "}",
 format(Source, Style));
 }
+
+TEST_F(FormatTest, InsertBraces) {
+  FormatStyle Style = getLLVMStyle();
+  StringRef IfSourceShort = "if (condition)\n"
+"  call_function(arg, arg);";
+  EXPECT_EQ(IfSourceShort, format(IfSourceShort, Style));
+
+  StringRef IfSourceLong = "if (condition)\n"
+   "  call_function(arg, arg, arg, arg, arg, arg);";
+  EXPECT_EQ(IfSourceLong, format(IfSourceLong, Style));
+
+  StringRef IfElseSourceShort = "if (condition)\n"
+"  a_function(arg, arg);\n"
+"else\n"
+"  another_function(arg, arg);";
+  EXPECT_EQ(IfElseSourceShort, format(IfElseSourceShort, Style));
+
+  StringRef IfElseSourceLong =
+  "if (condition)\n"
+  "  a_function(arg, arg, arg, arg, arg, arg);\n"
+  "else\n"
+  "  another_function(arg, arg, arg, arg, arg, arg);";
+  EXPECT_EQ(IfElseSourceLong, format(IfElseSourceLong, Style));
+
+  StringRef ForSourceShort = "for (auto val : container)\n"
+ "  call_function(arg, arg);";
+  EXPECT_EQ(ForSourceShort, format(ForSourceShort, Style));
+
+  StringRef ForSourceLong = "for (auto val : container)\n"
+"  call_function(arg, arg, arg, arg, arg, arg);";
+  EXPECT_EQ(ForSourceLong, format(ForSourceLong, Style));
+
+  Style.InsertBraces = FormatStyle::BIS_Always;
+
+  EXPECT_EQ("if (condition) {\n"
+"  call_function(arg, arg);\n"
+"}",
+format(IfSourceShort, Style));
+
+  EXPECT_EQ("if (condition) {\n"
+"  call_function(arg, arg, arg, arg, arg, arg);\n"
+"}",
+format(IfSourceLong, Style));
+
+  EXPECT_EQ("if (condition) {\n"
+"  a_function(arg, arg);\n"
+"} else {\n"
+"  another_function(arg, arg);\n"
+"}",
+format(IfElseSourceShort, Style));
+
+  EXPECT_EQ("if (condition) {\n"
+"  a_function(arg, arg, arg, arg, arg, arg);\n"
+"} else {\n"
+"  another_function(arg, arg, arg, arg, arg, arg);\n"
+"}",
+format(IfElseSourceLong, Style));
+
+  EXPECT_EQ("for (auto val : container) {\n"
+"  call_function(arg, arg);\n"
+"}",
+format(ForSourceShort, Style));
+
+  EXPECT_EQ("for (auto val : container) {\n"
+"  call_function(arg, arg, arg, arg, arg, arg);\n"
+"}",
+format(ForSourceLong, Style));
+
+  Style.InsertBraces = FormatStyle::BIS_WrapLikely;
+  Style.ColumnLimit = 35;
+
+  EXPECT_EQ(IfSourceShort, format(IfSourceShort, Style));
+
+  EXPECT_EQ("if (condition) {\n"
+"  call_function(arg, arg, arg, arg,\n"
+"arg, arg);\n"
+"}",
+format(IfSourceLong, Style));
+
+  EXPECT_EQ(IfElseSourceShort, format(IfElseSourceShort, Style));
+
+  EXPECT_EQ("if (condition) {\n"
+"  a_function(arg, arg, arg, arg,\n"
+" arg, arg);\n"
+"} else {\n"
+"  another_function(arg, arg, arg,\n"
+"   arg, arg, arg);\n"
+"}",
+format(IfElseSourceLong, Style));
+
+  EXPECT_EQ(ForSourceShort, format(ForSourceShort, Style));
+
+  EXPECT_EQ("for (auto val : container) {\n"
+"  call_function(arg, arg, arg, arg,\n"
+"arg, arg);\n"
+"}",
+format(ForSourceLong, Style));
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ 

Re: [PATCH] D70701: Fix more VFS tests on Windows

2021-01-22 Thread Adrian McCarthy via cfe-commits
BTW, I hope I didn't come across as overly negative in my previous
response.  I'd love to see the situation improved.  I just don't know what
that would look like.

> One thing I see, but wasn't obvious from your description, is that the
mixed/hybrid separator behaviour only happens for `defined(_WIN_32)`.
> [copy of `is_separator` elided]

It's a runtime decision based on the specified style, not a compile-time
one based on _WIN_32.  If the caller of `is_separator` passes
`Style::windows` then it'll accept either `/` or `\\`, even if LLVM was
compiled and run on Linux or Mac.  I believe there's a VFS test that
redirects a Windows-style path to a Posix-style one (an in-memory file
system), and that test passes on both kinds of hosts.

But I get the gist of the point.  My feeling is that, unless we can
eliminate hybrid styles, Paths should support a Style::hybrid.  It would be
messy because more ambiguities about how to map things crop up.

> Honestly, I'm not sure we have a good definition of what makeAbsolute
> should do.

I should have said:  **I** don't have a good understanding of what
makeAbsolute should do.  Even saying it should prepend the current working
directory is an incomplete answer.  On Windows, a process can have multiple
current directories:  one for each drive.  And a process has one current
drive.  So the current working directory is the current directory for the
current drive.  A Windows path like "D:foo.txt" is a relative path.
Literally prepending the current working directory gives us
`C:\users\me\D:foo.txt`, which is syntactically wrong.  But even if we're
smart enough to fix up the syntax, we'd get `C:\users\me\foo.txt` or
`D:\users\me\foo.txt`, both of which would (likely) be wrong.  The way the
OS would resolve it is to look up the process's current directory for the
D: drive, and insert that into the missing bit.

Anyway, I look forward to any and all proposals to improve this situation.


On Thu, Jan 21, 2021 at 6:47 PM Duncan P. N. Exon Smith via Phabricator <
revi...@reviews.llvm.org> wrote:

> dexonsmith added a comment.
>
> Thanks for the quick and detailed response!
>
> Your explanation of hybrid behaviour on Windows was especially helpful, as
> I didn't fully understand how that worked before.
>
> One thing I see, but wasn't obvious from your description, is that the
> mixed/hybrid separator behaviour only happens for `defined(_WIN_32)`. E.g.,
> from Path.cpp:
>
>   bool is_separator(char value, Style style) {
> if (value == '/')
>   return true;
> if (real_style(style) == Style::windows)
>   return value == '\\';
> return false;
>   }
>
>
>
> In D70701#2514143 , @amccarth
> wrote:
>
> >> - The path style is detected when reading the YAML file (as now).
> >
> > Which path's style?  The virtual one that's going to be redirected or the
> > actual one it's redirected at?
>
> Both, but you've mostly convinced me not to go down this route.
>
> > - Paths in the YAML file are canonicalized to native at parse time.
> >
> > If we canonicalize the virtual path, VFS would no longer be valuable for
> > creating platform-agnostic tests.
>
> This is a good point I hadn't considered.
>
> > In LLDB, we have the additional wrinkle of remote debugging, where the
> > debugger may be running on a Windows machine while the program being
> > debugged is running on a Linux box.  You always have to know whether a
> path
> > will be used on the debugger host or the debuggee host.  And there are
> > similar concerns for post-mortem debugging from a crash collected on a
> > different type of host.
>
> Ah, interesting.
>
> > Honestly, I'm not sure we have a good definition of what makeAbsolute
> > should do.
>
> Perhaps the name isn't ideal --
> `prependRelativePathsWithCurrentWorkingDirectory()` would be more precise
> -- but otherwise I'm not sure I fully agree. Regardless, I acknowledge your
> point that the two worlds are awkwardly different.
>
> I'm going to think about other options; thanks again for your feedback. I
> am still leaning toward `FileSystem::makeAbsolute()` not being virtual /
> overridden, but I have a better idea of how to approach that. One idea is
> for the `RedirectingFileSystem` to keep track of where different styles
> were used when parsing I'm not sure if that'll pan out though.
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D70701/new/
>
> https://reviews.llvm.org/D70701
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94844: [VFS] Add support to RedirectingFileSystem for mapping a virtual directory to one in the external FS.

2021-01-22 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

Overall this looks good. I wonder if abstracting the ExternalRedirect as a 
small wrapper class around a SmallString would help. There's a few operations 
that are repeated, like the example below, and it could also house the logic 
that's currently in the lambda.

  if (ExternalRedirect.empty()) {
assert(RE->getKind() == RedirectingFileSystem::EK_File);
ExternalRedirect = RE->getExternalContentsPath();
  }

One thing I found tricky during the review was differentiating between places 
where the ExternalRedirect was computed and uses. Looking at the signatures the 
`lookupPath` functions are computing it and `status` is consuming it, although 
the latter then changes the StringRef (which I guess shouldn't persist?). I 
don't know if the wrapper could alleviate this as well.




Comment at: llvm/include/llvm/Support/VirtualFileSystem.h:564
 ///
+/// Re-mapped directories are represented as
+/// /// \verbatim

I think we should expand on this a bit more to contrast a directory-remapped 
directory vs a file-remapped directory (for a lack of better term). 
Specifically, an empty file-remapped directory could be confusing, as it 
behaves quite differently but looks pretty similar in YAML. 

```
{
  'type': 'file',
  'name': ,
  'external-contents': 
}
```

```
{
  'type': 'directory',
  'name': ,
  'contents': []
}
```

Looking at the two, I wonder if there would be any benefit to changing the 
`type` in the yaml to match the `NameKind`.






Comment at: llvm/include/llvm/Support/VirtualFileSystem.h:624
+
+/// whether to use the external path as the name for this file or 
directory.
+bool useExternalName(bool GlobalUseExternalName) const {

nit: s/whether/Whether/



Comment at: llvm/include/llvm/Support/VirtualFileSystem.h:776-778
   /// Looks up \p Path in \c Roots.
-  ErrorOr lookupPath(const Twine ) const;
+  ErrorOr lookupPath(const Twine ,
+  SmallVectorImpl ) const;

dexonsmith wrote:
> It's not entirely clear what the extra parameters do / when they're filled in 
> / etc; can you add a bit more documentation?
> 
> Also, I see that the public caller ignores the `ExternalRedirect` parameter. 
> I wonder if this should be renamed to `lookupPathWithName` or 
> `lookupPathImpl`, leaving behind a `lookupPath` wrapper that creates the 
> ignored buffer for the public interface... no strong opinion though.
+1.


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

https://reviews.llvm.org/D94844

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


[PATCH] D95168: Add InsertBraces option

2021-01-22 Thread Tiago Macarios via Phabricator via cfe-commits
tiagoma added inline comments.



Comment at: clang/docs/ClangFormatStyleOptions.rst:2254
+
+  * ``BIS_WrapLikely`` (in configuration: ``WrapLikely``)
+Insert braces if wrapping is likely

curdeius wrote:
> Shouldn't it be consistent with clang-tidy? So instead of an enum, this 
> option might take a number of lines that will trigger brace insertion? None 
> may be sth like -1. "Likely" is very vague.
I am not sure this is possible. clang-tidy assumes the code is already 
formatted, we cannot assume that in clang-format. This pass runs before the 
formatter pass, so basing the behavior on line count would lead to different 
behavior across runs. For example:

Assuming we can set this option to 2 lines and we have the following code:


```
if (condition)
very_long_line_that_will_wrap(arg, arg, arg ,arg)
```

first run:


```
if (condition)
very_long_line_that_will_wrap(
arg, arg, arg ,arg)
```

second run:


```
if (condition) {
very_long_line_that_will_wrap(
arg, arg, arg ,arg)}
}
```

Likely is indeed vague by design. We "guess" that it will wrap in the formatter 
pass based on the current column value. See Format.cpp @ 1707. What might 
happen is that the line is incorrectly indentented and the wrapping never 
actually happens.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95168

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


[PATCH] D95246: [SystemZ][z/OS] Fix No such file or directory expression error matching in lit tests - continued

2021-01-22 Thread Muiez Ahmed via Phabricator via cfe-commits
muiez accepted this revision.
muiez 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/D95246/new/

https://reviews.llvm.org/D95246

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


[PATCH] D92808: [ObjC][ARC] Annotate calls with attributes instead of emitting retainRV or claimRV calls in the IR

2021-01-22 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: clang/lib/CodeGen/CGObjC.cpp:2342
+attrs = attrs.addAttribute(CGF.getLLVMContext(),
+   llvm::AttributeList::ReturnIndex, "rv_marker");
+callBase->setAttributes(attrs);

rjmccall wrote:
> ahatanak wrote:
> > rjmccall wrote:
> > > It's weird that these attributes use two different capitalization styles. 
> > >  Also, why are they both needed?  Did you consider making the role 
> > > (retain/claim) be the value of the attribute rather than a separate 
> > > attribute?
> > > 
> > > Should the attribute be namespaced, like `clang.arc.rv_marker`?
> > > 
> > > Let's go ahead and add globals for these strings so we can refer to them 
> > > symbolically, like you did with `retainRVMarkerKey`.  Is there an LLVM 
> > > header for ARC optimization we could reasonably pull them from, or are we 
> > > doomed to repeat ourselves across projects?
> > I think you are asking why both `retain/claim` and `rv_marker` are needed? 
> > Or are you asking why both 'retain' and 'claim' are needed?
> > 
> > We could do without `clang.arc.rv_marker` and just use 
> > `clang.arc.rv=retain/claim` since the middle-end and backend passes can 
> > easily determine whether a marker is needed or not. The only drawback to 
> > using only `clang.arc.rv` I can think of is that it's no longer possible to 
> > tell whether an instruction is implicitly followed by marker+retain/claimRV 
> > or just the marker, which makes `Instruction::mayWriteToMemory` return a 
> > conservative answer if the function call is read-only. A read-only call 
> > cannot be treated as read-only if it's followed by marker+retain/claimRV, 
> > but it is still read-only if it is followed just by the marker.
> > 
> > Note that ARC contract pass emits the retain/claimRV instruction into the 
> > IR and drops the corresponding `clang.arc.rv` attribute but doesn't remove 
> > the `clang.arc.rv_marker` attribute. So if we used only `clang.arc.rv`, a 
> > call annotated with the attribute would be implicitly followed by 
> > marker+retain/claimRV before ARC contract, while it would be followed by 
> > just the marker after ARC contract, but `Instruction::mayWriteToMemory` 
> > wouldn't' be able to tell the difference.
> > I think you are asking why both retain/claim and rv_marker are needed?
> 
> Yes.
> 
> > We could do without clang.arc.rv_marker and just use 
> > clang.arc.rv=retain/claim since the middle-end and backend passes can 
> > easily determine whether a marker is needed or not. The only drawback to 
> > using only clang.arc.rv I can think of is that it's no longer possible to 
> > tell whether an instruction is implicitly followed by marker+retain/claimRV 
> > or just the marker, which makes Instruction::mayWriteToMemory return a 
> > conservative answer if the function call is read-only. A read-only call 
> > cannot be treated as read-only if it's followed by marker+retain/claimRV, 
> > but it is still read-only if it is followed just by the marker.
> 
> Is there a situation where we emit the marker but not a following call?  Or 
> is that just in the places where we've already made the following call 
> explicit in IR?  Because in the latter case, presumably the following call 
> will still act as a barrier to anything that's querying `mayWriteToMemory`, 
> right?  (That is: in general, I expect that nobody just asks whether a 
> specific instruction can write to memory, they ask if any of the instructions 
> in a region can write to memory, and since the following call can...)
I think you are right. The retainRV/claimRV instruction that follows the 
annotated call will act as a barrier, so using `clang.arc.rv_marker` to 
distinguish between marker+retain/claimRV and marker only probably won't help 
the optimizations in practice.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92808

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


[PATCH] D95246: [SystemZ][z/OS] Fix No such file or directory expression error matching in lit tests - continued

2021-01-22 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan created this revision.
abhina.sreeskantharajan added reviewers: fanbo-meng, anirudhp, muiez, Kai, 
yusra.syeda.
Herald added subscribers: rupprecht, steven_wu, hiraditya, sbc100.
Herald added a reviewer: alexshap.
Herald added a reviewer: rupprecht.
Herald added a reviewer: jhenderson.
abhina.sreeskantharajan requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay, aheejin.
Herald added projects: clang, LLVM.

This is a continuation of https://reviews.llvm.org/D94239. I missed some other 
spellings of the same error.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95246

Files:
  clang/test/Driver/clang-offload-bundler.c
  clang/test/Frontend/output-failures.c
  llvm/test/Object/archive-extract-dir.test
  llvm/test/Object/archive-extract.test
  llvm/test/Object/directory.ll
  llvm/test/tools/llvm-ar/error-opening-directory.test
  llvm/test/tools/llvm-ar/move.test
  llvm/test/tools/llvm-ar/print.test
  llvm/test/tools/llvm-ar/quick-append.test
  llvm/test/tools/llvm-libtool-darwin/invalid-input-output-args.test
  llvm/test/tools/llvm-lipo/create-arch.test
  llvm/test/tools/llvm-lipo/replace-invalid-input.test
  llvm/test/tools/llvm-lto/error.ll
  llvm/test/tools/llvm-objcopy/wasm/dump-section.test
  llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test

Index: llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test
===
--- llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test
+++ llvm/test/tools/llvm-symbolizer/pdb/missing_pdb.test
@@ -4,7 +4,7 @@
 
 llvm-symbolizer should print one error and two unknown line info records.
 
-ERROR: LLVMSymbolizer: error reading file: {{.*}}: {{N|n}}o such file or directory
+ERROR: LLVMSymbolizer: error reading file: {{.*}}: {{.*}}{{N|n}}o such file or directory
 ERROR-NOT: error reading file
 
 CHECK: ??
Index: llvm/test/tools/llvm-objcopy/wasm/dump-section.test
===
--- llvm/test/tools/llvm-objcopy/wasm/dump-section.test
+++ llvm/test/tools/llvm-objcopy/wasm/dump-section.test
@@ -11,7 +11,7 @@
 # CHECK: 020 63 6c 61 6e 67 05 39 2e 30 2e 30
 
 # NONEXISTENT: section 'nonexistent' not found
-# DIROUT: error: {{.*}}/bar': {{[nN]}}o such file or directory
+# DIROUT: error: {{.*}}/bar': {{.*}}{{[nN]}}o such file or directory
 
 ## Check that dumping and removing a section works in the same invocation
 # RUN: llvm-objcopy --dump-section=producers=%t.sec --remove-section=producers %t %t2
Index: llvm/test/tools/llvm-lto/error.ll
===
--- llvm/test/tools/llvm-lto/error.ll
+++ llvm/test/tools/llvm-lto/error.ll
@@ -1,5 +1,5 @@
 ; RUN: not llvm-lto foobar 2>&1 | FileCheck %s
-; CHECK: llvm-lto: error loading file 'foobar': {{N|n}}o such file or directory
+; CHECK: llvm-lto: error loading file 'foobar': {{.*}}{{N|n}}o such file or directory
 
 ; RUN: not llvm-lto --list-symbols-only %S/Inputs/empty.bc 2>&1 | FileCheck %s --check-prefix=CHECK-LIST
 ; CHECK-LIST: llvm-lto: error loading file '{{.*}}/Inputs/empty.bc': The file was not recognized as a valid object file
Index: llvm/test/tools/llvm-lipo/replace-invalid-input.test
===
--- llvm/test/tools/llvm-lipo/replace-invalid-input.test
+++ llvm/test/tools/llvm-lipo/replace-invalid-input.test
@@ -12,7 +12,7 @@
 # INPUT_ARGS: error: replace expects a single input file
 
 # RUN: not llvm-lipo %t-universal.o -replace i386 %t-33.o  -o %t.o 2>&1 | FileCheck --check-prefix=INVALID_FILE %s
-# INVALID_FILE: {{[nN]}}o such file or directory
+# INVALID_FILE: {{.*}}{{[nN]}}o such file or directory
 
 # RUN: not llvm-lipo %t-universal.o -replace i3866 %t-32.o -o %t.o 2>&1 | FileCheck --check-prefix=INVALID_ARCH %s
 # INVALID_ARCH: error: Invalid architecture: i3866
Index: llvm/test/tools/llvm-lipo/create-arch.test
===
--- llvm/test/tools/llvm-lipo/create-arch.test
+++ llvm/test/tools/llvm-lipo/create-arch.test
@@ -14,4 +14,4 @@
 # INVALID_ARCH: error: Invalid architecture: i3866
 #
 # RUN: not llvm-lipo -arch i386 %t-33.o -create -o /dev/null 2>&1 | FileCheck --check-prefix=INVALID_FILE %s
-# INVALID_FILE: {{[nN]}}o such file or directory
+# INVALID_FILE: {{.*}}{{[nN]}}o such file or directory
Index: llvm/test/tools/llvm-libtool-darwin/invalid-input-output-args.test
===
--- llvm/test/tools/llvm-libtool-darwin/invalid-input-output-args.test
+++ llvm/test/tools/llvm-libtool-darwin/invalid-input-output-args.test
@@ -28,7 +28,7 @@
 # RUN: not llvm-libtool-darwin -static -o %t.lib %t.missing 2>&1 | \
 # RUN:   FileCheck %s --check-prefix=NO-FILE -DFILE=%t.missing
 
-# NO-FILE: error: '[[FILE]]': {{[nN]}}o such file or directory
+# NO-FILE: error: '[[FILE]]': {{.*}}{{[nN]}}o such file or directory
 

[PATCH] D92191: [clang-scan-deps] Add support for clang-cl

2021-01-22 Thread Sylvain Audi via Phabricator via cfe-commits
saudi updated this revision to Diff 318553.
saudi marked an inline comment as done.
saudi added a comment.

Applied the suggestions from the parent patch D95099 



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

https://reviews.llvm.org/D92191

Files:
  clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
  clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
  clang/test/ClangScanDeps/Inputs/headerwithdirname.json
  clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
  clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
  clang/test/ClangScanDeps/Inputs/no-werror.json
  clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json
  clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
  clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
  clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
  clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
  clang/test/ClangScanDeps/error.cpp
  clang/test/ClangScanDeps/has_include_if_elif.cpp
  clang/test/ClangScanDeps/header_stat_before_open.m
  clang/test/ClangScanDeps/headerwithdirname.cpp
  clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules.cpp
  clang/test/ClangScanDeps/no-werror.cpp
  clang/test/ClangScanDeps/regular_cdb.cpp
  clang/test/ClangScanDeps/static-analyzer.c
  clang/test/ClangScanDeps/strip_diag_serialize.cpp
  clang/test/ClangScanDeps/target-filename.cpp
  clang/test/ClangScanDeps/vfsoverlay.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -12,6 +12,8 @@
 #include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
 #include "clang/Tooling/JSONCompilationDatabase.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/InitLLVM.h"
@@ -49,7 +51,8 @@
   /// option and cache the results for reuse. \returns resource directory path
   /// associated with the given invocation command or empty string if the
   /// compiler path is NOT an absolute path.
-  StringRef findResourceDir(const tooling::CommandLineArguments ) {
+  StringRef findResourceDir(const tooling::CommandLineArguments ,
+bool ClangCLMode) {
 if (Args.size() < 1)
   return "";
 
@@ -65,8 +68,12 @@
 if (CachedResourceDir != Cache.end())
   return CachedResourceDir->second;
 
-std::vector PrintResourceDirArgs{ClangBinaryName,
-"-print-resource-dir"};
+std::vector PrintResourceDirArgs{ClangBinaryName};
+if (ClangCLMode)
+  PrintResourceDirArgs.push_back("/clang:-print-resource-dir");
+else
+  PrintResourceDirArgs.push_back("-print-resource-dir");
+
 llvm::SmallString<64> OutputFile, ErrorFile;
 llvm::sys::fs::createTemporaryFile("print-resource-dir-output",
"" /*no-suffix*/, OutputFile);
@@ -421,27 +428,55 @@
 bool HasMQ = false;
 bool HasMD = false;
 bool HasResourceDir = false;
+bool ClangCLMode = false;
 auto FlagsEnd = llvm::find(Args, "--");
 
 // We need to find the last -o value.
 if (FlagsEnd != Args.begin()) {
+  ClangCLMode =
+  llvm::sys::path::stem(Args[0]).contains_lower("clang-cl") ||
+  llvm::is_contained(Args, "--driver-mode=cl");
+
   // Reverse scan, starting at the end or at the element before "--".
   for (auto RB = llvm::make_reverse_iterator(FlagsEnd), RI = RB,
 RE = Args.rend();
RI != RE; ++RI) {
 StringRef Arg = *RI;
-if (LastO.empty()) {
-  if (Arg == "-o" && RI != RB)
-LastO = RI[-1]; // Next argument (reverse iterator)
-  else if (Arg.startswith("-o"))
-LastO = Arg.drop_front(2).str();
+if (ClangCLMode) {
+  if (LastO.empty()) {
+// With clang-cl, the output obj file can be specified with
+// "/opath", "/o path", "/Fopath", and the dash counterparts.
+// Also, clang-cl adds ".obj" extension if none is found.
+if ((Arg == "-o" || Arg == "/o") && RI != RB)
+  LastO = RI[-1]; // Next argument (reverse iterator)
+else if (Arg.startswith("/Fo") || Arg.startswith("-Fo"))
+  LastO = Arg.drop_front(3).str();
+else if (Arg.startswith("/o") || Arg.startswith("-o"))
+  LastO = Arg.drop_front(2).str();
+
+if 

[PATCH] D94919: [clangd] Fix a crash when indexing invalid ObjC method declaration

2021-01-22 Thread David Goldman via Phabricator via cfe-commits
dgoldman requested changes to this revision.
dgoldman added a comment.
This revision now requires changes to proceed.

Looks good but I think for posterity we should add a similar test to 
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp for the exact intended 
code complete behavior (or instead of SymbolCollectorTests.cpp - is there a 
particular reason you added a test there)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94919

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


[PATCH] D94942: [clangd] Add tweak for implementing abstract class

2021-01-22 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 318552.
njames93 added a comment.

If cursor is over one of the base specifiers, offer to implement only the pure 
methods from that base class.
Depends on D95231 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94942

Files:
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ImplementAbstract.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/tweaks/ImplementAbstractTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/ImplementAbstractTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/tweaks/ImplementAbstractTests.cpp
@@ -0,0 +1,391 @@
+//===-- ImplementAbstractTests.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 "TestTU.h"
+#include "TweakTesting.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using ::testing::Not;
+
+namespace clang {
+namespace clangd {
+namespace {
+
+TWEAK_TEST(ImplementAbstract);
+
+TEST_F(ImplementAbstractTest, TestUnavailable) {
+
+  StringRef Cases[]{
+  // Not a pure virtual method.
+  R"cpp(
+  class A {
+virtual void Foo();
+  };
+  class ^B : public A {};
+)cpp",
+  // Pure virtual method overridden in class.
+  R"cpp(
+  class A {
+virtual void Foo() = 0;
+  };
+  class ^B : public A {
+void Foo() override;
+  };
+)cpp",
+  // Pure virtual method overridden in class with virtual keyword
+  R"cpp(
+  class A {
+virtual void Foo() = 0;
+  };
+  class ^B : public A {
+virtual void Foo() override;
+  };
+)cpp",
+  // Pure virtual method overridden in class without override keyword
+  R"cpp(
+  class A {
+virtual void Foo() = 0;
+  };
+  class ^B : public A {
+void Foo();
+  };
+)cpp",
+  // Pure virtual method overriden in base class.
+  R"cpp(
+  class A {
+virtual void Foo() = 0;
+  };
+  class B : public A {
+void Foo() override;
+  };
+  class ^C : public B {
+  };
+)cpp"};
+  for (const auto  : Cases) {
+EXPECT_THAT(Case, Not(isAvailable()));
+  }
+}
+
+TEST_F(ImplementAbstractTest, NormalAvailable) {
+  struct Case {
+llvm::StringRef TestHeader;
+llvm::StringRef TestSource;
+llvm::StringRef ExpectedSource;
+  };
+
+  Case Cases[]{
+  {
+  R"cpp(
+class A {
+  virtual void Foo() = 0;
+};)cpp",
+  R"cpp(
+class B : public A {^};
+  )cpp",
+  R"cpp(
+class B : public A {
+  void Foo() override;
+  };
+  )cpp",
+  },
+  {
+  R"cpp(
+class A {
+  public:
+  virtual void Foo() = 0;
+};)cpp",
+  R"cpp(
+class ^B : public A {};
+  )cpp",
+  R"cpp(
+class B : public A {
+  public:
+
+  void Foo() override;
+  };
+  )cpp",
+  },
+  {
+  R"cpp(
+class A {
+  virtual void Foo(int Param) = 0;
+};)cpp",
+  R"cpp(
+class ^B : public A {};
+  )cpp",
+  R"cpp(
+class B : public A {
+  void Foo(int Param) override;
+  };
+  )cpp",
+  },
+  {
+  R"cpp(
+class A {
+  virtual void Foo(int Param) = 0;
+};)cpp",
+  R"cpp(
+struct ^B : public A {};
+  )cpp",
+  R"cpp(
+struct B : public A {
+  private:
+
+  void Foo(int Param) override;
+  };
+  )cpp",
+  },
+  {
+  R"cpp(
+class A {
+  virtual void Foo(int Param) const volatile = 0;
+  public:
+  virtual void Bar(int Param) = 0;
+};)cpp",
+  R"cpp(
+class ^B : public A {
+  void Foo(int Param) const volatile override;
+};
+  )cpp",
+  R"cpp(
+class B : public A {
+  void Foo(int Param) const volatile override;
+
+  public:
+
+  void Bar(int Param) override;
+  };
+  )cpp",
+  },
+  {
+  R"cpp(
+ class A {
+  virtual void Foo() = 0;
+  virtual void Bar() = 0;
+};
+class B : public A {
+  void Foo() 

[PATCH] D95002: [RISCV] Update B extension version to 0.93.

2021-01-22 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 318548.
craig.topper added a comment.

Remove reference to version from the rori comment. The version doesn't really 
matter, I doubt the encoding will ever be added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95002

Files:
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Target/RISCV/RISCVInstrInfoB.td


Index: llvm/lib/Target/RISCV/RISCVInstrInfoB.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfoB.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfoB.td
@@ -7,7 +7,7 @@
 
//===--===//
 //
 // This file describes the RISC-V instructions from the standard 'B' Bitmanip
-// extension, version 0.92.
+// extension, version 0.93.
 // This version is still experimental as the 'B' extension hasn't been
 // ratified yet.
 //
@@ -728,8 +728,8 @@
   (SROI GPR:$rs1, uimmlog2xlen:$shamt)>;
 } // Predicates = [HasStdExtZbp]
 
-// There's no encoding for roli in the current version of the 'B' extension
-// (v0.92) as it can be implemented with rori by negating the immediate.
+// There's no encoding for roli in the the 'B' extension as it can be
+// implemented with rori by negating the immediate.
 let Predicates = [HasStdExtZbbOrZbp] in {
 def : Pat<(rotr GPR:$rs1, uimmlog2xlen:$shamt),
   (RORI GPR:$rs1, uimmlog2xlen:$shamt)>;
Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -49,9 +49,9 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s
 // CHECK-C-EXT: __riscv_compressed 1
 
-// RUN: %clang -target riscv32-unknown-linux-gnu 
-menable-experimental-extensions -march=rv32ib0p92 -x c -E -dM %s \
+// RUN: %clang -target riscv32-unknown-linux-gnu 
-menable-experimental-extensions -march=rv32ib0p93 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
-// RUN: %clang -target riscv64-unknown-linux-gnu 
-menable-experimental-extensions -march=rv64ib0p92 -x c -E -dM %s \
+// RUN: %clang -target riscv64-unknown-linux-gnu 
-menable-experimental-extensions -march=rv64ib0p93 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
 // CHECK-B-EXT: __riscv_bitmanip 1
 
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -343,7 +343,7 @@
 // RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32ib0p1'
 // RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.1 for experimental 
extension
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32ib0p92 
-menable-experimental-extensions -### %s \
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ib0p93 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-GOODVERS %s
 // RV32-EXPERIMENTAL-GOODVERS: "-target-feature" "+experimental-b"
 
@@ -352,20 +352,20 @@
 // RV32-EXPERIMENTAL-ZBB-NOFLAG: error: invalid arch name 'rv32izbb'
 // RV32-EXPERIMENTAL-ZBB-NOFLAG: requires '-menable-experimental-extensions'
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p92 
-menable-experimental-extensions -### %s \
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p93 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBB %s
 // RV32-EXPERIMENTAL-ZBB: "-target-feature" "+experimental-zbb"
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p92_zbp0p92 
-menable-experimental-extensions -### %s \
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p93_zbp0p93 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP 
%s
 // RV32-EXPERIMENTAL-ZBB-ZBP: "-target-feature" "+experimental-zbb"
 // RV32-EXPERIMENTAL-ZBB-ZBP: "-target-feature" "+experimental-zbp"
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p92zbp0p92 
-menable-experimental-extensions -### %s \
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p93zbp0p93 
-menable-experimental-extensions -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE %s
-// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 
'rv32izbb0p92zbp0p92', multi-character extensions must be separated by 
underscores
+// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 
'rv32izbb0p93zbp0p93', multi-character extensions must be separated by 
underscores
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32izba0p92 

[PATCH] D95244: [clang][AST] Handle overload callee type in CallExpr::getCallReturnType.

2021-01-22 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Should add some responsible (for this code) reviewers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95244

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


[PATCH] D95244: [clang][AST] Handle overload callee type in CallExpr::getCallReturnType.

2021-01-22 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: martong, gamesh411, Szelethus, dkrupp.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Type of `Callee` can be overloaded function type that was not handled.
This causes a crash if the function is called in such case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95244

Files:
  clang/lib/AST/Expr.cpp


Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -1392,6 +1392,11 @@
 
 // This should never be overloaded and so should never return null.
 CalleeType = Expr::findBoundMemberType(Callee);
+  } else if (CalleeType->isSpecificPlaceholderType(BuiltinType::Overload)) {
+ASTContext::GetBuiltinTypeError Error;
+QualType RetTy = Ctx.GetBuiltinType(BuiltinType::Dependent, Error);
+assert(Error == ASTContext::GE_None);
+return RetTy;
   }
 
   const FunctionType *FnType = CalleeType->castAs();


Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -1392,6 +1392,11 @@
 
 // This should never be overloaded and so should never return null.
 CalleeType = Expr::findBoundMemberType(Callee);
+  } else if (CalleeType->isSpecificPlaceholderType(BuiltinType::Overload)) {
+ASTContext::GetBuiltinTypeError Error;
+QualType RetTy = Ctx.GetBuiltinType(BuiltinType::Dependent, Error);
+assert(Error == ASTContext::GE_None);
+return RetTy;
   }
 
   const FunctionType *FnType = CalleeType->castAs();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94814: [HIP] Support `__managed__` attribute

2021-01-22 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
yaxunl marked 2 inline comments as done.
Closed by commit rG622eaa4a4cea: [HIP] Support __managed__ attribute (authored 
by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D94814?vs=318243=318537#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94814

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CGCUDARuntime.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/AST/Inputs/cuda.h
  clang/test/AST/ast-dump-managed-var.cu
  clang/test/CodeGenCUDA/Inputs/cuda.h
  clang/test/CodeGenCUDA/managed-var.cu
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaCUDA/Inputs/cuda.h
  clang/test/SemaCUDA/bad-attributes.cu
  clang/test/SemaCUDA/device-var-init.cu
  clang/test/SemaCUDA/function-overload.cu
  clang/test/SemaCUDA/managed-var.cu
  clang/test/SemaCUDA/union-init.cu
  llvm/include/llvm/IR/ReplaceConstant.h
  llvm/lib/IR/CMakeLists.txt
  llvm/lib/IR/ReplaceConstant.cpp
  llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp

Index: llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp
===
--- llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp
+++ llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp
@@ -21,6 +21,7 @@
 #include "llvm/IR/IntrinsicsXCore.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/NoFolder.h"
+#include "llvm/IR/ReplaceConstant.h"
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CommandLine.h"
@@ -74,57 +75,6 @@
   return ConstantArray::get(NewType, Elements);
 }
 
-static Instruction *
-createReplacementInstr(ConstantExpr *CE, Instruction *Instr) {
-  IRBuilder Builder(Instr);
-  unsigned OpCode = CE->getOpcode();
-  switch (OpCode) {
-case Instruction::GetElementPtr: {
-  SmallVector CEOpVec(CE->operands());
-  ArrayRef CEOps(CEOpVec);
-  return dyn_cast(Builder.CreateInBoundsGEP(
-  cast(CE)->getSourceElementType(), CEOps[0],
-  CEOps.slice(1)));
-}
-case Instruction::Add:
-case Instruction::Sub:
-case Instruction::Mul:
-case Instruction::UDiv:
-case Instruction::SDiv:
-case Instruction::FDiv:
-case Instruction::URem:
-case Instruction::SRem:
-case Instruction::FRem:
-case Instruction::Shl:
-case Instruction::LShr:
-case Instruction::AShr:
-case Instruction::And:
-case Instruction::Or:
-case Instruction::Xor:
-  return dyn_cast(
-  Builder.CreateBinOp((Instruction::BinaryOps)OpCode,
-  CE->getOperand(0), CE->getOperand(1),
-  CE->getName()));
-case Instruction::Trunc:
-case Instruction::ZExt:
-case Instruction::SExt:
-case Instruction::FPToUI:
-case Instruction::FPToSI:
-case Instruction::UIToFP:
-case Instruction::SIToFP:
-case Instruction::FPTrunc:
-case Instruction::FPExt:
-case Instruction::PtrToInt:
-case Instruction::IntToPtr:
-case Instruction::BitCast:
-  return dyn_cast(
-  Builder.CreateCast((Instruction::CastOps)OpCode,
- CE->getOperand(0), CE->getType(),
- CE->getName()));
-default:
-  llvm_unreachable("Unhandled constant expression!\n");
-  }
-}
 
 static bool replaceConstantExprOp(ConstantExpr *CE, Pass *P) {
   do {
Index: llvm/lib/IR/ReplaceConstant.cpp
===
--- /dev/null
+++ llvm/lib/IR/ReplaceConstant.cpp
@@ -0,0 +1,70 @@
+//===- ReplaceConstant.cpp - Replace LLVM constant expression--===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements a utility function for replacing LLVM constant
+// expressions by instructions.
+//
+//===--===//
+
+#include "llvm/IR/ReplaceConstant.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/NoFolder.h"
+
+namespace llvm {
+// Replace a constant expression by instructions with equivalent operations at
+// a specified location.
+Instruction *createReplacementInstr(ConstantExpr *CE, Instruction *Instr) {
+  IRBuilder Builder(Instr);
+  unsigned OpCode = CE->getOpcode();
+  switch (OpCode) {
+  case Instruction::GetElementPtr: {
+SmallVector CEOpVec(CE->operands());
+ArrayRef 

[clang] 622eaa4 - [HIP] Support __managed__ attribute

2021-01-22 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-01-22T11:43:58-05:00
New Revision: 622eaa4a4cea17c2cec6942d9702b010deae392b

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

LOG: [HIP] Support __managed__ attribute

This patch implements codegen for __managed__ variable attribute for HIP.

Diagnostics will be added later.

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

Added: 
clang/test/AST/Inputs/cuda.h
clang/test/AST/ast-dump-managed-var.cu
clang/test/CodeGenCUDA/managed-var.cu
clang/test/SemaCUDA/managed-var.cu
llvm/include/llvm/IR/ReplaceConstant.h
llvm/lib/IR/ReplaceConstant.cpp

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/CodeGen/CGCUDARuntime.h
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CodeGenCUDA/Inputs/cuda.h
clang/test/Misc/pragma-attribute-supported-attributes-list.test
clang/test/SemaCUDA/Inputs/cuda.h
clang/test/SemaCUDA/bad-attributes.cu
clang/test/SemaCUDA/device-var-init.cu
clang/test/SemaCUDA/function-overload.cu
clang/test/SemaCUDA/union-init.cu
llvm/lib/IR/CMakeLists.txt
llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b30b91d3d4a6..bfd50f6a6779 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -324,6 +324,7 @@ class LangOpt {
 def MicrosoftExt : LangOpt<"MicrosoftExt">;
 def Borland : LangOpt<"Borland">;
 def CUDA : LangOpt<"CUDA">;
+def HIP : LangOpt<"HIP">;
 def SYCL : LangOpt<"SYCLIsDevice">;
 def COnly : LangOpt<"", "!LangOpts.CPlusPlus">;
 def CPlusPlus : LangOpt<"CPlusPlus">;
@@ -1115,6 +1116,13 @@ def CUDAHost : InheritableAttr {
   let Documentation = [Undocumented];
 }
 
+def HIPManaged : InheritableAttr {
+  let Spellings = [GNU<"managed">, Declspec<"__managed__">];
+  let Subjects = SubjectList<[Var]>;
+  let LangOpts = [HIP];
+  let Documentation = [HIPManagedAttrDocs];
+}
+
 def CUDAInvalidTarget : InheritableAttr {
   let Spellings = [];
   let Subjects = SubjectList<[Function]>;

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fffede41db1e..170a0fe3d4c4 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5419,6 +5419,17 @@ unbind runtime APIs.
   }];
 }
 
+def HIPManagedAttrDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+The ``__managed__`` attribute can be applied to a global variable declaration 
in HIP.
+A managed variable is emitted as an undefined global symbol in the device 
binary and is
+registered by ``__hipRegisterManagedVariable`` in init functions. The HIP 
runtime allocates
+managed memory and uses it to define the symbol when loading the device binary.
+A managed variable can be accessed in both device and host code.
+  }];
+}
+
 def LifetimeOwnerDocs : Documentation {
   let Category = DocCatDecl;
   let Content = [{

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 758b2ed3e90b..67c59f3ca09a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8237,7 +8237,7 @@ def err_cuda_device_exceptions : Error<
   "%select{__device__|__global__|__host__|__host__ __device__}1 function">;
 def err_dynamic_var_init : Error<
 "dynamic initialization is not supported for "
-"__device__, __constant__, and __shared__ variables.">;
+"__device__, __constant__, __shared__, and __managed__ variables.">;
 def err_shared_var_init : Error<
 "initialization is not supported for __shared__ variables.">;
 def err_cuda_vla : Error<
@@ -8247,7 +8247,8 @@ def err_cuda_extern_shared : Error<"__shared__ variable 
%0 cannot be 'extern'">;
 def err_cuda_host_shared : Error<
 "__shared__ local variables not allowed in "
 "%select{__device__|__global__|__host__|__host__ __device__}0 functions">;
-def err_cuda_nonstatic_constdev: Error<"__constant__ and __device__ are not 
allowed on non-static local variables">;
+def err_cuda_nonstatic_constdev: Error<"__constant__, __device__, and "
+"__managed__ are not allowed on non-static local variables">;
 def err_cuda_ovl_target : Error<
   "%select{__device__|__global__|__host__|__host__ __device__}0 function %1 "
   "cannot overload %select{__device__|__global__|__host__|__host__ 
__device__}2 function %3">;

diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 7c5ab39a85ec..33a2d6f4483e 100644
--- 

[PATCH] D95145: [clang] Fix a nullptr dereference bug on invalid code

2021-01-22 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added a comment.

PTAL




Comment at: clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp:2
+// RUN: %clang -fsyntax-only -std=c++17 %s -Xclang -verify
+#include 
+

adamcz wrote:
> hokein wrote:
> > A common practice is to avoid depending on STL in tests. I think we need to 
> > pull out (even simplify?) std::result_of implementation if it is needed for 
> > reproducing the crash.
> I've noticed that pattern, but can't tell why this is. Is it documented 
> somewhere?
> 
Anyway, I updated the change to not require type_traits. Turned out to be 
simpler than expected ;-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95145

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


[PATCH] D95145: [clang] Fix a nullptr dereference bug on invalid code

2021-01-22 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz updated this revision to Diff 318534.
adamcz added a comment.

addressed review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95145

Files:
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp


Index: clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang -fsyntax-only -std=c++17 %s -Xclang -verify
+
+// The important part is that we do not crash.
+
+template T declval();
+
+template 
+auto Call(T x) -> decltype(declval()(0)) {} // expected-note{{candidate 
template ignored}}
+
+class Status {};
+
+void fun() {
+  // The Status() (instead of Status) here used to cause a crash.
+  Call([](auto x) -> Status() {}); // expected-error{{function cannot return 
function type 'Status ()}}
+  // expected-error@-1{{no matching function for call to 'Call'}}
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4189,6 +4189,9 @@
   for (unsigned OldIdx = 0, NumOldParams = OldProtoLoc.getNumParams();
OldIdx != NumOldParams; ++OldIdx) {
 ParmVarDecl *OldParam = OldProtoLoc.getParam(OldIdx);
+if (!OldParam)
+  return nullptr;
+
 LocalInstantiationScope *Scope = SemaRef.CurrentInstantiationScope;
 
 Optional NumArgumentsInExpansion;


Index: clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang -fsyntax-only -std=c++17 %s -Xclang -verify
+
+// The important part is that we do not crash.
+
+template T declval();
+
+template 
+auto Call(T x) -> decltype(declval()(0)) {} // expected-note{{candidate template ignored}}
+
+class Status {};
+
+void fun() {
+  // The Status() (instead of Status) here used to cause a crash.
+  Call([](auto x) -> Status() {}); // expected-error{{function cannot return function type 'Status ()}}
+  // expected-error@-1{{no matching function for call to 'Call'}}
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4189,6 +4189,9 @@
   for (unsigned OldIdx = 0, NumOldParams = OldProtoLoc.getNumParams();
OldIdx != NumOldParams; ++OldIdx) {
 ParmVarDecl *OldParam = OldProtoLoc.getParam(OldIdx);
+if (!OldParam)
+  return nullptr;
+
 LocalInstantiationScope *Scope = SemaRef.CurrentInstantiationScope;
 
 Optional NumArgumentsInExpansion;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94814: [HIP] Support `__managed__` attribute

2021-01-22 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8245
 "%select{__device__|__global__|__host__|__host__ __device__}0 functions">;
-def err_cuda_nonstatic_constdev: Error<"__constant__ and __device__ are not 
allowed on non-static local variables">;
+def err_cuda_nonstatic_constdev: Error<"__constant__, __device__, and 
__managed__ are not allowed on non-static local variables">;
 def err_cuda_ovl_target : Error<

aaron.ballman wrote:
> Since we're modifying this line anyway, can you wrap it for the 80-col limit?
will fix when committing



Comment at: clang/test/SemaCUDA/managed-var.cu:45
+__managed__ A a;
+// expected-error@-1 {{dynamic initialization is not supported for __device__, 
__constant__, __shared__, and __managed__ variables}}

aaron.ballman wrote:
> I think you're missing tests that check that the new managed attribute 
> accepts no arguments and that it doesn't apply to things other than variables 
> (like a function declaration).
will add tests when committing


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

https://reviews.llvm.org/D94814

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


[PATCH] D95017: [clang-format] add case aware include sorting

2021-01-22 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

I can push that, but will wait a bit longer so the others have time to object.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95017

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


[PATCH] D94919: [clangd] Fix a crash when indexing invalid ObjC method declaration

2021-01-22 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added inline comments.



Comment at: 
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:1807-1811
+@interface Foo
+- (void)fun:(bool)foo
+  bar:(bool)bar,
+  baz:(bool)baz;
+@end

dgoldman wrote:
> It's hard to tell what Clang makes of this, I think instead we should test 
> out the root cause of this crash, IIUC, are the legacy C style parameters:
> 
> ```
> @interface Foo
> - (void)func:(bool)foo, bool bar;
> @end
> ```
Oh yeah, thanks. Like I said, I don't know ObjC, so I was just randomly 
changing code until it crashed ;-)



Comment at: 
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:1816-1819
+  // We mostly care about not crashing, but verify that we didn't insert 
garbage
+  // about X too.
+  EXPECT_THAT(TU.headerSymbols(), Not(Contains(QName("X";
+}

dgoldman wrote:
> We should verify the method name is exactly as expected but comment we mostly 
> care about not crashing.
Oops, that's a copy/paste leftover, sorry about that. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94919

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


[PATCH] D94919: [clangd] Fix a crash when indexing invalid ObjC method declaration

2021-01-22 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz updated this revision to Diff 318529.
adamcz marked an inline comment as done.
adamcz added a comment.

addressed review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94919

Files:
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp


Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -3506,9 +3506,11 @@
 Result.AddTypedTextChunk("");
 }
 unsigned Idx = 0;
+// The extra Idx < Sel.getNumArgs() check is needed due to legacy C-style
+// method parameters.
 for (ObjCMethodDecl::param_const_iterator P = Method->param_begin(),
   PEnd = Method->param_end();
- P != PEnd; (void)++P, ++Idx) {
+ P != PEnd && Idx < Sel.getNumArgs(); (void)++P, ++Idx) {
   if (Idx > 0) {
 std::string Keyword;
 if (Idx > StartParameter)
Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1801,6 +1801,20 @@
   EXPECT_THAT(TU.headerSymbols(), Not(Contains(QName("X";
 }
 
+TEST_F(SymbolCollectorTest, NoCrashOnObjCMethodCStyleParam) {
+  auto TU = TestTU::withCode(R"objc(
+@interface Foo
+- (void)fun:(bool)foo, bool bar;
+@end
+  )objc");
+  TU.ExtraArgs.push_back("-xobjective-c++");
+
+  TU.build();
+  // We mostly care about not crashing.
+  EXPECT_THAT(TU.headerSymbols(),
+  UnorderedElementsAre(QName("Foo"), QName("Foo::fun:")));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -3506,9 +3506,11 @@
 Result.AddTypedTextChunk("");
 }
 unsigned Idx = 0;
+// The extra Idx < Sel.getNumArgs() check is needed due to legacy C-style
+// method parameters.
 for (ObjCMethodDecl::param_const_iterator P = Method->param_begin(),
   PEnd = Method->param_end();
- P != PEnd; (void)++P, ++Idx) {
+ P != PEnd && Idx < Sel.getNumArgs(); (void)++P, ++Idx) {
   if (Idx > 0) {
 std::string Keyword;
 if (Idx > StartParameter)
Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1801,6 +1801,20 @@
   EXPECT_THAT(TU.headerSymbols(), Not(Contains(QName("X";
 }
 
+TEST_F(SymbolCollectorTest, NoCrashOnObjCMethodCStyleParam) {
+  auto TU = TestTU::withCode(R"objc(
+@interface Foo
+- (void)fun:(bool)foo, bool bar;
+@end
+  )objc");
+  TU.ExtraArgs.push_back("-xobjective-c++");
+
+  TU.build();
+  // We mostly care about not crashing.
+  EXPECT_THAT(TU.headerSymbols(),
+  UnorderedElementsAre(QName("Foo"), QName("Foo::fun:")));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95225: [clang][cli] NFC: Pass CC1Option explicitly to BoolOption

2021-01-22 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; this is much better!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95225

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


[PATCH] D95221: [clang][cli] NFC: Move prefix to the front of BoolOption

2021-01-22 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/D95221/new/

https://reviews.llvm.org/D95221

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


[PATCH] D95057: [clangd] WIP: configurable compilation database directory

2021-01-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 318526.
sammccall added a comment.

Add tests and fix bugs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95057

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  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/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp

Index: clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
===
--- clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -8,6 +8,7 @@
 
 #include "GlobalCompilationDatabase.h"
 
+#include "Config.h"
 #include "Matchers.h"
 #include "TestFS.h"
 #include "support/Path.h"
@@ -205,10 +206,12 @@
   llvm::formatv(CDBOuter, llvm::sys::path::convert_to_slash(testRoot()));
   FS.Files[testPath("build/compile_commands.json")] =
   llvm::formatv(CDBInner, llvm::sys::path::convert_to_slash(testRoot()));
+  FS.Files[testPath("foo/compile_flags.txt")] = "-DFOO";
 
   // Note that gen2.cc goes missing with our following model, not sure this
   // happens in practice though.
   {
+SCOPED_TRACE("Default ancestor scanning");
 DirectoryBasedGlobalCompilationDatabase DB(FS);
 std::vector DiscoveredFiles;
 auto Sub =
@@ -227,8 +230,53 @@
 EXPECT_THAT(DiscoveredFiles, UnorderedElementsAre(EndsWith("gen.cc")));
   }
 
-  // With a custom compile commands dir.
   {
+SCOPED_TRACE("With config");
+DirectoryBasedGlobalCompilationDatabase::Options Opts(FS);
+Opts.ContextProvider = [&](llvm::StringRef Path) {
+  Config Cfg;
+  if (Path.endswith("a.cc")) {
+// a.cc uses another directory's CDB, so it won't be discovered.
+Cfg.CompileFlags.CDBSearch.Policy = Config::CDBSearchSpec::FixedDir;
+Cfg.CompileFlags.CDBSearch.FixedCDBPath = testPath("foo");
+  } else if (Path.endswith("gen.cc")) {
+// gen.cc has CDB search disabled, so it won't be discovered.
+Cfg.CompileFlags.CDBSearch.Policy = Config::CDBSearchSpec::NoCDBSearch;
+  } else if (Path.endswith("gen2.cc")) {
+// gen2.cc explicitly lists this directory, so it will be discovered.
+Cfg.CompileFlags.CDBSearch.Policy = Config::CDBSearchSpec::FixedDir;
+Cfg.CompileFlags.CDBSearch.FixedCDBPath = testRoot();
+  }
+  return Context::current().derive(Config::Key, std::move(Cfg));
+};
+DirectoryBasedGlobalCompilationDatabase DB(Opts);
+std::vector DiscoveredFiles;
+auto Sub =
+DB.watch([](const std::vector Changes) {
+  DiscoveredFiles = Changes;
+});
+
+// Does not use the root CDB, so no broadcast.
+auto Cmd = DB.getCompileCommand(testPath("build/../a.cc"));
+ASSERT_TRUE(Cmd.hasValue());
+EXPECT_THAT(Cmd->CommandLine, Contains("-DFOO")) << "a.cc uses foo/ CDB";
+ASSERT_TRUE(DB.blockUntilIdle(timeoutSeconds(10)));
+EXPECT_THAT(DiscoveredFiles, IsEmpty()) << "Root CDB not discovered yet";
+
+// No special config for b.cc, so we trigger broadcast of the root CDB.
+DB.getCompileCommand(testPath("b.cc"));
+ASSERT_TRUE(DB.blockUntilIdle(timeoutSeconds(10)));
+EXPECT_THAT(DiscoveredFiles, ElementsAre(testPath("build/gen2.cc")));
+DiscoveredFiles.clear();
+
+// No CDB search so no discovery/broadcast triggered for build/ CDB.
+DB.getCompileCommand(testPath("build/gen.cc"));
+ASSERT_TRUE(DB.blockUntilIdle(timeoutSeconds(10)));
+EXPECT_THAT(DiscoveredFiles, IsEmpty());
+  }
+
+  {
+SCOPED_TRACE("With custom compile commands dir");
 DirectoryBasedGlobalCompilationDatabase::Options Opts(FS);
 Opts.CompileCommandsDir = testRoot();
 DirectoryBasedGlobalCompilationDatabase DB(Opts);
@@ -294,6 +342,58 @@
   EXPECT_EQ(testPath("x"), Commands.getValue().Directory);
 }
 
+MATCHER_P(hasArg, Flag, "") {
+  if (!arg.hasValue()) {
+*result_listener << "command is null";
+return false;
+  }
+  if (!llvm::is_contained(arg->CommandLine, Flag)) {
+*result_listener << "flags are " << llvm::join(arg->CommandLine, " ");
+return false;
+  }
+  return true;
+}
+
+TEST(GlobalCompilationDatabaseTest, Config) {
+  MockFS FS;
+  FS.Files[testPath("x/compile_flags.txt")] = "-DX";
+  FS.Files[testPath("x/y/z/compile_flags.txt")] = "-DZ";
+
+  Config::CDBSearchSpec Spec;
+  DirectoryBasedGlobalCompilationDatabase::Options Opts(FS);
+  Opts.ContextProvider = [&](llvm::StringRef Path) {
+Config C;
+C.CompileFlags.CDBSearch = Spec;
+return 

[PATCH] D95231: [clangd] Selection handles CXXBaseSpecifier

2021-01-22 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 318523.
njames93 added a comment.

Update FindTargets to fix symbol renaming on a CXXBaseSpecifier.
Add test to ensure rename wont trigger on a CXXBaseSpecifier.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95231

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp
  clang/lib/AST/ASTTypeTraits.cpp


Index: clang/lib/AST/ASTTypeTraits.cpp
===
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -193,5 +193,7 @@
 return TAL->getSourceRange();
   if (const auto *C = get())
 return SourceRange(C->getBeginLoc(), C->getEndLoc());
+  if (const auto *CBS = get())
+return CBS->getSourceRange();
   return SourceRange();
 }
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -261,6 +261,27 @@
   )cpp",
   "StringLiteral", // Not DeclRefExpr to operator()!
   },
+  {
+  R"cpp(
+struct Foo {};
+struct Bar : [[v^ir^tual private Foo]] {};
+  )cpp",
+  "CXXBaseSpecifier",
+  },
+  {
+  R"cpp(
+struct Foo {};
+struct Bar : [[private Fo^o]] {};
+  )cpp",
+  "CXXBaseSpecifier",
+  },
+  {
+  R"cpp(
+struct Foo {};
+struct Bar : [[Fo^o]] {};
+  )cpp",
+  "CXXBaseSpecifier",
+  },
 
   // Point selections.
   {"void foo() { [[^foo]](); }", "DeclRefExpr"},
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1024,6 +1024,12 @@
 }
   )cpp",
"new name is the same", !HeaderFile, nullptr, "SameName"},
+  {R"cpp(// Ensure it doesn't associate base specifier with base name.
+struct A {};
+struct B : priv^ate A {};
+  )cpp",
+   "Cannot rename symbol: there is no symbol at the given location", false,
+   nullptr},
   };
 
   for (const auto& Case : Cases) {
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -493,6 +493,14 @@
 return traverseNode(
 X, [&] { return Base::TraverseConstructorInitializer(X); });
   }
+  bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier ) {
+auto N = DynTypedNode::create(X);
+if (canSafelySkipNode(N))
+  return true;
+push(std::move(N));
+pop();
+return true;
+  }
   // Stmt is the same, but this form allows the data recursion optimization.
   bool dataTraverseStmtPre(Stmt *X) {
 if (!X || isImplicit(X))
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -710,7 +710,8 @@
 Finder.add(CCI, Flags);
   else if (const TemplateArgumentLoc *TAL = N.get())
 Finder.add(TAL->getArgument(), Flags);
-
+  else if (const CXXBaseSpecifier *CBS = N.get())
+Finder.add(CBS->getType(), Flags);
   return Finder.takeDecls();
 }
 


Index: clang/lib/AST/ASTTypeTraits.cpp
===
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -193,5 +193,7 @@
 return TAL->getSourceRange();
   if (const auto *C = get())
 return SourceRange(C->getBeginLoc(), C->getEndLoc());
+  if (const auto *CBS = get())
+return CBS->getSourceRange();
   return SourceRange();
 }
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -261,6 +261,27 @@
   )cpp",
   "StringLiteral", // Not DeclRefExpr to operator()!
   },
+  {
+  R"cpp(
+struct Foo {};
+struct Bar : [[v^ir^tual private Foo]] {};
+  )cpp",
+  "CXXBaseSpecifier",
+  },
+  {
+  R"cpp(
+struct Foo {};
+struct Bar : [[private Fo^o]] {};
+  )cpp",
+  "CXXBaseSpecifier",
+  },
+  {
+  R"cpp(
+struct Foo {};
+struct Bar : [[Fo^o]] {};
+  )cpp",
+  "CXXBaseSpecifier",
+  },
 
   // Point 

[PATCH] D95002: [RISCV] Update B extension version to 0.93.

2021-01-22 Thread Fraser Cormack via Phabricator via cfe-commits
frasercrmck added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoB.td:732
 // There's no encoding for roli in the current version of the 'B' extension
 // (v0.92) as it can be implemented with rori by negating the immediate.
 let Predicates = [HasStdExtZbbOrZbp] in {

This might need updated. The statement is still true in 0.92, but it's not the 
"current version"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95002

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


[PATCH] D94779: [Clang] Ensure vector predication pragma is ignored only when vectorization width is 1.

2021-01-22 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added a comment.

In D94779#2515157 , @dmgreen wrote:

> Thanks. @fhahn @SjoerdMeijer what do we think about the edge case where the 
> width==1? As far as I understand (with this patch):
>
>   #pragma clang loop vectorize_predicate(disable) vectorize_width(4)
>   Gives llvm.loop.vectorize.predicate.enable=false, 
> llvm.loop.vectorize.width=4, llvm.loop.vectorize.scalable.enable=false, 
> llvm.loop.vectorize.enable=true
>   
>   #pragma clang loop vectorize_predicate(disable) vectorize_width(4)

I guess this is a typo, and should be `vectorize_predicate(enable)`

> Gives llvm.loop.vectorize.predicate.enable=true, llvm.loop.vectorize.width=4, 
> llvm.loop.vectorize.scalable.enable=false, llvm.loop.vectorize.enable=true
>
> #pragma clang loop vectorize_predicate(enable) vectorize_width(1)
> Gives llvm.loop.vectorize.width=1, llvm.loop.vectorize.scalable.enable=false
>
> #pragma clang loop vectorize_predicate(disable) vectorize_width(1)
> Gives llvm.loop.vectorize.width=1, llvm.loop.vectorize.scalable.enable=false
>
>   Should we be adding llvm.loop.vectorize.predicate.enable metadata even when 
> width=1? I would be inclined to emit the predication pragma anyway.

So yeah, I got confused about this edge case width=1 earlier, but have 
refreshed my memory.
I would like to ask the question if it matters? Vectorize.width = 1 disables 
vectorisation, so unless I miss something, I don't think it matters if we emit 
`llvm.loop.vectorize.predicate.enable=true` or 
`llvm.loop.vectorize.predicate.enable=false` because it is ignored anyway? But 
if we have a combination that doesn't make sense, like `width(1)` and 
`predicate(enable)`, should we emit a diagnostic if this is not already done?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94779

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


[PATCH] D95231: [clangd] Selection handles CXXBaseSpecifier

2021-01-22 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: kadircet, hokein, sammccall.
Herald added subscribers: usaxena95, arphaman.
njames93 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Selection now includes the virtual and access modifier as part of their range 
for cxx base specifiers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95231

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp
  clang/lib/AST/ASTTypeTraits.cpp


Index: clang/lib/AST/ASTTypeTraits.cpp
===
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -193,5 +193,7 @@
 return TAL->getSourceRange();
   if (const auto *C = get())
 return SourceRange(C->getBeginLoc(), C->getEndLoc());
+  if (const auto *CBS = get())
+return CBS->getSourceRange();
   return SourceRange();
 }
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -261,6 +261,27 @@
   )cpp",
   "StringLiteral", // Not DeclRefExpr to operator()!
   },
+  {
+  R"cpp(
+struct Foo {};
+struct Bar : [[v^ir^tual private Foo]] {};
+  )cpp",
+  "CXXBaseSpecifier",
+  },
+  {
+  R"cpp(
+struct Foo {};
+struct Bar : [[private Fo^o]] {};
+  )cpp",
+  "CXXBaseSpecifier",
+  },
+  {
+  R"cpp(
+struct Foo {};
+struct Bar : [[Fo^o]] {};
+  )cpp",
+  "CXXBaseSpecifier",
+  },
 
   // Point selections.
   {"void foo() { [[^foo]](); }", "DeclRefExpr"},
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -493,6 +493,14 @@
 return traverseNode(
 X, [&] { return Base::TraverseConstructorInitializer(X); });
   }
+  bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier ) {
+auto N = DynTypedNode::create(X);
+if (canSafelySkipNode(N))
+  return true;
+push(std::move(N));
+pop();
+return true;
+  }
   // Stmt is the same, but this form allows the data recursion optimization.
   bool dataTraverseStmtPre(Stmt *X) {
 if (!X || isImplicit(X))


Index: clang/lib/AST/ASTTypeTraits.cpp
===
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -193,5 +193,7 @@
 return TAL->getSourceRange();
   if (const auto *C = get())
 return SourceRange(C->getBeginLoc(), C->getEndLoc());
+  if (const auto *CBS = get())
+return CBS->getSourceRange();
   return SourceRange();
 }
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -261,6 +261,27 @@
   )cpp",
   "StringLiteral", // Not DeclRefExpr to operator()!
   },
+  {
+  R"cpp(
+struct Foo {};
+struct Bar : [[v^ir^tual private Foo]] {};
+  )cpp",
+  "CXXBaseSpecifier",
+  },
+  {
+  R"cpp(
+struct Foo {};
+struct Bar : [[private Fo^o]] {};
+  )cpp",
+  "CXXBaseSpecifier",
+  },
+  {
+  R"cpp(
+struct Foo {};
+struct Bar : [[Fo^o]] {};
+  )cpp",
+  "CXXBaseSpecifier",
+  },
 
   // Point selections.
   {"void foo() { [[^foo]](); }", "DeclRefExpr"},
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -493,6 +493,14 @@
 return traverseNode(
 X, [&] { return Base::TraverseConstructorInitializer(X); });
   }
+  bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier ) {
+auto N = DynTypedNode::create(X);
+if (canSafelySkipNode(N))
+  return true;
+push(std::move(N));
+pop();
+return true;
+  }
   // Stmt is the same, but this form allows the data recursion optimization.
   bool dataTraverseStmtPre(Stmt *X) {
 if (!X || isImplicit(X))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94942: [clangd] Add tweak for implementing abstract class

2021-01-22 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D94942#2515049 , @kadircet wrote:

> Thanks this looks great, and something i've been longing for some time! But I 
> got a couple of questions about the how the interaction is designed (sorry if 
> I missed some high level discussions elsewhere, feel free to just point me in 
> that direction).

There was no high level discussions on my end. I'm just a guy on my own, who 
makes what I like, I don't even work in software. Though if there is a public 
place where people seem to discuss these I'd like to be pointed in the 
direction(discord seems to be mainly used for user support and clangd-dev has 
only had one relevant post in the last 6 months). Right now seems that GitHub 
issues and here are my best bets.

> - Why do we just declare methods, rather than defining them too (with dummy 
> bodies) ? This would allow users to move function bodies out-of-line if they 
> want to easily. Also it would enforce them to fill in the bodies, rather than 
> forgetting/skipping some of the methods. (Even more maybe we should take the 
> extra step and offer another action to declare the function inline and define 
> it out-of-line, but I think that could be done iteratively if we see the need)

I'm still unsure of the best way to go about that, Trouble with just defining 
empty methods is we will undoubtedly generate code that can't compile (without 
warnings), Mostly due to methods not having return statements or if we try and 
fix that, how do you implement the return when the function needs to return a 
reference.

> - Implementing all (pure) virtuals vs offering a code action for each 
> possible method. It is unfortunate that our existing tweak infrastructure 
> doesn't enable a single tweak to output multiple code actions, but I believe 
> in this case we might achieve a whole lot better UX if we did offer 
> implementing each method one by one, while possibly still suggesting 
> implement "all" overrides or "only" pures. It is still useful in its current 
> form ofcourse, as the user can manually change the declaration into a pure 
> one, or delete it, but it sounds cumbersome if they only want to implement a 
> small subset of all possible pure methods .
> - Acting on non-pure virtuals too, i believe this is also a quite common use 
> case that could benefit a lot of users. but this definitely increases the 
> need for a code action per override.

As code completion can help implement just one virtual method, not much is 
gained by offering to implement methods one by one.
Then there's the issue of say if a class has 50 virtual methods, Having 50 
different refactoring show up in the UI is likely going to be some issue.
There's a discussion 
 of adding a 
refactoring related methods to LSP which would enable a more interactive 
experience. There hasn't been an agreed design yet though. If that does make it 
through it would definitely extend the usefulness of this. Presenting a 
Interface to the user where they could choose exactly what methods they want to 
implement as well as letting them override already implemented virtual 
functions.

> - When to trigger? I suppose what you have in the code ATM makes sense (e.g. 
> just on `[[class X]] : ... [[{]] [[}]]`) but it would be great to spell it 
> out explicitly so that others have a chance to raise concerns. I don't think 
> triggering within the body would be useful though, as users are likely to 
> navigate within class body for various reasons, and spamming them with lots 
> of codeactions at each cursor move is likely to be annoying.

Fair point. Regarding the base specifier, Currently it doesn't offer the tweak 
when over the base specifier, I may be inclined to tweak behaviour so If you 
are over the base specifier, then only offer to implement pure virtual methods 
from that base class. Although rather annoyingly, The selection considers the 
`public|private|protected|virtual` part of a base specifier as part of the 
derived class, Instead of being part of the base specifier. I'm gonna push a 
separate patch to address that though.

> - When to land this :) we are at the edge of a branch cut, and tweaks are a 
> feature triggered automatically by editors. so any crashes in there are 
> likely to make clangd useless (as they'll persist no matter what). so I 
> believe we should either wait for release cut, and land this afterwards and 
> fixing any crash reports we get until next release, or include it in current 
> release while marking the tweak as hidden so that it will only annoy 
> experimental users.

I couldn't even rush this and get it ready before Tuesday :) Definitely not 
gonna make the 12 cut, even in experimental state.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94942


[PATCH] D95229: [clangd] Treat optional field type mismatches as soft failures

2021-01-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Clangd currently throws away any protocol messages whenever an optional
field has an unexpected type. This patch changes the behaviour to treat such
fields as missing.

This enables clangd to be more tolerant against small violations to the LSP
spec.

Fixes https://github.com/clangd/vscode-clangd/issues/134


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95229

Files:
  clang-tools-extra/clangd/Protocol.cpp

Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -27,6 +27,19 @@
 
 namespace clang {
 namespace clangd {
+namespace {
+// Helper to ignore type mismatches on optional fields.
+template 
+bool mapOptionalOrLog(llvm::json::ObjectMapper , llvm::StringLiteral Prop,
+  T ) {
+  if (!O.mapOptional(Prop, Out)) {
+elog("Unexpected value for optional field '{0}', ignoring", Prop);
+Out = T{}; // Default-initialize Out to ensure we don't have a
+   // half-constructed object.
+  }
+  return true;
+}
+} // namespace
 
 char LSPError::ID;
 
@@ -490,7 +503,7 @@
   return O && O.map("textDocument", R.textDocument) &&
  O.map("contentChanges", R.contentChanges) &&
  O.map("wantDiagnostics", R.wantDiagnostics) &&
- O.mapOptional("forceRebuild", R.forceRebuild);
+ mapOptionalOrLog(O, "forceRebuild", R.forceRebuild);
 }
 
 bool fromJSON(const llvm::json::Value , FileChangeType ,
@@ -580,10 +593,10 @@
   llvm::json::Path P) {
   llvm::json::ObjectMapper O(Params, P);
   return O && O.map("range", R.range) && O.map("message", R.message) &&
- O.mapOptional("severity", R.severity) &&
- O.mapOptional("category", R.category) &&
- O.mapOptional("code", R.code) && O.mapOptional("source", R.source);
-  return true;
+ mapOptionalOrLog(O, "severity", R.severity) &&
+ mapOptionalOrLog(O, "category", R.category) &&
+ mapOptionalOrLog(O, "code", R.code) &&
+ mapOptionalOrLog(O, "source", R.source);
 }
 
 llvm::json::Value toJSON(const PublishDiagnosticsParams ) {
@@ -817,9 +830,9 @@
   llvm::json::Path P) {
   llvm::json::ObjectMapper O(Params, P);
   int TriggerKind;
-  if (!O || !O.map("triggerKind", TriggerKind) ||
-  !O.mapOptional("triggerCharacter", R.triggerCharacter))
+  if (!O || !O.map("triggerKind", TriggerKind))
 return false;
+  mapOptionalOrLog(O, "triggerCharacter", R.triggerCharacter);
   R.triggerKind = static_cast(TriggerKind);
   return true;
 }
@@ -1121,8 +1134,9 @@
   llvm::json::ObjectMapper O(Params, P);
   if (!O)
 return true; // 'any' type in LSP.
-  return O.mapOptional("compilationDatabaseChanges",
-   S.compilationDatabaseChanges);
+  mapOptionalOrLog(O, "compilationDatabaseChanges",
+   S.compilationDatabaseChanges);
+  return true;
 }
 
 bool fromJSON(const llvm::json::Value , InitializationOptions ,
@@ -1133,8 +1147,8 @@
 
   return fromJSON(Params, Opts.ConfigSettings, P) &&
  O.map("compilationDatabasePath", Opts.compilationDatabasePath) &&
- O.mapOptional("fallbackFlags", Opts.fallbackFlags) &&
- O.mapOptional("clangdFileStatus", Opts.FileStatus);
+ mapOptionalOrLog(O, "fallbackFlags", Opts.fallbackFlags) &&
+ mapOptionalOrLog(O, "clangdFileStatus", Opts.FileStatus);
 }
 
 bool fromJSON(const llvm::json::Value , TypeHierarchyDirection ,
@@ -1190,10 +1204,11 @@
   return O && O.map("name", I.name) && O.map("kind", I.kind) &&
  O.map("uri", I.uri) && O.map("range", I.range) &&
  O.map("selectionRange", I.selectionRange) &&
- O.mapOptional("detail", I.detail) &&
- O.mapOptional("deprecated", I.deprecated) &&
- O.mapOptional("parents", I.parents) &&
- O.mapOptional("children", I.children) && O.mapOptional("data", I.data);
+ mapOptionalOrLog(O, "detail", I.detail) &&
+ mapOptionalOrLog(O, "deprecated", I.deprecated) &&
+ mapOptionalOrLog(O, "parents", I.parents) &&
+ mapOptionalOrLog(O, "children", I.children) &&
+ mapOptionalOrLog(O, "data", I.data);
 }
 
 bool fromJSON(const llvm::json::Value ,
@@ -1238,7 +1253,7 @@
   return O && O.map("name", I.name) && O.map("kind", I.kind) &&
  O.map("uri", I.uri) && O.map("range", I.range) &&
  O.map("selectionRange", I.selectionRange) &&
- O.mapOptional("data", I.data);
+ mapOptionalOrLog(O, "data", I.data);
 }
 
 bool fromJSON(const llvm::json::Value ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D95228: Add swift_async_context parameter attribute mapping to IR equivalent

2021-01-22 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover created this revision.
Herald added subscribers: dexonsmith, jdoerfert, mcrosier.
Herald added a reviewer: aaron.ballman.
t.p.northover requested review of this revision.

This adds `__attribute__((swift_async_context))` very much following the 
existing `swift_context` so that Swift's runtime implementation in C++ can 
generate functions that interact with Swift code properly. Hopefully nothing 
too controversial.

It depends on D95044  for the IR support.


https://reviews.llvm.org/D95228

Files:
  clang/include/clang/AST/Attr.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/Specifiers.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-swiftcall.c

Index: clang/test/Sema/attr-swiftcall.c
===
--- clang/test/Sema/attr-swiftcall.c
+++ clang/test/Sema/attr-swiftcall.c
@@ -5,6 +5,7 @@
 #define INDIRECT_RESULT __attribute__((swift_indirect_result))
 #define ERROR_RESULT __attribute__((swift_error_result))
 #define CONTEXT __attribute__((swift_context))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
 
 int notAFunction SWIFTCALL; // expected-warning {{'swiftcall' only applies to function types; type here is 'int'}}
 void variadic(int x, ...) SWIFTCALL; // expected-error {{variadic function cannot use swiftcall calling convention}}
@@ -29,3 +30,8 @@
 void context_bad_type(CONTEXT int context) SWIFTCALL; // expected-error {{'swift_context' parameter must have pointer type; type here is 'int'}}
 void context_okay(CONTEXT void *context) SWIFTCALL;
 void context_okay2(CONTEXT void *context, void *selfType, char **selfWitnessTable) SWIFTCALL;
+
+void async_context_okay_for_now(ASYNC_CONTEXT void *context);
+void async_context_bad_type(ASYNC_CONTEXT int context) SWIFTCALL; // expected-error {{'swift_async_context' parameter must have pointer type; type here is 'int'}}
+void async_context_okay(ASYNC_CONTEXT void *context) SWIFTCALL;
+void async_context_okay2(ASYNC_CONTEXT void *context, void *selfType, char **selfWitnessTable) SWIFTCALL;
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -154,6 +154,7 @@
 // CHECK-NEXT: SetTypestate (SubjectMatchRule_function_is_member)
 // CHECK-NEXT: SpeculativeLoadHardening (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: SwiftAsync (SubjectMatchRule_function, SubjectMatchRule_objc_method)
+// CHECK-NEXT: SwiftAsyncContext (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: SwiftAsyncName (SubjectMatchRule_objc_method, SubjectMatchRule_function)
 // CHECK-NEXT: SwiftBridgedTypedef (SubjectMatchRule_type_alias)
 // CHECK-NEXT: SwiftContext (SubjectMatchRule_variable_is_parameter)
Index: clang/test/CodeGen/arm-swiftcall.c
===
--- clang/test/CodeGen/arm-swiftcall.c
+++ clang/test/CodeGen/arm-swiftcall.c
@@ -6,6 +6,7 @@
 #define OUT __attribute__((swift_indirect_result))
 #define ERROR __attribute__((swift_error_result))
 #define CONTEXT __attribute__((swift_context))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
 
 /*/
 /** PARAMETER ABIS ***/
@@ -53,6 +54,9 @@
 SWIFTCALL void context_error_2(short s, CONTEXT int *self, ERROR float **error) {}
 // CHECK-LABEL: define{{.*}} void @context_error_2(i16{{.*}}, i32* swiftself{{.*}}, float** swifterror %0)
 
+SWIFTCALL void async_context_1(ASYNC_CONTEXT void *self) {}
+// CHECK-LABEL: define {{.*}} void @async_context_1(i8* swiftasync
+
 /*/
 /** LOWERING */
 /*/
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2791,6 +2791,10 @@
   checkForSwiftCC(paramIndex);
   continue;
 
+case ParameterABI::SwiftAsyncContext:
+  // FIXME: might want to require swiftasynccc when it exists
+  continue;
+
 // swift_error parameters must be preceded by a swift_context parameter.
 case ParameterABI::SwiftErrorResult:
   checkForSwiftCC(paramIndex);
Index: clang/lib/Sema/SemaDeclAttr.cpp

[PATCH] D95145: [clang] Fix a nullptr dereference bug on invalid code

2021-01-22 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added inline comments.



Comment at: clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp:2
+// RUN: %clang -fsyntax-only -std=c++17 %s -Xclang -verify
+#include 
+

hokein wrote:
> A common practice is to avoid depending on STL in tests. I think we need to 
> pull out (even simplify?) std::result_of implementation if it is needed for 
> reproducing the crash.
I've noticed that pattern, but can't tell why this is. Is it documented 
somewhere?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95145

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


[clang] 98a8344 - [clang][ASTImporter] Add support for importing CXXFoldExpr.

2021-01-22 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2021-01-22T15:20:55+01:00
New Revision: 98a8344895a8e1f2cfa98b664b50fb7b864afa52

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

LOG: [clang][ASTImporter] Add support for importing CXXFoldExpr.

Reviewed By: shafik, martong

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

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 5c6aa5d3c015..085c50c0667b 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -644,6 +644,7 @@ namespace clang {
 ExpectedStmt 
VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
 ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E);
 ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E);
+ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E);
 
 template
 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
@@ -8011,6 +8012,25 @@ ExpectedStmt 
ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
   *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
 }
 
+ExpectedStmt ASTNodeImporter::VisitCXXFoldExpr(CXXFoldExpr *E) {
+  Error Err = Error::success();
+
+  QualType ToType = importChecked(Err, E->getType());
+  UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
+  SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
+  Expr *ToLHS = importChecked(Err, E->getLHS());
+  SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
+  Expr *ToRHS = importChecked(Err, E->getRHS());
+  SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
+
+  if (Err)
+return std::move(Err);
+
+  return new (Importer.getToContext())
+  CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
+  ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
+}
+
 Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod,
CXXMethodDecl *FromMethod) {
   Error ImportErrors = Error::success();

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 8a07a5b8e0df..193523f2fc51 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -639,6 +639,38 @@ TEST_P(ImportExpr, ImportSizeOfPackExpr) {
   hasUnqualifiedDesugaredType(constantArrayType(hasSize(7));
 }
 
+const internal::VariadicDynCastAllOfMatcher cxxFoldExpr;
+
+AST_MATCHER_P(CXXFoldExpr, hasOperator, BinaryOperatorKind, Op) {
+  return Node.getOperator() == Op;
+}
+AST_MATCHER(CXXFoldExpr, hasInit) { return Node.getInit(); }
+AST_MATCHER(CXXFoldExpr, isRightFold) { return Node.isRightFold(); }
+AST_MATCHER(CXXFoldExpr, isLeftFold) { return Node.isLeftFold(); }
+
+TEST_P(ImportExpr, ImportCXXFoldExpr) {
+  auto Match1 =
+  cxxFoldExpr(hasOperator(BO_Add), isLeftFold(), unless(hasInit()));
+  auto Match2 = cxxFoldExpr(hasOperator(BO_Sub), isLeftFold(), hasInit());
+  auto Match3 =
+  cxxFoldExpr(hasOperator(BO_Mul), isRightFold(), unless(hasInit()));
+  auto Match4 = cxxFoldExpr(hasOperator(BO_Div), isRightFold(), hasInit());
+
+  MatchVerifier Verifier;
+  testImport("template "
+ "void declToImport(Ts... args) {"
+ "  const int i1 = (... + args);"
+ "  const int i2 = (1 - ... - args);"
+ "  const int i3 = (args * ...);"
+ "  const int i4 = (args / ... / 1);"
+ "};"
+ "void g() { declToImport(1, 2, 3, 4, 5); }",
+ Lang_CXX17, "", Lang_CXX17, Verifier,
+ functionTemplateDecl(hasDescendant(Match1), hasDescendant(Match2),
+  hasDescendant(Match3),
+  hasDescendant(Match4)));
+}
+
 /// \brief Matches __builtin_types_compatible_p:
 /// GNU extension to check equivalent types
 /// Given



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


[PATCH] D94786: [clang][ASTImporter] Add support for importing CXXFoldExpr.

2021-01-22 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG98a8344895a8: [clang][ASTImporter] Add support for importing 
CXXFoldExpr. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94786

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -639,6 +639,38 @@
   hasUnqualifiedDesugaredType(constantArrayType(hasSize(7));
 }
 
+const internal::VariadicDynCastAllOfMatcher cxxFoldExpr;
+
+AST_MATCHER_P(CXXFoldExpr, hasOperator, BinaryOperatorKind, Op) {
+  return Node.getOperator() == Op;
+}
+AST_MATCHER(CXXFoldExpr, hasInit) { return Node.getInit(); }
+AST_MATCHER(CXXFoldExpr, isRightFold) { return Node.isRightFold(); }
+AST_MATCHER(CXXFoldExpr, isLeftFold) { return Node.isLeftFold(); }
+
+TEST_P(ImportExpr, ImportCXXFoldExpr) {
+  auto Match1 =
+  cxxFoldExpr(hasOperator(BO_Add), isLeftFold(), unless(hasInit()));
+  auto Match2 = cxxFoldExpr(hasOperator(BO_Sub), isLeftFold(), hasInit());
+  auto Match3 =
+  cxxFoldExpr(hasOperator(BO_Mul), isRightFold(), unless(hasInit()));
+  auto Match4 = cxxFoldExpr(hasOperator(BO_Div), isRightFold(), hasInit());
+
+  MatchVerifier Verifier;
+  testImport("template "
+ "void declToImport(Ts... args) {"
+ "  const int i1 = (... + args);"
+ "  const int i2 = (1 - ... - args);"
+ "  const int i3 = (args * ...);"
+ "  const int i4 = (args / ... / 1);"
+ "};"
+ "void g() { declToImport(1, 2, 3, 4, 5); }",
+ Lang_CXX17, "", Lang_CXX17, Verifier,
+ functionTemplateDecl(hasDescendant(Match1), hasDescendant(Match2),
+  hasDescendant(Match3),
+  hasDescendant(Match4)));
+}
+
 /// \brief Matches __builtin_types_compatible_p:
 /// GNU extension to check equivalent types
 /// Given
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -644,6 +644,7 @@
 ExpectedStmt 
VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
 ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E);
 ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E);
+ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E);
 
 template
 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
@@ -8011,6 +8012,25 @@
   *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
 }
 
+ExpectedStmt ASTNodeImporter::VisitCXXFoldExpr(CXXFoldExpr *E) {
+  Error Err = Error::success();
+
+  QualType ToType = importChecked(Err, E->getType());
+  UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
+  SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
+  Expr *ToLHS = importChecked(Err, E->getLHS());
+  SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
+  Expr *ToRHS = importChecked(Err, E->getRHS());
+  SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
+
+  if (Err)
+return std::move(Err);
+
+  return new (Importer.getToContext())
+  CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
+  ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
+}
+
 Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod,
CXXMethodDecl *FromMethod) {
   Error ImportErrors = Error::success();


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -639,6 +639,38 @@
   hasUnqualifiedDesugaredType(constantArrayType(hasSize(7));
 }
 
+const internal::VariadicDynCastAllOfMatcher cxxFoldExpr;
+
+AST_MATCHER_P(CXXFoldExpr, hasOperator, BinaryOperatorKind, Op) {
+  return Node.getOperator() == Op;
+}
+AST_MATCHER(CXXFoldExpr, hasInit) { return Node.getInit(); }
+AST_MATCHER(CXXFoldExpr, isRightFold) { return Node.isRightFold(); }
+AST_MATCHER(CXXFoldExpr, isLeftFold) { return Node.isLeftFold(); }
+
+TEST_P(ImportExpr, ImportCXXFoldExpr) {
+  auto Match1 =
+  cxxFoldExpr(hasOperator(BO_Add), isLeftFold(), unless(hasInit()));
+  auto Match2 = cxxFoldExpr(hasOperator(BO_Sub), isLeftFold(), hasInit());
+  auto Match3 =
+  cxxFoldExpr(hasOperator(BO_Mul), isRightFold(), unless(hasInit()));
+  auto Match4 = cxxFoldExpr(hasOperator(BO_Div), isRightFold(), hasInit());
+
+  MatchVerifier Verifier;
+  testImport("template "
+ "void declToImport(Ts... args) {"
+ "  const int i1 = 

[PATCH] D94814: [HIP] Support `__managed__` attribute

2021-01-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

The attribute parts LGTM aside from some small nits.




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8245
 "%select{__device__|__global__|__host__|__host__ __device__}0 functions">;
-def err_cuda_nonstatic_constdev: Error<"__constant__ and __device__ are not 
allowed on non-static local variables">;
+def err_cuda_nonstatic_constdev: Error<"__constant__, __device__, and 
__managed__ are not allowed on non-static local variables">;
 def err_cuda_ovl_target : Error<

Since we're modifying this line anyway, can you wrap it for the 80-col limit?



Comment at: clang/test/SemaCUDA/managed-var.cu:45
+__managed__ A a;
+// expected-error@-1 {{dynamic initialization is not supported for __device__, 
__constant__, __shared__, and __managed__ variables}}

I think you're missing tests that check that the new managed attribute accepts 
no arguments and that it doesn't apply to things other than variables (like a 
function declaration).


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

https://reviews.llvm.org/D94814

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


[PATCH] D94986: Remove requirement for -maltivec to be used when using -mabi=vec-extabi or -mabi=vec-default when not using vector code

2021-01-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:4671
+  D.Diag(diag::err_aix_default_altivec_abi);
   }
 

Just to confirm, because the patch description confuses me a bit on this: The 
intent is to not complain on `-mabi=vec-default` or `-mabi=vec-extabi` at all 
on AIX, right? That is, `-mabi=vec-extabi` is one way to prepare non-vector 
code for eventual compatibility purposes. @ZarkoCA, I suggest updating the 
patch description (and eventual commit message).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94986

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


[PATCH] D94293: [clangd] automatically index STL

2021-01-22 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel abandoned this revision.
kuhnel added a comment.

thx for the review and feedback!

I guess I'll re-design the feature and add a new indexing layer instead. 
However that might take a while, so I'll abandon this revision and start a new 
one later on.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94293

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


[PATCH] D85528: [analyzer] Fix cast evaluation on scoped enums in ExprEngine

2021-01-22 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

The patch doesn't seem to affect the reports.
It only introduced 3 new reports during the analysis of clang + clang-tidy.
The analysis times indeed increased slightly, ~~ +3%.

Overall, I think it's a valuable patch, which resolves crashes when the Z3 
refutation enabled.
However, I can evaluate this patch on more C++ projects if you are still not 
convinced.

---

You can inspect my evaluation results at:
https://codechecker-demo.eastus.cloudapp.azure.com/Default/runs?run=D85528-fix-scoped-enum-cast-evaluation=name=false


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85528

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


[PATCH] D95057: [clangd] WIP: configurable compilation database directory

2021-01-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 318499.
sammccall added a comment.

Rebase, implement yaml bits (no tests yet)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95057

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  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/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp

Index: clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
@@ -194,6 +194,33 @@
   EXPECT_EQ(From["name"], "caller1");
 }
 
+TEST_F(LSPTest, CDBConfigIntegration) {
+  auto CfgProvider =
+  config::Provider::fromAncestorRelativeYAMLFiles(".clangd", FS);
+  Opts.ConfigProvider = CfgProvider.get();
+
+  // Map bar.cpp to a different compilation database which defines FOO->BAR.
+  FS.Files[".clangd"] = R"yaml(
+If:
+  PathMatch: bar.cpp
+CompileFlags:
+  CompilationDatabase: bar
+)yaml";
+  FS.Files["bar/compile_flags.txt"] = "-DFOO=BAR";
+
+  auto  = start();
+  // foo.cpp gets parsed as normal.
+  Client.didOpen("foo.cpp", "int x = FOO;");
+  EXPECT_THAT(Client.diagnostics("foo.cpp"),
+  llvm::ValueIs(testing::ElementsAre(
+  DiagMessage("Use of undeclared identifier 'FOO'";
+  // bar.cpp shows the configured compile command.
+  Client.didOpen("bar.cpp", "int x = FOO;");
+  EXPECT_THAT(Client.diagnostics("bar.cpp"),
+  llvm::ValueIs(testing::ElementsAre(
+  DiagMessage("Use of undeclared identifier 'BAR'";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/GlobalCompilationDatabase.h
===
--- clang-tools-extra/clangd/GlobalCompilationDatabase.h
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.h
@@ -103,8 +103,10 @@
 // (This is more expensive to check frequently, as we check many locations).
 std::chrono::steady_clock::duration RevalidateMissingAfter =
 std::chrono::seconds(30);
+// Used to provide per-file configuration.
+std::function ContextProvider;
 // Only look for a compilation database in this one fixed directory.
-llvm::Optional CompileCommandsDir;
+llvm::Optional CompileCommandsDir; // XXX
   };
 
   DirectoryBasedGlobalCompilationDatabase(const Options );
@@ -126,14 +128,9 @@
   Options Opts;
 
   class DirectoryCache;
-  // If there's an explicit CompileCommandsDir, cache of the CDB found there.
-  mutable std::unique_ptr OnlyDirCache;
-
   // Keyed by possibly-case-folded directory path.
   // We can hand out pointers as they're stable and entries are never removed.
-  // Empty if CompileCommandsDir is given (OnlyDirCache is used instead).
   mutable llvm::StringMap DirCaches;
-  // DirCaches access must be locked (unlike OnlyDirCache, which is threadsafe).
   mutable std::mutex DirCachesMutex;
 
   std::vector
Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
===
--- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "GlobalCompilationDatabase.h"
+#include "Config.h"
 #include "FS.h"
 #include "SourceCode.h"
 #include "support/Logger.h"
@@ -20,6 +21,7 @@
 #include "clang/Tooling/JSONCompilationDatabase.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallString.h"
@@ -362,8 +364,10 @@
 DirectoryBasedGlobalCompilationDatabase::
 DirectoryBasedGlobalCompilationDatabase(const Options )
 : Opts(Opts), Broadcaster(std::make_unique(*this)) {
-  if (Opts.CompileCommandsDir)
-OnlyDirCache = std::make_unique(*Opts.CompileCommandsDir);
+  if (!this->Opts.ContextProvider)
+this->Opts.ContextProvider = [](llvm::StringRef) {
+  return Context::current().clone();
+};
 }
 
 DirectoryBasedGlobalCompilationDatabase::
@@ -405,14 +409,6 @@
 #endif
 }
 
-static bool pathEqual(PathRef A, PathRef B) {
-#if defined(_WIN32) || defined(__APPLE__)
-  return A.equals_lower(B);
-#else
-  return A == B;
-#endif
-}
-
 std::vector
 DirectoryBasedGlobalCompilationDatabase::getDirectoryCaches(
 llvm::ArrayRef Dirs) const {
@@ -441,31 +437,42 @@
   assert(llvm::sys::path::is_absolute(Request.FileName) &&
  "path must be absolute");
 
+  std::string 

[PATCH] D95087: [clangd] Inject context provider rather than config into ClangdServer. NFC

2021-01-22 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG60cd75a098d4: [clangd] Inject context provider rather than 
config into ClangdServer. NFC (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D95087?vs=317995=318498#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95087

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/unittests/ClangdTests.cpp

Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -348,7 +348,8 @@
   } CfgProvider;
 
   auto Opts = ClangdServer::optsForTest();
-  Opts.ConfigProvider = 
+  Opts.ContextProvider =
+  ClangdServer::createConfiguredContextProvider(, nullptr);
   OverlayCDB CDB(/*Base=*/nullptr, /*FallbackFlags=*/{},
  tooling::ArgumentsAdjuster(CommandMangler::forTests()));
   MockFS FS;
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -80,6 +80,12 @@
 virtual void
 onBackgroundIndexProgress(const BackgroundQueue::Stats ) {}
   };
+  /// Creates a context provider that loads and installs config.
+  /// Errors in loading config are reported as diagnostics via Callbacks.
+  /// (This is typically used as ClangdServer::Options::ContextProvider).
+  static std::function
+  createConfiguredContextProvider(const config::Provider *Provider,
+  ClangdServer::Callbacks *);
 
   struct Options {
 /// To process requests asynchronously, ClangdServer spawns worker threads.
@@ -111,8 +117,16 @@
 /// If set, use this index to augment code completion results.
 SymbolIndex *StaticIndex = nullptr;
 
-/// If set, queried to obtain the configuration to handle each request.
-config::Provider *ConfigProvider = nullptr;
+/// If set, queried to derive a processing context for some work.
+/// Usually used to inject Config (see createConfiguredContextProvider).
+///
+/// When the provider is called, the active context will be that inherited
+/// from the request (e.g. addDocument()), or from the ClangdServer
+/// constructor if there is no such request (e.g. background indexing).
+///
+/// The path is an absolute path of the file being processed.
+/// If there is no particular file (e.g. project loading) then it is empty.
+std::function ContextProvider;
 
 /// The Options provider to use when running clang-tidy. If null, clang-tidy
 /// checks will be disabled.
@@ -343,19 +357,8 @@
   ArrayRef Ranges,
   Callback CB);
 
-  /// Derives a context for a task processing the specified source file.
-  /// This includes the current configuration (see Options::ConfigProvider).
-  /// The empty string means no particular file is the target.
-  /// Rather than called by each feature, this is exposed to the components
-  /// that control worker threads, like TUScheduler and BackgroundIndex.
-  /// This means it's OK to do some IO here, and it cuts across all features.
-  Context createProcessingContext(PathRef) const;
-  config::Provider *ConfigProvider = nullptr;
-
   const GlobalCompilationDatabase 
   const ThreadsafeFS 
-  Callbacks *ServerCallbacks = nullptr;
-  mutable std::mutex ConfigDiagnosticsMu;
 
   Path ResourceDir;
   // The index used to look up symbols. This could be:
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -133,14 +133,14 @@
   Opts.StorePreamblesInMemory = StorePreamblesInMemory;
   Opts.UpdateDebounce = UpdateDebounce;
   Opts.AsyncPreambleBuilds = AsyncPreambleBuilds;
+  Opts.ContextProvider = ContextProvider;
   return Opts;
 }
 
 ClangdServer::ClangdServer(const GlobalCompilationDatabase ,
const ThreadsafeFS , const Options ,
Callbacks *Callbacks)
-: ConfigProvider(Opts.ConfigProvider), CDB(CDB), TFS(TFS),
-  ServerCallbacks(Callbacks),
+: CDB(CDB), TFS(TFS),
   DynamicIdx(Opts.BuildDynamicSymbolIndex
  ? new FileIndex(Opts.HeavyweightDynamicSymbolIndex,
  Opts.CollectMainFileRefs)
@@ -153,14 +153,7 @@
   // FIXME(ioeric): this can be slow and we may be able to index on less
   // critical paths.
   WorkScheduler(
-  CDB,
-  [&, this] {
-

[clang-tools-extra] 60cd75a - [clangd] Inject context provider rather than config into ClangdServer. NFC

2021-01-22 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-01-22T14:34:30+01:00
New Revision: 60cd75a098d4f18d9c8903ddcb466b4e7deb0580

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

LOG: [clangd] Inject context provider rather than config into ClangdServer. NFC

This is a step towards allowing CDB behavior to being configurable.

Previously ClangdServer itself created the configs and installed them into
contexts. This was natural as it knows how to deal with resulting diagnostics.

However this prevents config being used in CDB, which must be created before
ClangdServer. So we extract the context provider (config loader) as a separate
object, which publishes diagnostics to a ClangdServer::Callbacks itself.

Now initialization looks like:
 - First create the config::Provider
 - Then create the ClangdLSPServer, passing config provider
 - Next, create the context provider, passing config provider + diagnostic 
callbacks
 - now create the CDB, passing context provider
 - finally create ClangdServer, passing CDB, context provider, and diagnostic 
callbacks

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

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/unittests/ClangdTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 4e5d9f8bf0fa..24d3a3509ca8 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -1469,6 +1469,12 @@ ClangdLSPServer::ClangdLSPServer(class Transport ,
   MsgHandler(new MessageHandler(*this)), TFS(TFS),
   SupportedSymbolKinds(defaultSymbolKinds()),
   SupportedCompletionItemKinds(defaultCompletionItemKinds()), Opts(Opts) {
+  if (Opts.ConfigProvider) {
+assert(!Opts.ContextProvider &&
+   "Only one of ConfigProvider and ContextProvider allowed!");
+this->Opts.ContextProvider = ClangdServer::createConfiguredContextProvider(
+Opts.ConfigProvider, this);
+  }
 
   // clang-format off
   MsgHandler->bind("initialize", ::onInitialize);

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index a41bc5666af3..3a46bd7b1bea 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -41,6 +41,8 @@ class SymbolIndex;
 class ClangdLSPServer : private ClangdServer::Callbacks {
 public:
   struct Options : ClangdServer::Options {
+/// Supplies configuration (overrides ClangdServer::ContextProvider).
+config::Provider *ConfigProvider = nullptr;
 /// Look for compilation databases, rather than using compile commands
 /// set via LSP (extensions) only.
 bool UseDirBasedCDB = true;

diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 32e08e688f44..4f9ea0499077 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -133,14 +133,14 @@ ClangdServer::Options::operator TUScheduler::Options() 
const {
   Opts.StorePreamblesInMemory = StorePreamblesInMemory;
   Opts.UpdateDebounce = UpdateDebounce;
   Opts.AsyncPreambleBuilds = AsyncPreambleBuilds;
+  Opts.ContextProvider = ContextProvider;
   return Opts;
 }
 
 ClangdServer::ClangdServer(const GlobalCompilationDatabase ,
const ThreadsafeFS , const Options ,
Callbacks *Callbacks)
-: ConfigProvider(Opts.ConfigProvider), CDB(CDB), TFS(TFS),
-  ServerCallbacks(Callbacks),
+: CDB(CDB), TFS(TFS),
   DynamicIdx(Opts.BuildDynamicSymbolIndex
  ? new FileIndex(Opts.HeavyweightDynamicSymbolIndex,
  Opts.CollectMainFileRefs)
@@ -153,14 +153,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase 
,
   // FIXME(ioeric): this can be slow and we may be able to index on less
   // critical paths.
   WorkScheduler(
-  CDB,
-  [&, this] {
-TUScheduler::Options O(Opts);
-O.ContextProvider = [this](PathRef P) {
-  return createProcessingContext(P);
-};
-return O;
-  }(),
+  CDB, TUScheduler::Options(Opts),
   std::make_unique(
   DynamicIdx.get(), Callbacks, Opts.TheiaSemanticHighlighting)) {
   // Adds an index to the stack, at higher priority than existing indexes.
@@ -181,9 +174,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase 
,
   if (Callbacks)
 Callbacks->onBackgroundIndexProgress(S);
 };
-

[PATCH] D95206: [clangd][SwapIndex] ensure that the old index is alive while we are using it via the function returned by `SwapIndex::indexedFiles()` call

2021-01-22 Thread Aleksandr Platonov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7388c3468595: [clangd][SwapIndex] ensure that the old index 
is alive while we are using it… (authored by ArcsinX).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95206

Files:
  clang-tools-extra/clangd/index/Index.cpp
  clang-tools-extra/clangd/index/Merge.cpp


Index: clang-tools-extra/clangd/index/Merge.cpp
===
--- clang-tools-extra/clangd/index/Merge.cpp
+++ clang-tools-extra/clangd/index/Merge.cpp
@@ -44,21 +44,23 @@
   SymbolSlab Dyn = std::move(DynB).build();
 
   llvm::DenseSet SeenDynamicSymbols;
-  auto DynamicContainsFile = Dynamic->indexedFiles();
-  More |= Static->fuzzyFind(Req, [&](const Symbol ) {
-// We expect the definition to see the canonical declaration, so it seems
-// to be enough to check only the definition if it exists.
-if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
- : S.CanonicalDeclaration.FileURI))
-  return;
-auto DynS = Dyn.find(S.ID);
-++StaticCount;
-if (DynS == Dyn.end())
-  return Callback(S);
-++MergedCount;
-SeenDynamicSymbols.insert(S.ID);
-Callback(mergeSymbol(*DynS, S));
-  });
+  {
+auto DynamicContainsFile = Dynamic->indexedFiles();
+More |= Static->fuzzyFind(Req, [&](const Symbol ) {
+  // We expect the definition to see the canonical declaration, so it seems
+  // to be enough to check only the definition if it exists.
+  if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
+   : S.CanonicalDeclaration.FileURI))
+return;
+  auto DynS = Dyn.find(S.ID);
+  ++StaticCount;
+  if (DynS == Dyn.end())
+return Callback(S);
+  ++MergedCount;
+  SeenDynamicSymbols.insert(S.ID);
+  Callback(mergeSymbol(*DynS, S));
+});
+  }
   SPAN_ATTACH(Tracer, "dynamic", DynamicCount);
   SPAN_ATTACH(Tracer, "static", StaticCount);
   SPAN_ATTACH(Tracer, "merged", MergedCount);
@@ -77,20 +79,22 @@
   Dynamic->lookup(Req, [&](const Symbol ) { B.insert(S); });
 
   auto RemainingIDs = Req.IDs;
-  auto DynamicContainsFile = Dynamic->indexedFiles();
-  Static->lookup(Req, [&](const Symbol ) {
-// We expect the definition to see the canonical declaration, so it seems
-// to be enough to check only the definition if it exists.
-if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
- : S.CanonicalDeclaration.FileURI))
-  return;
-const Symbol *Sym = B.find(S.ID);
-RemainingIDs.erase(S.ID);
-if (!Sym)
-  Callback(S);
-else
-  Callback(mergeSymbol(*Sym, S));
-  });
+  {
+auto DynamicContainsFile = Dynamic->indexedFiles();
+Static->lookup(Req, [&](const Symbol ) {
+  // We expect the definition to see the canonical declaration, so it seems
+  // to be enough to check only the definition if it exists.
+  if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
+   : S.CanonicalDeclaration.FileURI))
+return;
+  const Symbol *Sym = B.find(S.ID);
+  RemainingIDs.erase(S.ID);
+  if (!Sym)
+Callback(S);
+  else
+Callback(mergeSymbol(*Sym, S));
+});
+  }
   for (const auto  : RemainingIDs)
 if (const Symbol *Sym = B.find(ID))
   Callback(*Sym);
Index: clang-tools-extra/clangd/index/Index.cpp
===
--- clang-tools-extra/clangd/index/Index.cpp
+++ clang-tools-extra/clangd/index/Index.cpp
@@ -78,7 +78,13 @@
 
 llvm::unique_function
 SwapIndex::indexedFiles() const {
-  return snapshot()->indexedFiles();
+  // The index snapshot should outlive this method return value.
+  auto SnapShot = snapshot();
+  auto IndexedFiles = SnapShot->indexedFiles();
+  return [KeepAlive{std::move(SnapShot)},
+  IndexContainsFile{std::move(IndexedFiles)}](llvm::StringRef File) {
+return IndexContainsFile(File);
+  };
 }
 
 size_t SwapIndex::estimateMemoryUsage() const {


Index: clang-tools-extra/clangd/index/Merge.cpp
===
--- clang-tools-extra/clangd/index/Merge.cpp
+++ clang-tools-extra/clangd/index/Merge.cpp
@@ -44,21 +44,23 @@
   SymbolSlab Dyn = std::move(DynB).build();
 
   llvm::DenseSet SeenDynamicSymbols;
-  auto DynamicContainsFile = Dynamic->indexedFiles();
-  More |= Static->fuzzyFind(Req, [&](const Symbol ) {
-// We expect the definition to see the canonical declaration, so it seems
-// to be enough to check only the definition if it exists.
-if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
- : S.CanonicalDeclaration.FileURI))
-  return;
-auto DynS = Dyn.find(S.ID);
- 

[clang-tools-extra] 7388c34 - [clangd][SwapIndex] ensure that the old index is alive while we are using it via the function returned by `SwapIndex::indexedFiles()` call

2021-01-22 Thread Aleksandr Platonov via cfe-commits

Author: Aleksandr Platonov
Date: 2021-01-22T16:26:39+03:00
New Revision: 7388c34685954862e5f1fa4734f42f7087e697a2

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

LOG: [clangd][SwapIndex] ensure that the old index is alive while we are using 
it via the function returned by `SwapIndex::indexedFiles()` call

Without this patch the old index could be freed, but there still could be tries 
to access it via the function returned by `SwapIndex::indexedFiles()` call.
This leads to hard to reproduce clangd crashes at code completion.
This patch keeps the old index alive until the function returned by 
`SwapIndex::indexedFiles()` call is alive.

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/clangd/index/Index.cpp
clang-tools-extra/clangd/index/Merge.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/Index.cpp 
b/clang-tools-extra/clangd/index/Index.cpp
index 5da06f36ffe4..1b085140b4ff 100644
--- a/clang-tools-extra/clangd/index/Index.cpp
+++ b/clang-tools-extra/clangd/index/Index.cpp
@@ -78,7 +78,13 @@ void SwapIndex::relations(
 
 llvm::unique_function
 SwapIndex::indexedFiles() const {
-  return snapshot()->indexedFiles();
+  // The index snapshot should outlive this method return value.
+  auto SnapShot = snapshot();
+  auto IndexedFiles = SnapShot->indexedFiles();
+  return [KeepAlive{std::move(SnapShot)},
+  IndexContainsFile{std::move(IndexedFiles)}](llvm::StringRef File) {
+return IndexContainsFile(File);
+  };
 }
 
 size_t SwapIndex::estimateMemoryUsage() const {

diff  --git a/clang-tools-extra/clangd/index/Merge.cpp 
b/clang-tools-extra/clangd/index/Merge.cpp
index 0dd0d9e01518..6f369ed2edcf 100644
--- a/clang-tools-extra/clangd/index/Merge.cpp
+++ b/clang-tools-extra/clangd/index/Merge.cpp
@@ -44,21 +44,23 @@ bool MergedIndex::fuzzyFind(
   SymbolSlab Dyn = std::move(DynB).build();
 
   llvm::DenseSet SeenDynamicSymbols;
-  auto DynamicContainsFile = Dynamic->indexedFiles();
-  More |= Static->fuzzyFind(Req, [&](const Symbol ) {
-// We expect the definition to see the canonical declaration, so it seems
-// to be enough to check only the definition if it exists.
-if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
- : S.CanonicalDeclaration.FileURI))
-  return;
-auto DynS = Dyn.find(S.ID);
-++StaticCount;
-if (DynS == Dyn.end())
-  return Callback(S);
-++MergedCount;
-SeenDynamicSymbols.insert(S.ID);
-Callback(mergeSymbol(*DynS, S));
-  });
+  {
+auto DynamicContainsFile = Dynamic->indexedFiles();
+More |= Static->fuzzyFind(Req, [&](const Symbol ) {
+  // We expect the definition to see the canonical declaration, so it seems
+  // to be enough to check only the definition if it exists.
+  if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
+   : S.CanonicalDeclaration.FileURI))
+return;
+  auto DynS = Dyn.find(S.ID);
+  ++StaticCount;
+  if (DynS == Dyn.end())
+return Callback(S);
+  ++MergedCount;
+  SeenDynamicSymbols.insert(S.ID);
+  Callback(mergeSymbol(*DynS, S));
+});
+  }
   SPAN_ATTACH(Tracer, "dynamic", DynamicCount);
   SPAN_ATTACH(Tracer, "static", StaticCount);
   SPAN_ATTACH(Tracer, "merged", MergedCount);
@@ -77,20 +79,22 @@ void MergedIndex::lookup(
   Dynamic->lookup(Req, [&](const Symbol ) { B.insert(S); });
 
   auto RemainingIDs = Req.IDs;
-  auto DynamicContainsFile = Dynamic->indexedFiles();
-  Static->lookup(Req, [&](const Symbol ) {
-// We expect the definition to see the canonical declaration, so it seems
-// to be enough to check only the definition if it exists.
-if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
- : S.CanonicalDeclaration.FileURI))
-  return;
-const Symbol *Sym = B.find(S.ID);
-RemainingIDs.erase(S.ID);
-if (!Sym)
-  Callback(S);
-else
-  Callback(mergeSymbol(*Sym, S));
-  });
+  {
+auto DynamicContainsFile = Dynamic->indexedFiles();
+Static->lookup(Req, [&](const Symbol ) {
+  // We expect the definition to see the canonical declaration, so it seems
+  // to be enough to check only the definition if it exists.
+  if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
+   : S.CanonicalDeclaration.FileURI))
+return;
+  const Symbol *Sym = B.find(S.ID);
+  RemainingIDs.erase(S.ID);
+  if (!Sym)
+Callback(S);
+  else
+Callback(mergeSymbol(*Sym, S));
+});
+  }
   for (const auto  : RemainingIDs)
 if (const Symbol *Sym = B.find(ID))
 

[PATCH] D95225: [clang][cli] NFC: Pass CC1Option explicitly to BoolOption

2021-01-22 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
Herald added subscribers: dang, jfb.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When `Bool{F,G}Option` were introduced, they were designed after the existing 
`Opt{In,Out}FFlag` in that they implied `CC1Option` for the `ChangedBy` flag.

This means less typing, but can be misleading in situations when the `ResetBy` 
has explicit `CC1Option` and `ChangedBy` doesn't.

This patch stops implicitly putting `CC1Option` to `ChangedBy` flag.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95225

Files:
  clang/include/clang/Driver/Options.td

Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -473,38 +473,23 @@
  changed_by_flag, reset_by_flag, flag_suffix>;
 }
 
-/// Creates a BoolOption with the changing available on the CC1 command line.
-multiclass BoolCC1Option> {
-  defvar changed_by_cc1
-= ChangedBy;
-
-  defm NAME : BoolOption;
-}
-
-/// Creates a BoolOption where both of the flags are prefixed with "f", are in
-/// the Group, and the changing flag is also available on the CC1
-/// command line.
+/// Creates a BoolOption where both of the flags are prefixed with "f" and have
+/// the Group.
 multiclass BoolFOption> {
-  defm NAME : BoolCC1Option<"f", flag_base, kpm, defaults_to, changed_by,
-reset_by, both>,
+  defm NAME : BoolOption<"f", flag_base, kpm, defaults_to, changed_by, reset_by,
+ both>,
   Group;
 }
 
-// Creates a BoolOption where both of the flags are prefixed with "g", are in
-// the Group, and the changing flag is also available on the CC1
-// command line.
+// Creates a BoolOption where both of the flags are prefixed with "g" and have
+// the Group.
 multiclass BoolGOption> {
-  defm NAME : BoolCC1Option<"g", flag_base, kpm, defaults_to, changed_by,
-reset_by, both>,
+  defm NAME : BoolOption<"g", flag_base, kpm, defaults_to, changed_by, reset_by,
+ both>,
   Group;
 }
 
@@ -951,7 +936,7 @@
   " approximate transcendental functions">;
 defm gpu_rdc : BoolFOption<"gpu-rdc",
   LangOpts<"GPURelocatableDeviceCode">, DefaultsToFalse,
-  ChangedBy,
+  ChangedBy,
   ResetBy>;
 def : Flag<["-"], "fcuda-rdc">, Alias;
 def : Flag<["-"], "fno-cuda-rdc">, Alias;
@@ -971,17 +956,17 @@
   Group, Flags<[NoArgumentUnused, HelpHidden]>;
 defm hip_new_launch_api : BoolFOption<"hip-new-launch-api",
   LangOpts<"HIPUseNewLaunchAPI">, DefaultsToFalse,
-  ChangedBy, ResetBy,
+  ChangedBy, ResetBy,
   BothFlags<[], " new kernel launching API for HIP">>;
 defm gpu_allow_device_init : OptInFFlag<"gpu-allow-device-init",
   "Allow", "Don't allow", " device side init function in HIP">;
 defm gpu_defer_diag : BoolFOption<"gpu-defer-diag",
   LangOpts<"GPUDeferDiag">, DefaultsToFalse,
-  ChangedBy, ResetBy,
+  ChangedBy, ResetBy,
   BothFlags<[], " host/device related diagnostic messages for CUDA/HIP">>;
 defm gpu_exclude_wrong_side_overloads : BoolFOption<"gpu-exclude-wrong-side-overloads",
   LangOpts<"GPUExcludeWrongSideOverloads">, DefaultsToFalse,
-  ChangedBy,
+  ChangedBy,
   ResetBy,
   BothFlags<[HelpHidden], " in overloading resolution for CUDA/HIP">>;
 def gpu_max_threads_per_block_EQ : Joined<["--"], "gpu-max-threads-per-block=">,
@@ -1043,14 +1028,14 @@
 def fno_PIE : Flag<["-"], "fno-PIE">, Group;
 defm access_control : BoolFOption<"access-control",
   LangOpts<"AccessControl">, DefaultsToTrue,
-  ChangedBy,
+  ChangedBy,
   ResetBy>;
 def falign_functions : Flag<["-"], "falign-functions">, Group;
 def falign_functions_EQ : Joined<["-"], "falign-functions=">, Group;
 def fno_align_functions: Flag<["-"], "fno-align-functions">, Group;
 defm allow_editor_placeholders : BoolFOption<"allow-editor-placeholders",
   LangOpts<"AllowEditorPlaceholders">, DefaultsToFalse,
-  ChangedBy,
+  ChangedBy,
   ResetBy>;
 def fallow_unsupported : Flag<["-"], "fallow-unsupported">, Group;
 def fapple_kext : Flag<["-"], "fapple-kext">, Group, Flags<[CC1Option]>,
@@ -1058,7 +1043,7 @@
   MarshallingInfoFlag>;
 defm apple_pragma_pack : BoolFOption<"apple-pragma-pack",
   LangOpts<"ApplePragmaPack">, DefaultsToFalse,
-  ChangedBy,
+  ChangedBy,
   ResetBy>;
 def fxl_pragma_pack : Flag<["-"], "fxl-pragma-pack">, Group, Flags<[CC1Option]>,
   HelpText<"Enable IBM XL #pragma pack handling">;
@@ -1106,7 +1091,7 @@
   HelpText<"Embed placeholder LLVM IR data as a marker">;
 defm gnu_inline_asm : BoolFOption<"gnu-inline-asm",
   LangOpts<"GNUAsm">, DefaultsToTrue,
-  ChangedBy, ResetBy>;
+  ChangedBy, ResetBy>;
 
 def fprofile_sample_use : Flag<["-"], "fprofile-sample-use">, Group,
 Flags<[CoreOption]>;
@@ -1145,7 +1130,7 @@
 Alias;
 defm 

[PATCH] D94599: [clang][Tooling] Get rid of a hack in SymbolOccurrences, NFCI

2021-01-22 Thread Mikhail Maltsev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa0e30914f8c8: [clang][Tooling] Get rid of a hack in 
SymbolOccurrences, NFCI (authored by miyuki).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94599

Files:
  clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
  clang/lib/Basic/SourceLocation.cpp
  clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp


Index: clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
===
--- clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
+++ clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
@@ -21,13 +21,12 @@
  "mismatching number of locations and lengths");
   assert(!Locations.empty() && "no locations");
   if (Locations.size() == 1) {
-RangeOrNumRanges = SourceRange(
+new () SourceRange(
 Locations[0], Locations[0].getLocWithOffset(NamePieces[0].size()));
 return;
   }
   MultipleRanges = std::make_unique(Locations.size());
-  RangeOrNumRanges.setBegin(
-  SourceLocation::getFromRawEncoding(Locations.size()));
+  NumRanges = Locations.size();
   for (const auto  : llvm::enumerate(Locations)) {
 MultipleRanges[Loc.index()] = SourceRange(
 Loc.value(),
Index: clang/lib/Basic/SourceLocation.cpp
===
--- clang/lib/Basic/SourceLocation.cpp
+++ clang/lib/Basic/SourceLocation.cpp
@@ -42,6 +42,14 @@
 // SourceLocation
 
//===--===//
 
+static_assert(std::is_trivially_destructible::value,
+  "SourceLocation must be trivially destructible because it is "
+  "used in unions");
+
+static_assert(std::is_trivially_destructible::value,
+  "SourceRange must be trivially destructible because it is "
+  "used in unions");
+
 unsigned SourceLocation::getHashValue() const {
   return llvm::DenseMapInfo::getHashValue(ID);
 }
Index: clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
===
--- clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
+++ clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
@@ -69,17 +69,18 @@
   OccurrenceKind getKind() const { return Kind; }
 
   ArrayRef getNameRanges() const {
-if (MultipleRanges) {
-  return llvm::makeArrayRef(MultipleRanges.get(),
-RangeOrNumRanges.getBegin().getRawEncoding());
-}
-return RangeOrNumRanges;
+if (MultipleRanges)
+  return llvm::makeArrayRef(MultipleRanges.get(), NumRanges);
+return SingleRange;
   }
 
 private:
   OccurrenceKind Kind;
   std::unique_ptr MultipleRanges;
-  SourceRange RangeOrNumRanges;
+  union {
+SourceRange SingleRange;
+unsigned NumRanges;
+  };
 };
 
 using SymbolOccurrences = std::vector;


Index: clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
===
--- clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
+++ clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
@@ -21,13 +21,12 @@
  "mismatching number of locations and lengths");
   assert(!Locations.empty() && "no locations");
   if (Locations.size() == 1) {
-RangeOrNumRanges = SourceRange(
+new () SourceRange(
 Locations[0], Locations[0].getLocWithOffset(NamePieces[0].size()));
 return;
   }
   MultipleRanges = std::make_unique(Locations.size());
-  RangeOrNumRanges.setBegin(
-  SourceLocation::getFromRawEncoding(Locations.size()));
+  NumRanges = Locations.size();
   for (const auto  : llvm::enumerate(Locations)) {
 MultipleRanges[Loc.index()] = SourceRange(
 Loc.value(),
Index: clang/lib/Basic/SourceLocation.cpp
===
--- clang/lib/Basic/SourceLocation.cpp
+++ clang/lib/Basic/SourceLocation.cpp
@@ -42,6 +42,14 @@
 // SourceLocation
 //===--===//
 
+static_assert(std::is_trivially_destructible::value,
+  "SourceLocation must be trivially destructible because it is "
+  "used in unions");
+
+static_assert(std::is_trivially_destructible::value,
+  "SourceRange must be trivially destructible because it is "
+  "used in unions");
+
 unsigned SourceLocation::getHashValue() const {
   return llvm::DenseMapInfo::getHashValue(ID);
 }
Index: clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
===
--- clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
+++ clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
@@ -69,17 +69,18 @@
   

[clang] a0e3091 - [clang][Tooling] Get rid of a hack in SymbolOccurrences, NFCI

2021-01-22 Thread Mikhail Maltsev via cfe-commits

Author: Mikhail Maltsev
Date: 2021-01-22T13:01:41Z
New Revision: a0e30914f8c8bb60795a008ce2d9e3c0a4f9b7a2

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

LOG: [clang][Tooling] Get rid of a hack in SymbolOccurrences, NFCI

The class `SymbolOccurrences` can store either a single `SourceRange`
in-place or multiple `SourceRanges` on the heap. In the latter case
the number of source ranges is stored in the internal representation
of the beginning `SourceLocation` of the in-place `SourceRange`
object.

This change gets rid of such hack by placing `SourceRange` in a union
which holds either a valid `SourceRange` or an `unsigned int` (a number
of ranges).

The change also adds `static_assert`s that check that `SourceRange` and
`SourceLocation` are trivially destructible (this is required for the
current patch and for D94237 which has already been committed).

Reviewed By: MarkMurrayARM, simon_tatham

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

Added: 


Modified: 
clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
clang/lib/Basic/SourceLocation.cpp
clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp

Removed: 




diff  --git 
a/clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h 
b/clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
index 3b903cb822f3..c4bfaa9cc377 100644
--- a/clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
+++ b/clang/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
@@ -69,17 +69,18 @@ class SymbolOccurrence {
   OccurrenceKind getKind() const { return Kind; }
 
   ArrayRef getNameRanges() const {
-if (MultipleRanges) {
-  return llvm::makeArrayRef(MultipleRanges.get(),
-RangeOrNumRanges.getBegin().getRawEncoding());
-}
-return RangeOrNumRanges;
+if (MultipleRanges)
+  return llvm::makeArrayRef(MultipleRanges.get(), NumRanges);
+return SingleRange;
   }
 
 private:
   OccurrenceKind Kind;
   std::unique_ptr MultipleRanges;
-  SourceRange RangeOrNumRanges;
+  union {
+SourceRange SingleRange;
+unsigned NumRanges;
+  };
 };
 
 using SymbolOccurrences = std::vector;

diff  --git a/clang/lib/Basic/SourceLocation.cpp 
b/clang/lib/Basic/SourceLocation.cpp
index fde139932c40..6f6412028d77 100644
--- a/clang/lib/Basic/SourceLocation.cpp
+++ b/clang/lib/Basic/SourceLocation.cpp
@@ -42,6 +42,14 @@ void PrettyStackTraceLoc::print(raw_ostream ) const {
 // SourceLocation
 
//===--===//
 
+static_assert(std::is_trivially_destructible::value,
+  "SourceLocation must be trivially destructible because it is "
+  "used in unions");
+
+static_assert(std::is_trivially_destructible::value,
+  "SourceRange must be trivially destructible because it is "
+  "used in unions");
+
 unsigned SourceLocation::getHashValue() const {
   return llvm::DenseMapInfo::getHashValue(ID);
 }

diff  --git a/clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp 
b/clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
index 9e69d37e81ad..762864c953d8 100644
--- a/clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
+++ b/clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
@@ -21,13 +21,12 @@ SymbolOccurrence::SymbolOccurrence(const SymbolName , 
OccurrenceKind Kind,
  "mismatching number of locations and lengths");
   assert(!Locations.empty() && "no locations");
   if (Locations.size() == 1) {
-RangeOrNumRanges = SourceRange(
+new () SourceRange(
 Locations[0], Locations[0].getLocWithOffset(NamePieces[0].size()));
 return;
   }
   MultipleRanges = std::make_unique(Locations.size());
-  RangeOrNumRanges.setBegin(
-  SourceLocation::getFromRawEncoding(Locations.size()));
+  NumRanges = Locations.size();
   for (const auto  : llvm::enumerate(Locations)) {
 MultipleRanges[Loc.index()] = SourceRange(
 Loc.value(),



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


[PATCH] D92221: Don't delete default constructor of PathDiagnosticConsumerOptions

2021-01-22 Thread Moritz Sichert via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe16959c9b855: Dont delete default constructor of 
PathDiagnosticConsumerOptions (authored by MoritzS).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92221

Files:
  clang/include/clang/Analysis/PathDiagnostic.h


Index: clang/include/clang/Analysis/PathDiagnostic.h
===
--- clang/include/clang/Analysis/PathDiagnostic.h
+++ clang/include/clang/Analysis/PathDiagnostic.h
@@ -68,11 +68,11 @@
   /// Whether to include additional information about macro expansions
   /// with the diagnostics, because otherwise they can be hard to obtain
   /// without re-compiling the program under analysis.
-  bool ShouldDisplayMacroExpansions;
+  bool ShouldDisplayMacroExpansions = false;
 
   /// Whether to include LLVM statistics of the process in the diagnostic.
   /// Useful for profiling the tool on large real-world codebases.
-  bool ShouldSerializeStats;
+  bool ShouldSerializeStats = false;
 
   /// If the consumer intends to produce multiple output files, should it
   /// use randomly generated file names for these files (with the tiny risk of
@@ -82,21 +82,19 @@
   /// because deterministic mode is always superior when done right, but
   /// for some consumers this mode is experimental and needs to be
   /// off by default.
-  bool ShouldWriteStableReportFilename;
+  bool ShouldWriteStableReportFilename = false;
 
   /// Whether the consumer should treat consumed diagnostics as hard errors.
   /// Useful for breaking your build when issues are found.
-  bool ShouldDisplayWarningsAsErrors;
+  bool ShouldDisplayWarningsAsErrors = false;
 
   /// Whether the consumer should attempt to rewrite the source file
   /// with fix-it hints attached to the diagnostics it consumes.
-  bool ShouldApplyFixIts;
+  bool ShouldApplyFixIts = false;
 
   /// Whether the consumer should present the name of the entity that emitted
   /// the diagnostic (eg., a checker) so that the user knew how to disable it.
-  bool ShouldDisplayDiagnosticName;
-
-  PathDiagnosticConsumerOptions() = delete;
+  bool ShouldDisplayDiagnosticName = false;
 };
 
 class PathDiagnosticConsumer {


Index: clang/include/clang/Analysis/PathDiagnostic.h
===
--- clang/include/clang/Analysis/PathDiagnostic.h
+++ clang/include/clang/Analysis/PathDiagnostic.h
@@ -68,11 +68,11 @@
   /// Whether to include additional information about macro expansions
   /// with the diagnostics, because otherwise they can be hard to obtain
   /// without re-compiling the program under analysis.
-  bool ShouldDisplayMacroExpansions;
+  bool ShouldDisplayMacroExpansions = false;
 
   /// Whether to include LLVM statistics of the process in the diagnostic.
   /// Useful for profiling the tool on large real-world codebases.
-  bool ShouldSerializeStats;
+  bool ShouldSerializeStats = false;
 
   /// If the consumer intends to produce multiple output files, should it
   /// use randomly generated file names for these files (with the tiny risk of
@@ -82,21 +82,19 @@
   /// because deterministic mode is always superior when done right, but
   /// for some consumers this mode is experimental and needs to be
   /// off by default.
-  bool ShouldWriteStableReportFilename;
+  bool ShouldWriteStableReportFilename = false;
 
   /// Whether the consumer should treat consumed diagnostics as hard errors.
   /// Useful for breaking your build when issues are found.
-  bool ShouldDisplayWarningsAsErrors;
+  bool ShouldDisplayWarningsAsErrors = false;
 
   /// Whether the consumer should attempt to rewrite the source file
   /// with fix-it hints attached to the diagnostics it consumes.
-  bool ShouldApplyFixIts;
+  bool ShouldApplyFixIts = false;
 
   /// Whether the consumer should present the name of the entity that emitted
   /// the diagnostic (eg., a checker) so that the user knew how to disable it.
-  bool ShouldDisplayDiagnosticName;
-
-  PathDiagnosticConsumerOptions() = delete;
+  bool ShouldDisplayDiagnosticName = false;
 };
 
 class PathDiagnosticConsumer {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e16959c - Don't delete default constructor of PathDiagnosticConsumerOptions

2021-01-22 Thread Moritz Sichert via cfe-commits

Author: Moritz Sichert
Date: 2021-01-22T13:42:38+01:00
New Revision: e16959c9b8553a60ec5e9aa55d101154d5805292

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

LOG: Don't delete default constructor of PathDiagnosticConsumerOptions

This type is used as an aggregate, i.e. it has no member functions.
Starting with C++20 types with deleted default constructors are not
aggregate types anymore which means that aggregate initialization will
not work for this class anymore. This leads to a compile error in
clang::AnalyzerOptions::getDiagOpts() for example.

Also set the boolean flags to false by default to avoid undefined
behavior. Previously this was prevented by deleting the default
constructor, now we explicitly initialize them.

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

Added: 


Modified: 
clang/include/clang/Analysis/PathDiagnostic.h

Removed: 




diff  --git a/clang/include/clang/Analysis/PathDiagnostic.h 
b/clang/include/clang/Analysis/PathDiagnostic.h
index 544e9f4662d3..539aa20b8168 100644
--- a/clang/include/clang/Analysis/PathDiagnostic.h
+++ b/clang/include/clang/Analysis/PathDiagnostic.h
@@ -68,11 +68,11 @@ struct PathDiagnosticConsumerOptions {
   /// Whether to include additional information about macro expansions
   /// with the diagnostics, because otherwise they can be hard to obtain
   /// without re-compiling the program under analysis.
-  bool ShouldDisplayMacroExpansions;
+  bool ShouldDisplayMacroExpansions = false;
 
   /// Whether to include LLVM statistics of the process in the diagnostic.
   /// Useful for profiling the tool on large real-world codebases.
-  bool ShouldSerializeStats;
+  bool ShouldSerializeStats = false;
 
   /// If the consumer intends to produce multiple output files, should it
   /// use randomly generated file names for these files (with the tiny risk of
@@ -82,21 +82,19 @@ struct PathDiagnosticConsumerOptions {
   /// because deterministic mode is always superior when done right, but
   /// for some consumers this mode is experimental and needs to be
   /// off by default.
-  bool ShouldWriteStableReportFilename;
+  bool ShouldWriteStableReportFilename = false;
 
   /// Whether the consumer should treat consumed diagnostics as hard errors.
   /// Useful for breaking your build when issues are found.
-  bool ShouldDisplayWarningsAsErrors;
+  bool ShouldDisplayWarningsAsErrors = false;
 
   /// Whether the consumer should attempt to rewrite the source file
   /// with fix-it hints attached to the diagnostics it consumes.
-  bool ShouldApplyFixIts;
+  bool ShouldApplyFixIts = false;
 
   /// Whether the consumer should present the name of the entity that emitted
   /// the diagnostic (eg., a checker) so that the user knew how to disable it.
-  bool ShouldDisplayDiagnosticName;
-
-  PathDiagnosticConsumerOptions() = delete;
+  bool ShouldDisplayDiagnosticName = false;
 };
 
 class PathDiagnosticConsumer {



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


[PATCH] D95221: [clang][cli] NFC: Move prefix to the front of BoolOption

2021-01-22 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
Herald added subscribers: dang, jfb.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The prefix used to be the last (optional) argument to BoolOption. This decision 
was made with the expectation that only few command line options would need to 
pass it explicitly instead of using Bool{F,G}Option. It turns out that a 
considerable number of options don't conform to Bool{F,G}Option and need to 
provide the prefix anyways. This sometimes requires to explicitly pass 
`BothFlags<[]>`.

This patch makes prefix the first parameter, so it now directly precedes the 
spelling base string. Now 8 options dropped `BothFlags<[]>` and only two 
options (`pthread` and `emit_llvm_uselists`) need to pass an empty prefix.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95221

Files:
  clang/include/clang/Driver/Options.td

Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -375,10 +375,10 @@
 // BoolOption is the API that should be used most of the time. Use this only
 // when you need more control (e.g. to represent a marshalled option whose
 // keypath defaults to an arbitrarily complex boolean expression).
-multiclass BoolOptionBase,
-  string prefix = ""> {
+  FlagDefSuffix flags_suffix = FlagDefSuffix<[], "">> {
   defvar flag1 = FlagDefExpanded.Result,
  prefix, NAME, spelling_base>;
 
@@ -436,29 +436,28 @@
 /// Creates two command line flags that control the same boolean keypath.
 ///
 /// Example:
-///   defm my_boolean_option : BoolOption<"my-boolean-option",
+///   defm my_boolean_option : BoolOption<"f", "my-boolean-option",
 /// CodeGenOpts<"MyBooleanOption">, DefaultsToFalse,
 /// ChangedBy,
 /// ResetBy,
 /// BothFlags<[CoreOption], " my boolean option.">;
 ///
 ///   The Clang driver now knows two new command line flags: the "positive"
-///   -my-boolean-option and the "negative" -no-my-boolean-option. The positive
-///   flag is also available on the CC1 command line.
+///   -fmy-boolean-option and the "negative" -fno-my-boolean-option. The
+///   positive flag is also available on the CC1 command line.
 ///
 ///   * When the command line contains neither of the flags, the keypath value
 /// defaults to false.
 ///   * When the command line contains the positive -my-boolean-option, the
 /// keypath value changes to true.
-///   * When the command line contains the negative -no-my-bool-option, the
+///   * When the command line contains the negative -fno-my-bool-option, the
 /// keypath value resets to false.
 ///
 ///   The help text for -my-boolean-option is "Enable my boolean option." and
-///   "Disable my boolean option." for -no-my-boolean-option.
-multiclass BoolOption,
-  string name_prefix = ""> {
+  ResetBy reset_by, BothFlags both = BothFlags<[], "">> {
   defvar default = Default;
 
   defvar changed_by_flag = FlagDef;
 
-  defm NAME : BoolOptionBase;
+  defm NAME : BoolOptionBase;
 }
 
 /// Creates a BoolOption with the changing available on the CC1 command line.
-multiclass BoolCC1Option,
- string name_prefix = ""> {
+ ResetBy reset_by, BothFlags both = BothFlags<[], "">> {
   defvar changed_by_cc1
 = ChangedBy;
 
-  defm NAME : BoolOption;
+  defm NAME : BoolOption;
 }
 
 /// Creates a BoolOption where both of the flags are prefixed with "f", are in
@@ -494,8 +492,8 @@
 multiclass BoolFOption> {
-  defm NAME : BoolCC1Option,
+  defm NAME : BoolCC1Option<"f", flag_base, kpm, defaults_to, changed_by,
+reset_by, both>,
   Group;
 }
 
@@ -505,8 +503,8 @@
 multiclass BoolGOption> {
-  defm NAME : BoolCC1Option,
+  defm NAME : BoolCC1Option<"g", flag_base, kpm, defaults_to, changed_by,
+reset_by, both>,
   Group;
 }
 
@@ -1269,11 +1267,11 @@
   Flags<[CoreOption, CC1Option]>, HelpText<"Place uninitialized global variables in a common block">,
   MarshallingInfoNegativeFlag>;
 def fcompile_resource_EQ : Joined<["-"], "fcompile-resource=">, Group;
-defm complete_member_pointers : BoolOption<"complete-member-pointers",
+defm complete_member_pointers : BoolOption<"f", "complete-member-pointers",
   LangOpts<"CompleteMemberPointers">, DefaultsToFalse,
   ChangedBy, ResetBy,
   BothFlags<[CoreOption], " member pointer base types to be complete if they"
-" would be significant under the Microsoft ABI">, "f">,
+" would be significant under the Microsoft ABI">>,
   Group;
 def fcf_runtime_abi_EQ : Joined<["-"], "fcf-runtime-abi=">, Group,
 Flags<[CC1Option]>, 

[PATCH] D95016: [Clang][RISCV] Add custom TableGen backend for riscv-vector intrinsics.

2021-01-22 Thread Zakk Chen via Phabricator via cfe-commits
khchen updated this revision to Diff 318447.
khchen marked 2 inline comments as done.
khchen added a comment.

1. do not need to manually define new op in gen-rvv-tests.py.
2. do not need to manually add new op define in ALL marco.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95016

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/include/clang/Basic/CMakeLists.txt
  clang/include/clang/Basic/riscv_vector.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/test/CodeGen/RISCV/riscv-rvv-intrinsics-generic/vadd.c
  clang/test/CodeGen/RISCV/riscv-rvv-intrinsics-generic/vfadd.c
  clang/test/CodeGen/RISCV/riscv-rvv-intrinsics/vadd.c
  clang/test/CodeGen/RISCV/riscv-rvv-intrinsics/vfadd.c
  clang/test/CodeGen/RISCV/vadd.c
  clang/test/Headers/riscv-vector-header.c
  clang/utils/TableGen/CMakeLists.txt
  clang/utils/TableGen/RISCVVEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h
  clang/utils/TestUtils/gen-rvv-tests.py
  llvm/docs/CommandGuide/tblgen.rst

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


  1   2   >