[PATCH] D75364: [clang-format] Handle macros in function params and return value

2020-03-02 Thread Tamas Petz via Phabricator via cfe-commits
tamas.petz updated this revision to Diff 247561.

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

https://reviews.llvm.org/D75364

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7356,6 +7356,10 @@
   verifyFormat("void f(const MyFinal &final);");
   verifyIndependentOfContext("bool a = f() && override.f();");
   verifyIndependentOfContext("bool a = f() && final.f();");
+  verifyFormat("int f(M(x) *p1 = nullptr, M(x) *p2, volatile M(x) *p3);");
+  verifyFormat("M(x) *foo();");
+  verifyFormat("const M(x) *foo(M(x) *a = nullptr);");
+  verifyFormat("const M(x) *foo::bar(M(x) *a = nullptr);");
 
   verifyIndependentOfContext("InvalidRegions[*R] = 0;");
 
@@ -7396,6 +7400,10 @@
   verifyGoogleFormat("void f(Bar* a = nullptr, Bar* b);");
   verifyGoogleFormat("template \n"
  "void f(int i = 0, SomeType** temps = NULL);");
+  verifyGoogleFormat("int f(M(x)* p1 = nullptr, const M(x)* p2);");
+  verifyGoogleFormat("M(x)* foo();");
+  verifyGoogleFormat("const M(x)* foo(M(x)* a = nullptr);");
+  verifyGoogleFormat("const M(x)* foo::bar(M(x)* a = nullptr);");
 
   FormatStyle Left = getLLVMStyle();
   Left.PointerAlignment = FormatStyle::PAS_Left;
@@ -7410,6 +7418,11 @@
   verifyFormat("auto x(A&&, B&&, C&&) -> D;", Left);
   verifyFormat("auto x = [](A&&, B&&, C&&) -> D {};", Left);
   verifyFormat("template  X(T&&, T&&, T&&) -> X;", Left);
+  verifyFormat("int f(M(x)* p1 = nullptr, const M(x)* p2, volatile M(x)* p3);",
+   Left);
+  verifyFormat("M(x)* foo();", Left);
+  verifyFormat("const M(x)* foo(M(x)* a = nullptr);", Left);
+  verifyFormat("const M(x)* foo::bar(M(x)* a = nullptr);", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
@@ -7537,6 +7550,11 @@
   verifyFormat("A = new SomeType *[Length]();", PointerMiddle);
   verifyFormat("A = new SomeType *[Length];", PointerMiddle);
   verifyFormat("T ** t = new T *;", PointerMiddle);
+  verifyFormat("int f(M(x) * p1 = nullptr, const M(x) * p2 = nullptr);",
+   PointerMiddle);
+  verifyFormat("M(x) * foo();", PointerMiddle);
+  verifyFormat("const M(x) * foo(M(x) * a = nullptr);", PointerMiddle);
+  verifyFormat("const M(x) * foo::bar(M(x) * a = nullptr);", PointerMiddle);
 
   // Member function reference qualifiers aren't binary operators.
   verifyFormat("string // break\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -160,6 +160,14 @@
 return false;
   }
 
+  /// Parses CPP qualified function names.
+  bool parse_function_qname(FormatToken *Tok) const {
+while (Tok && Tok->isOneOf(tok::coloncolon, tok::identifier)) {
+  Tok = Tok->Next;
+}
+return Tok && Tok->is(tok::l_paren);
+  }
+
   bool parseParens(bool LookForDecls = false) {
 if (!CurrentToken)
   return false;
@@ -250,6 +258,7 @@
 bool HasMultipleParametersOnALine = false;
 bool MightBeObjCForRangeLoop =
 Left->Previous && Left->Previous->is(tok::kw_for);
+bool HasStarToken = false;
 FormatToken *PossibleObjCForInToken = nullptr;
 while (CurrentToken) {
   // LookForDecls is set when "if (" has been seen. Check for
@@ -299,6 +308,55 @@
   }
 }
 
+// Detect cases where macros are used in function parameter lists,
+// for example:
+//   void f(volatile ElfW(Addr)* addr = nullptr);
+if (HasStarToken) {
+  for (FormatToken *Tok = Left; Tok != CurrentToken; Tok = Tok->Next) {
+// Search for ') *' patterns.
+if (Tok->is(tok::star) && Tok->Previous->is(tok::r_paren)) {
+  // Extend search to left looking for 'X(...) *' patterns.
+  FormatToken *LparenTok = Tok->Previous->MatchingParen;
+  if (LparenTok && LparenTok->is(tok::l_paren) &&
+  LparenTok->Previous) {
+FormatToken *MacroTok = LparenTok->Previous;
+// Decide if 'X' is following "l_paren" of this function,
+// a keyword or a comma.
+if (MacroTok->is(tok::identifier) && MacroTok->Previous &&
+(MacroTok->Previous == Left ||
+ MacroTok->Previous->isOneOf(tok::comma, tok::kw_const,
+ tok::kw_volatile))) {
+  Tok->Type = TT_PointerOrReference;
+  LparenTok->Previous->Type = TT_TypenameMacro;
+}
+  }
+}
+  }
+}
+
+// Detect cases where macros are used in function return types,
+// for example:
+//   const ElfW(A

[PATCH] D71227: [cuda][hip] Fix function overload resolution in the global initiailizer.

2020-03-02 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:11444
+  return nullptr;
+const Decl *ContextDecl = dyn_cast(CurContext);
+if (!ContextDecl)

rjmccall wrote:
> You really want this to match whenever we're in a local context, right?  How 
> about structuring the function like:
> 
> ```
> if (CurContext->isFunctionOrMethod())
>   return cast(CurContext);
> if (!CurContext->isFileContext())
>   return nullptr;
> return getCUDACurrentNonLocalVariable();
> ```
> 
> As a more general solution, I think Sema funnels all changes to CurContext 
> through a small number of places, and you could make those places save and 
> restore the currently initialized variable as well.
Richard, I'd like your opinion about this.  We have three separate patches 
right now that would all benefit from being able to track that they're 
currently within a variable/field initializer in Sema.  And it's a general 
deficiency that it's hard to track declarations in initializers back to their 
initialized variable.

Swift actually bit the bullet and introduced a kind of `DeclContext` that's a 
non-local initializer, and that links back to the variable.  That would be hard 
to bring back to Clang with the current AST because Clang assumes that all 
`DeclContext`s are `Decl`s, and I don't think we can reasonably remove that 
assumption; and of course `VarDecl` and `FieldDecl` aren't `DeclContext`s.

Now, we could try to change that latter point.  Making *all* `VarDecl`s and 
`FieldDecl`s DCs would have prohibitive memory overhead, since the vast 
majority are local / uninitialized; however, we could introduce a `VarDecl` 
subclass for global variables (including static member variables, of course), 
and similarly we could have a `FieldDecl` subclass for fields with 
initializers, which would nicely move some of the other overhead out-of-line 
and optimize for the C-style/old-style case.  (We always know whether a field 
has an in-class initializer at parse time, right?)

Less invasively, we could forget about trying to track this in the AST and just 
also track a current initialized variable in Sema.  Anything which tried to 
change the context would have to save and restore that as well.  That might be 
annoying because of PushDeclContext/PopDeclContext, though, which assume that 
you can restore the old context by just looking at the current context.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16702
+  if (!D || D->isInvalidDecl() || !isNonlocalVariable(D))
+return;
+  assert(!CUDANonLocalVariableStack.empty() &&

The declaration could become invalid while processing its initializer; I think 
you should drop that condition.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71227



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


[clang] 802b22b - Revert "[DebugInfo][clang][DWARF5]: Added support for debuginfo generation for defaulted parameters"

2020-03-02 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2020-03-02T09:30:52+01:00
New Revision: 802b22b5c8c30bebc1695a217478be02653c6b53

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

LOG: Revert "[DebugInfo][clang][DWARF5]: Added support for debuginfo generation 
for defaulted parameters"

The Bitcode/DITemplateParameter-5.0.ll test is failing:

FAIL: LLVM :: Bitcode/DITemplateParameter-5.0.ll (5894 of 36324)
 TEST 'LLVM :: Bitcode/DITemplateParameter-5.0.ll' FAILED 

Script:
--
: 'RUN: at line 1';   
/usr/local/google/home/thakis/src/llvm-project/out/gn/bin/llvm-dis -o - 
/usr/local/google/home/thakis/src/llvm-project/llvm/test/Bitcode/DITemplateParameter-5.0.ll.bc
 | /usr/local/google/home/thakis/src/llvm-project/out/gn/bin/FileCheck 
/usr/local/google/home/thakis/src/llvm-project/llvm/test/Bitcode/DITemplateParameter-5.0.ll
--
Exit Code: 2

Command Output (stderr):
--

It looks like the Bitcode/DITemplateParameter-5.0.ll.bc file was never checked 
in.

This reverts commit c2b437d53d40b6dc5603c97f527398f477d9c5f1.

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/DebugInfoMetadata.cpp
llvm/lib/IR/LLVMContextImpl.h
llvm/unittests/IR/MetadataTest.cpp

Removed: 
llvm/test/Assembler/DITemplateParameter.ll
llvm/test/Bitcode/DITemplateParameter-5.0.ll



diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 404ecfa975a1..e171082942f6 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1787,36 +1787,18 @@ CGDebugInfo::CollectTemplateParams(const 
TemplateParameterList *TPList,
   for (unsigned i = 0, e = TAList.size(); i != e; ++i) {
 const TemplateArgument &TA = TAList[i];
 StringRef Name;
-bool defaultParameter = false;
 if (TPList)
   Name = TPList->getParam(i)->getName();
 switch (TA.getKind()) {
 case TemplateArgument::Type: {
   llvm::DIType *TTy = getOrCreateType(TA.getAsType(), Unit);
-
-  if (TPList)
-if (auto *templateType =
-dyn_cast_or_null(TPList->getParam(i)))
-  if (templateType->hasDefaultArgument())
-defaultParameter =
-templateType->getDefaultArgument() == TA.getAsType();
-
-  TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
-  TheCU, Name, TTy, defaultParameter));
-
+  TemplateParams.push_back(
+  DBuilder.createTemplateTypeParameter(TheCU, Name, TTy));
 } break;
 case TemplateArgument::Integral: {
   llvm::DIType *TTy = getOrCreateType(TA.getIntegralType(), Unit);
-  if (TPList)
-if (auto *templateType =
-dyn_cast_or_null(TPList->getParam(i)))
-  if (templateType->hasDefaultArgument())
-defaultParameter =
-templateType->getDefaultArgument()->EvaluateKnownConstInt(
-CGM.getContext()) == TA.getAsIntegral();
-
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
-  TheCU, Name, TTy, defaultParameter,
+  TheCU, Name, TTy,
   llvm::ConstantInt::get(CGM.getLLVMContext(), TA.getAsIntegral(;
 } break;
 case TemplateArgument::Declaration: {
@@ -1855,7 +1837,7 @@ CGDebugInfo::CollectTemplateParams(const 
TemplateParameterList *TPList,
 V = V->stripPointerCasts();
   }
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
-  TheCU, Name, TTy, defaultParameter, 
cast_or_null(V)));
+  TheCU, Name, TTy, cast_or_null(V)));
 } break;
 case TemplateArgument::NullPtr: {
   QualType T = TA.getNullPtrType();
@@ -1873,8 +1855,8 @@ CGDebugInfo::CollectTemplateParams(const 
TemplateParameterList *TPList,
   V = CGM.getCXXABI().EmitNullMemberPointer(MPT);
   if (!V)
 V = llvm::ConstantInt::get(CGM.Int8Ty, 0);
-  TemplateParams.push_back(DBuilder.createTemplateValueParameter(
-  TheCU, Name, TTy, defaultParameter, V));
+  TemplateParams.push_back(
+  DBuilder.createTemplateValueParameter(TheCU, Name, TTy, V));
 } break;
 case TemplateArgument::Template:
   TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
@@ -1895,7 +1877,7 @@ CGDebugInfo::CollectTemplateParams(const 
TemplateParameterList *TPList,
   assert(V && "Expression in template argument isn't constant");
   llvm::DIType *TTy = getOrCreateType(T, Unit);
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
-  

[PATCH] D73462: [dwarf-5] Support DebugInfo for Defaulted parameters for C++ templates

2020-03-02 Thread Muhammad Omair Javaid via Phabricator via cfe-commits
omjavaid reopened this revision.
omjavaid added a comment.
This revision is now accepted and ready to land.

This change breaks lldb buildbots here:

http://lab.llvm.org:8011/builders/lldb-aarch64-ubuntu/builds/2123
http://lab.llvm.org:8011/builders/lldb-x86_64-debian/builds/5911

Please revisit this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73462



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


[PATCH] D73649: [CodeComplete] Member completion for concept-constrained types.

2020-03-02 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4860
+  return;
+if (auto *CSE = llvm::dyn_cast(E)) {
+  // If the concept is

nridge wrote:
> clang-tidy gives me an `'auto *CSE' can be declared as 'const auto *CSE'` 
> here, and several similar diagnostics below.
> 
> Not sure if that's something we want to obey, or alter our configuration to 
> silence it.
That warning will go away next time the bot updates the version of clang tidy 
it uses. It was decided to reduce the constraints on diagnosing that check 
inside llvm but that hasn't reached the pre merge bot. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73649



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


[PATCH] D73462: [dwarf-5] Support DebugInfo for Defaulted parameters for C++ templates

2020-03-02 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D73462#1900364 , @omjavaid wrote:

> This change breaks lldb buildbots here:
>
> http://lab.llvm.org:8011/builders/lldb-aarch64-ubuntu/builds/2123
>  http://lab.llvm.org:8011/builders/lldb-x86_64-debian/builds/5911
>
> Please revisit this.


In addition to that, looks like the Bitcode/DITemplateParameter-5.0.ll.bc file 
was never checked in which is causing all bots to fail, e.g. 
http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/24492

I've reverted in 802b22b5c8c30bebc1695a217478be02653c6b53 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73462



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


[PATCH] D75373: [Clang] Fix Hurd toolchain class hierarchy

2020-03-02 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D75373#1898620 , @aganea wrote:

> @hans, do you think this could be included in 10.0?


I think it's too late in the process for this, maybe it can be merged for 
10.0.1.


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

https://reviews.llvm.org/D75373



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


[clang-tools-extra] c443b61 - [clangd] Remove the deprecated clangdServer::rename API, NFC.

2020-03-02 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-03-02T09:48:25+01:00
New Revision: c443b610bf3682eb32949b552b8c6908a8d96267

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

LOG: [clangd] Remove the deprecated clangdServer::rename API, NFC.

There is no actual user of it now.

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 92dcf841331a..f1a88902c8c0 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -394,14 +394,6 @@ void ClangdServer::rename(PathRef File, Position Pos, 
llvm::StringRef NewName,
   WorkScheduler.runWithAST("Rename", File, std::move(Action));
 }
 
-void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  bool WantFormat, Callback CB) {
-  RenameOptions Opts;
-  Opts.WantFormat = WantFormat;
-  Opts.AllowCrossFile = false;
-  rename(File, Pos, NewName, Opts, std::move(CB));
-}
-
 // May generate several candidate selections, due to SelectionTree ambiguity.
 // vector of pointers because GCC doesn't like non-copyable Selection.
 static llvm::Expected>>

diff  --git a/clang-tools-extra/clangd/ClangdServer.h 
b/clang-tools-extra/clangd/ClangdServer.h
index ced0325fc7b3..e9f2c30b1749 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -264,9 +264,6 @@ class ClangdServer {
   /// highlighting them in prepare stage).
   void rename(PathRef File, Position Pos, llvm::StringRef NewName,
   const RenameOptions &Opts, Callback CB);
-  // FIXME: remove this compatibility method in favor above.
-  void rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  bool WantFormat, Callback CB);
 
   struct TweakRef {
 std::string ID;/// ID to pass for applyTweak.



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


[PATCH] D75373: [Clang] Fix Hurd toolchain class hierarchy

2020-03-02 Thread Kristina Brooks via Phabricator via cfe-commits
kristina accepted this revision.
kristina added a comment.
This revision is now accepted and ready to land.

In D75373#1900237 , @aganea wrote:

> The patch did not make sense conceptually. Hurd is not Linux. I think now it 
> makes more sense.


Yes this seems to make more sense now. LGTM.


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

https://reviews.llvm.org/D75373



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


[PATCH] D75057: Syndicate, test and fix base64 implementation

2020-03-02 Thread serge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5a1958f2673f: Syndicate, test and fix base64 implementation 
(authored by serge-sans-paille).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75057

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  compiler-rt/lib/fuzzer/FuzzerUtil.cpp
  llvm/include/llvm/Support/Base64.h
  llvm/unittests/Support/Base64Test.cpp
  llvm/unittests/Support/CMakeLists.txt

Index: llvm/unittests/Support/CMakeLists.txt
===
--- llvm/unittests/Support/CMakeLists.txt
+++ llvm/unittests/Support/CMakeLists.txt
@@ -9,6 +9,7 @@
   AnnotationsTest.cpp
   ARMAttributeParser.cpp
   ArrayRecyclerTest.cpp
+  Base64Test.cpp
   BinaryStreamTest.cpp
   BlockFrequencyTest.cpp
   BranchProbabilityTest.cpp
Index: llvm/unittests/Support/Base64Test.cpp
===
--- /dev/null
+++ llvm/unittests/Support/Base64Test.cpp
@@ -0,0 +1,53 @@
+//===- llvm/unittest/Support/Base64Test.cpp - Base64 tests
+//===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file implements unit tests for the Base64 functions.
+//
+//===--===//
+
+#include "llvm/Support/Base64.h"
+#include "llvm/ADT/StringRef.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+/// Tests an arbitrary set of bytes passed as \p Input.
+void TestBase64(StringRef Input, StringRef Final) {
+  auto Res = encodeBase64(Input);
+  EXPECT_EQ(Res, Final);
+}
+
+} // namespace
+
+TEST(Base64Test, Base64) {
+  // from: https://tools.ietf.org/html/rfc4648#section-10
+  TestBase64("", "");
+  TestBase64("f", "Zg==");
+  TestBase64("fo", "Zm8=");
+  TestBase64("foo", "Zm9v");
+  TestBase64("foob", "Zm9vYg==");
+  TestBase64("fooba", "Zm9vYmE=");
+  TestBase64("foobar", "Zm9vYmFy");
+
+  // With non-printable values.
+  char NonPrintableVector[] = {0x00, 0x00, 0x00,   0x46,
+   0x00, 0x08, (char)0xff, (char)0xee};
+  TestBase64(StringRef(NonPrintableVector, sizeof(NonPrintableVector)),
+ "RgAI/+4=");
+
+  // Large test case
+  char LargeVector[] = {0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b,
+0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f,
+0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f,
+0x76, 0x65, 0x72, 0x20, 0x31, 0x33, 0x20, 0x6c, 0x61,
+0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67, 0x73, 0x2e};
+  TestBase64(LargeVector,
+ "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIDEzIGxhenkgZG9ncy4=");
+}
Index: llvm/include/llvm/Support/Base64.h
===
--- /dev/null
+++ llvm/include/llvm/Support/Base64.h
@@ -0,0 +1,53 @@
+//===--- Base64.h - Base64 Encoder/Decoder --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file provides generic base64 encoder/decoder.
+//
+//===--===//
+
+#ifndef LLVM_SUPPORT_BASE64_H
+#define LLVM_SUPPORT_BASE64_H
+
+#include 
+
+namespace llvm {
+
+template  std::string encodeBase64(InputBytes const &Bytes) {
+  static const char Table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+  "abcdefghijklmnopqrstuvwxyz"
+  "0123456789+/";
+  std::string Buffer;
+  Buffer.resize(((Bytes.size() + 2) / 3) * 4);
+
+  size_t i = 0, j = 0;
+  for (size_t n = Bytes.size() / 3 * 3; i < n; i += 3, j += 4) {
+uint32_t x = (Bytes[i] << 16) | (Bytes[i + 1] << 8) | Bytes[i + 2];
+Buffer[j + 0] = Table[(x >> 18) & 63];
+Buffer[j + 1] = Table[(x >> 12) & 63];
+Buffer[j + 2] = Table[(x >> 6) & 63];
+Buffer[j + 3] = Table[x & 63];
+  }
+  if (i + 1 == Bytes.size()) {
+uint32_t x = (Bytes[i] << 16);
+Buffer[j + 0] = Table[(x >> 18) & 63];
+Buffer[j + 1] = Table[(x >> 12) & 63];
+Buffer[j + 2] = '=';
+Buffer[j + 3] = '=';
+  } else if (i + 2 == Bytes.size()) {
+uint32_t x = (Bytes[i] << 16) | (Bytes[i + 1] << 8);
+Buffer[j + 0] = Table[(x >> 18) & 63];
+Buffer[j + 1] = Table[(x >> 12) & 63];
+Buffer[j + 2] = Table[(x >> 6) & 63];
+Buffer[j + 3] = '=';
+  }
+  return Buffer;
+

[PATCH] D75439: [clangd] No need to query ctor refs in cross-file rename.

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

This patch reverts 
https://github.com/llvm/llvm-project/commit/2c5ee78de113484978450b834498e1b0e2aab5c4,
now kythe (https://github.com/kythe/kythe/issues/4381) supports returning ctors 
refs as part of class references, so
there is no need to query the ctor refs in the index (this would also
make the results worse, lots of duplications)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75439

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
@@ -798,53 +798,6 @@
   testing::HasSubstr("too many occurrences"));
 }
 
-TEST(CrossFileRename, QueryCtorInIndex) {
-  const auto MainCode = Annotations("F^oo f;");
-  auto TU = TestTU::withCode(MainCode.code());
-  TU.HeaderCode = R"cpp(
-class Foo {
-public:
-  Foo() = default;
-};
-  )cpp";
-  auto AST = TU.build();
-
-  RefsRequest Req;
-  class RecordIndex : public SymbolIndex {
-  public:
-RecordIndex(RefsRequest *R) : Out(R) {}
-bool refs(const RefsRequest &Req,
-  llvm::function_ref Callback) const override {
-  *Out = Req;
-  return false;
-}
-
-bool fuzzyFind(const FuzzyFindRequest &,
-   llvm::function_ref) const override {
-  return false;
-}
-void lookup(const LookupRequest &,
-llvm::function_ref) const override {}
-
-void relations(const RelationsRequest &,
-   llvm::function_ref)
-const override {}
-size_t estimateMemoryUsage() const override { return 0; }
-
-RefsRequest *Out;
-  } RIndex(&Req);
-  auto Results = rename({MainCode.point(),
- "NewName",
- AST,
- testPath("main.cc"),
- &RIndex,
- {/*CrossFile=*/true}});
-  ASSERT_TRUE(bool(Results)) << Results.takeError();
-  const auto HeaderSymbols = TU.headerSymbols();
-  EXPECT_THAT(Req.IDs,
-  testing::Contains(findSymbol(HeaderSymbols, "Foo::Foo").ID));
-}
-
 TEST(CrossFileRenameTests, DeduplicateRefsFromIndex) {
   auto MainCode = Annotations("int [[^x]] = 2;");
   auto MainFilePath = testPath("main.cc");
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -295,23 +295,6 @@
   return R;
 }
 
-std::vector getConstructors(const NamedDecl *ND) {
-  std::vector Ctors;
-  if (const auto *RD = dyn_cast(ND)) {
-if (!RD->hasUserDeclaredConstructor())
-  return {};
-for (const CXXConstructorDecl *Ctor : RD->ctors())
-  Ctors.push_back(Ctor);
-for (const auto *D : RD->decls()) {
-  if (const auto *FTD = dyn_cast(D))
-if (const auto *Ctor =
-dyn_cast(FTD->getTemplatedDecl()))
-  Ctors.push_back(Ctor);
-}
-  }
-  return Ctors;
-}
-
 // Return all rename occurrences (using the index) outside of the main file,
 // grouped by the absolute file path.
 llvm::Expected>>
@@ -321,14 +304,6 @@
   trace::Span Tracer("FindOccurrencesOutsideFile");
   RefsRequest RQuest;
   RQuest.IDs.insert(*getSymbolID(&RenameDecl));
-  // Classes and their constructors are different symbols, and have different
-  // symbol ID.
-  // When querying references for a class, clangd's own index will also return
-  // references of the corresponding class constructors, but this is not true
-  // for all index backends, e.g. kythe, so we add all constructors to the query
-  // request.
-  for (const auto *Ctor : getConstructors(&RenameDecl))
-RQuest.IDs.insert(*getSymbolID(Ctor));
 
   // Absolute file path => rename occurrences in that file.
   llvm::StringMap> AffectedFiles;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73462: [dwarf-5] Support DebugInfo for Defaulted parameters for C++ templates

2020-03-02 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

I also just noticed that this broke the Chromium build, see the attached 
reproducer at https://bugs.chromium.org/p/chromium/issues/detail?id=1057559#c1

clang++: /work/llvm.monorepo/clang/lib/AST/ExprConstant.cpp:14013: llvm::APSInt 
clang::Expr::EvaluateKnownConstInt(const clang::ASTContext &, 
SmallVectorImpl *) const: Assertion 
`!isValueDependent() && "Expression evaluator can't be called on a dependent 
expression."' failed.

#10 0x046eb71d clang::Expr::EvaluateKnownConstInt(clang::ASTContext 
const&, llvm::SmallVectorImpl >*) const 
(../../../../llvm.monorepo/build.release/bin/clang+++0x46eb71d)
#11 0x027875de 
clang::CodeGen::CGDebugInfo::CollectTemplateParams(clang::TemplateParameterList 
const*, llvm::ArrayRef, llvm::DIFile*) 
(../../../../llvm.monorepo/build.release/bin/clang+++0x27875de)
#12 0x0278f67b 
clang::CodeGen::CGDebugInfo::CreateLimitedType(clang::RecordType const*) 
(../../../../llvm.monorepo/build.release/bin/clang+++0x278f67b)
#13 0x0278a2d1 
clang::CodeGen::CGDebugInfo::getOrCreateLimitedType(clang::RecordType const*, 
llvm::DIFile*) (../../../../llvm.monorepo/build.release/bin/clang+++0x278a2d1)
#14 0x0278980b 
clang::CodeGen::CGDebugInfo::CreateTypeDefinition(clang::RecordType const*) 
(../../../../llvm.monorepo/build.release/bin/clang+++0x278980b)
#15 0x0277eb15 
clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) 
(../../../../llvm.monorepo/build.release/bin/clang+++0x277eb15)
#16 0x02782c58 
clang::CodeGen::CGDebugInfo::CreateType(clang::TypedefType const*, 
llvm::DIFile*) (../../../../llvm.monorepo/build.release/bin/clang+++0x2782c58)
#17 0x0277eb15 
clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) 
(../../../../llvm.monorepo/build.release/bin/clang+++0x277eb15)
#18 0x02782a5f 
clang::CodeGen::CGDebugInfo::CreateType(clang::TypedefType const*, 
llvm::DIFile*) (../../../../llvm.monorepo/build.release/bin/clang+++0x2782a5f)
#19 0x0277eb15 
clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) 
(../../../../llvm.monorepo/build.release/bin/clang+++0x277eb15)
#20 0x0279a13d 
clang::CodeGen::CGDebugInfo::EmitExplicitCastType(clang::QualType) 
(../../../../llvm.monorepo/build.release/bin/clang+++0x279a13d)
#21 0x02a26632 clang::StmtVisitorBase::Visit(clang::Stmt*) 
(../../../../llvm.monorepo/build.release/bin/clang+++0x2a26632)
#22 0x02a32e14 (anonymous 
namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) 
(../../../../llvm.monorepo/build.release/bin/clang+++0x2a32e14)
#23 0x02a1e3c5 
clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) 
(../../../../llvm.monorepo/build.release/bin/clang+++0x2a1e3c5)
#24 0x028e8257 
clang::CodeGen::CodeGenFunction::EmitAtomicExpr(clang::AtomicExpr*) 
(../../../../llvm.monorepo/build.release/bin/clang+++0x28e8257)
...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73462



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


[PATCH] D75439: [clangd] No need to query ctor refs in cross-file rename.

2020-03-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks for following up!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75439



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


[PATCH] D75056: [Driver] Default to -fno-common for all targets

2020-03-02 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added a comment.

Friendly ping, and just checking: are we happy with this? Good to go?


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

https://reviews.llvm.org/D75056



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


[PATCH] D75441: [clang-tidy] Add helper base check classes that only run on specific language versions

2020-03-02 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, gribozavr2, alexfh, lebedev.ri, 
Eugene.Zelenko.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75441

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h


Index: clang-tools-extra/clang-tidy/ClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -204,6 +204,39 @@
   const LangOptions &getLangOpts() const { return Context->getLangOpts(); }
 };
 
+/// Helper class for clang-tidy checks that only register when in `Cc mode.
+class CClangTidyCheck : public ClangTidyCheck {
+  using ClangTidyCheck::ClangTidyCheck;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const final {
+return LangOpts.C99;
+  }
+};
+
+/// Helper class for clang-tidy checks that only register when in `c++` mode.
+class CppClangTidyCheck : public ClangTidyCheck {
+  using ClangTidyCheck::ClangTidyCheck;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const final {
+return LangOpts.CPlusPlus;
+  }
+};
+
+/// Helper class for clang-tidy checks that only register when in `c++11` mode.
+class Cpp11ClangTidyCheck : public ClangTidyCheck {
+  using ClangTidyCheck::ClangTidyCheck;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const final {
+return LangOpts.CPlusPlus11;
+  }
+};
+
+/// Helper class for clang-tidy checks that only register when in `Objective-c`
+/// mode.
+class ObjCClangTidyCheck : public ClangTidyCheck {
+  using ClangTidyCheck::ClangTidyCheck;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const final {
+return LangOpts.ObjC;
+  }
+};
+
 } // namespace tidy
 } // namespace clang
 


Index: clang-tools-extra/clang-tidy/ClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -204,6 +204,39 @@
   const LangOptions &getLangOpts() const { return Context->getLangOpts(); }
 };
 
+/// Helper class for clang-tidy checks that only register when in `Cc mode.
+class CClangTidyCheck : public ClangTidyCheck {
+  using ClangTidyCheck::ClangTidyCheck;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const final {
+return LangOpts.C99;
+  }
+};
+
+/// Helper class for clang-tidy checks that only register when in `c++` mode.
+class CppClangTidyCheck : public ClangTidyCheck {
+  using ClangTidyCheck::ClangTidyCheck;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const final {
+return LangOpts.CPlusPlus;
+  }
+};
+
+/// Helper class for clang-tidy checks that only register when in `c++11` mode.
+class Cpp11ClangTidyCheck : public ClangTidyCheck {
+  using ClangTidyCheck::ClangTidyCheck;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const final {
+return LangOpts.CPlusPlus11;
+  }
+};
+
+/// Helper class for clang-tidy checks that only register when in `Objective-c`
+/// mode.
+class ObjCClangTidyCheck : public ClangTidyCheck {
+  using ClangTidyCheck::ClangTidyCheck;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const final {
+return LangOpts.ObjC;
+  }
+};
+
 } // namespace tidy
 } // namespace clang
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d40afad - [git-clang-format] Fix typo in help message

2020-03-02 Thread Jim Lin via cfe-commits

Author: Jim Lin
Date: 2020-03-02T18:16:35+08:00
New Revision: d40afadec0acd5f093a5f46fa2362312aef54189

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

LOG: [git-clang-format] Fix typo in help message

Added: 


Modified: 
clang/tools/clang-format/git-clang-format

Removed: 




diff  --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index bf05d9143fa1..abbe3b7b97c6 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -45,7 +45,7 @@ second  that 
diff er from the first .
 The following git-config settings set the default of the corresponding option:
   clangFormat.binary
   clangFormat.commit
-  clangFormat.extension
+  clangFormat.extensions
   clangFormat.style
 '''
 



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


[PATCH] D75340: [clang-tidy] Change checks to use new isLanguageVersionSupported restriction

2020-03-02 Thread Nathan James via Phabricator via cfe-commits
njames93 planned changes to this revision.
njames93 added a comment.

Made another pull request that could neaten this implementation up - 
https://reviews.llvm.org/D75441, will wait to see how that goes down before 
getting this pushed.




Comment at: 
clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.h:30
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+return LangOpts.CPlusPlus && !LangOpts.CPlusPlus17;
+  }

gribozavr2 wrote:
> I think CPlusPlus17 implies CPlusPlus.
This is saying it needs c++ but not c++17, so c++98->c++14 are Ok but not 17 or 
20. Besides this is the current behaviour in the cpp file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75340



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


[PATCH] D75441: [clang-tidy] Add helper base check classes that only run on specific language versions

2020-03-02 Thread Nathan James via Phabricator via cfe-commits
njames93 marked an inline comment as done.
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/ClangTidyCheck.h:224
+/// Helper class for clang-tidy checks that only register when in `c++11` mode.
+class Cpp11ClangTidyCheck : public ClangTidyCheck {
+  using ClangTidyCheck::ClangTidyCheck;

Given the amount of new stuff added in c++11 and how many checks require c++11 
I thought having a separate c++11 mode class would be a good idea, c++14/17 
probably not so much though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75441



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


[PATCH] D72911: clang-format: fix spacing in `operator const char*()`

2020-03-02 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D72911#1900091 , @sylvestre.ledru 
wrote:

> @krasimir @MyDeveloperDay @hans Looks like it is a regression from 
> https://reviews.llvm.org/D72911
>  and the fix isn't in 10.0rc2.
>  Should we take it?


Seems pretty safe. I've pushed it as 99e5b2ff9df5ca4c7fe13b63f60d953058cd9ca3 
. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72911



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


[PATCH] D69573: [clang-format] [PR36294] AlwaysBreakAfterReturnType works incorrectly for some operator functions

2020-03-02 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D69573#1900089 , @sylvestre.ledru 
wrote:

> @MyDeveloperDay @hans what about adding this to the release notes?
>  I was trying clang-format 10 on Firefox code base and I noticed this change 
> which isn't documented in
>  
> https://prereleases.llvm.org/10.0.0/rc1/tools/clang/docs/ReleaseNotes.html#clang-format
>  (I can do it if you want)


Release notes are very welcome :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69573



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


[clang] a41ecf0 - [ARM, MVE] Add ACLE intrinsics for VQMOV[U]N family.

2020-03-02 Thread Simon Tatham via cfe-commits

Author: Simon Tatham
Date: 2020-03-02T10:33:30Z
New Revision: a41ecf0eb05190c8597f98b8d41d7a6e678aec0b

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

LOG: [ARM,MVE] Add ACLE intrinsics for VQMOV[U]N family.

Summary:
These instructions work like VMOVN (narrowing a vector of wide values
to half size, and overwriting every other lane of an output register
with the result), except that the narrowing conversion is saturating.
They come in three signedness flavours: signed to signed, unsigned to
unsigned, and signed to unsigned. All are represented in IR by a
target-specific intrinsic that takes two separate 'unsigned' flags.

Reviewers: MarkMurrayARM, dmgreen, miyuki, ostannard

Reviewed By: dmgreen

Subscribers: kristof.beyls, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Added: 
clang/test/CodeGen/arm-mve-intrinsics/vqmovn.c
llvm/test/CodeGen/Thumb2/mve-intrinsics/vqmovn.ll

Modified: 
clang/include/clang/Basic/arm_mve.td
clang/include/clang/Basic/arm_mve_defs.td
llvm/include/llvm/IR/IntrinsicsARM.td
llvm/lib/Target/ARM/ARMInstrMVE.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_mve.td 
b/clang/include/clang/Basic/arm_mve.td
index efc6be1158b8..c64a75ffeb8e 100644
--- a/clang/include/clang/Basic/arm_mve.td
+++ b/clang/include/clang/Basic/arm_mve.td
@@ -514,6 +514,33 @@ defm vmovntq: vmovn<1, (zip (vreinterpret $inactive, 
Vector), $a)>;
 defm vmovnbq: vmovn<0,
(zip $a, (vreinterpret (vrev $inactive, (bitsize Scalar)), Vector))>;
 
+multiclass vqmovn {
+  defvar RetVector = VecOf;
+
+  let params = [s16, u16, s32, u32] in {
+def : Intrinsic<
+  RetVector, (args RetVector:$inactive, Vector:$a),
+  (IRInt<"vqmovn", [RetVector, Vector]>
+  $inactive, $a, (unsignedflag RetScalar), (unsignedflag Scalar), 
top)>,
+  NameOverride;
+def: Intrinsic<
+  RetVector, (args RetVector:$inactive, Vector:$a, Predicate:$pred),
+  (IRInt<"vqmovn_predicated", [RetVector, Vector, Predicate]>
+  $inactive, $a, (unsignedflag RetScalar), (unsignedflag Scalar),
+  top, $pred)>,
+  NameOverride;
+  }
+}
+
+let params = [s16, s32, u16, u32] in {
+  defm vqmovntq: vqmovn<1, HalfScalar>;
+  defm vqmovnbq: vqmovn<0, HalfScalar>;
+}
+let params = [s16, s32] in {
+  defm vqmovuntq: vqmovn<1, UHalfScalar>;
+  defm vqmovunbq: vqmovn<0, UHalfScalar>;
+}
+
 multiclass vrnd {
   let params = T.Float in {
 def "": Intrinsic;

diff  --git a/clang/include/clang/Basic/arm_mve_defs.td 
b/clang/include/clang/Basic/arm_mve_defs.td
index dbcad78cce75..daf73871f052 100644
--- a/clang/include/clang/Basic/arm_mve_defs.td
+++ b/clang/include/clang/Basic/arm_mve_defs.td
@@ -323,8 +323,10 @@ def SVector: VecOf;
 // UHalfVector is a vector of half-sized _unsigned integers_.
 def DblVector: VecOf>;
 def DblPredicate: PredOf>;
-def HalfVector: VecOf>;
-def UHalfVector: VecOf>>;
+def HalfScalar: HalfSize;
+def HalfVector: VecOf;
+def UHalfScalar: Unsigned>;
+def UHalfVector: VecOf;
 
 // Expands to the 32-bit integer of the same signedness as Scalar.
 def Scalar32: CopyKind;

diff  --git a/clang/test/CodeGen/arm-mve-intrinsics/vqmovn.c 
b/clang/test/CodeGen/arm-mve-intrinsics/vqmovn.c
new file mode 100644
index ..24c3fd550bf4
--- /dev/null
+++ b/clang/test/CodeGen/arm-mve-intrinsics/vqmovn.c
@@ -0,0 +1,366 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature +mve 
-mfloat-abi hard -fallow-half-arguments-and-returns -O0 -disable-O0-optnone -S 
-emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s
+// RUN: %clang_cc1 -DPOLYMORPHIC -triple thumbv8.1m.main-arm-none-eabi 
-target-feature +mve -mfloat-abi hard -fallow-half-arguments-and-returns -O0 
-disable-O0-optnone -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s
+
+#include 
+
+// CHECK-LABEL: @test_vqmovnbq_s16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call <16 x i8> 
@llvm.arm.mve.vqmovn.v16i8.v8i16(<16 x i8> [[A:%.*]], <8 x i16> [[B:%.*]], i32 
0, i32 0, i32 0)
+// CHECK-NEXT:ret <16 x i8> [[TMP0]]
+//
+int8x16_t test_vqmovnbq_s16(int8x16_t a, int16x8_t b)
+{
+#ifdef POLYMORPHIC
+return vqmovnbq(a, b);
+#else /* POLYMORPHIC */
+return vqmovnbq_s16(a, b);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @test_vqmovnbq_s32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vqmovn.v8i16.v4i32(<8 x i16> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
0, i32 0, i32 0)
+// CHECK-NEXT:ret <8 x i16> [[TMP0]]
+//
+int16x8_t test_vqmovnbq_s32(int16x8_t a, int32x4_t b)
+{
+#ifdef POLYMORPHIC
+return vqmovnbq(a, b);
+#else /* POLYMORPHIC */
+return 

[clang] 1a8cbfa - [ARM, MVE] Add ACLE intrinsics for VCVT[ANPM] family.

2020-03-02 Thread Simon Tatham via cfe-commits

Author: Simon Tatham
Date: 2020-03-02T10:33:30Z
New Revision: 1a8cbfa514ff83ac62c20deec0d9ea2c6606bbdf

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

LOG: [ARM,MVE] Add ACLE intrinsics for VCVT[ANPM] family.

Summary:
These instructions convert a vector of floats to a vector of integers
of the same size, with assorted non-default rounding modes.
Implemented in IR as target-specific intrinsics, because as far as I
can see there are no matches for that functionality in the standard IR
intrinsics list.

Reviewers: MarkMurrayARM, dmgreen, miyuki, ostannard

Reviewed By: dmgreen

Subscribers: kristof.beyls, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Added: 
clang/test/CodeGen/arm-mve-intrinsics/vcvt_anpm.c
llvm/test/CodeGen/Thumb2/mve-intrinsics/vcvt_anpm.ll

Modified: 
clang/include/clang/Basic/arm_mve.td
llvm/include/llvm/IR/IntrinsicsARM.td
llvm/lib/Target/ARM/ARMInstrMVE.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_mve.td 
b/clang/include/clang/Basic/arm_mve.td
index dfdb101d587f..c1cc10b09dc6 100644
--- a/clang/include/clang/Basic/arm_mve.td
+++ b/clang/include/clang/Basic/arm_mve.td
@@ -482,11 +482,25 @@ multiclass float_int_conversions,
 NameOverride<"vcvtq_" # IScalar>;
+
+  foreach suffix = ["a","n","p","m"] in
+def : Intrinsic
+(unsignedflag IScalar), $a)>,
+  NameOverride<"vcvt"#suffix#"q_" # IScalar>;
 }
 defm vcvtq: IntrinsicMX
 $a, (unsignedflag IScalar), $pred, $inactive),
 1, "_" # IScalar, PNT_2Type, PNT_None>;
+
+foreach suffix = ["a","n","p","m"] in {
+  defm "vcvt"#suffix#"q" : IntrinsicMX<
+  IVector, (args FVector:$a, Predicate:$pred),
+  (IRInt<"vcvt"#suffix#"_predicated", [IVector, FVector, Predicate]>
+  (unsignedflag IScalar), $inactive, $a, $pred),
+  1, "_" # IScalar, PNT_2Type, PNT_None>;
+}
   }
 }
 

diff  --git a/clang/test/CodeGen/arm-mve-intrinsics/vcvt_anpm.c 
b/clang/test/CodeGen/arm-mve-intrinsics/vcvt_anpm.c
new file mode 100644
index ..e5dbd4c8f68b
--- /dev/null
+++ b/clang/test/CodeGen/arm-mve-intrinsics/vcvt_anpm.c
@@ -0,0 +1,614 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature 
+mve.fp -mfloat-abi hard -fallow-half-arguments-and-returns -O0 
-disable-O0-optnone -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s
+// RUN: %clang_cc1 -DPOLYMORPHIC -triple thumbv8.1m.main-arm-none-eabi 
-target-feature +mve.fp -mfloat-abi hard -fallow-half-arguments-and-returns -O0 
-disable-O0-optnone -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s
+
+#include 
+
+// CHECK-LABEL: @test_vcvtaq_s16_f16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vcvta.v8i16.v8f16(i32 0, <8 x half> [[A:%.*]])
+// CHECK-NEXT:ret <8 x i16> [[TMP0]]
+//
+int16x8_t test_vcvtaq_s16_f16(float16x8_t a)
+{
+return vcvtaq_s16_f16(a);
+}
+
+// CHECK-LABEL: @test_vcvtaq_s32_f32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call <4 x i32> 
@llvm.arm.mve.vcvta.v4i32.v4f32(i32 0, <4 x float> [[A:%.*]])
+// CHECK-NEXT:ret <4 x i32> [[TMP0]]
+//
+int32x4_t test_vcvtaq_s32_f32(float32x4_t a)
+{
+return vcvtaq_s32_f32(a);
+}
+
+// CHECK-LABEL: @test_vcvtaq_u16_f16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vcvta.v8i16.v8f16(i32 1, <8 x half> [[A:%.*]])
+// CHECK-NEXT:ret <8 x i16> [[TMP0]]
+//
+uint16x8_t test_vcvtaq_u16_f16(float16x8_t a)
+{
+return vcvtaq_u16_f16(a);
+}
+
+// CHECK-LABEL: @test_vcvtaq_u32_f32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call <4 x i32> 
@llvm.arm.mve.vcvta.v4i32.v4f32(i32 1, <4 x float> [[A:%.*]])
+// CHECK-NEXT:ret <4 x i32> [[TMP0]]
+//
+uint32x4_t test_vcvtaq_u32_f32(float32x4_t a)
+{
+return vcvtaq_u32_f32(a);
+}
+
+// CHECK-LABEL: @test_vcvtmq_s16_f16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vcvtm.v8i16.v8f16(i32 0, <8 x half> [[A:%.*]])
+// CHECK-NEXT:ret <8 x i16> [[TMP0]]
+//
+int16x8_t test_vcvtmq_s16_f16(float16x8_t a)
+{
+return vcvtmq_s16_f16(a);
+}
+
+// CHECK-LABEL: @test_vcvtmq_s32_f32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call <4 x i32> 
@llvm.arm.mve.vcvtm.v4i32.v4f32(i32 0, <4 x float> [[A:%.*]])
+// CHECK-NEXT:ret <4 x i32> [[TMP0]]
+//
+int32x4_t test_vcvtmq_s32_f32(float32x4_t a)
+{
+return vcvtmq_s32_f32(a);
+}
+
+// CHECK-LABEL: @test_vcvtmq_u16_f16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call <8 x i16> 
@llvm.arm.mve.vcvtm.v

[clang] b08d2dd - [ARM, MVE] Add ACLE intrinsics for VCVT.F32.F16 family.

2020-03-02 Thread Simon Tatham via cfe-commits

Author: Simon Tatham
Date: 2020-03-02T10:33:30Z
New Revision: b08d2ddd69b4a2209930b31fe456b4d7c1ce148f

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

LOG: [ARM,MVE] Add ACLE intrinsics for VCVT.F32.F16 family.

Summary:
These instructions make a vector of `<4 x float>` by widening every
other lane of a vector of `<8 x half>`.

I wondered about representing these using standard IR, along the lines
of a shufflevector to extract elements of the input into a `<4 x half>`
followed by an `fpext` to turn that into `<4 x float>`. But it looks as
if that would take a lot of work in isel lowering to make it match any
pattern I could sensibly write in Tablegen, and also I haven't been
able to think of any other case where that pattern might be generated
in IR, so there wouldn't be any extra code generation win from doing
it that way.

Therefore, I've just used another target-specific intrinsic. We can
always change it to the other way later if anyone thinks of a good
reason.

(In order to put the intrinsic definition near similar things in
`IntrinsicsARM.td`, I've also lifted the definition of the
`MVEMXPredicated` multiclass higher up the file, without changing it.)

Reviewers: MarkMurrayARM, dmgreen, miyuki, ostannard

Reviewed By: miyuki

Subscribers: kristof.beyls, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Added: 


Modified: 
clang/include/clang/Basic/arm_mve.td
clang/test/CodeGen/arm-mve-intrinsics/vcvt.c
llvm/include/llvm/IR/IntrinsicsARM.td
llvm/lib/Target/ARM/ARMInstrMVE.td
llvm/test/CodeGen/Thumb2/mve-intrinsics/vcvt.ll

Removed: 




diff  --git a/clang/include/clang/Basic/arm_mve.td 
b/clang/include/clang/Basic/arm_mve.td
index c64a75ffeb8e..dfdb101d587f 100644
--- a/clang/include/clang/Basic/arm_mve.td
+++ b/clang/include/clang/Basic/arm_mve.td
@@ -453,6 +453,15 @@ foreach half = [ "b", "t" ] in {
   VecOf, (args VecOf:$inactive, Vector:$a, PredOf:$pred),
   (IRInt<"vcvt_narrow_predicated"> $inactive, $a, halfconst, $pred)>;
   } // params = [f32], pnt = PNT_None
+
+  let params = [f16], pnt = PNT_None in {
+def vcvt#half#q_f32: Intrinsic, (args Vector:$a),
+  (IRInt<"vcvt_widen"> $a, halfconst)>;
+defm vcvt#half#q: IntrinsicMX<
+  VecOf, (args Vector:$a, PredOf:$pred),
+  (IRInt<"vcvt_widen_predicated"> $inactive, $a, halfconst, $pred),
+  1, "_f32">;
+  } // params = [f16], pnt = PNT_None
 } // loop over half = "b", "t"
 
 multiclass float_int_conversions {

diff  --git a/clang/test/CodeGen/arm-mve-intrinsics/vcvt.c 
b/clang/test/CodeGen/arm-mve-intrinsics/vcvt.c
index 0391b77e365f..d03ac31a8024 100644
--- a/clang/test/CodeGen/arm-mve-intrinsics/vcvt.c
+++ b/clang/test/CodeGen/arm-mve-intrinsics/vcvt.c
@@ -697,3 +697,71 @@ uint32x4_t test_vcvtq_x_n_u32_f32(float32x4_t a, 
mve_pred16_t p)
 {
 return vcvtq_x_n_u32_f32(a, 32, p);
 }
+
+// CHECK-LABEL: @test_vcvtbq_f32_f16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call <4 x float> @llvm.arm.mve.vcvt.widen(<8 
x half> [[A:%.*]], i32 0)
+// CHECK-NEXT:ret <4 x float> [[TMP0]]
+//
+float32x4_t test_vcvtbq_f32_f16(float16x8_t a)
+{
+return vcvtbq_f32_f16(a);
+}
+
+// CHECK-LABEL: @test_vcvttq_f32_f16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call <4 x float> @llvm.arm.mve.vcvt.widen(<8 
x half> [[A:%.*]], i32 1)
+// CHECK-NEXT:ret <4 x float> [[TMP0]]
+//
+float32x4_t test_vcvttq_f32_f16(float16x8_t a)
+{
+return vcvttq_f32_f16(a);
+}
+
+// CHECK-LABEL: @test_vcvtbq_m_f32_f16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = zext i16 [[P:%.*]] to i32
+// CHECK-NEXT:[[TMP1:%.*]] = call <4 x i1> @llvm.arm.mve.pred.i2v.v4i1(i32 
[[TMP0]])
+// CHECK-NEXT:[[TMP2:%.*]] = call <4 x float> 
@llvm.arm.mve.vcvt.widen.predicated(<4 x float> [[INACTIVE:%.*]], <8 x half> 
[[A:%.*]], i32 0, <4 x i1> [[TMP1]])
+// CHECK-NEXT:ret <4 x float> [[TMP2]]
+//
+float32x4_t test_vcvtbq_m_f32_f16(float32x4_t inactive, float16x8_t a, 
mve_pred16_t p)
+{
+return vcvtbq_m_f32_f16(inactive, a, p);
+}
+
+// CHECK-LABEL: @test_vcvttq_m_f32_f16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = zext i16 [[P:%.*]] to i32
+// CHECK-NEXT:[[TMP1:%.*]] = call <4 x i1> @llvm.arm.mve.pred.i2v.v4i1(i32 
[[TMP0]])
+// CHECK-NEXT:[[TMP2:%.*]] = call <4 x float> 
@llvm.arm.mve.vcvt.widen.predicated(<4 x float> [[INACTIVE:%.*]], <8 x half> 
[[A:%.*]], i32 1, <4 x i1> [[TMP1]])
+// CHECK-NEXT:ret <4 x float> [[TMP2]]
+//
+float32x4_t test_vcvttq_m_f32_f16(float32x4_t inactive, float16x8_t a, 
mve_pred16_t p)
+{
+return vcvttq_m_f32_f16(inactive, a, p);
+}
+
+// CHECK-LABEL: @test_vcvtbq_x_f32_f16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]]

[PATCH] D75252: [ARM,MVE] Add ACLE intrinsics for VQMOV[U]N family.

2020-03-02 Thread Simon Tatham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa41ecf0eb051: [ARM,MVE] Add ACLE intrinsics for VQMOV[U]N 
family. (authored by simon_tatham).

Changed prior to commit:
  https://reviews.llvm.org/D75252?vs=246934&id=247580#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75252

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

Index: llvm/test/CodeGen/Thumb2/mve-intrinsics/vqmovn.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/mve-intrinsics/vqmovn.ll
@@ -0,0 +1,299 @@
+; 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 arm_aapcs_vfpcc <16 x i8> @test_vqmovnbq_s16(<16 x i8> %a, <8 x i16> %b) {
+; CHECK-LABEL: test_vqmovnbq_s16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vqmovnb.s16 q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <16 x i8> @llvm.arm.mve.vqmovn.v16i8.v8i16(<16 x i8> %a, <8 x i16> %b, i32 0, i32 0, i32 0)
+  ret <16 x i8> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vqmovnbq_s32(<8 x i16> %a, <4 x i32> %b) {
+; CHECK-LABEL: test_vqmovnbq_s32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vqmovnb.s32 q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <8 x i16> @llvm.arm.mve.vqmovn.v8i16.v4i32(<8 x i16> %a, <4 x i32> %b, i32 0, i32 0, i32 0)
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_vqmovnbq_u16(<16 x i8> %a, <8 x i16> %b) {
+; CHECK-LABEL: test_vqmovnbq_u16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vqmovnb.u16 q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <16 x i8> @llvm.arm.mve.vqmovn.v16i8.v8i16(<16 x i8> %a, <8 x i16> %b, i32 1, i32 1, i32 0)
+  ret <16 x i8> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vqmovnbq_u32(<8 x i16> %a, <4 x i32> %b) {
+; CHECK-LABEL: test_vqmovnbq_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vqmovnb.u32 q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <8 x i16> @llvm.arm.mve.vqmovn.v8i16.v4i32(<8 x i16> %a, <4 x i32> %b, i32 1, i32 1, i32 0)
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_vqmovntq_s16(<16 x i8> %a, <8 x i16> %b) {
+; CHECK-LABEL: test_vqmovntq_s16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vqmovnt.s16 q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <16 x i8> @llvm.arm.mve.vqmovn.v16i8.v8i16(<16 x i8> %a, <8 x i16> %b, i32 0, i32 0, i32 1)
+  ret <16 x i8> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vqmovntq_s32(<8 x i16> %a, <4 x i32> %b) {
+; CHECK-LABEL: test_vqmovntq_s32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vqmovnt.s32 q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <8 x i16> @llvm.arm.mve.vqmovn.v8i16.v4i32(<8 x i16> %a, <4 x i32> %b, i32 0, i32 0, i32 1)
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_vqmovntq_u16(<16 x i8> %a, <8 x i16> %b) {
+; CHECK-LABEL: test_vqmovntq_u16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vqmovnt.u16 q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <16 x i8> @llvm.arm.mve.vqmovn.v16i8.v8i16(<16 x i8> %a, <8 x i16> %b, i32 1, i32 1, i32 1)
+  ret <16 x i8> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vqmovntq_u32(<8 x i16> %a, <4 x i32> %b) {
+; CHECK-LABEL: test_vqmovntq_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vqmovnt.u32 q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <8 x i16> @llvm.arm.mve.vqmovn.v8i16.v4i32(<8 x i16> %a, <4 x i32> %b, i32 1, i32 1, i32 1)
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_vqmovunbq_s16(<16 x i8> %a, <8 x i16> %b) {
+; CHECK-LABEL: test_vqmovunbq_s16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vqmovunb.s16 q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <16 x i8> @llvm.arm.mve.vqmovn.v16i8.v8i16(<16 x i8> %a, <8 x i16> %b, i32 1, i32 0, i32 0)
+  ret <16 x i8> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vqmovunbq_s32(<8 x i16> %a, <4 x i32> %b) {
+; CHECK-LABEL: test_vqmovunbq_s32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vqmovunb.s32 q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <8 x i16> @llvm.arm.mve.vqmovn.v8i16.v4i32(<8 x i16> %a, <4 x i32> %b, i32 1, i32 0, i32 0)
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_vqmovuntq_s16(<16 x i8> %a, <8 x i16> %b) {
+; CHECK-LABEL: test_vqmovuntq_s16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vqmovunt.s16 q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <16 x i8> @llvm.arm.mve.vqmovn.v16i8.v8i16(<16 x i8> %a, <8 x i16> %b, i32 1, i32 0, i32 1)
+  ret <16 x i8> %0
+}
+
+defi

[PATCH] D75254: [ARM,MVE] Add ACLE intrinsics for VCVT.F32.F16 family.

2020-03-02 Thread Simon Tatham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb08d2ddd69b4: [ARM,MVE] Add ACLE intrinsics for VCVT.F32.F16 
family. (authored by simon_tatham).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75254

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

Index: llvm/test/CodeGen/Thumb2/mve-intrinsics/vcvt.ll
===
--- llvm/test/CodeGen/Thumb2/mve-intrinsics/vcvt.ll
+++ llvm/test/CodeGen/Thumb2/mve-intrinsics/vcvt.ll
@@ -6,6 +6,8 @@
 
 declare <8 x half> @llvm.arm.mve.vcvt.narrow(<8 x half>, <4 x float>, i32)
 declare <8 x half> @llvm.arm.mve.vcvt.narrow.predicated(<8 x half>, <4 x float>, i32, <4 x i1>)
+declare <4 x float> @llvm.arm.mve.vcvt.widen(<8 x half>, i32)
+declare <4 x float> @llvm.arm.mve.vcvt.widen.predicated(<4 x float>, <8 x half>, i32, <4 x i1>)
 
 declare <8 x half> @llvm.arm.mve.vcvt.fix.v8f16.v8i16(i32, <8 x i16>, i32)
 declare <4 x float> @llvm.arm.mve.vcvt.fix.v4f32.v4i32(i32, <4 x i32>, i32)
@@ -367,3 +369,51 @@
   %2 = call <4 x i32> @llvm.arm.mve.vcvt.fix.predicated.v4i32.v4f32.v4i1(i32 1, <4 x i32> undef, <4 x float> %a, i32 32, <4 x i1> %1)
   ret <4 x i32> %2
 }
+
+define arm_aapcs_vfpcc <4 x float> @test_vcvtbq_f32_f16(<8 x half> %a) {
+; CHECK-LABEL: test_vcvtbq_f32_f16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvtb.f32.f16 q0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <4 x float> @llvm.arm.mve.vcvt.widen(<8 x half> %a, i32 0)
+  ret <4 x float> %0
+}
+
+define arm_aapcs_vfpcc <4 x float> @test_vcvttq_f32_f16(<8 x half> %a) {
+; CHECK-LABEL: test_vcvttq_f32_f16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvtt.f32.f16 q0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <4 x float> @llvm.arm.mve.vcvt.widen(<8 x half> %a, i32 1)
+  ret <4 x float> %0
+}
+
+define arm_aapcs_vfpcc <4 x float> @test_vcvtbq_m_f32_f16(<4 x float> %inactive, <8 x half> %a, i16 zeroext %p) {
+; CHECK-LABEL: test_vcvtbq_m_f32_f16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmsr p0, r0
+; CHECK-NEXT:vpst
+; CHECK-NEXT:vcvtbt.f32.f16 q0, q1
+; 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 float> @llvm.arm.mve.vcvt.widen.predicated(<4 x float> %inactive, <8 x half> %a, i32 0, <4 x i1> %1)
+  ret <4 x float> %2
+}
+
+define arm_aapcs_vfpcc <4 x float> @test_vcvttq_m_f32_f16(<4 x float> %inactive, <8 x half> %a, i16 zeroext %p) {
+; CHECK-LABEL: test_vcvttq_m_f32_f16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmsr p0, r0
+; CHECK-NEXT:vpst
+; CHECK-NEXT:vcvttt.f32.f16 q0, q1
+; 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 float> @llvm.arm.mve.vcvt.widen.predicated(<4 x float> %inactive, <8 x half> %a, i32 1, <4 x i1> %1)
+  ret <4 x float> %2
+}
Index: llvm/lib/Target/ARM/ARMInstrMVE.td
===
--- llvm/lib/Target/ARM/ARMInstrMVE.td
+++ llvm/lib/Target/ARM/ARMInstrMVE.td
@@ -4515,6 +4515,17 @@
 
 multiclass MVE_VCVT_h2f_m {
   def "": MVE_VCVT_ff;
+  defvar Inst = !cast(NAME);
+
+  let Predicates = [HasMVEFloat] in {
+def : Pat<(v4f32 (int_arm_mve_vcvt_widen (v8f16 MQPR:$Qm), (i32 half))),
+  (v4f32 (Inst (v8f16 MQPR:$Qm)))>;
+def : Pat<(v4f32 (int_arm_mve_vcvt_widen_predicated
+ (v4f32 MQPR:$inactive), (v8f16 MQPR:$Qm), (i32 half),
+ (v4i1 VCCR:$mask))),
+  (v4f32 (Inst (v8f16 MQPR:$Qm), ARMVCCThen,
+   (v4i1 VCCR:$mask), (v4f32 MQPR:$inactive)))>;
+  }
 }
 
 defm MVE_VCVTf16f32bh : MVE_VCVT_f2h_m<"vcvtb", 0b0>;
Index: llvm/include/llvm/IR/IntrinsicsARM.td
===
--- llvm/include/llvm/IR/IntrinsicsARM.td
+++ llvm/include/llvm/IR/IntrinsicsARM.td
@@ -911,8 +911,22 @@
   LLVMMatchType<0>, rets[0])], props>;
 }
 
+// Intrinsic with a predicated and a non-predicated case. The predicated case
+// has two additional parameters: inactive (the value for inactive lanes, can
+// be undef) and predicate.
+multiclass MVEMXPredicated rets, list flags,
+   list params, LLVMType inactive,
+   LLVMType predicate,
+   list props = [IntrNoMem]> {
+  def "":  Intrinsic;
+  def _predicated: Intrinsic;
+}
+
 defm int_arm_mve_vcvt_narrow: MVEPredicated<[llvm_v8f16_ty],
[llvm_v8f16_ty, llvm_v4f32_ty, llvm_i32_ty], llvm_v4i1_ty>;
+defm int_arm_mve_vcvt_widen: MVEMXPredicated<[llvm_v4f32_ty], [],
+   [llvm_v8f16

[PATCH] D75255: [ARM,MVE] Add ACLE intrinsics for VCVT[ANPM] family.

2020-03-02 Thread Simon Tatham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1a8cbfa514ff: [ARM,MVE] Add ACLE intrinsics for VCVT[ANPM] 
family. (authored by simon_tatham).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75255

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

Index: llvm/test/CodeGen/Thumb2/mve-intrinsics/vcvt_anpm.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/mve-intrinsics/vcvt_anpm.ll
@@ -0,0 +1,631 @@
+; 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 arm_aapcs_vfpcc <8 x i16> @test_vcvtaq_s16_f16(<8 x half> %a) {
+; CHECK-LABEL: test_vcvtaq_s16_f16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvta.s16.f16 q0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <8 x i16> @llvm.arm.mve.vcvta.v8i16.v8f16(i32 0, <8 x half> %a)
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vcvtaq_s32_f32(<4 x float> %a) {
+; CHECK-LABEL: test_vcvtaq_s32_f32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvta.s32.f32 q0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <4 x i32> @llvm.arm.mve.vcvta.v4i32.v4f32(i32 0, <4 x float> %a)
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vcvtaq_u16_f16(<8 x half> %a) {
+; CHECK-LABEL: test_vcvtaq_u16_f16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvta.u16.f16 q0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <8 x i16> @llvm.arm.mve.vcvta.v8i16.v8f16(i32 1, <8 x half> %a)
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vcvtaq_u32_f32(<4 x float> %a) {
+; CHECK-LABEL: test_vcvtaq_u32_f32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvta.u32.f32 q0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <4 x i32> @llvm.arm.mve.vcvta.v4i32.v4f32(i32 1, <4 x float> %a)
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vcvtmq_s16_f16(<8 x half> %a) {
+; CHECK-LABEL: test_vcvtmq_s16_f16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvtm.s16.f16 q0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <8 x i16> @llvm.arm.mve.vcvtm.v8i16.v8f16(i32 0, <8 x half> %a)
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vcvtmq_s32_f32(<4 x float> %a) {
+; CHECK-LABEL: test_vcvtmq_s32_f32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvtm.s32.f32 q0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <4 x i32> @llvm.arm.mve.vcvtm.v4i32.v4f32(i32 0, <4 x float> %a)
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vcvtmq_u16_f16(<8 x half> %a) {
+; CHECK-LABEL: test_vcvtmq_u16_f16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvtm.u16.f16 q0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <8 x i16> @llvm.arm.mve.vcvtm.v8i16.v8f16(i32 1, <8 x half> %a)
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vcvtmq_u32_f32(<4 x float> %a) {
+; CHECK-LABEL: test_vcvtmq_u32_f32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvtm.u32.f32 q0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <4 x i32> @llvm.arm.mve.vcvtm.v4i32.v4f32(i32 1, <4 x float> %a)
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vcvtnq_s16_f16(<8 x half> %a) {
+; CHECK-LABEL: test_vcvtnq_s16_f16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvtn.s16.f16 q0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <8 x i16> @llvm.arm.mve.vcvtn.v8i16.v8f16(i32 0, <8 x half> %a)
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vcvtnq_s32_f32(<4 x float> %a) {
+; CHECK-LABEL: test_vcvtnq_s32_f32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvtn.s32.f32 q0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <4 x i32> @llvm.arm.mve.vcvtn.v4i32.v4f32(i32 0, <4 x float> %a)
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vcvtnq_u16_f16(<8 x half> %a) {
+; CHECK-LABEL: test_vcvtnq_u16_f16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvtn.u16.f16 q0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <8 x i16> @llvm.arm.mve.vcvtn.v8i16.v8f16(i32 1, <8 x half> %a)
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vcvtnq_u32_f32(<4 x float> %a) {
+; CHECK-LABEL: test_vcvtnq_u32_f32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvtn.u32.f32 q0, q0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call <4 x i32> @llvm.arm.mve.vcvtn.v4i32.v4f32(i32 1, <4 x float> %a)
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vcvtpq_s16_f16(<8 x half> %a) {
+; CHECK-LABEL: test_vcvtpq_s16_f16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vcvtp.s16.f16 q0, q0

[PATCH] D75429: [clangd] DefineOutline removes `override` specified from overridden methods.

2020-03-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Thanks for working on this!

A few comments on macro handling and coding style. Apart from that mostly needs 
more testing.




Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:216
+  // Remove the virtual, override and final specifiers.
+  if (FD->hasAttrs()) {
+for (auto *Attr : FD->getAttrs()) {

nit:

```
auto DelAttr = [&](const Attr* A) { /* do magic */};
if(auto *OA = FD->getAttr())
  DelAttr(OA);
if(auto *FA = ...)
```



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:219
+  if (isa(Attr) || isa(Attr)) {
+assert(Attr->getLocation().isValid());
+if (Attr->getLocation().isMacroID()) {

can you rather use `auto AttrToken = 
TB.getSpelledTokens(TB.getExpandedTokens(Attr.getRange()));` throughout this 
part.
It can provide you with token range as well.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:220
+assert(Attr->getLocation().isValid());
+if (Attr->getLocation().isMacroID()) {
+  Errors = llvm::joinErrors(

can you add some test cases for this branch ? In theory it should be ok to drop 
this if full expansion is just the attr, i.e.

```
#define FNL final
struct A { virtual void foo() FNL {} };
```

but should possibly fail in :
```
#define MACRO foo() final
struct A { virtual void MACRO {} };
```



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:236
+if (auto Err =
+QualifierInsertions.add(tooling::Replacement(SM, DelRange, 
"")))
+  Errors = llvm::joinErrors(std::move(Errors), std::move(Err));

nit: I believe `QualifierInsertions` needs to be renamed now, maybe something 
like `DeclarationCleanups` ?



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:244
+bool Any = false;
+// Clang allows duplicating virtual specifiers so check for multiple
+// occurances.

again could you please add tests checking this case?



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:246
+// occurances.
+for (const syntax::Token &Tok : TokBuf.expandedTokens(SpecRange)) {
+  if (Tok.kind() == tok::kw_virtual) {

you would rather want to go over spelled tokens, as expandedtokens might not 
exist in the source code. (it looks like the usage above, not related to this 
patch, is also broken. No need to fix that one I'll try to prepare a fix, but 
patches welcome.)

`TokBuf.spelledForExpanded(TokBuf.expandedTokens(SpecRange))`



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:247
+for (const syntax::Token &Tok : TokBuf.expandedTokens(SpecRange)) {
+  if (Tok.kind() == tok::kw_virtual) {
+assert(Tok.location().isValid());

nit: use early exits, i.e:
```
if(Tok.kind() != tok::kw_virtual)
  continue;
``



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:249
+assert(Tok.location().isValid());
+if (Tok.location().isMacroID()) {
+  Errors =

same argument as above.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:260
+CharSourceRange DelRange =
+CharSourceRange::getTokenRange(Tok.location());
+if (auto Err =

you can use `Tok.range(SM)` instead



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:2113
+struct B : A {
+  void foo() final ;
+};)cpp",

can you also add a test case for `final override`/`override final`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75429



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


[clang] 7a42bab - Reland "[DebugInfo][clang][DWARF5]: Added support for debuginfo generation for defaulted parameters

2020-03-02 Thread Sourabh Singh Tomar via cfe-commits

Author: Awanish Pandey
Date: 2020-03-02T16:45:48+05:30
New Revision: 7a42babeb83e3927e89e72a0e7e45be9d41b6c23

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

LOG: Reland "[DebugInfo][clang][DWARF5]: Added support for debuginfo generation 
for defaulted parameters
in C++ templates."

This was reverted in 802b22b5c8c30bebc1695a217478be02653c6b53 due to
missing .bc file and a chromium bot failure.
https://bugs.chromium.org/p/chromium/issues/detail?id=1057559#c1
This revision address both of them.

Summary:
This patch adds support for debuginfo generation for defaulted
parameters in clang and also extends corresponding DebugMetadata/IR to support 
this feature.

Reviewers: probinson, aprantl, dblaikie

Reviewed By: aprantl, dblaikie

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

Added: 
llvm/test/Assembler/DIDefaultTemplateParam.ll
llvm/test/Bitcode/DITemplateParameter-5.0.ll
llvm/test/Bitcode/DITemplateParameter-5.0.ll.bc

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/DIBuilder.cpp
llvm/lib/IR/DebugInfoMetadata.cpp
llvm/lib/IR/LLVMContextImpl.h
llvm/unittests/IR/MetadataTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index e171082942f6..cbf45a5cf748 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1787,18 +1787,36 @@ CGDebugInfo::CollectTemplateParams(const 
TemplateParameterList *TPList,
   for (unsigned i = 0, e = TAList.size(); i != e; ++i) {
 const TemplateArgument &TA = TAList[i];
 StringRef Name;
+bool defaultParameter = false;
 if (TPList)
   Name = TPList->getParam(i)->getName();
 switch (TA.getKind()) {
 case TemplateArgument::Type: {
   llvm::DIType *TTy = getOrCreateType(TA.getAsType(), Unit);
-  TemplateParams.push_back(
-  DBuilder.createTemplateTypeParameter(TheCU, Name, TTy));
+
+  if (TPList)
+if (auto *templateType =
+dyn_cast_or_null(TPList->getParam(i)))
+  if (templateType->hasDefaultArgument())
+defaultParameter =
+templateType->getDefaultArgument() == TA.getAsType();
+
+  TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
+  TheCU, Name, TTy, defaultParameter));
+
 } break;
 case TemplateArgument::Integral: {
   llvm::DIType *TTy = getOrCreateType(TA.getIntegralType(), Unit);
+  if (TPList && CGM.getCodeGenOpts().DwarfVersion >= 5)
+if (auto *templateType =
+dyn_cast_or_null(TPList->getParam(i)))
+  if (templateType->hasDefaultArgument())
+defaultParameter =
+templateType->getDefaultArgument()->EvaluateKnownConstInt(
+CGM.getContext()) == TA.getAsIntegral();
+
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
-  TheCU, Name, TTy,
+  TheCU, Name, TTy, defaultParameter,
   llvm::ConstantInt::get(CGM.getLLVMContext(), TA.getAsIntegral(;
 } break;
 case TemplateArgument::Declaration: {
@@ -1837,7 +1855,7 @@ CGDebugInfo::CollectTemplateParams(const 
TemplateParameterList *TPList,
 V = V->stripPointerCasts();
   }
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
-  TheCU, Name, TTy, cast_or_null(V)));
+  TheCU, Name, TTy, defaultParameter, 
cast_or_null(V)));
 } break;
 case TemplateArgument::NullPtr: {
   QualType T = TA.getNullPtrType();
@@ -1855,8 +1873,8 @@ CGDebugInfo::CollectTemplateParams(const 
TemplateParameterList *TPList,
   V = CGM.getCXXABI().EmitNullMemberPointer(MPT);
   if (!V)
 V = llvm::ConstantInt::get(CGM.Int8Ty, 0);
-  TemplateParams.push_back(
-  DBuilder.createTemplateValueParameter(TheCU, Name, TTy, V));
+  TemplateParams.push_back(DBuilder.createTemplateValueParameter(
+  TheCU, Name, TTy, defaultParameter, V));
 } break;
 case TemplateArgument::Template:
   TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
@@ -1877,7 +1895,7 @@ CGDebugInfo::CollectTemplateParams(const 
TemplateParameterList *TPList,
   assert(V && "Expression in template argument isn't constant");
   llvm::DIType *TTy = getOrCreateType(T, Unit);
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
-  TheCU, Name, TTy, V->stripPointerCasts()));
+  TheCU, Name, TTy, defaultParameter, V->stripPointerCasts()));
 } break;
 // And the

[clang] b293a72 - [analyzer][StreamChecker] Using function description objects - NFC.

2020-03-02 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2020-03-02T12:35:07+01:00
New Revision: b293a7217bae22aa8a5f5e9aab025143c0f744e8

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

LOG: [analyzer][StreamChecker] Using function description objects - NFC.

Summary:
Have a description object for the stream functions
that can store different aspects of a single stream operation.

I plan to extend the structure with other members,
for example pre-callback and index of the stream argument.

Reviewers: Szelethus, baloghadamsoftware, NoQ, martong, Charusso, xazax.hun

Reviewed By: Szelethus

Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, 
mikhail.ramalho, Szelethus, donat.nagy, dkrupp, gamesh411, Charusso, martong, 
cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index ab4c9fafae1d..64412442a528 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -49,6 +49,15 @@ struct StreamState {
   }
 };
 
+class StreamChecker;
+
+using FnCheck = std::function;
+
+struct FnDescription {
+  FnCheck EvalFn;
+};
+
 class StreamChecker : public Checker {
   mutable std::unique_ptr BT_nullfp, BT_illegalwhence,
@@ -59,35 +68,33 @@ class StreamChecker : public Checker;
-
-  CallDescriptionMap Callbacks = {
-  {{"fopen"}, &StreamChecker::evalFopen},
-  {{"freopen", 3}, &StreamChecker::evalFreopen},
-  {{"tmpfile"}, &StreamChecker::evalFopen},
-  {{"fclose", 1}, &StreamChecker::evalFclose},
+
+  CallDescriptionMap FnDescriptions = {
+  {{"fopen"}, {&StreamChecker::evalFopen}},
+  {{"freopen", 3}, {&StreamChecker::evalFreopen}},
+  {{"tmpfile"}, {&StreamChecker::evalFopen}},
+  {{"fclose", 1}, {&StreamChecker::evalFclose}},
   {{"fread", 4},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)}},
   {{"fwrite", 4},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)},
-  {{"fseek", 3}, &StreamChecker::evalFseek},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)}},
+  {{"fseek", 3}, {&StreamChecker::evalFseek}},
   {{"ftell", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"rewind", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"fgetpos", 2},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"fsetpos", 2},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"clearerr", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"feof", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"ferror", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"fileno", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   };
 
   void evalFopen(const CallEvent &Call, CheckerContext &C) const;
@@ -125,11 +132,11 @@ bool StreamChecker::evalCall(const CallEvent &Call, 
CheckerContext &C) const {
   return false;
   }
 
-  const FnCheck *Callback = Callbacks.lookup(Call);
-  if (!Callback)
+  const FnDescription *Description = FnDescriptions.lookup(Call);
+  if (!Description)
 return false;
 
-  (*Callback)(this, Call, C);
+  (Description->EvalFn)(this, Call, C);
 
   return C.isDifferent();
 }



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


[clang-tools-extra] 071002f - [clang-tidy] Copy the Ranges field from the Diagnostic when creating the ClangTidyError

2020-03-02 Thread Alexander Kornienko via cfe-commits

Author: Joe Turner
Date: 2020-03-02T12:39:16+01:00
New Revision: 071002ffdb3f13fa3006618e7ee8277a75792df5

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

LOG: [clang-tidy] Copy the Ranges field from the Diagnostic when creating the 
ClangTidyError

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 5a4021c97b0f..7a807280d9b1 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -62,6 +62,9 @@ class ClangTidyDiagnosticRenderer : public DiagnosticRenderer 
{
 }
 assert(Error.Message.Message.empty() && "Overwriting a diagnostic 
message");
 Error.Message = TidyMessage;
+for (const CharSourceRange &SourceRange : Ranges) {
+  Error.Ranges.emplace_back(Loc.getManager(), SourceRange);
+}
   }
 
   void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,



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


[clang] 842c5c7 - Fix shadow variable warning. NFC.

2020-03-02 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-03-02T11:41:20Z
New Revision: 842c5c79945ebe664bf113a108eaba495ac0b6d4

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

LOG: Fix shadow variable warning. NFC.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index ba3b14cac217..fbb397ba3cfe 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1521,8 +1521,7 @@ static llvm::Value *dumpRecord(CodeGenFunction &CGF, 
QualType RType,
 
 // We check whether we are in a recursive type
 if (CanonicalType->isRecordType()) {
-  Value *TmpRes =
-  dumpRecord(CGF, CanonicalType, FieldPtr, Align, Func, Lvl + 1);
+  TmpRes = dumpRecord(CGF, CanonicalType, FieldPtr, Align, Func, Lvl + 1);
   Res = CGF.Builder.CreateAdd(TmpRes, Res);
   continue;
 }



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


[clang] 7d594cf - [ARM] Add Cortex-M55 Support for clang and llvm

2020-03-02 Thread Luke Geeson via cfe-commits

Author: Luke Geeson
Date: 2020-03-02T11:42:26Z
New Revision: 7d594cf003d1325a1d85a339c03b720fe63de4c9

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

LOG: [ARM] Add Cortex-M55 Support for clang and llvm

This patch upstreams support for the ARM Armv8.1m cpu Cortex-M55.

In detail adding support for:

 - mcpu option in clang
 - Arm Target Features in clang
 - llvm Arm TargetParser definitions

details of the CPU can be found here:
https://developer.arm.com/ip-products/processors/cortex-m/cortex-m55

Reviewers: chill

Reviewed By: chill

Subscribers: dmgreen, kristof.beyls, hiraditya, cfe-commits,
llvm-commits

Tags: #clang, #llvm

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

Added: 


Modified: 
clang/test/CodeGen/arm-target-features.c
clang/test/Driver/arm-cortex-cpus.c
clang/test/Preprocessor/arm-target-features.c
llvm/include/llvm/Support/ARMTargetParser.def
llvm/lib/Support/Host.cpp
llvm/lib/Target/ARM/ARM.td
llvm/test/CodeGen/ARM/build-attributes.ll
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/test/CodeGen/arm-target-features.c 
b/clang/test/CodeGen/arm-target-features.c
index 11fe4e505439..160d254c1302 100644
--- a/clang/test/CodeGen/arm-target-features.c
+++ b/clang/test/CodeGen/arm-target-features.c
@@ -107,4 +107,7 @@
 // RUN: %clang_cc1 -triple thumb-linux-gnueabi -target-cpu cortex-m33 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-ARMV8M-MAIN-LINUX 
 // CHECK-ARMV8M-MAIN-LINUX: 
"target-features"="+armv8-m.main,+dsp,+fp-armv8d16sp,+fp16,+hwdiv,+thumb-mode,+vfp2sp,+vfp3d16sp,+vfp4d16sp"
 
+// RUN: %clang_cc1 -triple thumb-linux-gnueabi -target-cpu cortex-m55 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-ARMV81M-MAIN-LINUX
+// CHECK-ARMV81M-MAIN-LINUX: 
"target-features"="+armv8.1-m.main,+dsp,+fp-armv8d16,+fp-armv8d16sp,+fp16,+fp64,+fullfp16,+hwdiv,+lob,+mve,+mve.fp,+ras,+thumb-mode,+vfp2,+vfp2sp,+vfp3d16,+vfp3d16sp,+vfp4d16,+vfp4d16sp"
+
 void foo() {}

diff  --git a/clang/test/Driver/arm-cortex-cpus.c 
b/clang/test/Driver/arm-cortex-cpus.c
index bb2f4ec44943..12129e4ee25f 100644
--- a/clang/test/Driver/arm-cortex-cpus.c
+++ b/clang/test/Driver/arm-cortex-cpus.c
@@ -820,6 +820,9 @@
 // CHECK-CORTEX-M33:  "-cc1"{{.*}} "-triple" "thumbv8m.main-{{.*}} 
"-target-cpu" "cortex-m33"
 // CHECK-CORTEX-M35P:  "-cc1"{{.*}} "-triple" "thumbv8m.main-{{.*}} 
"-target-cpu" "cortex-m35p"
 
+// RUN: %clang -target arm -mcpu=cortex-m55 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-CORTEX-M55 %s
+// CHECK-CORTEX-M55:  "-cc1"{{.*}} "-triple" "thumbv8.1m.main-{{.*}} 
"-target-cpu" "cortex-m55"
+
 // == Check whether -mcpu accepts mixed-case values.
 // RUN: %clang -target arm-linux-gnueabi -mcpu=Cortex-a5 -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-CASE-INSENSITIVE-CPUV7A %s
 // RUN: %clang -target arm-linux-gnueabi -mcpu=cortex-A7 -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-CASE-INSENSITIVE-CPUV7A %s

diff  --git a/clang/test/Preprocessor/arm-target-features.c 
b/clang/test/Preprocessor/arm-target-features.c
index 401e0a41a769..3cee4d0fc2b6 100644
--- a/clang/test/Preprocessor/arm-target-features.c
+++ b/clang/test/Preprocessor/arm-target-features.c
@@ -674,6 +674,7 @@
 // RUN: %clang -target armv8m.main-none-linux-gnu -mcmse -x c -E -dM %s -o - | 
FileCheck -match-full-lines --check-prefix=V8M_CMSE %s
 // RUN: %clang -target arm-none-linux-gnu -mcpu=cortex-m33 -mcmse -x c -E -dM 
%s -o - | FileCheck -match-full-lines --check-prefix=V8M_CMSE %s
 // RUN: %clang -target arm -mcpu=cortex-m23 -mcmse -x c -E -dM %s -o - | 
FileCheck -match-full-lines --check-prefix=V8M_CMSE %s
+// RUN: %clang -target arm-none-linux-gnu -mcpu=cortex-m55 -mcmse -x c -E -dM 
%s -o - | FileCheck -match-full-lines --check-prefix=V8M_CMSE %s
 // V8M_CMSE-NOT: __ARM_FEATURE_CMSE 1
 // V8M_CMSE: #define __ARM_FEATURE_CMSE 3
 
@@ -726,6 +727,20 @@
 // M33-ALLOW-FP-INSTR: #define __ARM_FP 0x6
 // M33-ALLOW-FP-INSTR: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
 
+// Test whether predefines are as expected when targeting cortex-m55 (softfp 
FP ABI as default).
+// RUN: %clang -target arm-eabi -mcpu=cortex-m55 -x c -E -dM %s -o - | 
FileCheck -match-full-lines --check-prefix=M55 %s
+// M55: #define __ARM_ARCH 8
+// M55: #define __ARM_ARCH_8_1M_MAIN__ 1
+// M55: #define __ARM_ARCH_EXT_IDIV__ 1
+// M55-NOT: __ARM_ARCH_ISA_ARM
+// M55: #define __ARM_ARCH_ISA_THUMB 2
+// M55: #define __ARM_ARCH_PROFILE 'M'
+// M55-NOT: __ARM_FEATURE_CRC32
+// M55: #define __ARM_FEATURE_DSP 1
+// M55: #define __ARM_FEATURE_MVE 3
+// M55: #define __ARM_FP 0xe
+// M55: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+
 // Test whether predefines are as expected when targeting krait (soft FP as 
default).
 // RUN: %clang -targe

[PATCH] D75414: [clangd] Resolve driver symlinks, and look up unknown relative drivers in PATH.

2020-03-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp:96
   Mangler.adjust(Cmd);
-  EXPECT_EQ("unknown-binary", Cmd.front());
+  EXPECT_EQ("/clangd-test/fake/unknown-binary", Cmd.front());
 

i suppose you rather want `testPath("fake/unknown-binary");`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75414



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


[PATCH] D75444: [ARM,MVE] Add the `vsbciq` intrinsics.

2020-03-02 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham created this revision.
simon_tatham added reviewers: MarkMurrayARM, dmgreen, miyuki, ostannard.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya, kristof.beyls.
Herald added projects: clang, LLVM.

These are exactly parallel to the existing `vadciq` intrinsics, which
we implemented last year as part of the original MVE intrinsics
framework setup.

Just like VADC/VADCI, the MVE VSBC/VSBCI instructions deliver two
outputs, both of which the intrinsic exposes: a modified vector
register and a carry flag. So they have to be instruction-selected in
C++ rather than Tablegen. However, in this case, that's trivial: the
same C++ isel routine we already have for VADC works unchanged, and
all we have to do is to pass it a different instruction id.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75444

Files:
  clang/include/clang/Basic/arm_mve.td
  clang/test/CodeGen/arm-mve-intrinsics/vadc.c
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp
  llvm/test/CodeGen/Thumb2/mve-intrinsics/vadc.ll

Index: llvm/test/CodeGen/Thumb2/mve-intrinsics/vadc.ll
===
--- llvm/test/CodeGen/Thumb2/mve-intrinsics/vadc.ll
+++ llvm/test/CodeGen/Thumb2/mve-intrinsics/vadc.ll
@@ -96,3 +96,187 @@
   %8 = extractvalue { <4 x i32>, i32 } %4, 0
   ret <4 x i32> %8
 }
+
+declare { <4 x i32>, i32 } @llvm.arm.mve.vsbc.v4i32(<4 x i32>, <4 x i32>, i32)
+
+define arm_aapcs_vfpcc <4 x i32> @test_vsbciq_s32(<4 x i32> %a, <4 x i32> %b, i32* nocapture %carry_out) {
+; CHECK-LABEL: test_vsbciq_s32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vsbci.i32 q0, q0, q1
+; CHECK-NEXT:vmrs r1, fpscr_nzcvqc
+; CHECK-NEXT:ubfx r1, r1, #29, #1
+; CHECK-NEXT:str r1, [r0]
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call { <4 x i32>, i32 } @llvm.arm.mve.vsbc.v4i32(<4 x i32> %a, <4 x i32> %b, i32 0)
+  %1 = extractvalue { <4 x i32>, i32 } %0, 1
+  %2 = lshr i32 %1, 29
+  %3 = and i32 %2, 1
+  store i32 %3, i32* %carry_out, align 4
+  %4 = extractvalue { <4 x i32>, i32 } %0, 0
+  ret <4 x i32> %4
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vsbciq_u32(<4 x i32> %a, <4 x i32> %b, i32* nocapture %carry_out) {
+; CHECK-LABEL: test_vsbciq_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vsbci.i32 q0, q0, q1
+; CHECK-NEXT:vmrs r1, fpscr_nzcvqc
+; CHECK-NEXT:ubfx r1, r1, #29, #1
+; CHECK-NEXT:str r1, [r0]
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call { <4 x i32>, i32 } @llvm.arm.mve.vsbc.v4i32(<4 x i32> %a, <4 x i32> %b, i32 0)
+  %1 = extractvalue { <4 x i32>, i32 } %0, 1
+  %2 = lshr i32 %1, 29
+  %3 = and i32 %2, 1
+  store i32 %3, i32* %carry_out, align 4
+  %4 = extractvalue { <4 x i32>, i32 } %0, 0
+  ret <4 x i32> %4
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vsbcq_s32(<4 x i32> %a, <4 x i32> %b, i32* nocapture %carry) {
+; CHECK-LABEL: test_vsbcq_s32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:ldr r1, [r0]
+; CHECK-NEXT:lsls r1, r1, #29
+; CHECK-NEXT:vmsr fpscr_nzcvqc, r1
+; CHECK-NEXT:vsbc.i32 q0, q0, q1
+; CHECK-NEXT:vmrs r1, fpscr_nzcvqc
+; CHECK-NEXT:ubfx r1, r1, #29, #1
+; CHECK-NEXT:str r1, [r0]
+; CHECK-NEXT:bx lr
+entry:
+  %0 = load i32, i32* %carry, align 4
+  %1 = shl i32 %0, 29
+  %2 = tail call { <4 x i32>, i32 } @llvm.arm.mve.vsbc.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %1)
+  %3 = extractvalue { <4 x i32>, i32 } %2, 1
+  %4 = lshr i32 %3, 29
+  %5 = and i32 %4, 1
+  store i32 %5, i32* %carry, align 4
+  %6 = extractvalue { <4 x i32>, i32 } %2, 0
+  ret <4 x i32> %6
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vsbcq_u32(<4 x i32> %a, <4 x i32> %b, i32* nocapture %carry) {
+; CHECK-LABEL: test_vsbcq_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:ldr r1, [r0]
+; CHECK-NEXT:lsls r1, r1, #29
+; CHECK-NEXT:vmsr fpscr_nzcvqc, r1
+; CHECK-NEXT:vsbc.i32 q0, q0, q1
+; CHECK-NEXT:vmrs r1, fpscr_nzcvqc
+; CHECK-NEXT:ubfx r1, r1, #29, #1
+; CHECK-NEXT:str r1, [r0]
+; CHECK-NEXT:bx lr
+entry:
+  %0 = load i32, i32* %carry, align 4
+  %1 = shl i32 %0, 29
+  %2 = tail call { <4 x i32>, i32 } @llvm.arm.mve.vsbc.v4i32(<4 x i32> %a, <4 x i32> %b, i32 %1)
+  %3 = extractvalue { <4 x i32>, i32 } %2, 1
+  %4 = lshr i32 %3, 29
+  %5 = and i32 %4, 1
+  store i32 %5, i32* %carry, align 4
+  %6 = extractvalue { <4 x i32>, i32 } %2, 0
+  ret <4 x i32> %6
+}
+
+declare { <4 x i32>, i32 } @llvm.arm.mve.vsbc.predicated.v4i32.v4i1(<4 x i32>, <4 x i32>, <4 x i32>, i32, <4 x i1>)
+
+define arm_aapcs_vfpcc <4 x i32> @test_vsbciq_m_s32(<4 x i32> %inactive, <4 x i32> %a, <4 x i32> %b, i32* nocapture %carry_out, i16 zeroext %p) {
+; CHECK-LABEL: test_vsbciq_m_s32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmsr p0, r1
+; CHECK-NEXT:vpst
+; CHECK-NEXT:vsbcit.i32 q0, q1, q2
+; CHECK-NEXT:vmrs r1, fpscr_nzcvqc
+; CHECK-NEXT:ubfx r1, r1, #29, #1
+; CHECK-NEXT:str r1, [r0]
+; CHECK-NEXT:bx lr
+entry:
+  %0 =

[PATCH] D75443: [AST] Unpack FPFeatures bits to BinaryOperator, NFC.

2020-03-02 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
hokein edited the summary of this revision.

The stmt bit-fields is full (max 64 bits) for BinaryOperator now, adding
a new bit field (error) causes an 'static_assert(sizeof(*this) <=8)'
violation in Stmt constructor.

This patch unpacks the FPFeautres, make available bitfields for error
bit (https://reviews.llvm.org/D65591).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75443

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/Stmt.h


Index: clang/include/clang/AST/Stmt.h
===
--- clang/include/clang/AST/Stmt.h
+++ clang/include/clang/AST/Stmt.h
@@ -531,10 +531,6 @@
 
 unsigned Opc : 6;
 
-/// This is only meaningful for operations on floating point
-/// types and 0 otherwise.
-unsigned FPFeatures : 8;
-
 SourceLocation OpLoc;
   };
 
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -3439,7 +3439,9 @@
 class BinaryOperator : public Expr {
   enum { LHS, RHS, END_EXPR };
   Stmt *SubExprs[END_EXPR];
-
+  /// This is only meaningful for operations on floating point
+  /// types and 0 otherwise.
+  FPOptions FPFeatures;
 public:
   typedef BinaryOperatorKind Opcode;
 
@@ -3452,9 +3454,9 @@
(lhs->isInstantiationDependent() ||
 rhs->isInstantiationDependent()),
(lhs->containsUnexpandedParameterPack() ||
-rhs->containsUnexpandedParameterPack())) {
+rhs->containsUnexpandedParameterPack())),
+FPFeatures(FPFeatures) {
 BinaryOperatorBits.Opc = opc;
-BinaryOperatorBits.FPFeatures = FPFeatures.getInt();
 BinaryOperatorBits.OpLoc = opLoc;
 SubExprs[LHS] = lhs;
 SubExprs[RHS] = rhs;
@@ -3610,11 +3612,11 @@
   // Set the FP contractability status of this operator. Only meaningful for
   // operations on floating point types.
   void setFPFeatures(FPOptions F) {
-BinaryOperatorBits.FPFeatures = F.getInt();
+FPFeatures = F;
   }
 
   FPOptions getFPFeatures() const {
-return FPOptions(BinaryOperatorBits.FPFeatures);
+return FPFeatures;
   }
 
   // Get the FP contractability status of this operator. Only meaningful for
@@ -3637,9 +3639,9 @@
(lhs->isInstantiationDependent() ||
 rhs->isInstantiationDependent()),
(lhs->containsUnexpandedParameterPack() ||
-rhs->containsUnexpandedParameterPack())) {
+rhs->containsUnexpandedParameterPack())),
+FPFeatures(FPFeatures) {
 BinaryOperatorBits.Opc = opc;
-BinaryOperatorBits.FPFeatures = FPFeatures.getInt();
 BinaryOperatorBits.OpLoc = opLoc;
 SubExprs[LHS] = lhs;
 SubExprs[RHS] = rhs;


Index: clang/include/clang/AST/Stmt.h
===
--- clang/include/clang/AST/Stmt.h
+++ clang/include/clang/AST/Stmt.h
@@ -531,10 +531,6 @@
 
 unsigned Opc : 6;
 
-/// This is only meaningful for operations on floating point
-/// types and 0 otherwise.
-unsigned FPFeatures : 8;
-
 SourceLocation OpLoc;
   };
 
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -3439,7 +3439,9 @@
 class BinaryOperator : public Expr {
   enum { LHS, RHS, END_EXPR };
   Stmt *SubExprs[END_EXPR];
-
+  /// This is only meaningful for operations on floating point
+  /// types and 0 otherwise.
+  FPOptions FPFeatures;
 public:
   typedef BinaryOperatorKind Opcode;
 
@@ -3452,9 +3454,9 @@
(lhs->isInstantiationDependent() ||
 rhs->isInstantiationDependent()),
(lhs->containsUnexpandedParameterPack() ||
-rhs->containsUnexpandedParameterPack())) {
+rhs->containsUnexpandedParameterPack())),
+FPFeatures(FPFeatures) {
 BinaryOperatorBits.Opc = opc;
-BinaryOperatorBits.FPFeatures = FPFeatures.getInt();
 BinaryOperatorBits.OpLoc = opLoc;
 SubExprs[LHS] = lhs;
 SubExprs[RHS] = rhs;
@@ -3610,11 +3612,11 @@
   // Set the FP contractability status of this operator. Only meaningful for
   // operations on floating point types.
   void setFPFeatures(FPOptions F) {
-BinaryOperatorBits.FPFeatures = F.getInt();
+FPFeatures = F;
   }
 
   FPOptions getFPFeatures() const {
-return FPOptions(BinaryOperatorBits.FPFeatures);
+return FPFeatures;
   }
 
   // Get the FP contractability status of this operator. Only meaningful for
@@ -3637,9 +3639,9 @@
(lhs->isInstantiationDependent() ||
 rhs->isInstantiationDependent()),
(lhs->containsUnexpandedParameterPack() ||
-rhs->containsUnexpandedParameterPack())) {
+rhs->containsUnexpandedParameterPac

[PATCH] D75414: [clangd] Resolve driver symlinks, and look up unknown relative drivers in PATH.

2020-03-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:145
+// Otherwise try to look it up on PATH. This won't change basename.
+if (auto Absolute = llvm::sys::findProgramByName(Driver))
+  Driver = Storage = *Absolute;

`findProgramByName` is evil :/ it is not guaranteed to return an absolute path.

for example if you've got `toolchain/clang` as your argv[0] (not sure if it is 
possible, but it is a non-absoltue path...) then it will return the argument 
directly, even though it is not an absolute path :(.



Comment at: clang-tools-extra/clangd/CompileCommands.cpp:156
+  llvm::SmallString<256> Resolved;
+  if (llvm::sys::fs::real_path(Driver, Resolved))
+return Driver.str();

what about taking a VFS instead and calling `VFS.getRealPath`?

It should make testing easier and commandmangler vfs friendly.



Comment at: clang-tools-extra/clangd/CompileCommands.h:48
   CommandMangler() = default;
+  Memoize> CachedResolveDriver;
 };

maybe just `ResolvedDriver`?



Comment at: clang-tools-extra/clangd/QueryDriverDatabase.cpp:286
+  // Caches includes extracted from a driver. Key is driver:lang.
+  Memoize>> DriverToIncludesCache;
+  llvm::Regex QueryDriverRegex;

nit: `QueriedDrivers`



Comment at: clang-tools-extra/clangd/Threading.h:154
+  template 
+  typename Container::mapped_type operator()(T &&Key, Func Compute) const {
+{

what about an explicit `getOrCreate` method instead?



Comment at: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp:140
+  std::vector Cmd = {(TempDir + "/bin/foo").str(), "foo.cc"};
+  Mangler.adjust(Cmd);
+  // Directory based on resolved symlink, basename preserved.

irrelevant to the patch:

any reason for `adjust` to mutate its parameter in-place instead of returning 
it(I believe callers can do `std::move(Cmd)` if need be) ?



Comment at: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp:144
+
+  // Set PATH to point to temp/bin so we can find 'foo' on it.
+  ASSERT_TRUE(::getenv("PATH"));

can we rather move the `ifdef` here the rest previous part should hopefully 
work on other platforms as well (at least after VFS)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75414



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


[PATCH] D74966: [PATCH] [ARM] Add Cortex-M55 Support for clang and llvm

2020-03-02 Thread Luke Geeson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7d594cf003d1: [ARM] Add Cortex-M55 Support for clang and 
llvm (authored by LukeGeeson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74966

Files:
  clang/test/CodeGen/arm-target-features.c
  clang/test/Driver/arm-cortex-cpus.c
  clang/test/Preprocessor/arm-target-features.c
  llvm/include/llvm/Support/ARMTargetParser.def
  llvm/lib/Support/Host.cpp
  llvm/lib/Target/ARM/ARM.td
  llvm/test/CodeGen/ARM/build-attributes.ll
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -290,6 +290,11 @@
  ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "8-M.Mainline"));
   EXPECT_TRUE(testARMCPU("cortex-m35p", "armv8-m.main", "fpv5-sp-d16",
  ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "8-M.Mainline"));
+  EXPECT_TRUE(testARMCPU("cortex-m55", "armv8.1-m.main", "fp-armv8-fullfp16-d16",
+ ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP | ARM::AEK_SIMD |
+ ARM::AEK_FP | ARM::AEK_RAS | ARM::AEK_LOB |
+ ARM::AEK_FP16,
+"8.1-M.Mainline"));
   EXPECT_TRUE(testARMCPU("iwmmxt", "iwmmxt", "none",
  ARM::AEK_NONE, "iwmmxt"));
   EXPECT_TRUE(testARMCPU("xscale", "xscale", "none",
@@ -299,7 +304,7 @@
  "7-S"));
 }
 
-static constexpr unsigned NumARMCPUArchs = 85;
+static constexpr unsigned NumARMCPUArchs = 86;
 
 TEST(TargetParserTest, testARMCPUArchList) {
   SmallVector List;
Index: llvm/test/CodeGen/ARM/build-attributes.ll
===
--- llvm/test/CodeGen/ARM/build-attributes.ll
+++ llvm/test/CodeGen/ARM/build-attributes.ll
@@ -233,6 +233,7 @@
 ; RUN: llc < %s -mtriple=thumbv8.1m.main-none-none-eabi | FileCheck %s --check-prefix=ARMv81M-MAIN
 ; RUN: llc < %s -mtriple=thumbv8.1m.main-none-none-eabi -mattr=+mve | FileCheck %s --check-prefix=ARMv81M-MAIN-MVEINT
 ; RUN: llc < %s -mtriple=thumbv8.1m.main-none-none-eabi -mattr=+mve.fp | FileCheck %s --check-prefix=ARMv81M-MAIN-MVEFP
+; RUN: llc < %s -mtriple=arm-none-none-eabi -mcpu=cortex-m55 | FileCheck %s --check-prefix=CORTEX-M55
 
 ; CPU-SUPPORTED-NOT: is not a recognized processor for this target
 
@@ -1722,6 +1723,28 @@
 ; ARMv81M-MAIN-MVEINT: .eabi_attribute 48, 1 @ Tag_MVE_arch
 ; ARMv81M-MAIN-MVEFP: .eabi_attribute 6, 21 @ Tag_CPU_arch
 ; ARMv81M-MAIN-MVEFP: .eabi_attribute 48, 2 @ Tag_MVE_arch
+
+; CORTEX-M55: .cpu cortex-m55
+; CORTEX-M55: .eabi_attribute 6, 21
+; CORTEX-M55: .eabi_attribute 7, 77
+; CORTEX-M55: .eabi_attribute 8, 0
+; CORTEX-M55: .eabi_attribute 9, 3
+; CORTEX-M55: .fpu fpv5-d16
+; CORTEX-M55: .eabi_attribute 36, 1
+; CORTEX-M55-NOT: .eabi_attribute 44
+; CORTEX-M55: .eabi_attribute 46, 1
+; CORTEX-M55: .eabi_attribute 34, 1
+; CORTEX-M55: .eabi_attribute 17, 1
+; CORTEX-M55-NOT: .eabi_attribute 19
+; CORTEX-M55: .eabi_attribute 20, 1
+; CORTEX-M55: .eabi_attribute 21, 1
+; CORTEX-M55: .eabi_attribute 23, 3
+; CORTEX-M55: .eabi_attribute 24, 1
+; CORTEX-M55: .eabi_attribute 25, 1
+; CORTEX-M55-NOT: .eabi_attribute 28
+; CORTEX-M55: .eabi_attribute 38, 1
+; CORTEX-M55: .eabi_attribute 14, 0
+
 define i32 @f(i64 %z) {
 ret i32 0
 }
Index: llvm/lib/Target/ARM/ARM.td
===
--- llvm/lib/Target/ARM/ARM.td
+++ llvm/lib/Target/ARM/ARM.td
@@ -1124,6 +1124,14 @@
  FeatureUseMISched,
  FeatureHasNoBranchPredictor]>;
 
+def : ProcessorModel<"cortex-m55", CortexM4Model,  [ARMv81mMainline,
+ FeatureDSP,
+ FeatureFPARMv8_D16,
+ FeatureUseMISched,
+ FeatureHasNoBranchPredictor,
+ FeaturePrefLoopAlign32,
+ FeatureHasSlowFPVMLx,
+ HasMVEFloatOps]>;
 
 def : ProcNoItin<"cortex-a32",   [ARMv8a,
  FeatureHWDivThumb,
Index: llvm/lib/Support/Host.cpp
===
--- llvm/lib/Support/Host.cpp
+++ llvm/lib/Support/Host.cpp
@@ -192,6 +192,7 @@
 .Case("0xc20", "cortex-m0")
 .Case("0xc23", "cortex-m3")
 .Case("0xc24", "cortex-m4")
+.C

[PATCH] D68887: [clang-tidy] Copy the Ranges field from the Diagnostic when creating the ClangTidyError

2020-03-02 Thread Alexander Kornienko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG071002ffdb3f: [clang-tidy] Copy the Ranges field from the 
Diagnostic when creating the… (authored by compositeprimes, committed by 
alexfh).

Changed prior to commit:
  https://reviews.llvm.org/D68887?vs=245915&id=247593#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68887

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp


Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -62,6 +62,9 @@
 }
 assert(Error.Message.Message.empty() && "Overwriting a diagnostic 
message");
 Error.Message = TidyMessage;
+for (const CharSourceRange &SourceRange : Ranges) {
+  Error.Ranges.emplace_back(Loc.getManager(), SourceRange);
+}
   }
 
   void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,


Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -62,6 +62,9 @@
 }
 assert(Error.Message.Message.empty() && "Overwriting a diagnostic message");
 Error.Message = TidyMessage;
+for (const CharSourceRange &SourceRange : Ranges) {
+  Error.Ranges.emplace_back(Loc.getManager(), SourceRange);
+}
   }
 
   void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73462: [dwarf-5] Support DebugInfo for Defaulted parameters for C++ templates

2020-03-02 Thread Sourabh Singh Tomar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7a42babeb83e: Reland "[DebugInfo][clang][DWARF5]: Added 
support for debuginfo generation for… (authored by awpandey, committed by 
SouraVX).

Changed prior to commit:
  https://reviews.llvm.org/D73462?vs=247557&id=247592#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73462

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/MetadataLoader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/test/Assembler/DIDefaultTemplateParam.ll
  llvm/test/Bitcode/DITemplateParameter-5.0.ll
  llvm/test/Bitcode/DITemplateParameter-5.0.ll.bc
  llvm/unittests/IR/MetadataTest.cpp

Index: llvm/unittests/IR/MetadataTest.cpp
===
--- llvm/unittests/IR/MetadataTest.cpp
+++ llvm/unittests/IR/MetadataTest.cpp
@@ -2076,17 +2076,19 @@
 TEST_F(DITemplateTypeParameterTest, get) {
   StringRef Name = "template";
   DIType *Type = getBasicType("basic");
+  bool defaulted = false;
 
-  auto *N = DITemplateTypeParameter::get(Context, Name, Type);
+  auto *N = DITemplateTypeParameter::get(Context, Name, Type, defaulted);
 
   EXPECT_EQ(dwarf::DW_TAG_template_type_parameter, N->getTag());
   EXPECT_EQ(Name, N->getName());
   EXPECT_EQ(Type, N->getType());
-  EXPECT_EQ(N, DITemplateTypeParameter::get(Context, Name, Type));
+  EXPECT_EQ(N, DITemplateTypeParameter::get(Context, Name, Type, defaulted));
 
-  EXPECT_NE(N, DITemplateTypeParameter::get(Context, "other", Type));
-  EXPECT_NE(N,
-DITemplateTypeParameter::get(Context, Name, getBasicType("other")));
+  EXPECT_NE(N, DITemplateTypeParameter::get(Context, "other", Type, defaulted));
+  EXPECT_NE(N, DITemplateTypeParameter::get(Context, Name,
+getBasicType("other"), defaulted));
+  EXPECT_NE(N, DITemplateTypeParameter::get(Context, Name, Type, true));
 
   TempDITemplateTypeParameter Temp = N->clone();
   EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
@@ -2098,24 +2100,31 @@
   unsigned Tag = dwarf::DW_TAG_template_value_parameter;
   StringRef Name = "template";
   DIType *Type = getBasicType("basic");
+  bool defaulted = false;
   Metadata *Value = getConstantAsMetadata();
 
-  auto *N = DITemplateValueParameter::get(Context, Tag, Name, Type, Value);
+  auto *N =
+  DITemplateValueParameter::get(Context, Tag, Name, Type, defaulted, Value);
   EXPECT_EQ(Tag, N->getTag());
   EXPECT_EQ(Name, N->getName());
   EXPECT_EQ(Type, N->getType());
   EXPECT_EQ(Value, N->getValue());
-  EXPECT_EQ(N, DITemplateValueParameter::get(Context, Tag, Name, Type, Value));
+  EXPECT_EQ(N, DITemplateValueParameter::get(Context, Tag, Name, Type,
+ defaulted, Value));
 
   EXPECT_NE(N, DITemplateValueParameter::get(
Context, dwarf::DW_TAG_GNU_template_template_param, Name,
-   Type, Value));
-  EXPECT_NE(N,
-DITemplateValueParameter::get(Context, Tag, "other", Type, Value));
+   Type, defaulted, Value));
+  EXPECT_NE(N, DITemplateValueParameter::get(Context, Tag, "other", Type,
+ defaulted, Value));
   EXPECT_NE(N, DITemplateValueParameter::get(Context, Tag, Name,
- getBasicType("other"), Value));
-  EXPECT_NE(N, DITemplateValueParameter::get(Context, Tag, Name, Type,
- getConstantAsMetadata()));
+ getBasicType("other"), defaulted,
+ Value));
+  EXPECT_NE(N,
+DITemplateValueParameter::get(Context, Tag, Name, Type, defaulted,
+  getConstantAsMetadata()));
+  EXPECT_NE(
+  N, DITemplateValueParameter::get(Context, Tag, Name, Type, true, Value));
 
   TempDITemplateValueParameter Temp = N->clone();
   EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Index: llvm/test/Bitcode/DITemplateParameter-5.0.ll
===
--- /dev/null
+++ llvm/test/Bitcode/DITemplateParameter-5.0.ll
@@ -0,0 +1,69 @@
+; RUN: llvm-dis -o - %s.bc | FileCheck %s
+
+; ModuleID = '/dir/test.cpp'
+source_filename = "test.cpp"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%class.foo = type { i8 }
+%class.foo.0 = type { i8 }
+; Function Attrs: noinline norecurse nounwind optnone uwtable
+define dso_local i32 @main() #0 !dbg !7 {
+entry:
+  %retval =

[PATCH] D75368: [clang-format] Handle ?. ?? and ?[ as C# tokens

2020-03-02 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: clang/include/clang/Basic/TokenKinds.def:237
+// C# support
+PUNCTUATOR(questionquestion,  "??")
+PUNCTUATOR(questionlsquare,   "?[")

I think this is not a good place to add these.
I think these definitions are generally for languages clang itself supports 
(compiling)
This could have unexpected ripple effects in unrelated parts of the clang.
Could you try to handle these somehow in lib/Format/FormatTokenLexer?
That's where the clang-format has some glue / heuristics for handling other 
languages syntax.



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

https://reviews.llvm.org/D75368



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


[PATCH] D75445: [ARM,MVE] Add the `vshlcq` intrinsics.

2020-03-02 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham created this revision.
simon_tatham added reviewers: MarkMurrayARM, dmgreen, miyuki, ostannard.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya, kristof.beyls.
Herald added projects: clang, LLVM.

The VSHLC instruction performs a left shift of a whole vector register
by an immediate shift count up to 32, shifting in new bits at the low
end from a GPR and delivering the shifted-out bits from the high end
back into the same GPR.

Since the instruction produces two outputs (the shifted vector
register and the output GPR of shifted-out bits), it has to be
instruction-selected in C++ rather than Tablegen.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75445

Files:
  clang/include/clang/Basic/arm_mve.td
  clang/test/CodeGen/arm-mve-intrinsics/vshlc.c
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp
  llvm/test/CodeGen/Thumb2/mve-intrinsics/vshlc.ll

Index: llvm/test/CodeGen/Thumb2/mve-intrinsics/vshlc.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/mve-intrinsics/vshlc.ll
@@ -0,0 +1,228 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=thumbv8.1m.main -mattr=+mve -verify-machineinstrs -o - %s | FileCheck %s
+
+define arm_aapcs_vfpcc <16 x i8> @test_vshlcq_s8(<16 x i8> %a, i32* nocapture %b) {
+; CHECK-LABEL: test_vshlcq_s8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:ldr r1, [r0]
+; CHECK-NEXT:vshlc q0, r1, #18
+; CHECK-NEXT:str r1, [r0]
+; CHECK-NEXT:bx lr
+entry:
+  %0 = load i32, i32* %b, align 4
+  %1 = tail call { i32, <16 x i8> } @llvm.arm.mve.vshlc.v16i8(<16 x i8> %a, i32 %0, i32 18)
+  %2 = extractvalue { i32, <16 x i8> } %1, 0
+  store i32 %2, i32* %b, align 4
+  %3 = extractvalue { i32, <16 x i8> } %1, 1
+  ret <16 x i8> %3
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vshlcq_s16(<8 x i16> %a, i32* nocapture %b) {
+; CHECK-LABEL: test_vshlcq_s16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:ldr r1, [r0]
+; CHECK-NEXT:vshlc q0, r1, #16
+; CHECK-NEXT:str r1, [r0]
+; CHECK-NEXT:bx lr
+entry:
+  %0 = load i32, i32* %b, align 4
+  %1 = tail call { i32, <8 x i16> } @llvm.arm.mve.vshlc.v8i16(<8 x i16> %a, i32 %0, i32 16)
+  %2 = extractvalue { i32, <8 x i16> } %1, 0
+  store i32 %2, i32* %b, align 4
+  %3 = extractvalue { i32, <8 x i16> } %1, 1
+  ret <8 x i16> %3
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vshlcq_s32(<4 x i32> %a, i32* nocapture %b) {
+; CHECK-LABEL: test_vshlcq_s32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:ldr r1, [r0]
+; CHECK-NEXT:vshlc q0, r1, #4
+; CHECK-NEXT:str r1, [r0]
+; CHECK-NEXT:bx lr
+entry:
+  %0 = load i32, i32* %b, align 4
+  %1 = tail call { i32, <4 x i32> } @llvm.arm.mve.vshlc.v4i32(<4 x i32> %a, i32 %0, i32 4)
+  %2 = extractvalue { i32, <4 x i32> } %1, 0
+  store i32 %2, i32* %b, align 4
+  %3 = extractvalue { i32, <4 x i32> } %1, 1
+  ret <4 x i32> %3
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_vshlcq_u8(<16 x i8> %a, i32* nocapture %b) {
+; CHECK-LABEL: test_vshlcq_u8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:ldr r1, [r0]
+; CHECK-NEXT:vshlc q0, r1, #17
+; CHECK-NEXT:str r1, [r0]
+; CHECK-NEXT:bx lr
+entry:
+  %0 = load i32, i32* %b, align 4
+  %1 = tail call { i32, <16 x i8> } @llvm.arm.mve.vshlc.v16i8(<16 x i8> %a, i32 %0, i32 17)
+  %2 = extractvalue { i32, <16 x i8> } %1, 0
+  store i32 %2, i32* %b, align 4
+  %3 = extractvalue { i32, <16 x i8> } %1, 1
+  ret <16 x i8> %3
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vshlcq_u16(<8 x i16> %a, i32* nocapture %b) {
+; CHECK-LABEL: test_vshlcq_u16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:ldr r1, [r0]
+; CHECK-NEXT:vshlc q0, r1, #17
+; CHECK-NEXT:str r1, [r0]
+; CHECK-NEXT:bx lr
+entry:
+  %0 = load i32, i32* %b, align 4
+  %1 = tail call { i32, <8 x i16> } @llvm.arm.mve.vshlc.v8i16(<8 x i16> %a, i32 %0, i32 17)
+  %2 = extractvalue { i32, <8 x i16> } %1, 0
+  store i32 %2, i32* %b, align 4
+  %3 = extractvalue { i32, <8 x i16> } %1, 1
+  ret <8 x i16> %3
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vshlcq_u32(<4 x i32> %a, i32* nocapture %b) {
+; CHECK-LABEL: test_vshlcq_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:ldr r1, [r0]
+; CHECK-NEXT:vshlc q0, r1, #20
+; CHECK-NEXT:str r1, [r0]
+; CHECK-NEXT:bx lr
+entry:
+  %0 = load i32, i32* %b, align 4
+  %1 = tail call { i32, <4 x i32> } @llvm.arm.mve.vshlc.v4i32(<4 x i32> %a, i32 %0, i32 20)
+  %2 = extractvalue { i32, <4 x i32> } %1, 0
+  store i32 %2, i32* %b, align 4
+  %3 = extractvalue { i32, <4 x i32> } %1, 1
+  ret <4 x i32> %3
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_vshlcq_m_s8(<16 x i8> %a, i32* nocapture %b, i16 zeroext %p) {
+; CHECK-LABEL: test_vshlcq_m_s8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmsr p0, r1
+; CHECK-NEXT:ldr r1, [r0]
+; CHECK-NEXT:vpst
+; CHECK-NEXT:vshlct q0, r1, #29
+; CHECK-NEXT:s

[PATCH] D75158: [analyzer][StreamChecker] Using function description objects - NFC.

2020-03-02 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb293a7217bae: [analyzer][StreamChecker] Using function 
description objects - NFC. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75158

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -49,6 +49,15 @@
   }
 };
 
+class StreamChecker;
+
+using FnCheck = std::function;
+
+struct FnDescription {
+  FnCheck EvalFn;
+};
+
 class StreamChecker : public Checker {
   mutable std::unique_ptr BT_nullfp, BT_illegalwhence,
@@ -59,35 +68,33 @@
   void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
 
 private:
-  using FnCheck = std::function;
-
-  CallDescriptionMap Callbacks = {
-  {{"fopen"}, &StreamChecker::evalFopen},
-  {{"freopen", 3}, &StreamChecker::evalFreopen},
-  {{"tmpfile"}, &StreamChecker::evalFopen},
-  {{"fclose", 1}, &StreamChecker::evalFclose},
+
+  CallDescriptionMap FnDescriptions = {
+  {{"fopen"}, {&StreamChecker::evalFopen}},
+  {{"freopen", 3}, {&StreamChecker::evalFreopen}},
+  {{"tmpfile"}, {&StreamChecker::evalFopen}},
+  {{"fclose", 1}, {&StreamChecker::evalFclose}},
   {{"fread", 4},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)}},
   {{"fwrite", 4},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)},
-  {{"fseek", 3}, &StreamChecker::evalFseek},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)}},
+  {{"fseek", 3}, {&StreamChecker::evalFseek}},
   {{"ftell", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"rewind", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"fgetpos", 2},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"fsetpos", 2},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"clearerr", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"feof", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"ferror", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   {{"fileno", 1},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
   };
 
   void evalFopen(const CallEvent &Call, CheckerContext &C) const;
@@ -125,11 +132,11 @@
   return false;
   }
 
-  const FnCheck *Callback = Callbacks.lookup(Call);
-  if (!Callback)
+  const FnDescription *Description = FnDescriptions.lookup(Call);
+  if (!Description)
 return false;
 
-  (*Callback)(this, Call, C);
+  (Description->EvalFn)(this, Call, C);
 
   return C.isDifferent();
 }


Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -49,6 +49,15 @@
   }
 };
 
+class StreamChecker;
+
+using FnCheck = std::function;
+
+struct FnDescription {
+  FnCheck EvalFn;
+};
+
 class StreamChecker : public Checker {
   mutable std::unique_ptr BT_nullfp, BT_illegalwhence,
@@ -59,35 +68,33 @@
   void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
 
 private:
-  using FnCheck = std::function;
-
-  CallDescriptionMap Callbacks = {
-  {{"fopen"}, &StreamChecker::evalFopen},
-  {{"freopen", 3}, &StreamChecker::evalFreopen},
-  {{"tmpfile"}, &StreamChecker::evalFopen},
-  {{"fclose", 1}, &StreamChecker::evalFclose},
+
+  CallDescriptionMap FnDescriptions = {
+  {{"fopen"}, {&StreamChecker::evalFopen}},
+  {{"freopen", 3}, {&StreamChecker::evalFreopen}},
+  {{"tmpfile"}, {&StreamChecker::evalFopen}},
+  {{"fclose", 1}, {&StreamChecker::evalFclose}},
   {{"fread", 4},
-   std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)},
+   {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)}},
   {{"fwrite", 4},
-   std

[PATCH] D75368: [clang-format] Handle ?. ?? and ?[ as C# tokens

2020-03-02 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe planned changes to this revision.
jbcoe added a comment.

Handle ??, ?. and ?[ in lib/Format/FormatTokenLexer.


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

https://reviews.llvm.org/D75368



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


[clang-tools-extra] c24c89d - [clangd] Get rid of unnecessary source transformations in locateMacroAt

2020-03-02 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-03-02T13:31:12+01:00
New Revision: c24c89d6f0f55bb95995b4f5587c791ac8d738fc

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

LOG: [clangd] Get rid of unnecessary source transformations in locateMacroAt

Summary:
All callers are already passing spelling locations to locateMacroAt.
Also there's no point at looking at macro expansion for figuring out undefs as
it is forbidden to have PP directives inside macro bodies.
Also fixes a bug when the previous sourcelocation is unavailable.

Reviewers: sammccall, hokein

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/clangd/SourceCode.h
clang-tools-extra/clangd/unittests/SourceCodeTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/SourceCode.cpp 
b/clang-tools-extra/clangd/SourceCode.cpp
index 3feddd1df24b..2c4338dce7c7 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -893,10 +893,11 @@ llvm::StringSet<> collectWords(llvm::StringRef Content) {
 
 llvm::Optional locateMacroAt(SourceLocation Loc,
Preprocessor &PP) {
+  assert(Loc.isFileID());
   const auto &SM = PP.getSourceManager();
   const auto &LangOpts = PP.getLangOpts();
   Token Result;
-  if (Lexer::getRawToken(SM.getSpellingLoc(Loc), Result, SM, LangOpts, false))
+  if (Lexer::getRawToken(Loc, Result, SM, LangOpts, false))
 return None;
   if (Result.is(tok::raw_identifier))
 PP.LookUpIdentifierInfo(Result);
@@ -904,14 +905,12 @@ llvm::Optional locateMacroAt(SourceLocation 
Loc,
   if (!IdentifierInfo || !IdentifierInfo->hadMacroDefinition())
 return None;
 
-  std::pair DecLoc = SM.getDecomposedExpansionLoc(Loc);
   // Get the definition just before the searched location so that a macro
-  // referenced in a '#undef MACRO' can still be found.
-  SourceLocation BeforeSearchedLocation =
-  SM.getMacroArgExpandedLocation(SM.getLocForStartOfFile(DecLoc.first)
- .getLocWithOffset(DecLoc.second - 1));
-  MacroDefinition MacroDef =
-  PP.getMacroDefinitionAtLoc(IdentifierInfo, BeforeSearchedLocation);
+  // referenced in a '#undef MACRO' can still be found. Note that we only do
+  // that if Loc is not pointing at start of file.
+  if (SM.getLocForStartOfFile(SM.getFileID(Loc)) != Loc)
+Loc = Loc.getLocWithOffset(-1);
+  MacroDefinition MacroDef = PP.getMacroDefinitionAtLoc(IdentifierInfo, Loc);
   if (auto *MI = MacroDef.getMacroInfo())
 return DefinedMacro{IdentifierInfo->getName(), MI};
   return None;

diff  --git a/clang-tools-extra/clangd/SourceCode.h 
b/clang-tools-extra/clangd/SourceCode.h
index 137a6f664ed9..32fe9c6c54b3 100644
--- a/clang-tools-extra/clangd/SourceCode.h
+++ b/clang-tools-extra/clangd/SourceCode.h
@@ -281,7 +281,8 @@ struct DefinedMacro {
   llvm::StringRef Name;
   const MacroInfo *Info;
 };
-/// Gets the macro at a specified \p Loc.
+/// Gets the macro at a specified \p Loc. It must be a spelling location and
+/// point to the beginning of identifier.
 llvm::Optional locateMacroAt(SourceLocation Loc,
Preprocessor &PP);
 

diff  --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp 
b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
index 305e07d7c0c3..7d614785a11d 100644
--- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -436,6 +436,20 @@ TEST(SourceCodeTests, GetMacros) {
   EXPECT_THAT(*Result, MacroName("MACRO"));
 }
 
+TEST(SourceCodeTests, WorksAtBeginOfFile) {
+  Annotations Code("^MACRO");
+  TestTU TU = TestTU::withCode(Code.code());
+  TU.HeaderCode = "#define MACRO int x;";
+  auto AST = TU.build();
+  auto CurLoc = sourceLocationInMainFile(AST.getSourceManager(), Code.point());
+  ASSERT_TRUE(bool(CurLoc));
+  const auto *Id = syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
+  ASSERT_TRUE(Id);
+  auto Result = locateMacroAt(Id->location(), AST.getPreprocessor());
+  ASSERT_TRUE(Result);
+  EXPECT_THAT(*Result, MacroName("MACRO"));
+}
+
 TEST(SourceCodeTests, IsInsideMainFile){
   TestTU TU;
   TU.HeaderCode = R"cpp(



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


[clang-tools-extra] 3ae2fc7 - [clangd] Get rid of lexer usage in locateMacroAt

2020-03-02 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-03-02T13:31:12+01:00
New Revision: 3ae2fc7a8bb3ee074d9fb9c0f235052b86c37aaf

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

LOG: [clangd] Get rid of lexer usage in locateMacroAt

Reviewers: sammccall, hokein

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/clangd/SourceCode.h
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
clang-tools-extra/clangd/unittests/SourceCodeTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index ce0c6d11cada..5796657a5800 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -532,32 +532,37 @@ llvm::Optional getHover(ParsedAST &AST, 
Position Pos,
   }
   auto TokensTouchingCursor =
   syntax::spelledTokensTouching(*CurLoc, AST.getTokens());
+  // Early exit if there were no tokens around the cursor.
   if (TokensTouchingCursor.empty())
 return llvm::None;
 
-  // In general we prefer the touching token that works over the one that
-  // doesn't, see SelectionTree::create(). The following locations are used 
only
-  // for triggering on macros and auto/decltype, so simply choosing the lone
-  // identifier-or-keyword token is equivalent.
+  // To be used as a backup for highlighting the selected token.
   SourceLocation IdentLoc;
-  SourceLocation AutoLoc;
+  llvm::Optional HI;
+  // Macros and deducedtype only works on identifiers and auto/decltype 
keywords
+  // respectively. Therefore they are only trggered on whichever works for 
them,
+  // similar to SelectionTree::create().
   for (const auto &Tok : TokensTouchingCursor) {
-if (Tok.kind() == tok::identifier)
+if (Tok.kind() == tok::identifier) {
   IdentLoc = Tok.location();
-if (Tok.kind() == tok::kw_auto || Tok.kind() == tok::kw_decltype)
-  AutoLoc = Tok.location();
+  if (auto M = locateMacroAt(Tok, AST.getPreprocessor())) {
+HI = getHoverContents(*M, AST);
+HI->SymRange = getTokenRange(AST.getSourceManager(), AST.getLangOpts(),
+ Tok.location());
+break;
+  }
+} else if (Tok.kind() == tok::kw_auto || Tok.kind() == tok::kw_decltype) {
+  if (auto Deduced = getDeducedType(AST.getASTContext(), Tok.location())) {
+HI = getHoverContents(*Deduced, AST.getASTContext(), Index);
+HI->SymRange = getTokenRange(AST.getSourceManager(), AST.getLangOpts(),
+ Tok.location());
+break;
+  }
+}
   }
 
-  llvm::Optional HI;
-  if (auto Deduced = getDeducedType(AST.getASTContext(), AutoLoc)) {
-HI = getHoverContents(*Deduced, AST.getASTContext(), Index);
-HI->SymRange =
-getTokenRange(AST.getSourceManager(), AST.getLangOpts(), AutoLoc);
-  } else if (auto M = locateMacroAt(IdentLoc, AST.getPreprocessor())) {
-HI = getHoverContents(*M, AST);
-HI->SymRange =
-getTokenRange(AST.getSourceManager(), AST.getLangOpts(), IdentLoc);
-  } else {
+  // If it wasn't auto/decltype or macro, look for decls and expressions.
+  if (!HI) {
 auto Offset = SM.getFileOffset(*CurLoc);
 // Editors send the position on the left of the hovered character.
 // So our selection tree should be biased right. (Tested with VSCode).

diff  --git a/clang-tools-extra/clangd/SourceCode.cpp 
b/clang-tools-extra/clangd/SourceCode.cpp
index 2c4338dce7c7..79d027def4bc 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -891,17 +891,12 @@ llvm::StringSet<> collectWords(llvm::StringRef Content) {
   return Result;
 }
 
-llvm::Optional locateMacroAt(SourceLocation Loc,
+llvm::Optional locateMacroAt(const syntax::Token &SpelledTok,
Preprocessor &PP) {
+  SourceLocation Loc = SpelledTok.location();
   assert(Loc.isFileID());
   const auto &SM = PP.getSourceManager();
-  const auto &LangOpts = PP.getLangOpts();
-  Token Result;
-  if (Lexer::getRawToken(Loc, Result, SM, LangOpts, false))
-return None;
-  if (Result.is(tok::raw_identifier))
-PP.LookUpIdentifierInfo(Result);
-  IdentifierInfo *IdentifierInfo = Result.getIdentifierInfo();
+  IdentifierInfo *IdentifierInfo = PP.getIdentifierInfo(SpelledTok.text(SM));
   if (!IdentifierInfo || !IdentifierInfo->hadMacroDefinition())
 return None;
 

diff  --git a/clang-tools-extra/clangd/SourceCode.h 
b/clang-tools-extra/clangd/SourceC

[PATCH] D75446: [clang][Syntax] Handle macro arguments in spelledForExpanded

2020-03-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
kadircet added a child revision: D75447: [clangd] Make use of token buffers in 
semantic highlighting.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75446

Files:
  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
@@ -620,6 +620,7 @@
 
 A split B
   )cpp");
+  // Ranges going across expansion boundaries.
   EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("a1 a2 a3 split b1 b2")),
   ValueIs(SameRange(findSpelled("A split B";
   EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("a1 a2 a3")),
@@ -640,22 +641,28 @@
 ID(ID(ID(a1) a2 a3)) split ID(B)
   )cpp");
 
-  EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("a1 a2 a3")),
-  ValueIs(SameRange(findSpelled("ID ( ID ( ID ( a1 ) a2 a3 ) )";
   EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("b1 b2")),
-  ValueIs(SameRange(findSpelled("ID ( B )";
+  ValueIs(SameRange(findSpelled("b1 b2";
   EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("a1 a2 a3 split b1 b2")),
   ValueIs(SameRange(findSpelled(
   "ID ( ID ( ID ( a1 ) a2 a3 ) ) split ID ( B )";
-  // Ranges crossing macro call boundaries.
-  EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("a1 a2 a3 split b1")),
-llvm::None);
-  EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("a2 a3 split b1")),
-llvm::None);
-  // FIXME: next two examples should map to macro arguments, but currently they
-  //fail.
-  EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("a2")), llvm::None);
-  EXPECT_EQ(Buffer.spelledForExpanded(findExpanded("a1 a2")), llvm::None);
+  // Mixed ranges with expanded and spelled tokens.
+  EXPECT_THAT(
+  Buffer.spelledForExpanded(findExpanded("a1 a2 a3 split")),
+  ValueIs(SameRange(findSpelled("ID ( ID ( ID ( a1 ) a2 a3 ) ) split";
+  EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("split b1 b2")),
+  ValueIs(SameRange(findSpelled("split ID ( B )";
+  // Macro arguments
+  EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("a1")),
+  ValueIs(SameRange(findSpelled("a1";
+  EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("a2")),
+  ValueIs(SameRange(findSpelled("a2";
+  EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("a3")),
+  ValueIs(SameRange(findSpelled("a3";
+  EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("a1 a2")),
+  ValueIs(SameRange(findSpelled("ID ( a1 ) a2";
+  EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("a1 a2 a3")),
+  ValueIs(SameRange(findSpelled("ID ( a1 ) a2 a3";
 
   // Empty macro expansions.
   recordTokens(R"cpp(
@@ -667,11 +674,11 @@
 ID(7 8 9) EMPTY EMPTY
   )cpp");
   EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("1 2 3")),
-  ValueIs(SameRange(findSpelled("ID ( 1 2 3 )";
+  ValueIs(SameRange(findSpelled("1 2 3";
   EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("4 5 6")),
-  ValueIs(SameRange(findSpelled("ID ( 4 5 6 )";
+  ValueIs(SameRange(findSpelled("4 5 6";
   EXPECT_THAT(Buffer.spelledForExpanded(findExpanded("7 8 9")),
-  ValueIs(SameRange(findSpelled("ID ( 7 8 9 )";
+  ValueIs(SameRange(findSpelled("7 8 9";
 
   // Empty mappings coming from various directives.
   recordTokens(R"cpp(
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -35,6 +35,64 @@
 using namespace clang;
 using namespace clang::syntax;
 
+namespace {
+// Finds the smallest consecutive subsuquence of Toks that covers R.
+llvm::ArrayRef
+getTokensCovering(llvm::ArrayRef Toks, SourceRange R,
+  const SourceManager &SM) {
+  if (R.isInvalid())
+return {};
+  const syntax::Token *Begin =
+  llvm::partition_point(Toks, [&](const syntax::Token &T) {
+return SM.isBeforeInTranslationUnit(T.location(), R.getBegin());
+  });
+  const syntax::Token *End =
+  llvm::partition_point(Toks, [&](const syntax::Token &T) {
+return !SM.isBeforeInTranslationUnit(R.getEnd(), T.location());
+  });
+  if (Begin > End)
+return {};
+  return {Begin, End};
+}
+
+// Finds the smallest expansion range that contains expanded tokens First and
+// Last, e.g.:
+// #define ID(x) x
+// ID(ID(ID(a1) a2))
+//  ~~   -> a1
+//  ~~   -> a2
+//   ~   -> a1 a2
+SourceRange findCommonRangeForMacroArgs(const syntax::Toke

[PATCH] D72874: [clangd] Add a textual fallback for go-to-definition

2020-03-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks! The scope looks good to me now, on to implementation details.
I'm being a bit picky on the behaivor because go-to-def is a heavily-used 
feature, many users won't be expecting what we're doing here, and we can't 
reasonably expect them to understand the failure modes.
So, let's try hard not to fail :-)

This reminds me: it's not completely obvious what set of "act on symbol under 
the cursor" things this should (eventually) apply to.
I think not having e.g. find-references work makes sense - user should navigate 
to a "real" occurrence to resolve the ambiguity, and things like code actions 
are right out.
However having `textDocument/hover` work when we have high confidence in 
results would be really cool.
Obviously nothing in scope for this patch, but it seems worth writing this down 
somewhere, precisely because we shouldn't do it now.

In D72874#1900149 , @nridge wrote:

> I currently handle `lowerCamel`, `UpperCamel`, `CAPS`, and `under_scores`. 
> I've left the others as follow-ups.


(sorry for shifting goalposts, I think `CAPS` may be too broad. Left a comment 
inline)

>> - if you get more than 3 results, and none from current file, maybe don't 
>> return anything, as confidence is too low. Or try a stricter query...
> 
> I implemented this, but my testing shows this causes a lot of results for 
> class names to be excluded. The reason appears to be that `fuzzyFind()` 
> returns the class and each of its constructors as distinct results, so if a 
> class has more than two constructors, we'll have more than 3 results (and 
> typically the class is declared in a different file).

I think we should just drop constructor results, they'll always have this 
problem.
(There are other cases but this is the biggest).

>> - handle the most common case of non-indexable symbols (local symbols) by 
>> running the query against the closest occurrence of the token in code.
> 
> I've left this as a follow-up.

Makes sense. I think this there's not a lot of new complexity here, we have the 
major pieces (getWordAtPosition, TokenBuffer, SelectionTree, targetDecl, index) 
but integration is definitely substantial.

I'd suggest we go down that path before adding complexity for the indexed-based 
path though, because I suspect it's going to handle many of the practical 
situations where the index-based approach needs a lot of help (and vice-versa).




Comment at: clang-tools-extra/clangd/SourceCode.cpp:313
 
 SourceLocation getBeginningOfIdentifier(const Position &Pos,
 const SourceManager &SM,

@kadircet is working on getting rid of this function because creating raw 
lexers is is wasteful and not actually very powerful. Mostly we're moving to 
syntax::TokenBuffer, which records actual lexed tokens, but that doesn't apply 
here.

The examples in the tests seem like they'd be covered by something *really* 
simple, like enclosing identifier chars:

```
unsigned Begin, End;
for (Begin = Offset; Begin > 0 && isIdentifierBody(Code[Begin-1]); --BeginEnd) 
{}
for (End = Offset; End < Code.size() && isIdentifierBody(Code[End]); ++End) {}
return Code.slice(Begin, End);
```

(Lexer::isIdentifierBodyChar requires langopts but just passes through 
DollarIdents to isIdentifierBody, and I don't think we care much about 
identifiers with $ in them.)

If we really want to do something more subtle here, we should check it in 
SourceCodeTests.



Comment at: clang-tools-extra/clangd/SourceCode.h:93
+/// the entire comment or string token.
+SourceRange getWordAtPosition(const Position &Pos, const SourceManager &SM,
+  const LangOptions &LangOpts);

consider moving the isLikelyToBeIdentifier check inside. The current API is 
pretty general and it's not clear yet what (else) it's good for so it's nice to 
direct towards intended usage.

Also doing the identifier check inside this function is more convenient when it 
relies on markers outside the identifier range (like doxygen `\p` or 
backtick-quoted identifiers)

That said, you may still want to return the range when it's not a likely 
identifier, with a signature like `StringRef getWordAtPosition(bool 
*LikelyIdentifier = nullptr)`. I'm thinking of the future case where the caller 
wants to find a nearby matching token and resolve it - resolving belongs in the 
caller so there's not much point having this function duplicate the check.



Comment at: clang-tools-extra/clangd/SourceCode.h:93
+/// the entire comment or string token.
+SourceRange getWordAtPosition(const Position &Pos, const SourceManager &SM,
+  const LangOptions &LangOpts);

sammccall wrote:
> consider moving the isLikelyToBeIdentifier check inside. The current API is 
> pretty general and it's not clear yet what (else) it's good for so it's nice 
> to dire

[PATCH] D75447: [clangd] Make use of token buffers in semantic highlighting

2020-03-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: hokein, sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.
kadircet added a parent revision: D75446: [clang][Syntax] Handle macro 
arguments in spelledForExpanded.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75447

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


Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
@@ -130,37 +131,30 @@
 /// Consumes source locations and maps them to text ranges for highlightings.
 class HighlightingsBuilder {
 public:
-  HighlightingsBuilder(const SourceManager &SourceMgr,
-   const LangOptions &LangOpts)
-  : SourceMgr(SourceMgr), LangOpts(LangOpts) {}
+  HighlightingsBuilder(ParsedAST &AST)
+  : TB(AST.getTokens()), SourceMgr(AST.getSourceManager()),
+LangOpts(AST.getLangOpts()) {}
 
   void addToken(HighlightingToken T) { Tokens.push_back(T); }
 
   void addToken(SourceLocation Loc, HighlightingKind Kind) {
-if (Loc.isInvalid())
+// This enables highlighting tokens coming from macro expansions, e.g.:
+// #define MACRO SOME_NAME
+// int MACRO;
+// ~ -> this will get highlighted as a macro token.
+// As `de-conflicting` logic inside `collect` would drop these otherwise.
+// There were tests specifically checking for that, not sure if it is 
needed
+// though.
+if (!SourceMgr.isMacroArgExpansion(Loc))
   return;
-if (Loc.isMacroID()) {
-  // Only intereseted in highlighting arguments in macros (DEF_X(arg)).
-  if (!SourceMgr.isMacroArgExpansion(Loc))
-return;
-  Loc = SourceMgr.getSpellingLoc(Loc);
-}
-
-// Non top level decls that are included from a header are not filtered by
-// topLevelDecls. (example: method declarations being included from
-// another file for a class from another file).
-// There are also cases with macros where the spelling loc will not be in
-// the main file and the highlighting would be incorrect.
-if (!isInsideMainFile(Loc, SourceMgr))
+auto Toks = TB.spelledForExpanded(TB.expandedTokens(Loc));
+if (!Toks || Toks->empty() ||
+!isInsideMainFile(Toks->front().location(), SourceMgr))
   return;
 
-auto Range = getTokenRange(SourceMgr, LangOpts, Loc);
-if (!Range) {
-  // R should always have a value, if it doesn't something is very wrong.
-  elog("Tried to add semantic token with an invalid range");
-  return;
-}
-Tokens.push_back(HighlightingToken{Kind, *Range});
+auto Range = halfOpenToRange(
+SourceMgr, Toks->front().range(SourceMgr).toCharRange(SourceMgr));
+Tokens.push_back(HighlightingToken{Kind, std::move(Range)});
   }
 
   std::vector collect(ParsedAST &AST) && {
@@ -210,6 +204,7 @@
   }
 
 private:
+  const syntax::TokenBuffer &TB;
   const SourceManager &SourceMgr;
   const LangOptions &LangOpts;
   std::vector Tokens;
@@ -341,7 +336,7 @@
 std::vector getSemanticHighlightings(ParsedAST &AST) {
   auto &C = AST.getASTContext();
   // Add highlightings for AST nodes.
-  HighlightingsBuilder Builder(AST.getSourceManager(), C.getLangOpts());
+  HighlightingsBuilder Builder(AST);
   // Highlight 'decltype' and 'auto' as their underlying types.
   CollectExtraHighlightings(Builder).TraverseAST(C);
   // Highlight all decls and references coming from the AST.


Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
@@ -130,37 +131,30 @@
 /// Consumes source locations and maps them to text ranges for highlightings.
 class HighlightingsBuilder {
 public:
-  HighlightingsBuilder(const SourceManager &SourceMgr,
-   const LangOptions &LangOpts)
-  : SourceMgr(SourceMgr), LangOpts(LangOpts) {}
+  HighlightingsBuilder(ParsedAST &AST)
+  : TB(AST.getTokens()), SourceMgr(AST.getSourceManager()),
+LangOpts(AST.getLangOpts()) {}
 
   void addToken(HighlightingToken T) { Tokens.push_back(T); }
 
   void addToken(SourceLocation Loc, HighlightingKind Kind) {
-if 

[PATCH] D72041: [clangd] Handle go-to-definition in macro invocations where the target appears in the expansion multiple times

2020-03-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Awesome, thanks for fixing this!




Comment at: clang-tools-extra/clangd/Selection.cpp:261
+  // consider it selected.
+  if (!SeenMacroCalls.insert(ArgStart).second) {
+return NoTokens;

nridge wrote:
> sammccall wrote:
> > sammccall wrote:
> > > Given the following program:
> > > ```
> > > #define SQUARE(x) x * x;
> > > int four = [[SQUARE(2)]];
> > > ```
> > > We're going to now report the binary operator and one of the operands as 
> > > selected and not the other, which doesn't seem desirable.
> > > 
> > > I think we want to accept macro-selected || arg-selected, so probably 
> > > doing the current "non-argument macro expansion" first unconditionally or 
> > > factoring it out into a function.
> > > 
> > > This will change the behavior of `int four = [[SQUARE]](2)` to consider 
> > > the literal children selected too, I think this is fine.
> > I don't think it's a good idea to add hidden state and side-effects to 
> > testChunk() - it breaks a lot of assumptions that help reason about the 
> > code, and using `mutable` hides the violation of them.
> > (And a possible source of bugs - this is first in traversal order rather 
> > than first in source order - these are mostly but IIRC not always the same).
> > 
> > Instead I think you can do this statelessly: from the top-level spelling 
> > location, walk down with `SM.getMacroArgExpandedLocation` until you hit the 
> > target FileID (this is the first-expansion of first-expansion of 
> > first-expansion...) or the FileID stops changing (you've reached the 
> > innermost macro invocation, and your target location was on a different 
> > branch).
> I agree that adding state is not great. I thought it was icky as I was 
> writing it, I just couldn't think of an alternative. Thank you for suggesting 
> one!
> 
> I implemented what you suggested, and it seems to work. I did want to ask a 
> clarifying question to make sure I understand correctly: when an argument 
> occurs multiple times in a macro exapnsion, the occurrences will have 
> distinct `FileID`s (as opposed just different offsets in the same macro 
> `FileID`)?
That's right. My mental model is:
 - a TU is a sequence of expanded (i.e. post-PP) tokens
 - a FileID always corresponds to a single subrange of these expanded tokens...
 - ...with holes in it for child FileIDs. Parents/children nest properly.

One of the things I really like about the syntax::TokenBuffer API is that it 
exposes this structure.



Comment at: clang-tools-extra/clangd/Selection.cpp:166
+if (SM.getFileID(Next) == SM.getFileID(Prev)) {
+  break;
+}

nit: return false directly?



Comment at: clang-tools-extra/clangd/Selection.cpp:287
 if (SM.getFileID(ArgStart) == SelFile) {
-  SourceLocation ArgEnd = SM.getTopMacroCallerLoc(Batch.back().location());
-  return testTokenRange(SM.getFileOffset(ArgStart),
-SM.getFileOffset(ArgEnd));
+  if (isFirstExpansion(FID, ArgStart, SM)) {
+SourceLocation ArgEnd =

when false is the fallthrough to handling as if part of the macro body 
deliberate?

Thinking about it I suppose either that or returning NoTokens works, but please 
document it, e.g. `} else { /* fall through and treat as part of the macro body 
*/}`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72041



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


[PATCH] D75429: [clangd] DefineOutline won't copy virtual specifiers on methods

2020-03-02 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 247601.
njames93 marked 8 inline comments as done.
njames93 added a comment.

- Refactor and extra test cases


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75429

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
@@ -2068,6 +2068,69 @@
   };)cpp",
   "Foo::Foo(int z) __attribute__((weak)) : bar(2){}\n",
   },
+  // Virt specifiers.
+  {
+  R"cpp(
+struct A {
+  virtual void f^oo() {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() ;
+};)cpp",
+  " void A::foo() {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() override {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() override ;
+};)cpp",
+  "void B::foo()  {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() final {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() final ;
+};)cpp",
+  "void B::foo()  {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() final override {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() final override ;
+};)cpp",
+  "void B::foo()   {}\n",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2229,6 +2292,61 @@
 << Case.TestHeader;
   }
 }
+
+TEST_F(DefineOutlineTest, FailsMacroSpecifier) {
+  FileName = "Test.hpp";
+  ExtraFiles["Test.cpp"] = "";
+
+  std::pair Cases[] = {
+  {
+  R"cpp(
+  #define VIRT virtual
+  struct A {
+VIRT void fo^o() {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `virtual` specifier."},
+  {
+  R"cpp(
+  #define OVER override
+  struct A {
+virtual void foo() {}
+  };
+  struct B : A {
+void fo^o() OVER {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `override` specifier."},
+  {
+  R"cpp(
+  #define FINAL final
+  #define OVER override
+  struct A {
+virtual void foo() {}
+  };
+  struct B : A {
+void fo^o() FINAL OVER {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `override` specifier.\ndefine outline: Can't move out of line "
+  "as function has a macro `final` specifier."},
+  {
+  R"cpp(
+  #define FINALOVER final override
+  struct A {
+virtual void foo() {}
+  };
+  struct B : A {
+void fo^o() FINALOVER {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `override` specifier.\ndefine outline: Can't move out of line "
+  "as function has a macro `final` specifier."},
+  };
+  for (const auto &Case : Cases) {
+EXPECT_EQ(apply(Case.first), Case.second);
+  }
+}
 } // 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
@@ -16,6 +16,7 @@
 #include "SourceCode.h"
 #include "refactor/Tweak.h"
 #include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
@@ -156,7 +157,7 @@
 "define outline: couldn't find a context for target");
 
   llvm::Error Errors = llvm::Error::success();
-  tooling::Replacements QualifierInsertions;
+  tooling::Replacements DeclarationCleanups;
 
   // Finds the first unqualified nam

[PATCH] D75429: [clangd] DefineOutline won't copy virtual specifiers on methods

2020-03-02 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

I'm not entirely sure how to get the spelledTokens working in a good macro safe 
way?




Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:220
+assert(Attr->getLocation().isValid());
+if (Attr->getLocation().isMacroID()) {
+  Errors = llvm::joinErrors(

kadircet wrote:
> can you add some test cases for this branch ? In theory it should be ok to 
> drop this if full expansion is just the attr, i.e.
> 
> ```
> #define FNL final
> struct A { virtual void foo() FNL {} };
> ```
> 
> but should possibly fail in :
> ```
> #define MACRO foo() final
> struct A { virtual void MACRO {} };
> ```
it's not a great idea refactoring functions with MACRO attributes, we can never 
know if there are side effects based on different definitions due to things 
like build configs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75429



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


[PATCH] D75429: [clangd] DefineOutline won't copy virtual specifiers on methods

2020-03-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

In D75429#1900709 , @njames93 wrote:

> I'm not entirely sure how to get the spelledTokens working in a good macro 
> safe way?


I don't really follow this comment, could you elaborate? `TB.expandedTokens` 
always refer to a subset of the pre-processed token stream, so they can contain 
non-spelled tokens therefore clangd should never try to operate on those 
tokens. For example:

  #define FOO(X) int X;
  FOO(y);

pre-processed token stream will only contain `int y` which doesn't exist in the 
source code at all. `TB.spelledForExpanded` tries to map those expanded range 
back to spelling (to `FOO(y)` for example if you've got the full range `int 
y`), which is safe to operate on.
if there's no direct mapping between selected range and source code then it 
returns None, so you should bail out in such cases.




Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:220
+assert(Attr->getLocation().isValid());
+if (Attr->getLocation().isMacroID()) {
+  Errors = llvm::joinErrors(

njames93 wrote:
> kadircet wrote:
> > can you add some test cases for this branch ? In theory it should be ok to 
> > drop this if full expansion is just the attr, i.e.
> > 
> > ```
> > #define FNL final
> > struct A { virtual void foo() FNL {} };
> > ```
> > 
> > but should possibly fail in :
> > ```
> > #define MACRO foo() final
> > struct A { virtual void MACRO {} };
> > ```
> it's not a great idea refactoring functions with MACRO attributes, we can 
> never know if there are side effects based on different definitions due to 
> things like build configs.
well that's definitely one way to go, but while designing this code action we 
decided user should know better and clangd currently provides this code action 
in cases involving macros, see `DefineOutlineTest.HandleMacros` and it would be 
inconsistent with rest of the behavior if it bailed out in half of the cases 
and kept working for the rest.

Also this case is even safer than the rest, since it is only trying to drop 
those qualifiers and not duplicate them in the definition side.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:244
+bool Any = false;
+// Clang allows duplicating virtual specifiers so check for multiple
+// occurances.

kadircet wrote:
> again could you please add tests checking this case?
sorry, i still don't see any cases with multiple virtual keywords.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75429



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


[PATCH] D75331: [clangd] Get rid of lexer usage in locateMacroAt

2020-03-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3ae2fc7a8bb3: [clangd] Get rid of lexer usage in 
locateMacroAt (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75331

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
  clang-tools-extra/clangd/unittests/SourceCodeTests.cpp

Index: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
===
--- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -431,7 +431,7 @@
   ASSERT_TRUE(bool(CurLoc));
   const auto *Id = syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
   ASSERT_TRUE(Id);
-  auto Result = locateMacroAt(Id->location(), AST.getPreprocessor());
+  auto Result = locateMacroAt(*Id, AST.getPreprocessor());
   ASSERT_TRUE(Result);
   EXPECT_THAT(*Result, MacroName("MACRO"));
 }
@@ -445,7 +445,7 @@
   ASSERT_TRUE(bool(CurLoc));
   const auto *Id = syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
   ASSERT_TRUE(Id);
-  auto Result = locateMacroAt(Id->location(), AST.getPreprocessor());
+  auto Result = locateMacroAt(*Id, AST.getPreprocessor());
   ASSERT_TRUE(Result);
   EXPECT_THAT(*Result, MacroName("MACRO"));
 }
Index: clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
===
--- clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
+++ clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
@@ -89,7 +89,9 @@
 
   auto Loc = sourceLocationInMainFile(SM, ExpectedRefs.begin()->start);
   ASSERT_TRUE(bool(Loc));
-  auto Macro = locateMacroAt(*Loc, PP);
+  const auto *Id = syntax::spelledIdentifierTouching(*Loc, AST.getTokens());
+  ASSERT_TRUE(Id);
+  auto Macro = locateMacroAt(*Id, PP);
   assert(Macro);
   auto SID = getSymbolID(Macro->Name, Macro->Info, SM);
 
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -502,7 +502,7 @@
 return makeError(ReasonToReject::NoSymbolFound);
   // FIXME: Renaming macros is not supported yet, the macro-handling code should
   // be moved to rename tooling library.
-  if (locateMacroAt(IdentifierToken->location(), AST.getPreprocessor()))
+  if (locateMacroAt(*IdentifierToken, AST.getPreprocessor()))
 return makeError(ReasonToReject::UnsupportedSymbol);
 
   auto DeclsUnderCursor = locateDeclAt(AST, IdentifierToken->location());
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -228,8 +228,7 @@
   const auto *TouchedIdentifier =
   syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
   if (TouchedIdentifier) {
-if (auto M = locateMacroAt(TouchedIdentifier->location(),
-   AST.getPreprocessor())) {
+if (auto M = locateMacroAt(*TouchedIdentifier, AST.getPreprocessor())) {
   if (auto Loc = makeLocation(AST.getASTContext(),
   M->Info->getDefinitionLoc(), *MainFilePath)) {
 LocatedSymbol Macro;
@@ -463,13 +462,14 @@
 llvm::consumeError(CurLoc.takeError());
 return {};
   }
-  SourceLocation SLocId;
+  llvm::Optional Macro;
   if (const auto *IdentifierAtCursor =
-  syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens()))
-SLocId = IdentifierAtCursor->location();
-  RefsRequest Req;
+  syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens())) {
+Macro = locateMacroAt(*IdentifierAtCursor, AST.getPreprocessor());
+  }
 
-  if (auto Macro = locateMacroAt(SLocId, AST.getPreprocessor())) {
+  RefsRequest Req;
+  if (Macro) {
 // Handle references to macro.
 if (auto MacroSID = getSymbolID(Macro->Name, Macro->Info, SM)) {
   // Collect macro references from main file.
@@ -587,8 +587,7 @@
   if (!IdentifierAtCursor)
 return Results;
 
-  if (auto M = locateMacroAt(IdentifierAtCursor->location(),
- AST.getPreprocessor())) {
+  if (auto M = locateMacroAt(*IdentifierAtCursor, AST.getPreprocessor())) {
 SymbolDetails NewMacro;
 NewMacro.name = std::string(M->Name);
 llvm::SmallString<32> USR;
Index: clang-tools-extra/clangd/SourceCode.h
===
--- clang-tools-extra/clangd/SourceCode.h
+++ clang-tools-extra/clangd/SourceCode.h
@@ -21,6 +21,7 @@
 #include "clang/Bas

[PATCH] D75444: [ARM,MVE] Add the `vsbciq` intrinsics.

2020-03-02 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki accepted this revision.
miyuki added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75444



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


[PATCH] D75259: [clangd] Get rid of unnecssary source transformations in locateMacroAt

2020-03-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc24c89d6f0f5: [clangd] Get rid of unnecessary source 
transformations in locateMacroAt (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75259

Files:
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/unittests/SourceCodeTests.cpp


Index: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
===
--- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -436,6 +436,20 @@
   EXPECT_THAT(*Result, MacroName("MACRO"));
 }
 
+TEST(SourceCodeTests, WorksAtBeginOfFile) {
+  Annotations Code("^MACRO");
+  TestTU TU = TestTU::withCode(Code.code());
+  TU.HeaderCode = "#define MACRO int x;";
+  auto AST = TU.build();
+  auto CurLoc = sourceLocationInMainFile(AST.getSourceManager(), Code.point());
+  ASSERT_TRUE(bool(CurLoc));
+  const auto *Id = syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
+  ASSERT_TRUE(Id);
+  auto Result = locateMacroAt(Id->location(), AST.getPreprocessor());
+  ASSERT_TRUE(Result);
+  EXPECT_THAT(*Result, MacroName("MACRO"));
+}
+
 TEST(SourceCodeTests, IsInsideMainFile){
   TestTU TU;
   TU.HeaderCode = R"cpp(
Index: clang-tools-extra/clangd/SourceCode.h
===
--- clang-tools-extra/clangd/SourceCode.h
+++ clang-tools-extra/clangd/SourceCode.h
@@ -281,7 +281,8 @@
   llvm::StringRef Name;
   const MacroInfo *Info;
 };
-/// Gets the macro at a specified \p Loc.
+/// Gets the macro at a specified \p Loc. It must be a spelling location and
+/// point to the beginning of identifier.
 llvm::Optional locateMacroAt(SourceLocation Loc,
Preprocessor &PP);
 
Index: clang-tools-extra/clangd/SourceCode.cpp
===
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -893,10 +893,11 @@
 
 llvm::Optional locateMacroAt(SourceLocation Loc,
Preprocessor &PP) {
+  assert(Loc.isFileID());
   const auto &SM = PP.getSourceManager();
   const auto &LangOpts = PP.getLangOpts();
   Token Result;
-  if (Lexer::getRawToken(SM.getSpellingLoc(Loc), Result, SM, LangOpts, false))
+  if (Lexer::getRawToken(Loc, Result, SM, LangOpts, false))
 return None;
   if (Result.is(tok::raw_identifier))
 PP.LookUpIdentifierInfo(Result);
@@ -904,14 +905,12 @@
   if (!IdentifierInfo || !IdentifierInfo->hadMacroDefinition())
 return None;
 
-  std::pair DecLoc = SM.getDecomposedExpansionLoc(Loc);
   // Get the definition just before the searched location so that a macro
-  // referenced in a '#undef MACRO' can still be found.
-  SourceLocation BeforeSearchedLocation =
-  SM.getMacroArgExpandedLocation(SM.getLocForStartOfFile(DecLoc.first)
- .getLocWithOffset(DecLoc.second - 1));
-  MacroDefinition MacroDef =
-  PP.getMacroDefinitionAtLoc(IdentifierInfo, BeforeSearchedLocation);
+  // referenced in a '#undef MACRO' can still be found. Note that we only do
+  // that if Loc is not pointing at start of file.
+  if (SM.getLocForStartOfFile(SM.getFileID(Loc)) != Loc)
+Loc = Loc.getLocWithOffset(-1);
+  MacroDefinition MacroDef = PP.getMacroDefinitionAtLoc(IdentifierInfo, Loc);
   if (auto *MI = MacroDef.getMacroInfo())
 return DefinedMacro{IdentifierInfo->getName(), MI};
   return None;


Index: clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
===
--- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
+++ clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
@@ -436,6 +436,20 @@
   EXPECT_THAT(*Result, MacroName("MACRO"));
 }
 
+TEST(SourceCodeTests, WorksAtBeginOfFile) {
+  Annotations Code("^MACRO");
+  TestTU TU = TestTU::withCode(Code.code());
+  TU.HeaderCode = "#define MACRO int x;";
+  auto AST = TU.build();
+  auto CurLoc = sourceLocationInMainFile(AST.getSourceManager(), Code.point());
+  ASSERT_TRUE(bool(CurLoc));
+  const auto *Id = syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens());
+  ASSERT_TRUE(Id);
+  auto Result = locateMacroAt(Id->location(), AST.getPreprocessor());
+  ASSERT_TRUE(Result);
+  EXPECT_THAT(*Result, MacroName("MACRO"));
+}
+
 TEST(SourceCodeTests, IsInsideMainFile){
   TestTU TU;
   TU.HeaderCode = R"cpp(
Index: clang-tools-extra/clangd/SourceCode.h
===
--- clang-tools-extra/clangd/SourceCode.h
+++ clang-tools-extra/clangd/SourceCode.h
@@ -281,7 +281,8 @@
   llvm::StringRef Name;
   const MacroInfo *Info;
 };
-/// Gets the macro at a specified \p Loc.
+/// Gets the

[PATCH] D75368: [clang-format] Handle NullCoalescing and NullConditional operators in C#

2020-03-02 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe updated this revision to Diff 247610.
jbcoe edited the summary of this revision.
jbcoe added a comment.

Do not add new punctuators for ??, ?. and ?[


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

https://reviews.llvm.org/D75368

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -170,6 +170,12 @@
   verifyFormat("public override string ToString() => \"{Name}\\{Age}\";");
 }
 
+TEST_F(FormatTestCSharp, CSharpConditionalExpressions) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+  // conditional expression is not seen as a NullConditional.
+  verifyFormat("var y = A < B ? -1 : 1;", Style);
+}
+
 TEST_F(FormatTestCSharp, CSharpNullConditional) {
   FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
   Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -972,6 +972,13 @@
   }
   break;
 case tok::question:
+  if (Tok->is(TT_CSharpNullConditionalSq)) {
+if (!parseSquare())
+  return false;
+break;
+  }
+  if (Tok->isOneOf(TT_CSharpNullConditional, TT_CSharpNullCoalescing))
+break;
   if (Style.Language == FormatStyle::LK_JavaScript && Tok->Next &&
   Tok->Next->isOneOf(tok::semi, tok::comma, tok::colon, tok::r_paren,
  tok::r_brace)) {
@@ -987,9 +994,11 @@
   if (Line.MustBeDeclaration && !Contexts.back().IsExpression &&
   Style.Language == FormatStyle::LK_JavaScript)
 break;
-  if (Style.isCSharp() && Line.MustBeDeclaration) {
-Tok->Type = TT_CSharpNullableTypeQuestionMark;
-break;
+  if (Style.isCSharp()) {
+if (Line.MustBeDeclaration && !Contexts.back().IsExpression) {
+  Tok->Type = TT_CSharpNullable;
+  break;
+}
   }
   parseConditional();
   break;
@@ -1437,6 +1446,21 @@
   // The token type is already known.
   return;
 
+if (Style.isCSharp() && CurrentToken->is(tok::question)) {
+  if (CurrentToken->TokenText == "??") {
+Current.Type = TT_CSharpNullCoalescing;
+return;
+  }
+  if (CurrentToken->TokenText == "?.") {
+Current.Type = TT_CSharpNullConditional;
+return;
+  }
+  if (CurrentToken->TokenText == "?[") {
+Current.Type = TT_CSharpNullConditionalSq;
+return;
+  }
+}
+
 if (Style.Language == FormatStyle::LK_JavaScript) {
   if (Current.is(tok::exclaim)) {
 if (Current.Previous &&
@@ -2907,9 +2931,29 @@
   return Style.SpacesInSquareBrackets;
 
 // No space before ? in nullable types.
-if (Right.is(TT_CSharpNullableTypeQuestionMark))
+if (Right.is(TT_CSharpNullable))
+  return false;
+
+// Require space after ? in nullable types.
+if (Left.is(TT_CSharpNullable))
+  return true;
+
+// No space before or after '?.'.
+if (Left.is(TT_CSharpNullConditional) || Right.is(TT_CSharpNullConditional))
   return false;
 
+// Space before and after '??'.
+if (Left.is(TT_CSharpNullCoalescing) || Right.is(TT_CSharpNullCoalescing))
+  return true;
+
+// No space before '?['.
+if (Right.is(TT_CSharpNullConditionalSq))
+  return false;
+
+// Possible space inside `?[ 0 ]`.
+if (Left.is(TT_CSharpNullConditionalSq))
+  return Style.SpacesInSquareBrackets;
+
 // space between keywords and paren e.g. "using ("
 if (Right.is(tok::l_paren))
   if (Left.isOneOf(tok::kw_using, Keywords.kw_async, Keywords.kw_when))
Index: clang/lib/Format/FormatTokenLexer.h
===
--- clang/lib/Format/FormatTokenLexer.h
+++ clang/lib/Format/FormatTokenLexer.h
@@ -52,8 +52,8 @@
   bool tryMergeJSPrivateIdentifier();
   bool tryMergeCSharpStringLiteral();
   bool tryMergeCSharpKeywordVariables();
-  bool tryMergeCSharpNullConditionals();
   bool tryMergeCSharpDoubleQuestion();
+  bool tryMergeCSharpNullConditional();
   bool tryTransformCSharpForEach();
   bool tryMergeCSharpAttributeAndTarget();
 
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -84,7 +84,7 @@
   return;
 if (tryMergeCSharpDoubleQuestion())
   return;
-if (tryMergeCSharpNullConditionals())
+if (tryMergeCSharpNullConditional())
   return;
 if (tryTransformCShar

[PATCH] D75368: [clang-format] Handle NullCoalescing and NullConditional operators in C#

2020-03-02 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Format/FormatToken.h:109
+  TYPE(CSharpNullConditional)  
\
+  TYPE(CSharpNullConditionalSq)
\
   TYPE(Unknown)

nit: consider renaming to `CSharpNullConditionalLSquare` for consistency with 
other similar token types.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2955
+if (Left.is(TT_CSharpNullConditionalSq))
+  return Style.SpacesInSquareBrackets;
+

please add a test case about this where `Style.SpacesInSquareBrakets == true`.


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

https://reviews.llvm.org/D75368



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


[PATCH] D75429: [clangd] DefineOutline won't copy virtual specifiers on methods

2020-03-02 Thread Nathan James via Phabricator via cfe-commits
njames93 marked 2 inline comments as done.
njames93 added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:220
+assert(Attr->getLocation().isValid());
+if (Attr->getLocation().isMacroID()) {
+  Errors = llvm::joinErrors(

kadircet wrote:
> njames93 wrote:
> > kadircet wrote:
> > > can you add some test cases for this branch ? In theory it should be ok 
> > > to drop this if full expansion is just the attr, i.e.
> > > 
> > > ```
> > > #define FNL final
> > > struct A { virtual void foo() FNL {} };
> > > ```
> > > 
> > > but should possibly fail in :
> > > ```
> > > #define MACRO foo() final
> > > struct A { virtual void MACRO {} };
> > > ```
> > it's not a great idea refactoring functions with MACRO attributes, we can 
> > never know if there are side effects based on different definitions due to 
> > things like build configs.
> well that's definitely one way to go, but while designing this code action we 
> decided user should know better and clangd currently provides this code 
> action in cases involving macros, see `DefineOutlineTest.HandleMacros` and it 
> would be inconsistent with rest of the behavior if it bailed out in half of 
> the cases and kept working for the rest.
> 
> Also this case is even safer than the rest, since it is only trying to drop 
> those qualifiers and not duplicate them in the definition side.
Thanks for explaining that for me, I'll give it a go and see how the test cases 
are handled



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:244
+bool Any = false;
+// Clang allows duplicating virtual specifiers so check for multiple
+// occurances.

kadircet wrote:
> kadircet wrote:
> > again could you please add tests checking this case?
> sorry, i still don't see any cases with multiple virtual keywords.
Ah I thought you meant a test case just containing virtual which there is, I'll 
get the second one added.
Should I even support multiple virtual decls, https://godbolt.org/z/kGbF22 
clang treats this as a warning, but for gcc its an error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75429



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


[PATCH] D75447: [clangd] Make use of token buffers in semantic highlighting

2020-03-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 247612.
kadircet added a comment.

- Add forgetten macroid check, before looking for an macroargexpansion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75447

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


Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
@@ -131,37 +132,30 @@
 /// Consumes source locations and maps them to text ranges for highlightings.
 class HighlightingsBuilder {
 public:
-  HighlightingsBuilder(const SourceManager &SourceMgr,
-   const LangOptions &LangOpts)
-  : SourceMgr(SourceMgr), LangOpts(LangOpts) {}
+  HighlightingsBuilder(ParsedAST &AST)
+  : TB(AST.getTokens()), SourceMgr(AST.getSourceManager()),
+LangOpts(AST.getLangOpts()) {}
 
   void addToken(HighlightingToken T) { Tokens.push_back(T); }
 
   void addToken(SourceLocation Loc, HighlightingKind Kind) {
-if (Loc.isInvalid())
+// This enables highlighting tokens coming from macro expansions, e.g.:
+// #define MACRO SOME_NAME
+// int MACRO;
+// ~ -> this will get highlighted as a macro token.
+// As `de-conflicting` logic inside `collect` would drop these otherwise.
+// There were tests specifically checking for that, not sure if it is 
needed
+// though.
+if (Loc.isMacroID() && !SourceMgr.isMacroArgExpansion(Loc))
   return;
-if (Loc.isMacroID()) {
-  // Only intereseted in highlighting arguments in macros (DEF_X(arg)).
-  if (!SourceMgr.isMacroArgExpansion(Loc))
-return;
-  Loc = SourceMgr.getSpellingLoc(Loc);
-}
-
-// Non top level decls that are included from a header are not filtered by
-// topLevelDecls. (example: method declarations being included from
-// another file for a class from another file).
-// There are also cases with macros where the spelling loc will not be in
-// the main file and the highlighting would be incorrect.
-if (!isInsideMainFile(Loc, SourceMgr))
+auto Toks = TB.spelledForExpanded(TB.expandedTokens(Loc));
+if (!Toks || Toks->empty() ||
+!isInsideMainFile(Toks->front().location(), SourceMgr))
   return;
 
-auto Range = getTokenRange(SourceMgr, LangOpts, Loc);
-if (!Range) {
-  // R should always have a value, if it doesn't something is very wrong.
-  elog("Tried to add semantic token with an invalid range");
-  return;
-}
-Tokens.push_back(HighlightingToken{Kind, *Range});
+auto Range = halfOpenToRange(
+SourceMgr, Toks->front().range(SourceMgr).toCharRange(SourceMgr));
+Tokens.push_back(HighlightingToken{Kind, std::move(Range)});
   }
 
   std::vector collect(ParsedAST &AST) && {
@@ -211,6 +205,7 @@
   }
 
 private:
+  const syntax::TokenBuffer &TB;
   const SourceManager &SourceMgr;
   const LangOptions &LangOpts;
   std::vector Tokens;
@@ -311,7 +306,7 @@
 std::vector getSemanticHighlightings(ParsedAST &AST) {
   auto &C = AST.getASTContext();
   // Add highlightings for AST nodes.
-  HighlightingsBuilder Builder(AST.getSourceManager(), C.getLangOpts());
+  HighlightingsBuilder Builder(AST);
   // Highlight 'decltype' and 'auto' as their underlying types.
   CollectExtraHighlightings(Builder).TraverseAST(C);
   // Highlight all decls and references coming from the AST.


Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
@@ -131,37 +132,30 @@
 /// Consumes source locations and maps them to text ranges for highlightings.
 class HighlightingsBuilder {
 public:
-  HighlightingsBuilder(const SourceManager &SourceMgr,
-   const LangOptions &LangOpts)
-  : SourceMgr(SourceMgr), LangOpts(LangOpts) {}
+  HighlightingsBuilder(ParsedAST &AST)
+  : TB(AST.getTokens()), SourceMgr(AST.getSourceManager()),
+LangOpts(AST.getLangOpts()) {}
 
   void addToken(HighlightingToken T) { Tokens.push_back(T); }
 
   void addToken(SourceLocation Loc, HighlightingKind Kind) {
-if (Loc.isInvalid())
+// This enables highlighting tokens coming from macr

[PATCH] D75365: [AST Matchers] Fix bug in 'optionally' matcher wherein all previous bindings are cleared when all inner matchers fail.

2020-03-02 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

+1 to this fix.

However, regarding `allOf` vs. `anyOf` semantics, since `optionally` always 
succeeds, is there a difference between the two semantics?

It seems to me that there should be no difference between `allOf(optionally(a), 
optionally(b))` vs. `anyOf(optionally(a), optionally(b))`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75365



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


[PATCH] D75271: [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions.

2020-03-02 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware accepted this revision.
baloghadamsoftware added a comment.

I think this is straightforward after D75360 . 
This was my original attempt as well, but without D75360 
 it did not work. This solves the problem of 
both accessing `AnalyzerOptions` and emitting an error message.


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

https://reviews.llvm.org/D75271



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


[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

The above patch composes sensibly with openmp, e.g.

  #include 
  #pragma omp declare target
  int data __attribute__((no_zero_initializer));
  #pragma omp allocate(data) allocator(omp_pteam_mem_alloc)
  #pragma omp end declare target

  @data = hidden addrspace(3) global i32 undef, align 4

I like `loader_uninitialized`. There's some prior art on using NOLOAD from a 
(gnu) linker script to achieve the same result, which is a similar name. I'll 
update the patch accordingly.

I found an arm toolchain which supports UNINIT in linker scripts. Asking around 
I've also heard that games dev is a potential user for this feature (perhaps 
analogous to mmap's MAP_UNINITIALIZED?) but haven't been able to confirm 
specifics.

I'll take a first shot at the documentation too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74361



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


[PATCH] D75429: [clangd] DefineOutline won't copy virtual specifiers on methods

2020-03-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:244
+bool Any = false;
+// Clang allows duplicating virtual specifiers so check for multiple
+// occurances.

njames93 wrote:
> kadircet wrote:
> > kadircet wrote:
> > > again could you please add tests checking this case?
> > sorry, i still don't see any cases with multiple virtual keywords.
> Ah I thought you meant a test case just containing virtual which there is, 
> I'll get the second one added.
> Should I even support multiple virtual decls, https://godbolt.org/z/kGbF22 
> clang treats this as a warning, but for gcc its an error.
If compiler has an error parsing those, we'll be on the safe side since AST 
will be broken for that node and we'll most likely bail out long before we 
reach here.

If compiler is happy with those, and produces just warnings, deleting one vs 
deleting multiple shouldn't make much difference in the code path(just a matter 
of breaking or not), but would make action more resilient so I would go for 
deleting multiple, since it won't have any side effects the user will still see 
the compiler warning in the header(declaration location).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75429



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


[PATCH] D75365: [AST Matchers] Fix bug in 'optionally' matcher wherein all previous bindings are cleared when all inner matchers fail.

2020-03-02 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D75365#1900784 , @gribozavr2 wrote:

> +1 to this fix.
>
> However, regarding `allOf` vs. `anyOf` semantics, since `optionally` always 
> succeeds, is there a difference between the two semantics?
>
> It seems to me that there should be no difference between 
> `allOf(optionally(a), optionally(b))` vs. `anyOf(optionally(a), 
> optionally(b))`.


I think the difference is in whether you continue with the submatchers after a 
success. Allof does while anyof does not.  That said, the original issue was 
forEach vs allOf/anyOf. So, I think Aaron's point holds - let optionally take 
one argument and then leave it to the user to explicitly specify forEach, 
allOf, anyOf, etc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75365



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


[clang] c3af063 - [clang-format] Handle NullCoalescing and NullConditional operators in C#

2020-03-02 Thread Jonathan Coe via cfe-commits

Author: Jonathan Coe
Date: 2020-03-02T13:55:54Z
New Revision: c3af063c2bbfe5408d565ee4350c36fc1d0b2758

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

LOG: [clang-format] Handle NullCoalescing and NullConditional operators in C#

Summary:
Disable merging of Type? into a single token.

Merge ?? ?. and ?[ into a single token.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

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

Added: 


Modified: 
clang/lib/Format/FormatToken.h
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestCSharp.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 61c3cda89cdc..ac117840ea33 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -102,9 +102,11 @@ namespace format {
   TYPE(TypenameMacro)  
\
   TYPE(UnaryOperator)  
\
   TYPE(CSharpStringLiteral)
\
-  TYPE(CSharpNullCoalescing)   
\
   TYPE(CSharpNamedArgumentColon)   
\
-  TYPE(CSharpNullableTypeQuestionMark) 
\
+  TYPE(CSharpNullable) 
\
+  TYPE(CSharpNullCoalescing)   
\
+  TYPE(CSharpNullConditional)  
\
+  TYPE(CSharpNullConditionalSq)
\
   TYPE(Unknown)
 
 enum TokenType {

diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index aa8cf427d468..da73361ee3d5 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -84,7 +84,7 @@ void FormatTokenLexer::tryMergePreviousTokens() {
   return;
 if (tryMergeCSharpDoubleQuestion())
   return;
-if (tryMergeCSharpNullConditionals())
+if (tryMergeCSharpNullConditional())
   return;
 if (tryTransformCSharpForEach())
   return;
@@ -319,7 +319,7 @@ bool FormatTokenLexer::tryMergeCSharpDoubleQuestion() {
   auto &SecondQuestion = *(Tokens.end() - 1);
   if (!FirstQuestion->is(tok::question) || !SecondQuestion->is(tok::question))
 return false;
-  FirstQuestion->Tok.setKind(tok::question);
+  FirstQuestion->Tok.setKind(tok::question); // no '??' in clang tokens.
   FirstQuestion->TokenText = StringRef(FirstQuestion->TokenText.begin(),
SecondQuestion->TokenText.end() -
FirstQuestion->TokenText.begin());
@@ -329,6 +329,32 @@ bool FormatTokenLexer::tryMergeCSharpDoubleQuestion() {
   return true;
 }
 
+// Merge '?[' and '?.' pairs into single tokens.
+bool FormatTokenLexer::tryMergeCSharpNullConditional() {
+  if (Tokens.size() < 2)
+return false;
+  auto &Question = *(Tokens.end() - 2);
+  auto &PeriodOrLSquare = *(Tokens.end() - 1);
+  if (!Question->is(tok::question) ||
+  !PeriodOrLSquare->isOneOf(tok::l_square, tok::period))
+return false;
+  Question->TokenText =
+  StringRef(Question->TokenText.begin(),
+PeriodOrLSquare->TokenText.end() - 
Question->TokenText.begin());
+  Question->ColumnWidth += PeriodOrLSquare->ColumnWidth;
+
+  if (PeriodOrLSquare->is(tok::l_square)) {
+Question->Tok.setKind(tok::question); // no '?[' in clang tokens.
+Question->Type = TT_CSharpNullConditionalSq;
+  } else {
+Question->Tok.setKind(tok::question); // no '?.' in clang tokens.
+Question->Type = TT_CSharpNullConditional;
+  }
+
+  Tokens.erase(Tokens.end() - 1);
+  return true;
+}
+
 bool FormatTokenLexer::tryMergeCSharpKeywordVariables() {
   if (Tokens.size() < 2)
 return false;
@@ -348,23 +374,6 @@ bool FormatTokenLexer::tryMergeCSharpKeywordVariables() {
   return true;
 }
 
-// In C# merge the Identifier and the ? together e.g. arg?.
-bool FormatTokenLexer::tryMergeCSharpNullConditionals() {
-  if (Tokens.size() < 2)
-return false;
-  auto &Identifier = *(Tokens.end() - 2);
-  auto &Question = *(Tokens.end() - 1);
-  if (!Identifier->isOneOf(tok::r_square, tok::identifier) ||
-  !Question->is(tok::question))
-return false;
-  Identifier->TokenText =
-  StringRef(Identifier->TokenText.begin(),
-Question->TokenText.end() - Identifier->TokenText.begin());
-  Identifier->ColumnWidth += Question->ColumnWidth;
-  Tokens.erase(Tokens.end() - 1);
-

[clang] 8cdcbca - [CodeGen] avoid running the entire optimizer pipeline in clang test file; NFC

2020-03-02 Thread Sanjay Patel via cfe-commits

Author: Sanjay Patel
Date: 2020-03-02T09:12:53-05:00
New Revision: 8cdcbcaa02e7055a6745f2c1bde003c47c91f79e

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

LOG: [CodeGen] avoid running the entire optimizer pipeline in clang test file; 
NFC

There are no failures from the first set of RUN lines here,
so the CHECKs were already vague enough to not be affected
by optimizations. The final RUN line does induce some kind
of failure, so I'll try to fix that separately in a
follow-up.

Added: 


Modified: 
clang/test/CodeGen/complex-math.c

Removed: 




diff  --git a/clang/test/CodeGen/complex-math.c 
b/clang/test/CodeGen/complex-math.c
index 6f81ff2ff285..22a9e287f07f 100644
--- a/clang/test/CodeGen/complex-math.c
+++ b/clang/test/CodeGen/complex-math.c
@@ -1,12 +1,12 @@
 // FIXME: This file should not be using -O1; that makes it depend on the 
entire LLVM IR optimizer.
 
-// RUN: %clang_cc1 %s -O1 -fno-experimental-new-pass-manager -emit-llvm 
-triple x86_64-unknown-unknown -o - | FileCheck %s --check-prefix=X86
-// RUN: %clang_cc1 %s -O1 -fno-experimental-new-pass-manager -emit-llvm 
-triple x86_64-pc-win64 -o - | FileCheck %s --check-prefix=X86
-// RUN: %clang_cc1 %s -O1 -fno-experimental-new-pass-manager -emit-llvm 
-triple i686-unknown-unknown -o - | FileCheck %s --check-prefix=X86
-// RUN: %clang_cc1 %s -O1 -fno-experimental-new-pass-manager -emit-llvm 
-triple powerpc-unknown-unknown -o - | FileCheck %s --check-prefix=PPC
-// RUN: %clang_cc1 %s -O1 -fno-experimental-new-pass-manager -emit-llvm 
-triple armv7-none-linux-gnueabi -o - | FileCheck %s --check-prefix=ARM
-// RUN: %clang_cc1 %s -O1 -fno-experimental-new-pass-manager -emit-llvm 
-triple armv7-none-linux-gnueabihf -o - | FileCheck %s --check-prefix=ARMHF
-// RUN: %clang_cc1 %s -O1 -fno-experimental-new-pass-manager -emit-llvm 
-triple thumbv7k-apple-watchos2.0 -o - -target-abi aapcs16 | FileCheck %s 
--check-prefix=ARM7K
+// RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple x86_64-unknown-unknown -o - | FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple x86_64-pc-win64 -o - | FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple i686-unknown-unknown -o - | FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple powerpc-unknown-unknown -o - | FileCheck %s --check-prefix=PPC
+// RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple armv7-none-linux-gnueabi -o - | FileCheck %s --check-prefix=ARM
+// RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple armv7-none-linux-gnueabihf -o - | FileCheck %s --check-prefix=ARMHF
+// RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple thumbv7k-apple-watchos2.0 -o - -target-abi aapcs16 | FileCheck %s 
--check-prefix=ARM7K
 // RUN: %clang_cc1 %s -O1 -fno-experimental-new-pass-manager -emit-llvm 
-triple aarch64-unknown-unknown -ffast-math -o - | FileCheck %s 
--check-prefix=AARCH64-FASTMATH
 
 float _Complex add_float_rr(float a, float b) {



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


[PATCH] D75447: [clangd] Make use of token buffers in semantic highlighting

2020-03-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:134
 public:
-  HighlightingsBuilder(const SourceManager &SourceMgr,
-   const LangOptions &LangOpts)
-  : SourceMgr(SourceMgr), LangOpts(LangOpts) {}
+  HighlightingsBuilder(ParsedAST &AST)
+  : TB(AST.getTokens()), SourceMgr(AST.getSourceManager()),

nit: this can be const



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:148
+// though.
+if (!SourceMgr.isMacroArgExpansion(Loc))
   return;

only if this is a macro!



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:150
   return;
-if (Loc.isMacroID()) {
-  // Only intereseted in highlighting arguments in macros (DEF_X(arg)).
-  if (!SourceMgr.isMacroArgExpansion(Loc))
-return;
-  Loc = SourceMgr.getSpellingLoc(Loc);
-}
-
-// Non top level decls that are included from a header are not filtered by
-// topLevelDecls. (example: method declarations being included from
-// another file for a class from another file).
-// There are also cases with macros where the spelling loc will not be in
-// the main file and the highlighting would be incorrect.
-if (!isInsideMainFile(Loc, SourceMgr))
+auto Toks = TB.spelledForExpanded(TB.expandedTokens(Loc));
+if (!Toks || Toks->empty() ||

I think using TokenBuffer to translate expanded -> spelled isn't actually an 
improvement here as the API exposes several possibilities that can't actually 
happen in our case.

The specialized translation from expanded to spelled location is *policy*, and 
it's pretty easy to implement I think:

```
// For a macro usage `DUMP(foo)`, we want:
//  - DUMP --> "macro"
//  - foo --> "variable".
SourceLocation getHighlightableSpellingToken(SourceLocation L) {
  if (L.isFileID()) return SM.isWrittenInMainFile(L) ? L : {};
  // Tokens expanded from the macro body contribute no highlightings.
  if (!SM.isMacroArgExpansion(L)) return {};
  // Tokens expanded from macro args are potentially highlightable.
  return getHighlightableSpellingToken(SM.getImmediateSpellingLocation(L));
}
```

once you have the spelling location, getting the range from tokenbuffer is easy 
:-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75447



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


[PATCH] D75445: [ARM,MVE] Add the `vshlcq` intrinsics.

2020-03-02 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki added a comment.

FYI: I have raised https://github.com/google/llvm-premerge-checks/issues/141 
(the premerge check machinery failed to apply the patch, but this is not 
reflected in the build status).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75445



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


[PATCH] D75350: [OpenMP] Allow const parameters in declare simd linear clause

2020-03-02 Thread Graham Hunter via Phabricator via cfe-commits
huntergr updated this revision to Diff 247614.
huntergr added a comment.

- Removed the ) my editor helpfully added to the CHECK line
- Added a test to declare_simd_aarch64.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75350

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_simd_aarch64.c
  clang/test/OpenMP/declare_simd_codegen.cpp

Index: clang/test/OpenMP/declare_simd_codegen.cpp
===
--- clang/test/OpenMP/declare_simd_codegen.cpp
+++ clang/test/OpenMP/declare_simd_codegen.cpp
@@ -114,6 +114,9 @@
 #pragma omp declare simd notinbranch
 double foo(double x) { return 0; }
 
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i) { return 0.0; }
+
 // CHECK-DAG: define {{.+}}@_Z5add_1Pf(
 // CHECK-DAG: define {{.+}}@_Z1hIiEvPT_S1_S1_S1_(
 // CHECK-DAG: define {{.+}}@_Z1hIfEvPT_S1_S1_S1_(
@@ -131,6 +134,7 @@
 // CHECK-DAG: define {{.+}}@_Z3fooPffi(
 // CHECK-DAG: define {{.+}}@_Z3food(
 // CHECK-DAG: declare {{.+}}@_Z5add_2Pf(
+// CHECK-DAG: define {{.+}}@_Z11constlineari(
 
 // CHECK-DAG: "_ZGVbM4l8__Z5add_1Pf"
 // CHECK-DAG: "_ZGVbN4l8__Z5add_1Pf"
@@ -320,6 +324,11 @@
 // CHECK-DAG: "_ZGVdN4v__Z3food"
 // CHECK-DAG: "_ZGVeN8v__Z3food"
 
+// CHECK-DAG: "_ZGVbN2l__Z11constlineari"
+// CHECK-DAG: "_ZGVcN4l__Z11constlineari"
+// CHECK-DAG: "_ZGVdN4l__Z11constlineari"
+// CHECK-DAG: "_ZGVeN8l__Z11constlineari"
+
 // CHECK-NOT: "_ZGV{{.+}}__Z1fRA_i
 
 #endif
Index: clang/test/OpenMP/declare_simd_aarch64.c
===
--- clang/test/OpenMP/declare_simd_aarch64.c
+++ clang/test/OpenMP/declare_simd_aarch64.c
@@ -116,6 +116,15 @@
 // AARCH64: "_ZGVnM16uv_c02" "_ZGVnM8uv_c02"
 // AARCH64-NOT: c02
 
+//
+/* Linear with a constant parameter */
+//
+
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i);
+// AARCH64: "_ZGVnN2l_constlinear" "_ZGVnN4l_constlinear"
+// AARCH64-NOT: constlinear
+
 /*/
 /* sincos-like signature */
 /*/
@@ -170,6 +179,7 @@
   D = b03(D);
   *I = c01(D, *S);
   *D = c02(D, *S);
+  constlinear(*I);
   sincos(*D, D, D);
   SinCos(*D, D, D);
   foo2(I, *I);
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -5269,7 +5269,8 @@
   E->containsUnexpandedParameterPack())
 continue;
   (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind,
-  PVD->getOriginalType());
+  PVD->getOriginalType(),
+  /*IsDeclareSimd=*/true);
   continue;
 }
   }
@@ -5289,7 +5290,7 @@
   E->isInstantiationDependent() || E->containsUnexpandedParameterPack())
 continue;
   (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind,
-  E->getType());
+  E->getType(), /*IsDeclareSimd=*/true);
   continue;
 }
 Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause)
@@ -14547,8 +14548,8 @@
 }
 
 bool Sema::CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
- OpenMPLinearClauseKind LinKind,
- QualType Type) {
+ OpenMPLinearClauseKind LinKind, QualType Type,
+ bool IsDeclareSimd) {
   const auto *VD = dyn_cast_or_null(D);
   // A variable must not have an incomplete type or a reference type.
   if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type))
@@ -14564,8 +14565,10 @@
   // OpenMP 5.0 [2.19.3, List Item Privatization, Restrictions]
   // A variable that is privatized must not have a const-qualified type
   // unless it is of class type with a mutable member. This restriction does
-  // not apply to the firstprivate clause.
-  if (rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
+  // not apply to the firstprivate clause, nor to the linear clause on
+  // declarative directives (like declare simd).
+  if (!IsDeclareSimd &&
+  rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
 return true;
 
   // A list item must be of integral or pointer type.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10173,7 +10173,8 @@
   /// Checks that the specified declaration matches requirements for the linear
   /// decls.
   bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
-   

[PATCH] D71110: [clangd] A tool to evaluate cross-file rename.

2020-03-02 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 247615.
hokein added a comment.

rebase to master.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71110

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/eval-rename/CMakeLists.txt
  clang-tools-extra/clangd/eval-rename/RenameMain.cpp
  clang-tools-extra/clangd/eval-rename/eval-rename.py
  clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt

Index: clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
@@ -0,0 +1,16 @@
+# normal functions
+clang-tools-extra/clangd/XRefs.h clang::clangd::findReferences clangd
+# normal class methods
+clang-tools-extra/clangd/index/Index.h clang::clangd::SwapIndex::reset clangd
+# normal classes
+clang-tools-extra/clangd/index/Index.h clang::clangd::SymbolIndex clangd
+clang-tools-extra/clangd/ClangdServer.h clang::clangd::ClangdServer clangd
+clang-tools-extra/clangd/GlobalCompilationDatabase.h clang::clangd::GlobalCompilationDatabase clangd
+clang-tools-extra/clangd/GlobalCompilationDatabase.h clang::clangd::OverlayCDB clangd
+clang-tools-extra/clangd/Protocol.h clang::clangd::CodeAction clangd
+# rename enum
+clang-tools-extra/clangd/index/Ref.h clang::clangd::RefKind clangd
+# rename enum constants
+clang-tools-extra/clangd/FindTarget.h clang::clangd::DeclRelation::Alias clangd
+# class with template constructors
+clang-tools-extra/clangd/index/MemIndex.h clang::clangd::MemIndex clangd
\ No newline at end of file
Index: clang-tools-extra/clangd/eval-rename/eval-rename.py
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/eval-rename.py
@@ -0,0 +1,88 @@
+#!/usr/bin/python
+"""
+A script to perform cross-file rename and evalute the results.
+
+Usage:
+
+$ cd /llvm-project
+$ ninja -C build clangd-indexer
+$ ./build/bin/clangd-indexer -format=binary -executor=all-TUs . > llvm-index.idx
+$ ninja -C build clangd-rename
+$ clang-tools-extra/clangd/eval-rename/eval-rename.py --index=llvm-index.idx --file=clang-tools-extra/clangd/eval-rename/symbol_to_rename.txt
+"""
+
+from __future__ import print_function
+
+import argparse
+import os
+import re
+import subprocess
+import sys
+import tempfile
+
+RENAME_EXECUTOR='build/bin/clangd-rename'
+
+def Run(cmd):
+  s = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+  print('>', ' '.join(cmd))
+  [stdout, stderr] = s.communicate()
+  return (s.returncode, stdout, stderr)
+
+if __name__ == '__main__':
+  if not os.getcwd().endswith('llvm-project'):
+sys.exit('The tool must be run from llvm-project/ root.')
+
+  ap = argparse.ArgumentParser()
+  ap.add_argument(
+  '-f',
+  '--file',
+  required=True,
+  help='A file containing rename symbols to be evaluted.'
+  )
+  ap.add_argument(
+  '-idx',
+  '--index',
+  required=True,
+  help='A path to the index file'
+  )
+  args = ap.parse_args()
+
+  with open(args.file) as f:
+out = f.read()
+  test_cases = [line.strip().split() for line in out.split('\n') \
+ if line and not line.startswith('#') and line.strip()]
+
+  log_output_dir = tempfile.mkdtemp(prefix='eval-rename_')
+  success_cnt = 0
+  for file_name, rename_symbol, verify_target in test_cases:
+Run(['git', 'reset', '--hard'])
+execute_rename_cmd = [
+  RENAME_EXECUTOR,
+   '--index-path=%s' % args.index,
+   '--rename-symbol=%s' % rename_symbol,
+   '-fix',
+   file_name,
+]
+rename_results = Run(execute_rename_cmd)
+if rename_results[0] != 0:
+  log_file = open(os.path.join(
+log_output_dir, rename_symbol.replace("::", "_") + '_RenameFailed'), 'w')
+  log_file.write(rename_results[1]) # stdout
+  log_file.write(rename_results[2]) # stderr
+  log_file.close()
+  continue
+
+build_results = Run(['ninja', '-C', 'build', verify_target])
+if build_results[0] != 0:
+  print('failed on renaming %s' % rename_symbol)
+  log_file = open(os.path.join(
+log_output_dir, rename_symbol.replace("::", "_") + '_BuildFailed'), 'w')
+  log_file.write(build_results[1]) # stdout
+  log_file.write(build_results[2]) # stderr
+  log_file.close()
+  continue
+print('succeed on renaming %s' % rename_symbol)
+success_cnt += 1
+  Run(['git', 'reset', '--hard'])
+  print('Evaluated rename on %d symbols, %d symbol succeeded, go %s for failure logs' %
+  (len(test_cases), success_cnt, log_output_dir))
Index: clang-tools-extra/clangd/eval-rename/RenameMain.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/eval-rename/RenameMain.cpp
@@ -0,0 +1,208 @@
+//===--- RenameMain.cpp --*- C++-*-===//
+//
+// Part of t

[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield updated this revision to Diff 247617.
JonChesterfield added a comment.

- Rename attribute, propose some documentation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74361

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/DeclBase.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-loader-uninitialized.cpp

Index: clang/test/Sema/attr-loader-uninitialized.cpp
===
--- /dev/null
+++ clang/test/Sema/attr-loader-uninitialized.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int good __attribute__((loader_uninitialized));
+const int still_cant_be_const __attribute__((loader_uninitialized)); // expected-error {{default initialization of an object of const type}}
+extern int external __attribute__((loader_uninitialized));
+
+void func() __attribute__((loader_uninitialized)) // expected-warning {{'loader_uninitialized' attribute only applies to global variables}}
+{
+  int local __attribute__((loader_uninitialized)); // expected-warning {{'loader_uninitialized' attribute only applies to global variables}}
+
+  static int sl __attribute__((loader_uninitialized));
+}
+
+struct s {
+  __attribute__((loader_uninitialized)) int field; // expected-warning {{'loader_uninitialized' attribute only applies to global variables}}
+
+  static __attribute__((loader_uninitialized)) int sfield;
+
+} __attribute__((loader_uninitialized)); // expected-warning {{'loader_uninitialized' attribute only applies to global variables}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -65,6 +65,7 @@
 // CHECK-NEXT: InitPriority (SubjectMatchRule_variable)
 // CHECK-NEXT: InternalLinkage (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record)
 // CHECK-NEXT: LTOVisibilityPublic (SubjectMatchRule_record)
+// CHECK-NEXT: LoaderUninitialized (SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: Lockable (SubjectMatchRule_record)
 // CHECK-NEXT: MIGServerRoutine (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_block)
 // CHECK-NEXT: MSStruct (SubjectMatchRule_record)
Index: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/attr-loader-uninitialized.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++11 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: @_ZZ4funcvE4data = internal global i32 undef
+int* func(void)
+{
+  static int data [[clang::loader_uninitialized]];
+  return &data;
+}
+
+// No code emitted
+extern int extern_unhelpful_but_harmless [[clang::loader_uninitialized]];
+
+// CHECK: @tentative = global i32 undef
+int tentative  [[clang::loader_uninitialized]];
+
+// CHECK: @_ZL16tentative_static = internal global i32 undef
+static int tentative_static [[clang::loader_uninitialized]] __attribute__((used));
+
+// CHECK: @nominally_zero_init = global i32 undef
+int nominally_zero_init  [[clang::loader_uninitialized]] = 0;
+
+// CHECK: @nominally_value_init = global i32 undef
+int nominally_value_init  [[clang::loader_uninitialized]] = 4;
+
+class trivial
+{
+  float x;
+};
+
+// CHECK: @ut = global %class.trivial undef
+trivial ut [[clang::loader_uninitialized]];
+
+struct nontrivial
+{
+  nontrivial() : x(3.14) {}
+  double x;
+};
+
+// CHECK: @unt = global %struct.nontrivial undef
+nontrivial unt [[clang::loader_uninitialized]];
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6505,6 +6505,11 @@
   D->addAttr(::new (S.Context) UninitializedAttr(S.Context, AL));
 }
 
+static void handleLoaderUninitializedAttr(Sema &S, Decl *D,
+const ParsedAttr &AL) {
+  D->addAttr(::new (S.Context) LoaderUninitializedAttr(S.Context, AL));
+}
+
 static bool tryMakeVariablePseudoStrong(Sema &S, VarDecl *VD,
 bool DiagnoseFailure) {
   QualType Ty = VD->getType();
@@ -7427,6 +7432,10 @@
 handleUninitializedAttr(S, D, AL);
 break;
 
+  case ParsedAttr::AT_LoaderUninitialized:
+handleLoaderUninitializedAttr(S, D, AL);
+break;
+
   case ParsedAttr::AT_ObjCExternallyRetained:
 handleObjCExternallyRetainedAttr(S, D, AL);
 break;
Index: clang/lib/CodeGen/CodeGenModule.cpp

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

2020-03-02 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:355
+  template 
+  void checkRealloc(CheckerContext &C, const CallExpr *CE,
+ProgramStateRef State) const;

The `CHECK_FN` could be used even here?
```
template 
CHECK_FN(checkRealloc)
```



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:1184
+checkCXXNewOrCXXDelete(C, CE, State);
+
+  checkOwnershipAttr(C, CE, State);

If these cases are exclusive the code looks better when `else` statements are 
added?


Repository:
  rG LLVM Github Monorepo

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] D75368: [clang-format] Handle NullCoalescing and NullConditional operators in C#

2020-03-02 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc3af063c2bbf: [clang-format] Handle NullCoalescing and 
NullConditional operators in C# (authored by Jonathan Coe 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75368

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -170,6 +170,12 @@
   verifyFormat("public override string ToString() => \"{Name}\\{Age}\";");
 }
 
+TEST_F(FormatTestCSharp, CSharpConditionalExpressions) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+  // conditional expression is not seen as a NullConditional.
+  verifyFormat("var y = A < B ? -1 : 1;", Style);
+}
+
 TEST_F(FormatTestCSharp, CSharpNullConditional) {
   FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
   Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -972,6 +972,13 @@
   }
   break;
 case tok::question:
+  if (Tok->is(TT_CSharpNullConditionalSq)) {
+if (!parseSquare())
+  return false;
+break;
+  }
+  if (Tok->isOneOf(TT_CSharpNullConditional, TT_CSharpNullCoalescing))
+break;
   if (Style.Language == FormatStyle::LK_JavaScript && Tok->Next &&
   Tok->Next->isOneOf(tok::semi, tok::comma, tok::colon, tok::r_paren,
  tok::r_brace)) {
@@ -987,9 +994,11 @@
   if (Line.MustBeDeclaration && !Contexts.back().IsExpression &&
   Style.Language == FormatStyle::LK_JavaScript)
 break;
-  if (Style.isCSharp() && Line.MustBeDeclaration) {
-Tok->Type = TT_CSharpNullableTypeQuestionMark;
-break;
+  if (Style.isCSharp()) {
+if (Line.MustBeDeclaration && !Contexts.back().IsExpression) {
+  Tok->Type = TT_CSharpNullable;
+  break;
+}
   }
   parseConditional();
   break;
@@ -1437,6 +1446,21 @@
   // The token type is already known.
   return;
 
+if (Style.isCSharp() && CurrentToken->is(tok::question)) {
+  if (CurrentToken->TokenText == "??") {
+Current.Type = TT_CSharpNullCoalescing;
+return;
+  }
+  if (CurrentToken->TokenText == "?.") {
+Current.Type = TT_CSharpNullConditional;
+return;
+  }
+  if (CurrentToken->TokenText == "?[") {
+Current.Type = TT_CSharpNullConditionalSq;
+return;
+  }
+}
+
 if (Style.Language == FormatStyle::LK_JavaScript) {
   if (Current.is(tok::exclaim)) {
 if (Current.Previous &&
@@ -2907,9 +2931,29 @@
   return Style.SpacesInSquareBrackets;
 
 // No space before ? in nullable types.
-if (Right.is(TT_CSharpNullableTypeQuestionMark))
+if (Right.is(TT_CSharpNullable))
+  return false;
+
+// Require space after ? in nullable types.
+if (Left.is(TT_CSharpNullable))
+  return true;
+
+// No space before or after '?.'.
+if (Left.is(TT_CSharpNullConditional) || Right.is(TT_CSharpNullConditional))
   return false;
 
+// Space before and after '??'.
+if (Left.is(TT_CSharpNullCoalescing) || Right.is(TT_CSharpNullCoalescing))
+  return true;
+
+// No space before '?['.
+if (Right.is(TT_CSharpNullConditionalSq))
+  return false;
+
+// Possible space inside `?[ 0 ]`.
+if (Left.is(TT_CSharpNullConditionalSq))
+  return Style.SpacesInSquareBrackets;
+
 // space between keywords and paren e.g. "using ("
 if (Right.is(tok::l_paren))
   if (Left.isOneOf(tok::kw_using, Keywords.kw_async, Keywords.kw_when))
Index: clang/lib/Format/FormatTokenLexer.h
===
--- clang/lib/Format/FormatTokenLexer.h
+++ clang/lib/Format/FormatTokenLexer.h
@@ -52,8 +52,8 @@
   bool tryMergeJSPrivateIdentifier();
   bool tryMergeCSharpStringLiteral();
   bool tryMergeCSharpKeywordVariables();
-  bool tryMergeCSharpNullConditionals();
   bool tryMergeCSharpDoubleQuestion();
+  bool tryMergeCSharpNullConditional();
   bool tryTransformCSharpForEach();
   bool tryMergeCSharpAttributeAndTarget();
 
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -84,7 +84,7 @@
   return;
 if (tryMergeCSharpDoubleQuestion())
   return;
-if (tryMer

[clang-tools-extra] 9ad1099 - [clangd] No need to query ctor refs in cross-file rename.

2020-03-02 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-03-02T15:21:32+01:00
New Revision: 9ad109922450ce3519a5431c72cdc9d4c20a18bf

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

LOG: [clangd] No need to query ctor refs in cross-file rename.

Summary:
This patch reverts 
https://github.com/llvm/llvm-project/commit/2c5ee78de113484978450b834498e1b0e2aab5c4,
now kythe (https://github.com/kythe/kythe/issues/4381) supports returning ctors 
refs as part of class references, so
there is no need to query the ctor refs in the index (this would also
make the results worse, lots of duplications)

Reviewers: sammccall

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

Tags: #clang

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/Rename.cpp 
b/clang-tools-extra/clangd/refactor/Rename.cpp
index 16dfef316a27..54112e09f0f9 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -295,23 +295,6 @@ Range toRange(const SymbolLocation &L) {
   return R;
 }
 
-std::vector getConstructors(const NamedDecl *ND) {
-  std::vector Ctors;
-  if (const auto *RD = dyn_cast(ND)) {
-if (!RD->hasUserDeclaredConstructor())
-  return {};
-for (const CXXConstructorDecl *Ctor : RD->ctors())
-  Ctors.push_back(Ctor);
-for (const auto *D : RD->decls()) {
-  if (const auto *FTD = dyn_cast(D))
-if (const auto *Ctor =
-dyn_cast(FTD->getTemplatedDecl()))
-  Ctors.push_back(Ctor);
-}
-  }
-  return Ctors;
-}
-
 // Return all rename occurrences (using the index) outside of the main file,
 // grouped by the absolute file path.
 llvm::Expected>>
@@ -321,14 +304,6 @@ findOccurrencesOutsideFile(const NamedDecl &RenameDecl,
   trace::Span Tracer("FindOccurrencesOutsideFile");
   RefsRequest RQuest;
   RQuest.IDs.insert(*getSymbolID(&RenameDecl));
-  // Classes and their constructors are 
diff erent symbols, and have 
diff erent
-  // symbol ID.
-  // When querying references for a class, clangd's own index will also return
-  // references of the corresponding class constructors, but this is not true
-  // for all index backends, e.g. kythe, so we add all constructors to the 
query
-  // request.
-  for (const auto *Ctor : getConstructors(&RenameDecl))
-RQuest.IDs.insert(*getSymbolID(Ctor));
 
   // Absolute file path => rename occurrences in that file.
   llvm::StringMap> AffectedFiles;

diff  --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp 
b/clang-tools-extra/clangd/unittests/RenameTests.cpp
index 9906d6b3c29d..55d78a82ab56 100644
--- a/clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -798,53 +798,6 @@ TEST(CrossFileRenameTests, DirtyBuffer) {
   testing::HasSubstr("too many occurrences"));
 }
 
-TEST(CrossFileRename, QueryCtorInIndex) {
-  const auto MainCode = Annotations("F^oo f;");
-  auto TU = TestTU::withCode(MainCode.code());
-  TU.HeaderCode = R"cpp(
-class Foo {
-public:
-  Foo() = default;
-};
-  )cpp";
-  auto AST = TU.build();
-
-  RefsRequest Req;
-  class RecordIndex : public SymbolIndex {
-  public:
-RecordIndex(RefsRequest *R) : Out(R) {}
-bool refs(const RefsRequest &Req,
-  llvm::function_ref Callback) const override {
-  *Out = Req;
-  return false;
-}
-
-bool fuzzyFind(const FuzzyFindRequest &,
-   llvm::function_ref) const override {
-  return false;
-}
-void lookup(const LookupRequest &,
-llvm::function_ref) const override {}
-
-void relations(const RelationsRequest &,
-   llvm::function_ref)
-const override {}
-size_t estimateMemoryUsage() const override { return 0; }
-
-RefsRequest *Out;
-  } RIndex(&Req);
-  auto Results = rename({MainCode.point(),
- "NewName",
- AST,
- testPath("main.cc"),
- &RIndex,
- {/*CrossFile=*/true}});
-  ASSERT_TRUE(bool(Results)) << Results.takeError();
-  const auto HeaderSymbols = TU.headerSymbols();
-  EXPECT_THAT(Req.IDs,
-  testing::Contains(findSymbol(HeaderSymbols, "Foo::Foo").ID));
-}
-
 TEST(CrossFileRenameTests, DeduplicateRefsFromIndex) {
   auto MainCode = Annotations("int [[^x]] = 2;");
   auto MainFilePath = testPath("main.cc");



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

[PATCH] D74973: [analyzer] StdLibraryFunctionsChecker refactor w/ inheritance

2020-03-02 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

I have some high level questions, you have spent far more time with this code 
and I'm happy to be proven wrong! :)

In D74973#1889188 , @martong wrote:

> > Is really more kind of constraint needed than range constraint?
>
> Yes, there are other constraints I am planning to implement:
>
> - Size requirements E.g.: asctime_s(char *buf, rsize_t bufsz, const struct tm 
> *time_ptr); `buf` size must be at least `bufsz`.
> - Not-null
> - Not-uninitalized
> - Not-tainted


Are we really sure that we need to express that with constraints? Can't we just 
change the name of `ValueRange` (or encapsulate it in another class) and add 
more fields to it, such as taintedness or initializedness? Is there an 
incentive to keep `ValueRange` lean?

This doesn't look too bad:

  auto Getc = [&]() {
return Summary(ArgTypes{Irrelevant}, RetType{IntTy}, NoEvalCall)
.Case(
{ReturnValueDescription(RangeConstraints(WithinRange, {{EOFv, 
EOFv}, {0, UCharMax}},
Tainted, Non_Uninitialized});
  };



>> A non-null can be represented as range constraint too.
> 
> Actually, to implement that we should have a branch in all 
> `ValueRange::apply*` functions that handles `Loc` SVals. Unfortunately, a 
> pointer cannot be handled as `NonLoc`, and the current Range based 
> implementation handles `NonLoc`s only.

So, why didn't we take that route instead? Marking a pointer non-null seems to 
be a less invasive change.

>> The compare constraint is used only for the return value for which a special 
>> `ReturnConstraint` can be used to handle the return value not like a normal 
>> argument (and then the `Ret` special value is not needed).
> 
> The Compare constraint is already forced into a Range "concept" whereas it 
> has nothing to do with ranges. By handling compare constraints separately, we 
> attach a single responsibility to each constraint class, instead of having a 
> monolithic god constraint class. Take a look at this coerced data 
> representation that we have today in ValueRange:
> 
>   BinaryOperator::Opcode getOpcode() const {
> assert(Kind == ComparesToArgument);
> assert(Args.size() == 1);
> BinaryOperator::Opcode Op =
> static_cast(Args[0].first);
> assert(BinaryOperator::isComparisonOp(Op) &&
>"Only comparison ops are supported for ComparesToArgument");
> return Op;
>   }
>
> 
> Subclasses are a good way to get rid of this not-so-intuitive structure and 
> assertions.

Having more fields feels like another possible solution.




Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:151
+
+  using ValueConstraintPtr = std::shared_ptr;
+  /// The complete list of constraints that defines a single branch.

gamesh411 wrote:
> martong wrote:
> > Note here, we need a copyable, polymorphic and default initializable type 
> > (vector needs that). A raw pointer were good, however, we cannot default 
> > initialize that. unique_ptr makes the Summary class non-copyable, therefore 
> > not an option.
> > Releasing the copyablitly requirement would render the initialization of 
> > the Summary map infeasible.
> > Perhaps we could come up with a [[ 
> > https://www.youtube.com/watch?v=bIhUE5uUFOA | type erasure technique 
> > without inheritance ]] once we consider the shared_ptr as restriction, but 
> > for now that seems to be overkill.
> std::variant (with std::monostate for the default constructibility) would 
> also be an option  (if c++17 were supported). But this is not really an 
> issue, i agree with that.
Ugh, we've historically been very hostile towards virtual functions. We don't 
mind them that much when they don't have to run a lot, like during bug report 
construction, but as a core part of the analysis, I'm not sure what the current 
stance is on it.

I'm not inherently (haha) against it, and I'm fine with leaving this as-is for 
the time being, though I'd prefer if you placed a `TODO` to revisit this issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74973



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


[PATCH] D75429: [clangd] DefineOutline won't copy virtual specifiers on methods

2020-03-02 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 247620.
njames93 added a comment.

- Macro handling more in line with rest of clangd


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75429

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
@@ -2068,6 +2068,69 @@
   };)cpp",
   "Foo::Foo(int z) __attribute__((weak)) : bar(2){}\n",
   },
+  // Virt specifiers.
+  {
+  R"cpp(
+struct A {
+  virtual void f^oo() {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() ;
+};)cpp",
+  " void A::foo() {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() override {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() override ;
+};)cpp",
+  "void B::foo()  {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() final {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() final ;
+};)cpp",
+  "void B::foo()  {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() final override {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() final override ;
+};)cpp",
+  "void B::foo()   {}\n",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2081,6 +2144,8 @@
   llvm::StringMap EditedFiles;
   ExtraFiles["Test.cpp"] = "";
   FileName = "Test.hpp";
+  ExtraArgs.push_back("-DVIRTUAL=virtual");
+  ExtraArgs.push_back("-DOVER=override");
 
   struct {
 llvm::StringRef Test;
@@ -2118,6 +2183,42 @@
   #define TARGET foo
   void TARGET();)cpp",
"void TARGET(){ return; }"},
+  {R"cpp(#define VIRT virtual
+  struct A {
+VIRT void f^oo() {}
+  };)cpp",
+   R"cpp(#define VIRT virtual
+  struct A {
+VIRT void foo() ;
+  };)cpp",
+" void A::foo() {}\n",
+  },
+  {R"cpp(
+  struct A {
+VIRTUAL void f^oo() {}
+  };)cpp",
+   R"cpp(
+  struct A {
+VIRTUAL void foo() ;
+  };)cpp",
+" void A::foo() {}\n",
+  },
+  {R"cpp(
+  struct A {
+virtual void foo() = 0;
+  };
+  struct B : A {
+void fo^o() OVER {}
+  };)cpp",
+   R"cpp(
+  struct A {
+virtual void foo() = 0;
+  };
+  struct B : A {
+void foo() OVER ;
+  };)cpp",
+"void B::foo()  {}\n",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2229,6 +2330,49 @@
 << Case.TestHeader;
   }
 }
+
+TEST_F(DefineOutlineTest, FailsMacroSpecifier) {
+  FileName = "Test.hpp";
+  ExtraFiles["Test.cpp"] = "";
+  ExtraArgs.push_back("-DFINALOVER=final override");
+
+  std::pair Cases[] = {
+  {
+  R"cpp(
+  #define VIRT virtual void
+  struct A {
+VIRT fo^o() {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `virtual` specifier."},
+  {
+  R"cpp(
+  #define OVERFINAL final override
+  struct A {
+virtual void foo() {}
+  };
+  struct B : A {
+void fo^o() OVERFINAL {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `override` specifier.\ndefine outline: Can't move out of line "
+  "as function has a macro `final` specifier."},
+  {
+  R"cpp(
+  struct A {
+virtual void foo() {}
+  };
+  struct B : A {
+void fo^o() FINALOVER {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `override` specifier.\ndefine outline: Can't move out of line "
+  "as function has a macro `final` sp

[PATCH] D75429: [clangd] DefineOutline won't copy virtual specifiers on methods

2020-03-02 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 247621.
njames93 marked 3 inline comments as done.
njames93 added a comment.

- added virtual virtual


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75429

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
@@ -2068,6 +2068,80 @@
   };)cpp",
   "Foo::Foo(int z) __attribute__((weak)) : bar(2){}\n",
   },
+  // Virt specifiers.
+  {
+  R"cpp(
+struct A {
+  virtual void f^oo() {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() ;
+};)cpp",
+  " void A::foo() {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual virtual void virtual f^oo() {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual virtual void virtual foo() ;
+};)cpp",
+  "  void  A::foo() {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() override {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() override ;
+};)cpp",
+  "void B::foo()  {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() final {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() final ;
+};)cpp",
+  "void B::foo()  {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() final override {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() final override ;
+};)cpp",
+  "void B::foo()   {}\n",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2081,6 +2155,8 @@
   llvm::StringMap EditedFiles;
   ExtraFiles["Test.cpp"] = "";
   FileName = "Test.hpp";
+  ExtraArgs.push_back("-DVIRTUAL=virtual");
+  ExtraArgs.push_back("-DOVER=override");
 
   struct {
 llvm::StringRef Test;
@@ -2118,6 +2194,42 @@
   #define TARGET foo
   void TARGET();)cpp",
"void TARGET(){ return; }"},
+  {R"cpp(#define VIRT virtual
+  struct A {
+VIRT void f^oo() {}
+  };)cpp",
+   R"cpp(#define VIRT virtual
+  struct A {
+VIRT void foo() ;
+  };)cpp",
+" void A::foo() {}\n",
+  },
+  {R"cpp(
+  struct A {
+VIRTUAL void f^oo() {}
+  };)cpp",
+   R"cpp(
+  struct A {
+VIRTUAL void foo() ;
+  };)cpp",
+" void A::foo() {}\n",
+  },
+  {R"cpp(
+  struct A {
+virtual void foo() = 0;
+  };
+  struct B : A {
+void fo^o() OVER {}
+  };)cpp",
+   R"cpp(
+  struct A {
+virtual void foo() = 0;
+  };
+  struct B : A {
+void foo() OVER ;
+  };)cpp",
+"void B::foo()  {}\n",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2229,6 +2341,49 @@
 << Case.TestHeader;
   }
 }
+
+TEST_F(DefineOutlineTest, FailsMacroSpecifier) {
+  FileName = "Test.hpp";
+  ExtraFiles["Test.cpp"] = "";
+  ExtraArgs.push_back("-DFINALOVER=final override");
+
+  std::pair Cases[] = {
+  {
+  R"cpp(
+  #define VIRT virtual void
+  struct A {
+VIRT fo^o() {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `virtual` specifier."},
+  {
+  R"cpp(
+  #define OVERFINAL final override
+  struct A {
+virtual void foo() {}
+  };
+  struct B : A {
+void fo^o() OVERFINAL {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `override` specifier.\ndefine outline: Can't move out of line "
+  "as function has a macro `final` specifier."},
+  {
+  R"cpp(
+  struct A {
+virtual void foo() 

[PATCH] D75439: [clangd] No need to query ctor refs in cross-file rename.

2020-03-02 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9ad109922450: [clangd] No need to query ctor refs in 
cross-file rename. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75439

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
@@ -798,53 +798,6 @@
   testing::HasSubstr("too many occurrences"));
 }
 
-TEST(CrossFileRename, QueryCtorInIndex) {
-  const auto MainCode = Annotations("F^oo f;");
-  auto TU = TestTU::withCode(MainCode.code());
-  TU.HeaderCode = R"cpp(
-class Foo {
-public:
-  Foo() = default;
-};
-  )cpp";
-  auto AST = TU.build();
-
-  RefsRequest Req;
-  class RecordIndex : public SymbolIndex {
-  public:
-RecordIndex(RefsRequest *R) : Out(R) {}
-bool refs(const RefsRequest &Req,
-  llvm::function_ref Callback) const override {
-  *Out = Req;
-  return false;
-}
-
-bool fuzzyFind(const FuzzyFindRequest &,
-   llvm::function_ref) const override {
-  return false;
-}
-void lookup(const LookupRequest &,
-llvm::function_ref) const override {}
-
-void relations(const RelationsRequest &,
-   llvm::function_ref)
-const override {}
-size_t estimateMemoryUsage() const override { return 0; }
-
-RefsRequest *Out;
-  } RIndex(&Req);
-  auto Results = rename({MainCode.point(),
- "NewName",
- AST,
- testPath("main.cc"),
- &RIndex,
- {/*CrossFile=*/true}});
-  ASSERT_TRUE(bool(Results)) << Results.takeError();
-  const auto HeaderSymbols = TU.headerSymbols();
-  EXPECT_THAT(Req.IDs,
-  testing::Contains(findSymbol(HeaderSymbols, "Foo::Foo").ID));
-}
-
 TEST(CrossFileRenameTests, DeduplicateRefsFromIndex) {
   auto MainCode = Annotations("int [[^x]] = 2;");
   auto MainFilePath = testPath("main.cc");
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -295,23 +295,6 @@
   return R;
 }
 
-std::vector getConstructors(const NamedDecl *ND) {
-  std::vector Ctors;
-  if (const auto *RD = dyn_cast(ND)) {
-if (!RD->hasUserDeclaredConstructor())
-  return {};
-for (const CXXConstructorDecl *Ctor : RD->ctors())
-  Ctors.push_back(Ctor);
-for (const auto *D : RD->decls()) {
-  if (const auto *FTD = dyn_cast(D))
-if (const auto *Ctor =
-dyn_cast(FTD->getTemplatedDecl()))
-  Ctors.push_back(Ctor);
-}
-  }
-  return Ctors;
-}
-
 // Return all rename occurrences (using the index) outside of the main file,
 // grouped by the absolute file path.
 llvm::Expected>>
@@ -321,14 +304,6 @@
   trace::Span Tracer("FindOccurrencesOutsideFile");
   RefsRequest RQuest;
   RQuest.IDs.insert(*getSymbolID(&RenameDecl));
-  // Classes and their constructors are different symbols, and have different
-  // symbol ID.
-  // When querying references for a class, clangd's own index will also return
-  // references of the corresponding class constructors, but this is not true
-  // for all index backends, e.g. kythe, so we add all constructors to the query
-  // request.
-  for (const auto *Ctor : getConstructors(&RenameDecl))
-RQuest.IDs.insert(*getSymbolID(Ctor));
 
   // Absolute file path => rename occurrences in that file.
   llvm::StringMap> AffectedFiles;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75350: [OpenMP] Allow const parameters in declare simd linear clause

2020-03-02 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli accepted this revision.
fpetrogalli added a comment.

LGTM, thank you @huntergr !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75350



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


[PATCH] D73898: [analyzer] StdLibraryFunctionsChecker: Add argument constraints

2020-03-02 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

The high level idea and the implementation of the checker seems great. In 
general, things that you want to address in later patches should be stated in 
the code with a `TODO`. I wrote a couple nits that I don't want to delete, but 
maybe it'd be better to address them after the dependency patch is agreed upon.




Comment at: clang/include/clang/StaticAnalyzer/Checkers/Checkers.td:296
+def StdCLibraryFunctionArgsChecker : Checker<"StdCLibraryFunctionArgs">,
+  HelpText<"Check constraints of arguments of C standard library functions">,
+  Dependencies<[StdCLibraryFunctionsChecker]>,

How about we add an example as well?



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:161
+
+ValueRange negate() const {
+  ValueRange tmp(*this);

Maybe `complement` would be a better name? That sounds a lot more like a set 
operation. Also, this function highlights well that inheritance might not be 
the best solution here.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:191
+  ///   * a list of branches - a list of list of ranges -
+  /// i.e. a list of lists of lists of segments,
+  ///   * a list of argument constraints, that must be true on every branch.

I think that is a rather poor example to help understand what `list of list of 
ranges` means :) -- Could you try to find something better?



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:10
 // This checker improves modeling of a few simple library functions.
 // It does not generate warnings.
 //

I suspect this comment is no longer relevant.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:399-407
+  auto Report = [&](ExplodedNode *N) {
+if (!ChecksEnabled[CK_StdCLibraryFunctionArgsChecker])
+  return;
+// FIXME Add detailed diagnostic.
+StringRef Msg = "Function argument constraint is not satisfied";
+auto R = std::make_unique(BT, Msg, N);
+bugreporter::trackExpressionValue(N, Call.getArgExpr(0), *R);

While I find your usage of lambdas fascinating, this one seems a bit 
unnecessary :)



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:402
+  return;
+// FIXME Add detailed diagnostic.
+StringRef Msg = "Function argument constraint is not satisfied";

That is a `TODO`, rather :^)



Comment at: clang/test/Analysis/std-c-library-functions-arg-constraints.c:1-7
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -triple x86_64-unknown-linux-gnu \
+// RUN:   -verify

Hmm, why do we have 2 different test files that essentially do the same? 
Shouldn't we only have a single one with `analyzer-output=text`?



Comment at: clang/test/Analysis/std-c-library-functions.c:1-31
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple i686-unknown-linux \
+// RUN:   -verify

What a beautiful sight. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73898



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


[PATCH] D74361: [Clang] Undef attribute for global variables

2020-03-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:4365
+The ``loader_uninitialized`` attribute can be placed on global variables to
+indicate that the variable does not need to be zero initialised by the loader.
+This is useful for variables that are always written to before use where the

initialised -> initialized



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7436
+  case ParsedAttr::AT_LoaderUninitialized:
+handleLoaderUninitializedAttr(S, D, AL);
+break;

If you don't need any custom semantic checking, you can remove that function 
and instead call `handleSimpleAttribute(S, D, AL);`



Comment at: clang/test/CodeGenCXX/attr-loader-uninitialized.cpp:14
+// CHECK: @tentative = global i32 undef
+int tentative  [[clang::loader_uninitialized]];
+

What should happen with redeclarations? e.g., in C:
```
int a;

int foo() { return a; }

int a __attribute__((loader_uninitialized));
```
(This would be a useful test case to add.)

Also, I'd like to see a test case where the attributed global is an array.



Comment at: clang/test/Sema/attr-loader-uninitialized.cpp:19
+
+} __attribute__((loader_uninitialized)); // expected-warning 
{{'loader_uninitialized' attribute only applies to global variables}}

I'd also like to see a test demonstrating it doesn't accept any arguments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74361



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


[PATCH] D75368: [clang-format] Handle NullCoalescing and NullConditional operators in C#

2020-03-02 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

Sorry, did the last round of comments not make sense?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75368



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


[clang] 1e30845 - [CodeGen] avoid running the entire optimizer pipeline in clang test file; NFC

2020-03-02 Thread Sanjay Patel via cfe-commits

Author: Sanjay Patel
Date: 2020-03-02T09:47:32-05:00
New Revision: 1e308452bf68b9576a76004de28307f0318ef9eb

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

LOG: [CodeGen] avoid running the entire optimizer pipeline in clang test file; 
NFC

I'm making the CHECK lines vague enough that they pass at -O0.
If that is too vague (we really want to check the data flow
to verify that the variables are not mismatched, etc), then
we can adjust those lines again to more closely match the output
at -O0 rather than -O1.

This change is based on the post-commit comments for:
https://github.com/llvm/llvm-project/commit/83f4372f3a708ceaa800feff8b1bd92ae2c3be5f
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20200224/307888.html

Added: 


Modified: 
clang/test/CodeGen/complex-math.c

Removed: 




diff  --git a/clang/test/CodeGen/complex-math.c 
b/clang/test/CodeGen/complex-math.c
index 22a9e287f07f..4d3869b085c6 100644
--- a/clang/test/CodeGen/complex-math.c
+++ b/clang/test/CodeGen/complex-math.c
@@ -1,5 +1,3 @@
-// FIXME: This file should not be using -O1; that makes it depend on the 
entire LLVM IR optimizer.
-
 // RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple x86_64-unknown-unknown -o - | FileCheck %s --check-prefix=X86
 // RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple x86_64-pc-win64 -o - | FileCheck %s --check-prefix=X86
 // RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple i686-unknown-unknown -o - | FileCheck %s --check-prefix=X86
@@ -7,7 +5,7 @@
 // RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple armv7-none-linux-gnueabi -o - | FileCheck %s --check-prefix=ARM
 // RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple armv7-none-linux-gnueabihf -o - | FileCheck %s --check-prefix=ARMHF
 // RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple thumbv7k-apple-watchos2.0 -o - -target-abi aapcs16 | FileCheck %s 
--check-prefix=ARM7K
-// RUN: %clang_cc1 %s -O1 -fno-experimental-new-pass-manager -emit-llvm 
-triple aarch64-unknown-unknown -ffast-math -o - | FileCheck %s 
--check-prefix=AARCH64-FASTMATH
+// RUN: %clang_cc1 %s -O0 -fno-experimental-new-pass-manager -emit-llvm 
-triple aarch64-unknown-unknown -ffast-math -o - | FileCheck %s 
--check-prefix=AARCH64-FASTMATH
 
 float _Complex add_float_rr(float a, float b) {
   // X86-LABEL: @add_float_rr(
@@ -137,23 +135,20 @@ float _Complex div_float_rc(float a, float _Complex b) {
   // AARCH64-FASTMATH-LABEL: @div_float_rc(float %a, [2 x float] %b.coerce)
   // A = a
   // B = 0
-  // AARCH64-FASTMATH: [[C:%.*]] = extractvalue [2 x float] %b.coerce, 0
-  // AARCH64-FASTMATH: [[D:%.*]] = extractvalue [2 x float] %b.coerce, 1
   //
-  // AARCH64-FASTMATH: [[AC:%.*]] = fmul fast float [[C]], %a
+  // AARCH64-FASTMATH: [[AC:%.*]] = fmul fast float
   // BD = 0
   // ACpBD = AC
   //
-  // AARCH64-FASTMATH: [[CC:%.*]] = fmul fast float [[C]], [[C]]
-  // AARCH64-FASTMATH: [[DD:%.*]] = fmul fast float [[D]], [[D]]
-  // AARCH64-FASTMATH: [[CCpDD:%.*]] = fadd fast float [[CC]], [[DD]]
+  // AARCH64-FASTMATH: [[CC:%.*]] = fmul fast float
+  // AARCH64-FASTMATH: [[DD:%.*]] = fmul fast float
+  // AARCH64-FASTMATH: [[CCpDD:%.*]] = fadd fast float
   //
   // BC = 0
-  // AARCH64-FASTMATH: [[NEGA:%.*]] = fneg fast float %a
-  // AARCH64-FASTMATH: [[AD:%.*]] = fmul fast float  [[D]], [[NEGA]]
+  // AARCH64-FASTMATH: [[AD:%.*]] = fmul fast float
   //
-  // AARCH64-FASTMATH: fdiv fast float [[AC]], [[CCpDD]]
-  // AARCH64-FASTMATH: fdiv fast float [[AD]], [[CCpDD]]
+  // AARCH64-FASTMATH: fdiv fast float
+  // AARCH64-FASTMATH: fdiv fast float
   // AARCH64-FASTMATH: ret
   return a / b;
 }
@@ -165,25 +160,21 @@ float _Complex div_float_cc(float _Complex a, float 
_Complex b) {
 
   // a / b = (A+iB) / (C+iD) = ((AC+BD)/(CC+DD)) + i((BC-AD)/(CC+DD))
   // AARCH64-FASTMATH-LABEL: @div_float_cc([2 x float] %a.coerce, [2 x float] 
%b.coerce)
-  // AARCH64-FASTMATH: [[A:%.*]] = extractvalue [2 x float] %a.coerce, 0
-  // AARCH64-FASTMATH: [[B:%.*]] = extractvalue [2 x float] %a.coerce, 1
-  // AARCH64-FASTMATH: [[C:%.*]] = extractvalue [2 x float] %b.coerce, 0
-  // AARCH64-FASTMATH: [[D:%.*]] = extractvalue [2 x float] %b.coerce, 1
   //
-  // AARCH64-FASTMATH: [[AC:%.*]] = fmul fast float [[C]], [[A]]
-  // AARCH64-FASTMATH: [[BD:%.*]] = fmul fast float [[D]], [[B]]
-  // AARCH64-FASTMATH: [[ACpBD:%.*]] = fadd fast float [[AC]], [[BD]]
+  // AARCH64-FASTMATH: [[AC:%.*]] = fmul fast float
+  // AARCH64-FASTMATH: [[BD:%.*]] = fmul fast float
+  // AARCH64-FASTMATH: [[ACpBD:%.*]] = fadd fast float
   //
-  // AARCH64-FASTMATH: [[CC:%.*]] = fmul fast float [[C]], [[C]]
-  // AARCH64-FA

[PATCH] D75453: [Driver][ARM] fix undefined behaviour when checking architecture version

2020-03-02 Thread Jan Ole Hüser via Phabricator via cfe-commits
j0le created this revision.
j0le added a reviewer: compnerd.
j0le added a project: clang.
Herald added a subscriber: kristof.beyls.

Hello everyone,

this is my first patch to/for clang. I hope, I did everything right. If not, 
please tell me.

I found this bug:
If you execute the following commandline multiple times, the behavior is not 
always the same:

  clang++ --target=thumbv7em-none-windows-eabi-coff -march=armv7-m 
-mcpu=cortex-m7 -o temp.obj -c -x c++ empty.cpp

where empty.cpp is an empty file in the current working directory.

Most of the time the compilation succeeds, but sometimes clang reports this 
error:

  clang++: error: the target architecture 'thumbv7em' is not supported by the 
target 'thumbv7em-none-windows-eabi'

With these commandline arguments, the variable Version is not set by 
getAsInteger() (see diff),
because it does not parse the substring "7em" of "thumbv7em".
To get a consistent behaviour, it's enough to initialize the variable Version 
to zero.
(Zero is smaller than 7, so the comparison will be true.)
Then the command always fails with the error message seen above.

I don't know, if this is the intended behaviour.
But if it isn't, I would suggest to use the function consumeInteger() instead.
And check the return value of course.

consumeInteger() is able to get 7 from "7em".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75453

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


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3531,9 +3531,10 @@
   if (Triple.isOSWindows() && (Triple.getArch() == llvm::Triple::arm ||
Triple.getArch() == llvm::Triple::thumb)) {
 unsigned Offset = Triple.getArch() == llvm::Triple::arm ? 4 : 6;
-unsigned Version;
-Triple.getArchName().substr(Offset).getAsInteger(10, Version);
-if (Version < 7)
+unsigned Version = 0;
+bool Failure =
+Triple.getArchName().substr(Offset).consumeInteger(10, Version);
+if (Failure || Version < 7)
   D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName()
 << TripleStr;
   }


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3531,9 +3531,10 @@
   if (Triple.isOSWindows() && (Triple.getArch() == llvm::Triple::arm ||
Triple.getArch() == llvm::Triple::thumb)) {
 unsigned Offset = Triple.getArch() == llvm::Triple::arm ? 4 : 6;
-unsigned Version;
-Triple.getArchName().substr(Offset).getAsInteger(10, Version);
-if (Version < 7)
+unsigned Version = 0;
+bool Failure =
+Triple.getArchName().substr(Offset).consumeInteger(10, Version);
+if (Failure || Version < 7)
   D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName()
 << TripleStr;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75356: [Analyzer][StreamChecker] Introduction of stream error state handling.

2020-03-02 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:50-68
+struct StreamErrorState {
+  // The error state of an opened stream.
+  // EofError: EOF condition (feof returns true)
+  // OtherError: other (non-EOF) error (ferror returns true)
+  // AnyError: EofError or OtherError
+  enum Kind { EofError, OtherError, AnyError } K;
+

Shouldn't we merge this with `StreamState`?



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:92-125
+class MakeRetVal {
+  const CallExpr *CE = nullptr;
+  std::unique_ptr RetVal;
+  SymbolRef RetSym;
+
+public:
+  MakeRetVal(const CallEvent &Call, CheckerContext &C)

Do you have other patches that really crave the need for this class? Why isn't 
`CallEvent::getReturnValue` sufficient? This is a legitimate question, I really 
don't know. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75356



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


[clang] ad49765 - [OpenMP] Allow const parameters in declare simd linear clause

2020-03-02 Thread Graham Hunter via cfe-commits

Author: Graham Hunter
Date: 2020-03-02T14:54:14Z
New Revision: ad497658d25a3616e4c57cf7d12e3497a1c66f35

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

LOG: [OpenMP] Allow const parameters in declare simd linear clause

Reviewers: ABataev, kkwli0, jdoerfert, fpetrogalli

Reviewed By: ABataev, fpetrogalli

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/declare_simd_aarch64.c
clang/test/OpenMP/declare_simd_codegen.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2d7676e23cfc..f1dfe411983a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10173,7 +10173,8 @@ class Sema final {
   /// Checks that the specified declaration matches requirements for the linear
   /// decls.
   bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
- OpenMPLinearClauseKind LinKind, QualType Type);
+ OpenMPLinearClauseKind LinKind, QualType Type,
+ bool IsDeclareSimd = false);
 
   /// Called on well-formed '\#pragma omp declare simd' after parsing of
   /// the associated method/function.

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 6aaf70918d02..de732577c81b 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5269,7 +5269,8 @@ Sema::DeclGroupPtrTy 
Sema::ActOnOpenMPDeclareSimdDirective(
   E->containsUnexpandedParameterPack())
 continue;
   (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind,
-  PVD->getOriginalType());
+  PVD->getOriginalType(),
+  /*IsDeclareSimd=*/true);
   continue;
 }
   }
@@ -5289,7 +5290,7 @@ Sema::DeclGroupPtrTy 
Sema::ActOnOpenMPDeclareSimdDirective(
   E->isInstantiationDependent() || 
E->containsUnexpandedParameterPack())
 continue;
   (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind,
-  E->getType());
+  E->getType(), /*IsDeclareSimd=*/true);
   continue;
 }
 Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause)
@@ -14547,8 +14548,8 @@ bool 
Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind,
 }
 
 bool Sema::CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
- OpenMPLinearClauseKind LinKind,
- QualType Type) {
+ OpenMPLinearClauseKind LinKind, QualType Type,
+ bool IsDeclareSimd) {
   const auto *VD = dyn_cast_or_null(D);
   // A variable must not have an incomplete type or a reference type.
   if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type))
@@ -14564,8 +14565,10 @@ bool Sema::CheckOpenMPLinearDecl(const ValueDecl *D, 
SourceLocation ELoc,
   // OpenMP 5.0 [2.19.3, List Item Privatization, Restrictions]
   // A variable that is privatized must not have a const-qualified type
   // unless it is of class type with a mutable member. This restriction does
-  // not apply to the firstprivate clause.
-  if (rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
+  // not apply to the firstprivate clause, nor to the linear clause on
+  // declarative directives (like declare simd).
+  if (!IsDeclareSimd &&
+  rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
 return true;
 
   // A list item must be of integral or pointer type.

diff  --git a/clang/test/OpenMP/declare_simd_aarch64.c 
b/clang/test/OpenMP/declare_simd_aarch64.c
index eff0eed07dfe..4af2ad9bb603 100644
--- a/clang/test/OpenMP/declare_simd_aarch64.c
+++ b/clang/test/OpenMP/declare_simd_aarch64.c
@@ -116,6 +116,15 @@ double c02(double *x, char y);
 // AARCH64: "_ZGVnM16uv_c02" "_ZGVnM8uv_c02"
 // AARCH64-NOT: c02
 
+//
+/* Linear with a constant parameter */
+//
+
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i);
+// AARCH64: "_ZGVnN2l_constlinear" "_ZGVnN4l_constlinear"
+// AARCH64-NOT: constlinear
+
 /*/
 /* sincos-like signature */
 /*/
@@ -170,6 +179,7 @@ void do_something() {
   D = b03(D);
   *I = c01(D, *S);
   *D = c02(D, *S);
+  constlinear(*I);
   sincos(*D, D, D);
   SinCos(*D, D, D);
   foo2(I, *I);

diff  --git a/clang/test/OpenMP/declare_simd_codegen.cpp 
b/clang/test/OpenMP/declare_simd_co

[PATCH] D75181: [AArch64] Handle BTI/PAC in case of generated functions.

2020-03-02 Thread Momchil Velikov via Phabricator via cfe-commits
chill added a comment.

That said, my comments are not of the "over my dead body" kind ;)




Comment at: clang/lib/CodeGen/CGCall.cpp:1828
+  if (CodeGenOpts.BranchTargetEnforcement) {
+FuncAttrs.addAttribute("branch-target-enforcement", "true");
+  }

I would really prefer to not set values "true" or "false" for the attribute: we 
don't really have tri-state logic there (absent/present-true/present-false), 
and those values just add some not-very useful string processing.




Comment at: clang/lib/CodeGen/CGCall.cpp:1831
+
+  auto RASignKind = CodeGenOpts.getSignReturnAddress();
+  if (RASignKind != CodeGenOptions::SignReturnAddressScope::None) {

What do we get from setting the PACBTI state in the  default function 
attributes? We still have 
to do a per function processing, we can just as well avoid repeating the logic, 
and spare us some
adding and potentially removing attributes churn.




Comment at: llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp:200
+if (!F.hasFnAttribute("branch-target-enforcement"))
+  return false;
+Attribute A = F.getFnAttribute("branch-target-enforcement");

This should be "true", although the comment might turn out moot.

If we somehow end up with a function, that does not have that attribute, we 
should clear the
ELF flag.




Comment at: llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp:201-202
+  return false;
+Attribute A = F.getFnAttribute("branch-target-enforcement");
+return !A.isStringAttribute() || A.getValueAsString() == "false";
   })) {

... that kind of string processing, here and elsewhere.



Comment at: llvm/lib/Target/AArch64/AArch64BranchTargets.cpp:62-66
+  Attribute A = F.getFnAttribute("branch-target-enforcement");
+  if (A.isStringAttribute() && A.getValueAsString() == "false")
+return false;
+
+  if (!F.hasFnAttribute("branch-target-enforcement") &&

Isn't there some redundancy with the two calls to `getFnAttribute` and to 
`hasFnAttribute` ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75181



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


[PATCH] D74131: [analyzer][taint] Add isTainted debug expression inspection check

2020-03-02 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

LGTM, thanks! Feel free to commit as you're ready.




Comment at: clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp:97
 .Case("clang_analyzer_express", &ExprInspectionChecker::analyzerExpress)
+.StartsWith("clang_analyzer_isTainted", 
&ExprInspectionChecker::analyzerIsTainted)
 .Default(nullptr);

Szelethus wrote:
> xazax.hun wrote:
> > I think a comment somewhere why/when do we check only the prefix would be 
> > useful.
> This isn't done?
The documentation shows plenty of other similar debug functions, I think this 
patch is fine in this regard.


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

https://reviews.llvm.org/D74131



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


[PATCH] D75181: [AArch64] Handle BTI/PAC in case of generated functions.

2020-03-02 Thread Momchil Velikov via Phabricator via cfe-commits
chill added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp:200
+if (!F.hasFnAttribute("branch-target-enforcement"))
+  return false;
+Attribute A = F.getFnAttribute("branch-target-enforcement");

chill wrote:
> This should be "true", although the comment might turn out moot.
> 
> If we somehow end up with a function, that does not have that attribute, we 
> should clear the
> ELF flag.
> 
Oh, I see, those are the cases of sanitizer functions, created at LLVM level, 
that don't have the attribute.
Please, leave a comment in that sense.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75181



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


[PATCH] D75350: [OpenMP] Allow const parameters in declare simd linear clause

2020-03-02 Thread Graham Hunter via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGad497658d25a: [OpenMP] Allow const parameters in declare 
simd linear clause (authored by huntergr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75350

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_simd_aarch64.c
  clang/test/OpenMP/declare_simd_codegen.cpp

Index: clang/test/OpenMP/declare_simd_codegen.cpp
===
--- clang/test/OpenMP/declare_simd_codegen.cpp
+++ clang/test/OpenMP/declare_simd_codegen.cpp
@@ -114,6 +114,9 @@
 #pragma omp declare simd notinbranch
 double foo(double x) { return 0; }
 
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i) { return 0.0; }
+
 // CHECK-DAG: define {{.+}}@_Z5add_1Pf(
 // CHECK-DAG: define {{.+}}@_Z1hIiEvPT_S1_S1_S1_(
 // CHECK-DAG: define {{.+}}@_Z1hIfEvPT_S1_S1_S1_(
@@ -131,6 +134,7 @@
 // CHECK-DAG: define {{.+}}@_Z3fooPffi(
 // CHECK-DAG: define {{.+}}@_Z3food(
 // CHECK-DAG: declare {{.+}}@_Z5add_2Pf(
+// CHECK-DAG: define {{.+}}@_Z11constlineari(
 
 // CHECK-DAG: "_ZGVbM4l8__Z5add_1Pf"
 // CHECK-DAG: "_ZGVbN4l8__Z5add_1Pf"
@@ -320,6 +324,11 @@
 // CHECK-DAG: "_ZGVdN4v__Z3food"
 // CHECK-DAG: "_ZGVeN8v__Z3food"
 
+// CHECK-DAG: "_ZGVbN2l__Z11constlineari"
+// CHECK-DAG: "_ZGVcN4l__Z11constlineari"
+// CHECK-DAG: "_ZGVdN4l__Z11constlineari"
+// CHECK-DAG: "_ZGVeN8l__Z11constlineari"
+
 // CHECK-NOT: "_ZGV{{.+}}__Z1fRA_i
 
 #endif
Index: clang/test/OpenMP/declare_simd_aarch64.c
===
--- clang/test/OpenMP/declare_simd_aarch64.c
+++ clang/test/OpenMP/declare_simd_aarch64.c
@@ -116,6 +116,15 @@
 // AARCH64: "_ZGVnM16uv_c02" "_ZGVnM8uv_c02"
 // AARCH64-NOT: c02
 
+//
+/* Linear with a constant parameter */
+//
+
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i);
+// AARCH64: "_ZGVnN2l_constlinear" "_ZGVnN4l_constlinear"
+// AARCH64-NOT: constlinear
+
 /*/
 /* sincos-like signature */
 /*/
@@ -170,6 +179,7 @@
   D = b03(D);
   *I = c01(D, *S);
   *D = c02(D, *S);
+  constlinear(*I);
   sincos(*D, D, D);
   SinCos(*D, D, D);
   foo2(I, *I);
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -5269,7 +5269,8 @@
   E->containsUnexpandedParameterPack())
 continue;
   (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind,
-  PVD->getOriginalType());
+  PVD->getOriginalType(),
+  /*IsDeclareSimd=*/true);
   continue;
 }
   }
@@ -5289,7 +5290,7 @@
   E->isInstantiationDependent() || E->containsUnexpandedParameterPack())
 continue;
   (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind,
-  E->getType());
+  E->getType(), /*IsDeclareSimd=*/true);
   continue;
 }
 Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause)
@@ -14547,8 +14548,8 @@
 }
 
 bool Sema::CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
- OpenMPLinearClauseKind LinKind,
- QualType Type) {
+ OpenMPLinearClauseKind LinKind, QualType Type,
+ bool IsDeclareSimd) {
   const auto *VD = dyn_cast_or_null(D);
   // A variable must not have an incomplete type or a reference type.
   if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type))
@@ -14564,8 +14565,10 @@
   // OpenMP 5.0 [2.19.3, List Item Privatization, Restrictions]
   // A variable that is privatized must not have a const-qualified type
   // unless it is of class type with a mutable member. This restriction does
-  // not apply to the firstprivate clause.
-  if (rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
+  // not apply to the firstprivate clause, nor to the linear clause on
+  // declarative directives (like declare simd).
+  if (!IsDeclareSimd &&
+  rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
 return true;
 
   // A list item must be of integral or pointer type.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10173,7 +10173,8 @@
   /// Checks that the specified declaration matches requirements for the linear
   /// decls.
   bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation 

[PATCH] D75455: [clang-format] Allow nested [] in C# attributes

2020-03-02 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe created this revision.
jbcoe added a reviewer: krasimir.
jbcoe added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Keep track of unpaired [] when identifying C# attribute lines


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75455

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -273,6 +273,15 @@
"{\n"
"}");
 
+  // [] in an attribute do not cause premature line wrapping or indenting.
+  verifyFormat(R"(//
+public class A
+{
+[SomeAttribute(new[] { RED, GREEN, BLUE }, -1.0f, 1.0f)]
+[DoNotSerialize]
+public Data MemberVariable;
+})");
+
   //  Unwrappable lines go on a line of their own.
   // 'target:' is not treated as a label.
   // Modify Style to enforce a column limit.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -324,12 +324,21 @@
 }
 
 void UnwrappedLineParser::parseCSharpAttribute() {
+  int UnpairedSquareBrackets = 1;
   do {
 switch (FormatTok->Tok.getKind()) {
 case tok::r_square:
   nextToken();
-  addUnwrappedLine();
-  return;
+  --UnpairedSquareBrackets;
+  if (UnpairedSquareBrackets == 0) {
+addUnwrappedLine();
+return;
+  }
+  break;
+case tok::l_square:
+  ++UnpairedSquareBrackets;
+  nextToken();
+  break;
 default:
   nextToken();
   break;


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -273,6 +273,15 @@
"{\n"
"}");
 
+  // [] in an attribute do not cause premature line wrapping or indenting.
+  verifyFormat(R"(//
+public class A
+{
+[SomeAttribute(new[] { RED, GREEN, BLUE }, -1.0f, 1.0f)]
+[DoNotSerialize]
+public Data MemberVariable;
+})");
+
   //  Unwrappable lines go on a line of their own.
   // 'target:' is not treated as a label.
   // Modify Style to enforce a column limit.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -324,12 +324,21 @@
 }
 
 void UnwrappedLineParser::parseCSharpAttribute() {
+  int UnpairedSquareBrackets = 1;
   do {
 switch (FormatTok->Tok.getKind()) {
 case tok::r_square:
   nextToken();
-  addUnwrappedLine();
-  return;
+  --UnpairedSquareBrackets;
+  if (UnpairedSquareBrackets == 0) {
+addUnwrappedLine();
+return;
+  }
+  break;
+case tok::l_square:
+  ++UnpairedSquareBrackets;
+  nextToken();
+  break;
 default:
   nextToken();
   break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72041: [clangd] Handle go-to-definition in macro invocations where the target appears in the expansion multiple times

2020-03-02 Thread Nathan Ridge via Phabricator via cfe-commits
nridge marked an inline comment as done.
nridge added inline comments.



Comment at: clang-tools-extra/clangd/Selection.cpp:287
 if (SM.getFileID(ArgStart) == SelFile) {
-  SourceLocation ArgEnd = SM.getTopMacroCallerLoc(Batch.back().location());
-  return testTokenRange(SM.getFileOffset(ArgStart),
-SM.getFileOffset(ArgEnd));
+  if (isFirstExpansion(FID, ArgStart, SM)) {
+SourceLocation ArgEnd =

sammccall wrote:
> when false is the fallthrough to handling as if part of the macro body 
> deliberate?
> 
> Thinking about it I suppose either that or returning NoTokens works, but 
> please document it, e.g. `} else { /* fall through and treat as part of the 
> macro body */}`
It is deliberate. In fact, it is intended to address [this previous 
comment](https://reviews.llvm.org/D72041#inline-663000). Please let me know if 
I've misunderstood and the solution doesn't match the request.

I'll add a comment as you suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72041



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


[clang] 736385c - EHScopeStack::Cleanup has virtual functions so the destructor should be too.

2020-03-02 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-03-02T15:06:34Z
New Revision: 736385c0b49d42f398ffa1458883f0d182178ef4

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

LOG: EHScopeStack::Cleanup has virtual functions so the destructor should be 
too.

Fixes cppcheck warning.

Added: 


Modified: 
clang/lib/CodeGen/EHScopeStack.h

Removed: 




diff  --git a/clang/lib/CodeGen/EHScopeStack.h 
b/clang/lib/CodeGen/EHScopeStack.h
index 0ed67aabcd62..4dd3da3e90e7 100644
--- a/clang/lib/CodeGen/EHScopeStack.h
+++ b/clang/lib/CodeGen/EHScopeStack.h
@@ -148,7 +148,7 @@ class EHScopeStack {
 virtual void anchor();
 
   protected:
-~Cleanup() = default;
+virtual ~Cleanup() = default;
 
   public:
 Cleanup(const Cleanup &) = default;



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


[clang] dc8680e - [CodeGenPGO] Fix shadow variable warning. NFC.

2020-03-02 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-03-02T15:06:34Z
New Revision: dc8680eceb7c992cf1d02f47ad963dca2e287eaf

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

LOG: [CodeGenPGO] Fix shadow variable warning. NFC.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenPGO.h

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h
index a3778b549910..dda8c66b6db2 100644
--- a/clang/lib/CodeGen/CodeGenPGO.h
+++ b/clang/lib/CodeGen/CodeGenPGO.h
@@ -40,8 +40,8 @@ class CodeGenPGO {
   uint64_t CurrentRegionCount;
 
 public:
-  CodeGenPGO(CodeGenModule &CGM)
-  : CGM(CGM), FuncNameVar(nullptr), NumValueSites({{0}}),
+  CodeGenPGO(CodeGenModule &CGModule)
+  : CGM(CGModule), FuncNameVar(nullptr), NumValueSites({{0}}),
 NumRegionCounters(0), FunctionHash(0), CurrentRegionCount(0) {}
 
   /// Whether or not we have PGO region data for the current function. This is



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


[PATCH] D75365: [AST Matchers] Fix bug in 'optionally' matcher wherein all previous bindings are cleared when all inner matchers fail.

2020-03-02 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

> I think the difference is in whether you continue with the submatchers after 
> a success. Allof does while anyof does not.

Oh, the short-circuiting makes a difference! I see.

+1 to making it non-variadic then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75365



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


[PATCH] D75456: [clang-format] Rename CSharpNullConditionalSq and add missing test

2020-03-02 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe created this revision.
jbcoe added a reviewer: krasimir.
jbcoe added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Rename CSharpNullConditionalSq to CSharpNullConditionalLSquare.

Add test for spaces inside [] with C# Null conditionals.

Address comments missed from https://reviews.llvm.org/D75368.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75456

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -607,6 +607,7 @@
 
   Style.SpacesInSquareBrackets = true;
   verifyFormat(R"(private float[ , ] Values;)", Style);
+  verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNullableTypes) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -972,7 +972,7 @@
   }
   break;
 case tok::question:
-  if (Tok->is(TT_CSharpNullConditionalSq)) {
+  if (Tok->is(TT_CSharpNullConditionalLSquare)) {
 if (!parseSquare())
   return false;
 break;
@@ -1456,7 +1456,7 @@
 return;
   }
   if (CurrentToken->TokenText == "?[") {
-Current.Type = TT_CSharpNullConditionalSq;
+Current.Type = TT_CSharpNullConditionalLSquare;
 return;
   }
 }
@@ -2947,11 +2947,11 @@
   return true;
 
 // No space before '?['.
-if (Right.is(TT_CSharpNullConditionalSq))
+if (Right.is(TT_CSharpNullConditionalLSquare))
   return false;
 
 // Possible space inside `?[ 0 ]`.
-if (Left.is(TT_CSharpNullConditionalSq))
+if (Left.is(TT_CSharpNullConditionalLSquare))
   return Style.SpacesInSquareBrackets;
 
 // space between keywords and paren e.g. "using ("
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -345,7 +345,7 @@
 
   if (PeriodOrLSquare->is(tok::l_square)) {
 Question->Tok.setKind(tok::question); // no '?[' in clang tokens.
-Question->Type = TT_CSharpNullConditionalSq;
+Question->Type = TT_CSharpNullConditionalLSquare;
   } else {
 Question->Tok.setKind(tok::question); // no '?.' in clang tokens.
 Question->Type = TT_CSharpNullConditional;
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -106,7 +106,7 @@
   TYPE(CSharpNullable) 
\
   TYPE(CSharpNullCoalescing)   
\
   TYPE(CSharpNullConditional)  
\
-  TYPE(CSharpNullConditionalSq)
\
+  TYPE(CSharpNullConditionalLSquare)   
 \
   TYPE(Unknown)
 
 enum TokenType {


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -607,6 +607,7 @@
 
   Style.SpacesInSquareBrackets = true;
   verifyFormat(R"(private float[ , ] Values;)", Style);
+  verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNullableTypes) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -972,7 +972,7 @@
   }
   break;
 case tok::question:
-  if (Tok->is(TT_CSharpNullConditionalSq)) {
+  if (Tok->is(TT_CSharpNullConditionalLSquare)) {
 if (!parseSquare())
   return false;
 break;
@@ -1456,7 +1456,7 @@
 return;
   }
   if (CurrentToken->TokenText == "?[") {
-Current.Type = TT_CSharpNullConditionalSq;
+Current.Type = TT_CSharpNullConditionalLSquare;
 return;
   }
 }
@@ -2947,11 +2947,11 @@
   return true;
 
 // No space before '?['.
-if (Right.is(TT_CSharpNullConditionalSq))
+if (Right.is(TT_CSharpNullConditionalLSquare))
   return false;
 
 // Possible space inside `?[ 0 ]`.
-if (Left.is(TT_CSharpNullConditionalSq))
+if (Left.is(TT_CSharpNullConditionalLSquare))
   return Style.SpacesInSquareBrackets;
 
 // space between keywords and paren e.g. "using ("
Index: clang/lib/Format/FormatTokenLexer.cpp
===

[PATCH] D75429: [clangd] DefineOutline won't copy virtual specifiers on methods

2020-03-02 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 247640.
njames93 added a comment.

- Fixed clang tidy warning, wont fix format as it's contradicting with the 
style of the rest of the function


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75429

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
@@ -2068,6 +2068,80 @@
   };)cpp",
   "Foo::Foo(int z) __attribute__((weak)) : bar(2){}\n",
   },
+  // Virt specifiers.
+  {
+  R"cpp(
+struct A {
+  virtual void f^oo() {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() ;
+};)cpp",
+  " void A::foo() {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual virtual void virtual f^oo() {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual virtual void virtual foo() ;
+};)cpp",
+  "  void  A::foo() {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() override {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() override ;
+};)cpp",
+  "void B::foo()  {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() final {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() final ;
+};)cpp",
+  "void B::foo()  {}\n",
+  },
+  {
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void fo^o() final override {}
+};)cpp",
+  R"cpp(
+struct A {
+  virtual void foo() = 0;
+};
+struct B : A {
+  void foo() final override ;
+};)cpp",
+  "void B::foo()   {}\n",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2081,6 +2155,8 @@
   llvm::StringMap EditedFiles;
   ExtraFiles["Test.cpp"] = "";
   FileName = "Test.hpp";
+  ExtraArgs.push_back("-DVIRTUAL=virtual");
+  ExtraArgs.push_back("-DOVER=override");
 
   struct {
 llvm::StringRef Test;
@@ -2118,6 +2194,42 @@
   #define TARGET foo
   void TARGET();)cpp",
"void TARGET(){ return; }"},
+  {R"cpp(#define VIRT virtual
+  struct A {
+VIRT void f^oo() {}
+  };)cpp",
+   R"cpp(#define VIRT virtual
+  struct A {
+VIRT void foo() ;
+  };)cpp",
+" void A::foo() {}\n",
+  },
+  {R"cpp(
+  struct A {
+VIRTUAL void f^oo() {}
+  };)cpp",
+   R"cpp(
+  struct A {
+VIRTUAL void foo() ;
+  };)cpp",
+" void A::foo() {}\n",
+  },
+  {R"cpp(
+  struct A {
+virtual void foo() = 0;
+  };
+  struct B : A {
+void fo^o() OVER {}
+  };)cpp",
+   R"cpp(
+  struct A {
+virtual void foo() = 0;
+  };
+  struct B : A {
+void foo() OVER ;
+  };)cpp",
+"void B::foo()  {}\n",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -2229,6 +2341,49 @@
 << Case.TestHeader;
   }
 }
+
+TEST_F(DefineOutlineTest, FailsMacroSpecifier) {
+  FileName = "Test.hpp";
+  ExtraFiles["Test.cpp"] = "";
+  ExtraArgs.push_back("-DFINALOVER=final override");
+
+  std::pair Cases[] = {
+  {
+  R"cpp(
+  #define VIRT virtual void
+  struct A {
+VIRT fo^o() {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `virtual` specifier."},
+  {
+  R"cpp(
+  #define OVERFINAL final override
+  struct A {
+virtual void foo() {}
+  };
+  struct B : A {
+void fo^o() OVERFINAL {}
+  };)cpp",
+  "fail: define outline: Can't move out of line as function has a "
+  "macro `override` specifier.\ndefine outline: Can't move out of line "
+  "as function has a macro `final` specifier."},
+  {
+  R"cpp(
+  

[PATCH] D75414: [clangd] Resolve driver symlinks, and look up unknown relative drivers in PATH.

2020-03-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a subscriber: jyknight.
sammccall added a comment.

Per @jyknight on discord: we `-no-canonical-prefixes` disables this behavior in 
clang.
Maybe we should scan for that and not resolve if it's present...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75414



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


Re: [clang] 83f4372 - [CodeGen] fix clang test that runs the optimizer pipeline; NFC

2020-03-02 Thread Sanjay Patel via cfe-commits
https://reviews.llvm.org/rG8cdcbcaa02e7
https://reviews.llvm.org/rG1e308452bf68

On Thu, Feb 27, 2020 at 6:29 PM Eric Christopher  wrote:

> Sure. That sounds great. Thanks!
>
> On Wed, Feb 26, 2020 at 10:45 AM Sanjay Patel 
> wrote:
>
>> To be clear - the test is checking IR instructions, but it's checking -O1
>> IR for various targets.
>> So there must be different expectations per target...
>> But I just tried a test of turning everything down to -O0, and it all
>> passed except for the "fast-math" run for AArch64.
>> I can tweak that to not be so specific if that sounds like a reasonable
>> solution.
>>
>> On Wed, Feb 26, 2020 at 1:05 PM Eric Christopher 
>> wrote:
>>
>>> I mean anything that's testing assembly output out of clang is less than
>>> ideal. There are some circumstances, but this doesn't seem like one of
>>> them.
>>>
>>> On Wed, Feb 26, 2020, 9:10 AM Sanjay Patel 
>>> wrote:
>>>
 The test file dates back to:
 https://reviews.llvm.org/D5698
 ...and I'm not familiar with _Complex enough to say how to fix this
 properly (seems like the check lines are already limited such that -O0
 rather than -O1 would work?).

 But this file keeps wiggling unexpectedly, it's going to move again
 with https://reviews.llvm.org/D75130

 On Tue, Feb 25, 2020 at 1:15 PM Eric Christopher 
 wrote:

> Is there any way to pull this test out of clang and as an opt test?
> What's it trying to test?
>
> -eric
>
> On Tue, Feb 25, 2020 at 6:15 AM Sanjay Patel via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>>
>> Author: Sanjay Patel
>> Date: 2020-02-25T09:13:49-05:00
>> New Revision: 83f4372f3a708ceaa800feff8b1bd92ae2c3be5f
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/83f4372f3a708ceaa800feff8b1bd92ae2c3be5f
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/83f4372f3a708ceaa800feff8b1bd92ae2c3be5f.diff
>>
>> LOG: [CodeGen] fix clang test that runs the optimizer pipeline; NFC
>>
>> There's already a FIXME note on this file; it can break when the
>> underlying LLVM behavior changes independently of anything in clang.
>>
>> Added:
>>
>>
>> Modified:
>> clang/test/CodeGen/complex-math.c
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git a/clang/test/CodeGen/complex-math.c
>> b/clang/test/CodeGen/complex-math.c
>> index e42418ad72c2..54dee473a364 100644
>> --- a/clang/test/CodeGen/complex-math.c
>> +++ b/clang/test/CodeGen/complex-math.c
>> @@ -93,14 +93,15 @@ float _Complex mul_float_rc(float a, float
>> _Complex b) {
>>// X86: ret
>>return a * b;
>>  }
>> +
>>  float _Complex mul_float_cc(float _Complex a, float _Complex b) {
>>// X86-LABEL: @mul_float_cc(
>>// X86: %[[AC:[^ ]+]] = fmul
>>// X86: %[[BD:[^ ]+]] = fmul
>>// X86: %[[AD:[^ ]+]] = fmul
>>// X86: %[[BC:[^ ]+]] = fmul
>> -  // X86: %[[RR:[^ ]+]] = fsub float %[[AC]], %[[BD]]
>> -  // X86: %[[RI:[^ ]+]] = fadd float
>> +  // X86: %[[RR:[^ ]+]] = fsub
>> +  // X86: %[[RI:[^ ]+]] = fadd
>>// X86-DAG: %[[AD]]
>>// X86-DAG: ,
>>// X86-DAG: %[[BC]]
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75356: [Analyzer][StreamChecker] Introduction of stream error state handling.

2020-03-02 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 2 inline comments as done.
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:50-68
+struct StreamErrorState {
+  // The error state of an opened stream.
+  // EofError: EOF condition (feof returns true)
+  // OtherError: other (non-EOF) error (ferror returns true)
+  // AnyError: EofError or OtherError
+  enum Kind { EofError, OtherError, AnyError } K;
+

Szelethus wrote:
> Shouldn't we merge this with `StreamState`?
The intention was that the error state is only stored when the stream is opened 
(in opened state). Additionally it exists in the map only if there is error, so 
no "NoError" kind is needed. This is only to save memory, if it is not relevant 
I can move the error information into `StreamState` (that will contain two 
enums then).



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:92-125
+class MakeRetVal {
+  const CallExpr *CE = nullptr;
+  std::unique_ptr RetVal;
+  SymbolRef RetSym;
+
+public:
+  MakeRetVal(const CallEvent &Call, CheckerContext &C)

Szelethus wrote:
> Do you have other patches that really crave the need for this class? Why 
> isn't `CallEvent::getReturnValue` sufficient? This is a legitimate question, 
> I really don't know. :)
This is an "interesting" solution for the problem that there is need for a 
function with 3 return values. The constructor performs the task of the 
function: Create a conjured value (and get the various objects for it). The 
output values are RetVal and RetSym, and the success state, and the call expr 
that is computed here anyway. It could be computed independently but if the 
value was retrieved once it is better to store it for later use. (I did not 
check how costly that operation is.)

I had some experience that using only `getReturnValue` and make constraints on 
that does not work as intended, and the reason can be that we need to bind a 
value for the call expr otherwise it is an unknown (undefined?) value (and not 
the conjured symbol)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75356



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


  1   2   3   >