[PATCH] D49530: [libc++] Implement Directory Entry Caching -- Sort of.

2020-01-22 Thread Billy Robert O'Neal III via Phabricator via cfe-commits
BillyONeal added a comment.
Herald added subscribers: libcxx-commits, dexonsmith.

> @BillyONeal has proposed a more reasonable set of requirements

I believe that was you. I wanted the throws/fails behavior.


Repository:
  rCXX libc++

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

https://reviews.llvm.org/D49530



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


[PATCH] D72998: [IR] Attribute/AttrBuilder: use Value::MaximumAlignment magic constant

2020-01-22 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72998



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


[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 239498.
kbobyrev added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746

Files:
  clang-tools-extra/clangd/index/Ref.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp

Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -256,21 +256,27 @@
 
 llvm::ArrayRef
 syntax::spelledTokensTouching(SourceLocation Loc,
-  const syntax::TokenBuffer &Tokens) {
+  llvm::ArrayRef Tokens) {
   assert(Loc.isFileID());
-  llvm::ArrayRef All =
-  Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc));
   auto *Right = llvm::partition_point(
-  All, [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
-  bool AcceptRight = Right != All.end() && Right->location() <= Loc;
-  bool AcceptLeft = Right != All.begin() && (Right - 1)->endLocation() >= Loc;
+  Tokens, [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
+  bool AcceptRight = Right != Tokens.end() && Right->location() <= Loc;
+  bool AcceptLeft =
+  Right != Tokens.begin() && (Right - 1)->endLocation() >= Loc;
   return llvm::makeArrayRef(Right - (AcceptLeft ? 1 : 0),
 Right + (AcceptRight ? 1 : 0));
 }
 
+llvm::ArrayRef
+syntax::spelledTokensTouching(SourceLocation Loc,
+  const syntax::TokenBuffer &Tokens) {
+  return spelledTokensTouching(
+  Loc, Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc)));
+}
+
 const syntax::Token *
 syntax::spelledIdentifierTouching(SourceLocation Loc,
-  const syntax::TokenBuffer &Tokens) {
+  llvm::ArrayRef Tokens) {
   for (const syntax::Token &Tok : spelledTokensTouching(Loc, Tokens)) {
 if (Tok.kind() == tok::identifier)
   return &Tok;
@@ -278,6 +284,13 @@
   return nullptr;
 }
 
+const syntax::Token *
+syntax::spelledIdentifierTouching(SourceLocation Loc,
+  const syntax::TokenBuffer &Tokens) {
+  return spelledIdentifierTouching(
+  Loc, Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc)));
+}
+
 std::vector
 TokenBuffer::macroExpansions(FileID FID) const {
   auto FileIt = Files.find(FID);
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/Syntax/Tokens.h
@@ -313,11 +313,22 @@
   const SourceManager *SourceMgr;
 };
 
+/// The spelled tokens that overlap or touch a spelling location Loc.
+/// This always returns 0-2 tokens.
+llvm::ArrayRef
+spelledTokensTouching(SourceLocation Loc, llvm::ArrayRef Tokens);
+
 /// The spelled tokens that overlap or touch a spelling location Loc.
 /// This always returns 0-2 tokens.
 llvm::ArrayRef
 spelledTokensTouching(SourceLocation Loc, const syntax::TokenBuffer &Tokens);
 
+/// The identifier token that overlaps or touches a spelling location Loc.
+/// If there is none, returns nullptr.
+const syntax::Token *
+spelledIdentifierTouching(SourceLocation Loc,
+  llvm::ArrayRef Tokens);
+
 /// The identifier token that overlaps or touches a spelling location Loc.
 /// If there is none, returns nullptr.
 const syntax::Token *
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -33,7 +33,7 @@
 // Convert a Range to a Ref.
 Ref refWithRange(const clangd::Range &Range, const std::string &URI) {
   Ref Result;
-  Result.Kind = RefKind::Reference;
+  Result.Kind = RefKind::Reference | RefKind::Spelled;
   Result.Location.Start.setLine(Range.start.line);
   Result.Location.Start.setColumn(Range.start.character);
   Result.Location.End.setLine(Range.end.line);
@@ -728,6 +728,22 @@
 llvm::StringRef FooH;
 llvm::StringRef FooCC;
   } Cases[] = {
+  {
+  // Implicit references in macro expansions.
+  R"cpp(
+class [[Fo^o]] {};
+#define FooFoo Foo
+#define FOO Foo
+  )cpp",
+  R"cpp(
+#include "foo.h"
+void bar() {
+  [[Foo]] x;
+  FOO y;
+  FooFoo z;
+}
+  )cpp",
+  },
   {
   // classes.
   R"cpp(
@@ -837,7 +853,7 @@
   {
   // variables.
   R"cpp(
-  static const int [[VA^R]] = 12

[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev planned changes to this revision.
kbobyrev added a comment.

Will put a TODO and revert helpers back to use plain binary search over the 
tokens.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746



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


[PATCH] D73106: [Alignment][NFC] Use Align with CreateMaskedStore

2020-01-22 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet updated this revision to Diff 239501.
gchatelet marked an inline comment as done.
gchatelet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73106

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/Constants.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/IRBuilder.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2343,7 +2343,7 @@
   Value *ShuffledMask = Builder.CreateShuffleVector(
   BlockInMaskPart, Undefs, RepMask, "interleaved.mask");
   NewStoreInstr = Builder.CreateMaskedStore(
-  IVec, AddrParts[Part], Group->getAlignment(), ShuffledMask);
+  IVec, AddrParts[Part], Group->getAlign(), ShuffledMask);
 }
 else
   NewStoreInstr = Builder.CreateAlignedStore(IVec, AddrParts[Part],
@@ -2449,8 +2449,8 @@
 }
 auto *VecPtr = CreateVecPtr(Part, State.get(Addr, {0, 0}));
 if (isMaskRequired)
-  NewSI = Builder.CreateMaskedStore(
-  StoredVal, VecPtr, Alignment.value(), BlockInMaskParts[Part]);
+  NewSI = Builder.CreateMaskedStore(StoredVal, VecPtr, Alignment,
+BlockInMaskParts[Part]);
 else
   NewSI =
   Builder.CreateAlignedStore(StoredVal, VecPtr, Alignment.value());
Index: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -2904,7 +2904,7 @@
 IRBuilder<> IRB(&I);
 Value *V = I.getArgOperand(0);
 Value *Addr = I.getArgOperand(1);
-const MaybeAlign Alignment(
+const Align Alignment(
 cast(I.getArgOperand(2))->getZExtValue());
 Value *Mask = I.getArgOperand(3);
 Value *Shadow = getShadow(V);
@@ -2921,21 +2921,20 @@
   insertShadowCheck(Mask, &I);
 }
 
-IRB.CreateMaskedStore(Shadow, ShadowPtr, Alignment ? Alignment->value() : 0,
-  Mask);
+IRB.CreateMaskedStore(Shadow, ShadowPtr, Alignment, Mask);
 
 if (MS.TrackOrigins) {
   auto &DL = F.getParent()->getDataLayout();
   paintOrigin(IRB, getOrigin(V), OriginPtr,
   DL.getTypeStoreSize(Shadow->getType()),
-  llvm::max(Alignment, kMinOriginAlignment));
+  std::max(Alignment, kMinOriginAlignment));
 }
   }
 
   bool handleMaskedLoad(IntrinsicInst &I) {
 IRBuilder<> IRB(&I);
 Value *Addr = I.getArgOperand(0);
-const MaybeAlign Alignment(
+const Align Alignment(
 cast(I.getArgOperand(1))->getZExtValue());
 Value *Mask = I.getArgOperand(2);
 Value *PassThru = I.getArgOperand(3);
@@ -2945,7 +2944,7 @@
 if (PropagateShadow) {
   std::tie(ShadowPtr, OriginPtr) =
   getShadowOriginPtr(Addr, IRB, ShadowTy, Alignment, /*isStore*/ false);
-  setShadow(&I, IRB.CreateMaskedLoad(ShadowPtr, *Alignment, Mask,
+  setShadow(&I, IRB.CreateMaskedLoad(ShadowPtr, Alignment, Mask,
  getShadow(PassThru), "_msmaskedld"));
 } else {
   setShadow(&I, getCleanShadow(&I));
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1372,7 +1372,7 @@
   // on each element's most significant bit (the sign bit).
   Constant *BoolMask = getNegativeIsTrueBoolVec(ConstMask);
 
-  IC.Builder.CreateMaskedStore(Vec, PtrCast, 1, BoolMask);
+  IC.Builder.CreateMaskedStore(Vec, PtrCast, Align::None(), BoolMask);
 
   // 'Replace uses' doesn't work for stores. Erase the original masked store.
   IC.eraseInstFromFunction(II);
Index: llvm/lib/IR/IRBuilder.cpp
===
--- llvm/lib/IR/IRBuilder.cpp
+++ llvm/lib/IR/IRBuilder.cpp
@@ -487,19 +487,19 @@
 }
 
 /// Create a call to a Masked Store intrinsic.
-/// \p Val   - data to be stored,
-/// \p Ptr   - base pointer for the store
-/// \p Align - alignment of the destination location
-/// \p Mask  - vector of booleans which indicates what vector lanes should
-///be accessed in memory
+/// \p Val   - data to be stored,
+/// \p Ptr   - base pointer for the store
+/// \p Alignment - alignment of the destination locati

[PATCH] D73106: [Alignment][NFC] Use Align with CreateMaskedStore

2020-01-22 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet marked 2 inline comments as done.
gchatelet added inline comments.



Comment at: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp:2907
 Value *Addr = I.getArgOperand(1);
-const MaybeAlign Alignment(
+const Align Alignment(
 cast(I.getArgOperand(2))->getZExtValue());

courbet wrote:
> I think it's actually OK for this one to be a `MaybeAlign`, e.g. in 
> `ARMTTIImpl::isLegalMaskedLoad`.
As discussed offline 
[Verifier.cpp](https://github.com/llvm-mirror/llvm/blob/2c4ca6832fa6b306ee6a7010bfb80a3f2596f824/lib/IR/Verifier.cpp#L4613)
 requires the alignment to be set for both `masked_load` and `masked_store` 
intrinsics. I've updated the documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73106



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


[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 239502.
kbobyrev added a comment.

Actually, this approach might be more generic (i.e. not relying on
implementation too much). Added the FIXME.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746

Files:
  clang-tools-extra/clangd/index/Ref.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp

Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -256,21 +256,27 @@
 
 llvm::ArrayRef
 syntax::spelledTokensTouching(SourceLocation Loc,
-  const syntax::TokenBuffer &Tokens) {
+  llvm::ArrayRef Tokens) {
   assert(Loc.isFileID());
-  llvm::ArrayRef All =
-  Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc));
   auto *Right = llvm::partition_point(
-  All, [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
-  bool AcceptRight = Right != All.end() && Right->location() <= Loc;
-  bool AcceptLeft = Right != All.begin() && (Right - 1)->endLocation() >= Loc;
+  Tokens, [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
+  bool AcceptRight = Right != Tokens.end() && Right->location() <= Loc;
+  bool AcceptLeft =
+  Right != Tokens.begin() && (Right - 1)->endLocation() >= Loc;
   return llvm::makeArrayRef(Right - (AcceptLeft ? 1 : 0),
 Right + (AcceptRight ? 1 : 0));
 }
 
+llvm::ArrayRef
+syntax::spelledTokensTouching(SourceLocation Loc,
+  const syntax::TokenBuffer &Tokens) {
+  return spelledTokensTouching(
+  Loc, Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc)));
+}
+
 const syntax::Token *
 syntax::spelledIdentifierTouching(SourceLocation Loc,
-  const syntax::TokenBuffer &Tokens) {
+  llvm::ArrayRef Tokens) {
   for (const syntax::Token &Tok : spelledTokensTouching(Loc, Tokens)) {
 if (Tok.kind() == tok::identifier)
   return &Tok;
@@ -278,6 +284,13 @@
   return nullptr;
 }
 
+const syntax::Token *
+syntax::spelledIdentifierTouching(SourceLocation Loc,
+  const syntax::TokenBuffer &Tokens) {
+  return spelledIdentifierTouching(
+  Loc, Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc)));
+}
+
 std::vector
 TokenBuffer::macroExpansions(FileID FID) const {
   auto FileIt = Files.find(FID);
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/Syntax/Tokens.h
@@ -313,11 +313,22 @@
   const SourceManager *SourceMgr;
 };
 
+/// The spelled tokens that overlap or touch a spelling location Loc.
+/// This always returns 0-2 tokens.
+llvm::ArrayRef
+spelledTokensTouching(SourceLocation Loc, llvm::ArrayRef Tokens);
+
 /// The spelled tokens that overlap or touch a spelling location Loc.
 /// This always returns 0-2 tokens.
 llvm::ArrayRef
 spelledTokensTouching(SourceLocation Loc, const syntax::TokenBuffer &Tokens);
 
+/// The identifier token that overlaps or touches a spelling location Loc.
+/// If there is none, returns nullptr.
+const syntax::Token *
+spelledIdentifierTouching(SourceLocation Loc,
+  llvm::ArrayRef Tokens);
+
 /// The identifier token that overlaps or touches a spelling location Loc.
 /// If there is none, returns nullptr.
 const syntax::Token *
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -33,7 +33,7 @@
 // Convert a Range to a Ref.
 Ref refWithRange(const clangd::Range &Range, const std::string &URI) {
   Ref Result;
-  Result.Kind = RefKind::Reference;
+  Result.Kind = RefKind::Reference | RefKind::Spelled;
   Result.Location.Start.setLine(Range.start.line);
   Result.Location.Start.setColumn(Range.start.character);
   Result.Location.End.setLine(Range.end.line);
@@ -728,6 +728,22 @@
 llvm::StringRef FooH;
 llvm::StringRef FooCC;
   } Cases[] = {
+  {
+  // Implicit references in macro expansions.
+  R"cpp(
+class [[Fo^o]] {};
+#define FooFoo Foo
+#define FOO Foo
+  )cpp",
+  R"cpp(
+#include "foo.h"
+void bar() {
+  [[Foo]] x;
+  FOO y;
+  FooFoo z;
+}
+  )cpp",
+  },
   {
   // classes.
   R"cpp(
@@ -837,7 +853,7 @@
   

[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 239503.
kbobyrev added a comment.

Move added rename unit test to the end of the list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746

Files:
  clang-tools-extra/clangd/index/Ref.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp

Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -256,21 +256,27 @@
 
 llvm::ArrayRef
 syntax::spelledTokensTouching(SourceLocation Loc,
-  const syntax::TokenBuffer &Tokens) {
+  llvm::ArrayRef Tokens) {
   assert(Loc.isFileID());
-  llvm::ArrayRef All =
-  Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc));
   auto *Right = llvm::partition_point(
-  All, [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
-  bool AcceptRight = Right != All.end() && Right->location() <= Loc;
-  bool AcceptLeft = Right != All.begin() && (Right - 1)->endLocation() >= Loc;
+  Tokens, [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
+  bool AcceptRight = Right != Tokens.end() && Right->location() <= Loc;
+  bool AcceptLeft =
+  Right != Tokens.begin() && (Right - 1)->endLocation() >= Loc;
   return llvm::makeArrayRef(Right - (AcceptLeft ? 1 : 0),
 Right + (AcceptRight ? 1 : 0));
 }
 
+llvm::ArrayRef
+syntax::spelledTokensTouching(SourceLocation Loc,
+  const syntax::TokenBuffer &Tokens) {
+  return spelledTokensTouching(
+  Loc, Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc)));
+}
+
 const syntax::Token *
 syntax::spelledIdentifierTouching(SourceLocation Loc,
-  const syntax::TokenBuffer &Tokens) {
+  llvm::ArrayRef Tokens) {
   for (const syntax::Token &Tok : spelledTokensTouching(Loc, Tokens)) {
 if (Tok.kind() == tok::identifier)
   return &Tok;
@@ -278,6 +284,13 @@
   return nullptr;
 }
 
+const syntax::Token *
+syntax::spelledIdentifierTouching(SourceLocation Loc,
+  const syntax::TokenBuffer &Tokens) {
+  return spelledIdentifierTouching(
+  Loc, Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc)));
+}
+
 std::vector
 TokenBuffer::macroExpansions(FileID FID) const {
   auto FileIt = Files.find(FID);
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/Syntax/Tokens.h
@@ -313,11 +313,22 @@
   const SourceManager *SourceMgr;
 };
 
+/// The spelled tokens that overlap or touch a spelling location Loc.
+/// This always returns 0-2 tokens.
+llvm::ArrayRef
+spelledTokensTouching(SourceLocation Loc, llvm::ArrayRef Tokens);
+
 /// The spelled tokens that overlap or touch a spelling location Loc.
 /// This always returns 0-2 tokens.
 llvm::ArrayRef
 spelledTokensTouching(SourceLocation Loc, const syntax::TokenBuffer &Tokens);
 
+/// The identifier token that overlaps or touches a spelling location Loc.
+/// If there is none, returns nullptr.
+const syntax::Token *
+spelledIdentifierTouching(SourceLocation Loc,
+  llvm::ArrayRef Tokens);
+
 /// The identifier token that overlaps or touches a spelling location Loc.
 /// If there is none, returns nullptr.
 const syntax::Token *
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -33,7 +33,7 @@
 // Convert a Range to a Ref.
 Ref refWithRange(const clangd::Range &Range, const std::string &URI) {
   Ref Result;
-  Result.Kind = RefKind::Reference;
+  Result.Kind = RefKind::Reference | RefKind::Spelled;
   Result.Location.Start.setLine(Range.start.line);
   Result.Location.Start.setColumn(Range.start.character);
   Result.Location.End.setLine(Range.end.line);
@@ -837,7 +837,7 @@
   {
   // variables.
   R"cpp(
-  static const int [[VA^R]] = 123;
+static const int [[VA^R]] = 123;
   )cpp",
   R"cpp(
 #include "foo.h"
@@ -868,6 +868,22 @@
 }
   )cpp",
   },
+  {
+  // Implicit references in macro expansions.
+  R"cpp(
+class [[Fo^o]] {};
+#define FooFoo Foo
+#define FOO Foo
+  )cpp",
+  R"cpp(
+#include "foo.h"
+void bar() {
+  [[Foo]] x;
+  FOO y;
+  F

[clang] de51559 - [Concepts] Fix incorrect recovery in TryAnnotateTypeConstraint

2020-01-22 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-22T10:50:53+02:00
New Revision: de51559fa68049da73b696a4e89468154b12852a

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

LOG: [Concepts] Fix incorrect recovery in TryAnnotateTypeConstraint

TryAnnotateTypeConstraint would not put the scope specifier back into the token 
stream when faced
with a non-concept name after a scope specifier.

Added: 


Modified: 
clang/lib/Parse/ParseTemplate.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index 0f7aefaa147a..2ac8be430c31 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -712,8 +712,11 @@ bool Parser::TryAnnotateTypeConstraint() {
   MemberOfUnknownSpecialization);
 assert(!MemberOfUnknownSpecialization
&& "Member when we only allowed namespace scope qualifiers??");
-if (!PossibleConcept || TNK != TNK_Concept_template)
+if (!PossibleConcept || TNK != TNK_Concept_template) {
+  if (SS.isNotEmpty())
+AnnotateScopeToken(SS, !WasScopeAnnotation);
   return false;
+}
 
 // At this point we're sure we're dealing with a constrained parameter. It
 // may or may not have a template parameter list following the concept



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


[PATCH] D73109: [clang][index] Index the injected class name types.

2020-01-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 239504.
hokein added a comment.

clang-format the code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73109

Files:
  clang/lib/Index/IndexTypeSourceInfo.cpp
  clang/unittests/Index/IndexTests.cpp


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -293,6 +293,27 @@
 WrittenAt(Position(4, 8);
 }
 
+TEST(IndexTest, InjecatedNameClass) {
+  std::string Code = R"cpp(
+template 
+class Foo {
+  void f(Foo x);
+};
+  )cpp";
+  auto Index = std::make_shared();
+  IndexingOptions Opts;
+  tooling::runToolOnCode(std::make_unique(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols,
+  UnorderedElementsAre(AllOf(QName("Foo"), Kind(SymbolKind::Class),
+ WrittenAt(Position(3, 11))),
+   AllOf(QName("Foo::f"),
+ Kind(SymbolKind::InstanceMethod),
+ WrittenAt(Position(4, 12))),
+   AllOf(QName("Foo"), Kind(SymbolKind::Class),
+ HasRole(SymbolRole::Reference),
+ WrittenAt(Position(4, 14);
+}
+
 } // namespace
 } // namespace index
 } // namespace clang
Index: clang/lib/Index/IndexTypeSourceInfo.cpp
===
--- clang/lib/Index/IndexTypeSourceInfo.cpp
+++ clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -170,6 +170,11 @@
 return true;
   }
 
+  bool VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
+return IndexCtx.handleReference(TL.getDecl(), TL.getNameLoc(), Parent,
+ParentDC, SymbolRoleSet(), Relations);
+  }
+
   bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
 const DependentNameType *DNT = TL.getTypePtr();
 const NestedNameSpecifier *NNS = DNT->getQualifier();


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -293,6 +293,27 @@
 WrittenAt(Position(4, 8);
 }
 
+TEST(IndexTest, InjecatedNameClass) {
+  std::string Code = R"cpp(
+template 
+class Foo {
+  void f(Foo x);
+};
+  )cpp";
+  auto Index = std::make_shared();
+  IndexingOptions Opts;
+  tooling::runToolOnCode(std::make_unique(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols,
+  UnorderedElementsAre(AllOf(QName("Foo"), Kind(SymbolKind::Class),
+ WrittenAt(Position(3, 11))),
+   AllOf(QName("Foo::f"),
+ Kind(SymbolKind::InstanceMethod),
+ WrittenAt(Position(4, 12))),
+   AllOf(QName("Foo"), Kind(SymbolKind::Class),
+ HasRole(SymbolRole::Reference),
+ WrittenAt(Position(4, 14);
+}
+
 } // namespace
 } // namespace index
 } // namespace clang
Index: clang/lib/Index/IndexTypeSourceInfo.cpp
===
--- clang/lib/Index/IndexTypeSourceInfo.cpp
+++ clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -170,6 +170,11 @@
 return true;
   }
 
+  bool VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
+return IndexCtx.handleReference(TL.getDecl(), TL.getNameLoc(), Parent,
+ParentDC, SymbolRoleSet(), Relations);
+  }
+
   bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
 const DependentNameType *DNT = TL.getTypePtr();
 const NestedNameSpecifier *NNS = DNT->getQualifier();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73109: [clang][index] Index the injected class name types.

2020-01-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D73109#1831399 , @kadircet wrote:

> Have you checked if this class is missing any other typelocs?


I haven't checked it in details, but the injected class name is an obvious 
missing case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73109



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


[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61855 tests passed, 0 failed 
and 781 were skipped.

{icon question-circle color=gray} clang-tidy: unknown.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746



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


[clang] a133cba - [clang][index] Index the injected class name types.

2020-01-22 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-01-22T10:07:54+01:00
New Revision: a133cbaad5b292aab7134e3a91e80c5b2dddbe7e

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

LOG: [clang][index] Index the injected class name types.

Summary: Currently, we (clangd) are missing this kind of references.

Reviewers: kadircet

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

Tags: #clang

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

Added: 


Modified: 
clang/lib/Index/IndexTypeSourceInfo.cpp
clang/unittests/Index/IndexTests.cpp

Removed: 




diff  --git a/clang/lib/Index/IndexTypeSourceInfo.cpp 
b/clang/lib/Index/IndexTypeSourceInfo.cpp
index 959d5f1197fe..b9fc90040cfc 100644
--- a/clang/lib/Index/IndexTypeSourceInfo.cpp
+++ b/clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -170,6 +170,11 @@ class TypeIndexer : public 
RecursiveASTVisitor {
 return true;
   }
 
+  bool VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
+return IndexCtx.handleReference(TL.getDecl(), TL.getNameLoc(), Parent,
+ParentDC, SymbolRoleSet(), Relations);
+  }
+
   bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
 const DependentNameType *DNT = TL.getTypePtr();
 const NestedNameSpecifier *NNS = DNT->getQualifier();

diff  --git a/clang/unittests/Index/IndexTests.cpp 
b/clang/unittests/Index/IndexTests.cpp
index 000cfe212505..3ccec68321b1 100644
--- a/clang/unittests/Index/IndexTests.cpp
+++ b/clang/unittests/Index/IndexTests.cpp
@@ -293,6 +293,27 @@ TEST(IndexTest, Constructors) {
 WrittenAt(Position(4, 8);
 }
 
+TEST(IndexTest, InjecatedNameClass) {
+  std::string Code = R"cpp(
+template 
+class Foo {
+  void f(Foo x);
+};
+  )cpp";
+  auto Index = std::make_shared();
+  IndexingOptions Opts;
+  tooling::runToolOnCode(std::make_unique(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols,
+  UnorderedElementsAre(AllOf(QName("Foo"), Kind(SymbolKind::Class),
+ WrittenAt(Position(3, 11))),
+   AllOf(QName("Foo::f"),
+ Kind(SymbolKind::InstanceMethod),
+ WrittenAt(Position(4, 12))),
+   AllOf(QName("Foo"), Kind(SymbolKind::Class),
+ HasRole(SymbolRole::Reference),
+ WrittenAt(Position(4, 14);
+}
+
 } // namespace
 } // namespace index
 } // namespace clang



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


[PATCH] D73109: [clang][index] Index the injected class name types.

2020-01-22 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa133cbaad5b2: [clang][index] Index the injected class name 
types. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73109

Files:
  clang/lib/Index/IndexTypeSourceInfo.cpp
  clang/unittests/Index/IndexTests.cpp


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -293,6 +293,27 @@
 WrittenAt(Position(4, 8);
 }
 
+TEST(IndexTest, InjecatedNameClass) {
+  std::string Code = R"cpp(
+template 
+class Foo {
+  void f(Foo x);
+};
+  )cpp";
+  auto Index = std::make_shared();
+  IndexingOptions Opts;
+  tooling::runToolOnCode(std::make_unique(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols,
+  UnorderedElementsAre(AllOf(QName("Foo"), Kind(SymbolKind::Class),
+ WrittenAt(Position(3, 11))),
+   AllOf(QName("Foo::f"),
+ Kind(SymbolKind::InstanceMethod),
+ WrittenAt(Position(4, 12))),
+   AllOf(QName("Foo"), Kind(SymbolKind::Class),
+ HasRole(SymbolRole::Reference),
+ WrittenAt(Position(4, 14);
+}
+
 } // namespace
 } // namespace index
 } // namespace clang
Index: clang/lib/Index/IndexTypeSourceInfo.cpp
===
--- clang/lib/Index/IndexTypeSourceInfo.cpp
+++ clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -170,6 +170,11 @@
 return true;
   }
 
+  bool VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
+return IndexCtx.handleReference(TL.getDecl(), TL.getNameLoc(), Parent,
+ParentDC, SymbolRoleSet(), Relations);
+  }
+
   bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
 const DependentNameType *DNT = TL.getTypePtr();
 const NestedNameSpecifier *NNS = DNT->getQualifier();


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -293,6 +293,27 @@
 WrittenAt(Position(4, 8);
 }
 
+TEST(IndexTest, InjecatedNameClass) {
+  std::string Code = R"cpp(
+template 
+class Foo {
+  void f(Foo x);
+};
+  )cpp";
+  auto Index = std::make_shared();
+  IndexingOptions Opts;
+  tooling::runToolOnCode(std::make_unique(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols,
+  UnorderedElementsAre(AllOf(QName("Foo"), Kind(SymbolKind::Class),
+ WrittenAt(Position(3, 11))),
+   AllOf(QName("Foo::f"),
+ Kind(SymbolKind::InstanceMethod),
+ WrittenAt(Position(4, 12))),
+   AllOf(QName("Foo"), Kind(SymbolKind::Class),
+ HasRole(SymbolRole::Reference),
+ WrittenAt(Position(4, 14);
+}
+
 } // namespace
 } // namespace index
 } // namespace clang
Index: clang/lib/Index/IndexTypeSourceInfo.cpp
===
--- clang/lib/Index/IndexTypeSourceInfo.cpp
+++ clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -170,6 +170,11 @@
 return true;
   }
 
+  bool VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
+return IndexCtx.handleReference(TL.getDecl(), TL.getNameLoc(), Parent,
+ParentDC, SymbolRoleSet(), Relations);
+  }
+
   bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
 const DependentNameType *DNT = TL.getTypePtr();
 const NestedNameSpecifier *NNS = DNT->getQualifier();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61855 tests passed, 0 failed 
and 781 were skipped.

{icon question-circle color=gray} clang-tidy: unknown.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746



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


[PATCH] D73106: [Alignment][NFC] Use Align with CreateMaskedStore

2020-01-22 Thread Clement Courbet via Phabricator via cfe-commits
courbet accepted this revision.
courbet added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/docs/LangRef.rst:14945
 
-The first operand is the base pointer for the load. The second operand is the 
alignment of the source location. It must be a constant integer value. The 
third operand, mask, is a vector of boolean values with the same number of 
elements as the return type. The fourth is a pass-through value that is used to 
fill the masked-off lanes of the result. The return type, underlying type of 
the base pointer and the type of the '``passthru``' operand are the same vector 
types.
-
+The first operand is the base pointer for the load. The second operand is the 
alignment of the source location. It must be a power of two constant integer 
value. The third operand, mask, is a vector of boolean values with the same 
number of elements as the return type. The fourth is a pass-through value that 
is used to fill the masked-off lanes of the result. The return type, underlying 
type of the base pointer and the type of the '``passthru``' operand are the 
same vector types.
 

Let's commit this as a base change, as this is just documenting what the 
verifier is already checking.



Comment at: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp:2907
 Value *Addr = I.getArgOperand(1);
-const MaybeAlign Alignment(
+const Align Alignment(
 cast(I.getArgOperand(2))->getZExtValue());

gchatelet wrote:
> courbet wrote:
> > I think it's actually OK for this one to be a `MaybeAlign`, e.g. in 
> > `ARMTTIImpl::isLegalMaskedLoad`.
> As discussed offline 
> [Verifier.cpp](https://github.com/llvm-mirror/llvm/blob/2c4ca6832fa6b306ee6a7010bfb80a3f2596f824/lib/IR/Verifier.cpp#L4613)
>  requires the alignment to be set for both `masked_load` and `masked_store` 
> intrinsics. I've updated the documentation.
There is still the issue of already serialized bitcode files: as discussed, 
these are not an issue wrt this patch as they do not touch the API directly, 
will still generate a 0 align that will be caught by the verifier.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73106



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


[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61855 tests passed, 0 failed 
and 781 were skipped.

{icon question-circle color=gray} clang-tidy: unknown.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746



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


[clang-tools-extra] 5d4e899 - [clangd] Handle the missing injectedClassNameType in targetDecl.

2020-01-22 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-01-22T10:13:39+01:00
New Revision: 5d4e89975714875a86cb8e62b60d93eebefa4029

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

LOG: [clangd] Handle the missing injectedClassNameType in targetDecl.

Reviewers: sammccall

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index cbe83cc2cce4..bed32c394089 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -374,6 +374,11 @@ struct TargetFinder {
   void VisitTagType(const TagType *TT) {
 Outer.add(TT->getAsTagDecl(), Flags);
   }
+
+  void VisitInjectedClassNameType(const InjectedClassNameType *ICNT) {
+Outer.add(ICNT->getDecl(), Flags);
+  }
+
   void VisitDecltypeType(const DecltypeType *DTT) {
 Outer.add(DTT->getUnderlyingType(), Flags | Rel::Underlying);
   }

diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 4c9fe120a8d6..c6ad75144f96 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -286,6 +286,14 @@ TEST_F(TargetDeclTest, Types) {
   )cpp";
   // FIXME: We don't do a good job printing TemplateTypeParmDecls, apparently!
   EXPECT_DECLS("SizeOfPackExpr", "");
+
+  Code = R"cpp(
+template 
+class Foo {
+  void f([[Foo]] x);
+};
+  )cpp";
+  EXPECT_DECLS("InjectedClassNameTypeLoc", "class Foo");
 }
 
 TEST_F(TargetDeclTest, ClassTemplate) {



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


[PATCH] D73102: [clangd] Handle the missing injectedClassNameType in targetDecl.

2020-01-22 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5d4e89975714: [clangd] Handle the missing 
injectedClassNameType in targetDecl. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73102

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -286,6 +286,14 @@
   )cpp";
   // FIXME: We don't do a good job printing TemplateTypeParmDecls, apparently!
   EXPECT_DECLS("SizeOfPackExpr", "");
+
+  Code = R"cpp(
+template 
+class Foo {
+  void f([[Foo]] x);
+};
+  )cpp";
+  EXPECT_DECLS("InjectedClassNameTypeLoc", "class Foo");
 }
 
 TEST_F(TargetDeclTest, ClassTemplate) {
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -374,6 +374,11 @@
   void VisitTagType(const TagType *TT) {
 Outer.add(TT->getAsTagDecl(), Flags);
   }
+
+  void VisitInjectedClassNameType(const InjectedClassNameType *ICNT) {
+Outer.add(ICNT->getDecl(), Flags);
+  }
+
   void VisitDecltypeType(const DecltypeType *DTT) {
 Outer.add(DTT->getUnderlyingType(), Flags | Rel::Underlying);
   }


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -286,6 +286,14 @@
   )cpp";
   // FIXME: We don't do a good job printing TemplateTypeParmDecls, apparently!
   EXPECT_DECLS("SizeOfPackExpr", "");
+
+  Code = R"cpp(
+template 
+class Foo {
+  void f([[Foo]] x);
+};
+  )cpp";
+  EXPECT_DECLS("InjectedClassNameTypeLoc", "class Foo");
 }
 
 TEST_F(TargetDeclTest, ClassTemplate) {
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -374,6 +374,11 @@
   void VisitTagType(const TagType *TT) {
 Outer.add(TT->getAsTagDecl(), Flags);
   }
+
+  void VisitInjectedClassNameType(const InjectedClassNameType *ICNT) {
+Outer.add(ICNT->getDecl(), Flags);
+  }
+
   void VisitDecltypeType(const DecltypeType *DTT) {
 Outer.add(DTT->getUnderlyingType(), Flags | Rel::Underlying);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 45538b5 - [Concepts] Fix bug when referencing function parameters in instantiated function template requires clause

2020-01-22 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-22T11:25:27+02:00
New Revision: 45538b5fb280e5b2903f7924fd4fa5b07a6dd3ea

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

LOG: [Concepts] Fix bug when referencing function parameters in instantiated 
function template requires clause

Fixes bug #44613 - instantiated parameters were not being added when 
instantiating the requires clauses.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/instantiate-requires-clause.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index a470cfc87440..bdea54de2414 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1766,6 +1766,70 @@ Decl 
*TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) {
   return Record;
 }
 
+/// Introduce the instantiated function parameters into the local
+/// instantiation scope, and set the parameter names to those used
+/// in the template.
+static bool addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function,
+ const FunctionDecl *PatternDecl,
+ LocalInstantiationScope &Scope,
+   const MultiLevelTemplateArgumentList &TemplateArgs) 
{
+  unsigned FParamIdx = 0;
+  for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) {
+const ParmVarDecl *PatternParam = PatternDecl->getParamDecl(I);
+if (!PatternParam->isParameterPack()) {
+  // Simple case: not a parameter pack.
+  assert(FParamIdx < Function->getNumParams());
+  ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
+  FunctionParam->setDeclName(PatternParam->getDeclName());
+  // If the parameter's type is not dependent, update it to match the type
+  // in the pattern. They can 
diff er in top-level cv-qualifiers, and we want
+  // the pattern's type here. If the type is dependent, they can't 
diff er,
+  // per core issue 1668. Substitute into the type from the pattern, in 
case
+  // it's instantiation-dependent.
+  // FIXME: Updating the type to work around this is at best fragile.
+  if (!PatternDecl->getType()->isDependentType()) {
+QualType T = S.SubstType(PatternParam->getType(), TemplateArgs,
+ FunctionParam->getLocation(),
+ FunctionParam->getDeclName());
+if (T.isNull())
+  return true;
+FunctionParam->setType(T);
+  }
+
+  Scope.InstantiatedLocal(PatternParam, FunctionParam);
+  ++FParamIdx;
+  continue;
+}
+
+// Expand the parameter pack.
+Scope.MakeInstantiatedLocalArgPack(PatternParam);
+Optional NumArgumentsInExpansion
+  = S.getNumArgumentsInExpansion(PatternParam->getType(), TemplateArgs);
+if (NumArgumentsInExpansion) {
+  QualType PatternType =
+  PatternParam->getType()->castAs()->getPattern();
+  for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg) {
+ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
+FunctionParam->setDeclName(PatternParam->getDeclName());
+if (!PatternDecl->getType()->isDependentType()) {
+  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, Arg);
+  QualType T = S.SubstType(PatternType, TemplateArgs,
+   FunctionParam->getLocation(),
+   FunctionParam->getDeclName());
+  if (T.isNull())
+return true;
+  FunctionParam->setType(T);
+}
+
+Scope.InstantiatedLocalPackArg(PatternParam, FunctionParam);
+++FParamIdx;
+  }
+}
+  }
+
+  return false;
+}
+
 /// Adjust the given function type for an instantiation of the
 /// given declaration, to cope with modifications to the function's type that
 /// aren't reflected in the type-source information.
@@ -1848,6 +1912,11 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
   // FIXME: Concepts: Do not substitute into constraint expressions
   Expr *TrailingRequiresClause = D->getTrailingRequiresClause();
   if (TrailingRequiresClause) {
+if (D->isTemplateInstantiation() &&
+addInstantiatedParametersToScope(
+SemaRef, D, D->getTemplateInstantiationPattern(), Scope,
+TemplateArgs))
+  return nullptr;
 ExprResult SubstRC = SemaRef.SubstExpr(TrailingRequiresClause,
TemplateArgs);
 if (SubstRC.isInvalid())
@@ -4105,70 +4174,6 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl 
*D,
   return NewTInfo;
 }
 
-/// Introduce the instant

[PATCH] D71966: [Wdocumentation][RFC] Improve identifier's of \param

2020-01-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/include/clang-c/Documentation.h:383
 CINDEX_LINKAGE
-CXString clang_ParamCommandComment_getParamName(CXComment Comment);
 

Mordante wrote:
> gribozavr2 wrote:
> > Please don't modify existing APIs in libclang -- it provides a stable API 
> > and ABI, and what has shipped, can't be changed. New functionality has to 
> > be exposed as new functions, while old functions should be kept working to 
> > the extent possible. It means that the resulting API can be subpar, but oh 
> > well, a stable ABI is a contract of libclang.
> I thought I had read this API was allowed to change, but required adding 
> information to the release notes. (I can't find it quickly.)
> I'll undo the changes to the existing functions and add new functions instead.
> I thought I had read this API was allowed to change

It would be interesting to find that doc. As far as I understand, libclang has 
a strict API & ABI stability rule.

> I'll undo the changes to the existing functions and add new functions instead.

Thanks!




Comment at: clang/include/clang/AST/Comment.h:781
+  /// @param Idx The index of the identifier in the \\param command.
+  StringRef getParamName(unsigned Idx) const LLVM_READONLY {
+return getArgText(Idx);

Mordante wrote:
> gribozavr2 wrote:
> > Users can already call getArgText, do we need a second function that does 
> > the same?
> I thought it made sense to offer these helper functions. `getParamName` seems 
> clearer than `getArgText`. Of course it's also possible to add documentation 
> instead of a helper function. What do you prefer?
> 
> Note: This function is the replacement of `getParamNameAsWritten`, so I can 
> also reinstate its former name.
I prefer using `getArgText`. It works uniformly for all block commands.



Comment at: clang/lib/AST/Comment.cpp:376
+  case InvalidParamIndex:
+return getParamName(Idx);
+

Mordante wrote:
> gribozavr2 wrote:
> > Previously, it was necessary for the index to be valid. Why relax the 
> > contract? (This change also makes things in consistent with, say, TParam).
> IMO it makes it easier on the caller site. If it wants the name of the 
> variable in the current `FullComment` context they can simply call this 
> function. Then they don't need to validate whether the index is valid or not. 
> (I intend to do a similar patch for TParam.)
The issue is that it is unclear what kind of name they get -- the as written 
name, or the mapped one.



Comment at: clang/lib/AST/CommentSema.cpp:852
+  OrphanedParamDecls.erase(OrphanedParamDecls.begin() +
+   CorrectedParamIndex);
+}

Mordante wrote:
> gribozavr2 wrote:
> > I'm not sure about this `erase` call. With this change, once a typo claims 
> > an identifier, it is gone no matter how bad the typo was. Even if there's a 
> > further, closer, typo, that identifier won't be suggested anymore.
> True, but I thought it was not allowed for fixits to give invalid hints. 
> Using the same correction twice will result in new warnings. What do you 
> think?
> True, but I thought it was not allowed for fixits to give invalid hints.

Fixits are allowed to be incorrect. Any fixit can be incorrect semantically 
(the user actually intended something different), even if it perfectly fixes 
the C++ and Doxygen issues.

> Using the same correction twice will result in new warnings.

I don't think users will apply all fixits without subsequent review. In an IDE 
setting, users pick and choose fixits.

Also, not reusing the same correction twice does not guarantee that the fixes 
are correct; it only ensures that we won't have a new warning about duplicated 
parameter names.



Comment at: clang/lib/AST/JSONNodeDumper.cpp:1586
+for (unsigned I = 0; I != E; ++I) {
+  Params.push_back(C->getParamName(FC, I));
+

Mordante wrote:
> gribozavr2 wrote:
> > Despite what the old code does (I didn't review it when it was submitted), 
> > I think it is more useful to dump the parameter name as written, not as 
> > found in the function declaration.
> You want the behaviour for all AST dumpers? (I assume yes)
Yes, I'd prefer it everywhere.



Comment at: clang/lib/Index/CommentToXML.cpp:748
+  if (E) {
+Result << "";
+for (unsigned I = 0; I != E; ++I) {

Mordante wrote:
> gribozavr2 wrote:
> > Why do we need an extra "" wrapping the list of parameters?
> What would you propose instead? No "" and just a list of 
> "" ?
Yep, "" can directly contain multiple "" tags.


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

https://reviews.llvm.org/D71966



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


[PATCH] D73109: [clang][index] Index the injected class name types.

2020-01-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62058 tests passed, 0 failed 
and 784 were skipped.

{icon question-circle color=gray} clang-tidy: unknown.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73109



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


[PATCH] D73162: [test] Avoid loop-unroll.c test getting confused by fadd in git revision

2020-01-22 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop created this revision.
russell.gallop added a reviewer: asbirlea.
Herald added a subscriber: zzheng.
Herald added a project: clang.

Saw this test failing as it was matching fadd in a (local) git revision:

  F:\git\llvm-project\clang\test\CodeGen\loop-unroll.c:38:30: error: 
CHECK-DISABLE-UNROLL-NOT: excluded string found in input
  // CHECK-DISABLE-UNROLL-NOT: fadd
   ^
  :69:92: note: found here
  !1 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 
a3eebdb6c1376e528a6fadd5eb33bb6eb986a126)"}


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73162

Files:
  clang/test/CodeGen/loop-unroll.c


Index: clang/test/CodeGen/loop-unroll.c
===
--- clang/test/CodeGen/loop-unroll.c
+++ clang/test/CodeGen/loop-unroll.c
@@ -12,15 +12,15 @@
 // CHECK-ENABLE-UNROLL: br i1 %[[EXITCOND:[a-z0-9_\.]+]], label 
%[[FORBODY5:[a-z0-9_\.]+]], label %[[FORBODY]]
 // CHECK-ENABLE-UNROLL: [[FORBODY5]]:
 // CHECK-ENABLE-UNROLL: fmul
-// CHECK-ENABLE-UNROLL: fadd
+// CHECK-ENABLE-UNROLL: fadd double
 // CHECK-ENABLE-UNROLL: store
 // CHECK-ENABLE-UNROLL: fmul
-// CHECK-ENABLE-UNROLL: fadd
+// CHECK-ENABLE-UNROLL: fadd double
 // CHECK-ENABLE-UNROLL: store
 // CHECK-ENABLE-UNROLL: fmul
-// CHECK-ENABLE-UNROLL: fadd
+// CHECK-ENABLE-UNROLL: fadd double
 // CHECK-ENABLE-UNROLL: store

 // CHECK-DISABLE-UNROLL-LABEL: @for_test()
 // CHECK-DISABLE-UNROLL: br label %[[FORBODY:[a-z0-9_\.]+]]
 // CHECK-DISABLE-UNROLL: [[FORBODY]]:
@@ -29,17 +29,17 @@
 // CHECK-DISABLE-UNROLL: br i1 %[[EXITCOND:[a-z0-9_\.]+]], label 
%[[FORBODY5:[a-z0-9_\.]+]], label %[[FORBODY]]
 // CHECK-DISABLE-UNROLL: [[FORBODY5]]:
 // CHECK-DISABLE-UNROLL: fmul
-// CHECK-DISABLE-UNROLL: fadd
+// CHECK-DISABLE-UNROLL: fadd double
 // CHECK-DISABLE-UNROLL: store
 // CHECK-DISABLE-UNROLL: fmul
-// CHECK-DISABLE-UNROLL: fadd
+// CHECK-DISABLE-UNROLL: fadd double
 // CHECK-DISABLE-UNROLL: store
 // CHECK-DISABLE-UNROLL-NOT: fmul
-// CHECK-DISABLE-UNROLL-NOT: fadd
+// CHECK-DISABLE-UNROLL-NOT: fadd double
 // CHECK-DISABLE-UNROLL-NOT: store

 int printf(const char * restrict format, ...);

 void for_test() {
   double A[1000], B[1000];
   int L = 500;


Index: clang/test/CodeGen/loop-unroll.c
===
--- clang/test/CodeGen/loop-unroll.c
+++ clang/test/CodeGen/loop-unroll.c
@@ -12,15 +12,15 @@
 // CHECK-ENABLE-UNROLL: br i1 %[[EXITCOND:[a-z0-9_\.]+]], label %[[FORBODY5:[a-z0-9_\.]+]], label %[[FORBODY]]
 // CHECK-ENABLE-UNROLL: [[FORBODY5]]:
 // CHECK-ENABLE-UNROLL: fmul
-// CHECK-ENABLE-UNROLL: fadd
+// CHECK-ENABLE-UNROLL: fadd double
 // CHECK-ENABLE-UNROLL: store
 // CHECK-ENABLE-UNROLL: fmul
-// CHECK-ENABLE-UNROLL: fadd
+// CHECK-ENABLE-UNROLL: fadd double
 // CHECK-ENABLE-UNROLL: store
 // CHECK-ENABLE-UNROLL: fmul
-// CHECK-ENABLE-UNROLL: fadd
+// CHECK-ENABLE-UNROLL: fadd double
 // CHECK-ENABLE-UNROLL: store

 // CHECK-DISABLE-UNROLL-LABEL: @for_test()
 // CHECK-DISABLE-UNROLL: br label %[[FORBODY:[a-z0-9_\.]+]]
 // CHECK-DISABLE-UNROLL: [[FORBODY]]:
@@ -29,17 +29,17 @@
 // CHECK-DISABLE-UNROLL: br i1 %[[EXITCOND:[a-z0-9_\.]+]], label %[[FORBODY5:[a-z0-9_\.]+]], label %[[FORBODY]]
 // CHECK-DISABLE-UNROLL: [[FORBODY5]]:
 // CHECK-DISABLE-UNROLL: fmul
-// CHECK-DISABLE-UNROLL: fadd
+// CHECK-DISABLE-UNROLL: fadd double
 // CHECK-DISABLE-UNROLL: store
 // CHECK-DISABLE-UNROLL: fmul
-// CHECK-DISABLE-UNROLL: fadd
+// CHECK-DISABLE-UNROLL: fadd double
 // CHECK-DISABLE-UNROLL: store
 // CHECK-DISABLE-UNROLL-NOT: fmul
-// CHECK-DISABLE-UNROLL-NOT: fadd
+// CHECK-DISABLE-UNROLL-NOT: fadd double
 // CHECK-DISABLE-UNROLL-NOT: store

 int printf(const char * restrict format, ...);

 void for_test() {
   double A[1000], B[1000];
   int L = 500;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73106: [Alignment][NFC] Use Align with CreateMaskedStore

2020-01-22 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet updated this revision to Diff 239513.
gchatelet marked an inline comment as done.
gchatelet added a comment.

- Reverting LangRef


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73106

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  llvm/include/llvm/IR/Constants.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/IRBuilder.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2343,7 +2343,7 @@
   Value *ShuffledMask = Builder.CreateShuffleVector(
   BlockInMaskPart, Undefs, RepMask, "interleaved.mask");
   NewStoreInstr = Builder.CreateMaskedStore(
-  IVec, AddrParts[Part], Group->getAlignment(), ShuffledMask);
+  IVec, AddrParts[Part], Group->getAlign(), ShuffledMask);
 }
 else
   NewStoreInstr = Builder.CreateAlignedStore(IVec, AddrParts[Part],
@@ -2449,8 +2449,8 @@
 }
 auto *VecPtr = CreateVecPtr(Part, State.get(Addr, {0, 0}));
 if (isMaskRequired)
-  NewSI = Builder.CreateMaskedStore(
-  StoredVal, VecPtr, Alignment.value(), BlockInMaskParts[Part]);
+  NewSI = Builder.CreateMaskedStore(StoredVal, VecPtr, Alignment,
+BlockInMaskParts[Part]);
 else
   NewSI =
   Builder.CreateAlignedStore(StoredVal, VecPtr, Alignment.value());
Index: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -2904,7 +2904,7 @@
 IRBuilder<> IRB(&I);
 Value *V = I.getArgOperand(0);
 Value *Addr = I.getArgOperand(1);
-const MaybeAlign Alignment(
+const Align Alignment(
 cast(I.getArgOperand(2))->getZExtValue());
 Value *Mask = I.getArgOperand(3);
 Value *Shadow = getShadow(V);
@@ -2921,21 +2921,20 @@
   insertShadowCheck(Mask, &I);
 }
 
-IRB.CreateMaskedStore(Shadow, ShadowPtr, Alignment ? Alignment->value() : 0,
-  Mask);
+IRB.CreateMaskedStore(Shadow, ShadowPtr, Alignment, Mask);
 
 if (MS.TrackOrigins) {
   auto &DL = F.getParent()->getDataLayout();
   paintOrigin(IRB, getOrigin(V), OriginPtr,
   DL.getTypeStoreSize(Shadow->getType()),
-  llvm::max(Alignment, kMinOriginAlignment));
+  std::max(Alignment, kMinOriginAlignment));
 }
   }
 
   bool handleMaskedLoad(IntrinsicInst &I) {
 IRBuilder<> IRB(&I);
 Value *Addr = I.getArgOperand(0);
-const MaybeAlign Alignment(
+const Align Alignment(
 cast(I.getArgOperand(1))->getZExtValue());
 Value *Mask = I.getArgOperand(2);
 Value *PassThru = I.getArgOperand(3);
@@ -2945,7 +2944,7 @@
 if (PropagateShadow) {
   std::tie(ShadowPtr, OriginPtr) =
   getShadowOriginPtr(Addr, IRB, ShadowTy, Alignment, /*isStore*/ false);
-  setShadow(&I, IRB.CreateMaskedLoad(ShadowPtr, *Alignment, Mask,
+  setShadow(&I, IRB.CreateMaskedLoad(ShadowPtr, Alignment, Mask,
  getShadow(PassThru), "_msmaskedld"));
 } else {
   setShadow(&I, getCleanShadow(&I));
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1372,7 +1372,7 @@
   // on each element's most significant bit (the sign bit).
   Constant *BoolMask = getNegativeIsTrueBoolVec(ConstMask);
 
-  IC.Builder.CreateMaskedStore(Vec, PtrCast, 1, BoolMask);
+  IC.Builder.CreateMaskedStore(Vec, PtrCast, Align::None(), BoolMask);
 
   // 'Replace uses' doesn't work for stores. Erase the original masked store.
   IC.eraseInstFromFunction(II);
Index: llvm/lib/IR/IRBuilder.cpp
===
--- llvm/lib/IR/IRBuilder.cpp
+++ llvm/lib/IR/IRBuilder.cpp
@@ -487,19 +487,19 @@
 }
 
 /// Create a call to a Masked Store intrinsic.
-/// \p Val   - data to be stored,
-/// \p Ptr   - base pointer for the store
-/// \p Align - alignment of the destination location
-/// \p Mask  - vector of booleans which indicates what vector lanes should
-///be accessed in memory
+/// \p Val   - data to be stored,
+/// \p Ptr   - base pointer for the store
+/// \p Alignment - alignment of the destination location
+/// \p Mask  - 

[PATCH] D72932: [ARM] Follow AACPS standard for volatile bit-fields access width

2020-01-22 Thread Diogo N. Sampaio via Phabricator via cfe-commits
dnsampaio added a comment.

In D72932#1829716 , @ostannard wrote:

> Why are you doing this in CodeGen, rather than adjusting the existing layout 
> code in CGRecordLowering? Doing it this way will result in 
> AdjustAAPCSBitfieldLValue being called for every access to the bitfield, 
> rather than just once. This is probably more fragile too, because it's 
> spreading the logic across multiple parts of the codebase, and has to undo 
> some of the layout done by CGRecordLowering.


@olista01 Indeed, after looking at the `CGRecordLayout` I am not kind for doing 
this change. It will require changing all possible initialization, with a 
sensible value, and add a special getAddress function that would consider if an 
access is volatile. I don't believe that volatile accesses are that frequent 
that this would pose much of an overhead, perhaps we can leave it as a todo to 
move it there?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72932



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


[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

the scope of this patch is not very clear, the changes touch two different code 
parts `SymbolCollector`, and `Rename`, and we are lacking tests for 
`SymbolCollector`. I'd suggest spliting this patch into smaller patches:

- a patch that adds a new kind to the ref, and updates the `SymbolCollector`
- a patch that updates the rename accordingly




Comment at: clang-tools-extra/clangd/index/Ref.h:33
+  Reference = 1 << 2,
+  Spelled = 1 << 3,
+  All = Declaration | Definition | Reference | Spelled,

could you please add some brief documentation on these fields?



Comment at: clang-tools-extra/clangd/index/Ref.h:34
+  Spelled = 1 << 3,
+  All = Declaration | Definition | Reference | Spelled,
 };

The `All` now indicates all spelled refs. I think `All` should include both 
non-spelled and spell refs, which should be `declaration | Definition | 
Reference`.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:591
+  const auto MainFileID = SM.getMainFileID();
+  if (const auto MainFileURI = GetURI(MainFileID)) {
+assert(ASTCtx && "ASTContext must be set.");

looks like we don't use the `MainFileURI` variable below, I think we can remove 
this `if` statement.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:598
+  syntax::tokenize(MainFileID, SM, ASTCtx->getLangOpts());
+const auto Tokens = FilesToTokensCache[MainFileID];
+for (auto &DeclAndRef : DeclRefs) {

since we only use `FilesToTokensCache` in this function, make it as a local 
variable rather than class member.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:599
+const auto Tokens = FilesToTokensCache[MainFileID];
+for (auto &DeclAndRef : DeclRefs) {
+  if (auto ID = getSymbolID(DeclAndRef.first)) {

note that the `DeclRefs` may contains references from non-main files, e.g. 
included headers if `RefsInHeaders` is true. I think we need to tokenize other 
files if the reference is not from main file.   `CollectRef` lambda is a better 
place to place the `FilesToTokensCache` logic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746



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


[PATCH] D73106: [Alignment][NFC] Use Align with CreateMaskedStore

2020-01-22 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet marked an inline comment as done.
gchatelet added inline comments.



Comment at: llvm/docs/LangRef.rst:14945
 
-The first operand is the base pointer for the load. The second operand is the 
alignment of the source location. It must be a constant integer value. The 
third operand, mask, is a vector of boolean values with the same number of 
elements as the return type. The fourth is a pass-through value that is used to 
fill the masked-off lanes of the result. The return type, underlying type of 
the base pointer and the type of the '``passthru``' operand are the same vector 
types.
-
+The first operand is the base pointer for the load. The second operand is the 
alignment of the source location. It must be a power of two constant integer 
value. The third operand, mask, is a vector of boolean values with the same 
number of elements as the return type. The fourth is a pass-through value that 
is used to fill the masked-off lanes of the result. The return type, underlying 
type of the base pointer and the type of the '``passthru``' operand are the 
same vector types.
 

courbet wrote:
> Let's commit this as a base change, as this is just documenting what the 
> verifier is already checking.
Done as rG1d549e68d4ac58e5fcdc1c9c6d2d09334fab4fbf


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73106



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


[PATCH] D72932: [ARM] Follow AACPS standard for volatile bit-fields access width

2020-01-22 Thread Diogo N. Sampaio via Phabricator via cfe-commits
dnsampaio added a comment.

In D72932#1829716 , @ostannard wrote:

> Why are you doing this in CodeGen, rather than adjusting the existing layout 
> code in CGRecordLowering? Doing it this way will result in 
> AdjustAAPCSBitfieldLValue being called for every access to the bitfield, 
> rather than just once. This is probably more fragile too, because it's 
> spreading the logic across multiple parts of the codebase, and has to undo 
> some of the layout done by CGRecordLowering.


@ostannard Indeed, after looking at the `CGRecordLayout` I am not kind for 
doing this change. It will require changing all possible initializations, with 
a sensible value. And either way, codegen will also need to change, to define 
the address, it must know if it is volatile or not. I don't believe that 
recomputing it a every access would pose much of an overhead, perhaps we can 
leave it as a TODO to move it there?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72932



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


[clang] 0957233 - [Alignment][NFC] Use Align with CreateMaskedStore

2020-01-22 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2020-01-22T11:04:39+01:00
New Revision: 0957233320eb0096bbb7665e0762a13bad1e7cb8

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

LOG: [Alignment][NFC] Use Align with CreateMaskedStore

Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: 
http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790

Reviewers: courbet

Subscribers: hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
llvm/include/llvm/IR/Constants.h
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/IRBuilder.cpp
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 29eebbb403ea..86a3f1e0d237 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9714,9 +9714,8 @@ static Value *getMaskVecValue(CodeGenFunction &CGF, Value 
*Mask,
   return MaskVec;
 }
 
-static Value *EmitX86MaskedStore(CodeGenFunction &CGF,
- ArrayRef Ops,
- unsigned Align) {
+static Value *EmitX86MaskedStore(CodeGenFunction &CGF, ArrayRef Ops,
+ Align Alignment) {
   // Cast the pointer to right type.
   Value *Ptr = CGF.Builder.CreateBitCast(Ops[0],

llvm::PointerType::getUnqual(Ops[1]->getType()));
@@ -9724,7 +9723,7 @@ static Value *EmitX86MaskedStore(CodeGenFunction &CGF,
   Value *MaskVec = getMaskVecValue(CGF, Ops[2],
Ops[1]->getType()->getVectorNumElements());
 
-  return CGF.Builder.CreateMaskedStore(Ops[1], Ptr, Align, MaskVec);
+  return CGF.Builder.CreateMaskedStore(Ops[1], Ptr, Alignment, MaskVec);
 }
 
 static Value *EmitX86MaskedLoad(CodeGenFunction &CGF, ArrayRef Ops,
@@ -10592,12 +10591,12 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI__builtin_ia32_storedquqi512_mask:
   case X86::BI__builtin_ia32_storeupd512_mask:
   case X86::BI__builtin_ia32_storeups512_mask:
-return EmitX86MaskedStore(*this, Ops, 1);
+return EmitX86MaskedStore(*this, Ops, Align::None());
 
   case X86::BI__builtin_ia32_storess128_mask:
-  case X86::BI__builtin_ia32_storesd128_mask: {
-return EmitX86MaskedStore(*this, Ops, 1);
-  }
+  case X86::BI__builtin_ia32_storesd128_mask:
+return EmitX86MaskedStore(*this, Ops, Align::None());
+
   case X86::BI__builtin_ia32_vpopcntb_128:
   case X86::BI__builtin_ia32_vpopcntd_128:
   case X86::BI__builtin_ia32_vpopcntq_128:
@@ -10708,11 +10707,11 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI__builtin_ia32_movdqa32store512_mask:
   case X86::BI__builtin_ia32_movdqa64store512_mask:
   case X86::BI__builtin_ia32_storeaps512_mask:
-  case X86::BI__builtin_ia32_storeapd512_mask: {
-unsigned Align =
-  getContext().getTypeAlignInChars(E->getArg(1)->getType()).getQuantity();
-return EmitX86MaskedStore(*this, Ops, Align);
-  }
+  case X86::BI__builtin_ia32_storeapd512_mask:
+return EmitX86MaskedStore(
+*this, Ops,
+
getContext().getTypeAlignInChars(E->getArg(1)->getType()).getAsAlign());
+
   case X86::BI__builtin_ia32_loadups128_mask:
   case X86::BI__builtin_ia32_loadups256_mask:
   case X86::BI__builtin_ia32_loadups512_mask:

diff  --git a/llvm/include/llvm/IR/Constants.h 
b/llvm/include/llvm/IR/Constants.h
index 262ab439df65..9b3c1e723a10 100644
--- a/llvm/include/llvm/IR/Constants.h
+++ b/llvm/include/llvm/IR/Constants.h
@@ -157,6 +157,10 @@ class ConstantInt final : public ConstantData {
 return Val.getSExtValue();
   }
 
+  /// Return the constant as an llvm::Align. Note that this method can assert 
if
+  /// the value does not fit in 64 bits or is not a power of two.
+  inline Align getAlignValue() const { return Align(getZExtValue()); }
+
   /// A helper method that can be used to determine if the constant contained
   /// within is equal to a constant.  This only works for very small values,
   /// because this is all that can be represented with all types.

diff  --git a/llvm/include/llvm/IR/IRBuilder.h 
b/llvm/include/llvm/IR/IRBuilder.h
index b02945f98101..4d242ae64067 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -752,13 +752,21 @@ class IRBuilderBase {
  

[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/Ref.h:34
+  Spelled = 1 << 3,
+  All = Declaration | Definition | Reference | Spelled,
 };

hokein wrote:
> The `All` now indicates all spelled refs. I think `All` should include both 
> non-spelled and spell refs, which should be `declaration | Definition | 
> Reference`.
I don't follow the argument here ,`All` is rather a bitmask that should be 
`OR`d with a `RefKindSet`.
It is not like we were saying only the references that are both declarations 
and  definitions were acceptable before, we were saying All implies either a 
declaration, definition or a reference in here. So the logic seems to be 
correct.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746



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


[PATCH] D73106: [Alignment][NFC] Use Align with CreateMaskedStore

2020-01-22 Thread Guillaume Chatelet via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0957233320eb: [Alignment][NFC] Use Align with 
CreateMaskedStore (authored by gchatelet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73106

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  llvm/include/llvm/IR/Constants.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/IRBuilder.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2343,7 +2343,7 @@
   Value *ShuffledMask = Builder.CreateShuffleVector(
   BlockInMaskPart, Undefs, RepMask, "interleaved.mask");
   NewStoreInstr = Builder.CreateMaskedStore(
-  IVec, AddrParts[Part], Group->getAlignment(), ShuffledMask);
+  IVec, AddrParts[Part], Group->getAlign(), ShuffledMask);
 }
 else
   NewStoreInstr = Builder.CreateAlignedStore(IVec, AddrParts[Part],
@@ -2449,8 +2449,8 @@
 }
 auto *VecPtr = CreateVecPtr(Part, State.get(Addr, {0, 0}));
 if (isMaskRequired)
-  NewSI = Builder.CreateMaskedStore(
-  StoredVal, VecPtr, Alignment.value(), BlockInMaskParts[Part]);
+  NewSI = Builder.CreateMaskedStore(StoredVal, VecPtr, Alignment,
+BlockInMaskParts[Part]);
 else
   NewSI =
   Builder.CreateAlignedStore(StoredVal, VecPtr, Alignment.value());
Index: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -2904,7 +2904,7 @@
 IRBuilder<> IRB(&I);
 Value *V = I.getArgOperand(0);
 Value *Addr = I.getArgOperand(1);
-const MaybeAlign Alignment(
+const Align Alignment(
 cast(I.getArgOperand(2))->getZExtValue());
 Value *Mask = I.getArgOperand(3);
 Value *Shadow = getShadow(V);
@@ -2921,21 +2921,20 @@
   insertShadowCheck(Mask, &I);
 }
 
-IRB.CreateMaskedStore(Shadow, ShadowPtr, Alignment ? Alignment->value() : 0,
-  Mask);
+IRB.CreateMaskedStore(Shadow, ShadowPtr, Alignment, Mask);
 
 if (MS.TrackOrigins) {
   auto &DL = F.getParent()->getDataLayout();
   paintOrigin(IRB, getOrigin(V), OriginPtr,
   DL.getTypeStoreSize(Shadow->getType()),
-  llvm::max(Alignment, kMinOriginAlignment));
+  std::max(Alignment, kMinOriginAlignment));
 }
   }
 
   bool handleMaskedLoad(IntrinsicInst &I) {
 IRBuilder<> IRB(&I);
 Value *Addr = I.getArgOperand(0);
-const MaybeAlign Alignment(
+const Align Alignment(
 cast(I.getArgOperand(1))->getZExtValue());
 Value *Mask = I.getArgOperand(2);
 Value *PassThru = I.getArgOperand(3);
@@ -2945,7 +2944,7 @@
 if (PropagateShadow) {
   std::tie(ShadowPtr, OriginPtr) =
   getShadowOriginPtr(Addr, IRB, ShadowTy, Alignment, /*isStore*/ false);
-  setShadow(&I, IRB.CreateMaskedLoad(ShadowPtr, *Alignment, Mask,
+  setShadow(&I, IRB.CreateMaskedLoad(ShadowPtr, Alignment, Mask,
  getShadow(PassThru), "_msmaskedld"));
 } else {
   setShadow(&I, getCleanShadow(&I));
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1372,7 +1372,7 @@
   // on each element's most significant bit (the sign bit).
   Constant *BoolMask = getNegativeIsTrueBoolVec(ConstMask);
 
-  IC.Builder.CreateMaskedStore(Vec, PtrCast, 1, BoolMask);
+  IC.Builder.CreateMaskedStore(Vec, PtrCast, Align::None(), BoolMask);
 
   // 'Replace uses' doesn't work for stores. Erase the original masked store.
   IC.eraseInstFromFunction(II);
Index: llvm/lib/IR/IRBuilder.cpp
===
--- llvm/lib/IR/IRBuilder.cpp
+++ llvm/lib/IR/IRBuilder.cpp
@@ -487,19 +487,19 @@
 }
 
 /// Create a call to a Masked Store intrinsic.
-/// \p Val   - data to be stored,
-/// \p Ptr   - base pointer for the store
-/// \p Align - alignment of the destination location
-/// \p Mask  - vector of booleans which indicates what vector lanes should
-///be accessed in memory
+/// \p Val   - data to be stored,
+/// \p Ptr   - base pointer for the store
+/// \p Alignment - alignment of the

[PATCH] D72867: [clangd] Support renaming designated initializers

2020-01-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/unittests/FindTargetTests.cpp:566
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
-TU.ExtraArgs.push_back("-std=c++17");
+TU.ExtraArgs.push_back("-std=c++2a");
 

sammccall wrote:
> isn't this spelled c++20 yet?
(No, it's not)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72867



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


[PATCH] D72647: [clangd] Only re-open files if their flags changed

2020-01-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Let's make the minimal change here and land this.




Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:1126
+  std::set ModifiedFiles;
+  auto Sub =
+  CDB->watch([&ModifiedFiles](const std::vector Changes) {

dgoldman wrote:
> sammccall wrote:
> > this is a clever technique. (Why not just use compilationDatabaseChanges 
> > directly? I suppose because then you have to deal more with path 
> > canonicalization?)
> > 
> > it risks having the CDB change concurrently and reloading those files too, 
> > though.
> > I guess there's not much harm in it. But in that case, why aren't we just 
> > permanently subscribing to CDB changes and re-parsing affected files? Lack 
> > of a thread to do it on?
> Yeah I think `compilationDatabaseChanges` would be equivalent to what is here 
> now, I can just swap to that.
> 
> For the perma subscribe I wasn't sure of the threading. If addDocument is 
> thread safe I think we're okay to just call `Server->AddDocument` from 
> whatever thread without holding a mutex?
ClangdServer isn't threadsafe, that's a good point.

> Yeah I think compilationDatabaseChanges would be equivalent to what is here 
> now, I can just swap to that.
This is the minimal change, let's do that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72647



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


[clang] 7b81c3f - Revert "[Concepts] Fix bug when referencing function parameters in instantiated function template requires clause"

2020-01-22 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-22T12:16:35+02:00
New Revision: 7b81c3f8793d30a4285095a9b67dcfca2117916c

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

LOG: Revert "[Concepts] Fix bug when referencing function parameters in 
instantiated function template requires clause"

This temporarily reverts commit 45538b5fb280e5b2903f7924fd4fa5b07a6dd3ea which 
breaks a test.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/instantiate-requires-clause.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 410e1f0f0984..2f2c06bb72de 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1766,70 +1766,6 @@ Decl 
*TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) {
   return Record;
 }
 
-/// Introduce the instantiated function parameters into the local
-/// instantiation scope, and set the parameter names to those used
-/// in the template.
-static bool addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function,
- const FunctionDecl *PatternDecl,
- LocalInstantiationScope &Scope,
-   const MultiLevelTemplateArgumentList &TemplateArgs) 
{
-  unsigned FParamIdx = 0;
-  for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) {
-const ParmVarDecl *PatternParam = PatternDecl->getParamDecl(I);
-if (!PatternParam->isParameterPack()) {
-  // Simple case: not a parameter pack.
-  assert(FParamIdx < Function->getNumParams());
-  ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
-  FunctionParam->setDeclName(PatternParam->getDeclName());
-  // If the parameter's type is not dependent, update it to match the type
-  // in the pattern. They can 
diff er in top-level cv-qualifiers, and we want
-  // the pattern's type here. If the type is dependent, they can't 
diff er,
-  // per core issue 1668. Substitute into the type from the pattern, in 
case
-  // it's instantiation-dependent.
-  // FIXME: Updating the type to work around this is at best fragile.
-  if (!PatternDecl->getType()->isDependentType()) {
-QualType T = S.SubstType(PatternParam->getType(), TemplateArgs,
- FunctionParam->getLocation(),
- FunctionParam->getDeclName());
-if (T.isNull())
-  return true;
-FunctionParam->setType(T);
-  }
-
-  Scope.InstantiatedLocal(PatternParam, FunctionParam);
-  ++FParamIdx;
-  continue;
-}
-
-// Expand the parameter pack.
-Scope.MakeInstantiatedLocalArgPack(PatternParam);
-Optional NumArgumentsInExpansion
-  = S.getNumArgumentsInExpansion(PatternParam->getType(), TemplateArgs);
-if (NumArgumentsInExpansion) {
-  QualType PatternType =
-  PatternParam->getType()->castAs()->getPattern();
-  for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg) {
-ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
-FunctionParam->setDeclName(PatternParam->getDeclName());
-if (!PatternDecl->getType()->isDependentType()) {
-  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, Arg);
-  QualType T = S.SubstType(PatternType, TemplateArgs,
-   FunctionParam->getLocation(),
-   FunctionParam->getDeclName());
-  if (T.isNull())
-return true;
-  FunctionParam->setType(T);
-}
-
-Scope.InstantiatedLocalPackArg(PatternParam, FunctionParam);
-++FParamIdx;
-  }
-}
-  }
-
-  return false;
-}
-
 /// Adjust the given function type for an instantiation of the
 /// given declaration, to cope with modifications to the function's type that
 /// aren't reflected in the type-source information.
@@ -1912,11 +1848,6 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
   // FIXME: Concepts: Do not substitute into constraint expressions
   Expr *TrailingRequiresClause = D->getTrailingRequiresClause();
   if (TrailingRequiresClause) {
-if (D->isTemplateInstantiation() &&
-addInstantiatedParametersToScope(
-SemaRef, D, D->getTemplateInstantiationPattern(), Scope,
-TemplateArgs))
-  return nullptr;
 ExprResult SubstRC = SemaRef.SubstExpr(TrailingRequiresClause,
TemplateArgs);
 if (SubstRC.isInvalid())
@@ -4184,6 +4115,70 @@ TemplateDeclInstantiator::SubstFunctionType(FunctionDecl 
*D,
   return NewTInfo;
 }
 
+/// Introduce the instantia

[PATCH] D73166: [ASTImporter] Properly delete decls from SavedImportPaths

2020-01-22 Thread Jaroslav Sevcik via Phabricator via cfe-commits
jarin created this revision.
jarin added reviewers: martong, teemperor.
Herald added subscribers: cfe-commits, rnkovacs.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: clang.

We see a significant regression (~40% slower on large codebases) in expression 
evaluation after https://reviews.llvm.org/rL364771. A sampling profile shows 
the extra time is spent in SavedImportPathsTy::operator[] when called from 
ASTImporter::Import. I believe this is because ASTImporter::Import adds an 
element to the SavedImportPaths map for each decl unconditionally (see 
https://github.com/llvm/llvm-project/blob/7b81c3f8793d30a4285095a9b67dcfca2117916c/clang/lib/AST/ASTImporter.cpp#L8256).

To fix this, we call SavedImportPathsTy::erase on the declaration rather than 
clearing its value vector. That way we do not accidentally introduce new empty 
elements.  (With this patch the performance is restored, and we do not see 
SavedImportPathsTy::operator[] in the profile anymore.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73166

Files:
  clang/lib/AST/ASTImporter.cpp


Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -8241,7 +8241,7 @@
   // FIXME Should we remove these Decls from the LookupTable,
   // and from ImportedFromDecls?
   }
-SavedImportPaths[FromD].clear();
+SavedImportPaths.erase(FromD);
 
 // Do not return ToDOrErr, error was taken out of it.
 return make_error(ErrOut);
@@ -8274,7 +8274,7 @@
   Imported(FromD, ToD);
 
   updateFlags(FromD, ToD);
-  SavedImportPaths[FromD].clear();
+  SavedImportPaths.erase(FromD);
   return ToDOrErr;
 }
 


Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -8241,7 +8241,7 @@
   // FIXME Should we remove these Decls from the LookupTable,
   // and from ImportedFromDecls?
   }
-SavedImportPaths[FromD].clear();
+SavedImportPaths.erase(FromD);
 
 // Do not return ToDOrErr, error was taken out of it.
 return make_error(ErrOut);
@@ -8274,7 +8274,7 @@
   Imported(FromD, ToD);
 
   updateFlags(FromD, ToD);
-  SavedImportPaths[FromD].clear();
+  SavedImportPaths.erase(FromD);
   return ToDOrErr;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 9570f1e - [clangd] Do not duplicate TemplatedDecls in findExplicitReferences

2020-01-22 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-01-22T11:43:53+01:00
New Revision: 9570f1e5a612348e92c2f149f5073ef06f9e5da5

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

LOG: [clangd] Do not duplicate TemplatedDecls in findExplicitReferences

Reviewers: hokein

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index bed32c394089..31cdcee0cfe7 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -586,6 +586,13 @@ llvm::SmallVector refInDecl(const Decl 
*D) {
 }
 
 void VisitNamedDecl(const NamedDecl *ND) {
+  // We choose to ignore {Class, Function, Var, TypeAlias}TemplateDecls. As
+  // as their underlying decls, covering the same range, will be visited.
+  if (llvm::isa(ND) ||
+  llvm::isa(ND) ||
+  llvm::isa(ND) ||
+  llvm::isa(ND))
+return;
   // FIXME: decide on how to surface destructors when we need them.
   if (llvm::isa(ND))
 return;

diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index c6ad75144f96..ed3da28aa0d1 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -741,21 +741,17 @@ TEST_F(FindExplicitReferencesTest, All) {
{R"cpp(
 namespace foo {
   template 
-  class $1^$2^Bar {
-~$3^Bar();
-void $4^f($5^Bar);
+  class $1^Bar {
+~$2^Bar();
+void $3^f($4^Bar);
   };
 }
   )cpp",
 "0: targets = {foo::Bar::T}, decl\n"
-// FIXME: avoid the 2 duplicated foo::Bar references below, the first
-// one comes from ClassTemplateDecl; the second comes from the
-// underlying CXXRecordDecl.
 "1: targets = {foo::Bar}, decl\n"
-"2: targets = {foo::Bar}, decl\n"
-"3: targets = {foo::Bar}\n"
-"4: targets = {foo::Bar::f}, decl\n"
-"5: targets = {foo::Bar}\n"},
+"2: targets = {foo::Bar}\n"
+"3: targets = {foo::Bar::f}, decl\n"
+"4: targets = {foo::Bar}\n"},
// MemberExpr should know their using declaration.
{R"cpp(
 struct X { void func(int); };
@@ -1055,7 +1051,47 @@ TEST_F(FindExplicitReferencesTest, All) {
   }
 )cpp",
"0: targets = {Test}\n"
-   "1: targets = {a}, decl\n"}};
+   "1: targets = {a}, decl\n"},
+   // Templates
+   {R"cpp(
+namespace foo {
+  template 
+  class $1^Bar {};
+}
+  )cpp",
+"0: targets = {foo::Bar::T}, decl\n"
+"1: targets = {foo::Bar}, decl\n"},
+   // Templates
+   {R"cpp(
+namespace foo {
+  template 
+  void $1^func();
+}
+  )cpp",
+"0: targets = {T}, decl\n"
+"1: targets = {foo::func}, decl\n"},
+   // Templates
+   {R"cpp(
+namespace foo {
+  template 
+  $1^T $2^x;
+}
+  )cpp",
+"0: targets = {foo::T}, decl\n"
+"1: targets = {foo::T}\n"
+"2: targets = {foo::x}, decl\n"},
+   // Templates
+   {R"cpp(
+template class vector {};
+namespace foo {
+  template 
+  using $1^V = $2^vector<$3^T>;
+}
+  )cpp",
+"0: targets = {foo::T}, decl\n"
+"1: targets = {foo::V}, decl\n"
+"2: targets = {vector}\n"
+"3: targets = {foo::T}\n"}};
 
   for (const auto &C : Cases) {
 llvm::StringRef ExpectedCode = C.first;



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


[PATCH] D73101: [clangd] Do not duplicate TemplatedDecls in findExplicitReferences

2020-01-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 239523.
kadircet marked 2 inline comments as done.
kadircet added a comment.

- Update comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73101

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -741,21 +741,17 @@
{R"cpp(
 namespace foo {
   template 
-  class $1^$2^Bar {
-~$3^Bar();
-void $4^f($5^Bar);
+  class $1^Bar {
+~$2^Bar();
+void $3^f($4^Bar);
   };
 }
   )cpp",
 "0: targets = {foo::Bar::T}, decl\n"
-// FIXME: avoid the 2 duplicated foo::Bar references below, the first
-// one comes from ClassTemplateDecl; the second comes from the
-// underlying CXXRecordDecl.
 "1: targets = {foo::Bar}, decl\n"
-"2: targets = {foo::Bar}, decl\n"
-"3: targets = {foo::Bar}\n"
-"4: targets = {foo::Bar::f}, decl\n"
-"5: targets = {foo::Bar}\n"},
+"2: targets = {foo::Bar}\n"
+"3: targets = {foo::Bar::f}, decl\n"
+"4: targets = {foo::Bar}\n"},
// MemberExpr should know their using declaration.
{R"cpp(
 struct X { void func(int); };
@@ -1055,7 +1051,47 @@
   }
 )cpp",
"0: targets = {Test}\n"
-   "1: targets = {a}, decl\n"}};
+   "1: targets = {a}, decl\n"},
+   // Templates
+   {R"cpp(
+namespace foo {
+  template 
+  class $1^Bar {};
+}
+  )cpp",
+"0: targets = {foo::Bar::T}, decl\n"
+"1: targets = {foo::Bar}, decl\n"},
+   // Templates
+   {R"cpp(
+namespace foo {
+  template 
+  void $1^func();
+}
+  )cpp",
+"0: targets = {T}, decl\n"
+"1: targets = {foo::func}, decl\n"},
+   // Templates
+   {R"cpp(
+namespace foo {
+  template 
+  $1^T $2^x;
+}
+  )cpp",
+"0: targets = {foo::T}, decl\n"
+"1: targets = {foo::T}\n"
+"2: targets = {foo::x}, decl\n"},
+   // Templates
+   {R"cpp(
+template class vector {};
+namespace foo {
+  template 
+  using $1^V = $2^vector<$3^T>;
+}
+  )cpp",
+"0: targets = {foo::T}, decl\n"
+"1: targets = {foo::V}, decl\n"
+"2: targets = {vector}\n"
+"3: targets = {foo::T}\n"}};
 
   for (const auto &C : Cases) {
 llvm::StringRef ExpectedCode = C.first;
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -586,6 +586,13 @@
 }
 
 void VisitNamedDecl(const NamedDecl *ND) {
+  // We choose to ignore {Class, Function, Var, TypeAlias}TemplateDecls. As
+  // as their underlying decls, covering the same range, will be visited.
+  if (llvm::isa(ND) ||
+  llvm::isa(ND) ||
+  llvm::isa(ND) ||
+  llvm::isa(ND))
+return;
   // FIXME: decide on how to surface destructors when we need them.
   if (llvm::isa(ND))
 return;


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -741,21 +741,17 @@
{R"cpp(
 namespace foo {
   template 
-  class $1^$2^Bar {
-~$3^Bar();
-void $4^f($5^Bar);
+  class $1^Bar {
+~$2^Bar();
+void $3^f($4^Bar);
   };
 }
   )cpp",
 "0: targets = {foo::Bar::T}, decl\n"
-// FIXME: avoid the 2 duplicated foo::Bar references below, the first
-// one comes from ClassTemplateDecl; the second comes from the
-// underlying CXXRecordDecl.
 "1: targets = {foo::Bar}, decl\n"
-"2: targets = {foo::Bar}, decl\n"
-"3: targets = {foo::Bar}\n"
-"4: targets = {foo::Bar::f}, decl\n"
-"5: targets = {foo::Bar}\n"},
+"2: targets = {foo::Bar}\n"
+"3: targets = {foo::Bar::f}, decl\n"
+"4: targets = {foo::Bar}\n"},
// MemberExpr should know their using declaration.
{R"cpp(
 struct X { void func(int); };
@@ -1055,7 +1051,47 @@
  

[PATCH] D73101: [clangd] Do not duplicate TemplatedDecls in findExplicitReferences

2020-01-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9570f1e5a612: [clangd] Do not duplicate TemplatedDecls in 
findExplicitReferences (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73101

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -741,21 +741,17 @@
{R"cpp(
 namespace foo {
   template 
-  class $1^$2^Bar {
-~$3^Bar();
-void $4^f($5^Bar);
+  class $1^Bar {
+~$2^Bar();
+void $3^f($4^Bar);
   };
 }
   )cpp",
 "0: targets = {foo::Bar::T}, decl\n"
-// FIXME: avoid the 2 duplicated foo::Bar references below, the first
-// one comes from ClassTemplateDecl; the second comes from the
-// underlying CXXRecordDecl.
 "1: targets = {foo::Bar}, decl\n"
-"2: targets = {foo::Bar}, decl\n"
-"3: targets = {foo::Bar}\n"
-"4: targets = {foo::Bar::f}, decl\n"
-"5: targets = {foo::Bar}\n"},
+"2: targets = {foo::Bar}\n"
+"3: targets = {foo::Bar::f}, decl\n"
+"4: targets = {foo::Bar}\n"},
// MemberExpr should know their using declaration.
{R"cpp(
 struct X { void func(int); };
@@ -1055,7 +1051,47 @@
   }
 )cpp",
"0: targets = {Test}\n"
-   "1: targets = {a}, decl\n"}};
+   "1: targets = {a}, decl\n"},
+   // Templates
+   {R"cpp(
+namespace foo {
+  template 
+  class $1^Bar {};
+}
+  )cpp",
+"0: targets = {foo::Bar::T}, decl\n"
+"1: targets = {foo::Bar}, decl\n"},
+   // Templates
+   {R"cpp(
+namespace foo {
+  template 
+  void $1^func();
+}
+  )cpp",
+"0: targets = {T}, decl\n"
+"1: targets = {foo::func}, decl\n"},
+   // Templates
+   {R"cpp(
+namespace foo {
+  template 
+  $1^T $2^x;
+}
+  )cpp",
+"0: targets = {foo::T}, decl\n"
+"1: targets = {foo::T}\n"
+"2: targets = {foo::x}, decl\n"},
+   // Templates
+   {R"cpp(
+template class vector {};
+namespace foo {
+  template 
+  using $1^V = $2^vector<$3^T>;
+}
+  )cpp",
+"0: targets = {foo::T}, decl\n"
+"1: targets = {foo::V}, decl\n"
+"2: targets = {vector}\n"
+"3: targets = {foo::T}\n"}};
 
   for (const auto &C : Cases) {
 llvm::StringRef ExpectedCode = C.first;
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -586,6 +586,13 @@
 }
 
 void VisitNamedDecl(const NamedDecl *ND) {
+  // We choose to ignore {Class, Function, Var, TypeAlias}TemplateDecls. As
+  // as their underlying decls, covering the same range, will be visited.
+  if (llvm::isa(ND) ||
+  llvm::isa(ND) ||
+  llvm::isa(ND) ||
+  llvm::isa(ND))
+return;
   // FIXME: decide on how to surface destructors when we need them.
   if (llvm::isa(ND))
 return;


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -741,21 +741,17 @@
{R"cpp(
 namespace foo {
   template 
-  class $1^$2^Bar {
-~$3^Bar();
-void $4^f($5^Bar);
+  class $1^Bar {
+~$2^Bar();
+void $3^f($4^Bar);
   };
 }
   )cpp",
 "0: targets = {foo::Bar::T}, decl\n"
-// FIXME: avoid the 2 duplicated foo::Bar references below, the first
-// one comes from ClassTemplateDecl; the second comes from the
-// underlying CXXRecordDecl.
 "1: targets = {foo::Bar}, decl\n"
-"2: targets = {foo::Bar}, decl\n"
-"3: targets = {foo::Bar}\n"
-"4: targets = {foo::Bar::f}, decl\n"
-"5: targets = {foo::Bar}\n"},
+"2: targets = {foo::Bar}\n"
+"3: targets = {foo::Bar::f}, decl\n"
+"4: targets = {foo::Bar}\n"},
// MemberExpr should know their using declaration.
{R"cpp(
 

[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/index/Ref.h:34
+  Spelled = 1 << 3,
+  All = Declaration | Definition | Reference | Spelled,
 };

kadircet wrote:
> hokein wrote:
> > The `All` now indicates all spelled refs. I think `All` should include both 
> > non-spelled and spell refs, which should be `declaration | Definition | 
> > Reference`.
> I don't follow the argument here ,`All` is rather a bitmask that should be 
> `OR`d with a `RefKindSet`.
> It is not like we were saying only the references that are both declarations 
> and  definitions were acceptable before, we were saying All implies either a 
> declaration, definition or a reference in here. So the logic seems to be 
> correct.
ah, you are right, I misthought about that, thanks for the clarification.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746



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


[PATCH] D72959: Relative VTables ABI on Fuchsia

2020-01-22 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

In D72959#1832011 , @pcc wrote:

> > On Aarch64, right now only CALL26 and JUMP26 instructions generate PLT 
> > relocations, so we manifest them with stubs that are just jumps to the 
> > original function.
>
> I think it would be worth considering defining a new relocation type for 
> this. I think we should make the new reloc type represent the relative 
> address shifted right by 2, which would allow it to be used freely in the 
> aarch64 small code model (which permits programs up to 4GB), but would 
> require the target to be 4-byte aligned, which seems like a reasonable 
> restriction. On aarch64, decoding this would not require any additional 
> instructions either (we can fold the lsl into the add). We could use the same 
> technique for a new GOTPCREL relocation to be used for the RTTI component. 
> @peter.smith what do you think?


The idea of a new relocation type has come up before, as I recall it was 
something like the equivalent of R_X86_PLT32

  | R_X86_64_PLT32 | 4 | word32 | L + A - P |
  Where L is defined as: L Represents the place (section offset or address) of 
the Procedure Linkage Table entry for a symbol.

For Fuchsia there are two options:
1.) Ask for an ABI relocation type to be defined. I've raised an ABI issue with 
Arm, for it to progress I think it needs a "yes we really would like one, here 
is the definition we want to use, this is the use case and it could be used 
outside of Fuchsia at some point." For example I can see position independent 
C++ being useful in bare-metal embedded C++. The external facing email for 
feedback on the abi is arm.e...@arm.com (address is on the first page of the 
doc below)
2.) There are two ranges of relocation types reserved for private and platform 
relocations: 
https://developer.arm.com/docs/ihi0056/f/elf-for-the-arm-64-bit-architecture-aarch64-abi-2019q2-documentation

  Private and platform-specific relocations
  Private relocations for vendor experiments:
  
  0xE000 to 0xEFFF for ELF64
  0xE0 to 0xEF for ELF32
  Platform ABI defined relocations:
  
  0xF000 to 0x for ELF64
  0xF0 to 0xFF for ELF32
  Platform ABI relocations can only be interpreted when the EI_OSABI field is 
set to indicate the Platform ABI governing the definition.
  
  All of the above codes will not be assigned by any future version of this 
standard.

If this could be generally useful outside of Fuchsia, then an official 
relocation would be preferable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72959



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


[PATCH] D73101: [clangd] Do not duplicate TemplatedDecls in findExplicitReferences

2020-01-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62094 tests passed, 0 failed 
and 785 were skipped.

{icon question-circle color=gray} clang-tidy: unknown.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73101



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


[PATCH] D72373: [clang-tidy] extend misc-misplaced-const to detect using besides typedef

2020-01-22 Thread Alexander Lanin via Phabricator via cfe-commits
AlexanderLanin added a comment.

ping

> Could someone commit this? As I can not.
>  Alexander Lanin 




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

https://reviews.llvm.org/D72373



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


[PATCH] D73025: [AArch64][SVE] Add first-faulting load intrinsic

2020-01-22 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen accepted this revision.
sdesmalen added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:11248
 
-static SDValue performLDNF1Combine(SDNode *N, SelectionDAG &DAG) {
+static SDValue performLDNF1Combine(SDNode *N, SelectionDAG &DAG, bool isFF) {
   SDLoc DL(N);

instead of passing in `bool isFF`, can we just pass in the opcode directly?


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

https://reviews.llvm.org/D73025



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


[PATCH] D72097: [LifetimeAnalysis] Do not forbid void deref type in gsl::Pointer/gsl::Owner annotations

2020-01-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

Sorry, just getting back to this review. Your justification makes sense, and 
the patch LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72097



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


[PATCH] D71698: [AArch64][SVE] Add intrinsic for non-faulting loads

2020-01-22 Thread Kerry McLaughlin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcdcc4f2a44b5: [AArch64][SVE] Add intrinsic for non-faulting 
loads (authored by kmclaughlin).

Changed prior to commit:
  https://reviews.llvm.org/D71698?vs=239144&id=239531#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71698

Files:
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
  llvm/lib/Target/AArch64/SVEInstrFormats.td
  llvm/test/CodeGen/AArch64/sve-intrinsics-loads-nf.ll

Index: llvm/test/CodeGen/AArch64/sve-intrinsics-loads-nf.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/sve-intrinsics-loads-nf.ll
@@ -0,0 +1,182 @@
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+
+define  @ldnf1b( %pg, i8* %a) {
+; CHECK-LABEL: ldnf1b:
+; CHECK: ldnf1b { z0.b }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv16i8( %pg, i8* %a)
+  ret  %load
+}
+
+define  @ldnf1b_h( %pg, i8* %a) {
+; CHECK-LABEL: ldnf1b_h:
+; CHECK: ldnf1b { z0.h }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv8i8( %pg, i8* %a)
+  %res = zext  %load to 
+  ret  %res
+}
+
+define  @ldnf1sb_h( %pg, i8* %a) {
+; CHECK-LABEL: ldnf1sb_h:
+; CHECK: ldnf1sb { z0.h }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv8i8( %pg, i8* %a)
+  %res = sext  %load to 
+  ret  %res
+}
+
+define  @ldnf1h( %pg, i16* %a) {
+; CHECK-LABEL: ldnf1h:
+; CHECK: ldnf1h { z0.h }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv8i16( %pg, i16* %a)
+  ret  %load
+}
+
+define  @ldnf1h_f16( %pg, half* %a) {
+; CHECK-LABEL: ldnf1h_f16:
+; CHECK: ldnf1h { z0.h }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv8f16( %pg, half* %a)
+  ret  %load
+}
+
+define  @ldnf1b_s( %pg, i8* %a) {
+; CHECK-LABEL: ldnf1b_s:
+; CHECK: ldnf1b { z0.s }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv4i8( %pg, i8* %a)
+  %res = zext  %load to 
+  ret  %res
+}
+
+define  @ldnf1sb_s( %pg, i8* %a) {
+; CHECK-LABEL: ldnf1sb_s:
+; CHECK: ldnf1sb { z0.s }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv4i8( %pg, i8* %a)
+  %res = sext  %load to 
+  ret  %res
+}
+
+define  @ldnf1h_s( %pg, i16* %a) {
+; CHECK-LABEL: ldnf1h_s:
+; CHECK: ldnf1h { z0.s }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv4i16( %pg, i16* %a)
+  %res = zext  %load to 
+  ret  %res
+}
+
+define  @ldnf1sh_s( %pg, i16* %a) {
+; CHECK-LABEL: ldnf1sh_s:
+; CHECK: ldnf1sh { z0.s }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv4i16( %pg, i16* %a)
+  %res = sext  %load to 
+  ret  %res
+}
+
+define  @ldnf1w( %pg, i32* %a) {
+; CHECK-LABEL: ldnf1w:
+; CHECK: ldnf1w { z0.s }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv4i32( %pg, i32* %a)
+  ret  %load
+}
+
+define  @ldnf1w_f32( %pg, float* %a) {
+; CHECK-LABEL: ldnf1w_f32:
+; CHECK: ldnf1w { z0.s }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv4f32( %pg, float* %a)
+  ret  %load
+}
+
+define  @ldnf1b_d( %pg, i8* %a) {
+; CHECK-LABEL: ldnf1b_d:
+; CHECK: ldnf1b { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv2i8( %pg, i8* %a)
+  %res = zext  %load to 
+  ret  %res
+}
+
+define  @ldnf1sb_d( %pg, i8* %a) {
+; CHECK-LABEL: ldnf1sb_d:
+; CHECK: ldnf1sb { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv2i8( %pg, i8* %a)
+  %res = sext  %load to 
+  ret  %res
+}
+
+define  @ldnf1h_d( %pg, i16* %a) {
+; CHECK-LABEL: ldnf1h_d:
+; CHECK: ldnf1h { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv2i16( %pg, i16* %a)
+  %res = zext  %load to 
+  ret  %res
+}
+
+define  @ldnf1sh_d( %pg, i16* %a) {
+; CHECK-LABEL: ldnf1sh_d:
+; CHECK: ldnf1sh { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv2i16( %pg, i16* %a)
+  %res = sext  %load to 
+  ret  %res
+}
+
+define  @ldnf1w_d( %pg, i32* %a) {
+; CHECK-LABEL: ldnf1w_d:
+; CHECK: ldnf1w { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv2i32( %pg, i32* %a)
+  %res = zext  %load to 
+  ret  %res
+}
+
+define  @ldnf1sw_d( %pg, i32* %a) {
+; CHECK-LABEL: ldnf1sw_d:
+; CHECK: ldnf1sw { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv2i32( %pg, i32* %a)
+  %res = sext  %load to 
+  ret  %res
+}
+
+define  @ldnf1d( %pg, i64* %a) {
+; CHECK-LABEL: ldnf1d:
+; CHECK: ldnf1d { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldnf1.nxv2i64( %pg, i64* %a)
+  ret  %load
+}
+
+define  @ldnf1d_f64( 

[PATCH] D31338: Move ParsedAttrInfos into a registry and point to one in ParsedAttr

2020-01-22 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 239536.
john.brawn added a comment.

Updated to match latest changes to D31337 .


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

https://reviews.llvm.org/D31338

Files:
  clang/include/clang/Sema/CMakeLists.txt
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/Basic/Attributes.cpp
  clang/lib/Sema/ParsedAttr.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -55,8 +55,6 @@
  llvm::raw_ostream &OS);
 void EmitClangAttrParsedAttrImpl(llvm::RecordKeeper &Records,
  llvm::raw_ostream &OS);
-void EmitClangAttrParsedAttrKinds(llvm::RecordKeeper &Records,
-  llvm::raw_ostream &OS);
 void EmitClangAttrTextNodeDump(llvm::RecordKeeper &Records,
llvm::raw_ostream &OS);
 void EmitClangAttrNodeTraverse(llvm::RecordKeeper &Records,
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -39,7 +39,6 @@
   GenClangAttrTemplateInstantiate,
   GenClangAttrParsedAttrList,
   GenClangAttrParsedAttrImpl,
-  GenClangAttrParsedAttrKinds,
   GenClangAttrTextNodeDump,
   GenClangAttrNodeTraverse,
   GenClangBasicReader,
@@ -122,9 +121,6 @@
 clEnumValN(GenClangAttrParsedAttrImpl,
"gen-clang-attr-parsed-attr-impl",
"Generate the clang parsed attribute helpers"),
-clEnumValN(GenClangAttrParsedAttrKinds,
-   "gen-clang-attr-parsed-attr-kinds",
-   "Generate a clang parsed attribute kinds"),
 clEnumValN(GenClangAttrTextNodeDump, "gen-clang-attr-text-node-dump",
"Generate clang attribute text node dumper"),
 clEnumValN(GenClangAttrNodeTraverse, "gen-clang-attr-node-traverse",
@@ -257,9 +253,6 @@
   case GenClangAttrParsedAttrImpl:
 EmitClangAttrParsedAttrImpl(Records, OS);
 break;
-  case GenClangAttrParsedAttrKinds:
-EmitClangAttrParsedAttrKinds(Records, OS);
-break;
   case GenClangAttrTextNodeDump:
 EmitClangAttrTextNodeDump(Records, OS);
 break;
Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -158,12 +158,14 @@
 typedef std::vector> ParsedAttrMap;
 
 static ParsedAttrMap getParsedAttrList(const RecordKeeper &Records,
-   ParsedAttrMap *Dupes = nullptr) {
+   ParsedAttrMap *Dupes = nullptr,
+   bool IncludeIgnored = false) {
   std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
   std::set Seen;
   ParsedAttrMap R;
   for (const auto *Attr : Attrs) {
-if (Attr->getValueAsBit("SemaHandler")) {
+if (Attr->getValueAsBit("SemaHandler") ||
+(IncludeIgnored && Attr->getValueAsBit("Ignored"))) {
   std::string AN;
   if (Attr->isSubClassOf("TargetSpecificAttr") &&
   !Attr->isValueUnset("ParseKind")) {
@@ -3590,9 +3592,10 @@
   getPragmaAttributeSupport(Records);
 
   // Get the list of parsed attributes, and accept the optional list of
-  // duplicates due to the ParseKind.
+  // duplicates due to the ParseKind. We also want to include ignored
+  // attributes as we want them to be successfully matched.
   ParsedAttrMap Dupes;
-  ParsedAttrMap Attrs = getParsedAttrList(Records, &Dupes);
+  ParsedAttrMap Attrs = getParsedAttrList(Records, &Dupes, true);
 
   // Generate the appertainsTo diagnostic methods and write their names into
   // another mapping. At the same time, generate the AttrInfoMap object
@@ -3608,10 +3611,18 @@
 // the spellings are identical, and custom parsing rules match, etc.
 
 // We need to generate struct instances based off ParsedAttrInfo from
-// ParsedAttr.cpp.
+// ParsedAttr.h.
 const Record &Attr = *I->second;
-SS << "struct ParsedAttrInfo" << I->first << " : public ParsedAttrInfo {\n";
-SS << "  ParsedAttrInfo" << I->first << "() {\n";
+const std::string &AttrName = I->first;
+std::vector Spellings = GetFlattenedSpellings(Attr);
+std::string AttrInfoName = "AttrInfo" + AttrName;
+SS << "struct " << AttrInfoName << " : public ParsedAttrInfo {\n";
+SS << "  " << AttrInfoName << "() {\n";
+if (Attr.getValueAsBit("Ignored")) {
+  SS << "AttrKind = ParsedAttr::IgnoredAttribute;\n";
+} else {
+  SS << "AttrKind = ParsedAttr::AT_" << AttrName << ";\n";
+}
 

[PATCH] D31337: Use virtual functions in ParsedAttrInfo instead of function pointers

2020-01-22 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 239535.
john.brawn added a comment.

Update based on review comments. Also fix warnings due to missing virtual 
destructor that I hadn't noticed before.


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

https://reviews.llvm.org/D31337

Files:
  clang/lib/Sema/ParsedAttr.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1801,7 +1801,7 @@
 
   void emitMatchRuleList(raw_ostream &OS);
 
-  std::string generateStrictConformsTo(const Record &Attr, raw_ostream &OS);
+  void generateStrictConformsTo(const Record &Attr, raw_ostream &OS);
 
   void generateParsingHelpers(raw_ostream &OS);
 };
@@ -1962,21 +1962,17 @@
   return Test;
 }
 
-std::string
+void
 PragmaClangAttributeSupport::generateStrictConformsTo(const Record &Attr,
   raw_ostream &OS) {
-  if (!isAttributedSupported(Attr))
-return "nullptr";
+  if (!isAttributedSupported(Attr) || Attr.isValueUnset("Subjects"))
+return;
   // Generate a function that constructs a set of matching rules that describe
   // to which declarations the attribute should apply to.
-  std::string FnName = "matchRulesFor" + Attr.getName().str();
-  OS << "static void " << FnName << "(llvm::SmallVectorImpl> &MatchRules, const LangOptions &LangOpts) {\n";
-  if (Attr.isValueUnset("Subjects")) {
-OS << "}\n\n";
-return FnName;
-  }
+ << ", bool>> &MatchRules, const LangOptions &LangOpts) const {\n";
   const Record *SubjectObj = Attr.getValueAsDef("Subjects");
   std::vector Subjects = SubjectObj->getValueAsListOfDefs("Subjects");
   for (const auto *Subject : Subjects) {
@@ -1993,7 +1989,6 @@
 }
   }
   OS << "}\n\n";
-  return FnName;
 }
 
 void PragmaClangAttributeSupport::generateParsingHelpers(raw_ostream &OS) {
@@ -3287,14 +3282,8 @@
 
   // If there is a variadic argument, we will set the optional argument count
   // to its largest value. Since it's currently a 4-bit number, we set it to 15.
-  OS << ArgCount << ", " << (HasVariadic ? 15 : OptCount);
-}
-
-static void GenerateDefaultAppertainsTo(raw_ostream &OS) {
-  OS << "static bool defaultAppertainsTo(Sema &, const ParsedAttr &,";
-  OS << "const Decl *) {\n";
-  OS << "  return true;\n";
-  OS << "}\n\n";
+  OS << "NumArgs = " << ArgCount << ";\n";
+  OS << "OptArgs = " << (HasVariadic ? 15 : OptCount) << ";\n";
 }
 
 static std::string GetDiagnosticSpelling(const Record &R) {
@@ -3408,11 +3397,12 @@
   return FnName;
 }
 
-static std::string GenerateAppertainsTo(const Record &Attr, raw_ostream &OS) {
+static void GenerateAppertainsTo(const Record &Attr, raw_ostream &SS,
+ raw_ostream &OS) {
   // If the attribute does not contain a Subjects definition, then use the
   // default appertainsTo logic.
   if (Attr.isValueUnset("Subjects"))
-return "defaultAppertainsTo";
+return;
 
   const Record *SubjectObj = Attr.getValueAsDef("Subjects");
   std::vector Subjects = SubjectObj->getValueAsListOfDefs("Subjects");
@@ -3420,22 +3410,19 @@
   // If the list of subjects is empty, it is assumed that the attribute
   // appertains to everything.
   if (Subjects.empty())
-return "defaultAppertainsTo";
+return;
 
   bool Warn = SubjectObj->getValueAsDef("Diag")->getValueAsBit("Warn");
 
   // Otherwise, generate an appertainsTo check specific to this attribute which
-  // checks all of the given subjects against the Decl passed in. Return the
-  // name of that check to the caller.
+  // checks all of the given subjects against the Decl passed in.
   //
   // If D is null, that means the attribute was not applied to a declaration
   // at all (for instance because it was applied to a type), or that the caller
   // has determined that the check should fail (perhaps prior to the creation
   // of the declaration).
-  std::string FnName = "check" + Attr.getName().str() + "AppertainsTo";
-  std::stringstream SS;
-  SS << "static bool " << FnName << "(Sema &S, const ParsedAttr &Attr, ";
-  SS << "const Decl *D) {\n";
+  SS << "virtual bool diagAppertainsToDecl(Sema &S, ";
+  SS << "const ParsedAttr &Attr, const Decl *D) const {\n";
   SS << "  if (!D || (";
   for (auto I = Subjects.begin(), E = Subjects.end(); I != E; ++I) {
 // If the subject has custom code associated with it, generate a function
@@ -3463,9 +3450,6 @@
   SS << "  }\n";
   SS << "  return true;\n";
   SS << "}\n\n";
-
-  OS << SS.str();
-  return FnName;
 }
 
 static void
@@ -3504,37 +3488,16 @@
   OS << "}\n\n";
 }
 
-static void GenerateDefaultLangOptRequirements(raw_ostream &OS) {
-  OS << "static bool defaultDiagnoseLangOpts(Sema &, ";
-  OS << "const ParsedAttr &) {\n";
-  OS << "  return true;\n";
-  OS << "}\n\n";
-}
-
-static std::string GenerateLangOptRequir

[clang-tools-extra] 201c646 - Remove extra '; ' to fix Wpedantic. NFCI.

2020-01-22 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-01-22T12:08:57Z
New Revision: 201c646b2b9988cdebf6e95d523283009ae2e5ba

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

LOG: Remove extra ';' to fix Wpedantic. NFCI.

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
index aad0ad94456a..c1b27a821ade 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
@@ -172,7 +172,7 @@ ReservedIdentifierCheck::GetDiagInfo(const NamingCheckId 
&ID,
 diag << ID.second
  << getMessageSelectIndex(Failure.Info.KindName);
   }};
-};
+}
 
 } // namespace bugprone
 } // namespace tidy



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


[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 239544.
kbobyrev marked 7 inline comments as done.
kbobyrev added a comment.

Address review comments, add implicit references filter for SymbolCollector,
test changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746

Files:
  clang-tools-extra/clangd/index/Ref.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp

Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -256,21 +256,27 @@
 
 llvm::ArrayRef
 syntax::spelledTokensTouching(SourceLocation Loc,
-  const syntax::TokenBuffer &Tokens) {
+  llvm::ArrayRef Tokens) {
   assert(Loc.isFileID());
-  llvm::ArrayRef All =
-  Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc));
   auto *Right = llvm::partition_point(
-  All, [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
-  bool AcceptRight = Right != All.end() && Right->location() <= Loc;
-  bool AcceptLeft = Right != All.begin() && (Right - 1)->endLocation() >= Loc;
+  Tokens, [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
+  bool AcceptRight = Right != Tokens.end() && Right->location() <= Loc;
+  bool AcceptLeft =
+  Right != Tokens.begin() && (Right - 1)->endLocation() >= Loc;
   return llvm::makeArrayRef(Right - (AcceptLeft ? 1 : 0),
 Right + (AcceptRight ? 1 : 0));
 }
 
+llvm::ArrayRef
+syntax::spelledTokensTouching(SourceLocation Loc,
+  const syntax::TokenBuffer &Tokens) {
+  return spelledTokensTouching(
+  Loc, Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc)));
+}
+
 const syntax::Token *
 syntax::spelledIdentifierTouching(SourceLocation Loc,
-  const syntax::TokenBuffer &Tokens) {
+  llvm::ArrayRef Tokens) {
   for (const syntax::Token &Tok : spelledTokensTouching(Loc, Tokens)) {
 if (Tok.kind() == tok::identifier)
   return &Tok;
@@ -278,6 +284,13 @@
   return nullptr;
 }
 
+const syntax::Token *
+syntax::spelledIdentifierTouching(SourceLocation Loc,
+  const syntax::TokenBuffer &Tokens) {
+  return spelledIdentifierTouching(
+  Loc, Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc)));
+}
+
 std::vector
 TokenBuffer::macroExpansions(FileID FID) const {
   auto FileIt = Files.find(FID);
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/Syntax/Tokens.h
@@ -313,11 +313,22 @@
   const SourceManager *SourceMgr;
 };
 
+/// The spelled tokens that overlap or touch a spelling location Loc.
+/// This always returns 0-2 tokens.
+llvm::ArrayRef
+spelledTokensTouching(SourceLocation Loc, llvm::ArrayRef Tokens);
+
 /// The spelled tokens that overlap or touch a spelling location Loc.
 /// This always returns 0-2 tokens.
 llvm::ArrayRef
 spelledTokensTouching(SourceLocation Loc, const syntax::TokenBuffer &Tokens);
 
+/// The identifier token that overlaps or touches a spelling location Loc.
+/// If there is none, returns nullptr.
+const syntax::Token *
+spelledIdentifierTouching(SourceLocation Loc,
+  llvm::ArrayRef Tokens);
+
 /// The identifier token that overlaps or touches a spelling location Loc.
 /// If there is none, returns nullptr.
 const syntax::Token *
Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -42,6 +42,7 @@
 using ::testing::IsEmpty;
 using ::testing::Not;
 using ::testing::Pair;
+using ::testing::SizeIs;
 using ::testing::UnorderedElementsAre;
 using ::testing::UnorderedElementsAreArray;
 
@@ -700,6 +701,40 @@
   EXPECT_THAT(Refs, IsEmpty());
 }
 
+TEST_F(SymbolCollectorTest, SpelledReference) {
+  Annotations Header(R"cpp(
+  class Foo {};
+  #define MACRO Foo
+  )cpp");
+  Annotations Main(R"cpp(
+  $spelled[[Foo]] Variable1;
+  $macro[[MACRO]] Variable2;
+  )cpp");
+  CollectorOpts.RefFilter = RefKind::All;
+  CollectorOpts.DropImplicitReferences = true;
+  runSymbolCollector(Header.code(), Main.code());
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Foo").ID,
+  HaveRanges(Main.ranges("spelled");
+  EXPEC

[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added inline comments.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:599
+const auto Tokens = FilesToTokensCache[MainFileID];
+for (auto &DeclAndRef : DeclRefs) {
+  if (auto ID = getSymbolID(DeclAndRef.first)) {

hokein wrote:
> note that the `DeclRefs` may contains references from non-main files, e.g. 
> included headers if `RefsInHeaders` is true. I think we need to tokenize 
> other files if the reference is not from main file.   `CollectRef` lambda is 
> a better place to place the `FilesToTokensCache` logic.
> note that the DeclRefs may contains references from non-main files, e.g. 
> included headers if RefsInHeaders is true. I think we need to tokenize other 
> files if the reference is not from main file.

Fair enough, fixed that!

> CollectRef lambda is a better place to place the FilesToTokensCache logic.

I don't really agree with that. In my opinion `CollectRef` should remain a 
simple helper that simply puts pre-processed reference into the storage. 
Complicating it (and also making it work with both `MacroRefs` and `DeclRefs` 
while the token spelling check is only required for declarations looks 
suboptimal to me. If you really want me to do that, please let me know, but I 
personally think it might be better this way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746



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


[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 239545.
kbobyrev added a comment.

Attempt to drop collected reference before doing more computation to improve
performance.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746

Files:
  clang-tools-extra/clangd/index/Ref.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp

Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -256,21 +256,27 @@
 
 llvm::ArrayRef
 syntax::spelledTokensTouching(SourceLocation Loc,
-  const syntax::TokenBuffer &Tokens) {
+  llvm::ArrayRef Tokens) {
   assert(Loc.isFileID());
-  llvm::ArrayRef All =
-  Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc));
   auto *Right = llvm::partition_point(
-  All, [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
-  bool AcceptRight = Right != All.end() && Right->location() <= Loc;
-  bool AcceptLeft = Right != All.begin() && (Right - 1)->endLocation() >= Loc;
+  Tokens, [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
+  bool AcceptRight = Right != Tokens.end() && Right->location() <= Loc;
+  bool AcceptLeft =
+  Right != Tokens.begin() && (Right - 1)->endLocation() >= Loc;
   return llvm::makeArrayRef(Right - (AcceptLeft ? 1 : 0),
 Right + (AcceptRight ? 1 : 0));
 }
 
+llvm::ArrayRef
+syntax::spelledTokensTouching(SourceLocation Loc,
+  const syntax::TokenBuffer &Tokens) {
+  return spelledTokensTouching(
+  Loc, Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc)));
+}
+
 const syntax::Token *
 syntax::spelledIdentifierTouching(SourceLocation Loc,
-  const syntax::TokenBuffer &Tokens) {
+  llvm::ArrayRef Tokens) {
   for (const syntax::Token &Tok : spelledTokensTouching(Loc, Tokens)) {
 if (Tok.kind() == tok::identifier)
   return &Tok;
@@ -278,6 +284,13 @@
   return nullptr;
 }
 
+const syntax::Token *
+syntax::spelledIdentifierTouching(SourceLocation Loc,
+  const syntax::TokenBuffer &Tokens) {
+  return spelledIdentifierTouching(
+  Loc, Tokens.spelledTokens(Tokens.sourceManager().getFileID(Loc)));
+}
+
 std::vector
 TokenBuffer::macroExpansions(FileID FID) const {
   auto FileIt = Files.find(FID);
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/Syntax/Tokens.h
@@ -313,11 +313,22 @@
   const SourceManager *SourceMgr;
 };
 
+/// The spelled tokens that overlap or touch a spelling location Loc.
+/// This always returns 0-2 tokens.
+llvm::ArrayRef
+spelledTokensTouching(SourceLocation Loc, llvm::ArrayRef Tokens);
+
 /// The spelled tokens that overlap or touch a spelling location Loc.
 /// This always returns 0-2 tokens.
 llvm::ArrayRef
 spelledTokensTouching(SourceLocation Loc, const syntax::TokenBuffer &Tokens);
 
+/// The identifier token that overlaps or touches a spelling location Loc.
+/// If there is none, returns nullptr.
+const syntax::Token *
+spelledIdentifierTouching(SourceLocation Loc,
+  llvm::ArrayRef Tokens);
+
 /// The identifier token that overlaps or touches a spelling location Loc.
 /// If there is none, returns nullptr.
 const syntax::Token *
Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -42,6 +42,7 @@
 using ::testing::IsEmpty;
 using ::testing::Not;
 using ::testing::Pair;
+using ::testing::SizeIs;
 using ::testing::UnorderedElementsAre;
 using ::testing::UnorderedElementsAreArray;
 
@@ -700,6 +701,40 @@
   EXPECT_THAT(Refs, IsEmpty());
 }
 
+TEST_F(SymbolCollectorTest, SpelledReference) {
+  Annotations Header(R"cpp(
+  class Foo {};
+  #define MACRO Foo
+  )cpp");
+  Annotations Main(R"cpp(
+  $spelled[[Foo]] Variable1;
+  $macro[[MACRO]] Variable2;
+  )cpp");
+  CollectorOpts.RefFilter = RefKind::All;
+  CollectorOpts.DropImplicitReferences = true;
+  runSymbolCollector(Header.code(), Main.code());
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Foo").ID,
+  HaveRanges(Main.ranges("spelled");
+  EXPECT_THAT(Refs, Contains(Pair(_, HaveRanges(Mai

[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61857 tests passed, 0 failed 
and 781 were skipped.

{icon question-circle color=gray} clang-tidy: unknown.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746



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


[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61857 tests passed, 0 failed 
and 781 were skipped.

{icon question-circle color=gray} clang-tidy: unknown.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746



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


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-22 Thread Eugene Leviant via Phabricator via cfe-commits
evgeny777 added inline comments.



Comment at: clang/test/CodeGenCXX/lto-visibility-inference.cpp:73
   c1->f();
-  // ITANIUM-NOT: type.test{{.*}}!"_ZTS2C2"
+  // ITANIUM: type.test{{.*}}!"_ZTS2C2"
   // MS: type.test{{.*}}!"?AUC2@@"

tejohnson wrote:
> evgeny777 wrote:
> > tejohnson wrote:
> > > evgeny777 wrote:
> > > > What caused this and other changes in this file?
> > > Because we now will insert type tests for non-hidden vtables. This is 
> > > enabled by the changes to LTO to interpret these based on the 
> > > vcall_visibility metadata.
> > The results of this test case
> > ```
> > %clang_cc1 -flto -triple x86_64-pc-windows-msvc -std=c++11 -fms-extensions 
> > -fwhole-program-vtables -flto-visibility-public-std -emit-llvm -o - %s | 
> > FileCheck --check-prefix=MS --check-prefix=MS-NOSTD %s
> > ```
> > look not correct to me. I think you shouldn't generate type tests for 
> > standard library classes with  `-flto-visibility-public-std`. Currently if 
> > this flag is given, clang doesn't do this either even with 
> > `-fvisibility=hidden`
> The associated vtables would get the vcall_visibility public metadata, so the 
> type tests themselves aren't problematic. I tend to think that an application 
> using such options should simply stick with -fvisibility=hidden to get WPD 
> and not use the new LTO option to convert all public vcall_visibility 
> metadata to hidden.
> The associated vtables would get the vcall_visibility public metadata, so the 
> type tests themselves aren't problematic. I tend to think that an application 
> using such options should simply stick with -fvisibility=hidden to get WPD 
> and not use the new LTO option to convert all public vcall_visibility 
> metadata to hidden.

I see two issues here:
1) It's not always good option to force hidden visibility for everything. For 
instance I work on proprietary platform which demands public visibility for 
certain symbols in order for dynamic loader to work properly. In this context 
your patch does a great job.

2) Standard library is almost never LTOed so in general we can't narrow std::* 
vtables visibility to linkage unit

Is there anything which prevents from implementing the same functionality with 
new -lto-whole-program-visibility option (i.e without forcing hidden 
visibility)? In other words the following looks good to me:

```
# Compile with lto/devirtualization support
clang -flto=thin -flto-visibility-public-std -fwhole-program-vtables -c *.cpp

# Link: everything is devirtualized except standard library classes virtual 
methods
clang -Wl,-lto-whole-program-visibility -fuse-ld=lld *.o
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71913



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


[PATCH] D72857: [SYCL] Driver option to enable SYCL mode and select SYCL version

2020-01-22 Thread Alexey Bader via Phabricator via cfe-commits
bader marked 2 inline comments as done.
bader added a comment.

> Maybe we should use the year of issue (2015 instead of 1.2.1) for the 
> -sycl-std version? That would be more stable for the upcoming SYCL versions, 
> and match somehow the C++ versioning.

Sounds good to me. I'll update the patch. I also have a couple of design 
related questions below.




Comment at: clang/include/clang/Basic/LangOptions.def:206
 LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "C++ for OpenCL version")
+ENUM_LANGOPT(SYCLVersion, SYCLVersionList, 4, SYCLVersionList::undefined, 
"Version of the SYCL standard used")
 LANGOPT(NativeHalfType, 1, 0, "Native half type support")

All other language options controlling standard versions are added as "LANGOPT" 
i.e. `int`. Why SYCLVersion is different?
@Ruyk, do you think we should convert other options (e.g. `OpenCL`) to enums as 
well?



Comment at: clang/include/clang/Driver/Options.td:3401
+def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group, 
Flags<[CC1Option]>,
+  HelpText<"SYCL language standard to compile for.">, Values<"1.2.1">;
 

What do you think we integrate sycl versions to existing clang options 
controlling language version: `-std`.
As far as I can see it's used for all the C/C+ extensions like 
OpenMP/OpenCL/CUDA/HIP/ObjC.

If I understand correctly clang supports `-cl-std` only because it's required 
by OpenCL standard. Similar option (i.e. `-sycl-std`) is not required by the 
SYCL specification, so using `-std` is more aligned with existing clang design.

See clang/include/clang/Basic/LangStandard.h and 
clang/include/clang/Basic/LangStandards.def.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72857



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


[PATCH] D73177: [clang][CodeComplete] Make completion work after initializer lists

2020-01-22 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.

CodeCompletion was not being triggered after successfully parsed
initializer lists, e.g.

  cpp
  void foo(int, bool);
  void bar() {
foo({1}^, false);
  }

CodeCompletion would suggest the function foo as an overload candidate up until
the point marked with `^` but after that point we do not trigger signature help
since parsing succeeds.

This patch handles that case by failing in parsing expression lists whenever we
see a codecompletion token, in addition to getting an invalid subexpression.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73177

Files:
  clang/lib/Parse/ParseExpr.cpp
  clang/test/CodeCompletion/call.cpp


Index: clang/test/CodeCompletion/call.cpp
===
--- clang/test/CodeCompletion/call.cpp
+++ clang/test/CodeCompletion/call.cpp
@@ -25,4 +25,10 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:13 %s -o - | 
FileCheck -check-prefix=CHECK-CC2 %s
   // CHECK-CC2-NOT: f(Y y, int ZZ)
   // CHECK-CC2: f(int i, int j, <#int k#>)
+  f({}, 0, 0);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns 
-code-completion-at=%s:28:7 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3: OVERLOAD: [#void#]f()
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#X#>)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#int i#>, int j, int k)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#float x#>, float y)
 }
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -3128,6 +3128,11 @@
 
 if (Tok.is(tok::ellipsis))
   Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
+else if (Tok.is(tok::code_completion)) {
+  SawError = true;
+  cutOffParsing();
+  break;
+}
 if (Expr.isInvalid()) {
   SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
   SawError = true;


Index: clang/test/CodeCompletion/call.cpp
===
--- clang/test/CodeCompletion/call.cpp
+++ clang/test/CodeCompletion/call.cpp
@@ -25,4 +25,10 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:13 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
   // CHECK-CC2-NOT: f(Y y, int ZZ)
   // CHECK-CC2: f(int i, int j, <#int k#>)
+  f({}, 0, 0);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:28:7 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3: OVERLOAD: [#void#]f()
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#X#>)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#int i#>, int j, int k)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#float x#>, float y)
 }
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -3128,6 +3128,11 @@
 
 if (Tok.is(tok::ellipsis))
   Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
+else if (Tok.is(tok::code_completion)) {
+  SawError = true;
+  cutOffParsing();
+  break;
+}
 if (Expr.isInvalid()) {
   SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
   SawError = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73177: [clang][CodeComplete] Make completion work after initializer lists

2020-01-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62094 tests passed, 0 failed 
and 785 were skipped.

{icon question-circle color=gray} clang-tidy: unknown.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73177



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


[PATCH] D73166: [ASTImporter] Properly delete decls from SavedImportPaths

2020-01-22 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

Thanks for the fix! Looks good to me!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73166



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


[clang-tools-extra] ecc7dae - Extend misc-misplaced-const to detect using declarations as well as typedef

2020-01-22 Thread Aaron Ballman via cfe-commits

Author: Alexander Lanin
Date: 2020-01-22T08:45:20-05:00
New Revision: ecc7dae50c41bc8a129a158ecf0ae0270126505c

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

LOG: Extend misc-misplaced-const to detect using declarations as well as typedef

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
clang-tools-extra/docs/clang-tidy/checks/misc-misplaced-const.rst
clang-tools-extra/test/clang-tidy/checkers/misc-misplaced-const.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
index 1e1b2b0d303b..7a028df588ff 100644
--- a/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
@@ -17,13 +17,16 @@ namespace tidy {
 namespace misc {
 
 void MisplacedConstCheck::registerMatchers(MatchFinder *Finder) {
+  auto NonConstAndNonFunctionPointerType = hasType(pointerType(unless(
+  pointee(anyOf(isConstQualified(), ignoringParens(functionType()));
+
   Finder->addMatcher(
-  valueDecl(hasType(isConstQualified()),
-hasType(typedefType(hasDeclaration(
-typedefDecl(hasType(pointerType(unless(pointee(
-anyOf(isConstQualified(),
-  ignoringParens(functionType(
-.bind("typedef")
+  valueDecl(
+  hasType(isConstQualified()),
+  hasType(typedefType(hasDeclaration(anyOf(
+  typedefDecl(NonConstAndNonFunctionPointerType).bind("typedef"),
+  typeAliasDecl(NonConstAndNonFunctionPointerType)
+  .bind("typeAlias"))
   .bind("decl"),
   this);
 }
@@ -45,16 +48,29 @@ static QualType guessAlternateQualification(ASTContext 
&Context, QualType QT) {
 
 void MisplacedConstCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *Var = Result.Nodes.getNodeAs("decl");
-  const auto *Typedef = Result.Nodes.getNodeAs("typedef");
   ASTContext &Ctx = *Result.Context;
   QualType CanQT = Var->getType().getCanonicalType();
 
-  diag(Var->getLocation(), "%0 declared with a const-qualified typedef type; "
-   "results in the type being '%1' instead of '%2'")
-  << Var << CanQT.getAsString(Ctx.getPrintingPolicy())
+  SourceLocation AliasLoc;
+  const char *AliasType;
+  if (const auto *Typedef = Result.Nodes.getNodeAs("typedef")) {
+AliasLoc = Typedef->getLocation();
+AliasType = "typedef";
+  } else if (const auto *TypeAlias =
+ Result.Nodes.getNodeAs("typeAlias")) {
+AliasLoc = TypeAlias->getLocation();
+AliasType = "type alias";
+  } else {
+llvm_unreachable("registerMatchers has registered an unknown matcher,"
+ " code out of sync");
+  }
+
+  diag(Var->getLocation(), "%0 declared with a const-qualified %1; "
+   "results in the type being '%2' instead of '%3'")
+  << Var << AliasType << CanQT.getAsString(Ctx.getPrintingPolicy())
   << guessAlternateQualification(Ctx, CanQT)
  .getAsString(Ctx.getPrintingPolicy());
-  diag(Typedef->getLocation(), "typedef declared here", DiagnosticIDs::Note);
+  diag(AliasLoc, "%0 declared here", DiagnosticIDs::Note) << AliasType;
 }
 
 } // namespace misc

diff  --git a/clang-tools-extra/docs/clang-tidy/checks/misc-misplaced-const.rst 
b/clang-tools-extra/docs/clang-tidy/checks/misc-misplaced-const.rst
index ee1549f11b2d..e583ecb54cac 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc-misplaced-const.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc-misplaced-const.rst
@@ -3,10 +3,10 @@
 misc-misplaced-const
 
 
-This check diagnoses when a ``const`` qualifier is applied to a ``typedef`` to 
a
-pointer type rather than to the pointee, because such constructs are often
-misleading to developers because the ``const`` applies to the pointer rather
-than the pointee.
+This check diagnoses when a ``const`` qualifier is applied to a ``typedef``/
+``using`` to a pointer type rather than to the pointee, because such constructs
+are often misleading to developers because the ``const`` applies to the pointer
+rather than the pointee.
 
 For instance, in the following code, the resulting type is ``int *`` ``const``
 rather than ``const int *``:
@@ -14,9 +14,12 @@ rather than ``const int *``:
 .. code-block:: c++
 
   typedef int *int_ptr;
-  void f(const int_ptr ptr);
+  void f(const int_ptr ptr) {
+*ptr = 0; // potentially quite unexpectedly the int can be modified here
+ptr = 0; // does not compile
+  }
 
-The check does not diagnose when the underlying ``typedef`` type is a pointer 
t

[PATCH] D73177: [clang][CodeComplete] Make completion work after initializer lists

2020-01-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 239555.
kadircet added a comment.

- Add comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73177

Files:
  clang/lib/Parse/ParseExpr.cpp
  clang/test/CodeCompletion/call.cpp


Index: clang/test/CodeCompletion/call.cpp
===
--- clang/test/CodeCompletion/call.cpp
+++ clang/test/CodeCompletion/call.cpp
@@ -25,4 +25,10 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:13 %s -o - | 
FileCheck -check-prefix=CHECK-CC2 %s
   // CHECK-CC2-NOT: f(Y y, int ZZ)
   // CHECK-CC2: f(int i, int j, <#int k#>)
+  f({}, 0, 0);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns 
-code-completion-at=%s:28:7 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3: OVERLOAD: [#void#]f()
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#X#>)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#int i#>, int j, int k)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#float x#>, float y)
 }
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -3128,6 +3128,16 @@
 
 if (Tok.is(tok::ellipsis))
   Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
+else if (Tok.is(tok::code_completion)) {
+  // There's nothing to suggest in here as we parsed a full expression.
+  // Instead fail and propogate the error since caller might have something
+  // the suggest, e.g. signature help in function call. Note that this is
+  // performed before pushing the \p Expr, so that signature help can 
report
+  // current argument correctly.
+  SawError = true;
+  cutOffParsing();
+  break;
+}
 if (Expr.isInvalid()) {
   SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
   SawError = true;


Index: clang/test/CodeCompletion/call.cpp
===
--- clang/test/CodeCompletion/call.cpp
+++ clang/test/CodeCompletion/call.cpp
@@ -25,4 +25,10 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:13 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
   // CHECK-CC2-NOT: f(Y y, int ZZ)
   // CHECK-CC2: f(int i, int j, <#int k#>)
+  f({}, 0, 0);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:28:7 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3: OVERLOAD: [#void#]f()
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#X#>)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#int i#>, int j, int k)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#float x#>, float y)
 }
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -3128,6 +3128,16 @@
 
 if (Tok.is(tok::ellipsis))
   Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
+else if (Tok.is(tok::code_completion)) {
+  // There's nothing to suggest in here as we parsed a full expression.
+  // Instead fail and propogate the error since caller might have something
+  // the suggest, e.g. signature help in function call. Note that this is
+  // performed before pushing the \p Expr, so that signature help can report
+  // current argument correctly.
+  SawError = true;
+  cutOffParsing();
+  break;
+}
 if (Expr.isInvalid()) {
   SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
   SawError = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72373: [clang-tidy] extend misc-misplaced-const to detect using besides typedef

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

I've commit on your behalf in ecc7dae50c41bc8a129a158ecf0ae0270126505c 
. Sorry 
about the delay in committing and thank you for the patch!


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

https://reviews.llvm.org/D72373



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


[PATCH] D72373: [clang-tidy] extend misc-misplaced-const to detect using besides typedef

2020-01-22 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Looks like this breaks tests: http://45.33.8.238/linux/8102/step_8.txt


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

https://reviews.llvm.org/D72373



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


[PATCH] D73177: [clang][CodeComplete] Make completion work after initializer lists

2020-01-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62094 tests passed, 0 failed 
and 785 were skipped.

{icon question-circle color=gray} clang-tidy: unknown.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73177



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


[PATCH] D73166: [ASTImporter] Properly delete decls from SavedImportPaths

2020-01-22 Thread Jaroslav Sevcik via Phabricator via cfe-commits
jarin added a comment.

Thanks for the review!

I am not a committer; could you land the fix for me?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73166



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


[clang-tools-extra] e3b15ed - Revert "Extend misc-misplaced-const to detect using declarations as well as typedef"

2020-01-22 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2020-01-22T09:06:24-05:00
New Revision: e3b15ed376f3753d2a4e16281f8230e4ffed41ba

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

LOG: Revert "Extend misc-misplaced-const to detect using declarations as well 
as typedef"

This reverts commit ecc7dae50c41bc8a129a158ecf0ae0270126505c due to breaking 
bots:

http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/22157
http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/43297

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
clang-tools-extra/docs/clang-tidy/checks/misc-misplaced-const.rst
clang-tools-extra/test/clang-tidy/checkers/misc-misplaced-const.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
index 7a028df588ff..1e1b2b0d303b 100644
--- a/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
@@ -17,16 +17,13 @@ namespace tidy {
 namespace misc {
 
 void MisplacedConstCheck::registerMatchers(MatchFinder *Finder) {
-  auto NonConstAndNonFunctionPointerType = hasType(pointerType(unless(
-  pointee(anyOf(isConstQualified(), ignoringParens(functionType()));
-
   Finder->addMatcher(
-  valueDecl(
-  hasType(isConstQualified()),
-  hasType(typedefType(hasDeclaration(anyOf(
-  typedefDecl(NonConstAndNonFunctionPointerType).bind("typedef"),
-  typeAliasDecl(NonConstAndNonFunctionPointerType)
-  .bind("typeAlias"))
+  valueDecl(hasType(isConstQualified()),
+hasType(typedefType(hasDeclaration(
+typedefDecl(hasType(pointerType(unless(pointee(
+anyOf(isConstQualified(),
+  ignoringParens(functionType(
+.bind("typedef")
   .bind("decl"),
   this);
 }
@@ -48,29 +45,16 @@ static QualType guessAlternateQualification(ASTContext 
&Context, QualType QT) {
 
 void MisplacedConstCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *Var = Result.Nodes.getNodeAs("decl");
+  const auto *Typedef = Result.Nodes.getNodeAs("typedef");
   ASTContext &Ctx = *Result.Context;
   QualType CanQT = Var->getType().getCanonicalType();
 
-  SourceLocation AliasLoc;
-  const char *AliasType;
-  if (const auto *Typedef = Result.Nodes.getNodeAs("typedef")) {
-AliasLoc = Typedef->getLocation();
-AliasType = "typedef";
-  } else if (const auto *TypeAlias =
- Result.Nodes.getNodeAs("typeAlias")) {
-AliasLoc = TypeAlias->getLocation();
-AliasType = "type alias";
-  } else {
-llvm_unreachable("registerMatchers has registered an unknown matcher,"
- " code out of sync");
-  }
-
-  diag(Var->getLocation(), "%0 declared with a const-qualified %1; "
-   "results in the type being '%2' instead of '%3'")
-  << Var << AliasType << CanQT.getAsString(Ctx.getPrintingPolicy())
+  diag(Var->getLocation(), "%0 declared with a const-qualified typedef type; "
+   "results in the type being '%1' instead of '%2'")
+  << Var << CanQT.getAsString(Ctx.getPrintingPolicy())
   << guessAlternateQualification(Ctx, CanQT)
  .getAsString(Ctx.getPrintingPolicy());
-  diag(AliasLoc, "%0 declared here", DiagnosticIDs::Note) << AliasType;
+  diag(Typedef->getLocation(), "typedef declared here", DiagnosticIDs::Note);
 }
 
 } // namespace misc

diff  --git a/clang-tools-extra/docs/clang-tidy/checks/misc-misplaced-const.rst 
b/clang-tools-extra/docs/clang-tidy/checks/misc-misplaced-const.rst
index e583ecb54cac..ee1549f11b2d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc-misplaced-const.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc-misplaced-const.rst
@@ -3,10 +3,10 @@
 misc-misplaced-const
 
 
-This check diagnoses when a ``const`` qualifier is applied to a ``typedef``/
-``using`` to a pointer type rather than to the pointee, because such constructs
-are often misleading to developers because the ``const`` applies to the pointer
-rather than the pointee.
+This check diagnoses when a ``const`` qualifier is applied to a ``typedef`` to 
a
+pointer type rather than to the pointee, because such constructs are often
+misleading to developers because the ``const`` applies to the pointer rather
+than the pointee.
 
 For instance, in the following code, the resulting type is ``int *`` ``const``
 rather than ``const int *``:
@@ -14,12 +14,9 @@ rather than ``const int *``:
 .. code-block:: c++
 
   typedef int *int_ptr;
-  void f(const int_ptr ptr)

[PATCH] D72373: [clang-tidy] extend misc-misplaced-const to detect using besides typedef

2020-01-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D72373#1833569 , @thakis wrote:

> Looks like this breaks tests: http://45.33.8.238/linux/8102/step_8.txt


I reverted in e3b15ed376f3753d2a4e16281f8230e4ffed41ba 
. 
@AlexanderLanin, do you mind taking a look?


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

https://reviews.llvm.org/D72373



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


[clang] 4481eef - [ASTImporter] Properly delete decls from SavedImportPaths

2020-01-22 Thread Raphael Isemann via cfe-commits

Author: Jaroslav Sevcik
Date: 2020-01-22T15:20:06+01:00
New Revision: 4481eefbe8425c63289186dd13319aaa7043e67f

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

LOG: [ASTImporter] Properly delete decls from SavedImportPaths

Summary:
We see a significant regression (~40% slower on large codebases) in expression 
evaluation after https://reviews.llvm.org/rL364771. A sampling profile shows 
the extra time is spent in SavedImportPathsTy::operator[] when called from 
ASTImporter::Import. I believe this is because ASTImporter::Import adds an 
element to the SavedImportPaths map for each decl unconditionally (see 
https://github.com/llvm/llvm-project/blob/7b81c3f8793d30a4285095a9b67dcfca2117916c/clang/lib/AST/ASTImporter.cpp#L8256).

To fix this, we call SavedImportPathsTy::erase on the declaration rather than 
clearing its value vector. That way we do not accidentally introduce new empty 
elements.  (With this patch the performance is restored, and we do not see 
SavedImportPathsTy::operator[] in the profile anymore.)

Reviewers: martong, teemperor, a.sidorin, shafik

Reviewed By: martong

Subscribers: rnkovacs, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 1f2ce30398c9..9dd20e2d5921 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8253,7 +8253,7 @@ Expected ASTImporter::Import(Decl *FromD) {
   // FIXME Should we remove these Decls from the LookupTable,
   // and from ImportedFromDecls?
   }
-SavedImportPaths[FromD].clear();
+SavedImportPaths.erase(FromD);
 
 // Do not return ToDOrErr, error was taken out of it.
 return make_error(ErrOut);
@@ -8286,7 +8286,7 @@ Expected ASTImporter::Import(Decl *FromD) {
   Imported(FromD, ToD);
 
   updateFlags(FromD, ToD);
-  SavedImportPaths[FromD].clear();
+  SavedImportPaths.erase(FromD);
   return ToDOrErr;
 }
 



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


[PATCH] D73182: [CodeGen] Emit IR for fixed-point multiplication and division.

2020-01-22 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan created this revision.
ebevhan added reviewers: rjmccall, leonardchan.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73182

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/Frontend/fixed_point_div.c
  clang/test/Frontend/fixed_point_mul.c

Index: clang/test/Frontend/fixed_point_mul.c
===
--- /dev/null
+++ clang/test/Frontend/fixed_point_mul.c
@@ -0,0 +1,431 @@
+// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
+// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
+
+void SignedMultiplication() {
+  // CHECK-LABEL: SignedMultiplication
+  short _Accum sa;
+  _Accum a, b, c, d;
+  long _Accum la;
+  unsigned short _Accum usa;
+  unsigned _Accum ua;
+  unsigned long _Accum ula;
+
+  short _Fract sf;
+  _Fract f;
+  long _Fract lf;
+  unsigned short _Fract usf;
+  unsigned _Fract uf;
+  unsigned long _Fract ulf;
+
+  // Same type
+  // CHECK:   [[TMP0:%.*]] = load i16, i16* %sa, align 2
+  // CHECK-NEXT:  [[TMP1:%.*]] = load i16, i16* %sa, align 2
+  // CHECK-NEXT:  [[TMP2:%.*]] = call i16 @llvm.smul.fix.i16(i16 [[TMP0]], i16 [[TMP1]], i32 7)
+  // CHECK-NEXT:  store i16 [[TMP2]], i16* %sa, align 2
+  sa = sa * sa;
+
+  // To larger scale and larger width
+  // CHECK:   [[TMP3:%.*]] = load i16, i16* %sa, align 2
+  // CHECK-NEXT:  [[TMP4:%.*]] = load i32, i32* %a, align 4
+  // CHECK-NEXT:  [[RESIZE:%.*]] = sext i16 [[TMP3]] to i32
+  // CHECK-NEXT:  [[UPSCALE:%.*]] = shl i32 [[RESIZE]], 8
+  // CHECK-NEXT:  [[TMP5:%.*]] = call i32 @llvm.smul.fix.i32(i32 [[UPSCALE]], i32 [[TMP4]], i32 15)
+  // CHECK-NEXT:  store i32 [[TMP5]], i32* %a, align 4
+  a = sa * a;
+
+  // To same scale and smaller width
+  // CHECK:   [[TMP6:%.*]] = load i16, i16* %sa, align 2
+  // CHECK-NEXT:  [[TMP7:%.*]] = load i8, i8* %sf, align 1
+  // CHECK-NEXT:  [[RESIZE1:%.*]] = sext i8 [[TMP7]] to i16
+  // CHECK-NEXT:  [[TMP8:%.*]] = call i16 @llvm.smul.fix.i16(i16 [[TMP6]], i16 [[RESIZE1]], i32 7)
+  // CHECK-NEXT:  store i16 [[TMP8]], i16* %sa, align 2
+  sa = sa * sf;
+
+  // To smaller scale and same width.
+  // CHECK:   [[TMP9:%.*]] = load i16, i16* %sa, align 2
+  // CHECK-NEXT:  [[TMP10:%.*]] = load i16, i16* %f, align 2
+  // CHECK-NEXT:  [[RESIZE2:%.*]] = sext i16 [[TMP9]] to i24
+  // CHECK-NEXT:  [[UPSCALE3:%.*]] = shl i24 [[RESIZE2]], 8
+  // CHECK-NEXT:  [[RESIZE4:%.*]] = sext i16 [[TMP10]] to i24
+  // CHECK-NEXT:  [[TMP11:%.*]] = call i24 @llvm.smul.fix.i24(i24 [[UPSCALE3]], i24 [[RESIZE4]], i32 15)
+  // CHECK-NEXT:  [[DOWNSCALE:%.*]] = ashr i24 [[TMP11]], 8
+  // CHECK-NEXT:  [[RESIZE5:%.*]] = trunc i24 [[DOWNSCALE]] to i16
+  // CHECK-NEXT:  store i16 [[RESIZE5]], i16* %sa, align 2
+  sa = sa * f;
+
+  // To smaller scale and smaller width
+  // CHECK:   [[TMP12:%.*]] = load i32, i32* %a, align 4
+  // CHECK-NEXT:  [[TMP13:%.*]] = load i8, i8* %sf, align 1
+  // CHECK-NEXT:  [[RESIZE6:%.*]] = sext i8 [[TMP13]] to i32
+  // CHECK-NEXT:  [[UPSCALE7:%.*]] = shl i32 [[RESIZE6]], 8
+  // CHECK-NEXT:  [[TMP14:%.*]] = call i32 @llvm.smul.fix.i32(i32 [[TMP12]], i32 [[UPSCALE7]], i32 15)
+  // CHECK-NEXT:  store i32 [[TMP14]], i32* %a, align 4
+  a = a * sf;
+
+  // To larger scale and same width
+  // CHECK:   [[TMP15:%.*]] = load i32, i32* %a, align 4
+  // CHECK-NEXT:  [[TMP16:%.*]] = load i32, i32* %lf, align 4
+  // CHECK-NEXT:  [[RESIZE8:%.*]] = sext i32 [[TMP15]] to i48
+  // CHECK-NEXT:  [[UPSCALE9:%.*]] = shl i48 [[RESIZE8]], 16
+  // CHECK-NEXT:  [[RESIZE10:%.*]] = sext i32 [[TMP16]] to i48
+  // CHECK-NEXT:  [[TMP17:%.*]] = call i48 @llvm.smul.fix.i48(i48 [[UPSCALE9]], i48 [[RESIZE10]], i32 31)
+  // CHECK-NEXT:  [[DOWNSCALE11:%.*]] = ashr i48 [[TMP17]], 16
+  // CHECK-NEXT:  [[RESIZE12:%.*]] = trunc i48 [[DOWNSCALE11]] to i32
+  // CHECK-NEXT:  store i32 [[RESIZE12]], i32* %a, align 4
+  a = a * lf;
+
+  // With corresponding unsigned type
+  // CHECK:[[TMP18:%.*]] = load i16, i16* %sa, align 2
+  // CHECK-NEXT:   [[TMP19:%.*]] = load i16, i16* %usa, align 2
+  // SIGNED-NEXT:  [[RESIZE13:%.*]] = sext i16 [[TMP18]] to i17
+  // SIGNED-NEXT:  [[UPSCALE14:%.*]] = shl i17 [[RESIZE13]], 1
+  // SIGNED-NEXT:  [[RESIZE15:%.*]] = zext i16 [[TMP19]] to i17
+  // SIGNED-NEXT:  [[TMP20:%.*]] = call i17 @llvm.smul.fix.i17(i17 [[UPSCALE14]], i17 [[RESIZE15]], i32 8)
+  // SIGNED-NEXT:  [[DOWNSCALE16:%.*]] = ashr i17 [[TMP20]], 1
+  // SIGNED-NEXT:  [[RESIZE17:%.*]] = trunc i17 [[DOWNSCALE16]] to i16
+  // SIGNED-NEXT:  store i16 [[RESIZE17]], i16* %sa, align 2
+  // UNSIGNED-NEXT:[[TMP20:%.*]] = call i16 @llvm.smul.fix.i16(i16 [[TMP18]], i16 [[TMP19]], i32 7)
+  // UNSIGNED-NEXT:store i16 [[TMP20]], i16* %sa, align 2
+  sa = sa * us

[PATCH] D73166: [ASTImporter] Properly delete decls from SavedImportPaths

2020-01-22 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

I can land it, seems to pass all LLDB tests too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73166



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


[PATCH] D73183: [CodeGen] Emit IR for fixed-point unary operators.

2020-01-22 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan created this revision.
ebevhan added reviewers: rjmccall, leonardchan.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73183

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/Frontend/fixed_point_unary.c

Index: clang/test/Frontend/fixed_point_unary.c
===
--- /dev/null
+++ clang/test/Frontend/fixed_point_unary.c
@@ -0,0 +1,264 @@
+// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
+// RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
+
+_Accum a;
+_Fract f;
+long _Fract lf;
+unsigned _Accum ua;
+short unsigned _Accum usa;
+unsigned _Fract uf;
+
+_Sat _Accum sa;
+_Sat _Fract sf;
+_Sat long _Fract slf;
+_Sat unsigned _Accum sua;
+_Sat short unsigned _Accum susa;
+_Sat unsigned _Fract suf;
+
+// CHECK-LABEL: @Increment(
+void Increment() {
+// CHECK: [[TMP0:%.*]] = load i32, i32* @a, align 4
+// CHECK-NEXT:[[TMP1:%.*]] = sub i32 [[TMP0]], -32768
+// CHECK-NEXT:store i32 [[TMP1]], i32* @a, align 4
+  a++;
+
+// CHECK: [[TMP2:%.*]] = load i16, i16* @f, align 2
+// CHECK-NEXT:[[TMP3:%.*]] = sub i16 [[TMP2]], -32768
+// CHECK-NEXT:store i16 [[TMP3]], i16* @f, align 2
+  f++;
+
+// CHECK: [[TMP4:%.*]] = load i32, i32* @lf, align 4
+// CHECK-NEXT:[[TMP5:%.*]] = sub i32 [[TMP4]], -2147483648
+// CHECK-NEXT:store i32 [[TMP5]], i32* @lf, align 4
+  lf++;
+
+// CHECK: [[TMP6:%.*]] = load i32, i32* @ua, align 4
+// SIGNED-NEXT:   [[TMP7:%.*]] = add i32 [[TMP6]], 65536
+// UNSIGNED-NEXT: [[TMP7:%.*]] = add i32 [[TMP6]], 32768
+// CHECK-NEXT:store i32 [[TMP7]], i32* @ua, align 4
+  ua++;
+
+// CHECK: [[TMP8:%.*]] = load i16, i16* @usa, align 2
+// SIGNED-NEXT:   [[TMP9:%.*]] = add i16 [[TMP8]], 256
+// UNSIGNED-NEXT: [[TMP9:%.*]] = add i16 [[TMP8]], 128
+// CHECK-NEXT:store i16 [[TMP9]], i16* @usa, align 2
+  usa++;
+
+// CHECK: [[TMP10:%.*]] = load i16, i16* @uf, align 2
+// SIGNED-NEXT:   [[TMP11:%.*]] = add i16 [[TMP10]], undef
+// UNSIGNED-NEXT: [[TMP11:%.*]] = add i16 [[TMP10]], -32768
+// CHECK-NEXT:store i16 [[TMP11]], i16* @uf, align 2
+  uf++;
+
+// CHECK: [[TMP12:%.*]] = load i32, i32* @sa, align 4
+// CHECK-NEXT:[[TMP13:%.*]] = call i32 @llvm.ssub.sat.i32(i32 [[TMP12]], i32 -32768)
+// CHECK-NEXT:store i32 [[TMP13]], i32* @sa, align 4
+  sa++;
+
+// CHECK: [[TMP14:%.*]] = load i16, i16* @sf, align 2
+// CHECK-NEXT:[[TMP15:%.*]] = call i16 @llvm.ssub.sat.i16(i16 [[TMP14]], i16 -32768)
+// CHECK-NEXT:store i16 [[TMP15]], i16* @sf, align 2
+  sf++;
+
+// CHECK: [[TMP16:%.*]] = load i32, i32* @slf, align 4
+// CHECK-NEXT:[[TMP17:%.*]] = call i32 @llvm.ssub.sat.i32(i32 [[TMP16]], i32 -2147483648)
+// CHECK-NEXT:store i32 [[TMP17]], i32* @slf, align 4
+  slf++;
+
+// CHECK: [[TMP18:%.*]] = load i32, i32* @sua, align 4
+// SIGNED-NEXT:   [[TMP19:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[TMP18]], i32 65536)
+// SIGNED-NEXT:   store i32 [[TMP19]], i32* @sua, align 4
+// UNSIGNED-NEXT: [[RESIZE:%.*]] = trunc i32 [[TMP18]] to i31
+// UNSIGNED-NEXT: [[TMP19:%.*]] = call i31 @llvm.uadd.sat.i31(i31 [[RESIZE]], i31 32768)
+// UNSIGNED-NEXT: [[RESIZE1:%.*]] = zext i31 [[TMP19]] to i32
+// UNSIGNED-NEXT: store i32 [[RESIZE1]], i32* @sua, align 4
+  sua++;
+
+// CHECK: [[TMP20:%.*]] = load i16, i16* @susa, align 2
+// SIGNED-NEXT:   [[TMP21:%.*]] = call i16 @llvm.uadd.sat.i16(i16 [[TMP20]], i16 256)
+// SIGNED-NEXT:   store i16 [[TMP21]], i16* @susa, align 2
+// UNSIGNED-NEXT: [[RESIZE2:%.*]] = trunc i16 [[TMP20]] to i15
+// UNSIGNED-NEXT: [[TMP21:%.*]] = call i15 @llvm.uadd.sat.i15(i15 [[RESIZE2]], i15 128)
+// UNSIGNED-NEXT: [[RESIZE3:%.*]] = zext i15 [[TMP21]] to i16
+// UNSIGNED-NEXT: store i16 [[RESIZE3]], i16* @susa, align 2
+  susa++;
+
+// CHECK: [[TMP22:%.*]] = load i16, i16* @suf, align 2
+// SIGNED-NEXT:   [[TMP23:%.*]] = call i16 @llvm.uadd.sat.i16(i16 [[TMP22]], i16 -1)
+// SIGNED-NEXT:   store i16 [[TMP23]], i16* @suf, align 2
+// UNSIGNED-NEXT: [[RESIZE4:%.*]] = trunc i16 [[TMP22]] to i15
+// UNSIGNED-NEXT: [[TMP23:%.*]] = call i15 @llvm.uadd.sat.i15(i15 [[RESIZE4]], i15 -1)
+// UNSIGNED-NEXT: [[RESIZE5:%.*]] = zext i15 [[TMP23]] to i16
+// UNSIGNED-NEXT: store i16 [[RESIZE5]], i16* @suf, align 2
+  suf++;
+}
+
+// CHECK-LABEL: @Decrement(
+void Decrement() {
+// CHECK: [[TMP0:%.*]] = load i32, i32* @a, align 4
+// CHECK-NEXT:[[TMP1:%.*]] = add i32 [[TMP0]], -32768
+// CHECK-NEXT:store i32 [[TMP1]], i32* @a, align 4
+  a--;
+
+// CHECK: [[TMP2:%.*]] = load i16, i16* @f, align 2
+// CHECK-NEXT:[[TMP3:%.*]] = add i16 [[TMP2]], -32768
+// CHECK-NEXT:store i16 [[TMP3]], i16* @f, align 2
+  f--;
+
+// CHECK: [[TMP4:%.*]] = load i32

[PATCH] D73184: [CodeGen] Emit IR for compound assignment with fixed-point operands.

2020-01-22 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan created this revision.
ebevhan added reviewers: rjmccall, leonardchan.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73184

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Frontend/fixed_point_compound.c

Index: clang/test/Frontend/fixed_point_compound.c
===
--- /dev/null
+++ clang/test/Frontend/fixed_point_compound.c
@@ -0,0 +1,374 @@
+// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
+// RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
+
+short _Fract shf;
+_Accum a;
+unsigned _Fract uf;
+unsigned long _Accum ula;
+
+_Sat short _Fract sshf;
+_Sat _Accum sa;
+_Sat unsigned _Fract suf;
+_Sat unsigned long _Accum sula;
+
+int i;
+unsigned int u;
+signed char c;
+
+
+// CHECK-LABEL: @Addition(
+void Addition() {
+// CHECK: [[TMP0:%.*]] = load i32, i32* @a, align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load i8, i8* @shf, align 1
+// CHECK-NEXT:[[RESIZE:%.*]] = sext i8 [[TMP1]] to i32
+// CHECK-NEXT:[[UPSCALE:%.*]] = shl i32 [[RESIZE]], 8
+// CHECK-NEXT:[[TMP2:%.*]] = add i32 [[UPSCALE]], [[TMP0]]
+// CHECK-NEXT:[[DOWNSCALE:%.*]] = ashr i32 [[TMP2]], 8
+// CHECK-NEXT:[[RESIZE1:%.*]] = trunc i32 [[DOWNSCALE]] to i8
+// CHECK-NEXT:store i8 [[RESIZE1]], i8* @shf, align 1
+  shf += a;
+
+// CHECK: [[TMP3:%.*]] = load i16, i16* @uf, align 2
+// CHECK-NEXT:[[TMP4:%.*]] = load i32, i32* @a, align 4
+// SIGNED-NEXT:   [[RESIZE2:%.*]] = sext i32 [[TMP4]] to i33
+// SIGNED-NEXT:   [[UPSCALE3:%.*]] = shl i33 [[RESIZE2]], 1
+// SIGNED-NEXT:   [[RESIZE4:%.*]] = zext i16 [[TMP3]] to i33
+// SIGNED-NEXT:   [[TMP5:%.*]] = add i33 [[UPSCALE3]], [[RESIZE4]]
+// SIGNED-NEXT:   [[DOWNSCALE5:%.*]] = ashr i33 [[TMP5]], 1
+// SIGNED-NEXT:   [[RESIZE6:%.*]] = trunc i33 [[DOWNSCALE5]] to i32
+// SIGNED-NEXT:   store i32 [[RESIZE6]], i32* @a, align 4
+// UNSIGNED-NEXT: [[RESIZE2:%.*]] = zext i16 [[TMP3]] to i32
+// UNSIGNED-NEXT: [[TMP5:%.*]] = add i32 [[TMP4]], [[RESIZE2]]
+// UNSIGNED-NEXT: store i32 [[TMP5]], i32* @a, align 4
+  a += uf;
+
+// CHECK: [[TMP6:%.*]] = load i64, i64* @ula, align 8
+// CHECK-NEXT:[[TMP7:%.*]] = load i16, i16* @uf, align 2
+// CHECK-NEXT:[[RESIZE7:%.*]] = zext i16 [[TMP7]] to i64
+// CHECK-NEXT:[[UPSCALE8:%.*]] = shl i64 [[RESIZE7]], 16
+// CHECK-NEXT:[[TMP8:%.*]] = add i64 [[UPSCALE8]], [[TMP6]]
+// CHECK-NEXT:[[DOWNSCALE9:%.*]] = lshr i64 [[TMP8]], 16
+// CHECK-NEXT:[[RESIZE10:%.*]] = trunc i64 [[DOWNSCALE9]] to i16
+// CHECK-NEXT:store i16 [[RESIZE10]], i16* @uf, align 2
+  uf += ula;
+
+// CHECK: [[TMP9:%.*]] = load i8, i8* @shf, align 1
+// CHECK-NEXT:[[TMP10:%.*]] = load i64, i64* @ula, align 8
+// SIGNED-NEXT:   [[RESIZE11:%.*]] = zext i64 [[TMP10]] to i65
+// SIGNED-NEXT:   [[RESIZE12:%.*]] = sext i8 [[TMP9]] to i65
+// SIGNED-NEXT:   [[UPSCALE13:%.*]] = shl i65 [[RESIZE12]], 25
+// SIGNED-NEXT:   [[TMP11:%.*]] = add i65 [[RESIZE11]], [[UPSCALE13]]
+// SIGNED-NEXT:   [[DOWNSCALE14:%.*]] = ashr i65 [[TMP11]], 1
+// SIGNED-NEXT:   [[RESIZE15:%.*]] = trunc i65 [[DOWNSCALE14]] to i64
+// SIGNED-NEXT:   [[UPSCALE16:%.*]] = shl i64 [[RESIZE15]], 1
+// SIGNED-NEXT:   store i64 [[UPSCALE16]], i64* @ula, align 8
+// UNSIGNED-NEXT: [[RESIZE7:%.*]] = sext i8 [[TMP9]] to i64
+// UNSIGNED-NEXT: [[UPSCALE8:%.*]] = shl i64 [[RESIZE7]], 24
+// UNSIGNED-NEXT: [[TMP11:%.*]] = add i64 [[TMP10]], [[UPSCALE8]]
+// UNSIGNED-NEXT: store i64 [[TMP11]], i64* @ula, align 8
+  ula += shf;
+
+// CHECK: [[TMP12:%.*]] = load i8, i8* @shf, align 1
+// CHECK-NEXT:[[TMP13:%.*]] = load i16, i16* @uf, align 2
+// SIGNED-NEXT:   [[RESIZE17:%.*]] = zext i16 [[TMP13]] to i17
+// SIGNED-NEXT:   [[RESIZE18:%.*]] = sext i8 [[TMP12]] to i17
+// SIGNED-NEXT:   [[UPSCALE19:%.*]] = shl i17 [[RESIZE18]], 9
+// SIGNED-NEXT:   [[TMP14:%.*]] = add i17 [[RESIZE17]], [[UPSCALE19]]
+// SIGNED-NEXT:   [[DOWNSCALE20:%.*]] = ashr i17 [[TMP14]], 1
+// SIGNED-NEXT:   [[RESIZE21:%.*]] = trunc i17 [[DOWNSCALE20]] to i16
+// SIGNED-NEXT:   [[UPSCALE22:%.*]] = shl i16 [[RESIZE21]], 1
+// SIGNED-NEXT:   store i16 [[UPSCALE22]], i16* @uf, align 2
+// UNSIGNED-NEXT: [[RESIZE9:%.*]] = sext i8 [[TMP12]] to i16
+// UNSIGNED-NEXT: [[UPSCALE10:%.*]] = shl i16 [[RESIZE9]], 8
+// UNSIGNED-NEXT: [[TMP14:%.*]] = add i16 [[TMP13]], [[UPSCALE10]]
+// UNSIGNED-NEXT: store i16 [[TMP14]], i16* @uf, align 2
+  uf += shf;
+
+// CHECK: [[TMP15:%.*]] = load i8, i8* @shf, align 1
+// CHECK-NEXT:[[TMP16:%.*]] = load i32, i32* @a, align 4
+// CHECK-NEXT:[[RESIZE23:%.*]] = sext i8 [[TMP15]] to i32
+// CHECK-NEXT:[[UPSCALE24:%.*]] = shl i32 [[RESIZE23]], 8
+// CHECK-NEXT:[[TMP17:%.*]] = add i32 [[TMP16]], [[UPSCALE24]]
+// CHECK-NE

[PATCH] D73185: [AST] Add fixed-point subtraction constant evaluation.

2020-01-22 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan created this revision.
ebevhan added reviewers: rjmccall, leonardchan.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73185

Files:
  clang/include/clang/Basic/FixedPoint.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Basic/FixedPoint.cpp
  clang/test/Frontend/fixed_point_sub.c

Index: clang/test/Frontend/fixed_point_sub.c
===
--- clang/test/Frontend/fixed_point_sub.c
+++ clang/test/Frontend/fixed_point_sub.c
@@ -1,6 +1,55 @@
 // RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
 // RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
 
+// Subtraction between different fixed point types
+short _Accum sa_const = 1.0hk - 2.0hk;  // CHECK-DAG: @sa_const  = {{.*}}global i16 -128, align 2
+_Accum a_const = 1.0hk - 2.0k;  // CHECK-DAG: @a_const   = {{.*}}global i32 -32768, align 4
+long _Accum la_const = 1.0hk - 2.0lk;   // CHECK-DAG: @la_const  = {{.*}}global i64 -2147483648, align 8
+short _Accum sa_const2 = 0.5hr - 2.0hk; // CHECK-DAG: @sa_const2  = {{.*}}global i16 -192, align 2
+short _Accum sa_const3 = 0.5r - 2.0hk;  // CHECK-DAG: @sa_const3  = {{.*}}global i16 -192, align 2
+short _Accum sa_const4 = 0.5lr - 2.0hk; // CHECK-DAG: @sa_const4  = {{.*}}global i16 -192, align 2
+short _Accum sa_const5 = 2.0hk - 0.5lr; // CHECK-DAG: @sa_const5  = {{.*}}global i16 192, align 2
+
+// Unsigned subtraction
+unsigned short _Accum usa_const = 3.0uhk - 2.0uhk;
+// CHECK-SIGNED-DAG:   @usa_const = {{.*}}global i16 768, align 2
+// CHECK-UNSIGNED-DAG: @usa_const = {{.*}}global i16 384, align 2
+
+// Unsigned - signed
+short _Accum sa_const6 = 1.0uhk - 2.0hk;
+// CHECK-DAG: @sa_const6 = {{.*}}global i16 -128, align 2
+
+// Subtraction with negative number
+short _Accum sa_const7 = 0.5hr - (-2.0hk);
+// CHECK-DAG: @sa_const7 = {{.*}}global i16 320, align 2
+
+// Int subtraction
+unsigned short _Accum usa_const2 = 2 - 0.5uhk;
+// CHECK-SIGNED-DAG:   @usa_const2 = {{.*}}global i16 640, align 2
+// CHECK-UNSIGNED-DAG: @usa_const2 = {{.*}}global i16 320, align 2
+short _Accum sa_const8 = 2 - (-0.5hk);   // CHECK-DAG: @sa_const8 = {{.*}}global i16 320, align 2
+short _Accum sa_const9 = 257 - 2.0hk;// CHECK-DAG: @sa_const9 = {{.*}}global i16 32640, align 2
+long _Fract lf_const = 0.5lr - 1;// CHECK-DAG: @lf_const  = {{.*}}global i32 -1073741824, align 4
+
+// Saturated subtraction
+_Sat short _Accum sat_sa_const = (_Sat short _Accum)128.0hk - (-128.0hk);
+// CHECK-DAG: @sat_sa_const = {{.*}}global i16 32767, align 2
+_Sat unsigned short _Accum sat_usa_const = (_Sat unsigned short _Accum)128.0uhk - (-128.0uhk);
+// CHECK-SIGNED-DAG:   @sat_usa_const = {{.*}}global i16 65535, align 2
+// CHECK-UNSIGNED-DAG: @sat_usa_const = {{.*}}global i16 32767, align 2
+_Sat short _Accum sat_sa_const2 = (_Sat short _Accum)128.0hk - (-128);
+// CHECK-DAG: @sat_sa_const2 = {{.*}}global i16 32767, align 2
+_Sat unsigned short _Accum sat_usa_const2 = (_Sat unsigned short _Accum)128.0uhk - (-128);
+// CHECK-SIGNED-DAG:   @sat_usa_const2 = {{.*}}global i16 65535, align 2
+// CHECK-UNSIGNED-DAG: @sat_usa_const2 = {{.*}}global i16 32767, align 2
+_Sat unsigned short _Accum sat_usa_const3 = (_Sat unsigned short _Accum)0.5uhk - 2;
+// CHECK-DAG:   @sat_usa_const3 = {{.*}}global i16 0, align 2
+_Sat short _Accum sat_sa_const3 = (_Sat short _Accum)-128.0hk - 128;
+// CHECK-DAG: @sat_sa_const3 = {{.*}}global i16 -32768, align 2
+_Sat short _Accum sat_sa_const4 = (_Sat short _Accum)-150.0hk - 130.0lk;
+// CHECK-DAG: @sat_sa_const4 = {{.*}}global i16 -32768, align 2
+
+
 void SignedSubtraction() {
   // CHECK-LABEL: SignedSubtraction
   short _Accum sa;
Index: clang/lib/Basic/FixedPoint.cpp
===
--- clang/lib/Basic/FixedPoint.cpp
+++ clang/lib/Basic/FixedPoint.cpp
@@ -173,6 +173,30 @@
   return APFixedPoint(Result, CommonFXSema);
 }
 
+APFixedPoint APFixedPoint::sub(const APFixedPoint &Other,
+   bool *Overflow) const {
+  auto CommonFXSema = Sema.getCommonSemantics(Other.getSemantics());
+  APFixedPoint ConvertedThis = convert(CommonFXSema);
+  APFixedPoint ConvertedOther = Other.convert(CommonFXSema);
+  llvm::APSInt ThisVal = ConvertedThis.getValue();
+  llvm::APSInt OtherVal = ConvertedOther.getValue();
+  bool Overflowed = false;
+
+  llvm::APSInt Result;
+  if (CommonFXSema.isSaturated()) {
+Result = CommonFXSema.isSigned() ? ThisVal.ssub_sat(OtherVal)
+ : ThisVal.usub_sat(OtherVal);
+  } else {
+Result = ThisVal.isSigned() ? ThisVal.ssub_ov(OtherVal, Overflowed)
+: ThisVal.usub_ov(OtherVal, Overflowed);
+  }
+
+  if (Overflow)
+*Overflow = Overflowed;
+
+  return APFixedPoint(Resu

[PATCH] D73166: [ASTImporter] Properly delete decls from SavedImportPaths

2020-01-22 Thread Raphael Isemann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4481eefbe842: [ASTImporter] Properly delete decls from 
SavedImportPaths (authored by jarin, committed by teemperor).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73166

Files:
  clang/lib/AST/ASTImporter.cpp


Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -8253,7 +8253,7 @@
   // FIXME Should we remove these Decls from the LookupTable,
   // and from ImportedFromDecls?
   }
-SavedImportPaths[FromD].clear();
+SavedImportPaths.erase(FromD);
 
 // Do not return ToDOrErr, error was taken out of it.
 return make_error(ErrOut);
@@ -8286,7 +8286,7 @@
   Imported(FromD, ToD);
 
   updateFlags(FromD, ToD);
-  SavedImportPaths[FromD].clear();
+  SavedImportPaths.erase(FromD);
   return ToDOrErr;
 }
 


Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -8253,7 +8253,7 @@
   // FIXME Should we remove these Decls from the LookupTable,
   // and from ImportedFromDecls?
   }
-SavedImportPaths[FromD].clear();
+SavedImportPaths.erase(FromD);
 
 // Do not return ToDOrErr, error was taken out of it.
 return make_error(ErrOut);
@@ -8286,7 +8286,7 @@
   Imported(FromD, ToD);
 
   updateFlags(FromD, ToD);
-  SavedImportPaths[FromD].clear();
+  SavedImportPaths.erase(FromD);
   return ToDOrErr;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73187: [AST] Add fixed-point division constant evaluation.

2020-01-22 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan created this revision.
ebevhan added reviewers: rjmccall, leonardchan, bjope.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73187

Files:
  clang/include/clang/Basic/FixedPoint.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Basic/FixedPoint.cpp
  clang/test/Frontend/fixed_point_div.c

Index: clang/test/Frontend/fixed_point_div.c
===
--- clang/test/Frontend/fixed_point_div.c
+++ clang/test/Frontend/fixed_point_div.c
@@ -1,6 +1,70 @@
 // RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
 // RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
 
+// Division between different fixed point types
+short _Accum sa_const = 1.0hk / 2.0hk;  // CHECK-DAG: @sa_const  = {{.*}}global i16 64, align 2
+_Accum a_const = 1.0hk / 2.0k;  // CHECK-DAG: @a_const   = {{.*}}global i32 16384, align 4
+long _Accum la_const = 1.0hk / 2.0lk;   // CHECK-DAG: @la_const  = {{.*}}global i64 1073741824, align 8
+short _Accum sa_const2 = 0.5hr / 2.0hk; // CHECK-DAG: @sa_const2  = {{.*}}global i16 32, align 2
+short _Accum sa_const3 = 0.5r / 2.0hk;  // CHECK-DAG: @sa_const3  = {{.*}}global i16 32, align 2
+short _Accum sa_const4 = 0.5lr / 2.0hk; // CHECK-DAG: @sa_const4  = {{.*}}global i16 32, align 2
+short _Accum sa_const5 = 2.0hk / 0.5lr; // CHECK-DAG: @sa_const5  = {{.*}}global i16 512, align 2
+
+// Unsigned division
+unsigned short _Accum usa_const = 3.0uhk / 2.0uhk;
+// CHECK-SIGNED-DAG:   @usa_const = {{.*}}global i16 192, align 2
+// CHECK-UNSIGNED-DAG: @usa_const = {{.*}}global i16 384, align 2
+
+// Unsigned / signed
+short _Accum sa_const6 = 1.0uhk / 2.0hk;
+// CHECK-DAG: @sa_const6 = {{.*}}global i16 64, align 2
+
+// Division with negative number
+short _Accum sa_const7 = 0.5hr / (-2.0hk);
+// CHECK-DAG: @sa_const7 = {{.*}}global i16 -32, align 2
+
+// Int division
+unsigned short _Accum usa_const2 = 2 / 0.5uhk;
+// CHECK-SIGNED-DAG:   @usa_const2 = {{.*}}global i16 512, align 2
+// CHECK-UNSIGNED-DAG: @usa_const2 = {{.*}}global i16 1024, align 2
+short _Accum sa_const8 = 2 / (-0.5hk);   // CHECK-DAG: @sa_const8 = {{.*}}global i16 -512, align 2
+short _Accum sa_const9 = 256 / 2.0hk;// CHECK-DAG: @sa_const9 = {{.*}}global i16 16384, align 2
+long _Fract lf_const = 0.5lr / -1;   // CHECK-DAG: @lf_const  = {{.*}}global i32 -1073741824, align 4
+
+// Saturated division
+_Sat short _Accum sat_sa_const = (_Sat short _Accum)128.0hk / (-0.25hk);
+// CHECK-DAG: @sat_sa_const = {{.*}}global i16 -32768, align 2
+_Sat unsigned short _Accum sat_usa_const = (_Sat unsigned short _Accum)128.0uhk / (0.25uhk);
+// CHECK-SIGNED-DAG:   @sat_usa_const = {{.*}}global i16 65535, align 2
+// CHECK-UNSIGNED-DAG: @sat_usa_const = {{.*}}global i16 32767, align 2
+_Sat short _Accum sat_sa_const2 = (_Sat short _Accum)-128.0hk / (-0.0125hr);
+// CHECK-DAG: @sat_sa_const2 = {{.*}}global i16 32767, align 2
+_Sat unsigned short _Accum sat_usa_const2 = (_Sat unsigned short _Accum)128.0uhk / (-128);
+// CHECK-SIGNED-DAG:   @sat_usa_const2 = {{.*}}global i16 65535, align 2
+// CHECK-UNSIGNED-DAG: @sat_usa_const2 = {{.*}}global i16 32767, align 2
+_Sat unsigned short _Accum sat_usa_const3 = (_Sat unsigned short _Accum)0.5uhk / -1;
+// CHECK-DAG:   @sat_usa_const3 = {{.*}}global i16 0, align 2
+_Sat short _Accum sat_sa_const3 = (_Sat short _Accum)-128.0hk / 128;
+// CHECK-DAG: @sat_sa_const3 = {{.*}}global i16 -128, align 2
+_Sat short _Accum sat_sa_const4 = (_Sat short _Accum)-25.7hk / 0.1lk;
+// CHECK-DAG: @sat_sa_const4 = {{.*}}global i16 -32768, align 2
+
+// Some more cases
+short _Accum sa_const10 = 255.9921875hk / 255.9921875hk;
+// CHECK-DAG: @sa_const10 = {{.*}}global i16 128, align 2
+short _Accum sat_sa_const5 = (_Sat short _Accum)(-255.0hk - 1.0hk) / 0.0078125hk;
+// CHECK-DAG: @sat_sa_const5 = {{.*}}global i16 -32768, align 2
+_Sat short _Accum sat_sa_const6 = (_Sat short _Accum)(-255.0hk - 1.0hk) / -0.0078125hk;
+// CHECK-DAG: @sat_sa_const6 = {{.*}}global i16 32767, align 2
+short _Accum sa_const12 = 255.9921875hk / -1.0hk;
+// CHECK-DAG: @sa_const12 = {{.*}}global i16 -32767, align 2
+_Sat short _Accum sat_sa_const7 = (_Sat short _Accum)(-255.0hk - 1.0hk) / -1.0hk;
+// CHECK-DAG: @sat_sa_const7 = {{.*}}global i16 32767, align 2
+short _Accum sa_const13 = 0.0234375hk / 2.0hk;
+// CHECK-DAG: @sa_const13 = {{.*}}global i16 1, align 2
+short _Accum sa_const14 = -0.0234375hk / 2.0hk;
+// CHECK-DAG: @sa_const14 = {{.*}}global i16 -2, align 2
+
 void SignedDivision() {
   // CHECK-LABEL: SignedDivision
   short _Accum sa;
Index: clang/lib/Basic/FixedPoint.cpp
===
--- clang/lib/Basic/FixedPoint.cpp
+++ clang/lib/Basic/FixedPoint

[PATCH] D73186: [AST] Add fixed-point multiplication constant evaluation.

2020-01-22 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan created this revision.
ebevhan added reviewers: rjmccall, leonardchan, bjope.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73186

Files:
  clang/include/clang/Basic/FixedPoint.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Basic/FixedPoint.cpp
  clang/test/Frontend/fixed_point_mul.c

Index: clang/test/Frontend/fixed_point_mul.c
===
--- clang/test/Frontend/fixed_point_mul.c
+++ clang/test/Frontend/fixed_point_mul.c
@@ -1,6 +1,49 @@
 // RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
 // RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
 
+// Multiplication between different fixed point types
+short _Accum sa_const = 2.0hk * 2.0hk;  // CHECK-DAG: @sa_const  = {{.*}}global i16 512, align 2
+_Accum a_const = 3.0hk * 2.0k;  // CHECK-DAG: @a_const   = {{.*}}global i32 196608, align 4
+long _Accum la_const = 4.0hk * 2.0lk;   // CHECK-DAG: @la_const  = {{.*}}global i64 17179869184, align 8
+short _Accum sa_const2 = 0.5hr * 2.0hk; // CHECK-DAG: @sa_const2  = {{.*}}global i16 128, align 2
+short _Accum sa_const3 = 0.5r * 3.0hk;  // CHECK-DAG: @sa_const3  = {{.*}}global i16 192, align 2
+short _Accum sa_const4 = 0.5lr * 4.0hk; // CHECK-DAG: @sa_const4  = {{.*}}global i16 256, align 2
+
+// Unsigned multiplication
+unsigned short _Accum usa_const = 1.0uhk * 2.0uhk;
+// CHECK-SIGNED-DAG:   @usa_const = {{.*}}global i16 768, align 2
+// CHECK-UNSIGNED-DAG: @usa_const = {{.*}}global i16 384, align 2
+
+// Unsigned * signed
+short _Accum sa_const5 = 20.0uhk * 3.0hk;
+// CHECK-DAG: @sa_const5 = {{.*}}global i16 7680, align 2
+
+// Multiplication with negative number
+short _Accum sa_const6 = 0.5hr * (-2.0hk);
+// CHECK-DAG: @sa_const6 = {{.*}}global i16 -128, align 2
+
+// Int multiplication
+unsigned short _Accum usa_const2 = 5 * 10.5uhk;
+// CHECK-SIGNED-DAG:   @usa_const2 = {{.*}}global i16 640, align 2
+// CHECK-UNSIGNED-DAG: @usa_const2 = {{.*}}global i16 320, align 2
+short _Accum sa_const7 = 3 * (-0.5hk);   // CHECK-DAG: @sa_const7 = {{.*}}global i16 -192, align 2
+short _Accum sa_const8 = 100 * (-2.0hk); // CHECK-DAG: @sa_const8 = {{.*}}global i16 -25600, align 2
+long _Fract lf_const = -0.25lr * 3;  // CHECK-DAG: @lf_const  = {{.*}}global i32 -1610612736, align 4
+
+// Saturated multiplication
+_Sat short _Accum sat_sa_const = (_Sat short _Accum)128.0hk * 3.0hk;
+// CHECK-DAG: @sat_sa_const = {{.*}}global i16 32767, align 2
+_Sat unsigned short _Accum sat_usa_const = (_Sat unsigned short _Accum)128.0uhk * 128.0uhk;
+// CHECK-SIGNED-DAG:   @sat_usa_const = {{.*}}global i16 65535, align 2
+// CHECK-UNSIGNED-DAG: @sat_usa_const = {{.*}}global i16 32767, align 2
+_Sat short _Accum sat_sa_const2 = (_Sat short _Accum)128.0hk * -128;
+// CHECK-DAG: @sat_sa_const2 = {{.*}}global i16 -32768, align 2
+_Sat unsigned short _Accum sat_usa_const2 = (_Sat unsigned short _Accum)128.0uhk * 30;
+// CHECK-SIGNED-DAG:   @sat_usa_const2 = {{.*}}global i16 65535, align 2
+// CHECK-UNSIGNED-DAG: @sat_usa_const2 = {{.*}}global i16 32767, align 2
+_Sat unsigned short _Accum sat_usa_const3 = (_Sat unsigned short _Accum)0.5uhk * (-2);
+// CHECK-DAG:   @sat_usa_const3 = {{.*}}global i16 0, align 2
+
 void SignedMultiplication() {
   // CHECK-LABEL: SignedMultiplication
   short _Accum sa;
Index: clang/lib/Basic/FixedPoint.cpp
===
--- clang/lib/Basic/FixedPoint.cpp
+++ clang/lib/Basic/FixedPoint.cpp
@@ -197,6 +197,57 @@
   return APFixedPoint(Result, CommonFXSema);
 }
 
+APFixedPoint APFixedPoint::mul(const APFixedPoint &Other,
+   bool *Overflow) const {
+  auto CommonFXSema = Sema.getCommonSemantics(Other.getSemantics());
+  APFixedPoint ConvertedThis = convert(CommonFXSema);
+  APFixedPoint ConvertedOther = Other.convert(CommonFXSema);
+  llvm::APSInt ThisVal = ConvertedThis.getValue();
+  llvm::APSInt OtherVal = ConvertedOther.getValue();
+  bool Overflowed = false;
+
+  // Widen the LHS and RHS so we can perform a full multiplication.
+  unsigned Wide = CommonFXSema.getWidth() * 2;
+  if (CommonFXSema.isSigned()) {
+ThisVal = ThisVal.sextOrSelf(Wide);
+OtherVal = OtherVal.sextOrSelf(Wide);
+  } else {
+ThisVal = ThisVal.zextOrSelf(Wide);
+OtherVal = OtherVal.zextOrSelf(Wide);
+  }
+
+  // Perform the full multiplication and downscale to get the same scale.
+  llvm::APSInt Result;
+  if (CommonFXSema.isSigned())
+Result = ThisVal.smul_ov(OtherVal, Overflowed)
+.ashr(CommonFXSema.getScale());
+  else
+Result = ThisVal.umul_ov(OtherVal, Overflowed)
+.lshr(CommonFXSema.getScale());
+  assert(!Overflowed && "Full multiplic

[PATCH] D73188: [AST] Improve overflow diagnostics for fixed-point constant evaluation.

2020-01-22 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan created this revision.
ebevhan added reviewers: rjmccall, leonardchan, bjope.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Diagnostics for overflow were not being produced for fixed-point
evaluation. This patch refactors a bit of the evaluator and adds
a proper diagnostic for these cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73188

Files:
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/test/Frontend/fixed_point_errors.c

Index: clang/test/Frontend/fixed_point_errors.c
===
--- clang/test/Frontend/fixed_point_errors.c
+++ clang/test/Frontend/fixed_point_errors.c
@@ -250,3 +250,11 @@
 char c_const = 256.0uk;   // expected-warning{{implicit conversion from 256.0 cannot fit within the range of values for 'char'}}
 short _Accum sa_const5 = 256; // expected-warning{{implicit conversion from 256 cannot fit within the range of values for 'short _Accum'}}
 unsigned short _Accum usa_const2 = -2;// expected-warning{{implicit conversion from -2 cannot fit within the range of values for 'unsigned short _Accum'}}
+
+short _Accum add_ovf1 = 255.0hk + 20.0hk; // expected-warning {{overflow in expression; result is -237.0 with type 'short _Accum'}}
+short _Accum add_ovf2 = 10 + 0.5hr;   // expected-warning {{overflow in expression; result is 0.5 with type 'short _Fract'}}
+short _Accum sub_ovf1 = 16.0uhk - 32.0uhk;// expected-warning {{overflow in expression; result is 240.0 with type 'unsigned short _Accum'}}
+short _Accum sub_ovf2 = -255.0hk - 20;// expected-warning {{overflow in expression; result is 237.0 with type 'short _Accum'}}
+short _Accum mul_ovf1 = 200.0uhk * 10.0uhk;   // expected-warning {{overflow in expression; result is 208.0 with type 'unsigned short _Accum'}}
+short _Accum mul_ovf2 = (-0.5hr - 0.5hr) * (-0.5hr - 0.5hr);  // expected-warning {{overflow in expression; result is -1.0 with type 'short _Fract'}}
+short _Accum div_ovf1 = 255.0hk / 0.5hk;  // expected-warning {{overflow in expression; result is -2.0 with type 'short _Accum'}}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -12413,8 +12413,14 @@
   return false;
 bool Overflowed;
 APFixedPoint Result = Src.convert(DestFXSema, &Overflowed);
-if (Overflowed && !HandleOverflow(Info, E, Result, DestType))
-  return false;
+if (Overflowed) {
+  if (Info.checkingForUndefinedBehavior())
+Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
+ diag::warn_fixedpoint_constant_overflow)
+  << Result.toString() << E->getType();
+  else if (!HandleOverflow(Info, E, Result, E->getType()))
+return false;
+}
 return Success(Result, E);
   }
   case CK_IntegralToFixedPoint: {
@@ -12426,8 +12432,14 @@
 APFixedPoint IntResult = APFixedPoint::getFromIntValue(
 Src, Info.Ctx.getFixedPointSemantics(DestType), &Overflowed);
 
-if (Overflowed && !HandleOverflow(Info, E, IntResult, DestType))
-  return false;
+if (Overflowed) {
+  if (Info.checkingForUndefinedBehavior())
+Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
+ diag::warn_fixedpoint_constant_overflow)
+  << IntResult.toString() << E->getType();
+  else if (!HandleOverflow(Info, E, IntResult, E->getType()))
+return false;
+}
 
 return Success(IntResult, E);
   }
@@ -12452,47 +12464,41 @@
   if (!EvaluateFixedPointOrInteger(RHS, RHSFX, Info))
 return false;
 
+  bool OpOverflow = false, ConversionOverflow = false;
+  APFixedPoint Result(LHSFX.getSemantics());
   switch (E->getOpcode()) {
   case BO_Add: {
-bool AddOverflow, ConversionOverflow;
-APFixedPoint Result = LHSFX.add(RHSFX, &AddOverflow)
-   .convert(ResultFXSema, &ConversionOverflow);
-if ((AddOverflow || ConversionOverflow) &&
-!HandleOverflow(Info, E, Result, E->getType()))
-  return false;
-return Success(Result, E);
+Result = LHSFX.add(RHSFX, &OpOverflow)
+  .convert(ResultFXSema, &ConversionOverflow);
+break;
   }
   case BO_Sub: {
-bool AddOverflow, ConversionOverflow;
-APFixedPoint Result = LHSFX.sub(RHSFX, &AddOverflow)
-   .convert(ResultFXSema, &ConversionOverflow);
-if ((AddOverflow || ConversionOverflow) &&
-!HandleOverflow(Info, E, Result, E->getType()))
-  return false;
-return Success(Result, E);
+Result = LHSFX.sub(RHSFX, &OpOverflow)
+  .convert(ResultFXSema, &ConversionOverflow);
+break;
   }
   case BO_Mul: {
-bool Ad

[PATCH] D73189: [AST] Fix certain consteval assignment and comma operator issues with fixed-point types.

2020-01-22 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan created this revision.
ebevhan added reviewers: rjmccall, leonardchan, bjope.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Assignment and comma operators for fixed-point types were being constevaled as 
other
binary operators, but they need special treatment.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73189

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/Frontend/fixed_point_crash.c


Index: clang/test/Frontend/fixed_point_crash.c
===
--- /dev/null
+++ clang/test/Frontend/fixed_point_crash.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -ffixed-point %s
+
+union a {
+  _Accum x;
+  int i;
+};
+
+int fn1() {
+  union a m;
+  m.x = 5.6k;
+  return m.i;
+}
+
+int fn2() {
+  union a m;
+  m.x = 7, 5.6k; // expected-warning {{expression result unused}}
+  return m.x, m.i; // expected-warning {{expression result unused}}
+}
+
+_Accum acc = (0.5r, 6.9k); // expected-warning {{expression result unused}}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -12452,6 +12452,9 @@
 }
 
 bool FixedPointExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
+  if (E->isPtrMemOp() || E->isAssignmentOp() || E->getOpcode() == BO_Comma)
+return ExprEvaluatorBaseTy::VisitBinaryOperator(E);
+
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
   FixedPointSemantics ResultFXSema =


Index: clang/test/Frontend/fixed_point_crash.c
===
--- /dev/null
+++ clang/test/Frontend/fixed_point_crash.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -ffixed-point %s
+
+union a {
+  _Accum x;
+  int i;
+};
+
+int fn1() {
+  union a m;
+  m.x = 5.6k;
+  return m.i;
+}
+
+int fn2() {
+  union a m;
+  m.x = 7, 5.6k; // expected-warning {{expression result unused}}
+  return m.x, m.i; // expected-warning {{expression result unused}}
+}
+
+_Accum acc = (0.5r, 6.9k); // expected-warning {{expression result unused}}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -12452,6 +12452,9 @@
 }
 
 bool FixedPointExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
+  if (E->isPtrMemOp() || E->isAssignmentOp() || E->getOpcode() == BO_Comma)
+return ExprEvaluatorBaseTy::VisitBinaryOperator(E);
+
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
   FixedPointSemantics ResultFXSema =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72144: Treat C# `using` as a control statement

2020-01-22 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe marked 2 inline comments as done.
jbcoe added inline comments.



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:259
+
+  verifyFormat("using (StreamWriter sw = new StreamWriter(filenameB)) {}",
+   Style);

krasimir wrote:
> Can this appear at the top-level? If not, just keep the other test case to 
> avoid confusion.
I'm following the example set by by test cases above. I can remove (all) if you 
prefer and agree it does not test anything new.


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

https://reviews.llvm.org/D72144



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


[PATCH] D72144: Treat C# `using` as a control statement

2020-01-22 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe updated this revision to Diff 239574.
jbcoe added a comment.

Handle `using` case where SpaceBeforeParensOptions is set to 
SBPO_NonEmptyParentheses


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

https://reviews.llvm.org/D72144

Files:
  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
@@ -249,6 +249,23 @@
 
   verifyFormat("using(StreamWriter sw = new StreamWriter(filenameB)) {}",
Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter(filenameA)) {}\n"
+   "}",
+   Style);
+
+  verifyFormat("using (StreamWriter sw = new StreamWriter(filenameB)) {}",
+   Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_NonEmptyParentheses;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+   "}",
+   Style);
+
+  verifyFormat("using() {}", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpRegions) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2869,7 +2869,8 @@
 // space between keywords and paren e.g. "using ("
 if (Right.is(tok::l_paren))
   if (Left.is(tok::kw_using))
-return spaceRequiredBeforeParens(Left);
+return Style.SpaceBeforeParens == FormatStyle::SBPO_ControlStatements 
||
+   spaceRequiredBeforeParens(Right);
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -249,6 +249,23 @@
 
   verifyFormat("using(StreamWriter sw = new StreamWriter(filenameB)) {}",
Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter(filenameA)) {}\n"
+   "}",
+   Style);
+
+  verifyFormat("using (StreamWriter sw = new StreamWriter(filenameB)) {}",
+   Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_NonEmptyParentheses;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+   "}",
+   Style);
+
+  verifyFormat("using() {}", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpRegions) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2869,7 +2869,8 @@
 // space between keywords and paren e.g. "using ("
 if (Right.is(tok::l_paren))
   if (Left.is(tok::kw_using))
-return spaceRequiredBeforeParens(Left);
+return Style.SpaceBeforeParens == FormatStyle::SBPO_ControlStatements ||
+   spaceRequiredBeforeParens(Right);
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73098: [clang-tidy] readability-identifier-naming disregards parameters restrictions on main like functions

2020-01-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D73098#1832489 , @njames93 wrote:

> In D73098#1832131 , @Mordante wrote:
>
> > Would it make sense to also allow wmain with wchar_t? 
> > https://docs.microsoft.com/en-us/cpp/cpp/main-function-command-line-args?view=vs-2019
>
>
> Does wmain get used in a lot of projects. If it's very niche then I don't 
> feel it warrants a place in here. If it does I'll add it in.


It's not uncommon on Windows, at the very least. I think it's worth supporting.




Comment at: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:474
   if (const auto *Decl = dyn_cast(D)) {
+if (isParamInMainLikeFunction(*Decl))
+  return SK_Invalid;

njames93 wrote:
> aaron.ballman wrote:
> > I think a better approach may be to look at the `DeclContext` for the 
> > `ParmVarDecl` object to see if it is a `FunctionDecl`, and if it is, call 
> > `FunctionDecl::isMain()` to check.
> I specifically didn't want to do that as is I want to get functions that act 
> like main, usually the case when main itself dispatches to other functions 
> with the same signature. 
I'm not certain that's a case we should support -- users who write their own 
main-like interfaces should probably follow their usual naming rules (even if 
we don't do it ourselves). For instance, this will catch functions that are 
definitely *not* `main`-like  except in the signature. e.g., `int 
accumulate_string_lengths(int count, char *strings[]);`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73098



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


[clang] 968561b - Unconditionally enable lvalue function designators; NFC

2020-01-22 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2020-01-22T09:54:34-05:00
New Revision: 968561bcdc34c7d74482fe3bb69a045abf08d2c1

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

LOG: Unconditionally enable lvalue function designators; NFC

We previously had to guard against older MSVC and GCC versions which had rvalue
references but not support for marking functions with ref qualifiers. However,
having bumped our minimum required version to MSVC 2017 and GCC 5.1 mean we can
unconditionally enable this feature. Rather than keeping the macro around, this
replaces use of the macro with the actual ref qualifier.

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
llvm/include/llvm/ADT/Optional.h
llvm/include/llvm/ADT/PointerIntPair.h
llvm/include/llvm/Support/Compiler.h
llvm/unittests/ADT/OptionalTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
index e87772c04b9b..e808423cb1f5 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
@@ -34,7 +34,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/Support/Allocator.h"
-#include "llvm/Support/Compiler.h"
 #include 
 #include 
 #include 
@@ -169,7 +168,7 @@ class ExplodedNode : public llvm::FoldingSetNode {
   const ProgramStateRef &getState() const { return State; }
 
   template 
-  Optional getLocationAs() const LLVM_LVALUE_FUNCTION {
+  Optional getLocationAs() const & {
 return Location.getAs();
   }
 

diff  --git a/llvm/include/llvm/ADT/Optional.h 
b/llvm/include/llvm/ADT/Optional.h
index c84f9aa8b342..95363439aa7b 100644
--- a/llvm/include/llvm/ADT/Optional.h
+++ b/llvm/include/llvm/ADT/Optional.h
@@ -16,7 +16,6 @@
 #define LLVM_ADT_OPTIONAL_H
 
 #include "llvm/ADT/None.h"
-#include "llvm/Support/Compiler.h"
 #include "llvm/Support/type_traits.h"
 #include 
 #include 
@@ -69,20 +68,18 @@ class OptionalStorage {
 
   bool hasValue() const noexcept { return hasVal; }
 
-  T &getValue() LLVM_LVALUE_FUNCTION noexcept {
+  T &getValue() & noexcept {
 assert(hasVal);
 return value;
   }
-  T const &getValue() const LLVM_LVALUE_FUNCTION noexcept {
+  T const &getValue() const & noexcept {
 assert(hasVal);
 return value;
   }
-#if LLVM_HAS_RVALUE_REFERENCE_THIS
   T &&getValue() && noexcept {
 assert(hasVal);
 return std::move(value);
   }
-#endif
 
   template  void emplace(Args &&... args) {
 reset();
@@ -169,20 +166,18 @@ template  class OptionalStorage {
 
   bool hasValue() const noexcept { return hasVal; }
 
-  T &getValue() LLVM_LVALUE_FUNCTION noexcept {
+  T &getValue() & noexcept {
 assert(hasVal);
 return value;
   }
-  T const &getValue() const LLVM_LVALUE_FUNCTION noexcept {
+  T const &getValue() const & noexcept {
 assert(hasVal);
 return value;
   }
-#if LLVM_HAS_RVALUE_REFERENCE_THIS
   T &&getValue() && noexcept {
 assert(hasVal);
 return std::move(value);
   }
-#endif
 
   template  void emplace(Args &&... args) {
 reset();
@@ -252,30 +247,29 @@ template  class Optional {
 
   const T *getPointer() const { return &Storage.getValue(); }
   T *getPointer() { return &Storage.getValue(); }
-  const T &getValue() const LLVM_LVALUE_FUNCTION { return Storage.getValue(); }
-  T &getValue() LLVM_LVALUE_FUNCTION { return Storage.getValue(); }
+  const T &getValue() const & { return Storage.getValue(); }
+  T &getValue() & { return Storage.getValue(); }
 
   explicit operator bool() const { return hasValue(); }
   bool hasValue() const { return Storage.hasValue(); }
   const T *operator->() const { return getPointer(); }
   T *operator->() { return getPointer(); }
-  const T &operator*() const LLVM_LVALUE_FUNCTION { return getValue(); }
-  T &operator*() LLVM_LVALUE_FUNCTION { return getValue(); }
+  const T &operator*() const & { return getValue(); }
+  T &operator*() & { return getValue(); }
 
   template 
-  constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION {
+  constexpr T getValueOr(U &&value) const & {
 return hasValue() ? getValue() : std::forward(value);
   }
 
   /// Apply a function to the value if present; otherwise return None.
   template 
-  auto map(const Function &F) const
+  auto map(const Function &F) const &
   -> Optional {
 if (*this) return F(getValue());
 return None;
   }
 
-#if LLVM_HAS_RVALUE_REFERENCE_THIS
   T &&getValue() && { return std::move(Storage.getValue()); }
   T &&operator*() && { return std::move(Storage.getValue()); }
 
@@ -291,7 +285,6 @@ template  class Optional {
 if (*this) return F(std::move(

[PATCH] D72746: [clangd] Add a flag for implicit references in the Index

2020-01-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/index/Ref.h:32
+  //
+  // class Foo {};
+  //   ^ Foo declaration

 could you confirm with it? this looks like a `Foo` class definition.



Comment at: clang-tools-extra/clangd/index/Ref.h:108
   using iterator = const_iterator;
+  using size_type = size_t;
 

nit: I don't understand why we need this change? it seems irrelevant to the 
patch. 



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:599
+const auto Tokens = FilesToTokensCache[MainFileID];
+for (auto &DeclAndRef : DeclRefs) {
+  if (auto ID = getSymbolID(DeclAndRef.first)) {

kbobyrev wrote:
> hokein wrote:
> > note that the `DeclRefs` may contains references from non-main files, e.g. 
> > included headers if `RefsInHeaders` is true. I think we need to tokenize 
> > other files if the reference is not from main file.   `CollectRef` lambda 
> > is a better place to place the `FilesToTokensCache` logic.
> > note that the DeclRefs may contains references from non-main files, e.g. 
> > included headers if RefsInHeaders is true. I think we need to tokenize 
> > other files if the reference is not from main file.
> 
> Fair enough, fixed that!
> 
> > CollectRef lambda is a better place to place the FilesToTokensCache logic.
> 
> I don't really agree with that. In my opinion `CollectRef` should remain a 
> simple helper that simply puts pre-processed reference into the storage. 
> Complicating it (and also making it work with both `MacroRefs` and `DeclRefs` 
> while the token spelling check is only required for declarations looks 
> suboptimal to me. If you really want me to do that, please let me know, but I 
> personally think it might be better this way.
> I don't really agree with that. In my opinion CollectRef should remain a 
> simple helper that simply puts pre-processed reference into the storage. 
> Complicating it (and also making it work with both MacroRefs and DeclRefs 
> while the token spelling check is only required for declarations looks 
> suboptimal to me. If you really want me to do that, please let me know, but I 
> personally think it might be better this way.

SG.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:191
+Result |= RefKind::Reference;
+  if (!(Roles & static_cast(index::SymbolRole::Implicit)))
+Result |= RefKind::Spelled;

I was confused at the first time reading the code -- it turns out we reset the 
flag in the caller. 

Maybe adjust the function like `RefKind toRefKind(index::SymbolRoleSet Roles, 
bool isSpelled)`?



Comment at: clang-tools-extra/clangd/index/SymbolCollector.h:91
+/// explicitly spell out symbol's name.
+bool DropImplicitReferences = false;
   };

what's the use case for this flag? I think we don't need it as we always want 
all references.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:299
   return;
+if (!static_cast(R.Kind & RefKind::Spelled))
+  return;

again, I would suggest doing this change in a follow-up patch.



Comment at: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:711
+  $spelled[[Foo]] Variable1;
+  $macro[[MACRO]] Variable2;
+  )cpp");

could you add a test case for class constructor/destructor to make sure the 
references are marked `spelled`?

```
class [[Foo]] {
   [[Foo]]();
   ~[[Foo]]();
}
```



Comment at: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:719
+  EXPECT_THAT(Refs, Contains(Pair(_, HaveRanges(Main.ranges("macro");
+  EXPECT_THAT(Refs, SizeIs(2));
+}

I think we need to verify the `RefKind` in the test, just add a new gtest 
matcher `IsRefKind`.

nit: we can simplify the code by aggregating the above 3 `EXPECT_THAT`s, like 

```
 EXPECT_THAT(Refs,
  UnorderedElementsAre(Pair(findSymbol(Symbols, "Foo").ID,
HaveRanges(Header.ranges("Foo")))...);
```



Comment at: clang/include/clang/Tooling/Syntax/Tokens.h:324
 llvm::ArrayRef
 spelledTokensTouching(SourceLocation Loc, const syntax::TokenBuffer &Tokens);
 

nit: I would make this function come immediately after the above one (without a 
blank line) to avoid the duplicated documentations, e.g.

```
/// The spelled tokens that overlap or touch a spelling location Loc.
/// This always returns 0-2 tokens.
llvm::ArrayRef
spelledTokensTouching(SourceLocation Loc, llvm::ArrayRef Tokens);
llvm::ArrayRef
spelledTokensTouching(SourceLocation Loc, const syntax::TokenBuffer &Tokens);
```

the same below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72746



___
cfe-commits mail

[PATCH] D73199: [clangd] Errors in TestTU cause test failures unless suppressed with error-ok.

2020-01-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

The historic behavior of TestTU is to gather diagnostics and otherwise ignore
them. So if a test has a syntax error, and doesn't assert diagnostics, it
silently misbehaves.
This can be annoying when developing tests, as evidenced by various tests
gaining "assert no diagnostics" where that's not really the point of the test.

This patch aims to make that default behavior. For the first error
(not warning), TestTU will call ADD_FAILURE().

This can be suppressed with a comment containing "error-ok". For now that will
suppress any errors in the TU. We can make this stricter later -verify style.
(-verify itself is hard to reuse because of DiagnosticConsumer interfaces...)
A magic-comment was chosen over a TestTU option because of table-driven tests.

In addition to the behavior change, this patch:

- adds //error-ok where we're knowingly testing invalid code (e.g. for 
diagnostics, crash-resilience, or token-level tests)
- fixes a bunch of errors in the checked-in tests, mostly trivial (missing ;)
- removes a bunch of now-redundant instances of "assert no diagnostics"


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73199

Files:
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/clangd/unittests/PrintASTTests.cpp
  clang-tools-extra/clangd/unittests/QualityTests.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
  clang-tools-extra/clangd/unittests/SymbolInfoTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h
  clang-tools-extra/clangd/unittests/TweakTests.cpp
  clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -515,10 +515,6 @@
 TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
 
 auto AST = TU.build();
-for (auto &D : AST.getDiagnostics())
-  ADD_FAILURE() << D;
-ASSERT_TRUE(AST.getDiagnostics().empty()) << Test;
-
 auto Results = locateSymbolAt(AST, T.point());
 
 if (!WantDecl) {
@@ -868,7 +864,7 @@
 
   R"cpp(// Forward declaration
 class [[Foo]];
-class [[Foo]] {}
+class [[Foo]] {};
 int main() {
   [[Fo^o]] foo;
 }
@@ -878,7 +874,7 @@
 int [[foo]](int) {}
 int main() {
   auto *X = &[[^foo]];
-  [[foo]](42)
+  [[foo]](42);
 }
   )cpp",
 
@@ -1182,8 +1178,6 @@
   for (const Case &C : Cases) {
 Annotations File(C.AnnotatedCode);
 auto AST = TestTU::withCode(File.code()).build();
-ASSERT_TRUE(AST.getDiagnostics().empty())
-<< AST.getDiagnostics().begin()->Message;
 SourceLocation SL = llvm::cantFail(
 sourceLocationInMainFile(AST.getSourceManager(), File.point()));
 
Index: clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
===
--- clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
+++ clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
@@ -71,8 +71,6 @@
   TestTU TU = TestTU::withCode(Source.code());
   auto AST = TU.build();
 
-  ASSERT_TRUE(AST.getDiagnostics().empty());
-
   for (Position Pt : Source.points()) {
 const CXXRecordDecl *RD = findRecordTypeAt(AST, Pt);
 EXPECT_EQ(&findDecl(AST, "Child2"), static_cast(RD));
@@ -95,8 +93,6 @@
   TestTU TU = TestTU::withCode(Source.code());
   auto AST = TU.build();
 
-  ASSERT_TRUE(AST.getDiagnostics().empty());
-
   for (Position Pt : Source.points()) {
 const CXXRecordDecl *RD = findRecordTypeAt(AST, Pt);
 EXPECT_EQ(&findDecl(AST, "Child2"), static_cast(RD));
@@ -118,8 +114,6 @@
   TestTU TU = TestTU::withCode(Source.code());
   auto AST = TU.build();
 
-  ASSERT_TRUE(AST.getDiagnostics().empty());
-
   for (Position Pt : Source.points()) {
 const CXXRecordDecl *RD = findRecordTypeAt(AST, Pt);
 // A field does not unambiguously specify a record type
@@ -147,8 +141,6 @@
   TestTU TU = TestTU::withCode(Source.code());
   auto AST = TU.build();
 
-  ASSERT_TRUE(AST.getDiagnostics().empty());
-
   const CXXRecordDecl *Parent =
   dyn_cast(&findDecl(AS

[PATCH] D72829: Implement -fsemantic-interposition

2020-01-22 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 239598.
serge-sans-paille added a comment.

- extra  test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72829

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/IR/GlobalValue.h
  llvm/include/llvm/IR/Module.h
  llvm/lib/IR/Globals.cpp
  llvm/lib/IR/Module.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/test/Transforms/Inline/inline-semantic-interposition.ll
  llvm/test/Verifier/module-flags-semantic-interposition.ll

Index: llvm/test/Verifier/module-flags-semantic-interposition.ll
===
--- /dev/null
+++ llvm/test/Verifier/module-flags-semantic-interposition.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+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"
+
+@foo = dso_local global i32 1, align 4
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 1, !"SemanticInterposition", float 1.}
+
+; CHECK: SemanticInterposition metadata requires constant integer argument
Index: llvm/test/Transforms/Inline/inline-semantic-interposition.ll
===
--- /dev/null
+++ llvm/test/Transforms/Inline/inline-semantic-interposition.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -inline  -S | FileCheck %s
+
+define internal i32 @callee1(i32 %A) {
+  ret i32 %A
+}
+define i32 @callee2(i32 %A) {
+  ret i32 %A
+}
+
+; CHECK-LABEL: @caller
+define i32 @caller(i32 %A) {
+; CHECK-NOT: call i32 @callee1(i32 %A)
+  %A1 = call i32 @callee1(i32 %A)
+; CHECK: %A2 = call i32 @callee2(i32 %A)
+  %A2 = call i32 @callee2(i32 %A)
+; CHECK: add i32 %A, %A2
+  %R = add i32 %A1, %A2
+  ret i32 %R
+}
+
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 1, !"SemanticInterposition", i32 1}
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1476,6 +1476,13 @@
"'Linker Options' named metadata no longer supported");
   }
 
+  if (ID->getString() == "SemanticInterposition") {
+ConstantInt *Value =
+mdconst::dyn_extract_or_null(Op->getOperand(2));
+Assert(Value,
+   "SemanticInterposition metadata requires constant integer argument");
+  }
+
   if (ID->getString() == "CG Profile") {
 for (const MDOperand &MDO : cast(Op->getOperand(2))->operands())
   visitModuleFlagCGProfileEntry(MDO);
Index: llvm/lib/IR/Module.cpp
===
--- llvm/lib/IR/Module.cpp
+++ llvm/lib/IR/Module.cpp
@@ -554,6 +554,20 @@
: getModuleFlag("ProfileSummary"));
 }
 
+bool Module::getSemanticInterposition() const {
+  auto *Val =
+  cast_or_null(getModuleFlag("SemanticInterposition"));
+
+  if (!Val)
+return false;
+
+  return cast(Val->getValue())->getZExtValue();
+}
+
+void Module::setSemanticInterposition(bool SI) {
+  addModuleFlag(ModFlagBehavior::Error, "SemanticInterposition", SI);
+}
+
 void Module::setOwnedMemoryBuffer(std::unique_ptr MB) {
   OwnedMemoryBuffer = std::move(MB);
 }
Index: llvm/lib/IR/Globals.cpp
===
--- llvm/lib/IR/Globals.cpp
+++ llvm/lib/IR/Globals.cpp
@@ -94,6 +94,13 @@
   llvm_unreachable("not a global");
 }
 
+bool GlobalValue::isInterposable() const {
+  if (isInterposableLinkage(getLinkage()))
+return true;
+  return getParent() && getParent()->getSemanticInterposition() &&
+ !isDSOLocal();
+}
+
 unsigned GlobalValue::getAlignment() const {
   if (auto *GA = dyn_cast(this)) {
 // In general we cannot compute this at the IR level, but we try.
Index: llvm/include/llvm/IR/Module.h
===
--- llvm/include/llvm/IR/Module.h
+++ llvm/include/llvm/IR/Module.h
@@ -848,6 +848,17 @@
   Metadata *getProfileSummary(bool IsCS);
   /// @}
 
+  /// @name Utility functions for querying and setting semantic interposition
+  /// @{
+
+  /// Returns whether semantic interposition is to be respected.
+  bool getSemanticInterposition() const;
+
+  /// Set whether semantic interposition is to be respected.
+  void setSemanticInterposition(bool);
+
+  /// @}
+
   /// Returns true if PLT should be avoided for RTLib calls.
   bool getRtLibUseGOT() const;
 
Index: llvm/include/llvm/IR/GlobalValue.h
===
--- llvm/include/llvm/IR/GlobalValue.h
+++ llvm/include/llvm/IR/GlobalValue.h
@@ -284,6 +284,8 @@
 return IsDSOLocal;
   }
 
+  bool isDSOPreemptable() const { return !IsDSOLocal; }
+
   bool hasPartition() const {
 re

[PATCH] D72829: Implement -fsemantic-interposition

2020-01-22 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

> I tried modifying `GlobalValue::maybeSetDsoLocal`: `setDSOLocal(true)` for 
> ExternalLinkage. Unfortunately that will break 1337 tests. If not so many 
> tests need fixing, I wish we can place `getParent() && 
> getParent()->getSemanticInterposition()` logic in `maybeSetDsoLocal` and 
> simplify `isInterposable`.

Tried that and ended up with various check failures.
I also tried to update isInterposableLinkage to either

- set more linkage type as interposable unconditionnaly, and with no surprise, 
it triggers plenty check failures
- accept a mandatory « `HonorSemanticInterposition` argument, so that both 
`isInterposableLinkage` and `isInterposable` are consistent, but in some cases, 
`isInterposableLinkage` doesn't have a module reference to gather the 
ModuleFlag from...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72829



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


[PATCH] D73199: [clangd] Errors in TestTU cause test failures unless suppressed with error-ok.

2020-01-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon question-circle color=gray} Unit tests: unknown.

{icon question-circle color=gray} clang-tidy: unknown.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73199



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


[PATCH] D50360: [Concepts] Requires Expressions

2020-01-22 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

I figured out the incremental build test problem, see D73202 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D50360



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


[PATCH] D73202: Make AST reading work better with LLVM_APPEND_VC_REV=NO

2020-01-22 Thread Nico Weber via Phabricator via cfe-commits
thakis marked an inline comment as done.
thakis added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3645
   // CityHash, but this will do for now.
   hash_code code = hash_value(getClangFullRepositoryVersion());
 

Arguably, we should omit the full repo version from the hash: There's no reason 
to use a new cache dir just because someone fixed a typo in the (say) mlir 
docs. We'd also be better about remembering to bump 
clang::serialization::VERSION_MAJOR/MINOR in that case.


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

https://reviews.llvm.org/D73202



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


[PATCH] D73202: Make AST reading work better with LLVM_APPEND_VC_REV=NO

2020-01-22 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added reviewers: saar.raz, rsmith.
thakis marked an inline comment as done.
thakis added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3645
   // CityHash, but this will do for now.
   hash_code code = hash_value(getClangFullRepositoryVersion());
 

Arguably, we should omit the full repo version from the hash: There's no reason 
to use a new cache dir just because someone fixed a typo in the (say) mlir 
docs. We'd also be better about remembering to bump 
clang::serialization::VERSION_MAJOR/MINOR in that case.


With LLVM_APPEND_VC_REV=NO, Modules/merge-lifetime-extended-temporary.cpp
would fail if it ran before a0f50d731639350c7a7 
 (which 
changed
the serialization format) and then after, for these reasons:

1. With LLVM_APPEND_VC_REV=NO, the module hash before and after the change was 
the same.

2. Modules/merge-lifetime-extended-temporary.cpp is the only test we have that 
uses -fmodule-cache-path=%t that a) actually writes to the cache path b) 
doesn't do `rm -rf %t` at the top of the test

So the old run would write a module file, and then the new run would
try to load it, but the serialized format changed.

Do several things to fix this:

1. Include clang::serialization::VERSION_MAJOR/VERSION_MINOR in the module 
hash, so that when the AST format changes (...and we remember to bump these), 
we use a different module cache dir.
2. Bump VERSION_MAJOR, since a0f50d731639350c7a7 
 changed 
the on-disk format in a way that a gch file written before that change can't be 
read after that change.
3. Add `rm -rf %t` to all tests that pass -fmodule-cache-path=%t. This is 
unneccessary from a correctness PoV after 1 and 2, but makes it so that we 
don't amass many cache dirs over time. (Arguably, it also makes it so that the 
test suite doesn't catch when we change the serialization format but don't bump 
clang::serialization::VERSION_MAJOR/VERSION_MINOR; oh well.)


https://reviews.llvm.org/D73202

Files:
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Modules/diagnostics.modulemap
  clang/test/Modules/exception-spec.cpp
  clang/test/Modules/merge-lifetime-extended-temporary.cpp
  clang/test/Modules/objc-method-redecl.m
  clang/test/Modules/using-decl-inheritance.cpp


Index: clang/test/Modules/using-decl-inheritance.cpp
===
--- clang/test/Modules/using-decl-inheritance.cpp
+++ clang/test/Modules/using-decl-inheritance.cpp
@@ -1,3 +1,4 @@
+// RUN: rm -rf %t
 // RUN: %clang_cc1 -x c++ -fmodules -fmodules-local-submodule-visibility 
-fmodules-cache-path=%t %s -verify
 // RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t %s -verify
 
Index: clang/test/Modules/objc-method-redecl.m
===
--- clang/test/Modules/objc-method-redecl.m
+++ clang/test/Modules/objc-method-redecl.m
@@ -1,3 +1,4 @@
+// RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c-header 
-emit-pch %S/Inputs/objc-method-redecl.h -o %t.pch -Wno-objc-root-class
 // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c 
-include-pch %t.pch %s -verify -Wno-objc-root-class
 // expected-no-diagnostics
Index: clang/test/Modules/merge-lifetime-extended-temporary.cpp
===
--- clang/test/Modules/merge-lifetime-extended-temporary.cpp
+++ clang/test/Modules/merge-lifetime-extended-temporary.cpp
@@ -1,3 +1,4 @@
+// RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x 
c++ -I%S/Inputs/merge-lifetime-extended-temporary -verify -std=c++11 %s 
-DORDER=1
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -x 
c++ -I%S/Inputs/merge-lifetime-extended-temporary -verify -std=c++11 %s 
-DORDER=2
 
Index: clang/test/Modules/exception-spec.cpp
===
--- clang/test/Modules/exception-spec.cpp
+++ clang/test/Modules/exception-spec.cpp
@@ -1,3 +1,4 @@
+// RUN: rm -rf %t
 // RUN: %clang_cc1 -x c++ -std=c++17 -fmodules 
-fmodules-local-submodule-visibility -fmodules-cache-path=%t %s -verify
 
 // expected-no-diagnostics
Index: clang/test/Modules/diagnostics.modulemap
===
--- clang/test/Modules/diagnostics.modulemap
+++ clang/test/Modules/diagnostics.modulemap
@@ -1,3 +1,4 @@
+// RUN: rm -rf %t
 // RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t 
-fmodule-map-file=%S/Inputs/diagnostics-aux.modulemap -fmodule-map-file=%s 
-fsyntax-only -x c++ /dev/null 2>&1 | FileCheck %s --implicit-check-not error:
 
 // CHECK: In file included from {{.*}}diagnostics-aux.modulema

[PATCH] D73203: [clang-tidy] Prevent a remove only fixit causing a conflict when enclosed by another fixit

2020-01-22 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73203

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
@@ -589,8 +589,8 @@
 };
 
 Event(unsigned Begin, unsigned End, EventType Type, unsigned ErrorId,
-  unsigned ErrorSize)
-: Type(Type), ErrorId(ErrorId) {
+  unsigned ErrorSize, const tooling::Replacement &Replacement)
+: Type(Type), ErrorId(ErrorId), Replacement(&Replacement) {
   // The events are going to be sorted by their position. In case of draw:
   //
   // * If an interval ends at the same position at which other interval
@@ -631,6 +631,8 @@
 // The index of the error to which the interval that generated this event
 // belongs.
 unsigned ErrorId;
+// The replacement this event relates to.
+const tooling::Replacement *Replacement;
 // The events will be sorted based on this field.
 std::tuple Priority;
   };
@@ -666,15 +668,19 @@
 if (Begin == End)
   continue;
 auto &Events = FileEvents[FilePath];
-Events.emplace_back(Begin, End, Event::ET_Begin, I, Sizes[I]);
-Events.emplace_back(Begin, End, Event::ET_End, I, Sizes[I]);
+Events.emplace_back(Begin, End, Event::ET_Begin, I, Sizes[I], Replace);
+Events.emplace_back(Begin, End, Event::ET_End, I, Sizes[I], Replace);
   }
 }
   }
 
   std::vector Apply(ErrorFixes.size(), true);
   for (auto &FileAndEvents : FileEvents) {
+llvm::SmallSet RemoveOnlyEvents;
 std::vector &Events = FileAndEvents.second;
+llvm::SmallDenseMap>
+DiscardableReplacements;
 // Sweep.
 std::sort(Events.begin(), Events.end());
 int OpenIntervals = 0;
@@ -683,12 +689,60 @@
 --OpenIntervals;
   // This has to be checked after removing the interval from the count if it
   // is an end event, or before adding it if it is a begin event.
-  if (OpenIntervals != 0)
-Apply[Event.ErrorId] = false;
+  if (OpenIntervals != 0) {
+if (Event.Replacement->getReplacementText().empty()) {
+  if (Event.Type == Event::ET_Begin) {
+// Starting a removal only fix-it is OK inside another fix-it.
+// But need to discard this specific fix-it from its parent so it
+// wont get executed later and cause a conflict.
+RemoveOnlyEvents.insert(&Event);
+DiscardableReplacements[Event.ErrorId].insert(Event.Replacement);
+  } else if (Event.Type == Event::ET_End) {
+// End of a Remove only fix-it, Remove it from the set
+bool Found = false;
+for (const auto *RemoveOnlyEvent : RemoveOnlyEvents) {
+  if (RemoveOnlyEvent->ErrorId == Event.ErrorId) {
+assert(!Found && "Event should only appear in set once");
+RemoveOnlyEvents.erase(RemoveOnlyEvent);
+Found = true;
+  }
+}
+assert(Found && "Event didn't appear in set");
+  }
+} else {
+  // This isnt a text removal only change, so must be a conflict
+  Apply[Event.ErrorId] = false;
+}
+  } else {
+assert(RemoveOnlyEvents.empty() &&
+   "Once OpenIntervals is `0` this set should be empty");
+  }
   if (Event.Type == Event::ET_Begin)
 ++OpenIntervals;
 }
 assert(OpenIntervals == 0 && "Amount of begin/end points doesn't match");
+for (const auto &ErrorAndDiscarded : DiscardableReplacements) {
+  unsigned ErrorIndex = ErrorAndDiscarded.first;
+  const auto &Discarded = ErrorAndDiscarded.second;
+  if (!Apply[ErrorIndex])
+continue; // The whole error has already been discarded
+  tooling::Replacements NewReplacements;
+  const auto &CurReplacements =
+  ErrorFixes[ErrorIndex].second->lookup(FileAndEvents.first);
+  for (const auto &Replacement : CurReplacements) {
+// Comparing the pointer here is fine as they are pointing to the same
+// Replacement.
+if (Discarded.count(&Replacement))
+  continue;
+if (NewReplacements.add(Replacement)) {
+  // This should never fire as we have just tested
+  // but leave the check in just in case.
+  Apply[ErrorIndex] = false;
+}
+  }
+  ErrorFixes[ErrorIndex].second->insert_or_assign(
+  FileAndEvents.first, std::move(NewReplacements));
+}
   }
 
   for (unsigned I = 0; I < ErrorFixes.size(); ++I) {
___
cfe-commits mailing list
cfe-commits@lists.l

[PATCH] D72578: [compiler-rt] [builtins] Fix clear_cache_test to work with MPROTECT

2020-01-22 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3215f7c7a81f: [compiler-rt] [builtins] Fix clear_cache_test 
to work with MPROTECT (authored by mgorny).
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72578

Files:
  compiler-rt/test/builtins/Unit/clear_cache_test.c


Index: compiler-rt/test/builtins/Unit/clear_cache_test.c
===
--- compiler-rt/test/builtins/Unit/clear_cache_test.c
+++ compiler-rt/test/builtins/Unit/clear_cache_test.c
@@ -1,6 +1,6 @@
 // REQUIRES: native-run
 // UNSUPPORTED: arm, aarch64
-// RUN: %clang_builtins %s %librt -o %t && %run_nomprotect %t
+// RUN: %clang_builtins %s %librt -o %t && %run %t
 // REQUIRES: librt_has_clear_cache
 //===-- clear_cache_test.c - Test clear_cache 
-===//
 //
@@ -30,28 +30,56 @@
 static int func1() { return 1; }
 static int func2() { return 2; }
 
-void *__attribute__((noinline))
+void __attribute__((noinline))
 memcpy_f(void *dst, const void *src, size_t n) {
 // ARM and MIPS nartually align functions, but use the LSB for ISA selection
 // (THUMB, MIPS16/uMIPS respectively).  Ensure that the ISA bit is ignored in
 // the memcpy
 #if defined(__arm__) || defined(__mips__)
-  return (void *)((uintptr_t)memcpy(dst, (void *)((uintptr_t)src & ~1), n) |
-  ((uintptr_t)src & 1));
+  memcpy(dst, (void *)((uintptr_t)src & ~1), n);
+#else
+  memcpy(dst, (void *)((uintptr_t)src), n);
+#endif
+}
+
+// Realign the 'dst' pointer as if it has been returned by memcpy() above.
+// We need to split it because we're using two mappings for the same area.
+void *__attribute__((noinline))
+realign_f(void *dst, const void *src, size_t n) {
+#if defined(__arm__) || defined(__mips__)
+  return (void *)((uintptr_t)dst | ((uintptr_t)src & 1));
 #else
-  return memcpy(dst, (void *)((uintptr_t)src), n);
+  return dst;
 #endif
 }
 
 int main()
 {
 const int kSize = 128;
-#if !defined(_WIN32)
+#if defined(__NetBSD__)
+// we need to create separate RW and RX mappings to satisfy MPROTECT
+uint8_t *write_buffer = mmap(0, kSize,
+ PROT_MPROTECT(PROT_READ | PROT_WRITE |
+   PROT_EXEC),
+ MAP_ANON | MAP_PRIVATE, -1, 0);
+if (write_buffer == MAP_FAILED)
+  return 1;
+uint8_t *execution_buffer = mremap(write_buffer, kSize, NULL, kSize,
+   MAP_REMAPDUP);
+if (execution_buffer == MAP_FAILED)
+  return 1;
+
+if (mprotect(write_buffer, kSize, PROT_READ | PROT_WRITE) == -1)
+  return 1;
+if (mprotect(execution_buffer, kSize, PROT_READ | PROT_EXEC) == -1)
+  return 1;
+#elif !defined(_WIN32)
 uint8_t *execution_buffer = mmap(0, kSize,
  PROT_READ | PROT_WRITE | PROT_EXEC,
  MAP_ANON | MAP_PRIVATE, -1, 0);
 if (execution_buffer == MAP_FAILED)
   return 1;
+uint8_t *write_buffer = execution_buffer;
 #else
 HANDLE mapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
PAGE_EXECUTE_READWRITE, 0, kSize, NULL);
@@ -62,16 +90,19 @@
 mapping, FILE_MAP_ALL_ACCESS | FILE_MAP_EXECUTE, 0, 0, 0);
 if (execution_buffer == NULL)
 return 1;
+uint8_t *write_buffer = execution_buffer;
 #endif
 
 // verify you can copy and execute a function
-pfunc f1 = (pfunc)memcpy_f(execution_buffer, func1, kSize);
+memcpy_f(write_buffer, func1, kSize);
+pfunc f1 = (pfunc)realign_f(execution_buffer, func1, kSize);
 __clear_cache(execution_buffer, execution_buffer + kSize);
 if ((*f1)() != 1)
 return 1;
 
 // verify you can overwrite a function with another
-pfunc f2 = (pfunc)memcpy_f(execution_buffer, func2, kSize);
+memcpy_f(write_buffer, func2, kSize);
+pfunc f2 = (pfunc)realign_f(execution_buffer, func2, kSize);
 __clear_cache(execution_buffer, execution_buffer + kSize);
 if ((*f2)() != 2)
 return 1;


Index: compiler-rt/test/builtins/Unit/clear_cache_test.c
===
--- compiler-rt/test/builtins/Unit/clear_cache_test.c
+++ compiler-rt/test/builtins/Unit/clear_cache_test.c
@@ -1,6 +1,6 @@
 // REQUIRES: native-run
 // UNSUPPORTED: arm, aarch64
-// RUN: %clang_builtins %s %librt -o %t && %run_nomprotect %t
+// RUN: %clang_builtins %s %librt -o %t && %run %t
 // REQUIRES: librt_has_clear_cache
 //===-- clear_cache_test.c - Test clear_cache -===//
 //
@@ -30,28 +30,56 @@
 static int func1() { return 1; }
 static int func2() { return 2; }
 
-void *__attribute__((noinline))
+void __attribute__((noinline))
 memcpy_f(void *dst, const void *

[PATCH] D67537: [clangd] Client-side support for inactive regions

2020-01-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

sorry for the looong delay, I was OOO for a few weeks before.

The patch looks fine, my concern is that how do we support this `line` 
extension when LSP provides a standard implementation -- there is some 
significant progress about semantic highlighting on VSCode,  VSCode now 
provides an experimental semantic token API 
, but 
no LSP binding yet (is not far away I think). When it is ready, we'd like to 
switch to that and get rid of our own implementation. Looking at the API there, 
it seems like we could make the line-style scope name `meta.disable` clangd 
specific, and define our own style.




Comment at: 
clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts:293
   });
+  if (line.isInactive) {
+inactiveRanges.push(new vscode.Range(

 another solution that requires minimal changes (but more hacky) is that, since 
clangd emits a `meta.disabled` token with line-set-only range, we could inject 
the `inactiveCodeDecorationType` to the `meta.disabled` slot of 
`Highlighter::decorationTypes`, and everything should work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67537



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


[PATCH] D73203: [clang-tidy] Prevent a remove only fixit causing a conflict when enclosed by another fixit

2020-01-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62056 tests passed, 0 failed 
and 783 were skipped.

{icon question-circle color=gray} clang-tidy: unknown.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73203



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


[PATCH] D73098: [clang-tidy] readability-identifier-naming disregards parameters restrictions on main like functions

2020-01-22 Thread Nathan James via Phabricator via cfe-commits
njames93 marked an inline comment as done.
njames93 added a comment.

In D73098#1833736 , @aaron.ballman 
wrote:

> In D73098#1832489 , @njames93 wrote:
>
> > In D73098#1832131 , @Mordante 
> > wrote:
> >
> > > Would it make sense to also allow wmain with wchar_t? 
> > > https://docs.microsoft.com/en-us/cpp/cpp/main-function-command-line-args?view=vs-2019
> >
> >
> > Does wmain get used in a lot of projects. If it's very niche then I don't 
> > feel it warrants a place in here. If it does I'll add it in.
>
>
> It's not uncommon on Windows, at the very least. I think it's worth 
> supporting.


I'll add that in




Comment at: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:474
   if (const auto *Decl = dyn_cast(D)) {
+if (isParamInMainLikeFunction(*Decl))
+  return SK_Invalid;

aaron.ballman wrote:
> njames93 wrote:
> > aaron.ballman wrote:
> > > I think a better approach may be to look at the `DeclContext` for the 
> > > `ParmVarDecl` object to see if it is a `FunctionDecl`, and if it is, call 
> > > `FunctionDecl::isMain()` to check.
> > I specifically didn't want to do that as is I want to get functions that 
> > act like main, usually the case when main itself dispatches to other 
> > functions with the same signature. 
> I'm not certain that's a case we should support -- users who write their own 
> main-like interfaces should probably follow their usual naming rules (even if 
> we don't do it ourselves). For instance, this will catch functions that are 
> definitely *not* `main`-like  except in the signature. e.g., `int 
> accumulate_string_lengths(int count, char *strings[]);`
Thats a good point, how about checking if the name of the function starts or 
ends with "main" or "wmain" for windows, maybe even have an option to enable 
ignore "main like" functions, but always ignore the actual main function


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73098



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


[PATCH] D72996: [Sema] Attempt to perform call-size-specific `__attribute__((alloc_align(param_idx)))` validation

2020-01-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:4489
+// Alignment calculations can wrap around if it's greater than 2**29.
+unsigned MaximumAlignment = 536870912;
+if (I > MaximumAlignment)

hfinkel wrote:
> jdoerfert wrote:
> > hfinkel wrote:
> > > jdoerfert wrote:
> > > > erichkeane wrote:
> > > > > jdoerfert wrote:
> > > > > > erichkeane wrote:
> > > > > > > I thought we had this stored somewhere else?  We probably should 
> > > > > > > have this be a constant somewhere in the frontend.  I THINK I 
> > > > > > > remember doing a review where I pulled this value into clang 
> > > > > > > somewhere...
> > > > > > That was D72998, and I don't think Clang is the right place for 
> > > > > > this constant. It is a property of the llvm alignment attribute and 
> > > > > > it should live there. Thus, llvm/include/Attributes.h or some 
> > > > > > similar place. Can't we "fix" the linker error by making it a 
> > > > > > constexpr global or are the errors because of other file content? 
> > > > > > If the latter, we could go with a llvm/include/magic_constants.h ;)
> > > > > The one I was thinking of was this one: 
> > > > > https://reviews.llvm.org/D68824
> > > > > 
> > > > > I don't remember what we came up with on the linking issue.  It would 
> > > > > be really nice if it was just something included from LLVM, but I 
> > > > > think SEMA typically doesn't include stuff from LLVM either.
> > > > I'm not too happy with the duplication of the constant but defining it 
> > > > once in clang is certainly better than having it in N places. For 
> > > > OpenMP we look into LLVM during SEMA and here there is an argument to 
> > > > be made that we should as well. I imagine more cases would pop up over 
> > > > time.
> > > > 
> > > > FWIW, if we allow to include LLVM headers, e.g., from IR or Frontend, 
> > > > we could still have a wrapper in SEMA to get the information so it 
> > > > doesn't expose the llvm:: namespace at the use sides (if that helps).
> > > > For OpenMP we look into LLVM during SEMA 
> > > 
> > > How do we do that?
> > > 
> > > There's certainly an interesting philosophical issue around whether 
> > > changes in LLVM should directly manifest as Clang behavioral changes, 
> > > especially in -fsyntax-only. The answer to this question might be 
> > > different for extensions vs. core language features (although alignment 
> > > restrictions might implicate both). AFAIKT, historically , our answer has 
> > > been to insist on separation.
> > > > For OpenMP we look into LLVM during SEMA
> > > How do we do that?
> > 
> > I was referring to code like this 
> > https://reviews.llvm.org/D71830#C1739755NL11085 
> > which is in CodeGen right now but has to move to SemaOverload. The code is 
> > completely reusable between Clang and Flang so I put it in 
> > lib/Frontend/OpenMP and I think that is the right place for it.
> > 
> > > There's certainly an interesting philosophical issue around whether 
> > > changes in LLVM should directly manifest as Clang behavioral changes, 
> > > especially in -fsyntax-only. The answer to this question might be 
> > > different for extensions vs. core language features (although alignment 
> > > restrictions might implicate both). AFAIKT, historically , our answer has 
> > > been to insist on separation.
> > 
> > 
> > I get that in a general sense. For the problem at hand, and as far as I 
> > known, the restriction stems only from the LLVM-IR restriction, correct? If 
> > so, what is the argument for separation? I mean, a change of the value in 
> > LLVM might directly impact Clang behavior.
> > 
> > I could also see us clamping the alignment during codegen. While that might 
> > have other problems they seem less practical to me.
> > 
> > 
> > 
> > 
> > I was referring to code like this 
> > https://reviews.llvm.org/D71830#C1739755NL11085
> > which is in CodeGen right now but has to move to SemaOverload. The code is 
> > completely reusable between Clang and Flang so I put it in 
> > lib/Frontend/OpenMP and I think that is the right place for it.
> 
> Fair, but that's a library designed to be a home for cross-language frontend 
> components. The variant-selection logic to which you're referring, itself, 
> does not actually need to link to LLVM's IR library, correct?
> 
> > I get that in a general sense. For the problem at hand, and as far as I 
> > known, the restriction stems only from the LLVM-IR restriction, correct? If 
> > so, what is the argument for separation? I mean, a change of the value in 
> > LLVM might directly impact Clang behavior.
> 
> Yes, I believe that the restriction is necessary because of an underlying 
> LLVM IR restriction. From my perspective, your argument is perfectly 
> rational. Clang only supports code generation using LLVM IR, and a 
> restriction that comes from LLVM should be directly tied to the underlying 
> LLVM threshold regardless of where

[PATCH] D68520: [cmake] Fix clang builds with BUILD_SHARED=ON and CLANG_LINK_CLANG_DYLIB=ON

2020-01-22 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.

Seems reasonable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68520



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


[PATCH] D72144: Treat C# `using` as a control statement

2020-01-22 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/unittests/Format/FormatTestCSharp.cpp:259
+
+  verifyFormat("using (StreamWriter sw = new StreamWriter(filenameB)) {}",
+   Style);

jbcoe wrote:
> krasimir wrote:
> > Can this appear at the top-level? If not, just keep the other test case to 
> > avoid confusion.
> I'm following the example set by by test cases above. I can remove (all) if 
> you prefer and agree it does not test anything new.
I didn't notice the old example. Yes, please remove all of them.


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

https://reviews.llvm.org/D72144



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


[PATCH] D72829: Implement -fsemantic-interposition

2020-01-22 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 62107 tests passed, 0 failed 
and 808 were skipped.

{icon question-circle color=gray} clang-tidy: unknown.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72829



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


[PATCH] D72114: [MS] Overhaul how clang passes overaligned args on x86_32

2020-01-22 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper 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/D72114/new/

https://reviews.llvm.org/D72114



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


[PATCH] D72934: [ARM,MVE] Support immediate vbicq,vorrq,vmvnq intrinsics.

2020-01-22 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham updated this revision to Diff 239609.
simon_tatham marked an inline comment as done.
simon_tatham edited the summary of this revision.
simon_tatham added a comment.

I've revised the MC representations of VBIC and VORR as suggested, but that was 
a big enough patch that I've done it separately as D73205 
. This patch now sits on top of that one.

Changing VBIC and VORR meant I could do the isel for the unpredicated forms in 
pure Tablegen. But the predicated ones would still have needed C++, because the 
IR intrinsics would have wanted the immediate in its natural form, but by the 
time you generate an instruction, it has to be re-encoded as NEON. The simplest 
way was to stop adding new IR intrinsics, and instead encode the predicated 
instructions as a select. Then I still get to use isel lowering's conversion 
into VBICIMM/VORRIMM which does the immediate translation for me.

Adjusting the VMOVL pattern to expect the result of my modified lowering has 
made all those unrelated MVE codegen tests go back to the way they were before, 
so the new version of this patch doesn't have to change anything there.

Also added a negative llc test with an immediate that doesn't fit into VBICIMM, 
to prove that it gets sensibly selected as a different instruction sequence and 
nothing crashes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72934

Files:
  clang/include/clang/Basic/arm_mve.td
  clang/include/clang/Basic/arm_mve_defs.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/arm-mve-intrinsics/bitwise-imm.c
  clang/test/Sema/arm-mve-immediates.c
  clang/utils/TableGen/MveEmitter.cpp
  llvm/lib/Target/ARM/ARMISelLowering.cpp
  llvm/lib/Target/ARM/ARMInstrInfo.td
  llvm/lib/Target/ARM/ARMInstrMVE.td
  llvm/lib/Target/ARM/ARMInstrNEON.td
  llvm/test/CodeGen/Thumb2/mve-intrinsics/bitwise-imm.ll

Index: llvm/test/CodeGen/Thumb2/mve-intrinsics/bitwise-imm.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/mve-intrinsics/bitwise-imm.ll
@@ -0,0 +1,365 @@
+; 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 <8 x i16> @test_vbicq_n_u16_sh0(<8 x i16> %a) {
+; CHECK-LABEL: test_vbicq_n_u16_sh0:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vbic.i16 q0, #0x64
+; CHECK-NEXT:bx lr
+entry:
+  %0 = and <8 x i16> %a, 
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vbicq_n_u16_sh8(<8 x i16> %a) {
+; CHECK-LABEL: test_vbicq_n_u16_sh8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vbic.i16 q0, #0x6400
+; CHECK-NEXT:bx lr
+entry:
+  %0 = and <8 x i16> %a, 
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vbicq_n_u32_sh0(<4 x i32> %a) {
+; CHECK-LABEL: test_vbicq_n_u32_sh0:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vbic.i32 q0, #0x64
+; CHECK-NEXT:bx lr
+entry:
+  %0 = and <4 x i32> %a, 
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vbicq_n_u32_sh8(<4 x i32> %a) {
+; CHECK-LABEL: test_vbicq_n_u32_sh8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vbic.i32 q0, #0x6400
+; CHECK-NEXT:bx lr
+entry:
+  %0 = and <4 x i32> %a, 
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vbicq_n_u32_sh16(<4 x i32> %a) {
+; CHECK-LABEL: test_vbicq_n_u32_sh16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vbic.i32 q0, #0x64
+; CHECK-NEXT:bx lr
+entry:
+  %0 = and <4 x i32> %a, 
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vbicq_n_u32_sh24(<4 x i32> %a) {
+; CHECK-LABEL: test_vbicq_n_u32_sh24:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vbic.i32 q0, #0x6400
+; CHECK-NEXT:bx lr
+entry:
+  %0 = and <4 x i32> %a, 
+  ret <4 x i32> %0
+}
+
+; The immediate in this case is legal for a VMVN but not for a VBIC,
+; so in this case we expect to see the constant being prepared in
+; another register.
+define arm_aapcs_vfpcc <4 x i32> @test_vbicq_n_u32_illegal(<4 x i32> %a) {
+; CHECK-LABEL: test_vbicq_n_u32_illegal:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmvn.i32 q1, #0x54ff
+; CHECK-NEXT:vand q0, q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = and <4 x i32> %a, 
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vorrq_n_u16_sh0(<8 x i16> %a) {
+; CHECK-LABEL: test_vorrq_n_u16_sh0:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vorr.i16 q0, #0x64
+; CHECK-NEXT:bx lr
+entry:
+  %0 = or <8 x i16> %a, 
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vorrq_n_u16_sh8(<8 x i16> %a) {
+; CHECK-LABEL: test_vorrq_n_u16_sh8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vorr.i16 q0, #0x6400
+; CHECK-NEXT:bx lr
+entry:
+  %0 = or <8 x i16> %a, 
+  ret <8 x i16> %0
+}
+
+define

  1   2   3   >