[PATCH] D70804: [Frontend] Allow OpenMP offloading to aarch64

2019-11-29 Thread Bryan Chan via Phabricator via cfe-commits
bryanpkc updated this revision to Diff 231582.
bryanpkc added a comment.

Add tests for -fopenmp-targets=.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70804

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/OpenMP/openmp_offload_registration.cpp
  clang/test/OpenMP/target_messages.cpp


Index: clang/test/OpenMP/target_messages.cpp
===
--- clang/test/OpenMP/target_messages.cpp
+++ clang/test/OpenMP/target_messages.cpp
@@ -1,11 +1,13 @@
 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 -o - %s
-// RUN: not %clang_cc1 -fopenmp -std=c++11 -fopenmp-targets=aaa-bbb-ccc-ddd -o 
- %s 2>&1 | FileCheck %s
-
 // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++11 -o - %s
+
+// RUN: not %clang_cc1 -fopenmp -std=c++11 -fopenmp-targets=aaa-bbb-ccc-ddd -o 
- %s 2>&1 | FileCheck %s
 // CHECK: error: OpenMP target is invalid: 'aaa-bbb-ccc-ddd'
+
 // RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx64-nvidia-cuda -o - %s 
2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
 // RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx-nvidia-cuda -o - %s 
2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
 // CHECK-UNSUPPORTED-HOST-TARGET: error: The target 
'{{nvptx64-nvidia-cuda|nvptx-nvidia-cuda}}' is not a supported OpenMP host 
target.
+
 // RUN: not %clang_cc1 -fopenmp -std=c++11 -fopenmp-targets=hexagon-linux-gnu 
-o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-DEVICE-TARGET %s
 // CHECK-UNSUPPORTED-DEVICE-TARGET: OpenMP target is invalid: 
'hexagon-linux-gnu'
 
Index: clang/test/OpenMP/openmp_offload_registration.cpp
===
--- clang/test/OpenMP/openmp_offload_registration.cpp
+++ clang/test/OpenMP/openmp_offload_registration.cpp
@@ -1,5 +1,8 @@
-// Test for offload registration code for two targets
+// Test offload registration for two targets, and test offload target 
validation.
 // RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-unknown-linux-gnu 
-fopenmp-targets=x86_64-pc-linux-gnu,powerpc64le-ibm-linux-gnu -emit-llvm %s -o 
- | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-unknown-linux-gnu 
-fopenmp-targets=aarch64-unknown-linux-gnu,powerpc64-ibm-linux-gnu -emit-llvm 
%s -o - | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-unknown-linux-gnu 
-fopenmp-targets=i686-pclinux-gnu,powerpc-ibm-linux-gnu -emit-llvm %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-unknown-linux-gnu 
-fopenmp-targets=nvptx-nvidia-cuda,nvptx64-nvidia-cuda -emit-llvm %s -o - | 
FileCheck %s
 // expected-no-diagnostics
 
 void foo() {
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3070,7 +3070,8 @@
   llvm::Triple TT(A->getValue(i));
 
   if (TT.getArch() == llvm::Triple::UnknownArch ||
-  !(TT.getArch() == llvm::Triple::ppc ||
+  !(TT.getArch() == llvm::Triple::aarch64 ||
+TT.getArch() == llvm::Triple::ppc ||
 TT.getArch() == llvm::Triple::ppc64 ||
 TT.getArch() == llvm::Triple::ppc64le ||
 TT.getArch() == llvm::Triple::nvptx ||


Index: clang/test/OpenMP/target_messages.cpp
===
--- clang/test/OpenMP/target_messages.cpp
+++ clang/test/OpenMP/target_messages.cpp
@@ -1,11 +1,13 @@
 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 -o - %s
-// RUN: not %clang_cc1 -fopenmp -std=c++11 -fopenmp-targets=aaa-bbb-ccc-ddd -o - %s 2>&1 | FileCheck %s
-
 // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++11 -o - %s
+
+// RUN: not %clang_cc1 -fopenmp -std=c++11 -fopenmp-targets=aaa-bbb-ccc-ddd -o - %s 2>&1 | FileCheck %s
 // CHECK: error: OpenMP target is invalid: 'aaa-bbb-ccc-ddd'
+
 // RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx64-nvidia-cuda -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
 // RUN: not %clang_cc1 -fopenmp -std=c++11 -triple nvptx-nvidia-cuda -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-HOST-TARGET %s
 // CHECK-UNSUPPORTED-HOST-TARGET: error: The target '{{nvptx64-nvidia-cuda|nvptx-nvidia-cuda}}' is not a supported OpenMP host target.
+
 // RUN: not %clang_cc1 -fopenmp -std=c++11 -fopenmp-targets=hexagon-linux-gnu -o - %s 2>&1 | FileCheck --check-prefix CHECK-UNSUPPORTED-DEVICE-TARGET %s
 // CHECK-UNSUPPORTED-DEVICE-TARGET: OpenMP target is invalid: 'hexagon-linux-gnu'
 
Index: clang/test/OpenMP/openmp_offload_registration.cpp
===
--- clang/test/OpenMP/openmp_offload_registration.cpp
+++ clang/test/OpenMP/openmp_offload_registration.cpp
@@ -1,5 +1,8 @@
-// Test for offload registration code f

[PATCH] D70512: [clangd] Rethink how SelectionTree deals with macros and #includes.

2019-11-29 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

That particular bot does GN builds, but these test failures repro in the cmake 
build for me on both macs I tried. (Remember that the official mac bots are on 
greendragon, not on buildbot -- I'd guess it shows there too.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70512



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


[PATCH] D69620: Add AIX assembler support

2019-11-29 Thread Steven Wan via Phabricator via cfe-commits
stevewan marked 3 inline comments as done.
stevewan added inline comments.



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:68
+  if (Inputs.size() != 1)
+llvm_unreachable("Invalid number of input files.");
+  const InputInfo &II = Inputs[0];

hubert.reinterpretcast wrote:
> `llvm_unreachable` is not the right solution if this can be reached by "user 
> error". We should produce a proper error message.
One risky condition I can think of is the user passes in multiple assembly 
sources to the driver, which may lead to multiple assembler inputs. To verify 
how the driver handles such a case, I added a new test into `aix-as.c` below, 
whose results suggested that this is okay because the driver would invoke `as` 
for each and every input files respectively. Looking into the code, the driver 
would construct an action list for each input files individually, which again 
matches the behaviour we observed in the testing results. That said, I believe 
the `llvm_unreachable` here is indeed not reachable by "user errors" like this, 
and if it triggers, it's likly an internal error. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69620



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


[PATCH] D69620: Add AIX assembler support

2019-11-29 Thread Steven Wan via Phabricator via cfe-commits
stevewan updated this revision to Diff 231579.
stevewan added a comment.
Herald added subscribers: kbarton, nemanjai.

Add more input file handling

1. Check if the input file is of type Filename or Nothing, throw assertion 
otherwise.
2. Add a test case to verify the correct behaviour of assembler invocation when 
multiple input files are specified by the user.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69620

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/AIX.h
  clang/test/Driver/Inputs/aix_ppc_tree/dummy0.s
  clang/test/Driver/Inputs/aix_ppc_tree/dummy1.s
  clang/test/Driver/Inputs/aix_ppc_tree/dummy2.s
  clang/test/Driver/aix-as.c

Index: clang/test/Driver/aix-as.c
===
--- /dev/null
+++ clang/test/Driver/aix-as.c
@@ -0,0 +1,73 @@
+// General tests that as(1) invocations on AIX targets are sane. Note that we
+// only test assembler functionalities in this suite.
+
+// Check powerpc-ibm-aix7.1.0.0, 32-bit.
+// RUN: %clang -no-canonical-prefixes %s -### -c -o %t.o 2>&1 \
+// RUN: -target powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-AS32 %s
+// CHECK-AS32-NOT: warning:
+// CHECK-AS32: {{.*}}clang{{(.exe)?}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-AS32: "{{.*}}as{{(.exe)?}}" 
+// CHECK-AS32: "-a32" 
+// CHECK-AS32: "-u" 
+// CHECK-AS32: "-many" 
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit.
+// RUN: %clang -no-canonical-prefixes %s -### -c -o %t.o 2>&1 \
+// RUN: -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-AS64 %s
+// CHECK-AS64-NOT: warning:
+// CHECK-AS64: {{.*}}clang{{(.exe)?}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
+// CHECK-AS64: "{{.*}}as{{(.exe)?}}" 
+// CHECK-AS64: "-a64" 
+// CHECK-AS64: "-u" 
+// CHECK-AS64: "-many"
+
+
+// Check powerpc-ibm-aix7.1.0.0, 32-bit. -Xassembler  option. 
+// RUN: %clang -no-canonical-prefixes %s -### -c -o %t.o 2>&1 \
+// RUN: -Xassembler -w \
+// RUN: -target powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-AS32-Xassembler %s
+// CHECK-AS32-Xassembler-NOT: warning:
+// CHECK-AS32-Xassembler: {{.*}}clang{{(.exe)?}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-AS32-Xassembler: "{{.*}}as{{(.exe)?}}" 
+// CHECK-AS32-Xassembler: "-a32" 
+// CHECK-AS32-Xassembler: "-u" 
+// CHECK-AS32-Xassembler: "-many"
+// CHECK-AS32-Xassembler: "-w"
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -Wa,, option.
+// RUN: %clang -no-canonical-prefixes %s -### -c -o %t.o 2>&1 \
+// RUN: -Wa,-v,-w \
+// RUN: -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-AS64-Wa %s
+// CHECK-AS64-Wa-NOT: warning:
+// CHECK-AS64-Wa: {{.*}}clang{{(.exe)?}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
+// CHECK-AS64-Wa: "{{.*}}as{{(.exe)?}}" 
+// CHECK-AS64-Wa: "-a64" 
+// CHECK-AS64-Wa: "-u" 
+// CHECK-AS64-Wa: "-many"
+// CHECK-AS64-Wa: "-v"
+// CHECK-AS64-Wa: "-w"
+
+// Check powerpc-ibm-aix7.1.0.0, 32-bit. Multiple input files.
+// RUN: %clang -no-canonical-prefixes -### -c \
+// RUN: %S/Inputs/aix_ppc_tree/dummy0.s \
+// RUN: %S/Inputs/aix_ppc_tree/dummy1.s \
+// RUN: %S/Inputs/aix_ppc_tree/dummy2.s 2>&1 \
+// RUN: -target powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-AS32-MultiInput %s
+// CHECK-AS32-MultiInput-NOT: warning:
+// CHECK-AS32-MultiInput: "{{.*}}as{{(.exe)?}}"
+// CHECK-AS32-MultiInput: "-a32"
+// CHECK-AS32-MultiInput: "-u"
+// CHECK-AS32-MultiInput: "-many"
+// CHECK-AS32-MultiInput: "{{.*}}as{{(.exe)?}}"
+// CHECK-AS32-MultiInput: "-a32"
+// CHECK-AS32-MultiInput: "-u"
+// CHECK-AS32-MultiInput: "-many"
+// CHECK-AS32-MultiInput: "{{.*}}as{{(.exe)?}}"
+// CHECK-AS32-MultiInput: "-a32"
+// CHECK-AS32-MultiInput: "-u"
+// CHECK-AS32-MultiInput: "-many"
Index: clang/lib/Driver/ToolChains/AIX.h
===
--- clang/lib/Driver/ToolChains/AIX.h
+++ clang/lib/Driver/ToolChains/AIX.h
@@ -16,10 +16,21 @@
 namespace driver {
 namespace tools {
 
-/// aix -- Directly call system default linker.
-// TODO: Enable direct call to system default assembler.
+/// aix -- Directly call system default assembler and linker.
 namespace aix {
 
+class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
+public:
+  Assembler(const ToolChain &TC) : Tool("aix::Assembler", "assembler", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation &C, const JobAction &JA,
+const InputInfo &Output, const InputInfoList &Inputs,
+const llvm::opt::ArgList &TCArgs,
+const char *LinkingOutput) const override;
+};
+
 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
 public:
   Linker(const ToolChain &TC) : Tool("aix::Linker", "linker", TC) {}
@@ -53,6 +6

[PATCH] D67463: [MS] Warn when shadowing template parameters under -fms-compatibility

2019-11-29 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

You probably already know this, but the behavior between MSVC & Clang is 
different as to the value of the constant (testcase for PR43265).
See: https://godbolt.org/z/y4uvgp
Clang gives 0, while MSVC gives 5. This incompatibility is a potential source 
of failure, one of our tests broke because of that.

Do you think this patch could/should be back-ported into 9.0.1? At least having 
the warning gives an indication about a potential failure.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D67463



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


[PATCH] D70819: [ASTImporter] Support functions with placeholder return types ...

2019-11-29 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin added a comment.

Hello Gabor,
That's an interesting case, thank for fixing this!




Comment at: clang/lib/AST/ASTImporter.cpp:3008
+// which is equal to the given DC.
+bool isAncestorDeclContextOf(DeclContext *DC, Decl *D) {
+  DeclContext *DCi = D->getDeclContext();

 ASTImporter is not very const-friendly, but this function is pure, so I think 
it's better to const-qualify the parameters.



Comment at: clang/lib/AST/ASTImporter.cpp:3020
+  QualType FromTy = D->getType();
+  const FunctionProtoType *FromFPT = FromTy->getAs();
+  if (AutoType *AutoT = FromFPT->getReturnType()->getContainedAutoType()) {

Is it possible for getAs() to return nullptr at this point?



Comment at: clang/lib/AST/ASTImporter.cpp:3174
+  bool UsedDifferentProtoType = false;
+  const auto *FromFPT = FromTy->getAs();
+  if (FromFPT) {

If FromFPT is not used outside of the condition, we can move the initialization 
inside if().



Comment at: clang/unittests/AST/ASTImporterTest.cpp:5609
+  R"(
+  auto X = [](long l){
+using int_type = long;

Nit: a space before '{'.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:5625
+  // parsed libcxx/src/filesystem/directory_iterator.cpp, but could not reduce
+  // that with creduce, because after preprocessing, the AST no longer
+  // contained the TypeAlias as a return type of the lambda.

That's interesting. Have you tried '-frewrite-includes' for expanding 
inclusions only without macro expansion?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70819



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


[PATCH] D64305: [clangd] Add path mappings functionality

2019-11-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Sorry, I was out for a bit and this fell off my radar.
It looks good, but the last snapshot seems to have reverted some earlier 
changes (book vs enum, some doxygen comments etc). Do you know what's up there?

Either way I should be able to apply this on Monday


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

https://reviews.llvm.org/D64305



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


[PATCH] D64305: [clangd] Add path mappings functionality

2019-11-29 Thread William Wagner via Phabricator via cfe-commits
wwagner19 added a comment.

Hey @sammccall, any update here?


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

https://reviews.llvm.org/D64305



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


[PATCH] D70512: [clangd] Rethink how SelectionTree deals with macros and #includes.

2019-11-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Reverted as 905b002c139f039a32ab9bf1fad63d745d12423f 


@thakis any information available about that bot configuration?
I'm not seeing any failures on "official" ones, I can't reproduce locally, and 
the failures don't make a lot of sense to me (lots of off-by-ones everywhere 
maybe?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70512



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


[PATCH] D70864: update trailing newline treatment in clang-format.py

2019-11-29 Thread Paul Seyfert via Phabricator via cfe-commits
pseyfert updated this revision to Diff 231568.
pseyfert added a comment.

added comments


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

https://reviews.llvm.org/D70864

Files:
  clang/tools/clang-format/clang-format.py


Index: clang/tools/clang-format/clang-format.py
===
--- clang/tools/clang-format/clang-format.py
+++ clang/tools/clang-format/clang-format.py
@@ -70,7 +70,8 @@
   # Get the current text.
   encoding = vim.eval("&encoding")
   buf = get_buffer(encoding)
-  text = '\n'.join(buf)
+  # Join the buffer into a single string with a terminating newline
+  text = '\n'.join(buf) + '\n'
 
   # Determine range to format.
   if vim.eval('exists("l:lines")') == '1':
@@ -129,7 +130,10 @@
   else:
 lines = stdout.decode(encoding).split('\n')
 output = json.loads(lines[0])
-lines = lines[1:]
+# Strip off the trailing newline (added above).
+# This maintains trailing empty lines present in the buffer if
+# the -lines specification requests them to remain unchanged.
+lines = lines[1:-1]
 sequence = difflib.SequenceMatcher(None, buf, lines)
 for op in reversed(sequence.get_opcodes()):
   if op[0] is not 'equal':


Index: clang/tools/clang-format/clang-format.py
===
--- clang/tools/clang-format/clang-format.py
+++ clang/tools/clang-format/clang-format.py
@@ -70,7 +70,8 @@
   # Get the current text.
   encoding = vim.eval("&encoding")
   buf = get_buffer(encoding)
-  text = '\n'.join(buf)
+  # Join the buffer into a single string with a terminating newline
+  text = '\n'.join(buf) + '\n'
 
   # Determine range to format.
   if vim.eval('exists("l:lines")') == '1':
@@ -129,7 +130,10 @@
   else:
 lines = stdout.decode(encoding).split('\n')
 output = json.loads(lines[0])
-lines = lines[1:]
+# Strip off the trailing newline (added above).
+# This maintains trailing empty lines present in the buffer if
+# the -lines specification requests them to remain unchanged.
+lines = lines[1:-1]
 sequence = difflib.SequenceMatcher(None, buf, lines)
 for op in reversed(sequence.get_opcodes()):
   if op[0] is not 'equal':
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 905b002 - Revert "[clangd] Rethink how SelectionTree deals with macros and #includes."

2019-11-29 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2019-11-29T19:59:02+01:00
New Revision: 905b002c139f039a32ab9bf1fad63d745d12423f

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

LOG: Revert "[clangd] Rethink how SelectionTree deals with macros and 
#includes."

This reverts commit 19daa21f841ad45290c923689ee3d25198651a4c.

It causes a bunch of failures on a bot that I've been unable to
reproduce so far:
http://45.33.8.238/mac/3308/step_7.txt

Added: 


Modified: 
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/Selection.h
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang-tools-extra/clangd/unittests/TweakTests.cpp
clang/include/clang/Tooling/Syntax/Tokens.h
clang/lib/Tooling/Syntax/Tokens.cpp
clang/unittests/Tooling/Syntax/TokensTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Selection.cpp 
b/clang-tools-extra/clangd/Selection.cpp
index 54b182b3c706..5b29b916b33c 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -34,283 +34,95 @@ namespace {
 using Node = SelectionTree::Node;
 using ast_type_traits::DynTypedNode;
 
-// An IntervalSet maintains a set of disjoint subranges of an array.
-//
-// Initially, it contains the entire array.
-//   [---]
-//
-// When a range is erased(), it will typically split the array in two.
-//  Claim: []
-//  after:   []  [---]
-//
-// erase() returns the segments actually erased. Given the state above:
-//  Claim:  [---]
-//  Out:[-]  [--]
-//  After:   [-] [---]
-//
-// It is used to track (expanded) tokens not yet associated with an AST node.
-// On traversing an AST node, its token range is erased from the unclaimed set.
-// The tokens actually removed are associated with that node, and hit-tested
-// against the selection to determine whether the node is selected.
-template 
-class IntervalSet {
-public:
-  IntervalSet(llvm::ArrayRef Range) : UnclaimedRanges(&rangeLess) {
-UnclaimedRanges.insert(Range);
-  }
-
-  // Removes the elements of Claim from the set, modifying or removing ranges
-  // that overlap it.
-  // Returns the continuous subranges of Claim that were actually removed.
-  llvm::SmallVector, 4> erase(llvm::ArrayRef Claim) {
-llvm::SmallVector, 4> Out;
-if (Claim.empty())
-  return Out;
-// equal_range finds overlapping ranges, because of how we chose <.
-auto Overlap = UnclaimedRanges.equal_range(Claim);
-if (Overlap.first == Overlap.second)
-  return Out;
-
-// General case:
-// Claim:   [-]
-// UnclaimedRanges: [-A-] [-B-] [-C-] [-D-] [-E-] [-F-] [-G-]
-// Overlap:   ^first  ^second
-// Ranges C and D are fully included. Ranges B and E must be trimmed.
-
-// First, copy all overlapping ranges into the output.
-auto OutFirst = Out.insert(Out.end(), Overlap.first, Overlap.second);
-// If any of the overlapping ranges were sliced by the claim, split them:
-//  - restrict the returned range to the claimed part
-//  - save the unclaimed part so it can be reinserted
-llvm::ArrayRef RemainingHead, RemainingTail;
-if (Claim.begin() > OutFirst->begin()) {
-  RemainingHead = {OutFirst->begin(), Claim.begin()};
-  *OutFirst = {Claim.begin(), OutFirst->end()};
-}
-if (Claim.end() < Out.back().end()) {
-  RemainingTail = {Claim.end(), Out.back().end()};
-  Out.back() = {Out.back().begin(), Claim.end()};
-}
-
-// Erase all the overlapping ranges (invalidating all iterators).
-UnclaimedRanges.erase(Overlap.first, Overlap.second);
-// Reinsert ranges that were merely trimmed.
-if (!RemainingHead.empty())
-  UnclaimedRanges.insert(RemainingHead);
-if (!RemainingTail.empty())
-  UnclaimedRanges.insert(RemainingTail);
-
-return Out;
-  }
-
-private:
-  using TokenRange = llvm::ArrayRef;
-  // Given that the ranges we insert are disjoint, there are several ways to
-  // legally define range < range.
-  // We choose to define it so overlapping ranges compare equal.
-  static bool rangeLess(llvm::ArrayRef L, llvm::ArrayRef R) {
-return L.end() <= R.begin();
-  }
-
-  // Disjoint sorted unclaimed ranges of expanded tokens.
-  std::set, decltype(&rangeLess)> UnclaimedRanges;
-};
-
-// Sentinel value for the selectedness of a node where we've seen no tokens 
yet.
-// This resolves to Unselected if no tokens are ever seen.
-// But Unselected + Complete -> Partial, while N

[PATCH] D70839: [clang][IFS] Claiming -emit-merged-ifs in clang driver when -c is used.

2019-11-29 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

The commit message doesn't really explain much.  Why simply consume the 
argument?  Why not actually halt the build since this clearly is conflicting, 
and its unclear what the user intended.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70839



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


[PATCH] D70864: update trailing newline treatment in clang-format.py

2019-11-29 Thread Paul Seyfert via Phabricator via cfe-commits
pseyfert created this revision.
pseyfert added reviewers: klimek, MyDeveloperDay.
pseyfert added projects: clang-format, clang.

The current clang-format.py does not handle trailing newlines at the end of a 
file correctly.
Trailing empty lines get removed except one.
As far as I understand this is because clang-format gets fed from stdin and 
writes to stdout when called from clang-format.py.
In a "normal" file (with no trailing empty lines) the string that gets passed 
to clang-format does not contain a trailing '\n' after the '\n'.join from 
python.
The clang-format binary does not add a trailing newline to input from stdin, 
but (if there are multiple trailing '\n', all except one get removed).

When reading back this means that we see in python from a "normal" file a 
string with no trailing '\n'. From a file with (potentially multiple) empty 
line(s) at the end, we get a string with one trailing '\n' back in python. In 
the former case all is fine, in the latter case split('\n') makes one empty 
line at the end of the file out of the clang-format output. Desired would be 
instead that the **file** ends with a newline, but not with an empty line.

For the case that a user specifies a range to format (and wants to keep 
trailing empty lines) I did **not** try to fix this by simply removing all 
trailing newlines from the clang-format output. Instead, I add a '\n' to the 
unformatted file content (i.e. newline-terminate what is passed to 
clang-format) and then strip off the last newline from the output (which itself 
is now for sure the newline termination of the clang-format output).

(Should this get approved, I'll need someone to help me land this.)


https://reviews.llvm.org/D70864

Files:
  clang/tools/clang-format/clang-format.py


Index: clang/tools/clang-format/clang-format.py
===
--- clang/tools/clang-format/clang-format.py
+++ clang/tools/clang-format/clang-format.py
@@ -70,7 +70,7 @@
   # Get the current text.
   encoding = vim.eval("&encoding")
   buf = get_buffer(encoding)
-  text = '\n'.join(buf)
+  text = '\n'.join(buf) + '\n'
 
   # Determine range to format.
   if vim.eval('exists("l:lines")') == '1':
@@ -129,7 +129,7 @@
   else:
 lines = stdout.decode(encoding).split('\n')
 output = json.loads(lines[0])
-lines = lines[1:]
+lines = lines[1:-1]
 sequence = difflib.SequenceMatcher(None, buf, lines)
 for op in reversed(sequence.get_opcodes()):
   if op[0] is not 'equal':


Index: clang/tools/clang-format/clang-format.py
===
--- clang/tools/clang-format/clang-format.py
+++ clang/tools/clang-format/clang-format.py
@@ -70,7 +70,7 @@
   # Get the current text.
   encoding = vim.eval("&encoding")
   buf = get_buffer(encoding)
-  text = '\n'.join(buf)
+  text = '\n'.join(buf) + '\n'
 
   # Determine range to format.
   if vim.eval('exists("l:lines")') == '1':
@@ -129,7 +129,7 @@
   else:
 lines = stdout.decode(encoding).split('\n')
 output = json.loads(lines[0])
-lines = lines[1:]
+lines = lines[1:-1]
 sequence = difflib.SequenceMatcher(None, buf, lines)
 for op in reversed(sequence.get_opcodes()):
   if op[0] is not 'equal':
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70863: [clangd] Try harder to find a plausible `clang` as argv0, particularly on Mac.

2019-11-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: kbobyrev, ilya-biryukov.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay.
Herald added a project: clang.

Fixes https://github.com/clangd/clangd/issues/211
Fixes https://github.com/clangd/clangd/issues/178

No tests - this is hard to test, and basically impossible to verify what we want
(this produces compile commands that work on a real mac with recent toolchain)

(Need someone on mac to verify it actually fixes these!)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70863

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

Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
===
--- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -18,7 +18,9 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
 #include 
 #include 
 #include 
@@ -63,14 +65,86 @@
 
 } // namespace
 
-static std::string getFallbackClangPath() {
-  static int Dummy;
-  std::string ClangdExecutable =
-  llvm::sys::fs::getMainExecutable("clangd", (void *)&Dummy);
-  SmallString<128> ClangPath;
-  ClangPath = llvm::sys::path::parent_path(ClangdExecutable);
-  llvm::sys::path::append(ClangPath, "clang");
-  return ClangPath.str();
+// On Mac, `which clang` is /usr/bin/clang. It runs `xcrun clang`, which knows
+// where the real clang is kept. We need to do the same thing,
+// because cc1 (not the driver!) will find libc++ relative to argv[0].
+static llvm::Optional getMacClangPath() {
+#ifndef __APPLE__
+  return llvm::None;
+#endif
+
+  auto Xcrun = llvm::sys::findProgramByName("xcrun");
+  if (!Xcrun) {
+log("Couldn't find xcrun. Hopefully you have a non-apple toolchain...");
+return llvm::None;
+  }
+  llvm::SmallString<64> OutFile;
+  llvm::sys::fs::createTemporaryFile("clangd-xcrun", "", OutFile);
+  llvm::FileRemover OutRemover(OutFile);
+  llvm::Optional Redirects[3] = {
+  /*stdin=*/{""}, /*stdout=*/{OutFile}, /*stderr=*/{""}};
+  vlog("Invoking {0} to find fallback clang path", *Xcrun);
+  int Ret = llvm::sys::ExecuteAndWait(*Xcrun, {"xcrun", "--find", "clang"},
+  /*Env=*/llvm::None, Redirects,
+  /*SecondsToWait=*/10);
+  if (Ret != 0) {
+log("xcrun exists but failed with code {0}. "
+"If you have a non-apple toolchain, this is OK. "
+"Otherwise, try xcode-select --install.",
+Ret);
+return llvm::None;
+  }
+
+  auto Buf = llvm::MemoryBuffer::getFile(OutFile);
+  if (!Buf) {
+log("Can't read xcrun output: {0}", Buf.getError().message());
+return llvm::None;
+  }
+  StringRef Path = Buf->get()->getBuffer().trim();
+  if (Path.empty()) {
+log("xcrun produced no output");
+return llvm::None;
+  }
+  return Path.str();
+}
+
+// Resolve symlinks if possible.
+static std::string resolve(std::string Path) {
+  llvm::SmallString<128> Resolved;
+  if (llvm::sys::fs::real_path(Path, Resolved))
+return Path; // On error;
+  return Resolved.str();
+}
+
+// Get a plausible `clang` to use in the fallback compile command.
+// FIXME: should we also use this if compile_commands.json has just `clang`?
+static StringRef getFallbackClangPath() {
+  static const std::string &MemoizedFallbackPath = [&]() -> std::string {
+// The driver and/or cc1 sometimes depend on the binary name to compute
+// useful things like the standard library location.
+// We need to emulate what clang on this system is likely to see.
+// cc1 in particular looks at the "real path" of the running process, and
+// so if /usr/bin/clang is a symlink, it sees the resolved path.
+// clangd doesn't have that luxury, so we resolve symlinks ourselves.
+
+// /usr/bin/clang on a mac is a program that redirects to the right clang.
+// We resolve it as if it were a symlink.
+if (auto MacClang = getMacClangPath())
+  return resolve(std::move(*MacClang));
+// On other platforms, just look for compilers on the PATH.
+for (const char* Name : {"clang", "gcc", "ccc"})
+  if (auto PathCC = llvm::sys::findProgramByName(Name))
+return resolve(std::move(*PathCC));
+// Fallback: a nonexistent 'clang' binary next to clangd.
+static int Dummy;
+std::string ClangdExecutable =
+llvm::sys::fs::getMainExecutable("clangd", (void *)&Dummy);
+SmallString<128> ClangPath;
+ClangPath = llvm::sys::path::parent_path(ClangdExecutable);
+llvm::sys::path::append(ClangPath, "clang");
+return ClangPath.str();
+  }();
+  return MemoizedFallbackPath;
 }
 
 tooling::CompileCommand
___
cfe-commits mailing list
cfe-commi

[PATCH] D70838: [clang][IFS] Ignoring -Xlinker/-Xclang arguments in InterfaceStubs pass for now.

2019-11-29 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd accepted this revision.
compnerd added a comment.
This revision is now accepted and ready to land.

Could you please provide a proper commit message before committing this?  Also 
`-Xifs` is actually the inverse of what you want - that would be a set of 
arguments designed to be passed to `llvm-ifs`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70838



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


Re: [PATCH] D70512: [clangd] Rethink how SelectionTree deals with macros and #includes.

2019-11-29 Thread Sam McCall via cfe-commits
Thanks! It's not obvious what's going on, I can't reproduce it.
I'm sure I'll end up reverting, but as I can't see it on any of the
"official" bots either - do you have any description of the configuration?

On Fri, Nov 29, 2019 at 7:06 PM Nico Weber via Phabricator <
revi...@reviews.llvm.org> wrote:

> thakis added a comment.
>
> hover.test is failing on Mac: http://45.33.8.238/mac/3308/step_7.txt
>
> Please take a look, and revert if it takes a while.
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D70512/new/
>
> https://reviews.llvm.org/D70512
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70366: Add new 'flatten' LLVM attribute to fix clang's 'flatten' function attribute

2019-11-29 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

We need more tests here.

For one, the flatten attribute is not necessary to pass the test.
Second, we need to check the corner cases, e.g. reduction with different cycle 
lengths.




Comment at: llvm/docs/LangRef.rst:1428
 can prove that the call/invoke cannot call a convergent function.
+``flatten``
+This attribute is similar to ``alwaysinline``, but applies recursively to

LevitatingLion wrote:
> arsenm wrote:
> > It's not obvious to me what the flatten name means. flatteninline? 
> > recursive_alwaysinline? Something else?
> I agree. What about always_inline_recurse or always_inline_recursively?
I'd prefer `always_inline_recursively` or `recursive_alwaysinline` so far. 
Though something shorter would be fine too.
`always_inline_rec` maybe?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70366



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


[PATCH] D69620: Add AIX assembler support

2019-11-29 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:70
+  const InputInfo &II = Inputs[0];
+  if (II.isFilename())
+CmdArgs.push_back(II.getFilename());

Should is also be checked as being either a filename or "nothing"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69620



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


[PATCH] D70512: [clangd] Rethink how SelectionTree deals with macros and #includes.

2019-11-29 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

hover.test is failing on Mac: http://45.33.8.238/mac/3308/step_7.txt

Please take a look, and revert if it takes a while.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70512



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


[PATCH] D69620: Add AIX assembler support

2019-11-29 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/Driver/ToolChains/AIX.cpp:68
+  if (Inputs.size() != 1)
+llvm_unreachable("Invalid number of input files.");
+  const InputInfo &II = Inputs[0];

`llvm_unreachable` is not the right solution if this can be reached by "user 
error". We should produce a proper error message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69620



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


[PATCH] D70638: [Diagnostic] add a warning which warns about misleading indentation

2019-11-29 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 231561.

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

https://reviews.llvm.org/D70638

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Parse/ParseStmt.cpp
  clang/test/Index/pragma-diag-reparse.c
  clang/test/Misc/warning-wall.c
  clang/test/Parser/warn-misleading-indentation.cpp
  clang/test/Preprocessor/pragma_diagnostic_sections.cpp

Index: clang/test/Preprocessor/pragma_diagnostic_sections.cpp
===
--- clang/test/Preprocessor/pragma_diagnostic_sections.cpp
+++ clang/test/Preprocessor/pragma_diagnostic_sections.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wall -Wunused-macros -Wunused-parameter -Wno-uninitialized -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wall -Wunused-macros -Wunused-parameter -Wno-uninitialized -Wno-misleading-indentation -verify %s
 
 // rdar://8365684
 struct S {
Index: clang/test/Parser/warn-misleading-indentation.cpp
===
--- /dev/null
+++ clang/test/Parser/warn-misleading-indentation.cpp
@@ -0,0 +1,210 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wmisleading-indentation -DWITH_WARN %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -Wall -Wno-unused -DWITH_WARN -DCXX17 %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -Wall -Wno-unused -Wno-misleading-indentation -DCXX17 %s
+
+#ifndef WITH_WARN
+// expected-no-diagnostics
+#endif
+
+void f0(int i) {
+  if (i)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = i + 1;
+int x = 0;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
+#endif
+  return;
+#ifdef CXX17
+  if constexpr (false)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = 0;
+i += 1;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
+#endif
+#endif
+}
+
+void f1(int i) {
+  for (;i;)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = i + 1;
+i *= 2;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'for'}}
+#endif
+  return;
+}
+
+void f2(int i) {
+  while (i)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = i + 1; i *= 2;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'while'}}
+#endif
+  return;
+}
+
+void f3(int i) {
+  if (i)
+i = i + 1;
+  else
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i *= 2;
+const int x = 0;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'else'}}
+#endif
+}
+
+#ifdef CXX17
+struct Range {
+  int *begin() {return nullptr;}
+  int *end() {return nullptr;}
+};
+#endif
+
+void f4(int i) {
+  if (i)
+  i *= 2;
+  return;
+  if (i)
+i *= 2;
+;
+  if (i)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i *= 2;
+typedef int Int;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
+#endif
+#ifdef CXX17
+  Range R;
+  for (auto e : R)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i *= 2;
+using Int2 = int;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'for'}}
+#endif
+#endif
+}
+
+int bar(void);
+
+int foo(int* dst)
+{   
+if (dst)
+   return
+bar();
+  if (dst)
+dst = dst + \
+bar();
+  return 0;
+}
+
+// No diagnostics from GCC on this
+void g(int i) {
+  if (1)
+i = 2;
+  else
+ if (i == 3)
+i = 4;
+i = 5;
+}
+
+// Or this
+#define TEST i = 5
+void g0(int i) {
+  if (1)
+i = 2;
+  else
+i = 5;
+TEST;
+}
+
+void g1(int i) {
+  if (1)
+i = 2;
+  else
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+if (i == 3)
+i = 4;
+i = 5;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'else'}}
+#endif
+}
+
+void g2(int i) {
+  if (1)
+i = 2;
+  else
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+if (i == 3)
+{i = 4;}
+i = 5;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'else'}}
+#endif
+}
+
+void g6(int i) {
+if (1)
+if (i == 3)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = 4;
+i = 5;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
+#endif
+}
+
+void g7(int i) {
+  if (1)
+i = 4;
+#ifdef TEST1
+#endif
+i = 5;
+}
+
+void a1(int i) { if (1) i = 4; return; }
+
+void a2(int i) 

[PATCH] D68862: [ARM] Allocatable Global Register Variables for ARM

2019-11-29 Thread Carey Williams via Phabricator via cfe-commits
carwil added a comment.

Reverted.


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

https://reviews.llvm.org/D68862



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


[PATCH] D70862: [ARM][AArch64] Complex addition Neon intrinsics for Armv8.3-A

2019-11-29 Thread Victor Campos via Phabricator via cfe-commits
vhscampos created this revision.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya, kristof.beyls.
Herald added projects: clang, LLVM.

Add support for vcadd_* family of intrinsics. This set of intrinsics is
available in Armv8.3-A.

The fp16 versions require the FP16 extension, which has been available
(opt-in) since Armv8.2-A.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70862

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-vcadd.c
  clang/test/CodeGen/arm-neon-vcadd.c
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/ARM/ARMInstrNEON.td
  llvm/test/CodeGen/AArch64/neon-vcadd.ll
  llvm/test/CodeGen/ARM/neon-vcadd.ll

Index: llvm/test/CodeGen/ARM/neon-vcadd.ll
===
--- /dev/null
+++ llvm/test/CodeGen/ARM/neon-vcadd.ll
@@ -0,0 +1,54 @@
+; RUN: llc %s -mtriple=arm -mattr=+armv8.3-a,+fullfp16 -o - | FileCheck %s
+
+define <4 x half> @foo16x4_rot(<4 x half> %a, <4 x half> %b) {
+entry:
+; CHECK-LABEL: foo16x4_rot
+; CHECK-DAG: vcadd.f16 d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}, #90
+; CHECK-DAG: vcadd.f16 d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}, #270
+  %vcadd_rot90_v2.i = tail call <4 x half> @llvm.arm.neon.vcadd.rot90.v4f16(<4 x half> %a, <4 x half> %b)
+  %vcadd_rot270_v2.i = tail call <4 x half> @llvm.arm.neon.vcadd.rot270.v4f16(<4 x half> %a, <4 x half> %b)
+  %add = fadd <4 x half> %vcadd_rot90_v2.i, %vcadd_rot270_v2.i
+  ret <4 x half> %add
+}
+
+define <2 x float> @foo32x2_rot(<2 x float> %a, <2 x float> %b) {
+entry:
+; CHECK-LABEL: foo32x2_rot
+; CHECK-DAG: vcadd.f32 d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}, #90
+; CHECK-DAG: vcadd.f32 d{{[0-9]+}}, d{{[0-9]+}}, d{{[0-9]+}}, #270
+  %vcadd_rot90_v2.i = tail call <2 x float> @llvm.arm.neon.vcadd.rot90.v2f32(<2 x float> %a, <2 x float> %b)
+  %vcadd_rot270_v2.i = tail call <2 x float> @llvm.arm.neon.vcadd.rot270.v2f32(<2 x float> %a, <2 x float> %b)
+  %add = fadd <2 x float> %vcadd_rot90_v2.i, %vcadd_rot270_v2.i
+  ret <2 x float> %add
+}
+
+define <8 x half> @foo16x8_rot(<8 x half> %a, <8 x half> %b) {
+entry:
+; CHECK-LABEL: foo16x8_rot
+; CHECK-DAG: vcadd.f16 q{{[0-9]+}}, q{{[0-9]+}}, q{{[0-9]+}}, #90
+; CHECK-DAG: vcadd.f16 q{{[0-9]+}}, q{{[0-9]+}}, q{{[0-9]+}}, #270
+  %vcaddq_rot90_v2.i = tail call <8 x half> @llvm.arm.neon.vcadd.rot90.v8f16(<8 x half> %a, <8 x half> %b)
+  %vcaddq_rot270_v2.i = tail call <8 x half> @llvm.arm.neon.vcadd.rot270.v8f16(<8 x half> %a, <8 x half> %b)
+  %add = fadd <8 x half> %vcaddq_rot90_v2.i, %vcaddq_rot270_v2.i
+  ret <8 x half> %add
+}
+
+define <4 x float> @foo32x4_rot(<4 x float> %a, <4 x float> %b) {
+entry:
+; CHECK-LABEL: foo32x4_rot
+; CHECK-DAG: vcadd.f32 q{{[0-9]+}}, q{{[0-9]+}}, q{{[0-9]+}}, #90
+; CHECK-DAG: vcadd.f32 q{{[0-9]+}}, q{{[0-9]+}}, q{{[0-9]+}}, #270
+  %vcaddq_rot90_v2.i = tail call <4 x float> @llvm.arm.neon.vcadd.rot90.v4f32(<4 x float> %a, <4 x float> %b)
+  %vcaddq_rot270_v2.i = tail call <4 x float> @llvm.arm.neon.vcadd.rot270.v4f32(<4 x float> %a, <4 x float> %b)
+  %add = fadd <4 x float> %vcaddq_rot90_v2.i, %vcaddq_rot270_v2.i
+  ret <4 x float> %add
+}
+
+declare <4 x half> @llvm.arm.neon.vcadd.rot90.v4f16(<4 x half>, <4 x half>)
+declare <4 x half> @llvm.arm.neon.vcadd.rot270.v4f16(<4 x half>, <4 x half>)
+declare <2 x float> @llvm.arm.neon.vcadd.rot90.v2f32(<2 x float>, <2 x float>)
+declare <2 x float> @llvm.arm.neon.vcadd.rot270.v2f32(<2 x float>, <2 x float>)
+declare <8 x half> @llvm.arm.neon.vcadd.rot90.v8f16(<8 x half>, <8 x half>)
+declare <8 x half> @llvm.arm.neon.vcadd.rot270.v8f16(<8 x half>, <8 x half>)
+declare <4 x float> @llvm.arm.neon.vcadd.rot90.v4f32(<4 x float>, <4 x float>)
+declare <4 x float> @llvm.arm.neon.vcadd.rot270.v4f32(<4 x float>, <4 x float>)
Index: llvm/test/CodeGen/AArch64/neon-vcadd.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/neon-vcadd.ll
@@ -0,0 +1,67 @@
+; RUN: llc %s -mtriple=aarch64 -mattr=+v8.3a,+fullfp16 -o - | FileCheck %s
+
+define <4 x half> @foo16x4_rot(<4 x half> %a, <4 x half> %b) {
+entry:
+; CHECK-LABEL: foo16x4_rot
+; CHECK-DAG: fcadd v{{[0-9]+}}.4h, v{{[0-9]+}}.4h, v{{[0-9]+}}.4h, #90
+; CHECK-DAG: fcadd v{{[0-9]+}}.4h, v{{[0-9]+}}.4h, v{{[0-9]+}}.4h, #270
+  %vcadd_rot90_v2.i = tail call <4 x half> @llvm.aarch64.neon.vcadd.rot90.v4f16(<4 x half> %a, <4 x half> %b)
+  %vcadd_rot270_v2.i = tail call <4 x half> @llvm.aarch64.neon.vcadd.rot270.v4f16(<4 x half> %a, <4 x half> %b)
+  %add = fadd <4 x half> %vcadd_rot90_v2.i, %vcadd_rot270_v2.i
+  ret <4 x half> %add
+}
+
+define <2 x float> @foo32x2_rot(<2 x float> %a, <2 x float> %b) {
+entry:
+; CHECK-LABEL: foo32x2_rot
+; CHECK-DAG: fcadd v{{[0-9]+}}.2s, v{{[0-

[PATCH] D69620: Add AIX assembler support

2019-11-29 Thread Steven Wan via Phabricator via cfe-commits
stevewan updated this revision to Diff 231557.
stevewan added a comment.

Correct a typo in a comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69620

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/AIX.h
  clang/test/Driver/aix-as.c

Index: clang/test/Driver/aix-as.c
===
--- /dev/null
+++ clang/test/Driver/aix-as.c
@@ -0,0 +1,52 @@
+// General tests that as(1) invocations on AIX targets are sane. Note that we
+// only test assembler functionalities in this suite.
+
+// Check powerpc-ibm-aix7.1.0.0, 32-bit.
+// RUN: %clang -no-canonical-prefixes %s -### -c -o %t.o 2>&1 \
+// RUN: -target powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-AS32 %s
+// CHECK-AS32-NOT: warning:
+// CHECK-AS32: {{.*}}clang{{(.exe)?}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-AS32: "{{.*}}as{{(.exe)?}}" 
+// CHECK-AS32: "-a32" 
+// CHECK-AS32: "-u" 
+// CHECK-AS32: "-many" 
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit.
+// RUN: %clang -no-canonical-prefixes %s -### -c -o %t.o 2>&1 \
+// RUN: -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-AS64 %s
+// CHECK-AS64-NOT: warning:
+// CHECK-AS64: {{.*}}clang{{(.exe)?}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
+// CHECK-AS64: "{{.*}}as{{(.exe)?}}" 
+// CHECK-AS64: "-a64" 
+// CHECK-AS64: "-u" 
+// CHECK-AS64: "-many"
+
+
+// Check powerpc-ibm-aix7.1.0.0, 32-bit. -Xassembler  option. 
+// RUN: %clang -no-canonical-prefixes %s -### -c -o %t.o 2>&1 \
+// RUN: -Xassembler -w \
+// RUN: -target powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-AS32-Xassembler %s
+// CHECK-AS32-Xassembler-NOT: warning:
+// CHECK-AS32-Xassembler: {{.*}}clang{{(.exe)?}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-AS32-Xassembler: "{{.*}}as{{(.exe)?}}" 
+// CHECK-AS32-Xassembler: "-a32" 
+// CHECK-AS32-Xassembler: "-u" 
+// CHECK-AS32-Xassembler: "-many"
+// CHECK-AS32-Xassembler: "-w"
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -Wa,, option.
+// RUN: %clang -no-canonical-prefixes %s -### -c -o %t.o 2>&1 \
+// RUN: -Wa,-v,-w \
+// RUN: -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefix=CHECK-AS64-Wa %s
+// CHECK-AS64-Wa-NOT: warning:
+// CHECK-AS64-Wa: {{.*}}clang{{(.exe)?}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
+// CHECK-AS64-Wa: "{{.*}}as{{(.exe)?}}" 
+// CHECK-AS64-Wa: "-a64" 
+// CHECK-AS64-Wa: "-u" 
+// CHECK-AS64-Wa: "-many"
+// CHECK-AS64-Wa: "-v"
+// CHECK-AS64-Wa: "-w"
Index: clang/lib/Driver/ToolChains/AIX.h
===
--- clang/lib/Driver/ToolChains/AIX.h
+++ clang/lib/Driver/ToolChains/AIX.h
@@ -16,10 +16,21 @@
 namespace driver {
 namespace tools {
 
-/// aix -- Directly call system default linker.
-// TODO: Enable direct call to system default assembler.
+/// aix -- Directly call system default assembler and linker.
 namespace aix {
 
+class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
+public:
+  Assembler(const ToolChain &TC) : Tool("aix::Assembler", "assembler", TC) {}
+
+  bool hasIntegratedCPP() const override { return false; }
+
+  void ConstructJob(Compilation &C, const JobAction &JA,
+const InputInfo &Output, const InputInfoList &Inputs,
+const llvm::opt::ArgList &TCArgs,
+const char *LinkingOutput) const override;
+};
+
 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
 public:
   Linker(const ToolChain &TC) : Tool("aix::Linker", "linker", TC) {}
@@ -53,6 +64,7 @@
   bool isPICDefaultForced() const override { return true; }
 
 protected:
+  Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
 };
 
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -20,6 +20,60 @@
 
 using namespace llvm::opt;
 
+void aix::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
+  const InputInfo &Output,
+  const InputInfoList &Inputs,
+  const ArgList &Args,
+  const char *LinkingOutput) const {
+  ArgStringList CmdArgs;
+
+  const bool IsArch32Bit = getToolChain().getTriple().isArch32Bit();
+  const bool IsArch64Bit = getToolChain().getTriple().isArch64Bit();
+  // Only support 32 and 64 bit.
+  if (!IsArch32Bit && !IsArch64Bit)
+llvm_unreachable("Unsupported bit width value.");
+
+  // Specify the mode in which the as(1) command operates.
+  if (IsArch32Bit) {
+CmdArgs.push_back("-a32");
+  } else {
+// Must be 64-bit, otherwise asserted already.
+CmdArgs.push_back("-a64");
+  }
+
+  // Accept an undefined symbol as an 

[PATCH] D70638: [Diagnostic] add a warning which warns about misleading indentation

2019-11-29 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

>> there is only one case in llvm's code in which this warning is more 
>> agressive thant GCC's.

I think that's okay. If after-commit feedback shows this is bad, we can always 
tune this diagnostic more and do not warn in that case.


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

https://reviews.llvm.org/D70638



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


[PATCH] D70638: [Diagnostic] add a warning which warns about misleading indentation

2019-11-29 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: clang/include/clang/Parse/Parser.h:2269
 
+public:
   /// isCXXDeclarationStatement - C++-specialized function that disambiguates

Extra change? Your code does not use isCXXDeclarationStatement.


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

https://reviews.llvm.org/D70638



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


[PATCH] D70696: [DebugInfo] Support to emit debugInfo for extern variables

2019-11-29 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

@SouraVX Currently, I filtered all external globals if they are not used. See

  for (auto D: ExternalDeclarations) {
if (!D || D->isInvalidDecl() || D->getPreviousDecl() || !D->isUsed())
  continue;
  
Consumer.CompleteExternalDeclaration(D);
  }

If I remove `!D->isUsed()`, I should be able to generate the debuginfo for 
`global_var` and eventually in dwarf in your above case.

I tested with gcc 7.3.1, indeed gcc generates dwarf info for `global_var` as 
you stated in the above.

What exactly your use case here for these unused external variables?

I would like to hear comments from llvm/clang debuginfo experts before making 
the change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70696



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


[clang] 3b0b753 - On Windows, fix fuse-ld.c test when lld is provided explictly in -DCMAKE_LINKER

2019-11-29 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2019-11-29T11:28:49-05:00
New Revision: 3b0b7536a3182c1c69ade2bee80cdf954813a059

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

LOG: On Windows, fix fuse-ld.c test when lld is provided explictly in 
-DCMAKE_LINKER

Added: 


Modified: 
clang/test/Driver/fuse-ld.c

Removed: 




diff  --git a/clang/test/Driver/fuse-ld.c b/clang/test/Driver/fuse-ld.c
index 4b2ec7b1bb2a..13e709ccfdfa 100644
--- a/clang/test/Driver/fuse-ld.c
+++ b/clang/test/Driver/fuse-ld.c
@@ -79,13 +79,13 @@
 // RUN: %clang %s -### -fuse-ld=lld \
 // RUN: -target i686-unknown-windows-msvc 2>&1 \
 // RUN:   | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-LLD
-// CHECK-WINDOWS-MSVC-LLD: "{{.*}}lld-link"
+// CHECK-WINDOWS-MSVC-LLD: "{{.*}}lld-link{{\.exe"|"}}
 // CHECK-WINDOWS-MSVC-LLD-SAME: "-out:{{.*}}"
 
 // RUN: %clang %s -### -fuse-ld=lld-link \
 // RUN: -target i686-unknown-windows-msvc 2>&1 \
 // RUN:   | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-LLD-LINK
-// CHECK-WINDOWS-MSVC-LLD-LINK: "{{.*}}lld-link"
+// CHECK-WINDOWS-MSVC-LLD-LINK: "{{.*}}lld-link{{\.exe"|"}}
 // CHECK-WINDOWS-MSVC-LLD-LINK-SAME: "-out:{{.*}}"
 
 // RUN: %clang %s -### -fuse-ld=bfd \



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


[PATCH] D68165: [analyzer][MallocChecker][NFC] Split checkPostCall up, deploy CallDescriptionMap

2019-11-29 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:865
+  if (FreeingMemFnMap.lookup(Call))
 return true;
 

baloghadamsoftware wrote:
> Maybe `return !!FreeingMemFnMap.lookup(Call)`?
I think the code changed after I wrote this comment, it is not valid anymore.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:879
+bool MallocChecker::isMemCall(const CallEvent &Call) const {
+  if (FreeingMemFnMap.lookup(Call) || NonFreeingMemFnMap.lookup(Call))
 return true;

baloghadamsoftware wrote:
> Same here: why not just `return FreeingMemFnMap.lookup(Call) || 
> NonFreeingMemFn.lookup(Call)`?
Here as well. Disregard these comments.


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

https://reviews.llvm.org/D68165



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


[PATCH] D70638: [Diagnostic] add a warning which warns about misleading indentation

2019-11-29 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 231545.
Tyker added a comment.

I just found out that `Parser::isCXXDeclarationStatement` is does more then 
just disambiguation it can emit diagnostics. which can cause error on correct 
code. so we can't use it in this context to disambiguate.

so it is not possible to easily disambiguate between statements and 
declaration. i changed the warning message to reflect that but the message 
isn't so good now.


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

https://reviews.llvm.org/D70638

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/test/Index/pragma-diag-reparse.c
  clang/test/Misc/warning-wall.c
  clang/test/Preprocessor/pragma_diagnostic_sections.cpp

Index: clang/test/Preprocessor/pragma_diagnostic_sections.cpp
===
--- clang/test/Preprocessor/pragma_diagnostic_sections.cpp
+++ clang/test/Preprocessor/pragma_diagnostic_sections.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wall -Wunused-macros -Wunused-parameter -Wno-uninitialized -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wall -Wunused-macros -Wunused-parameter -Wno-uninitialized -Wno-misleading-indentation -verify %s
 
 // rdar://8365684
 struct S {
Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -90,6 +90,7 @@
 CHECK-NEXT:-Wdangling-else
 CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
+CHECK-NEXT:  -Wmisleading-indentation
 
 
 CHECK-NOT:-W
Index: clang/test/Index/pragma-diag-reparse.c
===
--- clang/test/Index/pragma-diag-reparse.c
+++ clang/test/Index/pragma-diag-reparse.c
@@ -11,6 +11,7 @@
   return x;
 }
 
+#pragma clang diagnostic ignored "-Wmisleading-indentation"
 void foo() { int b=0; while (b==b); }
 
 // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_FAILONERROR=1 c-index-test -test-load-source-reparse 5 local \
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2525,19 +2525,18 @@
 
 // Find the most recent expression bound to the symbol in the current
 // context.
-  if (!ReferenceRegion) {
-if (const MemRegion *MR = C.getLocationRegionIfPostStore(N)) {
-  SVal Val = State->getSVal(MR);
-  if (Val.getAsLocSymbol() == Sym) {
-const VarRegion* VR = MR->getBaseRegion()->getAs();
-// Do not show local variables belonging to a function other than
-// where the error is reported.
-if (!VR ||
-(VR->getStackFrame() == LeakContext->getStackFrame()))
-  ReferenceRegion = MR;
-  }
+if (!ReferenceRegion) {
+  if (const MemRegion *MR = C.getLocationRegionIfPostStore(N)) {
+SVal Val = State->getSVal(MR);
+if (Val.getAsLocSymbol() == Sym) {
+  const VarRegion *VR = MR->getBaseRegion()->getAs();
+  // Do not show local variables belonging to a function other than
+  // where the error is reported.
+  if (!VR || (VR->getStackFrame() == LeakContext->getStackFrame()))
+ReferenceRegion = MR;
 }
   }
+}
 
 // Allocation node, is the last node in the current or parent context in
 // which the symbol was tracked.
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1191,6 +1191,55 @@
   return false;
 }
 
+namespace {
+
+enum MisleadingStatementKind { MSK_if, MSK_else, MSK_for, MSK_while };
+
+struct MisleadingIndentationChecker {
+  Parser &P;
+  SourceLocation StmtLoc;
+  SourceLocation PrevLoc;
+  unsigned NumDirectives;
+  MisleadingStatementKind Kind;
+  bool NeedsChecking;
+  bool HasBraces;
+  MisleadingIndentationChecker(Parser &P, MisleadingStatementKind K,
+   SourceLocation SL)
+  : P(P), StmtLoc(SL), PrevLoc(P.getCurToken().getLocation()),
+NumDirectives(P.getPreprocessor().getNumDirectives()), Kind(K),
+NeedsChecking(true), HasBraces(P.getCurToken().is(tok::l_brace)) {
+}
+  void Check(bool ShouldCheck) {
+NeedsChecking = false;
+Token Tok = P.getCurToken();
+if (!ShouldCheck || HasBraces ||
+NumDirectives != P.getPreprocessor().getNumDirectives() ||
+Tok.isOneOf(tok::semi, tok::r_brace) || Tok.isAnnotation() ||
+Tok.getLocation().isMacroID() || PrevLoc.isMacroID() ||
+StmtLoc.isMacro

[PATCH] D70149: [C-index] Fix annotate-deep-statements test in Debug target

2019-11-29 Thread Alexandre Ganea via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG471d06020a6a: [CIndex] Fix annotate-deep-statements test 
when using a Debug build (authored by aganea).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70149

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/tools/libclang/CIndex.cpp


Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -3595,6 +3595,7 @@
 const char *const *command_line_args, int num_command_line_args,
 struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files,
 unsigned options, CXTranslationUnit *out_TU) {
+  noteBottomOfStack();
   SmallVector Args;
   Args.push_back("clang");
   Args.append(command_line_args, command_line_args + num_command_line_args);
@@ -3619,6 +3620,7 @@
 
   CXErrorCode result = CXError_Failure;
   auto ParseTranslationUnitImpl = [=, &result] {
+noteBottomOfStack();
 result = clang_parseTranslationUnit_Impl(
 CIdx, source_filename, command_line_args, num_command_line_args,
 llvm::makeArrayRef(unsaved_files, num_unsaved_files), options, out_TU);
@@ -6622,9 +6624,10 @@
 
 void clang_executeOnThread(void (*fn)(void*), void *user_data,
unsigned stack_size) {
-  llvm::llvm_execute_on_thread(
-  fn, user_data,
-  stack_size == 0 ? llvm::None : llvm::Optional(stack_size));
+  llvm::llvm_execute_on_thread(fn, user_data,
+   stack_size == 0
+   ? clang::DesiredStackSize
+   : llvm::Optional(stack_size));
 }
 
 
//===--===//
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -12950,7 +12950,8 @@
 //   expression or statement in the body of the function [and thus before
 //   the value computation of its result].
 SequencedSubexpression Sequenced(*this);
-Base::VisitCallExpr(CE);
+SemaRef.runWithSufficientStackSpace(CE->getExprLoc(),
+[&] { Base::VisitCallExpr(CE); });
 
 // FIXME: CXXNewExpr and CXXDeleteExpr implicitly call functions.
   }


Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -3595,6 +3595,7 @@
 const char *const *command_line_args, int num_command_line_args,
 struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files,
 unsigned options, CXTranslationUnit *out_TU) {
+  noteBottomOfStack();
   SmallVector Args;
   Args.push_back("clang");
   Args.append(command_line_args, command_line_args + num_command_line_args);
@@ -3619,6 +3620,7 @@
 
   CXErrorCode result = CXError_Failure;
   auto ParseTranslationUnitImpl = [=, &result] {
+noteBottomOfStack();
 result = clang_parseTranslationUnit_Impl(
 CIdx, source_filename, command_line_args, num_command_line_args,
 llvm::makeArrayRef(unsaved_files, num_unsaved_files), options, out_TU);
@@ -6622,9 +6624,10 @@
 
 void clang_executeOnThread(void (*fn)(void*), void *user_data,
unsigned stack_size) {
-  llvm::llvm_execute_on_thread(
-  fn, user_data,
-  stack_size == 0 ? llvm::None : llvm::Optional(stack_size));
+  llvm::llvm_execute_on_thread(fn, user_data,
+   stack_size == 0
+   ? clang::DesiredStackSize
+   : llvm::Optional(stack_size));
 }
 
 //===--===//
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -12950,7 +12950,8 @@
 //   expression or statement in the body of the function [and thus before
 //   the value computation of its result].
 SequencedSubexpression Sequenced(*this);
-Base::VisitCallExpr(CE);
+SemaRef.runWithSufficientStackSpace(CE->getExprLoc(),
+[&] { Base::VisitCallExpr(CE); });
 
 // FIXME: CXXNewExpr and CXXDeleteExpr implicitly call functions.
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 471d060 - [CIndex] Fix annotate-deep-statements test when using a Debug build

2019-11-29 Thread Alexandre Ganea via cfe-commits

Author: Alexandre Ganea
Date: 2019-11-29T10:52:20-05:00
New Revision: 471d06020a6a12c621131c508e58878890db3906

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

LOG: [CIndex] Fix annotate-deep-statements test when using a Debug build

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

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index adefca7fe4e7..ed42833531d4 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12950,7 +12950,8 @@ class SequenceChecker : public 
EvaluatedExprVisitor {
 //   expression or statement in the body of the function [and thus before
 //   the value computation of its result].
 SequencedSubexpression Sequenced(*this);
-Base::VisitCallExpr(CE);
+SemaRef.runWithSufficientStackSpace(CE->getExprLoc(),
+[&] { Base::VisitCallExpr(CE); });
 
 // FIXME: CXXNewExpr and CXXDeleteExpr implicitly call functions.
   }

diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 2078e4719522..a8222356db44 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -3595,6 +3595,7 @@ enum CXErrorCode clang_parseTranslationUnit2(
 const char *const *command_line_args, int num_command_line_args,
 struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files,
 unsigned options, CXTranslationUnit *out_TU) {
+  noteBottomOfStack();
   SmallVector Args;
   Args.push_back("clang");
   Args.append(command_line_args, command_line_args + num_command_line_args);
@@ -3619,6 +3620,7 @@ enum CXErrorCode clang_parseTranslationUnit2FullArgv(
 
   CXErrorCode result = CXError_Failure;
   auto ParseTranslationUnitImpl = [=, &result] {
+noteBottomOfStack();
 result = clang_parseTranslationUnit_Impl(
 CIdx, source_filename, command_line_args, num_command_line_args,
 llvm::makeArrayRef(unsaved_files, num_unsaved_files), options, out_TU);
@@ -6622,9 +6624,10 @@ void clang_enableStackTraces(void) {
 
 void clang_executeOnThread(void (*fn)(void*), void *user_data,
unsigned stack_size) {
-  llvm::llvm_execute_on_thread(
-  fn, user_data,
-  stack_size == 0 ? llvm::None : llvm::Optional(stack_size));
+  llvm::llvm_execute_on_thread(fn, user_data,
+   stack_size == 0
+   ? clang::DesiredStackSize
+   : llvm::Optional(stack_size));
 }
 
 
//===--===//



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


[PATCH] D70594: [clangd] Implement range patching heuristics for cross-file rename.

2019-11-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 231541.
hokein added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70594

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/refactor/Rename.h
  clang-tools-extra/clangd/unittests/RenameTests.cpp

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -11,6 +11,7 @@
 #include "TestTU.h"
 #include "index/Ref.h"
 #include "refactor/Rename.h"
+#include "clang/Basic/LangOptions.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "gmock/gmock.h"
@@ -695,6 +696,111 @@
 expectedResult(Code, expectedResult(T, "abc")));
 }
 
+TEST(CrossFileRenameTests, RangePatching) {
+  struct {
+llvm::StringRef LatestCode;
+llvm::StringRef IndexCode;
+RangeMatcher::MatchType ExpectedMatch;
+  } Tests [] = {
+{
+  // Equal
+  R"([[foo]])",
+  R"([[foo]])",
+  RangeMatcher::MatchType::Subset,
+},
+{
+  // proper subset
+  R"([[foo]] [[foo]])",
+  R"([[foo]])",
+  RangeMatcher::MatchType::Subset,
+},
+{
+  // same line, near-miss column.
+  R"([[foo]] [[foo]])",
+  R"(  [[foo]] [[foo]])",
+  RangeMatcher::MatchType::NearMiss,
+},
+{
+  // same line, near-miss column.
+  R"([[foo]] [[foo]])",
+  R"([[foo]]   [[foo]])",
+  RangeMatcher::MatchType::NearMiss,
+},
+{
+  // same column, near-miss line
+  R"(
+[[foo]] [[foo]]
+  )",
+  R"(
+
+[[foo]] [[foo]]
+  )",
+  RangeMatcher::MatchType::NearMiss,
+},
+
+
+{
+  // same line, but column diff > near-miss threshold
+  R"([[foo]])",
+  R"(   [[foo]])",
+  RangeMatcher::MatchType::NoMatch,
+},
+{
+  // same column, but line diff > near-miss threshold
+  R"(
+[[foo]] [[foo]]
+  )",
+  R"(
+
+
+
+[[foo]] [[foo]]
+  )",
+  RangeMatcher::MatchType::NoMatch,
+},
+{
+  // two lines with different number of elements are not near-miss.
+  R"(
+[[foo]] [[foo]]
+  )",
+  R"(
+[[foo]]
+[[foo]]
+  )",
+  RangeMatcher::MatchType::NoMatch,
+}
+  };
+  LangOptions LangOpts;
+  LangOpts.CPlusPlus = true;
+  RangeMatcher Matcher(LangOpts);
+
+  for (const auto &T : Tests) {
+auto IndexOccurrences = Annotations(T.IndexCode).ranges();
+auto Candidates = Annotations(T.LatestCode).ranges();
+EXPECT_EQ(T.ExpectedMatch,
+  RangeMatcher::match(IndexOccurrences, Candidates))
+<< T.LatestCode << ":" << T.IndexCode;
+
+
+auto AuthoritativeResult = Matcher.getBest(Annotations(T.LatestCode).code(),
+   "foo", IndexOccurrences);
+switch (T.ExpectedMatch) {
+case RangeMatcher::MatchType::NoMatch:
+  EXPECT_EQ(llvm::None, AuthoritativeResult);
+  break;
+case RangeMatcher::MatchType::Subset:
+  ASSERT_TRUE(AuthoritativeResult);
+  EXPECT_EQ(IndexOccurrences, *AuthoritativeResult);
+  break;
+case RangeMatcher::MatchType::NearMiss:
+  ASSERT_TRUE(AuthoritativeResult);
+
+  EXPECT_EQ(Candidates, *AuthoritativeResult);
+  break;
+}
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/refactor/Rename.h
===
--- clang-tools-extra/clangd/refactor/Rename.h
+++ clang-tools-extra/clangd/refactor/Rename.h
@@ -55,6 +55,49 @@
  std::vector Occurrences,
  llvm::StringRef NewName);
 
+/// Check whether the index results are good enough to perform the cross-file
+/// rename.
+///
+/// Index may be stale at the point of renaming, this class is designed to
+/// mitigate the issue of staleness index that may hurt the quality of rename
+/// results.
+///
+/// Techniques:
+///   - lex the latest file content (from dirty buffer/disk) to find all rename
+/// candidates, this yields a superset candidates
+///   - apply range patching heuristics to generate "authoritative" rename
+/// candidates. Scenarios that we are confident:
+///  (a) index returns a subset of candidates
+///- fully equal, we are sure the index is up-to-date
+///- proper subset, index is correct in most cases? there may be false
+///  positives (e.g. candidates got appended), but rename is still safe
+///  (b) index returns non-candidate results
+///- check whether they are near-miss (same line/column)
+class RangeMatcher {
+public:
+  enum class MatchType : uint8_t {
+NoMatch,
+
+Subset,
+NearMiss,
+  };

[PATCH] D70638: [Diagnostic] add a warning which warns about misleading indentation

2019-11-29 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Please land code fixes as NFC patch and then try to reland this patch.




Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:2532
+if (Val.getAsLocSymbol() == Sym) {
+  const VarRegion *VR = MR->getBaseRegion()->getAs();
+  // Do not show local variables belonging to a function other than

Please land as separated NFCI commit.


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

https://reviews.llvm.org/D70638



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


[PATCH] D70829: [ARM][MVE][Intrinsics] Add VMINQ/VMAXQ/VMINNMQ/VMAXNMQ intrinsics.

2019-11-29 Thread Mark Murray via Phabricator via cfe-commits
MarkMurrayARM updated this revision to Diff 231540.
MarkMurrayARM added a comment.

Fix non-predicated floats.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70829

Files:
  clang/include/clang/Basic/arm_mve.td
  clang/include/clang/Basic/arm_mve_defs.td
  clang/test/CodeGen/arm-mve-intrinsics/vmaxnmq.c
  clang/test/CodeGen/arm-mve-intrinsics/vmaxq.c
  clang/test/CodeGen/arm-mve-intrinsics/vminnmq.c
  clang/test/CodeGen/arm-mve-intrinsics/vminq.c
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/lib/Target/ARM/ARMInstrMVE.td
  llvm/test/CodeGen/Thumb2/mve-intrinsics/vmaxnmq.ll
  llvm/test/CodeGen/Thumb2/mve-intrinsics/vmaxq.ll
  llvm/test/CodeGen/Thumb2/mve-intrinsics/vminnmq.ll
  llvm/test/CodeGen/Thumb2/mve-intrinsics/vminq.ll

Index: llvm/test/CodeGen/Thumb2/mve-intrinsics/vminq.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/mve-intrinsics/vminq.ll
@@ -0,0 +1,89 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=thumbv8.1m.main -mattr=+mve.fp -verify-machineinstrs -o - %s | FileCheck %s
+
+define dso_local arm_aapcs_vfpcc <16 x i8> @test_vminq_u8(<16 x i8> %a, <16 x i8> %b) local_unnamed_addr #0 {
+; CHECK-LABEL: test_vminq_u8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmin.u8 q0, q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = icmp ugt <16 x i8> %a, %b
+  %1 = select <16 x i1> %0, <16 x i8> %b, <16 x i8> %a
+  ret <16 x i8> %1
+}
+
+define dso_local arm_aapcs_vfpcc <8 x i16> @test_vminq_s16(<8 x i16> %a, <8 x i16> %b) local_unnamed_addr #0 {
+; CHECK-LABEL: test_vminq_s16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmin.s16 q0, q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = icmp sgt <8 x i16> %a, %b
+  %1 = select <8 x i1> %0, <8 x i16> %b, <8 x i16> %a
+  ret <8 x i16> %1
+}
+
+define dso_local arm_aapcs_vfpcc <4 x i32> @test_vminq_u32(<4 x i32> %a, <4 x i32> %b) local_unnamed_addr #0 {
+; CHECK-LABEL: test_vminq_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmin.u32 q0, q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = icmp ugt <4 x i32> %a, %b
+  %1 = select <4 x i1> %0, <4 x i32> %b, <4 x i32> %a
+  ret <4 x i32> %1
+}
+
+define dso_local arm_aapcs_vfpcc <16 x i8> @test_vminq_m_s8(<16 x i8> %inactive, <16 x i8> %a, <16 x i8> %b, i16 zeroext %p) local_unnamed_addr #1 {
+; CHECK-LABEL: test_vminq_m_s8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmsr p0, r0
+; CHECK-NEXT:vpst
+; CHECK-NEXT:vmint.s8 q0, q1, q2
+; CHECK-NEXT:bx lr
+entry:
+  %0 = zext i16 %p to i32
+  %1 = tail call <16 x i1> @llvm.arm.mve.pred.i2v.v16i1(i32 %0)
+  %2 = tail call <16 x i8> @llvm.arm.mve.min.predicated.v16i8.v16i1(<16 x i8> %a, <16 x i8> %b, <16 x i1> %1, <16 x i8> %inactive)
+  ret <16 x i8> %2
+}
+
+declare <16 x i1> @llvm.arm.mve.pred.i2v.v16i1(i32) #2
+
+declare <16 x i8> @llvm.arm.mve.min.predicated.v16i8.v16i1(<16 x i8>, <16 x i8>, <16 x i1>, <16 x i8>) #2
+
+define dso_local arm_aapcs_vfpcc <8 x i16> @test_vminq_m_u16(<8 x i16> %inactive, <8 x i16> %a, <8 x i16> %b, i16 zeroext %p) local_unnamed_addr #1 {
+; CHECK-LABEL: test_vminq_m_u16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmsr p0, r0
+; CHECK-NEXT:vpst
+; CHECK-NEXT:vmint.s16 q0, q1, q2
+; CHECK-NEXT:bx lr
+entry:
+  %0 = zext i16 %p to i32
+  %1 = tail call <8 x i1> @llvm.arm.mve.pred.i2v.v8i1(i32 %0)
+  %2 = tail call <8 x i16> @llvm.arm.mve.min.predicated.v8i16.v8i1(<8 x i16> %a, <8 x i16> %b, <8 x i1> %1, <8 x i16> %inactive)
+  ret <8 x i16> %2
+}
+
+declare <8 x i1> @llvm.arm.mve.pred.i2v.v8i1(i32) #2
+
+declare <8 x i16> @llvm.arm.mve.min.predicated.v8i16.v8i1(<8 x i16>, <8 x i16>, <8 x i1>, <8 x i16>) #2
+
+define dso_local arm_aapcs_vfpcc <4 x i32> @test_vminq_m_s32(<4 x i32> %inactive, <4 x i32> %a, <4 x i32> %b, i16 zeroext %p) local_unnamed_addr #1 {
+; CHECK-LABEL: test_vminq_m_s32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmsr p0, r0
+; CHECK-NEXT:vpst
+; CHECK-NEXT:vmint.s32 q0, q1, q2
+; CHECK-NEXT:bx lr
+entry:
+  %0 = zext i16 %p to i32
+  %1 = tail call <4 x i1> @llvm.arm.mve.pred.i2v.v4i1(i32 %0)
+  %2 = tail call <4 x i32> @llvm.arm.mve.min.predicated.v4i32.v4i1(<4 x i32> %a, <4 x i32> %b, <4 x i1> %1, <4 x i32> %inactive)
+  ret <4 x i32> %2
+}
+
+declare <4 x i1> @llvm.arm.mve.pred.i2v.v4i1(i32) #2
+
+declare <4 x i32> @llvm.arm.mve.min.predicated.v4i32.v4i1(<4 x i32>, <4 x i32>, <4 x i1>, <4 x i32>) #2
Index: llvm/test/CodeGen/Thumb2/mve-intrinsics/vminnmq.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/mve-intrinsics/vminnmq.ll
@@ -0,0 +1,62 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=thumbv8.1m.main -mattr=+mve.fp -verify-machineinstrs -o - %s | FileCheck %s
+
+define dso_local arm_aapcs_vfpcc <8 x half> @test_vminnmq_f

[PATCH] D70638: [Diagnostic] add a warning which warns about misleading indentation

2019-11-29 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 231534.
Tyker added a comment.

yeah i saw. this version of the patch builds all llvm subproject(not tested on 
llgo) without warnings. there is only one case in llvm's code in which this 
warning is more agressive thant GCC's.

  if (1)
i = 0;
  
  // comment
i = 1; //  clang + this patch warns through the comment wereas gcc doesn't.

i don't believe a warning in this case is too bad.


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

https://reviews.llvm.org/D70638

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/test/Index/pragma-diag-reparse.c
  clang/test/Misc/warning-wall.c
  clang/test/Parser/warn-misleading-indentation.cpp
  clang/test/Preprocessor/pragma_diagnostic_sections.cpp

Index: clang/test/Preprocessor/pragma_diagnostic_sections.cpp
===
--- clang/test/Preprocessor/pragma_diagnostic_sections.cpp
+++ clang/test/Preprocessor/pragma_diagnostic_sections.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wall -Wunused-macros -Wunused-parameter -Wno-uninitialized -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wall -Wunused-macros -Wunused-parameter -Wno-uninitialized -Wno-misleading-indentation -verify %s
 
 // rdar://8365684
 struct S {
Index: clang/test/Parser/warn-misleading-indentation.cpp
===
--- /dev/null
+++ clang/test/Parser/warn-misleading-indentation.cpp
@@ -0,0 +1,210 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wmisleading-indentation -DWITH_WARN %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -Wall -Wno-unused -DWITH_WARN -DCXX17 %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -Wall -Wno-unused -Wno-misleading-indentation -DCXX17 %s
+
+#ifndef WITH_WARN
+// expected-no-diagnostics
+#endif
+
+void f0(int i) {
+  if (i)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = i + 1;
+int x = 0;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; declaration is not part of the previous 'if'}}
+#endif
+  return;
+#ifdef CXX17
+  if constexpr (false)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = 0;
+i += 1;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'if'}}
+#endif
+#endif
+}
+
+void f1(int i) {
+  for (;i;)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = i + 1;
+i *= 2;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'for'}}
+#endif
+  return;
+}
+
+void f2(int i) {
+  while (i)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i = i + 1; i *= 2;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'while'}}
+#endif
+  return;
+}
+
+void f3(int i) {
+  if (i)
+i = i + 1;
+  else
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i *= 2;
+const int x = 0;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; declaration is not part of the previous 'else'}}
+#endif
+}
+
+#ifdef CXX17
+struct Range {
+  int *begin() {return nullptr;}
+  int *end() {return nullptr;}
+};
+#endif
+
+void f4(int i) {
+  if (i)
+  i *= 2;
+  return;
+  if (i)
+i *= 2;
+;
+  if (i)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i *= 2;
+typedef int Int;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; declaration is not part of the previous 'if'}}
+#endif
+#ifdef CXX17
+  Range R;
+  for (auto e : R)
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+i *= 2;
+using Int2 = int;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; declaration is not part of the previous 'for'}}
+#endif
+#endif
+}
+
+int bar(void);
+
+int foo(int* dst)
+{   
+if (dst)
+   return
+bar();
+  if (dst)
+dst = dst + \
+bar();
+  return 0;
+}
+
+// No diagnostics from GCC on this
+void g(int i) {
+  if (1)
+i = 2;
+  else
+ if (i == 3)
+i = 4;
+i = 5;
+}
+
+// Or this
+#define TEST i = 5
+void g0(int i) {
+  if (1)
+i = 2;
+  else
+i = 5;
+TEST;
+}
+
+void g1(int i) {
+  if (1)
+i = 2;
+  else
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+if (i == 3)
+i = 4;
+i = 5;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not part of the previous 'else'}}
+#endif
+}
+
+void g2(int i) {
+  if (1)
+i = 2;
+  else
+#ifdef WITH_WARN
+// expected-note@-2 {{here}}
+#endif
+if (i == 3)
+{i = 4;}
+i = 5;
+#ifdef WITH_WARN
+// expected-warning@-2 {{misleading indentation; statement is not pa

[PATCH] D70857: [llvm][Support] Take in CurrentDirectory as a parameter in ExpandResponseFiles

2019-11-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.
kadircet added a parent revision: D70769: [Support] add vfs support for 
ExpandResponseFiles.
kadircet edited parent revisions, added: D70222: [clang][Tooling] Add support 
for .rsp files in compile_commands.json; removed: D70769: [Support] add vfs 
support for ExpandResponseFiles.

This is a follow-up to D70769  and D70222 
, which allows propagation of
current directory down to ExpandResponseFiles for handling of relative paths.

Previously clients had to mutate FS to achieve that, which is not thread-safe
and can even be thread-hostile in the case of real file system.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70857

Files:
  clang/include/clang/Tooling/CompilationDatabase.h
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/lib/Tooling/JSONCompilationDatabase.cpp
  llvm/include/llvm/Support/CommandLine.h
  llvm/lib/Support/CommandLine.cpp

Index: llvm/lib/Support/CommandLine.cpp
===
--- llvm/lib/Support/CommandLine.cpp
+++ llvm/lib/Support/CommandLine.cpp
@@ -24,6 +24,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Config/config.h"
@@ -1045,14 +1046,20 @@
   return (S.size() >= 3 && S[0] == '\xef' && S[1] == '\xbb' && S[2] == '\xbf');
 }
 
-static llvm::Error ExpandResponseFile(StringRef FName, StringSaver &Saver,
-   TokenizerCallback Tokenizer,
-   SmallVectorImpl &NewArgv,
-   bool MarkEOLs, bool RelativeNames,
-   llvm::vfs::FileSystem &FS) {
-  llvm::ErrorOr CurrDirOrErr = FS.getCurrentWorkingDirectory();
-  if (!CurrDirOrErr)
-return llvm::errorCodeToError(CurrDirOrErr.getError());
+static llvm::Error ExpandResponseFile(
+StringRef FName, StringSaver &Saver, TokenizerCallback Tokenizer,
+SmallVectorImpl &NewArgv, bool MarkEOLs, bool RelativeNames,
+llvm::vfs::FileSystem &FS, llvm::Optional CurrentDir) {
+  SmallString<128> CurrDir;
+  if (llvm::sys::path::is_relative(FName)) {
+if (!CurrentDir)
+  llvm::sys::fs::current_path(CurrDir);
+else
+  CurrDir = *CurrentDir;
+llvm::sys::path::append(CurrDir, FName);
+FName = CurrDir.str();
+  }
+
   llvm::ErrorOr> MemBufOrErr =
   FS.getBufferForFile(FName);
   if (!MemBufOrErr)
@@ -1078,28 +1085,26 @@
   // Tokenize the contents into NewArgv.
   Tokenizer(Str, Saver, NewArgv, MarkEOLs);
 
+  if (!RelativeNames)
+return Error::success();
+  llvm::StringRef BasePath = llvm::sys::path::parent_path(FName);
   // If names of nested response files should be resolved relative to including
   // file, replace the included response file names with their full paths
   // obtained by required resolution.
-  if (RelativeNames)
-for (unsigned I = 0; I < NewArgv.size(); ++I)
-  if (NewArgv[I]) {
-StringRef Arg = NewArgv[I];
-if (Arg.front() == '@') {
-  StringRef FileName = Arg.drop_front();
-  if (llvm::sys::path::is_relative(FileName)) {
-SmallString<128> ResponseFile;
-ResponseFile.append(1, '@');
-if (llvm::sys::path::is_relative(FName)) {
-  ResponseFile.append(CurrDirOrErr.get());
-}
-llvm::sys::path::append(
-ResponseFile, llvm::sys::path::parent_path(FName), FileName);
-NewArgv[I] = Saver.save(ResponseFile.c_str()).data();
-  }
-}
-  }
+  for (auto &Arg : NewArgv) {
+// Skip non-rsp file arguments.
+if (!Arg || Arg[0] != '@')
+  continue;
 
+StringRef FileName(Arg + 1);
+// Skip if non-relative.
+if (!llvm::sys::path::is_relative(FileName))
+  continue;
+
+SmallString<128> ResponseFile;
+llvm::sys::path::append(ResponseFile, "@", BasePath, FileName);
+Arg = Saver.save(ResponseFile.c_str()).data();
+  }
   return Error::success();
 }
 
@@ -1107,7 +1112,8 @@
 /// StringSaver and tokenization strategy.
 bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
  SmallVectorImpl &Argv, bool MarkEOLs,
- bool RelativeNames, llvm::vfs::FileSystem &FS) {
+ bool RelativeNames, llvm::vfs::FileSystem &FS,
+ llvm::Optional CurrentDir) {
   bool AllExpanded = true;
   struct ResponseFileRecord {
 const char *File;
@@ -1174,7 +1180,7 @@
 SmallVector ExpandedArgv;
 if (llvm::Error Err =
 ExpandResponseFile(FName, Saver, Tokenizer, ExpandedArgv, MarkEOLs,
-  

[PATCH] D70856: [Syntax] Build nodes for simple cases of top level declarations

2019-11-29 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: gribozavr2.
Herald added a project: clang.

More complicated nodes (e.g. template declarations) will be implemented
in the follow-up patches.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70856

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -512,7 +512,205 @@
 | | `-tb
 | `-;
 `-}
-  )txt"}};
+  )txt"},
+  {R"cpp(
+namespace a { namespace b {} }
+namespace {}
+
+namespace foo = a;
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-NamespaceDefinition
+| |-namespace
+| |-a
+| |-{
+| |-NamespaceDefinition
+| | |-namespace
+| | |-b
+| | |-{
+| | `-}
+| `-}
+|-NamespaceDefinition
+| |-namespace
+| |-{
+| `-}
+`-NamespaceAliasDefinition
+  |-namespace
+  |-foo
+  |-=
+  |-a
+  `-;
+)txt"},
+  {R"cpp(
+namespace ns {}
+using namespace ::ns;
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-NamespaceDefinition
+| |-namespace
+| |-ns
+| |-{
+| `-}
+`-UsingNamespaceDirective
+  |-using
+  |-namespace
+  |-::
+  |-ns
+  `-;
+   )txt"},
+  {R"cpp(
+namespace ns { int a; }
+using ns::a;
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-NamespaceDefinition
+| |-namespace
+| |-ns
+| |-{
+| |-SimpleDeclaration
+| | |-int
+| | |-a
+| | `-;
+| `-}
+`-UsingDeclaration
+  |-using
+  |-ns
+  |-::
+  |-a
+  `-;
+   )txt"},
+  {R"cpp(
+template  struct X {
+  using T::foo;
+  using typename T::bar;
+};
+)cpp",
+   R"txt(
+*: TranslationUnit
+`-UnknownDeclaration
+  |-template
+  |-<
+  |-UnknownDeclaration
+  | |-class
+  | `-T
+  |->
+  |-struct
+  |-X
+  |-{
+  |-UsingDeclaration
+  | |-using
+  | |-T
+  | |-::
+  | |-foo
+  | `-;
+  |-UsingDeclaration
+  | |-using
+  | |-typename
+  | |-T
+  | |-::
+  | |-bar
+  | `-;
+  |-}
+  `-;
+   )txt"},
+  {R"cpp(
+using type = int;
+)cpp",
+   R"txt(
+*: TranslationUnit
+`-TypeAliasDeclaration
+  |-using
+  |-type
+  |-=
+  |-int
+  `-;
+   )txt"},
+  {R"cpp(
+;
+)cpp",
+   R"txt(
+*: TranslationUnit
+`-EmptyDeclaration
+  `-;
+   )txt"},
+  {R"cpp(
+static_assert(true, "message");
+static_assert(true);
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-StaticAssertDeclaration
+| |-static_assert
+| |-(
+| |-UnknownExpression
+| | `-true
+| |-,
+| |-UnknownExpression
+| | `-"message"
+| |-)
+| `-;
+`-StaticAssertDeclaration
+  |-static_assert
+  |-(
+  |-UnknownExpression
+  | `-true
+  |-)
+  `-;
+   )txt"},
+  {R"cpp(
+extern "C" int a;
+extern "C" { int b; int c; }
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-LinkageSpecificationDeclaration
+| |-extern
+| |-"C"
+| `-SimpleDeclaration
+|   |-int
+|   |-a
+|   `-;
+`-LinkageSpecificationDeclaration
+  |-extern
+  |-"C"
+  |-{
+  |-SimpleDeclaration
+  | |-int
+  | |-b
+  | `-;
+  |-SimpleDeclaration
+  | |-int
+  | |-c
+  | `-;
+  `-}
+   )txt"},
+  {R"cpp(
+static_assert(true, "message");
+static_assert(true);
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-StaticAssertDeclaration
+| |-static_assert
+| |-(
+| |-UnknownExpression
+| | `-true
+| |-,
+| |-UnknownExpression
+| | `-"message"
+| |-)
+| `-;
+`-StaticAssertDeclaration
+  |-static_assert
+  |-(
+  |-UnknownExpression
+  | `-true
+  |-)
+  `-;
+   )txt"}};
 
   for (const auto &T : Cases) {
 auto *Root = buildTree(T.first);
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -50,8 +50,24 @@
 return OS << "CompoundStatement";
   case NodeKind::UnknownDeclaration:
 return OS << "UnknownDeclaration";
+  case NodeKind::EmptyDeclaration:
+return OS << "EmptyDeclaration";
+  case NodeKind::StaticAssertDeclaration:
+return OS << "StaticAssertDeclaration";
+  case NodeKind::LinkageSpecificationDeclaration:
+return OS << "LinkageSpecificationDeclaration";
   case NodeKind::SimpleDeclaration:
 return OS << "SimpleDeclaration";
+  case NodeKind::NamespaceDefinition:
+return OS << "NamespaceDefinition";
+  case NodeKind::NamespaceAliasDefinition:
+return OS << "NamespaceAliasDefinition";
+  case NodeKind::UsingNamespaceDirective:
+return OS << "UsingNamespaceDirective";
+  case NodeKind::UsingDeclaration:
+return OS << "UsingDeclaration";
+  case NodeKind::TypeAliasDeclaration:
+return OS << "TypeAliasDeclaration";
   }
   llvm_unreachable("unknown node kind");
 }
@@ -84,6 +100,8 @@
 return OS << "ExpressionStatement_expression";
   case syntax::NodeRole::CompoundStatement_statement:
 return OS << "CompoundStatement_statement";
+  case syntax::NodeRole::Stati

[PATCH] D70183: Detect source location overflow due includes

2019-11-29 Thread Diogo N. Sampaio via Phabricator via cfe-commits
dnsampaio added a comment.

Just wondering, I don't fully understand why is that important from the point I 
do a `return FileID();`. The critical error has already been inserted to the 
error list. clang shall either die due an assert in debug, or with a nice 
message in release. Unless clang is all broken, and the error message would be 
corrupted, which I don't believe is the case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70183



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


[PATCH] D70849: [AST] Traverse the class type loc inside the member pointer type loc.

2019-11-29 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang/include/clang/AST/RecursiveASTVisitor.h:1165
 
 // FIXME: location of base class?
 // We traverse this in the type case as well, but how is it not reached through

Remove this FIXME



Comment at: clang/include/clang/AST/RecursiveASTVisitor.h:1169
 DEF_TRAVERSE_TYPELOC(MemberPointerType, {
-  TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
+  if (auto *TSI = TL.getClassTInfo())
+TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));

Can this actually happen in practice?
Did we try doing **only** `TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()))` and 
seeing whether this fails?

The code in `MemberPointerTypeLoc` suggests this can happen, but would be 
interesting to find examples when it happens.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70849



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


[PATCH] D70853: [clangd] Fix a regression issue in local rename.

2019-11-29 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:136
+  else if (!DeclaredInMainFile)
+// the symbol declared outside of the main file, can't be main file only.
+IsMainFileOnly = false;

NIT: the comment seems to duplicate the code, maybe remove it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70853



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


[PATCH] D70854: [Clang] In tests, do not always assume others permissions are set

2019-11-29 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea created this revision.
aganea added reviewers: dblaikie, rnk.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
aganea retitled this revision from "[Clang] Do not always assume others 
permissions are set" to "[Clang] In tests, do not always assume others 
permissions are set".

On my Linux Ubuntu box, permissions for "others" are always unset/empty, thus 
`clang/test/Misc/permissions.cpp` used to always fail.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70854

Files:
  clang/test/Misc/permissions.cpp


Index: clang/test/Misc/permissions.cpp
===
--- clang/test/Misc/permissions.cpp
+++ clang/test/Misc/permissions.cpp
@@ -3,9 +3,9 @@
 // RUN: umask 000
 // RUN: %clang_cc1 -emit-llvm-bc %s -o %t
 // RUN: ls -l %t | FileCheck --check-prefix=CHECK000 %s
-// CHECK000: rw-rw-rw-
+// CHECK000: rw-rw-{{rw-|---}}
 
 // RUN: umask 002
 // RUN: %clang_cc1 -emit-llvm-bc %s -o %t
 // RUN: ls -l %t | FileCheck --check-prefix=CHECK002 %s
-// CHECK002: rw-rw-r--
+// CHECK002: rw-rw-{{r--|---}}


Index: clang/test/Misc/permissions.cpp
===
--- clang/test/Misc/permissions.cpp
+++ clang/test/Misc/permissions.cpp
@@ -3,9 +3,9 @@
 // RUN: umask 000
 // RUN: %clang_cc1 -emit-llvm-bc %s -o %t
 // RUN: ls -l %t | FileCheck --check-prefix=CHECK000 %s
-// CHECK000: rw-rw-rw-
+// CHECK000: rw-rw-{{rw-|---}}
 
 // RUN: umask 002
 // RUN: %clang_cc1 -emit-llvm-bc %s -o %t
 // RUN: ls -l %t | FileCheck --check-prefix=CHECK002 %s
-// CHECK002: rw-rw-r--
+// CHECK002: rw-rw-{{r--|---}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70568: [Support] Possibly use exception handler in the Crash Recovery Context in the same way as global exceptions

2019-11-29 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D70568#1763824 , @aganea wrote:

> Thanks for analyzing this!
>
> In D70568#1763769 , @hans wrote:
>
> > - About making CrashRecoveryContext::Enable() the default, that seems 
> > somewhat orthogonal to this change. You mention the use case of running 
> > several compilations in parallel, but I don't think that's a scenario that 
> > happens today? If doing this is necessary, I think it would be good to 
> > break it out into a separate patch.
>
>
> Even for non-parallel compilations, we still need to enable the 
> `CrashRecoveryContext` inside the new `CC1Command`, just before calling 
> `RunSafely()`.
>  If you look at a previous diff  
> of D69825 , in `clang/lib/Driver/Job.cpp, 
> L389` there is:
>
>   static bool CRCEnabled{};
>   if (!CRCEnabled) {
> llvm::CrashRecoveryContext::Enable();
> CRCEnabled = true;
>   }
>   
>
> Which I removed, because I find it a bit awkward to "enable" something that 
> should be decided internally by CrashRecoveryContext (this Enable API sounds 
> more like internal behaviour leaking outside of CrashRecoveryContext).
>  The purpose of Enable/Disable is either for debugging (when enabling 
> `LIBCLANG_DISABLE_CRASH_RECOVERY`) or possibly bubbling up the crash, as 
> described in D23662 .
>  Also consider the scenario where we sequentially compile several TUs: 
> `clang-cl a.cpp b.cpp c.cpp`. Only the first call to `CC1Command::Execute()` 
> should call `llvm::CrashRecoveryContext::Enable()`.
>  It is orthogonal, I can send a separate patch. Should we instead call 
> `llvm::CrashRecoveryContext::Enable()` in D69825 
> , when `clang.exe` starts?


Yes, maybe enabling it on startup is the best way to do it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70568



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


[PATCH] D70512: [clangd] Rethink how SelectionTree deals with macros and #includes.

2019-11-29 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sammccall marked 2 inline comments as done.
Closed by commit rG19daa21f841a: [clangd] Rethink how SelectionTree deals with 
macros and #includes. (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D70512?vs=231206&id=231528#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70512

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/Selection.h
  clang-tools-extra/clangd/unittests/SelectionTests.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp

Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -40,6 +40,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "llvm/Testing/Support/SupportHelpers.h"
+#include "gmock/gmock.h"
 #include 
 #include 
 #include 
@@ -663,6 +664,20 @@
   ValueIs(SameRange(findSpelled("not_mapped";
 }
 
+TEST_F(TokenBufferTest, ExpandedTokensForRange) {
+  recordTokens(R"cpp(
+#define SIGN(X) X##_washere
+A SIGN(B) C SIGN(D) E SIGN(F) G
+  )cpp");
+
+  SourceRange R(findExpanded("C").front().location(),
+findExpanded("F_washere").front().location());
+  // Sanity check: expanded and spelled tokens are stored separately.
+  EXPECT_THAT(Buffer.expandedTokens(R),
+  SameRange(findExpanded("C D_washere E F_washere")));
+  EXPECT_THAT(Buffer.expandedTokens(SourceRange()), testing::IsEmpty());
+}
+
 TEST_F(TokenBufferTest, ExpansionStartingAt) {
   // Object-like macro expansions.
   recordTokens(R"cpp(
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -119,6 +119,22 @@
   return Text.substr(Begin, length());
 }
 
+llvm::ArrayRef TokenBuffer::expandedTokens(SourceRange R) const {
+  if (R.isInvalid())
+return {};
+  const Token *Begin =
+  llvm::partition_point(expandedTokens(), [&](const syntax::Token &T) {
+return SourceMgr->isBeforeInTranslationUnit(T.location(), R.getBegin());
+  });
+  const Token *End =
+  llvm::partition_point(expandedTokens(), [&](const syntax::Token &T) {
+return !SourceMgr->isBeforeInTranslationUnit(R.getEnd(), T.location());
+  });
+  if (Begin > End)
+return {};
+  return {Begin, End};
+}
+
 std::pair
 TokenBuffer::spelledForExpandedToken(const syntax::Token *Expanded) const {
   assert(Expanded);
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/Syntax/Tokens.h
@@ -175,6 +175,7 @@
   /// All tokens produced by the preprocessor after all macro replacements,
   /// directives, etc. Source locations found in the clang AST will always
   /// point to one of these tokens.
+  /// Tokens are in TU order (per SourceManager::isBeforeInTranslationUnit()).
   /// FIXME: figure out how to handle token splitting, e.g. '>>' can be split
   ///into two '>' tokens by the parser. However, TokenBuffer currently
   ///keeps it as a single '>>' token.
@@ -182,6 +183,10 @@
 return ExpandedTokens;
   }
 
+  /// Returns the subrange of expandedTokens() corresponding to the closed
+  /// token range R.
+  llvm::ArrayRef expandedTokens(SourceRange R) const;
+
   /// Find the subrange of spelled tokens that produced the corresponding \p
   /// Expanded tokens.
   ///
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -269,7 +269,7 @@
   EXPECT_UNAVAILABLE(UnavailableCases);
 
   // vector of pairs of input and output strings
-  const std::vector>
+  const std::vector>
   InputOutputs = {
   // extraction from variable declaration/assignment
   {R"cpp(void varDecl() {
@@ -321,17 +321,10 @@
if(1)
 LOOP(5 + [[3]])
  })cpp",
-   /*FIXME: It should be extracted like this. SelectionTree needs to be
- * fixed for macros.
 R"cpp(#define LOOP(x) while (1) {a = x;}
-void f(int a) {
-  auto dummy = 3; if(1)
-   LOOP(5 + dummy)
-})cpp"},*/
-   R"cpp(#define LOOP(x) while (1) {a = x;}
  void f(int a) {
-   auto dummy = LOOP(5 + 3); if(1)
- 

[clang-tools-extra] 19daa21 - [clangd] Rethink how SelectionTree deals with macros and #includes.

2019-11-29 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2019-11-29T15:21:13+01:00
New Revision: 19daa21f841ad45290c923689ee3d25198651a4c

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

LOG: [clangd] Rethink how SelectionTree deals with macros and #includes.

Summary:
The exclusive-claim model is successful at resolving conflicts over tokens
between parent/child or siblings. However claims at the spelled-token
level do the wrong thing for macro expansions, where siblings can be
equally associated with the macro invocation.
Moreover, any model that only uses the endpoints in a range can fail when
a macro invocation occurs inside the node.

To address this, we use the existing TokenBuffer in more depth.
Claims are expressed in terms of expanded tokens, so there is no need to worry
about macros, includes etc.

Once we know which expanded tokens were claimed, they are mapped onto
spelled tokens for hit-testing.
This mapping is fairly flexible, currently the handling of macros is
pretty simple (map macro args onto spellings, other macro expansions onto the
macro name token).
This mapping is in principle token-by-token for correctness (though
there's some batching for performance).

The aggregation of the selection enum is now more principled as we need to be
able to aggregate several hit-test results together.

For simplicity i removed the ability to determine selectedness of TUDecl.
(That was originally implemented in 90a5bf92ff97b1, but doesn't seem to be very
important or worth the complexity any longer).

The expandedTokens(SourceLocation) helper could be added locally, but seems to
make sense on TokenBuffer.

Fixes https://github.com/clangd/clangd/issues/202
Fixes https://github.com/clangd/clangd/issues/126

Reviewers: hokein

Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits, 
ilya-biryukov

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/Selection.h
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang-tools-extra/clangd/unittests/TweakTests.cpp
clang/include/clang/Tooling/Syntax/Tokens.h
clang/lib/Tooling/Syntax/Tokens.cpp
clang/unittests/Tooling/Syntax/TokensTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Selection.cpp 
b/clang-tools-extra/clangd/Selection.cpp
index 5b29b916b33c..54b182b3c706 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -34,95 +34,283 @@ namespace {
 using Node = SelectionTree::Node;
 using ast_type_traits::DynTypedNode;
 
-// Identifies which tokens are selected, and evaluates claims of source ranges
-// by AST nodes. Tokens may be claimed only once: first-come, first-served.
-class SelectedTokens {
+// An IntervalSet maintains a set of disjoint subranges of an array.
+//
+// Initially, it contains the entire array.
+//   [---]
+//
+// When a range is erased(), it will typically split the array in two.
+//  Claim: []
+//  after:   []  [---]
+//
+// erase() returns the segments actually erased. Given the state above:
+//  Claim:  [---]
+//  Out:[-]  [--]
+//  After:   [-] [---]
+//
+// It is used to track (expanded) tokens not yet associated with an AST node.
+// On traversing an AST node, its token range is erased from the unclaimed set.
+// The tokens actually removed are associated with that node, and hit-tested
+// against the selection to determine whether the node is selected.
+template 
+class IntervalSet {
+public:
+  IntervalSet(llvm::ArrayRef Range) : UnclaimedRanges(&rangeLess) {
+UnclaimedRanges.insert(Range);
+  }
+
+  // Removes the elements of Claim from the set, modifying or removing ranges
+  // that overlap it.
+  // Returns the continuous subranges of Claim that were actually removed.
+  llvm::SmallVector, 4> erase(llvm::ArrayRef Claim) {
+llvm::SmallVector, 4> Out;
+if (Claim.empty())
+  return Out;
+// equal_range finds overlapping ranges, because of how we chose <.
+auto Overlap = UnclaimedRanges.equal_range(Claim);
+if (Overlap.first == Overlap.second)
+  return Out;
+
+// General case:
+// Claim:   [-]
+// UnclaimedRanges: [-A-] [-B-] [-C-] [-D-] [-E-] [-F-] [-G-]
+// Overlap:   ^first  ^second
+// Ranges C and D are fully included. Ranges B and E must be trimmed.
+
+// First, copy all overlapping ranges into the output.
+auto O

[PATCH] D69620: Add AIX assembler support

2019-11-29 Thread David Tenty via Phabricator via cfe-commits
daltenty accepted this revision.
daltenty added a comment.
This revision is now accepted and ready to land.

Other than minor nit, LGTM




Comment at: clang/lib/Driver/ToolChains/AIX.cpp:68
+  if (Inputs.size() != 1)
+llvm_unreachable("Invalid number of input file.");
+  const InputInfo &II = Inputs[0];

nit: plural, "files"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69620



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


[PATCH] D70568: [Support] Possibly use exception handler in the Crash Recovery Context in the same way as global exceptions

2019-11-29 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

Thanks for analyzing this!

In D70568#1763769 , @hans wrote:

> - About making CrashRecoveryContext::Enable() the default, that seems 
> somewhat orthogonal to this change. You mention the use case of running 
> several compilations in parallel, but I don't think that's a scenario that 
> happens today? If doing this is necessary, I think it would be good to break 
> it out into a separate patch.


Even for non-parallel compilations, we still need to enable the 
`CrashRecoveryContext` inside the new `CC1Command`, just before calling 
`RunSafely()`.
If you look at a previous diff  of 
D69825 , in `clang/lib/Driver/Job.cpp, L389` 
there is:

  static bool CRCEnabled{};
  if (!CRCEnabled) {
llvm::CrashRecoveryContext::Enable();
CRCEnabled = true;
  }

Which I removed, because I find it a bit awkward to "enable" something that 
should be decided internally by CrashRecoveryContext (this Enable API sounds 
more like internal behaviour leaking outside of CrashRecoveryContext).
The purpose of Enable/Disable is either for debugging (when enabling 
`LIBCLANG_DISABLE_CRASH_RECOVERY`) or possibly bubbling up the crash, as 
described in D23662 .
Also consider the scenario where we sequentially compile several TUs: `clang-cl 
a.cpp b.cpp c.cpp`. Only the first call to `CC1Command::Execute()` should call 
`llvm::CrashRecoveryContext::Enable()`.
It is orthogonal, I can send a separate patch. Should we instead call 
`llvm::CrashRecoveryContext::Enable()` in D69825 
, when `clang.exe` starts?

> - The main purpose of the patch is the new "EnableExceptionHandler" mode for 
> CrashRecoveryContext. I find the name a bit confusing, because on Posix 
> there's no exception handler, and on Win32 an exception handler is used to 
> implement CrashRecoverContext::RunSafely, but that's a different one.
> 
>   What the mode really does is print a stack trace, write a minidump (on 
> windows), and run cleanups. Perhaps a better name for that would be 
> "DumpStackAndCleanupOnFailure"? Maybe they could be separate flags even.

Will do.

> 
> 
> - The mechanism for doing the stack dump and cleanups looks a bit scary to 
> me. That's sys::InvokeExceptionHandler, a name which doesn't really make 
> sense on Posix where it calls SignalHandler, and passes in the RetCode 
> argument as the signal parameter. On Win32 it calls 
> LLVMUnhandledExceptionFilter, and it does this inside the SEH filter 
> function, although I think it will always return EXCEPTION_EXECUTE_HANDLER, 
> so it could just be called inside the exception handler instead?
> 
>   On Posix, the call to SignalHandler looks scary, because it does a bunch of 
> signal stuff, and e.g. on S390 hosts it raises the signal again to make sure 
> to crash (which I don't think we want inside a CrashRecoveryContext).
> 
>   I wish the stack dumping and cleanup could be factored out into something 
> that doesn't involve all the signal stuff, and that could have a clean 
> interface that CrashRecoveryContext could simply call when it catches a 
> crash. Maybe sys::DumpStackAndCleanup(...).  Do you think this would be 
> possible?

I'll make it possible :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70568



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


[PATCH] D70853: [clangd] Fix a regression issue in local rename.

2019-11-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added subscribers: usaxena95, kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

The regression is that we can't rename symbols in annonymous
namespaces.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70853

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -450,13 +450,20 @@
   )cpp",
"used outside main file", HeaderFile, Index},
 
-  {R"cpp(// disallow -- symbol is not indexable.
+  {R"cpp(// disallow -- symbol in annonymous namespace in header is not 
indexable.
 namespace {
 class Unin^dexable {};
 }
   )cpp",
"not eligible for indexing", HeaderFile, Index},
 
+  {R"cpp(// allow -- symbol in annonymous namespace in non-header file is 
indexable.
+namespace {
+class [[F^oo]] {};
+}
+  )cpp",
+   nullptr, !HeaderFile, Index},
+
   {R"cpp(// disallow -- namespace symbol isn't supported
 namespace n^s {}
   )cpp",
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -123,20 +123,27 @@
   if (RenameDecl.getParentFunctionOrMethod())
 return None;
 
+  // Check whether the symbol being rename is indexable.
+  auto &ASTCtx = RenameDecl.getASTContext();
+  bool MainFileIsHeader = isHeaderFile(MainFilePath, ASTCtx.getLangOpts());
+  bool DeclaredInMainFile =
+  isInsideMainFile(RenameDecl.getBeginLoc(), ASTCtx.getSourceManager());
+  bool IsMainFileOnly = true;
+  if (MainFileIsHeader)
+// main file is a header, the symbol can't be main file only.
+IsMainFileOnly = false;
+  else if (!DeclaredInMainFile)
+// the symbol declared outside of the main file, can't be main file only.
+IsMainFileOnly = false;
   bool IsIndexable =
   isa(RenameDecl) &&
   SymbolCollector::shouldCollectSymbol(
   cast(RenameDecl), RenameDecl.getASTContext(),
-  SymbolCollector::Options(), CrossFile);
+  SymbolCollector::Options(), IsMainFileOnly);
   if (!IsIndexable) // If the symbol is not indexable, we disallow rename.
 return ReasonToReject::NonIndexable;
 
   if (!CrossFile) {
-auto &ASTCtx = RenameDecl.getASTContext();
-const auto &SM = ASTCtx.getSourceManager();
-bool MainFileIsHeader = isHeaderFile(MainFilePath, ASTCtx.getLangOpts());
-bool DeclaredInMainFile = isInsideMainFile(RenameDecl.getBeginLoc(), SM);
-
 if (!DeclaredInMainFile)
   // We are sure the symbol is used externally, bail out early.
   return ReasonToReject::UsedOutsideFile;


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -450,13 +450,20 @@
   )cpp",
"used outside main file", HeaderFile, Index},
 
-  {R"cpp(// disallow -- symbol is not indexable.
+  {R"cpp(// disallow -- symbol in annonymous namespace in header is not indexable.
 namespace {
 class Unin^dexable {};
 }
   )cpp",
"not eligible for indexing", HeaderFile, Index},
 
+  {R"cpp(// allow -- symbol in annonymous namespace in non-header file is indexable.
+namespace {
+class [[F^oo]] {};
+}
+  )cpp",
+   nullptr, !HeaderFile, Index},
+
   {R"cpp(// disallow -- namespace symbol isn't supported
 namespace n^s {}
   )cpp",
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -123,20 +123,27 @@
   if (RenameDecl.getParentFunctionOrMethod())
 return None;
 
+  // Check whether the symbol being rename is indexable.
+  auto &ASTCtx = RenameDecl.getASTContext();
+  bool MainFileIsHeader = isHeaderFile(MainFilePath, ASTCtx.getLangOpts());
+  bool DeclaredInMainFile =
+  isInsideMainFile(RenameDecl.getBeginLoc(), ASTCtx.getSourceManager());
+  bool IsMainFileOnly = true;
+  if (MainFileIsHeader)
+// main file is a header, the symbol can't be main file only.
+IsMainFileOnly = false;
+  else if (!DeclaredInMainFile)
+// the symbol declared outside of the main file, can't be main file only.
+IsMainFileOnly = false;
   bool IsIndexable =
   isa(RenameDecl) &&
   SymbolCollector::shouldCollectSymbol(
   cast(RenameDecl), RenameDecl.getASTContext(),
-

[PATCH] D70366: Add new 'flatten' LLVM attribute to fix clang's 'flatten' function attribute

2019-11-29 Thread LevitatingLion via Phabricator via cfe-commits
LevitatingLion added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70366



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


[PATCH] D70727: [clangd] Keep go-to-definition working at the end of an identifier (fixes #194)

2019-11-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D70727#1760485 , @nridge wrote:

> By the way, may I get permissions to assign issues to myself (and make other 
> such metadata changes to issues) on github?


sure, we just sent you an invitation to the clangd org.




Comment at: clang-tools-extra/clangd/XRefs.cpp:153
+  // allowing go-to-definition to work at the end of an identifier.
+  if (Result.empty() && Offset > 0) {
+Result = getDeclAtOffset(AST, Offset - 1, Relations);

this looks a hacky workaround, I assume it may introduce other regression 
issues. 

I think https://reviews.llvm.org/D70773 and https://reviews.llvm.org/D70807 
should fix most annoying cases (function call). 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70727



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


[PATCH] D70253: [AArch64][SVE2] Implement remaining SVE2 floating-point intrinsics

2019-11-29 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.
Herald added a reviewer: efriedma.



Comment at: llvm/include/llvm/IR/IntrinsicsAArch64.td:898
+ llvm_i32_ty],
+[IntrNoMem]>;
+

efriedma wrote:
> kmclaughlin wrote:
> > sdesmalen wrote:
> > > I'd expect the `llvm_i32_ty` to be an immediate for these instructions, 
> > > right? If so you'll need to add `ImmArg`  to the list of properties.
> > > 
> > Thanks for taking a look at this :) I tried your suggestion of adding 
> > ImmAr to the list of properties here but had some problems with it 
> > (i.e. Cannot select: intrinsic %llvm.aarch64.sve.fmlalb.lane). I don't 
> > think this is too much of an issue here as we have additional checks on the 
> > immediate with VectorIndexH32b, which ensures the immediate is in the 
> > correct range.
> The point of immarg markings isn't to assist the backend; it's to ensure IR 
> optimizations don't break your intrinsic calls.
The pattern is probably not matching because the immediate operand is a 
`TargetConstant` where the `AsmVectorIndexOpnd` derives from `ImmLeaf`, rather 
than `TImmLeaf` as introduced by D58232.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70253



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


[PATCH] D70568: [Support] Possibly use exception handler in the Crash Recovery Context in the same way as global exceptions

2019-11-29 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Sorry for the slow response. This is a pretty complicated patch, so I needed 
some time to wrap my head around it. I'm still not entirely sure I got it 
right, but here are some high-level comments.

- About making CrashRecoveryContext::Enable() the default, that seems somewhat 
orthogonal to this change. You mention the use case of running several 
compilations in parallel, but I don't think that's a scenario that happens 
today? If doing this is necessary, I think it would be good to break it out 
into a separate patch.

- The main purpose of the patch is the new "EnableExceptionHandler" mode for 
CrashRecoveryContext. I find the name a bit confusing, because on Posix there's 
no exception handler, and on Win32 an exception handler is used to implement 
CrashRecoverContext::RunSafely, but that's a different one.

  What the mode really does is print a stack trace, write a minidump (on 
windows), and run cleanups. Perhaps a better name for that would be 
"DumpStackAndCleanupOnFailure"? Maybe they could be separate flags even.

- The mechanism for doing the stack dump and cleanups looks a bit scary to me. 
That's sys::InvokeExceptionHandler, a name which doesn't really make sense on 
Posix where it calls SignalHandler, and passes in the RetCode argument as the 
signal parameter. On Win32 it calls LLVMUnhandledExceptionFilter, and it does 
this inside the SEH filter function, although I think it will always return 
EXCEPTION_EXECUTE_HANDLER, so it could just be called inside the exception 
handler instead?

  On Posix, the call to SignalHandler looks scary, because it does a bunch of 
signal stuff, and e.g. on S390 hosts it raises the signal again to make sure to 
crash (which I don't think we want inside a CrashRecoveryContext).

  I wish the stack dumping and cleanup could be factored out into something 
that doesn't involve all the signal stuff, and that could have a clean 
interface that CrashRecoveryContext could simply call when it catches a crash. 
Maybe sys::DumpStackAndCleanup(...).  Do you think this would be possible?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70568



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


[PATCH] D70850: [Clang-Tidy] Quick fix for bug in bugprone-macro-parentheses 43804

2019-11-29 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added reviewers: alexfh, aaron.ballman.
baloghadamsoftware added a project: clang-tools-extra.
Herald added subscribers: mgehre, gamesh411, Szelethus, rnkovacs, xazax.hun, 
whisperity.
Herald added a project: clang.

Applying parentheses for statement leads to compilation error. Bug [[ 43804 | 
https://bugs.llvm.org/show_bug.cgi?id=43804 ]] is a compilation error suggested 
by a wrong fix of this checker. This patch is a quick fix for this issue.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D70850

Files:
  clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-macro-parentheses.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-macro-parentheses.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-macro-parentheses.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-macro-parentheses.cpp
@@ -43,6 +43,7 @@
 #define GOOD30(args...)   std::cout << args;
 #define GOOD31(X) A*X=2
 #define GOOD32(X) std::vector
+#define GOOD33(x) if (!a__##x) a_##x = &f(#x)
 
 // These are allowed for now..
 #define MAYBE1*12.34
Index: clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
@@ -54,7 +54,7 @@
 /// Is given TokenKind a keyword?
 static bool isKeyword(const Token &T) {
   // FIXME: better matching of keywords to avoid false positives.
-  return T.isOneOf(tok::kw_case, tok::kw_const, tok::kw_struct);
+  return T.isOneOf(tok::kw_if, tok::kw_case, tok::kw_const, tok::kw_struct);
 }
 
 /// Warning is written when one of these operators are not within parentheses.


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-macro-parentheses.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-macro-parentheses.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-macro-parentheses.cpp
@@ -43,6 +43,7 @@
 #define GOOD30(args...)   std::cout << args;
 #define GOOD31(X) A*X=2
 #define GOOD32(X) std::vector
+#define GOOD33(x) if (!a__##x) a_##x = &f(#x)
 
 // These are allowed for now..
 #define MAYBE1*12.34
Index: clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/MacroParenthesesCheck.cpp
@@ -54,7 +54,7 @@
 /// Is given TokenKind a keyword?
 static bool isKeyword(const Token &T) {
   // FIXME: better matching of keywords to avoid false positives.
-  return T.isOneOf(tok::kw_case, tok::kw_const, tok::kw_struct);
+  return T.isOneOf(tok::kw_if, tok::kw_case, tok::kw_const, tok::kw_struct);
 }
 
 /// Warning is written when one of these operators are not within parentheses.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70849: [AST] Traverse the class type loc inside the member type loc.

2019-11-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added subscribers: usaxena95, kadircet, mgorny.
Herald added a project: clang.

We are missing this currently.

This would fix https://github.com/clangd/clangd/issues/216.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70849

Files:
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp


Index: clang/unittests/Tooling/RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp
@@ -0,0 +1,37 @@
+//===- unittest/Tooling/RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp 
-===//
+//
+// 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 "TestVisitor.h"
+
+using namespace clang;
+
+namespace {
+
+class MemberPointerTypeLocVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool VisitRecordTypeLoc(RecordTypeLoc RTL) {
+if (!RTL)
+  return true;
+Match(RTL.getDecl()->getName(), RTL.getNameLoc());
+return true;
+  }
+};
+
+TEST(RecursiveASTVisitor, VisitTypeLocInMemberPointerTypeLoc) {
+  MemberPointerTypeLocVisitor Visitor;
+  Visitor.ExpectMatch("Bar", 4, 36);
+  EXPECT_TRUE(Visitor.runOver(R"cpp(
+ class Bar { void func(int); };
+ class Foo {
+   void bind(const char*, void(Bar::*Foo)(int)) {}
+ };
+  )cpp"));
+}
+
+} // end anonymous namespace
Index: clang/unittests/Tooling/CMakeLists.txt
===
--- clang/unittests/Tooling/CMakeLists.txt
+++ clang/unittests/Tooling/CMakeLists.txt
@@ -42,6 +42,7 @@
   RecursiveASTVisitorTests/LambdaDefaultCapture.cpp
   RecursiveASTVisitorTests/LambdaExpr.cpp
   RecursiveASTVisitorTests/LambdaTemplateParams.cpp
+  RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp
   RecursiveASTVisitorTests/NestedNameSpecifiers.cpp
   RecursiveASTVisitorTests/ParenExpr.cpp
   RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -1166,7 +1166,10 @@
 // We traverse this in the type case as well, but how is it not reached through
 // the pointee type?
 DEF_TRAVERSE_TYPELOC(MemberPointerType, {
-  TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
+  if (auto *TSI = TL.getClassTInfo())
+TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));
+  else
+TRY_TO(TraverseType(QualType(TL.getTypePtr()->getClass(), 0)));
   TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
 })
 


Index: clang/unittests/Tooling/RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp
@@ -0,0 +1,37 @@
+//===- unittest/Tooling/RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp -===//
+//
+// 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 "TestVisitor.h"
+
+using namespace clang;
+
+namespace {
+
+class MemberPointerTypeLocVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool VisitRecordTypeLoc(RecordTypeLoc RTL) {
+if (!RTL)
+  return true;
+Match(RTL.getDecl()->getName(), RTL.getNameLoc());
+return true;
+  }
+};
+
+TEST(RecursiveASTVisitor, VisitTypeLocInMemberPointerTypeLoc) {
+  MemberPointerTypeLocVisitor Visitor;
+  Visitor.ExpectMatch("Bar", 4, 36);
+  EXPECT_TRUE(Visitor.runOver(R"cpp(
+ class Bar { void func(int); };
+ class Foo {
+   void bind(const char*, void(Bar::*Foo)(int)) {}
+ };
+  )cpp"));
+}
+
+} // end anonymous namespace
Index: clang/unittests/Tooling/CMakeLists.txt
===
--- clang/unittests/Tooling/CMakeLists.txt
+++ clang/unittests/Tooling/CMakeLists.txt
@@ -42,6 +42,7 @@
   RecursiveASTVisitorTests/LambdaDefaultCapture.cpp
   RecursiveASTVisitorTests/LambdaExpr.cpp
   RecursiveASTVisitorTests/LambdaTemplateParams.cpp
+  RecursiveASTVisitorTests/MemberPointerTypeLoc.cpp
   RecursiveASTVisitorTests/NestedNameSpecifiers.cpp
   RecursiveASTVisitorTests/ParenExpr.cpp
   RecursiveASTVisitorTests/TemplateArgumentLocTraverser.cpp
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===

[PATCH] D70769: [Support] add vfs support for ExpandResponseFiles

2019-11-29 Thread James Henderson via Phabricator via cfe-commits
jhenderson added a comment.

In D70769#1763703 , @kadircet wrote:

> @jhenderson I am planning to commit this if the discussion around `std::errc` 
> vs `llvm::errc` is resolved, I don't have any preference towards one or the 
> other both seems to get the work done.


I'm not going to block this being committed. I do think llvm::errc exists for a 
reason, and those reasons are documented in the associated file, giving me the 
impression we should use it and not std::errc. However, I don't know how 
applicable those reasons really are nowadays - I'm certainly no authority on 
them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70769



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


[PATCH] D70769: [Support] add vfs support for ExpandResponseFiles

2019-11-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

@jhenderson I am planning to commit this if the discussion around `std::errc` 
vs `llvm::errc` is resolved, I don't have any preference towards one or the 
other both seems to get the work done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70769



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


[PATCH] D70656: [clangd] Define out-of-line qualify function name

2019-11-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 231513.
kadircet added a comment.

- Update comments after rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70656

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2006,7 +2006,7 @@
 Bar foo() ;
   }
 })cpp",
-   "a::Foo::Bar foo() { return {}; }\n"},
+   "a::Foo::Bar a::Foo::foo() { return {}; }\n"},
   {R"cpp(
 class Foo;
 Foo fo^o() { return; })cpp",
@@ -2024,6 +2024,58 @@
   }
 }
 
+TEST_F(DefineOutlineTest, QualifyFunctionName) {
+  FileName = "Test.hpp";
+  struct {
+llvm::StringRef TestHeader;
+llvm::StringRef TestSource;
+llvm::StringRef ExpectedHeader;
+llvm::StringRef ExpectedSource;
+  } Cases[] = {
+  {
+  R"cpp(
+namespace a {
+  namespace b {
+class Foo {
+  void fo^o() {}
+};
+  }
+})cpp",
+  "",
+  R"cpp(
+namespace a {
+  namespace b {
+class Foo {
+  void foo() ;
+};
+  }
+})cpp",
+  "void a::b::Foo::foo() {}\n",
+  },
+  {
+  "namespace a { namespace b { void f^oo() {} } }",
+  "namespace a{}",
+  "namespace a { namespace b { void foo() ; } }",
+  "namespace a{void b::foo() {} }",
+  },
+  {
+  "namespace a { namespace b { void f^oo() {} } }",
+  "using namespace a;",
+  "namespace a { namespace b { void foo() ; } }",
+  // FIXME: Take using namespace directives in the source file into
+  // account. This can be spelled as b::foo instead.
+  "using namespace a;void a::b::foo() {} ",
+  },
+  };
+  llvm::StringMap EditedFiles;
+  for (auto &Case : Cases) {
+ExtraFiles["Test.cpp"] = Case.TestSource;
+EXPECT_EQ(apply(Case.TestHeader, &EditedFiles), Case.ExpectedHeader);
+EXPECT_THAT(EditedFiles, testing::ElementsAre(FileWithContents(
+ testPath("Test.cpp"), Case.ExpectedSource)))
+<< Case.TestHeader;
+  }
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -107,7 +107,6 @@
 // Contains function signature, body and template parameters if applicable.
 // No need to qualify parameters, as they are looked up in the context
 // containing the function/method.
-// FIXME: Qualify function name depending on the target context.
 llvm::Expected
 getFunctionSourceCode(const FunctionDecl *FD, llvm::StringRef TargetNamespace) {
   auto &SM = FD->getASTContext().getSourceManager();
@@ -120,16 +119,17 @@
   llvm::Error Errors = llvm::Error::success();
   tooling::Replacements QualifierInsertions;
 
-  // Finds the first unqualified name in function return type and qualifies it
-  // to be valid in TargetContext.
+  // Finds the first unqualified name in function return type and name, then
+  // qualifies those to be valid in TargetContext.
   findExplicitReferences(FD, [&](ReferenceLoc Ref) {
 // It is enough to qualify the first qualifier, so skip references with a
 // qualifier. Also we can't do much if there are no targets or name is
 // inside a macro body.
 if (Ref.Qualifier || Ref.Targets.empty() || Ref.NameLoc.isMacroID())
   return;
-// Qualify return type
-if (Ref.NameLoc != FD->getReturnTypeSourceRange().getBegin())
+// Only qualify return type and function name.
+if (Ref.NameLoc != FD->getReturnTypeSourceRange().getBegin() &&
+Ref.NameLoc != FD->getLocation())
   return;
 
 for (const NamedDecl *ND : Ref.Targets) {
@@ -284,9 +284,7 @@
 auto FuncDef =
 getFunctionSourceCode(Source, InsertionPoint->EnclosingNamespace);
 if (!FuncDef)
-  return llvm::createStringError(
-  llvm::inconvertibleErrorCode(),
-  "Couldn't get full source for function definition.");
+  return FuncDef.takeError();
 
 SourceManagerForFile SMFF(*CCFile, Contents);
 const tooling::Replacement InsertFunctionDef(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70535: [clangd] Define out-of-line qualify return value

2019-11-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:153
+  // Get new begin and end positions for the qualified body.
+  auto OrigFuncRange = toHalfOpenFileRange(
+  SM, FD->getASTContext().getLangOpts(), FD->getSourceRange());

hokein wrote:
> we have similar code in define-inline as well, would be nice to have them in 
> a single place in the long term. probably a FIXME?
they're quite similar but, different in nature. one of them returns the full 
function definition, including template parameter lists, whereas the other only 
operates on function body.



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:1778
 
+TEST_F(DefineOutlineTest, QualifyReturnValue) {
+  FileName = "Test.hpp";

hokein wrote:
> can't we merge these into the above `ApplyTest`?
I would rather keep these separate, as these tests tends to get out of control 
otherwise, e.g. `Hover.All`



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:1810
+})cpp",
+   "a::Foo::Bar foo() { return {}; }\n"},
+  {R"cpp(

hokein wrote:
> oh, this is very tricky case (I think you meant to test the public members), 
> note that Bar and foo are private member of Foo, we can't move the body out 
> of the class `Foo`, for this case I think we should disallow the tweak.
> 
> No need to do it in this patch, but please update the test here (to test 
> public members).
I don't follow, the following compiles nicely:
```
namespace a {
class Foo {
  class Bar {};
  Bar foo();
};
}  // namespace a

a::Foo::Bar a::Foo::foo() { return {}; }
```

the problem here is we are not qualifying the function name, which is handled 
in the follow up patch D70656


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70535



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


[PATCH] D70656: [clangd] Define out-of-line qualify function name

2019-11-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 231512.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70656

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2006,7 +2006,7 @@
 Bar foo() ;
   }
 })cpp",
-   "a::Foo::Bar foo() { return {}; }\n"},
+   "a::Foo::Bar a::Foo::foo() { return {}; }\n"},
   {R"cpp(
 class Foo;
 Foo fo^o() { return; })cpp",
@@ -2024,6 +2024,58 @@
   }
 }
 
+TEST_F(DefineOutlineTest, QualifyFunctionName) {
+  FileName = "Test.hpp";
+  struct {
+llvm::StringRef TestHeader;
+llvm::StringRef TestSource;
+llvm::StringRef ExpectedHeader;
+llvm::StringRef ExpectedSource;
+  } Cases[] = {
+  {
+  R"cpp(
+namespace a {
+  namespace b {
+class Foo {
+  void fo^o() {}
+};
+  }
+})cpp",
+  "",
+  R"cpp(
+namespace a {
+  namespace b {
+class Foo {
+  void foo() ;
+};
+  }
+})cpp",
+  "void a::b::Foo::foo() {}\n",
+  },
+  {
+  "namespace a { namespace b { void f^oo() {} } }",
+  "namespace a{}",
+  "namespace a { namespace b { void foo() ; } }",
+  "namespace a{void b::foo() {} }",
+  },
+  {
+  "namespace a { namespace b { void f^oo() {} } }",
+  "using namespace a;",
+  "namespace a { namespace b { void foo() ; } }",
+  // FIXME: Take using namespace directives in the source file into
+  // account. This can be spelled as b::foo instead.
+  "using namespace a;void a::b::foo() {} ",
+  },
+  };
+  llvm::StringMap EditedFiles;
+  for (auto &Case : Cases) {
+ExtraFiles["Test.cpp"] = Case.TestSource;
+EXPECT_EQ(apply(Case.TestHeader, &EditedFiles), Case.ExpectedHeader);
+EXPECT_THAT(EditedFiles, testing::ElementsAre(FileWithContents(
+ testPath("Test.cpp"), Case.ExpectedSource)))
+<< Case.TestHeader;
+  }
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -128,8 +128,9 @@
 // inside a macro body.
 if (Ref.Qualifier || Ref.Targets.empty() || Ref.NameLoc.isMacroID())
   return;
-// Qualify return type
-if (Ref.NameLoc != FD->getReturnTypeSourceRange().getBegin())
+// Only qualify return type and function name.
+if (Ref.NameLoc != FD->getReturnTypeSourceRange().getBegin() &&
+Ref.NameLoc != FD->getLocation())
   return;
 
 for (const NamedDecl *ND : Ref.Targets) {
@@ -284,9 +285,7 @@
 auto FuncDef =
 getFunctionSourceCode(Source, InsertionPoint->EnclosingNamespace);
 if (!FuncDef)
-  return llvm::createStringError(
-  llvm::inconvertibleErrorCode(),
-  "Couldn't get full source for function definition.");
+  return FuncDef.takeError();
 
 SourceManagerForFile SMFF(*CCFile, Contents);
 const tooling::Replacement InsertFunctionDef(


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2006,7 +2006,7 @@
 Bar foo() ;
   }
 })cpp",
-   "a::Foo::Bar foo() { return {}; }\n"},
+   "a::Foo::Bar a::Foo::foo() { return {}; }\n"},
   {R"cpp(
 class Foo;
 Foo fo^o() { return; })cpp",
@@ -2024,6 +2024,58 @@
   }
 }
 
+TEST_F(DefineOutlineTest, QualifyFunctionName) {
+  FileName = "Test.hpp";
+  struct {
+llvm::StringRef TestHeader;
+llvm::StringRef TestSource;
+llvm::StringRef ExpectedHeader;
+llvm::StringRef ExpectedSource;
+  } Cases[] = {
+  {
+  R"cpp(
+namespace a {
+  namespace b {
+class Foo {
+  void fo^o() {}
+};
+  }
+})cpp",
+  "",
+  R"cpp(
+namespace a {
+  namespace b {
+class Foo {
+  void foo() ;
+};
+  }
+})cpp",
+  "void a::b::Foo::foo() {}\n",
+  },
+  {
+  "namespace a { n

[PATCH] D70832: [clangd] Log cc1 args at verbose level.

2019-11-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 3 inline comments as done.
sammccall added a comment.

Sorry about committing this too early, had it confused with another patch. 
Fixed in 4f000824222f97c0cfd5b19951a1068132e57e79 





Comment at: clang-tools-extra/clangd/TUScheduler.cpp:412
 std::unique_ptr Invocation =
 buildCompilerInvocation(Inputs, CompilerInvocationDiagConsumer);
+// Log cc1 args even (especially!) if creating invocation failed.

kbobyrev wrote:
> `buildCompilerInvocation(Inputs, CompilerInvocationDiagConsumer, &CC1Args)`? 
> Otherwise, I think the vector would always be empty, right?
You're right, I changed this after testing it.

Fixed in 4f000824222f97c0cfd5b19951a1068132e57e79



Comment at: clang/include/clang/Frontend/Utils.h:231
+bool ShouldRecoverOnErrors = false,
+std::vector *CC1Args = nullptr);
 

kbobyrev wrote:
> Nit: `llvm::Optional` might look better for `CC1Args`
Doesn't really work as we want optional + pass-by-reference here - a pointer is 
the usual idiom.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70832



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


[PATCH] D70535: [clangd] Define out-of-line qualify return value

2019-11-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 231511.
kadircet marked 9 inline comments as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70535

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -1974,6 +1974,56 @@
   }
 }
 
+TEST_F(DefineOutlineTest, QualifyReturnValue) {
+  FileName = "Test.hpp";
+  ExtraFiles["Test.cpp"] = "";
+
+  struct {
+llvm::StringRef Test;
+llvm::StringRef ExpectedHeader;
+llvm::StringRef ExpectedSource;
+  } Cases[] = {
+  {R"cpp(
+namespace a { class Foo; }
+using namespace a;
+Foo fo^o() { return; })cpp",
+   R"cpp(
+namespace a { class Foo; }
+using namespace a;
+Foo foo() ;)cpp",
+   "a::Foo foo() { return; }"},
+  {R"cpp(
+namespace a {
+  class Foo {
+class Bar {};
+Bar fo^o() { return {}; }
+  }
+})cpp",
+   R"cpp(
+namespace a {
+  class Foo {
+class Bar {};
+Bar foo() ;
+  }
+})cpp",
+   "a::Foo::Bar foo() { return {}; }\n"},
+  {R"cpp(
+class Foo;
+Foo fo^o() { return; })cpp",
+   R"cpp(
+class Foo;
+Foo foo() ;)cpp",
+   "Foo foo() { return; }"},
+  };
+  llvm::StringMap EditedFiles;
+  for (auto &Case : Cases) {
+apply(Case.Test, &EditedFiles);
+EXPECT_EQ(apply(Case.Test, &EditedFiles), Case.ExpectedHeader);
+EXPECT_THAT(EditedFiles, testing::ElementsAre(FileWithContents(
+ testPath("Test.cpp"), Case.ExpectedSource)));
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -6,13 +6,17 @@
 //
 //===--===//
 
+#include "AST.h"
+#include "FindTarget.h"
 #include "HeaderSourceSwitch.h"
+#include "Logger.h"
 #include "Path.h"
 #include "Selection.h"
 #include "SourceCode.h"
 #include "refactor/Tweak.h"
 #include "clang/AST/ASTTypeTraits.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Stmt.h"
 #include "clang/Basic/SourceLocation.h"
@@ -20,10 +24,13 @@
 #include "clang/Driver/Types.h"
 #include "clang/Format/Format.h"
 #include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/Error.h"
 #include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -57,31 +64,127 @@
   return getCorrespondingHeaderOrSource(FileName, Sel.AST, Sel.Index);
 }
 
+// Synthesize a DeclContext for TargetNS from CurContext. TargetNS must be empty
+// for global namespace, and endwith "::" otherwise.
+// Returns None if TargetNS is not a prefix of CurContext.
+llvm::Optional
+findContextForNS(llvm::StringRef TargetNS, const DeclContext *CurContext) {
+  assert(TargetNS.empty() || TargetNS.endswith("::"));
+  // Skip any non-namespace contexts, e.g. TagDecls, functions/methods.
+  CurContext = CurContext->getEnclosingNamespaceContext();
+  // If TargetNS is empty, it means global ns, which is translation unit.
+  if (TargetNS.empty()) {
+while (!CurContext->isTranslationUnit())
+  CurContext = CurContext->getParent();
+return CurContext;
+  }
+  // Otherwise we need to drop any trailing namespaces from CurContext until
+  // we reach TargetNS.
+  std::string TargetContextNS =
+  CurContext->isNamespace()
+  ? llvm::cast(CurContext)->getQualifiedNameAsString()
+  : "";
+  TargetContextNS.append("::");
+
+  llvm::StringRef CurrentContextNS(TargetContextNS);
+  // If TargetNS is not a prefix of CurrentContext, there's no way to reach
+  // it.
+  if (!CurrentContextNS.startswith(TargetNS))
+return llvm::None;
+
+  while (CurrentContextNS != TargetNS) {
+CurContext = CurContext->getParent();
+// These colons always exists since TargetNS is a prefix of
+// CurrentContextNS, it ends with "::" and they are not equal.
+CurrentContextNS = CurrentContextNS.take_front(
+CurrentContextNS.drop_back(2).rfind("::") + 2);
+  }
+  return CurContext;
+}
+
 // Creates a modified version of function definition that can be inserted at a
-// different location. Contains both function signature and body.

[clang-tools-extra] 4f00082 - [clangd] Fix 407ac2e, which was broken and committed too soon

2019-11-29 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2019-11-29T12:05:12+01:00
New Revision: 4f000824222f97c0cfd5b19951a1068132e57e79

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

LOG: [clangd] Fix 407ac2e, which was broken and committed too soon

Added: 


Modified: 
clang-tools-extra/clangd/TUScheduler.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index b51221d7d903..884c82d5b190 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -408,11 +408,11 @@ void ASTWorker::update(ParseInputs Inputs, 
WantDiagnostics WantDiags) {
 // Rebuild the preamble and the AST.
 StoreDiags CompilerInvocationDiagConsumer;
 std::vector CC1Args;
-std::unique_ptr Invocation =
-buildCompilerInvocation(Inputs, CompilerInvocationDiagConsumer);
+std::unique_ptr Invocation = buildCompilerInvocation(
+Inputs, CompilerInvocationDiagConsumer, &CC1Args);
 // Log cc1 args even (especially!) if creating invocation failed.
 if (!CC1Args.empty())
-  vlog("cc1 args: {0}", llvm::join(CC1Args, " "));
+  vlog("Driver produced command: cc1 {0}", llvm::join(CC1Args, " "));
 std::vector CompilerInvocationDiags =
 CompilerInvocationDiagConsumer.take();
 if (!Invocation) {



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


[PATCH] D70222: [clang][Tooling] Add support for .rsp files in compile_commands.json

2019-11-29 Thread liu hui via Phabricator via cfe-commits
lh123 added a comment.

In D70222#1763553 , @kadircet wrote:

> Thanks a lot for working on this patch, LGTM!
>
> again please make sure the changes are clang-formatted.


I'm sure the code has been formatted.

> Do you have commit access?

I don't have commit access, please commit it for me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70222



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


[PATCH] D70769: [Support] add vfs support for ExpandResponseFiles

2019-11-29 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 231510.
lh123 marked an inline comment as done.
lh123 added a comment.

fix typo:
"Could not convert UTF16 To UTF8" -> "Could not convert UTF16 to UTF8"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70769

Files:
  llvm/include/llvm/Support/CommandLine.h
  llvm/lib/Support/CommandLine.cpp

Index: llvm/lib/Support/CommandLine.cpp
===
--- llvm/lib/Support/CommandLine.cpp
+++ llvm/lib/Support/CommandLine.cpp
@@ -29,6 +29,7 @@
 #include "llvm/Config/config.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Host.h"
@@ -37,6 +38,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/StringSaver.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -1043,14 +1045,18 @@
   return (S.size() >= 3 && S[0] == '\xef' && S[1] == '\xbb' && S[2] == '\xbf');
 }
 
-static bool ExpandResponseFile(StringRef FName, StringSaver &Saver,
+static llvm::Error ExpandResponseFile(StringRef FName, StringSaver &Saver,
TokenizerCallback Tokenizer,
SmallVectorImpl &NewArgv,
-   bool MarkEOLs, bool RelativeNames) {
-  ErrorOr> MemBufOrErr =
-  MemoryBuffer::getFile(FName);
+   bool MarkEOLs, bool RelativeNames,
+   llvm::vfs::FileSystem &FS) {
+  llvm::ErrorOr CurrDirOrErr = FS.getCurrentWorkingDirectory();
+  if (!CurrDirOrErr)
+return llvm::errorCodeToError(CurrDirOrErr.getError());
+  llvm::ErrorOr> MemBufOrErr =
+  FS.getBufferForFile(FName);
   if (!MemBufOrErr)
-return false;
+return llvm::errorCodeToError(MemBufOrErr.getError());
   MemoryBuffer &MemBuf = *MemBufOrErr.get();
   StringRef Str(MemBuf.getBufferStart(), MemBuf.getBufferSize());
 
@@ -1059,7 +1065,8 @@
   std::string UTF8Buf;
   if (hasUTF16ByteOrderMark(BufRef)) {
 if (!convertUTF16ToUTF8String(BufRef, UTF8Buf))
-  return false;
+  return llvm::createStringError(std::errc::illegal_byte_sequence,
+ "Could not convert UTF16 to UTF8");
 Str = StringRef(UTF8Buf);
   }
   // If we see UTF-8 BOM sequence at the beginning of a file, we shall remove
@@ -1084,9 +1091,7 @@
 SmallString<128> ResponseFile;
 ResponseFile.append(1, '@');
 if (llvm::sys::path::is_relative(FName)) {
-  SmallString<128> curr_dir;
-  llvm::sys::fs::current_path(curr_dir);
-  ResponseFile.append(curr_dir.str());
+  ResponseFile.append(CurrDirOrErr.get());
 }
 llvm::sys::path::append(
 ResponseFile, llvm::sys::path::parent_path(FName), FileName);
@@ -1095,14 +1100,14 @@
 }
   }
 
-  return true;
+  return Error::success();
 }
 
 /// Expand response files on a command line recursively using the given
 /// StringSaver and tokenization strategy.
 bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
- SmallVectorImpl &Argv,
- bool MarkEOLs, bool RelativeNames) {
+ SmallVectorImpl &Argv, bool MarkEOLs,
+ bool RelativeNames, llvm::vfs::FileSystem &FS) {
   bool AllExpanded = true;
   struct ResponseFileRecord {
 const char *File;
@@ -1139,8 +1144,20 @@
 }
 
 const char *FName = Arg + 1;
-auto IsEquivalent = [FName](const ResponseFileRecord &RFile) {
-  return sys::fs::equivalent(RFile.File, FName);
+auto IsEquivalent = [FName, &FS](const ResponseFileRecord &RFile) {
+  llvm::ErrorOr LHS = FS.status(FName);
+  if (!LHS) {
+// TODO: The error should be propagated up the stack.
+llvm::consumeError(llvm::errorCodeToError(LHS.getError()));
+return false;
+  }
+  llvm::ErrorOr RHS = FS.status(RFile.File);
+  if (!RHS) {
+// TODO: The error should be propagated up the stack.
+llvm::consumeError(llvm::errorCodeToError(RHS.getError()));
+return false;
+  }
+  return LHS->equivalent(*RHS);
 };
 
 // Check for recursive response files.
@@ -1155,10 +1172,13 @@
 // Replace this response file argument with the tokenization of its
 // contents.  Nested response files are expanded in subsequent iterations.
 SmallVector ExpandedArgv;
-if (!ExpandResponseFile(FName, Saver, Tokenizer, ExpandedArgv, MarkEOLs,
-RelativeNames)) {
+if (llvm::Error Err =
+ExpandResponseFile(FName, Saver, Tokenizer, ExpandedArgv, MarkEOLs,
+   

[PATCH] D60455: [SYCL] Add sycl_kernel attribute for accelerated code outlining

2019-11-29 Thread Alexey Bader via Phabricator via cfe-commits
bader updated this revision to Diff 231506.
bader added a comment.

Minor update adjusting to the recent changes.

Updated comment "The 'sycl_kernel' attribute applies only to functions" -> "The 
'sycl_kernel' attribute applies only to function templates".
Renamed tests from "device-attributes*" to "kernel-attribute*".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60455

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaSYCL/kernel-attribute-on-non-sycl.cpp
  clang/test/SemaSYCL/kernel-attribute.cpp

Index: clang/test/SemaSYCL/kernel-attribute.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/kernel-attribute.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
+
+[[clang::sycl_kernel]] int gv2 = 0; // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
+__attribute__((sycl_kernel)) int gv3 = 0; // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
+
+__attribute__((sycl_kernel(1))) void foo(); // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
+[[clang::sycl_kernel(1)]] void foo2(); // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
+
+// Only function templates
+__attribute__((sycl_kernel)) void foo(); // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
+[[clang::sycl_kernel]] void foo1(); // expected-warning {{'sycl_kernel' attribute only applies to function templates}}
+
+// At least two template parameters
+template 
+__attribute__((sycl_kernel)) void foo(T P); // expected-warning {{'sycl_kernel' attribute only applies to a function template with at least two template parameters}}
+template 
+[[clang::sycl_kernel]] void foo1(T P); // expected-warning {{'sycl_kernel' attribute only applies to a function template with at least two template parameters}}
+
+// First two template parameters cannot be non-type template parameters
+template 
+__attribute__((sycl_kernel)) void foo(T P); // expected-warning {{template parameter of a function template with the 'sycl_kernel' attribute cannot be a non-type template parameter}}
+template 
+[[clang::sycl_kernel]] void foo1(T P); // expected-warning {{template parameter of a function template with the 'sycl_kernel' attribute cannot be a non-type template parameter}}
+
+// Must return void
+template 
+__attribute__((sycl_kernel)) int foo(T P); // expected-warning {{function template with 'sycl_kernel' attribute must have a 'void' return type}}
+template 
+[[clang::sycl_kernel]] int foo1(T P); // expected-warning {{function template with 'sycl_kernel' attribute must have a 'void' return type}}
+
+// Must take at least one argument
+template 
+__attribute__((sycl_kernel)) void foo(); // expected-warning {{function template with 'sycl_kernel' attribute must have a single parameter}}
+template 
+[[clang::sycl_kernel]] void foo1(T t, A a); // expected-warning {{function template with 'sycl_kernel' attribute must have a single parameter}}
+
+// No diagnostics
+template 
+__attribute__((sycl_kernel)) void foo(T P);
+template 
+[[clang::sycl_kernel]] void foo1(T P);
Index: clang/test/SemaSYCL/kernel-attribute-on-non-sycl.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/kernel-attribute-on-non-sycl.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -x c++ %s
+
+#ifndef __SYCL_DEVICE_ONLY__
+// expected-warning@+7 {{'sycl_kernel' attribute ignored}}
+// expected-warning@+8 {{'sycl_kernel' attribute ignored}}
+#else
+// expected-no-diagnostics
+#endif
+
+template 
+__attribute__((sycl_kernel)) void foo(T P);
+template 
+[[clang::sycl_kernel]] void foo1(T P);
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6412,6 +6412,45 @@
   D->addAttr(::new (S.Context) OpenCLAccessAttr(S.Context, AL));
 }
 
+static void handleSYCLKernelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  // The 'sycl_kernel' attribute applies only to function templates.
+  const auto *FD = cast(D);
+  const FunctionTemplateDecl *FT = FD->getDescribedFunctionTemplate();
+  assert(FT && "Function template is expected");
+
+  // Function template must have at least two template parameters.
+  const TemplateParameterList *TL = FT->getTemplateParameters();
+  if (TL->size() < 2) {
+S.Diag(FT->getLocation(), diag::warn_sycl_kernel_num_of_template_params);
+return;
+  }
+
+  // Template parameters must be typenames.
+  for (unsigned I = 0; I < 2; ++I) {
+   

[PATCH] D70787: [Syntax] Build SimpleDeclaration node that groups multiple declarators

2019-11-29 Thread Ilya Biryukov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe702bdb8598f: [Syntax] Build SimpleDeclaration node that 
groups multiple declarators (authored by ilya-biryukov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70787

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -130,7 +130,7 @@
 )cpp",
   R"txt(
 *: TranslationUnit
-|-TopLevelDeclaration
+|-SimpleDeclaration
 | |-int
 | |-main
 | |-(
@@ -138,7 +138,7 @@
 | `-CompoundStatement
 |   |-{
 |   `-}
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-foo
   |-(
@@ -157,7 +157,7 @@
 )cpp",
   R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-int
   |-main
   |-(
@@ -202,7 +202,7 @@
 )cpp",
R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-test
   |-(
@@ -224,7 +224,7 @@
   {"void test() { int a = 10; }",
R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-test
   |-(
@@ -232,16 +232,18 @@
   `-CompoundStatement
 |-{
 |-DeclarationStatement
-| |-int
-| |-a
-| |-=
-| |-10
+| |-SimpleDeclaration
+| | |-int
+| | |-a
+| | |-=
+| | `-UnknownExpression
+| |   `-10
 | `-;
 `-}
 )txt"},
   {"void test() { ; }", R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-test
   |-(
@@ -263,7 +265,7 @@
 )cpp",
R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-test
   |-(
@@ -299,7 +301,7 @@
 )cpp",
R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-test
   |-(
@@ -329,7 +331,7 @@
   )cpp",
R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-int
   |-test
   |-(
@@ -352,7 +354,7 @@
   )cpp",
R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-test
   |-(
@@ -360,18 +362,21 @@
   `-CompoundStatement
 |-{
 |-DeclarationStatement
-| |-int
-| |-a
-| |-[
-| |-3
-| |-]
+| |-SimpleDeclaration
+| | |-int
+| | |-a
+| | |-[
+| | |-UnknownExpression
+| | | `-3
+| | `-]
 | `-;
 |-RangeBasedForStatement
 | |-for
 | |-(
-| |-int
-| |-x
-| |-:
+| |-SimpleDeclaration
+| | |-int
+| | |-x
+| | `-:
 | |-UnknownExpression
 | | `-a
 | |-)
@@ -384,7 +389,7 @@
   // counterpart.
   {"void main() { foo: return 100; }", R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-main
   |-(
@@ -411,7 +416,7 @@
 )cpp",
R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-test
   |-(
@@ -444,7 +449,70 @@
 |   | `-)
 |   `-;
 `-}
-)txt"}};
+)txt"},
+  // Multiple declarators group into a single SimpleDeclaration.
+  {R"cpp(
+  int *a, b;
+  )cpp",
+   R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-int
+  |-*
+  |-a
+  |-,
+  |-b
+  `-;
+  )txt"},
+  {R"cpp(
+typedef int *a, b;
+  )cpp",
+   R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-typedef
+  |-int
+  |-*
+  |-a
+  |-,
+  |-b
+  `-;
+  )txt"},
+  // Multiple declarators inside a statement.
+  {R"cpp(
+void foo() {
+  int *a, b;
+  typedef int *ta, tb;
+}
+  )cpp",
+   R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-foo
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-DeclarationStatement
+| |-SimpleDeclaration
+| | |-int
+| | |-*
+| | |-a
+| | |-,
+| | `-b
+| `-;
+|-DeclarationStatement
+| |-SimpleDeclaration
+| | |-typedef
+| | |-int
+| | |-*
+| | |-ta
+| | |-,
+| | `-tb
+| `-;
+`-}
+  )txt"}};
 
   for (const auto &T : Cases) {
 auto *Root = buildTree(T.first);
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -16,8 +16,6 @@
 return OS << "Leaf";
   case NodeKind::TranslationUnit:
 return OS << "TranslationUnit";
-  case NodeKind::TopLevelDeclaration:
-return OS << "TopLevelDeclaration";
   case NodeKind::UnknownExpression:
 return OS << "UnknownExpression";
   case NodeKind::UnknownStatement:
@@ -50,6 +48,10 @@
 return OS << "ExpressionStatement";
   case NodeKind::CompoundStatement:
 return OS << "CompoundStatement";
+  case NodeKind::UnknownDeclaration:
+retur

[PATCH] D70787: [Syntax] Build SimpleDeclaration node that groups multiple declarators

2019-11-29 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 231504.
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.

Add tests with declarations inside function body


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70787

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -130,7 +130,7 @@
 )cpp",
   R"txt(
 *: TranslationUnit
-|-TopLevelDeclaration
+|-SimpleDeclaration
 | |-int
 | |-main
 | |-(
@@ -138,7 +138,7 @@
 | `-CompoundStatement
 |   |-{
 |   `-}
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-foo
   |-(
@@ -157,7 +157,7 @@
 )cpp",
   R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-int
   |-main
   |-(
@@ -202,7 +202,7 @@
 )cpp",
R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-test
   |-(
@@ -224,7 +224,7 @@
   {"void test() { int a = 10; }",
R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-test
   |-(
@@ -232,16 +232,18 @@
   `-CompoundStatement
 |-{
 |-DeclarationStatement
-| |-int
-| |-a
-| |-=
-| |-10
+| |-SimpleDeclaration
+| | |-int
+| | |-a
+| | |-=
+| | `-UnknownExpression
+| |   `-10
 | `-;
 `-}
 )txt"},
   {"void test() { ; }", R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-test
   |-(
@@ -263,7 +265,7 @@
 )cpp",
R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-test
   |-(
@@ -299,7 +301,7 @@
 )cpp",
R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-test
   |-(
@@ -329,7 +331,7 @@
   )cpp",
R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-int
   |-test
   |-(
@@ -352,7 +354,7 @@
   )cpp",
R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-test
   |-(
@@ -360,18 +362,21 @@
   `-CompoundStatement
 |-{
 |-DeclarationStatement
-| |-int
-| |-a
-| |-[
-| |-3
-| |-]
+| |-SimpleDeclaration
+| | |-int
+| | |-a
+| | |-[
+| | |-UnknownExpression
+| | | `-3
+| | `-]
 | `-;
 |-RangeBasedForStatement
 | |-for
 | |-(
-| |-int
-| |-x
-| |-:
+| |-SimpleDeclaration
+| | |-int
+| | |-x
+| | `-:
 | |-UnknownExpression
 | | `-a
 | |-)
@@ -384,7 +389,7 @@
   // counterpart.
   {"void main() { foo: return 100; }", R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-main
   |-(
@@ -411,7 +416,7 @@
 )cpp",
R"txt(
 *: TranslationUnit
-`-TopLevelDeclaration
+`-SimpleDeclaration
   |-void
   |-test
   |-(
@@ -444,7 +449,70 @@
 |   | `-)
 |   `-;
 `-}
-)txt"}};
+)txt"},
+  // Multiple declarators group into a single SimpleDeclaration.
+  {R"cpp(
+  int *a, b;
+  )cpp",
+   R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-int
+  |-*
+  |-a
+  |-,
+  |-b
+  `-;
+  )txt"},
+  {R"cpp(
+typedef int *a, b;
+  )cpp",
+   R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-typedef
+  |-int
+  |-*
+  |-a
+  |-,
+  |-b
+  `-;
+  )txt"},
+  // Multiple declarators inside a statement.
+  {R"cpp(
+void foo() {
+  int *a, b;
+  typedef int *ta, tb;
+}
+  )cpp",
+   R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-foo
+  |-(
+  |-)
+  `-CompoundStatement
+|-{
+|-DeclarationStatement
+| |-SimpleDeclaration
+| | |-int
+| | |-*
+| | |-a
+| | |-,
+| | `-b
+| `-;
+|-DeclarationStatement
+| |-SimpleDeclaration
+| | |-typedef
+| | |-int
+| | |-*
+| | |-ta
+| | |-,
+| | `-tb
+| `-;
+`-}
+  )txt"}};
 
   for (const auto &T : Cases) {
 auto *Root = buildTree(T.first);
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -16,8 +16,6 @@
 return OS << "Leaf";
   case NodeKind::TranslationUnit:
 return OS << "TranslationUnit";
-  case NodeKind::TopLevelDeclaration:
-return OS << "TopLevelDeclaration";
   case NodeKind::UnknownExpression:
 return OS << "UnknownExpression";
   case NodeKind::UnknownStatement:
@@ -50,6 +48,10 @@
 return OS << "ExpressionStatement";
   case NodeKind::CompoundStatement:
 return OS << "CompoundStatement";
+  case NodeKind::UnknownDeclaration:
+return OS << "UnknownDeclaratio

[clang] e702bdb - [Syntax] Build SimpleDeclaration node that groups multiple declarators

2019-11-29 Thread Ilya Biryukov via cfe-commits

Author: Ilya Biryukov
Date: 2019-11-29T11:39:45+01:00
New Revision: e702bdb8598fcb4224f465569e7692a155c3eb3e

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

LOG: [Syntax] Build SimpleDeclaration node that groups multiple declarators

Summary:
Also remove the temporary TopLevelDeclaration node and add
UnknownDeclaration to represent other unknown nodes.

See the follow-up change for building more top-level declarations.
Adding declarators is also pretty involved and will be done in another
follow-up patch.

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: merge_guards_bot, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Nodes.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/lib/Tooling/Syntax/Nodes.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Nodes.h 
b/clang/include/clang/Tooling/Syntax/Nodes.h
index c40b6bd24817..c4db4da892c2 100644
--- a/clang/include/clang/Tooling/Syntax/Nodes.h
+++ b/clang/include/clang/Tooling/Syntax/Nodes.h
@@ -37,7 +37,6 @@ namespace syntax {
 enum class NodeKind : uint16_t {
   Leaf,
   TranslationUnit,
-  TopLevelDeclaration,
 
   // Expressions
   UnknownExpression,
@@ -57,7 +56,11 @@ enum class NodeKind : uint16_t {
   ReturnStatement,
   RangeBasedForStatement,
   ExpressionStatement,
-  CompoundStatement
+  CompoundStatement,
+
+  // Declarations
+  UnknownDeclaration,
+  SimpleDeclaration,
 };
 /// For debugging purposes.
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, NodeKind K);
@@ -102,20 +105,6 @@ class TranslationUnit final : public Tree {
   }
 };
 
-/// FIXME: this node is temporary and will be replaced with nodes for various
-///'declarations' and 'declarators' from the C/C++ grammar
-///
-/// Represents any top-level declaration. Only there to give the syntax tree a
-/// bit of structure until we implement syntax nodes for declarations and
-/// declarators.
-class TopLevelDeclaration final : public Tree {
-public:
-  TopLevelDeclaration() : Tree(NodeKind::TopLevelDeclaration) {}
-  static bool classof(const Node *N) {
-return N->kind() == NodeKind::TopLevelDeclaration;
-  }
-};
-
 /// A base class for all expressions. Note that expressions are not statements,
 /// even though they are in clang.
 class Expression : public Tree {
@@ -313,6 +302,38 @@ class CompoundStatement final : public Statement {
   syntax::Leaf *rbrace();
 };
 
+/// A declaration that can appear at the top-level. Note that this does *not*
+/// correspond 1-to-1 to clang::Decl. Syntax trees distinguish between 
top-level
+/// declarations (e.g. namespace definitions) and declarators (e.g. variables,
+/// typedefs, etc.). Declarators are stored inside SimpleDeclaration.
+class Declaration : public Tree {
+public:
+  Declaration(NodeKind K) : Tree(K) {}
+  static bool classof(const Node *N) {
+return NodeKind::UnknownDeclaration <= N->kind() &&
+   N->kind() <= NodeKind::SimpleDeclaration;
+  }
+};
+
+/// Declaration of an unknown kind, e.g. not yet supported in syntax trees.
+class UnknownDeclaration final : public Declaration {
+public:
+  UnknownDeclaration() : Declaration(NodeKind::UnknownDeclaration) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::UnknownDeclaration;
+  }
+};
+
+/// Groups multiple declarators (e.g. variables, typedefs, etc.) together. All
+/// grouped declarators share the same declaration specifiers (e.g. 'int' or
+/// 'typedef').
+class SimpleDeclaration final : public Declaration {
+public:
+  SimpleDeclaration() : Declaration(NodeKind::SimpleDeclaration) {}
+  static bool classof(const Node *N) {
+return N->kind() == NodeKind::SimpleDeclaration;
+  }
+};
 } // namespace syntax
 } // namespace clang
 #endif

diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 22cdb89b7bfb..67081497d04c 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -6,6 +6,8 @@
 //
 
//===--===//
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclBase.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/Basic/LLVM.h"
@@ -56,6 +58,14 @@ class syntax::TreeBuilder {
   /// Range.
   void foldNode(llvm::ArrayRef Range, syntax::Tree *New);
 
+  /// Must be called with the range of each `DeclaratorDecl`. Ensures the
+  /// corresponding declarator nodes are covered by `SimpleDeclaration`.
+  void noticeDeclaratorRange(llvm::ArrayRef Range);
+
+  /// Notifies that we should not consume trail

[PATCH] D70832: [clangd] Log cc1 args at verbose level.

2019-11-29 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

Sorry, seems I was too late :(




Comment at: clang-tools-extra/clangd/TUScheduler.cpp:412
 std::unique_ptr Invocation =
 buildCompilerInvocation(Inputs, CompilerInvocationDiagConsumer);
+// Log cc1 args even (especially!) if creating invocation failed.

`buildCompilerInvocation(Inputs, CompilerInvocationDiagConsumer, &CC1Args)`? 
Otherwise, I think the vector would always be empty, right?



Comment at: clang/include/clang/Frontend/Utils.h:231
+bool ShouldRecoverOnErrors = false,
+std::vector *CC1Args = nullptr);
 

Nit: `llvm::Optional` might look better for `CC1Args`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70832



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


[PATCH] D70787: [Syntax] Build SimpleDeclaration node that groups multiple declarators

2019-11-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:453
+)txt"},
+  // Multiple declarators group into a single SimpleDeclaration.
+  {R"cpp(

Could you add two tests that are like these two, but within a function body?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70787



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


[clang] 4b24ab1 - [AST] Remove unused and undefined `TypeLoc::IgnoreMacroDefinitions` function. NFC

2019-11-29 Thread Ilya Biryukov via cfe-commits

Author: Ilya Biryukov
Date: 2019-11-29T11:21:07+01:00
New Revision: 4b24ab181aef58c6e2001e630331385648db3c08

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

LOG: [AST] Remove unused and undefined `TypeLoc::IgnoreMacroDefinitions` 
function. NFC

Looks like an accidental leftover from the older version of the code.

Added: 


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

Removed: 




diff  --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index f305680d775c..7f1d429ac3b4 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -173,9 +173,6 @@ class TypeLoc {
 
   TypeLoc IgnoreParens() const;
 
-  /// Strips MacroDefinitionTypeLocs from a type location.
-  TypeLoc IgnoreMacroDefinitions() const;
-
   /// Find a type with the location of an explicit type qualifier.
   ///
   /// The result, if non-null, will be one of:



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


[PATCH] D70656: [clangd] Define out-of-line qualify function name

2019-11-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:1831
+  struct {
+llvm::StringRef Test;
+llvm::StringRef SourceFile;

maybe name them `TestHeader`, and `TestSource`.



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:1854
+   "void a::b::Foo::foo() {}\n"},
+  {"namespace a { namespace b { void f^oo() {} } }", "namespace a{}",
+   "namespace a { namespace b { void foo() ; } }",

nit: could we keep each string per line? It would improve the code readability 
here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70656



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


[PATCH] D54149: [Analyzer] [WIP] Standard C++ library functions checker for the std::find() family

2019-11-29 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

The modeling framework in its current state cannot be used for detailed 
modeling of complex functions. Even detailed modeling (including handling of 
`GDM` data for checkers) of standard C functions are done manually: see `C 
string` and `stream` checkers. Template functions of the `C++ STL` are more 
complex, creating a generic modeling framework would be huge multi-year project 
for which we currently lack the resources. So we decided to model these 
functions manually: Model STL Algoirthms to improve the iterator checkers 



Repository:
  rC Clang

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

https://reviews.llvm.org/D54149



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


[PATCH] D49074: [Analyzer] Basic support for multiplication and division in the constraint manager

2019-11-29 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

We have applied this patch in our internal release and our users have used it 
for more than half a year without any problems: no crashes, no freezes and no 
suspicious false positives caused by it.


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

https://reviews.llvm.org/D49074



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


[PATCH] D70696: [DebugInfo] Support to emit debugInfo for extern variables

2019-11-29 Thread Sourabh Singh Tomar via Phabricator via cfe-commits
SouraVX added a comment.

Hi @yonghong-song ,  Thanks for doing this. 
I have a doubt, regarding clang behavior, is this relevant to this.

Consider the following test case --

  extern global_var;
  int main(){}

Now when compiled with clang -g test.c, In file ELF[DWARF] file
their is no, DebugInfo for `global_var`. 
While gcc compiled binary gcc -g test.c. has DebugInfo[DWARF]

  DW_TAG_variable
   DW_AT_name  ("global_var")
   DW_AT_decl_file ("/test.c)
   DW_AT_decl_line (1)
   DW_AT_decl_column   (0x0c)
   DW_AT_type  (0x0039 "int")
   DW_AT_external  (true)
   DW_AT_declaration   (true)

Is this relevant ? Does this patch, adds support for this in clang ? I mean 
`DIGlobalVariable` related stuff in clang generated Debug Metadata ? seems to, 
but still confirming.
Maybe I can use this, to build DWARF related DebugInfo on top of this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70696



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


[PATCH] D70535: [clangd] Define out-of-line qualify return value

2019-11-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:69
+llvm::Optional
+synthesizeContextForNS(llvm::StringRef TargetNS,
+   const DeclContext *CurContext) {

could you add some documentations, e.g. what's the requirement for the input 
`TargetNS`?

I'm not sure `Synthesize` is clear here, maybe `lookupTargetContext` or 
`findTargetContext`?



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:77
+while (!CurContext->isTranslationUnit())
+  CurContext = CurContext->getParent();
+  } else {

nit: maybe use early return?



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:117
+  bool HadErrors = false;
+  tooling::Replacements Replacements;
+  findExplicitReferences(FD, [&](ReferenceLoc Ref) {

could we use a more meaningful name, maybe AddQualifierEdit? Would be nice to 
have some comments explaining what the following code does.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:149
+llvm::inconvertibleErrorCode(),
+"define outline: Failed to compute qualifiers see logs for details.");
+  }

nit: I think this error message is exposed to users, I'm not sure "see logs for 
details" is friendly to them.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:153
+  // Get new begin and end positions for the qualified body.
+  auto OrigFuncRange = toHalfOpenFileRange(
+  SM, FD->getASTContext().getLangOpts(), FD->getSourceRange());

we have similar code in define-inline as well, would be nice to have them in a 
single place in the long term. probably a FIXME?



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:173
 
-  // FIXME: Qualify return type.
   // FIXME: Qualify function name depending on the target context.
 }

btw, do we need to qualify the function parameters. maybe it is not needed, but 
would be nice to have some brief comments explaining it.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:116
 // Creates a modified version of function definition that can be inserted at a
 // different location. Contains both function signature and body.
+llvm::Expected

could you also update the comments here, mentioning the function handles the 
return type qualifiers properly?



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:1778
 
+TEST_F(DefineOutlineTest, QualifyReturnValue) {
+  FileName = "Test.hpp";

can't we merge these into the above `ApplyTest`?



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:1810
+})cpp",
+   "a::Foo::Bar foo() { return {}; }\n"},
+  {R"cpp(

oh, this is very tricky case (I think you meant to test the public members), 
note that Bar and foo are private member of Foo, we can't move the body out of 
the class `Foo`, for this case I think we should disallow the tweak.

No need to do it in this patch, but please update the test here (to test public 
members).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70535



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


[PATCH] D70832: [clangd] Log cc1 args at verbose level.

2019-11-29 Thread Sam McCall via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG407ac2eb5f13: [clangd] Log cc1 args at verbose level. 
(authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70832

Files:
  clang-tools-extra/clangd/Compiler.cpp
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang/include/clang/Frontend/Utils.h
  clang/lib/Frontend/CreateInvocationFromCommandLine.cpp

Index: clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
===
--- clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
+++ clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
@@ -26,7 +26,8 @@
 
 std::unique_ptr clang::createInvocationFromCommandLine(
 ArrayRef ArgList, IntrusiveRefCntPtr Diags,
-IntrusiveRefCntPtr VFS, bool ShouldRecoverOnErorrs) {
+IntrusiveRefCntPtr VFS, bool ShouldRecoverOnErorrs,
+std::vector *CC1Args) {
   if (!Diags.get()) {
 // No diagnostics engine was provided, so create our own diagnostics object
 // with the default options.
@@ -89,6 +90,8 @@
   }
 
   const ArgStringList &CCArgs = Cmd.getArguments();
+  if (CC1Args)
+*CC1Args = {CCArgs.begin(), CCArgs.end()};
   auto CI = std::make_unique();
   if (!CompilerInvocation::CreateFromArgs(*CI, CCArgs, *Diags) &&
   !ShouldRecoverOnErorrs)
Index: clang/include/clang/Frontend/Utils.h
===
--- clang/include/clang/Frontend/Utils.h
+++ clang/include/clang/Frontend/Utils.h
@@ -217,14 +217,18 @@
 /// non-null (and possibly incorrect) CompilerInvocation if any errors were
 /// encountered. When this flag is false, always return null on errors.
 ///
-/// \return A CompilerInvocation, or 0 if none was built for the given
+/// \param CC1Args - if non-null, will be populated with the args to cc1
+/// expanded from \p Args. May be set even if nullptr is returned.
+///
+/// \return A CompilerInvocation, or nullptr if none was built for the given
 /// argument vector.
 std::unique_ptr createInvocationFromCommandLine(
 ArrayRef Args,
 IntrusiveRefCntPtr Diags =
 IntrusiveRefCntPtr(),
 IntrusiveRefCntPtr VFS = nullptr,
-bool ShouldRecoverOnErrors = false);
+bool ShouldRecoverOnErrors = false,
+std::vector *CC1Args = nullptr);
 
 /// Return the value of the last argument as an integer, or a default. If Diags
 /// is non-null, emits an error if the argument is given, but non-integral.
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -407,8 +407,12 @@
 llvm::join(Inputs.CompileCommand.CommandLine, " "));
 // Rebuild the preamble and the AST.
 StoreDiags CompilerInvocationDiagConsumer;
+std::vector CC1Args;
 std::unique_ptr Invocation =
 buildCompilerInvocation(Inputs, CompilerInvocationDiagConsumer);
+// Log cc1 args even (especially!) if creating invocation failed.
+if (!CC1Args.empty())
+  vlog("cc1 args: {0}", llvm::join(CC1Args, " "));
 std::vector CompilerInvocationDiags =
 CompilerInvocationDiagConsumer.take();
 if (!Invocation) {
Index: clang-tools-extra/clangd/Compiler.h
===
--- clang-tools-extra/clangd/Compiler.h
+++ clang-tools-extra/clangd/Compiler.h
@@ -52,8 +52,8 @@
 
 /// Builds compiler invocation that could be used to build AST or preamble.
 std::unique_ptr
-buildCompilerInvocation(const ParseInputs &Inputs,
-clang::DiagnosticConsumer &D);
+buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
+std::vector *CC1Args = nullptr);
 
 /// Creates a compiler instance, configured so that:
 ///   - Contents of the parsed file are remapped to \p MainFile.
Index: clang-tools-extra/clangd/Compiler.cpp
===
--- clang-tools-extra/clangd/Compiler.cpp
+++ clang-tools-extra/clangd/Compiler.cpp
@@ -42,7 +42,8 @@
 
 std::unique_ptr
 buildCompilerInvocation(const ParseInputs &Inputs,
-clang::DiagnosticConsumer &D) {
+clang::DiagnosticConsumer &D,
+std::vector *CC1Args) {
   std::vector ArgStrs;
   for (const auto &S : Inputs.CompileCommand.CommandLine)
 ArgStrs.push_back(S.c_str());
@@ -57,7 +58,7 @@
   CompilerInstance::createDiagnostics(new DiagnosticOptions, &D, false);
   std::unique_ptr CI = createInvocationFromCommandLine(
   ArgStrs, CommandLineDiagsEngine, Inputs.FS,
-  /*ShouldRecoverOnErrors=*/true);
+  /*ShouldRecoverOnErrors=*/true, C

[PATCH] D32905: [Analyzer] Iterator Checker - Part 9: Evaluation of std::find-like calls

2019-11-29 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware abandoned this revision.
baloghadamsoftware added a comment.
Herald added subscribers: Charusso, gamesh411.

The STL `find()` family is modeled in a separate checker: [[ 
https://reviews.llvm.org/D70818 | [Analyzer] Model STL Algoirthms to improve 
the iterator checkers ]]


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

https://reviews.llvm.org/D32905



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


[PATCH] D70818: [Analyzer] Model STL Algoirthms to improve the iterator checkers

2019-11-29 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

This patch supersedes both https://reviews.llvm.org/D32905 and 
https://reviews.llvm.org/D54149.


Repository:
  rC Clang

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

https://reviews.llvm.org/D70818



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


[clang-tools-extra] 407ac2e - [clangd] Log cc1 args at verbose level.

2019-11-29 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2019-11-29T11:00:01+01:00
New Revision: 407ac2eb5f136af5ddd213b8bcca176481ec5198

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

LOG: [clangd] Log cc1 args at verbose level.

Summary: This will help debugging driver issues.

Reviewers: kbobyrev

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, 
usaxena95, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/Compiler.cpp
clang-tools-extra/clangd/Compiler.h
clang-tools-extra/clangd/TUScheduler.cpp
clang/include/clang/Frontend/Utils.h
clang/lib/Frontend/CreateInvocationFromCommandLine.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Compiler.cpp 
b/clang-tools-extra/clangd/Compiler.cpp
index 795fd0082594..eae753b5c9b3 100644
--- a/clang-tools-extra/clangd/Compiler.cpp
+++ b/clang-tools-extra/clangd/Compiler.cpp
@@ -42,7 +42,8 @@ void 
IgnoreDiagnostics::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
 
 std::unique_ptr
 buildCompilerInvocation(const ParseInputs &Inputs,
-clang::DiagnosticConsumer &D) {
+clang::DiagnosticConsumer &D,
+std::vector *CC1Args) {
   std::vector ArgStrs;
   for (const auto &S : Inputs.CompileCommand.CommandLine)
 ArgStrs.push_back(S.c_str());
@@ -57,7 +58,7 @@ buildCompilerInvocation(const ParseInputs &Inputs,
   CompilerInstance::createDiagnostics(new DiagnosticOptions, &D, false);
   std::unique_ptr CI = createInvocationFromCommandLine(
   ArgStrs, CommandLineDiagsEngine, Inputs.FS,
-  /*ShouldRecoverOnErrors=*/true);
+  /*ShouldRecoverOnErrors=*/true, CC1Args);
   if (!CI)
 return nullptr;
   // createInvocationFromCommandLine sets DisableFree.

diff  --git a/clang-tools-extra/clangd/Compiler.h 
b/clang-tools-extra/clangd/Compiler.h
index 6ab1b0f075f9..51414c37fc04 100644
--- a/clang-tools-extra/clangd/Compiler.h
+++ b/clang-tools-extra/clangd/Compiler.h
@@ -52,8 +52,8 @@ struct ParseInputs {
 
 /// Builds compiler invocation that could be used to build AST or preamble.
 std::unique_ptr
-buildCompilerInvocation(const ParseInputs &Inputs,
-clang::DiagnosticConsumer &D);
+buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer 
&D,
+std::vector *CC1Args = nullptr);
 
 /// Creates a compiler instance, configured so that:
 ///   - Contents of the parsed file are remapped to \p MainFile.

diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index d740c3873695..b51221d7d903 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -407,8 +407,12 @@ void ASTWorker::update(ParseInputs Inputs, WantDiagnostics 
WantDiags) {
 llvm::join(Inputs.CompileCommand.CommandLine, " "));
 // Rebuild the preamble and the AST.
 StoreDiags CompilerInvocationDiagConsumer;
+std::vector CC1Args;
 std::unique_ptr Invocation =
 buildCompilerInvocation(Inputs, CompilerInvocationDiagConsumer);
+// Log cc1 args even (especially!) if creating invocation failed.
+if (!CC1Args.empty())
+  vlog("cc1 args: {0}", llvm::join(CC1Args, " "));
 std::vector CompilerInvocationDiags =
 CompilerInvocationDiagConsumer.take();
 if (!Invocation) {

diff  --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 0f9b17ee5089..2b142122cb66 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -217,14 +217,18 @@ createChainedIncludesSource(CompilerInstance &CI,
 /// non-null (and possibly incorrect) CompilerInvocation if any errors were
 /// encountered. When this flag is false, always return null on errors.
 ///
-/// \return A CompilerInvocation, or 0 if none was built for the given
+/// \param CC1Args - if non-null, will be populated with the args to cc1
+/// expanded from \p Args. May be set even if nullptr is returned.
+///
+/// \return A CompilerInvocation, or nullptr if none was built for the given
 /// argument vector.
 std::unique_ptr createInvocationFromCommandLine(
 ArrayRef Args,
 IntrusiveRefCntPtr Diags =
 IntrusiveRefCntPtr(),
 IntrusiveRefCntPtr VFS = nullptr,
-bool ShouldRecoverOnErrors = false);
+bool ShouldRecoverOnErrors = false,
+std::vector *CC1Args = nullptr);
 
 /// Return the value of the last argument as an integer, or a default. If Diags
 /// is non-null, emits an error if the argument is given, but non-integral.

diff  --git a/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp 
b/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
index ab62b6

[PATCH] D70769: [Support] add vfs support for ExpandResponseFiles

2019-11-29 Thread liu hui via Phabricator via cfe-commits
lh123 marked 3 inline comments as done.
lh123 added inline comments.



Comment at: llvm/lib/Support/CommandLine.cpp:1069
+  return llvm::createStringError(
+  std::make_error_code(std::errc::illegal_byte_sequence),
+  "Could not convert UTF16 To UTF8");

jhenderson wrote:
> lh123 wrote:
> > jhenderson wrote:
> > > jhenderson wrote:
> > > > `std::make_error_code(std::errc::illegal_byte_sequence)` -> 
> > > > `errc::illegal_byte_sequence`
> > > LLVM has its own errc error_code set. Please use that, i.e. delete the 
> > > `std::` (note that I didn't add `std::` in my previous comment).
> > I think we should use `std::errc::illegal_byte_sequence`, because it's 
> > sigature is:
> >  ```
> > template 
> > inline Error createStringError(std::errc EC, char const *Fmt, const Ts &... 
> > Vals)
> > ```
> I'm not sure if that's a mistake in the function interface or not, and it 
> looks like our usage is very inconsistent, but the comments in Errc.h imply 
> that we really should use llvm::errc values and not std::errc, or there may 
> be problems.
I think `llvm::errc` and `std::errc` are both correct, `llvm::errc` eventually 
implicitly converts to `std::error_code`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70769



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


[PATCH] D70222: [clang][Tooling] Add support for .rsp files in compile_commands.json

2019-11-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

Thanks a lot for working on this patch, LGTM!

again please make sure the changes are clang-formatted.

Do you have commit access?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70222



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


[PATCH] D70828: [clangd] Correct the file path in Edit::replacements when generating the rename edit.

2019-11-29 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG66ab932fcc10: [clangd] Correct the file path in 
Edit::replacements when generating the rename… (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70828

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/refactor/Rename.h
  clang-tools-extra/clangd/unittests/RenameTests.cpp


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -669,14 +669,16 @@
 TEST(CrossFileRenameTests, BuildRenameEdits) {
   Annotations Code("[[😂]]");
   auto LSPRange = Code.range();
-  auto Edit = buildRenameEdit(Code.code(), {LSPRange}, "abc");
+  llvm::StringRef FilePath = "/test/TestTU.cpp";
+  auto Edit = buildRenameEdit(FilePath, Code.code(), {LSPRange}, "abc");
   ASSERT_TRUE(bool(Edit)) << Edit.takeError();
   ASSERT_EQ(1UL, Edit->Replacements.size());
+  EXPECT_EQ(FilePath, Edit->Replacements.begin()->getFilePath());
   EXPECT_EQ(4UL, Edit->Replacements.begin()->getLength());
 
   // Test invalid range.
   LSPRange.end = {10, 0}; // out of range
-  Edit = buildRenameEdit(Code.code(), {LSPRange}, "abc");
+  Edit = buildRenameEdit(FilePath, Code.code(), {LSPRange}, "abc");
   EXPECT_FALSE(Edit);
   EXPECT_THAT(llvm::toString(Edit.takeError()),
   testing::HasSubstr("fail to convert"));
@@ -687,7 +689,7 @@
   [[range]]
   [[range]]
   )cpp");
-  Edit = buildRenameEdit(T.code(), T.ranges(), "abc");
+  Edit = buildRenameEdit(FilePath, T.code(), T.ranges(), "abc");
   ASSERT_TRUE(bool(Edit)) << Edit.takeError();
   EXPECT_EQ(applyEdits(FileEdits{{T.code(), std::move(*Edit)}}).front().second,
 expectedResult(Code, expectedResult(T, "abc")));
Index: clang-tools-extra/clangd/refactor/Rename.h
===
--- clang-tools-extra/clangd/refactor/Rename.h
+++ clang-tools-extra/clangd/refactor/Rename.h
@@ -50,7 +50,8 @@
 /// Generates rename edits that replaces all given occurrences with the
 /// NewName.
 /// Exposed for testing only.
-llvm::Expected buildRenameEdit(llvm::StringRef InitialCode,
+llvm::Expected buildRenameEdit(llvm::StringRef AbsFilePath,
+ llvm::StringRef InitialCode,
  std::vector Occurrences,
  llvm::StringRef NewName);
 
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -349,8 +349,9 @@
   elog("Fail to read file content: {0}", AffectedFileCode.takeError());
   continue;
 }
-auto RenameEdit = buildRenameEdit(
-*AffectedFileCode, std::move(FileAndOccurrences.second), NewName);
+auto RenameEdit =
+buildRenameEdit(FilePath, *AffectedFileCode,
+std::move(FileAndOccurrences.second), NewName);
 if (!RenameEdit) {
   return llvm::make_error(
   llvm::formatv("fail to build rename edit for file {0}: {1}", 
FilePath,
@@ -451,7 +452,8 @@
   return Results;
 }
 
-llvm::Expected buildRenameEdit(llvm::StringRef InitialCode,
+llvm::Expected buildRenameEdit(llvm::StringRef AbsFilePath,
+ llvm::StringRef InitialCode,
  std::vector Occurrences,
  llvm::StringRef NewName) {
   llvm::sort(Occurrences);
@@ -491,7 +493,7 @@
   for (const auto &R : OccurrencesOffsets) {
 auto ByteLength = R.second - R.first;
 if (auto Err = RenameEdit.add(
-tooling::Replacement(InitialCode, R.first, ByteLength, NewName)))
+tooling::Replacement(AbsFilePath, R.first, ByteLength, NewName)))
   return std::move(Err);
   }
   return Edit(InitialCode, std::move(RenameEdit));


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -669,14 +669,16 @@
 TEST(CrossFileRenameTests, BuildRenameEdits) {
   Annotations Code("[[😂]]");
   auto LSPRange = Code.range();
-  auto Edit = buildRenameEdit(Code.code(), {LSPRange}, "abc");
+  llvm::StringRef FilePath = "/test/TestTU.cpp";
+  auto Edit = buildRenameEdit(FilePath, Code.code(), {LSPRange}, "abc");
   ASSERT_TRUE(bool(Edit)) << Edit.takeError();
   ASSERT_EQ(1UL, Edit->Replacements.size());
+  EXPECT_EQ(FilePath, Edit->Replacements.begin()->getFilePath());
   EXPECT_EQ(4UL, Edit->Replacements.begin()->getLength());
 
   // Test invalid range.
   LSPRa

[PATCH] D70832: [clangd] Log cc1 args at verbose level.

2019-11-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 231487.
sammccall added a comment.

Fix Compiler.h changes that got mangled.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70832

Files:
  clang-tools-extra/clangd/Compiler.cpp
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang/include/clang/Frontend/Utils.h
  clang/lib/Frontend/CreateInvocationFromCommandLine.cpp

Index: clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
===
--- clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
+++ clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
@@ -26,7 +26,8 @@
 
 std::unique_ptr clang::createInvocationFromCommandLine(
 ArrayRef ArgList, IntrusiveRefCntPtr Diags,
-IntrusiveRefCntPtr VFS, bool ShouldRecoverOnErorrs) {
+IntrusiveRefCntPtr VFS, bool ShouldRecoverOnErorrs,
+std::vector *CC1Args) {
   if (!Diags.get()) {
 // No diagnostics engine was provided, so create our own diagnostics object
 // with the default options.
@@ -89,6 +90,8 @@
   }
 
   const ArgStringList &CCArgs = Cmd.getArguments();
+  if (CC1Args)
+*CC1Args = {CCArgs.begin(), CCArgs.end()};
   auto CI = std::make_unique();
   if (!CompilerInvocation::CreateFromArgs(*CI, CCArgs, *Diags) &&
   !ShouldRecoverOnErorrs)
Index: clang/include/clang/Frontend/Utils.h
===
--- clang/include/clang/Frontend/Utils.h
+++ clang/include/clang/Frontend/Utils.h
@@ -217,14 +217,18 @@
 /// non-null (and possibly incorrect) CompilerInvocation if any errors were
 /// encountered. When this flag is false, always return null on errors.
 ///
-/// \return A CompilerInvocation, or 0 if none was built for the given
+/// \param CC1Args - if non-null, will be populated with the args to cc1
+/// expanded from \p Args. May be set even if nullptr is returned.
+///
+/// \return A CompilerInvocation, or nullptr if none was built for the given
 /// argument vector.
 std::unique_ptr createInvocationFromCommandLine(
 ArrayRef Args,
 IntrusiveRefCntPtr Diags =
 IntrusiveRefCntPtr(),
 IntrusiveRefCntPtr VFS = nullptr,
-bool ShouldRecoverOnErrors = false);
+bool ShouldRecoverOnErrors = false,
+std::vector *CC1Args = nullptr);
 
 /// Return the value of the last argument as an integer, or a default. If Diags
 /// is non-null, emits an error if the argument is given, but non-integral.
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -407,8 +407,12 @@
 llvm::join(Inputs.CompileCommand.CommandLine, " "));
 // Rebuild the preamble and the AST.
 StoreDiags CompilerInvocationDiagConsumer;
+std::vector CC1Args;
 std::unique_ptr Invocation =
 buildCompilerInvocation(Inputs, CompilerInvocationDiagConsumer);
+// Log cc1 args even (especially!) if creating invocation failed.
+if (!CC1Args.empty())
+  vlog("cc1 args: {0}", llvm::join(CC1Args, " "));
 std::vector CompilerInvocationDiags =
 CompilerInvocationDiagConsumer.take();
 if (!Invocation) {
Index: clang-tools-extra/clangd/Compiler.h
===
--- clang-tools-extra/clangd/Compiler.h
+++ clang-tools-extra/clangd/Compiler.h
@@ -52,8 +52,8 @@
 
 /// Builds compiler invocation that could be used to build AST or preamble.
 std::unique_ptr
-buildCompilerInvocation(const ParseInputs &Inputs,
-clang::DiagnosticConsumer &D);
+buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
+std::vector *CC1Args = nullptr);
 
 /// Creates a compiler instance, configured so that:
 ///   - Contents of the parsed file are remapped to \p MainFile.
Index: clang-tools-extra/clangd/Compiler.cpp
===
--- clang-tools-extra/clangd/Compiler.cpp
+++ clang-tools-extra/clangd/Compiler.cpp
@@ -42,7 +42,8 @@
 
 std::unique_ptr
 buildCompilerInvocation(const ParseInputs &Inputs,
-clang::DiagnosticConsumer &D) {
+clang::DiagnosticConsumer &D,
+std::vector *CC1Args) {
   std::vector ArgStrs;
   for (const auto &S : Inputs.CompileCommand.CommandLine)
 ArgStrs.push_back(S.c_str());
@@ -57,7 +58,7 @@
   CompilerInstance::createDiagnostics(new DiagnosticOptions, &D, false);
   std::unique_ptr CI = createInvocationFromCommandLine(
   ArgStrs, CommandLineDiagsEngine, Inputs.FS,
-  /*ShouldRecoverOnErrors=*/true);
+  /*ShouldRecoverOnErrors=*/true, CC1Args);
   if (!CI)
 return nullptr;
   // createInvocationFromCommandLine sets DisableFree.

[clang] 302cb3b - [Syntax] Add a comment explaining the pointer keys in std::map. NFC

2019-11-29 Thread Ilya Biryukov via cfe-commits

Author: Ilya Biryukov
Date: 2019-11-29T09:49:24+01:00
New Revision: 302cb3bc3d7220e09f5dced64ddfdda33b9c49f9

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

LOG: [Syntax] Add a comment explaining the pointer keys in std::map. NFC

Added: 


Modified: 
clang/lib/Tooling/Syntax/BuildTree.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index b36b8e00f7c1..22cdb89b7bfb 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -209,6 +209,8 @@ class syntax::TreeBuilder {
 };
 
 /// Maps from the start token to a subtree starting at that token.
+/// Keys in the map are pointers into the array of expanded tokens, so
+/// pointer order corresponds to the order of preprocessor tokens.
 /// FIXME: storing the end tokens is redundant.
 /// FIXME: the key of a map is redundant, it is also stored in 
NodeForRange.
 std::map Trees;



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


[clang] def65bb - [Syntax] Remove unused parameter from `TreeBuilder::markChildToken`. NFC

2019-11-29 Thread Ilya Biryukov via cfe-commits

Author: Ilya Biryukov
Date: 2019-11-29T09:45:06+01:00
New Revision: def65bb4f5bc87588fa6f849225397c21dcefb2b

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

LOG: [Syntax] Remove unused parameter from `TreeBuilder::markChildToken`. NFC

Added: 


Modified: 
clang/lib/Tooling/Syntax/BuildTree.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index dddc265c8c41..b36b8e00f7c1 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -66,7 +66,7 @@ class syntax::TreeBuilder {
   void markExprChild(Expr *Child, NodeRole Role);
 
   /// Set role for a token starting at \p Loc.
-  void markChildToken(SourceLocation Loc, tok::TokenKind Kind, NodeRole R);
+  void markChildToken(SourceLocation Loc, NodeRole R);
 
   /// Finish building the tree and consume the root node.
   syntax::TranslationUnit *finalize() && {
@@ -255,11 +255,10 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   bool WalkUpFromCompoundStmt(CompoundStmt *S) {
 using NodeRole = syntax::NodeRole;
 
-Builder.markChildToken(S->getLBracLoc(), tok::l_brace, 
NodeRole::OpenParen);
+Builder.markChildToken(S->getLBracLoc(), NodeRole::OpenParen);
 for (auto *Child : S->body())
   Builder.markStmtChild(Child, NodeRole::CompoundStatement_statement);
-Builder.markChildToken(S->getRBracLoc(), tok::r_brace,
-   NodeRole::CloseParen);
+Builder.markChildToken(S->getRBracLoc(), NodeRole::CloseParen);
 
 Builder.foldNode(Builder.getStmtRange(S),
  new (allocator()) syntax::CompoundStatement);
@@ -323,7 +322,7 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   }
 
   bool WalkUpFromSwitchStmt(SwitchStmt *S) {
-Builder.markChildToken(S->getSwitchLoc(), tok::kw_switch,
+Builder.markChildToken(S->getSwitchLoc(),
syntax::NodeRole::IntroducerKeyword);
 Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
 Builder.foldNode(Builder.getStmtRange(S),
@@ -332,7 +331,7 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   }
 
   bool WalkUpFromCaseStmt(CaseStmt *S) {
-Builder.markChildToken(S->getKeywordLoc(), tok::kw_case,
+Builder.markChildToken(S->getKeywordLoc(),
syntax::NodeRole::IntroducerKeyword);
 Builder.markExprChild(S->getLHS(), syntax::NodeRole::CaseStatement_value);
 Builder.markStmtChild(S->getSubStmt(), syntax::NodeRole::BodyStatement);
@@ -342,7 +341,7 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   }
 
   bool WalkUpFromDefaultStmt(DefaultStmt *S) {
-Builder.markChildToken(S->getKeywordLoc(), tok::kw_default,
+Builder.markChildToken(S->getKeywordLoc(),
syntax::NodeRole::IntroducerKeyword);
 Builder.markStmtChild(S->getSubStmt(), syntax::NodeRole::BodyStatement);
 Builder.foldNode(Builder.getStmtRange(S),
@@ -351,11 +350,10 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   }
 
   bool WalkUpFromIfStmt(IfStmt *S) {
-Builder.markChildToken(S->getIfLoc(), tok::kw_if,
-   syntax::NodeRole::IntroducerKeyword);
+Builder.markChildToken(S->getIfLoc(), syntax::NodeRole::IntroducerKeyword);
 Builder.markStmtChild(S->getThen(),
   syntax::NodeRole::IfStatement_thenStatement);
-Builder.markChildToken(S->getElseLoc(), tok::kw_else,
+Builder.markChildToken(S->getElseLoc(),
syntax::NodeRole::IfStatement_elseKeyword);
 Builder.markStmtChild(S->getElse(),
   syntax::NodeRole::IfStatement_elseStatement);
@@ -365,8 +363,7 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   }
 
   bool WalkUpFromForStmt(ForStmt *S) {
-Builder.markChildToken(S->getForLoc(), tok::kw_for,
-   syntax::NodeRole::IntroducerKeyword);
+Builder.markChildToken(S->getForLoc(), 
syntax::NodeRole::IntroducerKeyword);
 Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
 Builder.foldNode(Builder.getStmtRange(S),
  new (allocator()) syntax::ForStatement);
@@ -374,7 +371,7 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   }
 
   bool WalkUpFromWhileStmt(WhileStmt *S) {
-Builder.markChildToken(S->getWhileLoc(), tok::kw_while,
+Builder.markChildToken(S->getWhileLoc(),
syntax::NodeRole::IntroducerKeyword);
 Builder.markStmtChild(S->getBody(), syntax::NodeRole::BodyStatement);
 Builder.foldNode(Builder.getStmtRange(S),
@@ -383,7 +380,7 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   }
 
   bool WalkUpFromContinueStmt(ContinueStmt *S) {
-  

[PATCH] D70804: [Frontend] Allow OpenMP offloading to aarch64

2019-11-29 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In D70804#1763443 , @bryanpkc wrote:

> In D70804#1763289 , @ABataev wrote:
>
> > Tests are required
>
>
> The tests for this were added in D30644 , 
> but they are currently failing on AArch64 due to D32035 
> . This patch allows those tests to pass 
> again. What further testing should I add?


There should be tests in Clang that the target is indeed supported. Tests in 
libomptarget are fine, but apparently they are not tested on a regular basis 
when failing for more than two years.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70804



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