[PATCH] D73354: clang-format: insert trailing commas into containers.

2020-02-03 Thread Martin Probst via Phabricator via cfe-commits
mprobst closed this revision.
mprobst marked an inline comment as done.
mprobst added a comment.

This has landed as https://reviews.llvm.org/rGa324fcf1ae6 (not sure why this 
hasn't closed automatically).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73354



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


[PATCH] D69868: Allow "callbr" to return non-void values

2020-02-03 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

Friendly ping. :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69868



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


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

2020-02-03 Thread Awanish Pandey via Phabricator via cfe-commits
awpandey updated this revision to Diff 241984.
awpandey marked 2 inline comments as done.
awpandey added a comment.

Thanks, @aprantl, and @dblaikie. I have added two new test cases as per your 
suggestions. I have to update // dityperefs-3.8.ll// and 
//dityperefs-3.8.ll.bc// because they are no longer compatible with this patch.


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

https://reviews.llvm.org/D73462

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/MetadataLoader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/test/Assembler/DITemplateParameter.ll
  llvm/test/Bitcode/DITemplateParameter-5.0.ll
  llvm/test/Bitcode/DITemplateParameter-5.0.ll.bc
  llvm/test/Bitcode/dityperefs-3.8.ll
  llvm/test/Bitcode/dityperefs-3.8.ll.bc
  llvm/test/DebugInfo/X86/debug-info-template-parameter.ll
  llvm/unittests/IR/MetadataTest.cpp

Index: llvm/unittests/IR/MetadataTest.cpp
===
--- llvm/unittests/IR/MetadataTest.cpp
+++ llvm/unittests/IR/MetadataTest.cpp
@@ -2077,16 +2077,16 @@
   StringRef Name = "template";
   DIType *Type = getBasicType("basic");
 
-  auto *N = DITemplateTypeParameter::get(Context, Name, Type);
+  auto *N = DITemplateTypeParameter::get(Context, Name, Type, false);
 
   EXPECT_EQ(dwarf::DW_TAG_template_type_parameter, N->getTag());
   EXPECT_EQ(Name, N->getName());
   EXPECT_EQ(Type, N->getType());
-  EXPECT_EQ(N, DITemplateTypeParameter::get(Context, Name, Type));
+  EXPECT_EQ(N, DITemplateTypeParameter::get(Context, Name, Type, false));
 
-  EXPECT_NE(N, DITemplateTypeParameter::get(Context, "other", Type));
-  EXPECT_NE(N,
-DITemplateTypeParameter::get(Context, Name, getBasicType("other")));
+  EXPECT_NE(N, DITemplateTypeParameter::get(Context, "other", Type, false));
+  EXPECT_NE(N, DITemplateTypeParameter::get(Context, Name,
+getBasicType("other"), false));
 
   TempDITemplateTypeParameter Temp = N->clone();
   EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
@@ -2100,21 +2100,23 @@
   DIType *Type = getBasicType("basic");
   Metadata *Value = getConstantAsMetadata();
 
-  auto *N = DITemplateValueParameter::get(Context, Tag, Name, Type, Value);
+  auto *N =
+  DITemplateValueParameter::get(Context, Tag, Name, Type, false, Value);
   EXPECT_EQ(Tag, N->getTag());
   EXPECT_EQ(Name, N->getName());
   EXPECT_EQ(Type, N->getType());
   EXPECT_EQ(Value, N->getValue());
-  EXPECT_EQ(N, DITemplateValueParameter::get(Context, Tag, Name, Type, Value));
+  EXPECT_EQ(
+  N, DITemplateValueParameter::get(Context, Tag, Name, Type, false, Value));
 
   EXPECT_NE(N, DITemplateValueParameter::get(
Context, dwarf::DW_TAG_GNU_template_template_param, Name,
-   Type, Value));
-  EXPECT_NE(N,
-DITemplateValueParameter::get(Context, Tag, "other", Type, Value));
-  EXPECT_NE(N, DITemplateValueParameter::get(Context, Tag, Name,
- getBasicType("other"), Value));
-  EXPECT_NE(N, DITemplateValueParameter::get(Context, Tag, Name, Type,
+   Type, false, Value));
+  EXPECT_NE(N, DITemplateValueParameter::get(Context, Tag, "other", Type, false,
+ Value));
+  EXPECT_NE(N, DITemplateValueParameter::get(
+   Context, Tag, Name, getBasicType("other"), false, Value));
+  EXPECT_NE(N, DITemplateValueParameter::get(Context, Tag, Name, Type, false,
  getConstantAsMetadata()));
 
   TempDITemplateValueParameter Temp = N->clone();
Index: llvm/test/DebugInfo/X86/debug-info-template-parameter.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/X86/debug-info-template-parameter.ll
@@ -0,0 +1,90 @@
+; RUN: %llc_dwarf  %s -filetype=obj -o - | llvm-dwarfdump -v - | FileCheck %s
+
+; C++ source to regenerate:
+
+;template 
+;class foo {
+;};
+;
+;int main() {
+; foo f1;
+; foo<> f2;
+; return 0;
+;}
+
+; $ clang++ -O0 -gdwarf-5 -S -gdwarf-5 test.cpp 
+
+; CHECK: .debug_abbrev contents:
+; CHECK: DW_AT_default_value DW_FORM_flag_present
+
+; CHECK: debug_info contents:
+
+; CHECK: DW_AT_name {{.*}} "foo"
+; CHECK: DW_AT_type {{.*}} "int"
+; CHECK-NEXT: DW_AT_name {{.*}} "T"
+; CHECK-NOT: DW_AT_default_value
+; CHECK: DW_AT_type {{.*}} "int"
+; CHECK-NEXT: DW_AT_name {{.*}} "i"
+; CHECK-NOT: DW_AT_default_value
+
+; CHECK: DW_AT_name {{.*}} "foo"
+; CHECK: DW_AT_type {{.*}} "char"
+; CHECK-NEXT: DW_AT_name {{.*}} "T"
+; CHECK_NEXT: DW_AT_default_value {{.*}}

[PATCH] D73543: [clang] Add support for __builtin_memcpy_inline

2020-02-03 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet updated this revision to Diff 241988.
gchatelet marked 3 inline comments as done.
gchatelet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73543

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-memcpy-inline.c
  clang/test/Sema/builtins-memcpy-inline.c
  llvm/include/llvm/IR/IRBuilder.h
  llvm/lib/IR/IRBuilder.cpp

Index: llvm/lib/IR/IRBuilder.cpp
===
--- llvm/lib/IR/IRBuilder.cpp
+++ llvm/lib/IR/IRBuilder.cpp
@@ -200,6 +200,30 @@
   return CI;
 }
 
+CallInst *IRBuilderBase::CreateMemCpyInline(Value *Dst, MaybeAlign DstAlign,
+Value *Src, MaybeAlign SrcAlign,
+Value *Size) {
+  Dst = getCastedInt8PtrValue(Dst);
+  Src = getCastedInt8PtrValue(Src);
+  Value *IsVolatile = getInt1(false);
+
+  Value *Ops[] = {Dst, Src, Size, IsVolatile};
+  Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
+  Function *F = BB->getParent();
+  Module *M = F->getParent();
+  Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpy_inline, Tys);
+
+  CallInst *CI = createCallHelper(TheFn, Ops, this);
+
+  auto *MCI = cast(CI);
+  if (DstAlign)
+MCI->setDestAlignment(*DstAlign);
+  if (SrcAlign)
+MCI->setSourceAlignment(*SrcAlign);
+
+  return CI;
+}
+
 CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemCpy(
 Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
 uint32_t ElementSize, MDNode *TBAATag, MDNode *TBAAStructTag,
Index: llvm/include/llvm/IR/IRBuilder.h
===
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -560,6 +560,9 @@
  MDNode *ScopeTag = nullptr,
  MDNode *NoAliasTag = nullptr);
 
+  CallInst *CreateMemCpyInline(Value *Dst, MaybeAlign DstAlign, Value *Src,
+   MaybeAlign SrcAlign, Value *Size);
+
   /// Create and insert an element unordered-atomic memcpy between the
   /// specified pointers.
   ///
Index: clang/test/Sema/builtins-memcpy-inline.c
===
--- /dev/null
+++ clang/test/Sema/builtins-memcpy-inline.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#define NULL ((char *)0)
+
+#if __has_feature(__builtin_memcpy_inline)
+#warning defined as expected
+// expected-warning@-1 {{defined as expected}}
+#endif
+
+void test_memcpy_inline_null_src(void *ptr) {
+  __builtin_memcpy_inline(ptr, NULL, 4); // expected-warning {{null passed to a callee that requires a non-null argument}}
+}
+
+void test_memcpy_inline_null_dst(void *ptr) {
+  __builtin_memcpy_inline(NULL, ptr, 4); // expected-warning {{null passed to a callee that requires a non-null argument}}
+}
+
+void test_memcpy_inline_null_buffers() {
+  __builtin_memcpy_inline(NULL, NULL, 4);
+  // expected-warning@-1 {{null passed to a callee that requires a non-null argument}}
+  // expected-warning@-2 {{null passed to a callee that requires a non-null argument}}
+}
+
+void test_memcpy_inline_null_buffer_is_ok_if_size_is_zero(void *ptr) {
+  __builtin_memcpy_inline(ptr, NULL, /*size */ 0);
+  __builtin_memcpy_inline(NULL, ptr, /*size */ 0);
+  __builtin_memcpy_inline(NULL, NULL, /*size */ 0);
+}
+
+void test_memcpy_inline_non_constant_size(void *dst, const void *src, unsigned size) {
+  __builtin_memcpy_inline(dst, src, size); // expected-error {{argument to '__builtin_memcpy_inline' must be a constant integer}}
+}
Index: clang/test/CodeGen/builtins-memcpy-inline.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-memcpy-inline.c
@@ -0,0 +1,26 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: define void @test_memcpy_inline_0(i8* %dst, i8* %src)
+void test_memcpy_inline_0(void *dst, const void *src) {
+  // CHECK:   call void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* align 1 %0, i8* align 1 %1, i64 0, i1 false)
+  __builtin_memcpy_inline(dst, src, 0);
+}
+
+// CHECK-LABEL: define void @test_memcpy_inline_1(i8* %dst, i8* %src)
+void test_memcpy_inline_1(void *dst, const void *src) {
+  // CHECK:   call void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* align 1 %0, i8* align 1 %1, i64 1, i1 false)
+  __builtin_memcpy_inline(dst, src, 1);
+}
+
+// CHECK-LABEL: define void @test_memcpy_inline_4(i8* %dst, i8* %src)
+void test_memcpy_inline_4(void *dst, const void *src) {
+  // CHECK:   call void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* align 1 %0, i8* align 1 %1, i64 4, i1 false)
+  __bui

[PATCH] D73543: [clang] Add support for __builtin_memcpy_inline

2020-02-03 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:2252
+
+ * ``__builtin_memcpy_inline``
+

efriedma wrote:
> This is in the wrong section of the documentation.  We could 
> constant-evaluate __builtin_memcpy_inline, I guess, but that isn't the 
> primary purpose, and your patch doesn't implement constant evaluation anyway.
> 
> Might make sense to add a new section, if no existing section makes sense.
I added a new `memory builtins` section. Let me know what you think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73543



___
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-02-03 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added inline comments.



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

hokein wrote:
>  could you confirm with it? this looks like a `Foo` class definition.
Good point, I thought it should be both.



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

hokein wrote:
> nit: I don't understand why we need this change? it seems irrelevant to the 
> patch. 
This one is required for `SizeIs` matcher, but I believe I could use 
`UnorderedAre` instead (to make sure there are no extra references).



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

hokein wrote:
> 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)`?
If my understanding is correct, the suggestion is to take `isSpelled` argument 
and apply the `RefKind` flag based on the value of the argument instead of 
using `SymbolRole::Implicit`. Is that right? In this case I would be concerned 
about doing because that increase the amount of code in case there is any other 
index provider that sets the flags itself. 

What do you think?



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

hokein wrote:
> 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.
Makes sense. I was concerned about Doxygen not generating comments for both of 
these functions, but I think it should be OK.


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-02-03 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 241994.
kbobyrev added a comment.

Remove unnecessary include.


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/SymbolLocation.cpp
  clang-tools-extra/clangd/index/SymbolLocation.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
@@ -316,11 +316,16 @@
 /// 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 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);
+const syntax::Token *
 spelledIdentifierTouching(SourceLocation Loc,
   const syntax::TokenBuffer &Tokens);
 
Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -100,10 +100,14 @@
 MATCHER(RefRange, "") {
   const Ref &Pos = ::testing::get<0>(arg);
   const Range &Range = ::testing::get<1>(arg);
-  return std::make_tuple(Pos.Location.Start.line(), Pos.Location.Start.column(),
- Pos.Location.End.line(), Pos.Location.End.column()) ==
- std::make_tuple(Range.start.line, Range.start.character,
- Range.end.line, Range.end.character);
+  return toRange(Pos.Location) == Range;
+}
+MATCHER_P2(RefKindIs, Kind, Ranges, "") {
+  for (const auto &Reference : arg)
+if ((llvm::find(Ranges, toRange(Reference.Location)) != end(Ranges)) ==
+((Reference.Kind & Kind) == RefKind::Unknown))
+  return false;
+  return true;
 }
 ::testing::Matcher &>
 HaveRanges(const std::vector Ranges) {
@@ -700,6 +704,32 @@
   EXPECT_THAT(Refs, IsEmpty());
 }
 
+TEST_F(SymbolCollectorTest, SpelledReference) {
+  Annotations Header(R"cpp(
+  struct Foo;
+  #define MACRO Foo
+  )cpp");
+  Annotation

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

2020-02-03 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 241993.
kbobyrev marked 14 inline comments as done.
kbobyrev added a comment.

Address a number of 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/index/SymbolLocation.cpp
  clang-tools-extra/clangd/index/SymbolLocation.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
@@ -316,11 +316,16 @@
 /// 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 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);
+const syntax::Token *
 spelledIdentifierTouching(SourceLocation Loc,
   const syntax::TokenBuffer &Tokens);
 
Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -100,10 +100,14 @@
 MATCHER(RefRange, "") {
   const Ref &Pos = ::testing::get<0>(arg);
   const Range &Range = ::testing::get<1>(arg);
-  return std::make_tuple(Pos.Location.Start.line(), Pos.Location.Start.column(),
- Pos.Location.End.line(), Pos.Location.End.column()) ==
- std::make_tuple(Range.start.line, Range.start.character,
- Range.end.line, Range.end.character);
+  return toRange(Pos.Location) == Range;
+}
+MATCHER_P2(RefKindIs, Kind, Ranges, "") {
+  for (const auto &Reference : arg)
+if ((llvm::find(Ranges, toRange(Reference.Location)) != end(Ranges)) ==
+((Reference.Kind & Kind) == RefKind::Unknown))
+  return false;
+  return true;
 }
 ::testing::Matcher &>
 HaveRanges(const std::vector Ranges) {
@@ -700,6 +704,32 @@
   EXPECT_THAT(Refs, IsEmpty());
 }
 
+TEST_F(SymbolCollectorTest, SpelledRefer

[clang-tools-extra] b79cb54 - [clangd] Refactor TUScheduler options into a struct. NFC

2020-02-03 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-02-03T11:20:48+01:00
New Revision: b79cb547121dbd9f4bd4eaaf05354829ab74ac8e

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

LOG: [clangd] Refactor TUScheduler options into a struct. NFC

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index cf883f130da8..00da7af06741 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -113,6 +113,15 @@ ClangdServer::Options ClangdServer::optsForTest() {
   return Opts;
 }
 
+ClangdServer::Options::operator TUScheduler::Options() const {
+  TUScheduler::Options Opts;
+  Opts.AsyncThreadsCount = AsyncThreadsCount;
+  Opts.RetentionPolicy = RetentionPolicy;
+  Opts.StorePreamblesInMemory = StorePreamblesInMemory;
+  Opts.UpdateDebounce = UpdateDebounce;
+  return Opts;
+}
+
 ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
const FileSystemProvider &FSProvider,
const Options &Opts, Callbacks *Callbacks)
@@ -129,10 +138,10 @@ ClangdServer::ClangdServer(const 
GlobalCompilationDatabase &CDB,
   // is parsed.
   // FIXME(ioeric): this can be slow and we may be able to index on less
   // critical paths.
-  WorkScheduler(CDB, Opts.AsyncThreadsCount, Opts.StorePreamblesInMemory,
-std::make_unique(
-DynamicIdx.get(), Callbacks, 
Opts.SemanticHighlighting),
-Opts.UpdateDebounce, Opts.RetentionPolicy) {
+  WorkScheduler(
+  CDB, TUScheduler::Options(Opts),
+  std::make_unique(DynamicIdx.get(), Callbacks,
+ Opts.SemanticHighlighting)) {
   // Adds an index to the stack, at higher priority than existing indexes.
   auto AddIndex = [&](SymbolIndex *Idx) {
 if (this->Index != nullptr) {

diff  --git a/clang-tools-extra/clangd/ClangdServer.h 
b/clang-tools-extra/clangd/ClangdServer.h
index 7b870e5b300f..2d0957f441bb 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -149,6 +149,8 @@ class ClangdServer {
 std::function TweakFilter = [](const Tweak &T) {
   return !T.hidden(); // only enable non-hidden tweaks.
 };
+
+explicit operator TUScheduler::Options() const;
   };
   // Sensible default options for use in tests.
   // Features like indexing must be enabled if desired.

diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index 9ea1582e9643..69dec9b677fb 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -847,18 +847,16 @@ struct TUScheduler::FileData {
 };
 
 TUScheduler::TUScheduler(const GlobalCompilationDatabase &CDB,
- unsigned AsyncThreadsCount,
- bool StorePreamblesInMemory,
- std::unique_ptr Callbacks,
- std::chrono::steady_clock::duration UpdateDebounce,
- ASTRetentionPolicy RetentionPolicy)
-: CDB(CDB), StorePreamblesInMemory(StorePreamblesInMemory),
+ const Options &Opts,
+ std::unique_ptr Callbacks)
+: CDB(CDB), StorePreamblesInMemory(Opts.StorePreamblesInMemory),
   Callbacks(Callbacks ? move(Callbacks)
   : std::make_unique()),
-  Barrier(AsyncThreadsCount),
-  IdleASTs(std::make_unique(RetentionPolicy.MaxRetainedASTs)),
-  UpdateDebounce(UpdateDebounce) {
-  if (0 < AsyncThreadsCount) {
+  Barrier(Opts.AsyncThreadsCount),
+  IdleASTs(
+  std::make_unique(Opts.RetentionPolicy.MaxRetainedASTs)),
+  UpdateDebounce(Opts.UpdateDebounce) {
+  if (0 < Opts.AsyncThreadsCount) {
 PreambleTasks.emplace();
 WorkerThreads.emplace();
   }

diff  --git a/clang-tools-extra/clangd/TUScheduler.h 
b/clang-tools-extra/clangd/TUScheduler.h
index 65d87df5a939..e59bebaea330 100644
--- a/clang-tools-extra/clangd/TUScheduler.h
+++ b/clang-tools-extra/clangd/TUScheduler.h
@@ -20,6 +20,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -143,14 +144,28 @@ class ParsingCallbacks {
 /// and scheduling tasks.
 /// Callbacks are run on a threadpool and it's appropriate to do slow work in
 /// them. Each task has a name, used for tracing (should 

[PATCH] D73775: [clang-tidy] Cover cases like (b && c && b) in the redundant expression check

2020-02-03 Thread Alexey Romanov via Phabricator via cfe-commits
alexeyr updated this revision to Diff 242000.
alexeyr added a comment.

Followed Eugene Zelenko's comments and fixed a false positive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73775

Files:
  clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
@@ -81,6 +81,11 @@
   if (P2.a[P1.x + 2] < P2.x && P2.a[(P1.x) + (2)] < (P2.x)) return 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: both sides of operator are equivalent
 
+  if (X && Y && X) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: Operator has equivalent nested operands
+  if (X || (Y || X)) return 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: Operator has equivalent nested operands
+
   return 0;
 }
 
@@ -106,6 +111,7 @@
   if (++X != ++X) return 1;
   if (P.a[X]++ != P.a[X]++) return 1;
   if (P.a[X++] != P.a[X++]) return 1;
+  if (X && X++ && X) return 1;
 
   if ("abc" == "ABC") return 1;
   if (foo(bar(0)) < (foo(bat(0, 1 return 1;
Index: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -18,7 +18,9 @@
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/SmallBitVector.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/Support/FormatVariadic.h"
 #include 
 #include 
 #include 
@@ -304,6 +306,114 @@
   }
 }
 
+// to use in the template below
+static OverloadedOperatorKind getOp(const BinaryOperator *Op) {
+  return BinaryOperator::getOverloadedOperator(Op->getOpcode());
+}
+
+static OverloadedOperatorKind getOp(const CXXOperatorCallExpr *Op) {
+  if (Op->getNumArgs() != 2)
+return OO_None;
+  return Op->getOperator();
+}
+
+static std::pair
+getOperands(const BinaryOperator *Op) {
+  return {Op->getLHS()->IgnoreParenImpCasts(),
+  Op->getRHS()->IgnoreParenImpCasts()};
+}
+
+static std::pair
+getOperands(const CXXOperatorCallExpr *Op) {
+  return {Op->getArg(0)->IgnoreParenImpCasts(),
+  Op->getArg(1)->IgnoreParenImpCasts()};
+}
+
+template 
+static const TExpr *checkOpKind(const Expr *TheExpr, OverloadedOperatorKind OpKind) {
+  const auto *AsTExpr = dyn_cast_or_null(TheExpr);
+  if (AsTExpr && getOp(AsTExpr) == OpKind)
+return AsTExpr;
+
+  return nullptr;
+}
+
+// returns true if a subexpression has two directly equivalent operands and
+// is already handled by operands/parametersAreEquivalent
+template 
+static bool collectOperands(const Expr *Part,
+SmallVector &AllOperands,
+OverloadedOperatorKind OpKind) {
+  const auto *PartAsBinOp = checkOpKind(Part, OpKind);
+  if (PartAsBinOp) {
+auto Operands = getOperands(PartAsBinOp);
+if (areEquivalentExpr(Operands.first, Operands.second))
+  return true;
+return collectOperands(Operands.first, AllOperands, OpKind) ||
+   collectOperands(Operands.second, AllOperands, OpKind);
+  } else {
+AllOperands.push_back(Part);
+  }
+  return false;
+}
+
+template 
+static bool
+markDuplicateOperands(const TExpr *TheExpr,
+  ast_matchers::internal::BoundNodesTreeBuilder *Builder,
+  ASTContext &Context) {
+  const OverloadedOperatorKind OpKind = getOp(TheExpr);
+  if (OpKind == OO_None)
+return false;
+  // if there are no nested operators of the same kind, it's handled by
+  // operands/parametersAreEquivalent
+  const std::pair Operands = getOperands(TheExpr);
+  if (!(checkOpKind(Operands.first, OpKind) ||
+checkOpKind(Operands.second, OpKind)))
+return false;
+
+  // if parent is the same kind of operator, it's handled by a previous call to
+  // markDuplicateOperands
+  const ASTContext::DynTypedNodeList Parents = Context.getParents(*TheExpr);
+  for (ast_type_traits::DynTypedNode Parent : Parents) {
+if (checkOpKind(Parent.get(), OpKind))
+  return false;
+  }
+
+  SmallVector AllOperands;
+  if (collectOperands(Operands.first, AllOperands, OpKind))
+return false;
+  if (collectOperands(Operands.second, AllOperands, OpKind))
+return false;
+  size_t NumOperands = AllOperands.size();
+  llvm::SmallBitVector Duplicates(NumOperands);
+  for (size_t I = 0; I < NumOperands; I++) {
+if (Duplicates[I])
+  continue;
+bool FoundDuplicates = false;
+
+for (size_t J = I + 1; J < NumOperands; J++) {
+  if (AllOperands[J]->HasSideEffects(Context))
+b

[clang-tools-extra] 6b15a3d - [clangd] TUScheduler::run() (i.e. workspace/symbol) counts towards concurrent threads

2020-02-03 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-02-03T11:32:33+01:00
New Revision: 6b15a3d722a98c8c4f99ac45cae118e4af9244af

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

LOG: [clangd] TUScheduler::run() (i.e. workspace/symbol) counts towards 
concurrent threads

This seems to just be an oversight.

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index 69dec9b677fb..9218ae9a03ce 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -929,8 +929,9 @@ void TUScheduler::run(llvm::StringRef Name,
   llvm::unique_function Action) {
   if (!PreambleTasks)
 return Action();
-  PreambleTasks->runAsync(Name, [Ctx = Context::current().clone(),
+  PreambleTasks->runAsync(Name, [this, Ctx = Context::current().clone(),
  Action = std::move(Action)]() mutable {
+std::lock_guard BarrierLock(Barrier);
 WithContext WC(std::move(Ctx));
 Action();
   });



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


[PATCH] D73775: [clang-tidy] Cover cases like (b && c && b) in the redundant expression check

2020-02-03 Thread Alexey Romanov via Phabricator via cfe-commits
alexeyr marked 11 inline comments as done.
alexeyr added inline comments.



Comment at: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:363
+  ASTContext &Context) {
+  const auto OpKind = getOp(TheExpr);
+  // if there are no nested operators of the same kind, it's handled by

alexeyr wrote:
> Eugene.Zelenko wrote:
> > Please don't use auto when type is not spelled explicitly or iterator.
> In this case the type will depend on `TExpr`: either `BinaryOperator::Opcode` 
> or `OverloadedOperatorKind`. I could make it a template parameter (but it 
> won't be deducible) or convert `OverloadedOperatorKind` to `Opcode`. Any 
> preference?
Converted both to `OverloadedOperatorKind` (because I have a use for `OO_None`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73775



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


[PATCH] D73869: [clang][AST] Add an AST matcher for deducedTemplateSpeializationType.

2020-02-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: gribozavr2.
Herald added a project: clang.

misc-unused-using clang-tidy check needs this matcher to fix a false
positive of C++17 deduced class template types.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73869

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1458,6 +1458,12 @@
   templateSpecializationType()));
 }
 
+TEST(TypeMatching, MatchesDeucedTemplateSpecializationType) {
+  EXPECT_TRUE(matches("template  class A{ public: A(T) {} }; A 
a(1);",
+  deducedTemplateSpecializationType(),
+  LanguageMode::Cxx17OrLater));
+}
+
 TEST(TypeMatching, MatchesRecordType) {
   EXPECT_TRUE(matches("class C{}; C c;", recordType()));
   EXPECT_TRUE(matches("struct S{}; S s;",
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -202,6 +202,7 @@
   REGISTER_MATCHER(declStmt);
   REGISTER_MATCHER(declaratorDecl);
   REGISTER_MATCHER(decltypeType);
+  REGISTER_MATCHER(deducedTemplateSpecializationType);
   REGISTER_MATCHER(defaultStmt);
   REGISTER_MATCHER(dependentSizedArrayType);
   REGISTER_MATCHER(designatedInitExpr);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -6030,6 +6030,20 @@
 extern const AstTypeMatcher
 templateSpecializationType;
 
+/// Matches C++17 deduced template specialization types, e.g. deduced class
+/// template types.
+///
+/// Given
+/// \code
+///   template 
+///   class C { public: C(T); };
+///
+///   C c(123);
+/// \endcode
+/// \c deducedTemplateSpecializationType() matches the type in \c c.
+extern const AstTypeMatcher
+deducedTemplateSpecializationType;
+
 /// Matches types nodes representing unary type transformations.
 ///
 /// Given:
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -1750,6 +1750,19 @@
 
 
 
+MatcherType>deducedTemplateSpecializationTypeMatcherDeducedTemplateSpecializationType>...
+Matches C++17 deduced template 
specialization types, e.g. deduced class
+template types.
+
+Given
+  template 
+  class C { public: C(T); };
+
+  C c(123);
+deducedTemplateSpecializationType() matches the type in c.
+
+
+
 MatcherType>dependentSizedArrayTypeMatcherDependentSizedArrayType>...
 Matches C++ 
arrays whose size is a value-dependent expression.
 
@@ -3522,7 +3535,7 @@
 
 
 
-MatcherNamedDecl>hasNameconst std::string  Name
+MatcherNamedDecl>hasNameStringRef Name
 Matches NamedDecl nodes 
that have the specified name.
 
 Supports specifying enclosing namespaces or classes by prefixing the name


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1458,6 +1458,12 @@
   templateSpecializationType()));
 }
 
+TEST(TypeMatching, MatchesDeucedTemplateSpecializationType) {
+  EXPECT_TRUE(matches("template  class A{ public: A(T) {} }; A a(1);",
+  deducedTemplateSpecializationType(),
+  LanguageMode::Cxx17OrLater));
+}
+
 TEST(TypeMatching, MatchesRecordType) {
   EXPECT_TRUE(matches("class C{}; C c;", recordType()));
   EXPECT_TRUE(matches("struct S{}; S s;",
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -202,6 +202,7 @@
   REGISTER_MATCHER(declStmt);
   REGISTER_MATCHER(declaratorDecl);
   REGISTER_MATCHER(decltypeType);
+  REGISTER_MATCHER(deducedTemplateSpecializationType);
   REGISTER_MATCHER(defaultStmt);
   REGISTER_MATCHER(dependentSizedArrayT

[PATCH] D73413: [clang-tidy] Add check to detect external definitions with no header declaration

2020-02-03 Thread Tony Lewis via Phabricator via cfe-commits
tonyelewis added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/misc/MissingHeaderFileDeclarationCheck.cpp:75
+  continue;
+if (AnyHeader || File->NamePart.equals_lower(ThisFile->NamePart))
+  return; // Found a good candidate for matching decl

njames93 wrote:
> tonyelewis wrote:
> > njames93 wrote:
> > > tonyelewis wrote:
> > > > njames93 wrote:
> > > > > gribozavr2 wrote:
> > > > > > njames93 wrote:
> > > > > > > gribozavr2 wrote:
> > > > > > > > njames93 wrote:
> > > > > > > > > gribozavr2 wrote:
> > > > > > > > > > This heuristic should be a lot more complex. In practice 
> > > > > > > > > > people have more complex naming conventions (for example, 
> > > > > > > > > > in Clang, Sema.h corresponds to many files named 
> > > > > > > > > > SemaSomethingSomething.cpp).
> > > > > > > > > > 
> > > > > > > > > > I think there is a high chance that checking only a header 
> > > > > > > > > > with a matching name will satisfy too few projects to be 
> > > > > > > > > > worth implementing.
> > > > > > > > > > 
> > > > > > > > > > On the other hand, if you could use C++ or Clang modules to 
> > > > > > > > > > narrow down the list of headers where the declaration 
> > > > > > > > > > should appear, that would be a much stronger signal.
> > > > > > > > > That is the reason I added the CheckAnyHeader option. For 
> > > > > > > > > small projects the matching name would be usually be enough, 
> > > > > > > > > but for big complex projects there is no feasible check that 
> > > > > > > > > would work. Falling back to making sure every external 
> > > > > > > > > definition has a declaration in at least one header will 
> > > > > > > > > always be a good warning
> > > > > > > > That's the thing -- due to the lack of consistency in projects 
> > > > > > > > and style guides for C++, I think most projects will have to 
> > > > > > > > turn on CheckAnyHeader. We get implementation complexity in 
> > > > > > > > ClangTidy, false positives in high-profile projects, force 
> > > > > > > > users to configure ClangTidy to work well for their projects 
> > > > > > > > (unless we set CheckAnyHeader=1 by default... which then nobody 
> > > > > > > > would flip back to zero), and little benefit for end users.
> > > > > > > Would you say the best way would be check if the source file name 
> > > > > > > starts with the header file name by default. Or is that very 
> > > > > > > specific to Clang?
> > > > > > > 
> > > > > > > ```
> > > > > > > /// 
> > > > > > > #include "SomeHeader.h"
> > > > > > > ```
> > > > > > > This file would check for declarations in `SomeHeader.h`
> > > > > > > 
> > > > > > > Or maybe check if the header file name starts with the source 
> > > > > > > file?
> > > > > > > 
> > > > > > > ```
> > > > > > > /// 
> > > > > > > #include "SomeHeaderImpl.h"
> > > > > > > ```
> > > > > > > This file would check for declarations in `SomeHeaderImpl.h`.
> > > > > > > Or even check both?
> > > > > > > Would you say the best way would be check if the source file name 
> > > > > > > starts with the header file name by default. Or is that very 
> > > > > > > specific to Clang?
> > > > > > 
> > > > > > I don't think it is too specific, it should cover many projects I 
> > > > > > think.
> > > > > > 
> > > > > > > Or maybe check if the header file name starts with the source 
> > > > > > > file?
> > > > > > 
> > > > > > Seems like an unusual case to me, but I'm willing to be convinced 
> > > > > > otherwise.
> > > > > I thought it was an unusual case and wasn't thinking it would be a 
> > > > > good idea to add. I'll just set it up so that it will always look in 
> > > > > header files whose names appear at the start of the main source file.
> > > > FWIW, my instinct is that there are two separate questions:
> > > > 
> > > >  1. What sort of files should have their external-linkage definitions 
> > > > checked?
> > > >  2. What sort of included files should be part of the search for 
> > > > adequate declarations that match those definitions?
> > > > 
> > > > ...and that my answers, in reverse order, are:
> > > > 
> > > >  2. All included files should be included (ie a check for a given 
> > > > external-linkage definition should be appeased by _any_ matching 
> > > > declaration in _any_ included file)
> > > >  1. Only main files. And (to prevent lots of false-positives when the 
> > > > tool is run over headers), only "c", "cc", "cxx", "cpp" files by 
> > > > default but with an option to check in _all_ main files.
> > > > 
> > > > I think this has the merits that it:
> > > >  * allows users to put their valid declaration in files with any 
> > > > extension they like
> > > >  * defaults to only firing when run against c/cc/cxx/cpp files but 
> > > > provides the option to fire when run against a file with _any_ extension
> > > > 
> > > > 
> > > > So I propose that there be one option and it be as follows:
> > > > 
> > > > 
> > > > > .. option:: CheckExtDefnsInA

[PATCH] D73869: [clang][AST] Add an AST matcher for deducedTemplateSpeializationType.

2020-02-03 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:6043
+/// \endcode
+/// \c deducedTemplateSpecializationType() matches the type in \c c.
+extern const AstTypeMatcher

"in the declaration of the variable \c c"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73869



___
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-02-03 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon times-circle color=red} Unit tests: fail. 61851 tests passed, 6 failed 
and 780 were skipped.

  failed: libc++.std/language_support/cmp/cmp_partialord/partialord.pass.cpp
  failed: libc++.std/language_support/cmp/cmp_strongeq/cmp.strongeq.pass.cpp
  failed: libc++.std/language_support/cmp/cmp_strongord/strongord.pass.cpp
  failed: libc++.std/language_support/cmp/cmp_weakeq/cmp.weakeq.pass.cpp
  failed: libc++.std/language_support/cmp/cmp_weakord/weakord.pass.cpp
  failed: lld.ELF/linkerscript/filename-spec.s

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

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

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


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


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] bdbdf74 - [clang][AST] Add an AST matcher for deducedTemplateSpeializationType.

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

Author: Haojian Wu
Date: 2020-02-03T12:11:44+01:00
New Revision: bdbdf748225525bb18cd0ffeb51c3e713f7b8e1b

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

LOG: [clang][AST] Add an AST matcher for deducedTemplateSpeializationType.

Summary:
misc-unused-using clang-tidy check needs this matcher to fix a false
positive of C++17 deduced class template types.

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 95328dcd82eb..3d2ff477853f 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -1750,6 +1750,20 @@ Node Matchers
 
 
 
+MatcherType>deducedTemplateSpecializationTypeMatcherDeducedTemplateSpecializationType>...
+Matches C++17 deduced template 
specialization types, e.g. deduced class
+template types.
+
+Given
+  template 
+  class C { public: C(T); };
+
+  C c(123);
+deducedTemplateSpecializationType() matches the type in the declaration
+of the variable c.
+
+
+
 MatcherType>dependentSizedArrayTypeMatcherDependentSizedArrayType>...
 Matches C++ 
arrays whose size is a value-dependent expression.
 
@@ -3522,7 +3536,7 @@ Narrowing Matchers
 
 
 
-MatcherNamedDecl>hasNameconst std::string  Name
+MatcherNamedDecl>hasNameStringRef Name
 Matches NamedDecl nodes 
that have the specified name.
 
 Supports specifying enclosing namespaces or classes by prefixing the name

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 4fdbf3e3ba6e..2bd24ef4cf6b 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -6030,6 +6030,21 @@ extern const AstTypeMatcher enumType;
 extern const AstTypeMatcher
 templateSpecializationType;
 
+/// Matches C++17 deduced template specialization types, e.g. deduced class
+/// template types.
+///
+/// Given
+/// \code
+///   template 
+///   class C { public: C(T); };
+///
+///   C c(123);
+/// \endcode
+/// \c deducedTemplateSpecializationType() matches the type in the declaration
+/// of the variable \c c.
+extern const AstTypeMatcher
+deducedTemplateSpecializationType;
+
 /// Matches types nodes representing unary type transformations.
 ///
 /// Given:

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 8c6dcfaaf52f..7344c622cc9d 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -202,6 +202,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(declStmt);
   REGISTER_MATCHER(declaratorDecl);
   REGISTER_MATCHER(decltypeType);
+  REGISTER_MATCHER(deducedTemplateSpecializationType);
   REGISTER_MATCHER(defaultStmt);
   REGISTER_MATCHER(dependentSizedArrayType);
   REGISTER_MATCHER(designatedInitExpr);

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 1fdaf66f285c..b603d764e3a6 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1458,6 +1458,12 @@ TEST(TypeMatching, MatchesTemplateSpecializationType) {
   templateSpecializationType()));
 }
 
+TEST(TypeMatching, MatchesDeucedTemplateSpecializationType) {
+  EXPECT_TRUE(matches("template  class A{ public: A(T) {} }; A 
a(1);",
+  deducedTemplateSpecializationType(),
+  LanguageMode::Cxx17OrLater));
+}
+
 TEST(TypeMatching, MatchesRecordType) {
   EXPECT_TRUE(matches("class C{}; C c;", recordType()));
   EXPECT_TRUE(matches("struct S{}; S s;",



___
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-02-03 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon times-circle color=red} Unit tests: fail. 61851 tests passed, 6 failed 
and 780 were skipped.

  failed: libc++.std/language_support/cmp/cmp_partialord/partialord.pass.cpp
  failed: libc++.std/language_support/cmp/cmp_strongeq/cmp.strongeq.pass.cpp
  failed: libc++.std/language_support/cmp/cmp_strongord/strongord.pass.cpp
  failed: libc++.std/language_support/cmp/cmp_weakeq/cmp.weakeq.pass.cpp
  failed: libc++.std/language_support/cmp/cmp_weakord/weakord.pass.cpp
  failed: lld.ELF/linkerscript/filename-spec.s

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

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

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


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


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] D73869: [clang][AST] Add an AST matcher for deducedTemplateSpeializationType.

2020-02-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 242007.
hokein marked an inline comment as done.
hokein added a comment.

address review comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73869

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1458,6 +1458,12 @@
   templateSpecializationType()));
 }
 
+TEST(TypeMatching, MatchesDeucedTemplateSpecializationType) {
+  EXPECT_TRUE(matches("template  class A{ public: A(T) {} }; A 
a(1);",
+  deducedTemplateSpecializationType(),
+  LanguageMode::Cxx17OrLater));
+}
+
 TEST(TypeMatching, MatchesRecordType) {
   EXPECT_TRUE(matches("class C{}; C c;", recordType()));
   EXPECT_TRUE(matches("struct S{}; S s;",
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -202,6 +202,7 @@
   REGISTER_MATCHER(declStmt);
   REGISTER_MATCHER(declaratorDecl);
   REGISTER_MATCHER(decltypeType);
+  REGISTER_MATCHER(deducedTemplateSpecializationType);
   REGISTER_MATCHER(defaultStmt);
   REGISTER_MATCHER(dependentSizedArrayType);
   REGISTER_MATCHER(designatedInitExpr);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -6030,6 +6030,21 @@
 extern const AstTypeMatcher
 templateSpecializationType;
 
+/// Matches C++17 deduced template specialization types, e.g. deduced class
+/// template types.
+///
+/// Given
+/// \code
+///   template 
+///   class C { public: C(T); };
+///
+///   C c(123);
+/// \endcode
+/// \c deducedTemplateSpecializationType() matches the type in the declaration
+/// of the variable \c c.
+extern const AstTypeMatcher
+deducedTemplateSpecializationType;
+
 /// Matches types nodes representing unary type transformations.
 ///
 /// Given:
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -1750,6 +1750,20 @@
 
 
 
+MatcherType>deducedTemplateSpecializationTypeMatcherDeducedTemplateSpecializationType>...
+Matches C++17 deduced template 
specialization types, e.g. deduced class
+template types.
+
+Given
+  template 
+  class C { public: C(T); };
+
+  C c(123);
+deducedTemplateSpecializationType() matches the type in the declaration
+of the variable c.
+
+
+
 MatcherType>dependentSizedArrayTypeMatcherDependentSizedArrayType>...
 Matches C++ 
arrays whose size is a value-dependent expression.
 
@@ -3522,7 +3536,7 @@
 
 
 
-MatcherNamedDecl>hasNameconst std::string  Name
+MatcherNamedDecl>hasNameStringRef Name
 Matches NamedDecl nodes 
that have the specified name.
 
 Supports specifying enclosing namespaces or classes by prefixing the name


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1458,6 +1458,12 @@
   templateSpecializationType()));
 }
 
+TEST(TypeMatching, MatchesDeucedTemplateSpecializationType) {
+  EXPECT_TRUE(matches("template  class A{ public: A(T) {} }; A a(1);",
+  deducedTemplateSpecializationType(),
+  LanguageMode::Cxx17OrLater));
+}
+
 TEST(TypeMatching, MatchesRecordType) {
   EXPECT_TRUE(matches("class C{}; C c;", recordType()));
   EXPECT_TRUE(matches("struct S{}; S s;",
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -202,6 +202,7 @@
   REGISTER_MATCHER(declStmt);
   REGISTER_MATCHER(declaratorDecl);
   REGISTER_MATCHER(decltypeType);
+  REGISTER_MATCHER(deducedTemplateSpecializationType);
   REGISTER_MATCHER

[PATCH] D73869: [clang][AST] Add an AST matcher for deducedTemplateSpeializationType.

2020-02-03 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbdbdf7482255: [clang][AST] Add an AST matcher for 
deducedTemplateSpeializationType. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73869

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1458,6 +1458,12 @@
   templateSpecializationType()));
 }
 
+TEST(TypeMatching, MatchesDeucedTemplateSpecializationType) {
+  EXPECT_TRUE(matches("template  class A{ public: A(T) {} }; A 
a(1);",
+  deducedTemplateSpecializationType(),
+  LanguageMode::Cxx17OrLater));
+}
+
 TEST(TypeMatching, MatchesRecordType) {
   EXPECT_TRUE(matches("class C{}; C c;", recordType()));
   EXPECT_TRUE(matches("struct S{}; S s;",
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -202,6 +202,7 @@
   REGISTER_MATCHER(declStmt);
   REGISTER_MATCHER(declaratorDecl);
   REGISTER_MATCHER(decltypeType);
+  REGISTER_MATCHER(deducedTemplateSpecializationType);
   REGISTER_MATCHER(defaultStmt);
   REGISTER_MATCHER(dependentSizedArrayType);
   REGISTER_MATCHER(designatedInitExpr);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -6030,6 +6030,21 @@
 extern const AstTypeMatcher
 templateSpecializationType;
 
+/// Matches C++17 deduced template specialization types, e.g. deduced class
+/// template types.
+///
+/// Given
+/// \code
+///   template 
+///   class C { public: C(T); };
+///
+///   C c(123);
+/// \endcode
+/// \c deducedTemplateSpecializationType() matches the type in the declaration
+/// of the variable \c c.
+extern const AstTypeMatcher
+deducedTemplateSpecializationType;
+
 /// Matches types nodes representing unary type transformations.
 ///
 /// Given:
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -1750,6 +1750,20 @@
 
 
 
+MatcherType>deducedTemplateSpecializationTypeMatcherDeducedTemplateSpecializationType>...
+Matches C++17 deduced template 
specialization types, e.g. deduced class
+template types.
+
+Given
+  template 
+  class C { public: C(T); };
+
+  C c(123);
+deducedTemplateSpecializationType() matches the type in the declaration
+of the variable c.
+
+
+
 MatcherType>dependentSizedArrayTypeMatcherDependentSizedArrayType>...
 Matches C++ 
arrays whose size is a value-dependent expression.
 
@@ -3522,7 +3536,7 @@
 
 
 
-MatcherNamedDecl>hasNameconst std::string  Name
+MatcherNamedDecl>hasNameStringRef Name
 Matches NamedDecl nodes 
that have the specified name.
 
 Supports specifying enclosing namespaces or classes by prefixing the name


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1458,6 +1458,12 @@
   templateSpecializationType()));
 }
 
+TEST(TypeMatching, MatchesDeucedTemplateSpecializationType) {
+  EXPECT_TRUE(matches("template  class A{ public: A(T) {} }; A a(1);",
+  deducedTemplateSpecializationType(),
+  LanguageMode::Cxx17OrLater));
+}
+
 TEST(TypeMatching, MatchesRecordType) {
   EXPECT_TRUE(matches("class C{}; C c;", recordType()));
   EXPECT_TRUE(matches("struct S{}; S s;",
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -202,6 +202,7 @@
   REGISTER_MATCHER(declStmt);
   REGISTER_MATCHER(declaratorDecl);
   REGISTER_MATCHER(decltypeType);
+  REGISTER

[clang] cf7e98e - [ARM,MVE] Add intrinsics for vdupq.

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

Author: Simon Tatham
Date: 2020-02-03T11:20:06Z
New Revision: cf7e98e6f7805f4e2693a6dbbd12c10fe06fde70

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

LOG: [ARM,MVE] Add intrinsics for vdupq.

Summary:
The unpredicated case of this is trivial: the clang codegen just makes
a vector splat of the input, and LLVM isel is already prepared to
handle that. For the predicated version, I've generated a `select`
between the same vector splat and the `inactive` input parameter, and
added new Tablegen isel rules to match that pattern into a predicated
`MVE_VDUP` instruction.

Reviewers: dmgreen, MarkMurrayARM, miyuki, ostannard

Reviewed By: dmgreen

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

Tags: #clang, #llvm

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

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

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

Removed: 




diff  --git a/clang/include/clang/Basic/arm_mve.td 
b/clang/include/clang/Basic/arm_mve.td
index ee0ce25bf516..e9ad26a4e88e 100644
--- a/clang/include/clang/Basic/arm_mve.td
+++ b/clang/include/clang/Basic/arm_mve.td
@@ -138,6 +138,15 @@ let params = !listconcat(T.Int16, T.Int32) in {
 (select $pred, (or $v, (splat (Scalar $imm))), $v)>;
 }
 
+let params = T.Usual in {
+  let pnt = PNT_None in
+def vdupq_n: Intrinsic:$s), (splat $s)>;
+
+  defm vdupq: IntrinsicMX<
+  Vector, (args unpromoted:$s, Predicate:$pred),
+  (select $pred, (splat $s), $inactive), 1, "_n", PNT_NType, PNT_None>;
+}
+
 // The bitcasting below is not overcomplicating the IR because while
 // Vector and UVector may be 
diff erent vector types at the C level i.e.
 // vectors of same size signed/unsigned ints. Once they're lowered

diff  --git a/clang/test/CodeGen/arm-mve-intrinsics/dup.c 
b/clang/test/CodeGen/arm-mve-intrinsics/dup.c
new file mode 100644
index ..3bcec9d2549e
--- /dev/null
+++ b/clang/test/CodeGen/arm-mve-intrinsics/dup.c
@@ -0,0 +1,351 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature 
+mve.fp -mfloat-abi hard -fallow-half-arguments-and-returns -O0 
-disable-O0-optnone -S -emit-llvm -o - %s | opt -S -mem2reg -sroa -early-cse | 
FileCheck %s
+// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature 
+mve.fp -mfloat-abi hard -fallow-half-arguments-and-returns -O0 
-disable-O0-optnone -DPOLYMORPHIC -S -emit-llvm -o - %s | opt -S -mem2reg -sroa 
-early-cse | FileCheck %s
+
+#include 
+
+// CHECK-LABEL: @test_vdupq_n_f16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast float [[A_COERCE:%.*]] to i32
+// CHECK-NEXT:[[TMP_0_EXTRACT_TRUNC:%.*]] = trunc i32 [[TMP0]] to i16
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast i16 [[TMP_0_EXTRACT_TRUNC]] to half
+// CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement <8 x half> undef, 
half [[TMP1]], i32 0
+// CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector <8 x half> 
[[DOTSPLATINSERT]], <8 x half> undef, <8 x i32> zeroinitializer
+// CHECK-NEXT:ret <8 x half> [[DOTSPLAT]]
+//
+float16x8_t test_vdupq_n_f16(float16_t a)
+{
+return vdupq_n_f16(a);
+}
+
+// CHECK-LABEL: @test_vdupq_n_f32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement <4 x float> undef, 
float [[A:%.*]], i32 0
+// CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector <4 x float> 
[[DOTSPLATINSERT]], <4 x float> undef, <4 x i32> zeroinitializer
+// CHECK-NEXT:ret <4 x float> [[DOTSPLAT]]
+//
+float32x4_t test_vdupq_n_f32(float32_t a)
+{
+return vdupq_n_f32(a);
+}
+
+// CHECK-LABEL: @test_vdupq_n_s8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement <16 x i8> undef, i8 
[[A:%.*]], i32 0
+// CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector <16 x i8> 
[[DOTSPLATINSERT]], <16 x i8> undef, <16 x i32> zeroinitializer
+// CHECK-NEXT:ret <16 x i8> [[DOTSPLAT]]
+//
+int8x16_t test_vdupq_n_s8(int8_t a)
+{
+return vdupq_n_s8(a);
+}
+
+// CHECK-LABEL: @test_vdupq_n_s16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement <8 x i16> undef, i16 
[[A:%.*]], i32 0
+// CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector <8 x i16> 
[[DOTSPLATINSERT]], <8 x i16> undef, <8 x i32> zeroinitializer
+// CHECK-NEXT:ret <8 x i16> [[DOTSPLAT]]
+//
+int16x8_t test_vdupq_n_s16(int16_t a)
+{
+return vdupq_n_s16(a);
+}
+
+// CHECK-LABEL: @test_vdupq_n_s32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement <4 x i32> undef, i32 
[[A:%.*]], i32 0
+// CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector <4 x i32> 
[[DOTSPLATINSERT]], <4 x i32> u

[PATCH] D73356: [ARM,MVE] Add intrinsics for vdupq.

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

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73356

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

Index: llvm/test/CodeGen/Thumb2/mve-intrinsics/dup.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/mve-intrinsics/dup.ll
@@ -0,0 +1,232 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=thumbv8.1m.main -mattr=+mve.fp -verify-machineinstrs -o - %s | FileCheck %s
+
+define arm_aapcs_vfpcc <8 x half> @test_vdupq_n_f16(float %a.coerce) {
+; CHECK-LABEL: test_vdupq_n_f16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmov r0, s0
+; CHECK-NEXT:vdup.16 q0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %0 = bitcast float %a.coerce to i32
+  %tmp.0.extract.trunc = trunc i32 %0 to i16
+  %1 = bitcast i16 %tmp.0.extract.trunc to half
+  %.splatinsert = insertelement <8 x half> undef, half %1, i32 0
+  %.splat = shufflevector <8 x half> %.splatinsert, <8 x half> undef, <8 x i32> zeroinitializer
+  ret <8 x half> %.splat
+}
+
+define arm_aapcs_vfpcc <4 x float> @test_vdupq_n_f32(float %a) {
+; CHECK-LABEL: test_vdupq_n_f32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmov r0, s0
+; CHECK-NEXT:vdup.32 q0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %.splatinsert = insertelement <4 x float> undef, float %a, i32 0
+  %.splat = shufflevector <4 x float> %.splatinsert, <4 x float> undef, <4 x i32> zeroinitializer
+  ret <4 x float> %.splat
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_vdupq_n_s8(i8 signext %a) {
+; CHECK-LABEL: test_vdupq_n_s8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vdup.8 q0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %.splatinsert = insertelement <16 x i8> undef, i8 %a, i32 0
+  %.splat = shufflevector <16 x i8> %.splatinsert, <16 x i8> undef, <16 x i32> zeroinitializer
+  ret <16 x i8> %.splat
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vdupq_n_s16(i16 signext %a) {
+; CHECK-LABEL: test_vdupq_n_s16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vdup.16 q0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %.splatinsert = insertelement <8 x i16> undef, i16 %a, i32 0
+  %.splat = shufflevector <8 x i16> %.splatinsert, <8 x i16> undef, <8 x i32> zeroinitializer
+  ret <8 x i16> %.splat
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vdupq_n_s32(i32 %a) {
+; CHECK-LABEL: test_vdupq_n_s32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vdup.32 q0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %.splatinsert = insertelement <4 x i32> undef, i32 %a, i32 0
+  %.splat = shufflevector <4 x i32> %.splatinsert, <4 x i32> undef, <4 x i32> zeroinitializer
+  ret <4 x i32> %.splat
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_vdupq_n_u8(i8 zeroext %a) {
+; CHECK-LABEL: test_vdupq_n_u8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vdup.8 q0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %.splatinsert = insertelement <16 x i8> undef, i8 %a, i32 0
+  %.splat = shufflevector <16 x i8> %.splatinsert, <16 x i8> undef, <16 x i32> zeroinitializer
+  ret <16 x i8> %.splat
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vdupq_n_u16(i16 zeroext %a) {
+; CHECK-LABEL: test_vdupq_n_u16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vdup.16 q0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %.splatinsert = insertelement <8 x i16> undef, i16 %a, i32 0
+  %.splat = shufflevector <8 x i16> %.splatinsert, <8 x i16> undef, <8 x i32> zeroinitializer
+  ret <8 x i16> %.splat
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vdupq_n_u32(i32 %a) {
+; CHECK-LABEL: test_vdupq_n_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vdup.32 q0, r0
+; CHECK-NEXT:bx lr
+entry:
+  %.splatinsert = insertelement <4 x i32> undef, i32 %a, i32 0
+  %.splat = shufflevector <4 x i32> %.splatinsert, <4 x i32> undef, <4 x i32> zeroinitializer
+  ret <4 x i32> %.splat
+}
+
+define arm_aapcs_vfpcc <8 x half> @test_vdupq_m_n_f16(<8 x half> %inactive, float %a.coerce, i16 zeroext %p) {
+; CHECK-LABEL: test_vdupq_m_n_f16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmov r1, s4
+; CHECK-NEXT:vmsr p0, r0
+; CHECK-NEXT:vpst
+; CHECK-NEXT:vdupt.16 q0, r1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = bitcast float %a.coerce to i32
+  %tmp.0.extract.trunc = trunc i32 %0 to i16
+  %1 = bitcast i16 %tmp.0.extract.trunc to half
+  %2 = zext i16 %p to i32
+  %3 = tail call <8 x i1> @llvm.arm.mve.pred.i2v.v8i1(i32 %2)
+  %.splatinsert = insertelement <8 x half> undef, half %1, i32 0
+  %.splat = shufflevector <8 x half> %.splatinsert, <8 x half> undef, <8 x i32> zeroinitializer
+  %4 = select <8 x i1> %3, <8 x half> %.splat, <8 x half> %inactive
+  ret <8 x half> %4

[PATCH] D73357: [ARM,MVE] Add intrinsics for v[id]dupq and v[id]wdupq.

2020-02-03 Thread Simon Tatham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf8d4afc49ad2: [ARM,MVE] Add intrinsics for v[id]dupq and 
v[id]wdupq. (authored by simon_tatham).

Changed prior to commit:
  https://reviews.llvm.org/D73357?vs=240207&id=242011#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73357

Files:
  clang/include/clang/Basic/arm_mve.td
  clang/include/clang/Basic/arm_mve_defs.td
  clang/test/CodeGen/arm-mve-intrinsics/idup.c
  clang/test/Sema/arm-mve-immediates.c
  clang/utils/TableGen/MveEmitter.cpp
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp
  llvm/test/CodeGen/Thumb2/mve-intrinsics/idup.ll

Index: llvm/test/CodeGen/Thumb2/mve-intrinsics/idup.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/mve-intrinsics/idup.ll
@@ -0,0 +1,775 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=thumbv8.1m.main -mattr=+mve.fp -verify-machineinstrs -o - %s | FileCheck %s
+
+define arm_aapcs_vfpcc <16 x i8> @test_vidupq_n_u8(i32 %a) {
+; CHECK-LABEL: test_vidupq_n_u8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vidup.u8 q0, r0, #4
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call { <16 x i8>, i32 } @llvm.arm.mve.vidup.v16i8(i32 %a, i32 4)
+  %1 = extractvalue { <16 x i8>, i32 } %0, 0
+  ret <16 x i8> %1
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vidupq_n_u16(i32 %a) {
+; CHECK-LABEL: test_vidupq_n_u16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vidup.u16 q0, r0, #1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call { <8 x i16>, i32 } @llvm.arm.mve.vidup.v8i16(i32 %a, i32 1)
+  %1 = extractvalue { <8 x i16>, i32 } %0, 0
+  ret <8 x i16> %1
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vidupq_n_u32(i32 %a) {
+; CHECK-LABEL: test_vidupq_n_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vidup.u32 q0, r0, #4
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call { <4 x i32>, i32 } @llvm.arm.mve.vidup.v4i32(i32 %a, i32 4)
+  %1 = extractvalue { <4 x i32>, i32 } %0, 0
+  ret <4 x i32> %1
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_vddupq_n_u8(i32 %a) {
+; CHECK-LABEL: test_vddupq_n_u8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vddup.u8 q0, r0, #2
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call { <16 x i8>, i32 } @llvm.arm.mve.vddup.v16i8(i32 %a, i32 2)
+  %1 = extractvalue { <16 x i8>, i32 } %0, 0
+  ret <16 x i8> %1
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vddupq_n_u16(i32 %a) {
+; CHECK-LABEL: test_vddupq_n_u16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vddup.u16 q0, r0, #4
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call { <8 x i16>, i32 } @llvm.arm.mve.vddup.v8i16(i32 %a, i32 4)
+  %1 = extractvalue { <8 x i16>, i32 } %0, 0
+  ret <8 x i16> %1
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vddupq_n_u32(i32 %a) {
+; CHECK-LABEL: test_vddupq_n_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vddup.u32 q0, r0, #2
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call { <4 x i32>, i32 } @llvm.arm.mve.vddup.v4i32(i32 %a, i32 2)
+  %1 = extractvalue { <4 x i32>, i32 } %0, 0
+  ret <4 x i32> %1
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_viwdupq_n_u8(i32 %a, i32 %b) {
+; CHECK-LABEL: test_viwdupq_n_u8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:viwdup.u8 q0, r0, r1, #4
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call { <16 x i8>, i32 } @llvm.arm.mve.viwdup.v16i8(i32 %a, i32 %b, i32 4)
+  %1 = extractvalue { <16 x i8>, i32 } %0, 0
+  ret <16 x i8> %1
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_viwdupq_n_u16(i32 %a, i32 %b) {
+; CHECK-LABEL: test_viwdupq_n_u16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:viwdup.u16 q0, r0, r1, #2
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call { <8 x i16>, i32 } @llvm.arm.mve.viwdup.v8i16(i32 %a, i32 %b, i32 2)
+  %1 = extractvalue { <8 x i16>, i32 } %0, 0
+  ret <8 x i16> %1
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_viwdupq_n_u32(i32 %a, i32 %b) {
+; CHECK-LABEL: test_viwdupq_n_u32:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:viwdup.u32 q0, r0, r1, #8
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call { <4 x i32>, i32 } @llvm.arm.mve.viwdup.v4i32(i32 %a, i32 %b, i32 8)
+  %1 = extractvalue { <4 x i32>, i32 } %0, 0
+  ret <4 x i32> %1
+}
+
+define arm_aapcs_vfpcc <16 x i8> @test_vdwdupq_n_u8(i32 %a, i32 %b) {
+; CHECK-LABEL: test_vdwdupq_n_u8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vdwdup.u8 q0, r0, r1, #4
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call { <16 x i8>, i32 } @llvm.arm.mve.vdwdup.v16i8(i32 %a, i32 %b, i32 4)
+  %1 = extractvalue { <16 x i8>, i32 } %0, 0
+  ret <16 x i8> %1
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vdwdupq_n_u16(i32 %a, i32 %b) {
+; CHECK-LABEL: test_vdwdupq_n_u16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vdwdup.u16 q0, r0, r1, #8
+; CHECK-NEXT:bx lr
+entry:
+  %0 = tail call { <8 x i16>, 

[PATCH] D73786: [ARM,MVE] Fix vreinterpretq in big-endian mode.

2020-02-03 Thread Simon Tatham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG961530fdc9f7: [ARM,MVE] Fix vreinterpretq in big-endian 
mode. (authored by simon_tatham).

Changed prior to commit:
  https://reviews.llvm.org/D73786?vs=241727&id=242012#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73786

Files:
  clang/include/clang/Basic/arm_mve.td
  clang/include/clang/Basic/arm_mve_defs.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/arm-mve-intrinsics/admin.c
  clang/test/CodeGen/arm-mve-intrinsics/reinterpret.c
  llvm/include/llvm/IR/IntrinsicsARM.td
  llvm/lib/Target/ARM/ARMISelLowering.cpp
  llvm/lib/Target/ARM/ARMISelLowering.h
  llvm/lib/Target/ARM/ARMInstrMVE.td
  llvm/test/CodeGen/Thumb2/mve-be.ll

Index: llvm/test/CodeGen/Thumb2/mve-be.ll
===
--- llvm/test/CodeGen/Thumb2/mve-be.ll
+++ llvm/test/CodeGen/Thumb2/mve-be.ll
@@ -295,3 +295,64 @@
   %3 = tail call <4 x i32> asm sideeffect "  VMULLB.s32 $0, $1, $1", "=&w,w"(<4 x i32> %2) #2
   ret <4 x i32> %3
 }
+
+; Test case demonstrating that 'bitcast' reinterprets the memory format of a
+; vector, as if stored and then loaded. So if it has to go between two
+; operations treating a register as having different lane sizes, then in
+; big-endian mode, it has to emit a vrev32.16, which is equivalent to the
+; effect that vstrw.32 followed by vldrh.16 would have.
+define arm_aapcs_vfpcc void @test_bitcast(<4 x i32>* readonly %in, <8 x i16>* %out) {
+; CHECK-LE-LABEL: test_bitcast:
+; CHECK-LE:   @ %bb.0: @ %entry
+; CHECK-LE-NEXT:vldrw.u32 q0, [r0]
+; CHECK-LE-NEXT:vmul.i32 q0, q0, q0
+; CHECK-LE-NEXT:vmul.i16 q0, q0, q0
+; CHECK-LE-NEXT:vstrw.32 q0, [r1]
+; CHECK-LE-NEXT:bx lr
+;
+; CHECK-BE-LABEL: test_bitcast:
+; CHECK-BE:   @ %bb.0: @ %entry
+; CHECK-BE-NEXT:vldrw.u32 q0, [r0]
+; CHECK-BE-NEXT:vmul.i32 q0, q0, q0
+; CHECK-BE-NEXT:vrev32.16 q0, q0
+; CHECK-BE-NEXT:vmul.i16 q0, q0, q0
+; CHECK-BE-NEXT:vstrh.16 q0, [r1]
+; CHECK-BE-NEXT:bx lr
+entry:
+  %vin = load <4 x i32>, <4 x i32>* %in, align 8
+  %vdbl = mul <4 x i32> %vin, %vin
+  %cast = bitcast <4 x i32> %vdbl to <8 x i16>
+  %cdbl = mul <8 x i16> %cast, %cast
+  store <8 x i16> %cdbl, <8 x i16>* %out, align 8
+  ret void
+}
+
+; Similar test case but using the arm.mve.vreinterpretq intrinsic instead,
+; which is defined to reinterpret the in-register format, so it generates no
+; instruction in either endianness.
+define arm_aapcs_vfpcc void @test_vreinterpretq(<4 x i32>* readonly %in, <8 x i16>* %out) {
+; CHECK-LE-LABEL: test_vreinterpretq:
+; CHECK-LE:   @ %bb.0: @ %entry
+; CHECK-LE-NEXT:vldrw.u32 q0, [r0]
+; CHECK-LE-NEXT:vmul.i32 q0, q0, q0
+; CHECK-LE-NEXT:vmul.i16 q0, q0, q0
+; CHECK-LE-NEXT:vstrw.32 q0, [r1]
+; CHECK-LE-NEXT:bx lr
+;
+; CHECK-BE-LABEL: test_vreinterpretq:
+; CHECK-BE:   @ %bb.0: @ %entry
+; CHECK-BE-NEXT:vldrw.u32 q0, [r0]
+; CHECK-BE-NEXT:vmul.i32 q0, q0, q0
+; CHECK-BE-NEXT:vmul.i16 q0, q0, q0
+; CHECK-BE-NEXT:vstrh.16 q0, [r1]
+; CHECK-BE-NEXT:bx lr
+entry:
+  %vin = load <4 x i32>, <4 x i32>* %in, align 8
+  %vdbl = mul <4 x i32> %vin, %vin
+  %cast = call <8 x i16> @llvm.arm.mve.vreinterpretq.v8i16.v4i32(<4 x i32> %vdbl)
+  %cdbl = mul <8 x i16> %cast, %cast
+  store <8 x i16> %cdbl, <8 x i16>* %out, align 8
+  ret void
+}
+
+declare <8 x i16> @llvm.arm.mve.vreinterpretq.v8i16.v4i32(<4 x i32>)
Index: llvm/lib/Target/ARM/ARMInstrMVE.td
===
--- llvm/lib/Target/ARM/ARMInstrMVE.td
+++ llvm/lib/Target/ARM/ARMInstrMVE.td
@@ -3959,9 +3959,23 @@
 // example when moving between rGPR and VPR.P0 as part of predicate vector
 // shuffles. We also sometimes need to cast between different predicate
 // vector types (v4i1<>v8i1, etc.) also as part of lowering vector shuffles.
-
 def predicate_cast : SDNode<"ARMISD::PREDICATE_CAST", SDTUnaryOp>;
 
+// 'vector_reg_cast' is an operation that reinterprets the contents of an MVE
+// vector register as a different vector type, without changing the contents of
+// the register. It differs from 'bitconvert' in that bitconvert reinterprets
+// the _memory_ storage format of the vector, whereas vector_reg_cast
+// reinterprets the _register_ format - and in big-endian, the memory and
+// register formats are different, so they are different operations.
+//
+// For example, 'vector_reg_cast' between v8i16 and v16i8 will map the LSB of
+// the zeroth i16 lane to the zeroth i8 lane, regardless of system endianness,
+// whereas 'bitconvert' will map it to the high byte in big-endian mode,
+// because that's what VSTRH.16 followed by VLDRB.8 would do. So the bitconvert
+// would have to emit a VREV16.8 instruction, whereas the vector_reg_cast emits
+// no code at all if the vector is already in a register.
+

[PATCH] D73869: [clang][AST] Add an AST matcher for deducedTemplateSpeializationType.

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

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

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

{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-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73869



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


[PATCH] D73536: [analyser][taint] Remove taint from symbolic expressions if used in comparisons

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

In D73536#1845031 , @NoQ wrote:

> > Describing value constraints in the taint config file is unfeasible.
>
> This is the only correct way to go, because, as you yourself point out, every 
> sink function (or other use of tainted value) does indeed have different 
> constraint requirements.


Over the last couple months I've been pretty conflicted on config files. While 
I see that it is the correct solution, I also fear that just like attributes, 
they require tedious work to set up and maintain. With that said, its been a 
while since I've evaluated analyses that had taint analysis in the focus, so I 
have no concrete data on whether its worth trying to reduce their count, though 
I suspect they wouldn't show the entire picture, as very few checkers utilize 
taintedness.

> What exactly is preventing you from describing value constraints in the 
> config file?

This sounds like moving, or even worse duplicating the same checks both in a 
tool-specific config file and in the code. I sympathize with this as well:

>   int idx;
>   scanf("%d", &idx);
>   
>   if (idx < 0 || 42 < idx) { // tainted
> return -1;
>   }
>   mySink(idx); // Warning {{Untrusted data is passed to a user-defined sink}}
>   return idx;
> 
> Even though we know at the point of `mySink` is called we know that `idx` is 
> properly constrained, `mySink` will emit warning since `idx` holds tainted 
> value.

This is valid, and I totally see how we can't possibly remove the taint (or in 
other words, prove to the analyzer that we properly checked the value) before 
passing it into a sink (as I understand it).

In summary, I think making decision like this is maybe a bit premature before 
we have some more results. It would be interesting to see what happens on 
larger projects once more checkers utilize taintedness, and act proactively, 
because

> Checking the wrong requirements is a very common source of security issues 
> and we cannot afford destroying our ability to catch them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73536



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


[PATCH] D73834: Update for Clang 10 release notes

2020-02-03 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

Looks good to me, go a head and commit it to the branch.

> Can you cherry-pick c03349e40f21 
>  for 
> D73434 ?

Cherry-picked in 72e9e378c545aadb213e95892d50aa0b1248e018 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73834



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


[PATCH] D73869: [clang][AST] Add an AST matcher for deducedTemplateSpeializationType.

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

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

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

{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-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73869



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


[PATCH] D73873: [clangd] Mechanism to make update debounce responsive to rebuild speed.

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

Currently we delay AST rebuilds by 500ms after each edit, to wait for
further edits. This is a win if a rebuild takes 5s, and a loss if it
takes 50ms.

This patch sets debouncepolicy = clamp(min, ratio * rebuild_time, max).
However it sets min = max = 500ms so there's no policy change or actual
customizability - will do that in a separate patch.

See https://github.com/clangd/clangd/issues/275


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73873

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -23,6 +23,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -208,7 +209,7 @@
   std::atomic CallbackCount(0);
   {
 auto Opts = optsForTest();
-Opts.UpdateDebounce = std::chrono::seconds(1);
+Opts.UpdateDebounce = DebouncePolicy::fixed(std::chrono::seconds(1));
 TUScheduler S(CDB, Opts, captureDiags());
 // FIXME: we could probably use timeouts lower than 1 second here.
 auto Path = testPath("foo.cpp");
@@ -361,7 +362,7 @@
   // Run TUScheduler and collect some stats.
   {
 auto Opts = optsForTest();
-Opts.UpdateDebounce = std::chrono::milliseconds(50);
+Opts.UpdateDebounce = DebouncePolicy::fixed(std::chrono::milliseconds(50));
 TUScheduler S(CDB, Opts, captureDiags());
 
 std::vector Files;
@@ -754,6 +755,32 @@
   EXPECT_THAT(Diagnostics, IsEmpty());
 }
 
+TEST(DebouncePolicy, Compute) {
+  namespace c = std::chrono;
+  std::vector History = {
+  c::seconds(0),
+  c::seconds(5),
+  c::seconds(10),
+  c::seconds(20),
+  };
+  DebouncePolicy Policy;
+  Policy.Min = c::seconds(3);
+  Policy.Max = c::seconds(25);
+  // Call Policy.compute(History) and return seconds as a float.
+  auto Compute = [&](llvm::ArrayRef History) {
+using FloatingSeconds = c::duration;
+return static_cast(Policy.compute(History) / FloatingSeconds(1));
+  };
+  EXPECT_NEAR(10, Compute(History), 0.01) << "(upper) median = 10";
+  Policy.RebuildRatio = 1.5;
+  EXPECT_NEAR(15, Compute(History), 0.01) << "median = 10, ratio = 1.5";
+  Policy.RebuildRatio = 3;
+  EXPECT_NEAR(25, Compute(History), 0.01) << "constrained by max";
+  Policy.RebuildRatio = 0;
+  EXPECT_NEAR(3, Compute(History), 0.01) << "constrained by min";
+  EXPECT_NEAR(25, Compute({}), 0.01) << "no history -> max";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -61,6 +61,28 @@
   unsigned MaxRetainedASTs = 3;
 };
 
+/// Clangd may wait after an update to see if another one comes along.
+/// This is so we rebuild once the user stops typing, not when they start.
+/// The debounce time should be responsive to user preferences and rebuild time.
+/// In the future, we could also consider different types of edits.
+struct DebouncePolicy {
+  using clock = std::chrono::steady_clock;
+
+  /// The minimum time that we always debounce for.
+  /// (Debounce may still be disabled/interrupted if we must build this version)
+  clock::duration Min = /*zero*/ {};
+  /// The maximum time we may debounce for.
+  clock::duration Max = /*zero*/ {};
+  /// Target debounce, as a fraction of file rebuild time.
+  /// e.g. RebuildRatio = 2, recent builds took 200ms => debounce for 400ms.
+  float RebuildRatio = 1;
+
+  /// Compute the time to debounce based on this policy and recent build times.
+  clock::duration compute(llvm::ArrayRef History) const;
+  /// A policy that always returns the same duration, useful for tests.
+  static DebouncePolicy fixed(clock::duration);
+};
+
 struct TUAction {
   enum State {
 Queued,   // The TU is pending in the thread task queue to be built.
@@ -158,7 +180,7 @@
 
 /// Time to wait after an update to see if another one comes along.
 /// This tries to ensure we rebuild once the user stops typing.
-std::chrono::steady_clock::duration UpdateDebounce = /*zero*/ {};
+DebouncePolicy UpdateDebounce;
 
 /// Determines when to keep idle ASTs in memory for future use.
 ASTRetentionPolicy RetentionPolicy;
@@ -273,7 +295,7 @@
   // asynchronously.
   llvm::Optional PreambleTasks;
   llvm::Optional WorkerThreads;
-  std::chrono::st

[PATCH] D73873: [clangd] Mechanism to make update debounce responsive to rebuild speed.

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

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

{icon times-circle color=red} clang-tidy: fail. clang-tidy found 0 errors and 1 
warnings 
.
 1 of them are added as review comments below (why? 
).

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

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


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73873



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


[PATCH] D72304: [OpenMP][OMPIRBuilder] Add Directives (master and critical) to OMPBuilder.

2020-02-03 Thread Fady Ghanim via Phabricator via cfe-commits
fghanim added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72304



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


[PATCH] D73865: [CodeGenModule] Assume dso_local for -fpic -fno-semantic-interposition

2020-02-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: peter.smith, rnk, serge-sans-paille, sfertile.
Herald added subscribers: cfe-commits, luismarques, apazos, sameer.abuasal, 
pzheng, s.egerton, lenary, Jim, jsji, jocewei, PkmX, arphaman, the_o, 
brucehoult, MartinMosbeck, rogfer01, atanasyan, edward-jones, zzheng, jrtc27, 
niosHD, sabuasal, simoncook, johnrusso, rbar, asb, fedor.sergeev, kbarton, 
jvesely, nemanjai, dylanmckay, jyknight, dschuff.
Herald added a reviewer: jfb.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

Clang -fpic defaults to -fno-semantic-interposition (GCC -fpic defaults
to -fsemantic-interposition).
Users need to specify -fsemantic-interposition to get semantic
interposition behavior.

Semantic interposition is currently a best-effort feature. There may
still be some cases where it is not handled well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73865

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CXX/expr/p10-0x.cpp
  clang/test/CodeGen/2006-05-19-SingleEltReturn.c
  clang/test/CodeGen/2008-07-30-implicit-initialization.c
  clang/test/CodeGen/2008-07-31-promotion-of-compound-pointer-arithmetic.c
  clang/test/CodeGen/3dnow-builtins.c
  clang/test/CodeGen/_Bool-conversion.c
  clang/test/CodeGen/aapcs-align.cpp
  clang/test/CodeGen/aapcs64-align.cpp
  clang/test/CodeGen/aarch64-args.cpp
  clang/test/CodeGen/aarch64-branch-protection-attr.c
  clang/test/CodeGen/aarch64-byval-temp.c
  clang/test/CodeGen/aarch64-neon-3v.c
  clang/test/CodeGen/aarch64-neon-across.c
  clang/test/CodeGen/aarch64-neon-dot-product.c
  clang/test/CodeGen/aarch64-neon-extract.c
  clang/test/CodeGen/aarch64-neon-fcvt-intrinsics.c
  clang/test/CodeGen/aarch64-neon-fma.c
  clang/test/CodeGen/aarch64-neon-fp16fml.c
  clang/test/CodeGen/aarch64-neon-ldst-one.c
  clang/test/CodeGen/aarch64-neon-scalar-copy.c
  clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem.c
  clang/test/CodeGen/aarch64-neon-tbl.c
  clang/test/CodeGen/aarch64-neon-vcombine.c
  clang/test/CodeGen/aarch64-neon-vget-hilo.c
  clang/test/CodeGen/aarch64-poly128.c
  clang/test/CodeGen/aarch64-poly64.c
  clang/test/CodeGen/aarch64-tme.cpp
  clang/test/CodeGen/aarch64-varargs.c
  clang/test/CodeGen/aarch64-vpcs.c
  clang/test/CodeGen/address-space.c
  clang/test/CodeGen/alias.c
  clang/test/CodeGen/align-systemz.c
  clang/test/CodeGen/align_value.cpp
  clang/test/CodeGen/alignment.c
  clang/test/CodeGen/alloc-align-attr.c
  clang/test/CodeGen/altivec.c
  clang/test/CodeGen/arc/arguments.c
  clang/test/CodeGen/arc/struct-align.c
  clang/test/CodeGen/arm-aapcs-vfp.c
  clang/test/CodeGen/arm-cc.c
  clang/test/CodeGen/arm-float-helpers.c
  clang/test/CodeGen/arm-fp16-arguments.c
  clang/test/CodeGen/arm-homogenous.c
  clang/test/CodeGen/arm-neon-directed-rounding.c
  clang/test/CodeGen/arm-neon-dot-product.c
  clang/test/CodeGen/arm-neon-fma.c
  clang/test/CodeGen/arm-neon-numeric-maxmin.c
  clang/test/CodeGen/arm-neon-vcvtX.c
  clang/test/CodeGen/arm-pcs.c
  clang/test/CodeGen/arm-varargs.c
  clang/test/CodeGen/arm-vfp16-arguments.c
  clang/test/CodeGen/arm-vfp16-arguments2.cpp
  clang/test/CodeGen/arm64-aapcs-arguments.c
  clang/test/CodeGen/arm64-mte.c
  clang/test/CodeGen/arm_function_epilog.cpp
  clang/test/CodeGen/asm-label.c
  clang/test/CodeGen/assign.c
  clang/test/CodeGen/atomics-inlining.c
  clang/test/CodeGen/attr-msp430.c
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGen/attr-weakref.c
  clang/test/CodeGen/attr-weakref2.c
  clang/test/CodeGen/attr-x86-interrupt.c
  clang/test/CodeGen/attributes.c
  clang/test/CodeGen/avr-builtins.c
  clang/test/CodeGen/avr/attributes/interrupt.c
  clang/test/CodeGen/avr/attributes/signal.c
  clang/test/CodeGen/bitfield-2.c
  clang/test/CodeGen/blocks.c
  clang/test/CodeGen/bool-convert.c
  clang/test/CodeGen/bool-init.c
  clang/test/CodeGen/bool_test.c
  clang/test/CodeGen/builtin-align.c
  clang/test/CodeGen/builtin-constant-p.c
  clang/test/CodeGen/builtin-expect.c
  clang/test/CodeGen/builtin-ms-noop.cpp
  clang/test/CodeGen/builtin-unpredictable.c
  clang/test/CodeGen/builtins-arm.c
  clang/test/CodeGen/builtins-ppc-altivec.c
  clang/test/CodeGen/builtins-ppc-crypto.c
  clang/test/CodeGen/builtins-ppc-htm.c
  clang/test/CodeGen/builtins-ppc-p7.c
  clang/test/CodeGen/builtins-ppc-p8vector.c
  clang/test/CodeGen/builtins-ppc-quadword.c
  clang/test/CodeGen/builtins-ppc-vsx.c
  clang/test/CodeGen/builtins-ppc.c
  clang/test/CodeGen/c11atomics.c
  
clang/test/CodeGen/catch-alignment-assumption-attribute-align_value-on-lvalue.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-align_value-on-paramvar.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  
clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function-two-params.cpp
  
clang/test/CodeGen/catch-alignment-assumption-

[PATCH] D73865: [CodeGenModule] Assume dso_local for -fpic -fno-semantic-interposition

2020-02-03 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

If I've understood correctly this would make LLVM more aggressive for PIC 
relocation models, but perhaps more honest in an inter procedural optimisation 
context? The code changes look fine to me, I'm wondering if we've discussed 
this widely enough with the community to work out how to proceed here. For 
example do we have plan to test -fno-semantic-interposition well enough for it 
to be relied on. The consensus may already exist, and I don't know enough about 
it though.




Comment at: clang/lib/CodeGen/CodeGenModule.cpp:845
 
   // If this is not an executable, don't assume anything is local.
   const auto &CGOpts = CGM.getCodeGenOpts();

I think that this comment needs updating to explain the effect of 
SemanticInterposition, and maybe the clang default.



Comment at: clang/test/CodeGen/aapcs-align.cpp:21
 }
-// CHECK: define void @g0
+// CHECK: define dso_local void @g0
 // CHECK: call void @f0(i32 1, [2 x i32] [i32 6, i32 7]

I initially thought a triple of arm-none-none-eabi (bare-metal for embedded 
systems) would have a relocation model of static and hence should have already 
been dso_local. Thinking about it in more detail the clang-driver will usually 
pass the relocation model to cc1 so by default the driver is assuming PIC. May 
be worth pointing that out in your description.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73865



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


[PATCH] D73865: [CodeGenModule] Assume dso_local for -fpic -fno-semantic-interposition

2020-02-03 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.
Herald added subscribers: wuzish, dexonsmith.

{icon times-circle color=red} Unit tests: fail. 62284 tests passed, 121 failed 
and 839 were skipped.

  failed: Clang.CXX/modules-ts/basic/basic_link/p3.cppm
  failed: Clang.CXX/modules-ts/codegen-basics.cppm
  failed: Clang.CodeGen/arm-aapcs-vfp.c
  failed: Clang.CodeGen/attr-cpuspecific.c
  failed: Clang.CodeGen/attr-target-mv-func-ptrs.c
  failed: Clang.CodeGen/attr-target-mv-va-args.c
  failed: Clang.CodeGenCUDA/address-spaces.cu
  failed: Clang.CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
  failed: Clang.CodeGenCUDA/amdgpu-kernel-attrs.cu
  failed: Clang.CodeGenCUDA/amdgpu-visibility.cu
  failed: Clang.CodeGenCUDA/convergent.cu
  failed: Clang.CodeGenCUDA/cuda-builtin-vars.cu
  failed: Clang.CodeGenCUDA/device-stub.cu
  failed: Clang.CodeGenCUDA/device-var-init.cu
  failed: Clang.CodeGenCUDA/device-vtable.cu
  failed: Clang.CodeGenCUDA/function-overload.cu
  failed: Clang.CodeGenCUDA/kernel-amdgcn.cu
  failed: Clang.CodeGenCUDA/kernel-args.cu
  failed: Clang.CodeGenCUDA/library-builtin.cu
  failed: Clang.CodeGenCUDA/link-device-bitcode.cu
  failed: Clang.CodeGenCUDA/nothrow.cu
  failed: Clang.CodeGenCUDA/propagate-metadata.cu
  failed: Clang.CodeGenCUDA/ptx-kernels.cu
  failed: Clang.CodeGenCUDA/types.cu
  failed: Clang.CodeGenCUDA/usual-deallocators.cu
  failed: 
Clang.CodeGenCXX/attr-exclude_from_explicit_instantiation.dont_assume_extern_instantiation.cpp
  failed: Clang.CodeGenCXX/attr-target-mv-diff-ns.cpp
  failed: Clang.CodeGenCXX/attr-target-mv-member-funcs.cpp
  failed: Clang.CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  failed: Clang.CodeGenCXX/attr-target-mv-overloads.cpp
  failed: Clang.CodeGenCXX/attr.cpp
  failed: Clang.CodeGenCXX/builtin-source-location.cpp
  failed: Clang.CodeGenCXX/conditional-temporaries.cpp
  failed: Clang.CodeGenCXX/const-init-cxx2a.cpp
  failed: Clang.CodeGenCXX/ctor-dtor-alias.cpp
  failed: Clang.CodeGenCXX/cxx0x-initializer-stdinitializerlist-pr12086.cpp
  failed: Clang.CodeGenCXX/cxx0x-initializer-stdinitializerlist-startend.cpp
  failed: Clang.CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
  failed: Clang.CodeGenCXX/cxx11-extern-constexpr.cpp
  failed: Clang.CodeGenCXX/cxx11-initializer-aggregate.cpp
  failed: Clang.CodeGenCXX/cxx11-thread-local-reference.cpp
  failed: Clang.CodeGenCXX/cxx11-thread-local-visibility.cpp
  failed: Clang.CodeGenCXX/cxx1y-variable-template-linkage.cpp
  failed: Clang.CodeGenCXX/cxx1z-inline-variables.cpp
  failed: Clang.CodeGenCXX/explicit-instantiation.cpp
  failed: Clang.CodeGenCXX/inheriting-constructor.cpp
  failed: Clang.CodeGenCXX/member-function-pointers.cpp
  failed: Clang.CodeGenCXX/microsoft-uuidof.cpp
  failed: Clang.CodeGenCXX/no-odr-use.cpp
  failed: Clang.CodeGenCXX/pragma-visibility.cpp
  failed: Clang.CodeGenCXX/regcall.cpp
  failed: Clang.CodeGenCXX/static-data-member.cpp
  failed: Clang.CodeGenCXX/static-init.cpp
  failed: Clang.CodeGenCXX/static-member-variable-explicit-specialization.cpp
  failed: Clang.CodeGenCXX/visibility-inlines-hidden-staticvar.cpp
  failed: Clang.CodeGenCXX/vtable-linkage.cpp
  failed: Clang.CodeGenCXX/x86_64-arguments.cpp
  failed: Clang.CodeGenCoroutines/coro-await-resume-eh.cpp
  failed: Clang.CodeGenCoroutines/coro-await.cpp
  failed: Clang.CodeGenCoroutines/coro-cleanup.cpp
  failed: Clang.CodeGenCoroutines/coro-gro-nrvo.cpp
  failed: Clang.CodeGenCoroutines/coro-params.cpp
  failed: Clang.CodeGenCoroutines/coro-ret-void.cpp
  failed: Clang.CodeGenObjC/assign.m
  failed: Clang.CodeGenObjC/constant-strings.m
  failed: Clang.CodeGenObjC/gnu-exceptions.m
  failed: Clang.CodeGenObjC/gnustep2-proto.m
  failed: Clang.CodeGenObjC/objfw.m
  failed: Clang.CodeGenObjC/property.m
  failed: Clang.CodeGenObjC/stret_lookup.m
  failed: Clang.CodeGenObjCXX/designated-initializers.mm
  failed: Clang.CodeGenObjCXX/objfw-exceptions.mm
  failed: Clang.CodeGenOpenCL/addr-space-struct-arg.cl
  failed: Clang.CodeGenOpenCL/address-spaces-conversions.cl
  failed: Clang.CodeGenOpenCL/amdgcn-automatic-variable.cl
  failed: Clang.CodeGenOpenCL/amdgcn-large-globals.cl
  failed: Clang.CodeGenOpenCL/amdgpu-abi-struct-coerce.cl
  failed: Clang.CodeGenOpenCL/amdgpu-attrs.cl
  failed: Clang.CodeGenOpenCL/amdgpu-call-kernel.cl
  failed: Clang.CodeGenOpenCL/amdgpu-calling-conv.cl
  failed: Clang.CodeGenOpenCL/amdgpu-enqueue-kernel.cl
  failed: Clang.CodeGenOpenCL/amdgpu-nullptr.cl
  failed: Clang.CodeGenOpenCL/as_type.cl
  failed: Clang.CodeGenOpenCL/bool_cast.cl
  failed: Clang.CodeGenOpenCL/cl20-device-side-enqueue.cl
  failed: Clang.CodeGenOpenCL/constant-addr-space-globals.cl
  failed: Clang.CodeGenOpenCL/convergent.cl
  failed: Clang.CodeGenOpenCL/extension-begin.cl
  failed: Clang.CodeGenOpenCL/kernel-arg-info.cl
  failed: Clang.CodeGenOpenCL/kernels-have-spir-cc-by-default.cl
  failed: Clang.CodeGenOpenCL/partial_initializer.cl
  failed: Clang.CodeGenOpenCL/pipe_types.cl
  failed: Clang.CodeGenOpenCL/ptx-calls.cl
  failed: 

[clang] 0ce5773 - [clang] Add a missing change of bdbdf748225525bb18cd0ffeb51c3e713f7b8e1b, fix the buildbot.

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

Author: Haojian Wu
Date: 2020-02-03T13:43:26+01:00
New Revision: 0ce57731da9bf5967d0332b0b1d35790b65007d7

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

LOG: [clang] Add a missing change of bdbdf748225525bb18cd0ffeb51c3e713f7b8e1b, 
fix the buildbot.

Added: 


Modified: 
clang/lib/ASTMatchers/ASTMatchersInternal.cpp

Removed: 




diff  --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index b09ab752719b..03b56fae9038 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -864,6 +864,8 @@ const AstTypeMatcher builtinType;
 const AstTypeMatcher arrayType;
 const AstTypeMatcher complexType;
 const AstTypeMatcher constantArrayType;
+const AstTypeMatcher
+deducedTemplateSpecializationType;
 const AstTypeMatcher dependentSizedArrayType;
 const AstTypeMatcher incompleteArrayType;
 const AstTypeMatcher variableArrayType;



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


Re: [clang] 1f3f8c3 - PR44721: Don't consider overloaded operators for built-in comparisons

2020-02-03 Thread Hans Wennborg via cfe-commits
Yes, go ahead.

On Fri, Jan 31, 2020 at 2:19 AM Richard Smith  wrote:
>
> Hi Hans,
>
> This is a pretty safe bugfix for a new feature in Clang 10. OK for branch?
>
> On Thu, 30 Jan 2020 at 17:17, Richard Smith via cfe-commits 
>  wrote:
>>
>>
>> Author: Richard Smith
>> Date: 2020-01-30T17:16:50-08:00
>> New Revision: 1f3f8c369a5067a132c871f33a955a7feaea8534
>>
>> URL: 
>> https://github.com/llvm/llvm-project/commit/1f3f8c369a5067a132c871f33a955a7feaea8534
>> DIFF: 
>> https://github.com/llvm/llvm-project/commit/1f3f8c369a5067a132c871f33a955a7feaea8534.diff
>>
>> LOG: PR44721: Don't consider overloaded operators for built-in comparisons
>> when building a defaulted comparison.
>>
>> As a convenient way of asking whether `x @ y` is valid and building it,
>> we previouly always performed overload resolution and built an
>> overloaded expression, which would both end up picking a builtin
>> operator candidate when given a non-overloadable type. But that's not
>> quite right, because it can result in our finding a user-declared
>> operator overload, which we should never do when applying operators
>> non-overloadable types.
>>
>> Handle this more correctly: skip overload resolution when building
>> `x @ y` if the operands are not overloadable. But still perform overload
>> resolution (considering only builtin candidates) when checking validity,
>> as we don't have any other good way to ask whether a binary operator
>> expression would be valid.
>>
>> Added:
>>
>>
>> Modified:
>> clang/lib/Sema/SemaDeclCXX.cpp
>> clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
>>
>> Removed:
>>
>>
>>
>> 
>> diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
>> index 814a3c64eeba..65526e4020cf 100644
>> --- a/clang/lib/Sema/SemaDeclCXX.cpp
>> +++ b/clang/lib/Sema/SemaDeclCXX.cpp
>> @@ -7373,7 +7373,14 @@ class DefaultedComparisonAnalyzer
>>  ///   resolution [...]
>>  CandidateSet.exclude(FD);
>>
>> -S.LookupOverloadedBinOp(CandidateSet, OO, Fns, Args);
>> +if (Args[0]->getType()->isOverloadableType())
>> +  S.LookupOverloadedBinOp(CandidateSet, OO, Fns, Args);
>> +else {
>> +  // FIXME: We determine whether this is a valid expression by checking 
>> to
>> +  // see if there's a viable builtin operator candidate for it. That 
>> isn't
>> +  // really what the rules ask us to do, but should give the right 
>> results.
>> +  S.AddBuiltinOperatorCandidates(OO, FD->getLocation(), Args, 
>> CandidateSet);
>> +}
>>
>>  Result R;
>>
>> @@ -7826,10 +7833,14 @@ class DefaultedComparisonSynthesizer
>>return StmtError();
>>
>>  OverloadedOperatorKind OO = FD->getOverloadedOperator();
>> -ExprResult Op = S.CreateOverloadedBinOp(
>> -Loc, BinaryOperator::getOverloadedOpcode(OO), Fns,
>> -Obj.first.get(), Obj.second.get(), /*PerformADL=*/true,
>> -/*AllowRewrittenCandidates=*/true, FD);
>> +BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(OO);
>> +ExprResult Op;
>> +if (Type->isOverloadableType())
>> +  Op = S.CreateOverloadedBinOp(Loc, Opc, Fns, Obj.first.get(),
>> +   Obj.second.get(), /*PerformADL=*/true,
>> +   /*AllowRewrittenCandidates=*/true, FD);
>> +else
>> +  Op = S.CreateBuiltinBinOp(Loc, Opc, Obj.first.get(), 
>> Obj.second.get());
>>  if (Op.isInvalid())
>>return StmtError();
>>
>> @@ -7869,8 +7880,12 @@ class DefaultedComparisonSynthesizer
>>llvm::APInt ZeroVal(S.Context.getIntWidth(S.Context.IntTy), 0);
>>Expr *Zero =
>>IntegerLiteral::Create(S.Context, ZeroVal, S.Context.IntTy, Loc);
>> -  ExprResult Comp = S.CreateOverloadedBinOp(Loc, BO_NE, Fns, 
>> VDRef.get(),
>> -Zero, true, true, FD);
>> +  ExprResult Comp;
>> +  if (VDRef.get()->getType()->isOverloadableType())
>> +Comp = S.CreateOverloadedBinOp(Loc, BO_NE, Fns, VDRef.get(), Zero, 
>> true,
>> +   true, FD);
>> +  else
>> +Comp = S.CreateBuiltinBinOp(Loc, BO_NE, VDRef.get(), Zero);
>>if (Comp.isInvalid())
>>  return StmtError();
>>Sema::ConditionResult Cond = S.ActOnCondition(
>>
>> diff  --git 
>> a/clang/test/CXX/class/class.compare/class.compare.default/p3.cpp 
>> b/clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
>> index 3d0ab2c5bde6..81a48a393a06 100644
>> --- a/clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
>> +++ b/clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
>> @@ -190,3 +190,15 @@ bool operator<(const G&, const G&);
>>  bool operator<=(const G&, const G&);
>>  bool operator>(const G&, const G&);
>>  bool operator>=(const G&, const G&);
>> +
>> +namespace PR44721 {
>> +  template  bool operator==(T const &, T const &) { r

[clang-tools-extra] 6423ae4 - Allow modernize-use-using to apply to enumerations as well.

2020-02-03 Thread Aaron Ballman via cfe-commits

Author: Karasev Nikita
Date: 2020-02-03T07:54:38-05:00
New Revision: 6423ae417e17611c4ee529f5848e839e6d9cb795

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

LOG: Allow modernize-use-using to apply to enumerations as well.

This addresses PR44528.

Added: 

clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-use-using/modernize-use-using.h

Modified: 
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index 164c9fe9bae4..918b4846bf3a 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -25,18 +25,17 @@ void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
 return;
   Finder->addMatcher(typedefDecl(unless(isInstantiated())).bind("typedef"),
  this);
-  // This matcher used to find structs defined in source code within typedefs.
+  // This matcher used to find tag declarations in source code within typedefs.
   // They appear in the AST just *prior* to the typedefs.
-  Finder->addMatcher(cxxRecordDecl(unless(isImplicit())).bind("struct"), this);
+  Finder->addMatcher(tagDecl(unless(isImplicit())).bind("tagdecl"), this);
 }
 
 void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
   // Match CXXRecordDecl only to store the range of the last non-implicit full
   // declaration, to later check whether it's within the typdef itself.
-  const auto *MatchedCxxRecordDecl =
-  Result.Nodes.getNodeAs("struct");
-  if (MatchedCxxRecordDecl) {
-LastCxxDeclRange = MatchedCxxRecordDecl->getSourceRange();
+  const auto *MatchedTagDecl = Result.Nodes.getNodeAs("tagdecl");
+  if (MatchedTagDecl) {
+LastTagDeclRange = MatchedTagDecl->getSourceRange();
 return;
   }
 
@@ -70,9 +69,13 @@ void UseUsingCheck::check(const MatchFinder::MatchResult 
&Result) {
   // consecutive TypedefDecl nodes whose SourceRanges overlap. Each range 
starts
   // at the "typedef" and then continues *across* previous definitions through
   // the end of the current TypedefDecl definition.
+  // But also we need to check that the ranges belong to the same file because
+  // 
diff erent files may contain overlapping ranges.
   std::string Using = "using ";
   if (ReplaceRange.getBegin().isMacroID() ||
-  ReplaceRange.getBegin() >= LastReplacementEnd) {
+  (Result.SourceManager->getFileID(ReplaceRange.getBegin()) !=
+   Result.SourceManager->getFileID(LastReplacementEnd)) ||
+  (ReplaceRange.getBegin() >= LastReplacementEnd)) {
 // This is the first (and possibly the only) TypedefDecl in a typedef. Save
 // Type and Name in case we find subsequent TypedefDecl's in this typedef.
 FirstTypedefType = Type;
@@ -95,11 +98,12 @@ void UseUsingCheck::check(const MatchFinder::MatchResult 
&Result) {
 
   auto Diag = diag(ReplaceRange.getBegin(), UseUsingWarning);
 
-  // If typedef contains a full struct/class declaration, extract its full 
text.
-  if (LastCxxDeclRange.isValid() && 
ReplaceRange.fullyContains(LastCxxDeclRange)) {
+  // If typedef contains a full tag declaration, extract its full text.
+  if (LastTagDeclRange.isValid() &&
+  ReplaceRange.fullyContains(LastTagDeclRange)) {
 bool Invalid;
 Type = std::string(
-Lexer::getSourceText(CharSourceRange::getTokenRange(LastCxxDeclRange),
+Lexer::getSourceText(CharSourceRange::getTokenRange(LastTagDeclRange),
  *Result.SourceManager, getLangOpts(), &Invalid));
 if (Invalid)
   return;

diff  --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
index f1899da7124b..616bc27947cf 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
@@ -23,7 +23,7 @@ class UseUsingCheck : public ClangTidyCheck {
 
   const bool IgnoreMacros;
   SourceLocation LastReplacementEnd;
-  SourceRange LastCxxDeclRange;
+  SourceRange LastTagDeclRange;
   std::string FirstTypedefType;
   std::string FirstTypedefName;
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-use-using/modernize-use-using.h
 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-use-using/modernize-use-using.h
new file mode 100644
index ..c82be21fcf1e
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-use-using/modernize-use-using.h
@@ -0,0 +1,6 @@
+#ifndef MODERNIZE_USE_USING_H
+#define MODERNIZE_

[PATCH] D73090: [clang-tidy] Fix PR#44528 'modernize-use-using and enums'

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

In D73090#1854031 , @f00kat wrote:

> Sorry for my english. Sometimes it's more difficult than bug fixing


It's not a problem at all, that's why we help one another out spotting those 
things! :-)

I've commit on your behalf in 6423ae417e17611c4ee529f5848e839e6d9cb795 





Comment at: clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp:74
   if (ReplaceRange.getBegin().isMacroID() ||
-  ReplaceRange.getBegin() >= LastReplacementEnd) {
+  (Result.SourceManager->getFileID(ReplaceRange.getBegin()) != 
Result.SourceManager->getFileID(LastReplacementEnd)) ||
+  (ReplaceRange.getBegin() >= LastReplacementEnd)) {

f00kat wrote:
> aaron.ballman wrote:
> > Be sure to run clang-format over the patch; this looks well beyond the 
> > usual 80-col limit. You can also drop the unnecessary parens around the sub 
> > expressions.
> > 
> > Also, a comment explaining why this code is needed would help future folks 
> > as would a test case showing what this corrects.
> I left the brackets because they seem to increase readability. Or not? :)
We don't typically use them unless there's a need, but it doesn't harm 
readability to keep them, so this is fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73090



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


[PATCH] D73876: [clang-tidy] Fix a false positive about C++17 deduced class template types in unused-using-decl check.

2020-02-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: gribozavr2.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73876

Files:
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s misc-unused-using-decls %t --
+// -- -fno-delayed-template-parsing -isystem %S/Inputs/
+
+namespace ns {
+
+template  class Foo {
+public:
+  Foo(T);
+};
+// Deduction hint (CTAD)
+template  Foo(T t) -> Foo;
+
+template  class Bar {
+public:
+  Bar(T);
+};
+
+template  class Unused {};
+
+} // namespace ns
+
+using ns::Bar;
+using ns::Foo;
+using ns::Unused; // Unused
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using decl 'Unused' is unused
+// CHECK-FIXES: {{^}}// Unused
+
+void f() {
+  Foo(123);
+  Bar(1);
+}
Index: clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -38,6 +38,13 @@
   *Builder = std::move(Result);
   return Matched;
 }
+
+AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl,
+  clang::ast_matchers::internal::Matcher, DeclMatcher) {
+  if (const auto *TD = Node.getTemplateName().getAsTemplateDecl())
+return DeclMatcher.matches(*TD, Finder, Builder);
+  return false;
+}
 } // namespace
 
 // A function that helps to tell whether a TargetDecl in a UsingDecl will be
@@ -56,6 +63,9 @@
   Finder->addMatcher(loc(enumType(DeclMatcher)), this);
   Finder->addMatcher(loc(recordType(DeclMatcher)), this);
   Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
+  Finder->addMatcher(loc(deducedTemplateSpecializationType(
+ refsToTemplatedDecl(namedDecl().bind("used",
+ this);
   Finder->addMatcher(declRefExpr().bind("used"), this);
   Finder->addMatcher(callExpr(callee(unresolvedLookupExpr().bind("used"))),
  this);


Index: clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s misc-unused-using-decls %t --
+// -- -fno-delayed-template-parsing -isystem %S/Inputs/
+
+namespace ns {
+
+template  class Foo {
+public:
+  Foo(T);
+};
+// Deduction hint (CTAD)
+template  Foo(T t) -> Foo;
+
+template  class Bar {
+public:
+  Bar(T);
+};
+
+template  class Unused {};
+
+} // namespace ns
+
+using ns::Bar;
+using ns::Foo;
+using ns::Unused; // Unused
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using decl 'Unused' is unused
+// CHECK-FIXES: {{^}}// Unused
+
+void f() {
+  Foo(123);
+  Bar(1);
+}
Index: clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -38,6 +38,13 @@
   *Builder = std::move(Result);
   return Matched;
 }
+
+AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl,
+  clang::ast_matchers::internal::Matcher, DeclMatcher) {
+  if (const auto *TD = Node.getTemplateName().getAsTemplateDecl())
+return DeclMatcher.matches(*TD, Finder, Builder);
+  return false;
+}
 } // namespace
 
 // A function that helps to tell whether a TargetDecl in a UsingDecl will be
@@ -56,6 +63,9 @@
   Finder->addMatcher(loc(enumType(DeclMatcher)), this);
   Finder->addMatcher(loc(recordType(DeclMatcher)), this);
   Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
+  Finder->addMatcher(loc(deducedTemplateSpecializationType(
+ refsToTemplatedDecl(namedDecl().bind("used",
+ this);
   Finder->addMatcher(declRefExpr().bind("used"), this);
   Finder->addMatcher(callExpr(callee(unresolvedLookupExpr().bind("used"))),
  this);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73775: [clang-tidy] Cover cases like (b && c && b) in the redundant expression check

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



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp:114
   if (P.a[X++] != P.a[X++]) return 1;
+  if (X && X++ && X) return 1;
 

What do you think about the following?
```
bool foo(int&);
bool bar();

int i;
if (foo(i) && bar() && foo(i)) return 1;
```
I think that this should not be warned on (under the assumption that the 
reference variable can be modified by the call and thus may or may not be 
duplicate), but didn't see a test covering it.

It also brings up an interesting question about what to do if those were 
non-const pointers rather than references, because the data being pointed to 
could be modified as well.

(If you think this should be done separately from this review, that's totally 
fine by me, it looks like it would be an issue with the original code as well.)

One thing that is missing from this review are tests for the overloaded 
operator functionality.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73775



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


[PATCH] D73856: [docu] Improve docu of misc-misplaced-const

2020-02-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

> East const makes the problem more obvious. With west const people were 
> telling me the const is on the wrong side.

I don't see how this makes the problem more obvious and it seems odd to me that 
we'd mix styles in code and prose. I prefer leaving this as a west const.

I have no opinion about `typedef` vs `using` in this spot, but given that the 
check can be used in C as well as C++, `typedef` is slightly more portable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73856



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


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

2020-02-03 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added inline comments.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:639
+void VisitDesignatedInitExpr(const DesignatedInitExpr *DIE) {
+  for (const DesignatedInitExpr::Designator &D : DIE->designators()) {
+if (!D.isFieldDesignator())

sammccall wrote:
> you're breaking after the first one - I think you'd like to report every one 
> instead?
> You'd test this with a DIE like `{ .Foo.Bar = 2 }` where `Foo` has struct 
> type.
> 
> (targetDecl only reports the *last* one, because the Designator can't be a 
> DynTypedNode, but we don't care about that here)
Sorry, I tried to understand this comment but I wasn't able to in the end. 
Could you please elaborate on this?

I'm adding the test cases that I originally thought you meant, but those work 
correctly so I assume I didn't understand what case you were referring to.


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] D72867: [clangd] Support renaming designated initializers

2020-02-03 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 242040.
kbobyrev marked an inline comment as done.
kbobyrev added a comment.

Add tests for nested designated initializers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72867

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

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -440,6 +440,35 @@
 template  class Z> struct Bar { };
 template <> struct Bar<[[Foo]]> {};
   )cpp",
+
+  // Designated initializer.
+  R"cpp(
+struct Bar {
+  int [[Fo^o]];
+};
+Bar bar { .[[^Foo]] = 42 };
+  )cpp",
+
+  // Nested designated initializer.
+  R"cpp(
+struct Baz {
+  int Field;
+};
+struct Bar {
+  Baz [[Fo^o]];
+};
+// FIXME:v selecting here results in renaming Field.
+Bar bar { .[[Foo]].Field = 42 };
+  )cpp",
+  R"cpp(
+struct Baz {
+  int [[Fiel^d]];
+};
+struct Bar {
+  Baz Foo;
+};
+Bar bar { .Foo.[[^Field]] = 42 };
+  )cpp",
   };
   for (llvm::StringRef T : Tests) {
 SCOPED_TRACE(T);
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -1155,7 +1155,41 @@
   )cpp",
"0: targets = {f}\n"
"1: targets = {I::x}\n"
-   "2: targets = {I::setY:}\n"}};
+   "2: targets = {I::setY:}\n"},
+   // Designated initializers.
+   {R"cpp(
+void foo() {
+  struct $0^Foo {
+int $1^Bar;
+  };
+  $2^Foo $3^f { .$4^Bar = 42 };
+}
+)cpp",
+"0: targets = {Foo}, decl\n"
+"1: targets = {foo()::Foo::Bar}, decl\n"
+"2: targets = {Foo}\n"
+"3: targets = {f}, decl\n"
+"4: targets = {foo()::Foo::Bar}\n"},
+   {R"cpp(
+void foo() {
+  struct $0^Baz {
+int $1^Field;
+  };
+  struct $2^Bar {
+$3^Baz $4^Foo;
+  };
+  $5^Bar $6^bar { .$7^Foo.$8^Field = 42 };
+}
+)cpp",
+"0: targets = {Baz}, decl\n"
+"1: targets = {foo()::Baz::Field}, decl\n"
+"2: targets = {Bar}, decl\n"
+"3: targets = {Baz}\n"
+"4: targets = {foo()::Bar::Foo}, decl\n"
+"5: targets = {Bar}\n"
+"6: targets = {bar}, decl\n"
+"7: targets = {foo()::Bar::Foo}\n"
+"8: targets = {foo()::Baz::Field}\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
@@ -668,6 +668,17 @@
   // Select the getter, setter, or @property depending on the call.
   explicitReferenceTargets(DynTypedNode::create(*E), {})});
 }
+
+void VisitDesignatedInitExpr(const DesignatedInitExpr *DIE) {
+  for (const DesignatedInitExpr::Designator &D : DIE->designators()) {
+if (!D.isFieldDesignator())
+  continue;
+Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
+D.getFieldLoc(),
+/*IsDecl=*/false,
+{D.getField()}});
+  }
+}
   };
 
   Visitor V;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72742: Don't assume promotable integers are zero/sign-extended already in x86-64 ABI.

2020-02-03 Thread Emilio Cobos Álvarez via Phabricator via cfe-commits
emilio added a comment.

Could anyone update me with how do they want me to proceed here? Is fixing the 
coercions enough to allow this to land? Do I need to make it target-specific? 
If so, which targets should keep the current behavior?

Another slightly more backwards-compatible alternative (though hacky, arguably) 
is to just not use the zext for optimization purposes in the backend. This 
would be simpler and should keep clang always sign-extending on the caller too, 
for now. We could then after a while, switch to this approach. D71178 
 contains such a patch, for comparison.

Thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72742



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


[PATCH] D73876: [clang-tidy] Fix a false positive about C++17 deduced class template types in unused-using-decl check.

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

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

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

{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-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73876



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


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

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

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

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

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

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


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


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


[clang] eacca48 - [Concepts] Instantiate invented template type parameter type-constraint along with function parameters

2020-02-03 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-02-03T15:47:32+02:00
New Revision: eacca4824463d8b96e2e1c9f8bbf886055218a16

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

LOG: [Concepts] Instantiate invented template type parameter type-constraint 
along with function parameters

We previously instantiated type-constraints of template type parameters along 
with the type parameter itself,
this caused problems when the type-constraints created by abbreviated templates 
refreneced other parameters
in the abbreviated templates.

When encountering a template type parameter with a type constraint, if it is 
implicit, delay instantiation of
the type-constraint until the function parameter which created the invented 
template type parameter is
instantiated.

Added: 
clang/test/SemaTemplate/instantiate-abbreviated-template.cpp

Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index dff336f2ff2d..8c312c9d2c5a 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/PrettyDeclStackTrace.h"
+#include "clang/AST/TypeVisitor.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Stack.h"
 #include "clang/Sema/DeclSpec.h"
@@ -2145,6 +2146,94 @@ void Sema::SubstExceptionSpec(FunctionDecl *New, const 
FunctionProtoType *Proto,
   UpdateExceptionSpec(New, ESI);
 }
 
+namespace {
+
+  struct GetContainedInventedTypeParmVisitor :
+public TypeVisitor {
+using TypeVisitor::Visit;
+
+TemplateTypeParmDecl *Visit(QualType T) {
+  if (T.isNull())
+return nullptr;
+  return Visit(T.getTypePtr());
+}
+// The deduced type itself.
+TemplateTypeParmDecl *VisitTemplateTypeParmType(
+const TemplateTypeParmType *T) {
+  if (!T->getDecl()->isImplicit())
+return nullptr;
+  return T->getDecl();
+}
+
+// Only these types can contain 'auto' types, and subsequently be replaced
+// by references to invented parameters.
+
+TemplateTypeParmDecl *VisitElaboratedType(const ElaboratedType *T) {
+  return Visit(T->getNamedType());
+}
+
+TemplateTypeParmDecl *VisitPointerType(const PointerType *T) {
+  return Visit(T->getPointeeType());
+}
+
+TemplateTypeParmDecl *VisitBlockPointerType(const BlockPointerType *T) {
+  return Visit(T->getPointeeType());
+}
+
+TemplateTypeParmDecl *VisitReferenceType(const ReferenceType *T) {
+  return Visit(T->getPointeeTypeAsWritten());
+}
+
+TemplateTypeParmDecl *VisitMemberPointerType(const MemberPointerType *T) {
+  return Visit(T->getPointeeType());
+}
+
+TemplateTypeParmDecl *VisitArrayType(const ArrayType *T) {
+  return Visit(T->getElementType());
+}
+
+TemplateTypeParmDecl *VisitDependentSizedExtVectorType(
+  const DependentSizedExtVectorType *T) {
+  return Visit(T->getElementType());
+}
+
+TemplateTypeParmDecl *VisitVectorType(const VectorType *T) {
+  return Visit(T->getElementType());
+}
+
+TemplateTypeParmDecl *VisitFunctionProtoType(const FunctionProtoType *T) {
+  return VisitFunctionType(T);
+}
+
+TemplateTypeParmDecl *VisitFunctionType(const FunctionType *T) {
+  return Visit(T->getReturnType());
+}
+
+TemplateTypeParmDecl *VisitParenType(const ParenType *T) {
+  return Visit(T->getInnerType());
+}
+
+TemplateTypeParmDecl *VisitAttributedType(const AttributedType *T) {
+  return Visit(T->getModifiedType());
+}
+
+TemplateTypeParmDecl *VisitMacroQualifiedType(const MacroQualifiedType *T) 
{
+  return Visit(T->getUnderlyingType());
+}
+
+TemplateTypeParmDecl *VisitAdjustedType(const AdjustedType *T) {
+  return Visit(T->getOriginalType());
+}
+
+TemplateTypeParmDecl *VisitPackExpansionType(const PackExpansionType *T) {
+  return Visit(T->getPattern());
+}
+  };
+
+} // namespace
+
 ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
 const MultiLevelTemplateArgumentList &TemplateArgs,
 int indexAdjustment,
@@ -2192,6 +2281,41 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
 return nullptr;
   }
 
+  // In abbreviated templates, TemplateTypeParmDecls with possible
+  // TypeConstraints are created when the parameter list is originally parsed.
+  // The TypeConstraints can therefore reference other functions parameters in
+  // the abbreviated function template, which is why we must instantiate them
+  // here, when the ins

[PATCH] D73873: [clangd] Mechanism to make update debounce responsive to rebuild speed.

2020-02-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

looks good, a few nits.




Comment at: clang-tools-extra/clangd/TUScheduler.cpp:249
+  llvm::SmallVector
+  RebuildTimes; /* GUARDED_BY(Mutex) */
   /// File that ASTWorker is responsible for.

nit: maybe move it after the `Mutex` declaration.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:771
   // e.g. the first keystroke is live until obsoleted by the second.
   // We debounce "maybe-unused" writes, sleeping 500ms in case they become 
dead.
   // But don't delay reads (including updates where diagnostics are needed).

nit: update the stale comment.



Comment at: clang-tools-extra/clangd/TUScheduler.h:66
+/// This is so we rebuild once the user stops typing, not when they start.
+/// The debounce time should be responsive to user preferences and rebuild 
time.
+/// In the future, we could also consider different types of edits.

nit: `should be` sounds like this is something we haven't done yet? maybe add 
`FIXME`?



Comment at: clang-tools-extra/clangd/TUScheduler.h:72
+  /// The minimum time that we always debounce for.
+  /// (Debounce may still be disabled/interrupted if we must build this 
version)
+  clock::duration Min = /*zero*/ {};

nit: this comment in `()` seems to be more related to the `DebouncePolicy`, 
maybe move it around the class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73873



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


[clang] 8c16d8b - Revert "[Concepts] Instantiate invented template type parameter type-constraint along with function parameters"

2020-02-03 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-02-03T16:04:48+02:00
New Revision: 8c16d8b235b997389a26d0ac7efe7840e208bb4d

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

LOG: Revert "[Concepts] Instantiate invented template type parameter 
type-constraint along with function parameters"

This temporarily reverts commit eacca4824463d8b96e2e1c9f8bbf886055218a16, which 
caused some test failures.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 
clang/test/SemaTemplate/instantiate-abbreviated-template.cpp



diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 8c312c9d2c5a..dff336f2ff2d 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -18,7 +18,6 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/PrettyDeclStackTrace.h"
-#include "clang/AST/TypeVisitor.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Stack.h"
 #include "clang/Sema/DeclSpec.h"
@@ -2146,94 +2145,6 @@ void Sema::SubstExceptionSpec(FunctionDecl *New, const 
FunctionProtoType *Proto,
   UpdateExceptionSpec(New, ESI);
 }
 
-namespace {
-
-  struct GetContainedInventedTypeParmVisitor :
-public TypeVisitor {
-using TypeVisitor::Visit;
-
-TemplateTypeParmDecl *Visit(QualType T) {
-  if (T.isNull())
-return nullptr;
-  return Visit(T.getTypePtr());
-}
-// The deduced type itself.
-TemplateTypeParmDecl *VisitTemplateTypeParmType(
-const TemplateTypeParmType *T) {
-  if (!T->getDecl()->isImplicit())
-return nullptr;
-  return T->getDecl();
-}
-
-// Only these types can contain 'auto' types, and subsequently be replaced
-// by references to invented parameters.
-
-TemplateTypeParmDecl *VisitElaboratedType(const ElaboratedType *T) {
-  return Visit(T->getNamedType());
-}
-
-TemplateTypeParmDecl *VisitPointerType(const PointerType *T) {
-  return Visit(T->getPointeeType());
-}
-
-TemplateTypeParmDecl *VisitBlockPointerType(const BlockPointerType *T) {
-  return Visit(T->getPointeeType());
-}
-
-TemplateTypeParmDecl *VisitReferenceType(const ReferenceType *T) {
-  return Visit(T->getPointeeTypeAsWritten());
-}
-
-TemplateTypeParmDecl *VisitMemberPointerType(const MemberPointerType *T) {
-  return Visit(T->getPointeeType());
-}
-
-TemplateTypeParmDecl *VisitArrayType(const ArrayType *T) {
-  return Visit(T->getElementType());
-}
-
-TemplateTypeParmDecl *VisitDependentSizedExtVectorType(
-  const DependentSizedExtVectorType *T) {
-  return Visit(T->getElementType());
-}
-
-TemplateTypeParmDecl *VisitVectorType(const VectorType *T) {
-  return Visit(T->getElementType());
-}
-
-TemplateTypeParmDecl *VisitFunctionProtoType(const FunctionProtoType *T) {
-  return VisitFunctionType(T);
-}
-
-TemplateTypeParmDecl *VisitFunctionType(const FunctionType *T) {
-  return Visit(T->getReturnType());
-}
-
-TemplateTypeParmDecl *VisitParenType(const ParenType *T) {
-  return Visit(T->getInnerType());
-}
-
-TemplateTypeParmDecl *VisitAttributedType(const AttributedType *T) {
-  return Visit(T->getModifiedType());
-}
-
-TemplateTypeParmDecl *VisitMacroQualifiedType(const MacroQualifiedType *T) 
{
-  return Visit(T->getUnderlyingType());
-}
-
-TemplateTypeParmDecl *VisitAdjustedType(const AdjustedType *T) {
-  return Visit(T->getOriginalType());
-}
-
-TemplateTypeParmDecl *VisitPackExpansionType(const PackExpansionType *T) {
-  return Visit(T->getPattern());
-}
-  };
-
-} // namespace
-
 ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
 const MultiLevelTemplateArgumentList &TemplateArgs,
 int indexAdjustment,
@@ -2281,41 +2192,6 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
 return nullptr;
   }
 
-  // In abbreviated templates, TemplateTypeParmDecls with possible
-  // TypeConstraints are created when the parameter list is originally parsed.
-  // The TypeConstraints can therefore reference other functions parameters in
-  // the abbreviated function template, which is why we must instantiate them
-  // here, when the instantiated versions of those referenced parameters are in
-  // scope.
-  if (TemplateTypeParmDecl *TTP =
-  GetContainedInventedTypeParmVisitor().Visit(OldDI->getType())) {
-if (const TypeConstraint *TC = TTP->getTypeConstraint()) {
-  // TODO: Concepts: do not instantiate the constraint (delayed constraint
-  // substitution)
-  const A

[PATCH] D72705: [clang][checkers] Added new checker 'alpha.unix.ErrorReturn'.

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

Please add tests for all the functions in the list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72705



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


[clang] 1ca7403 - [OpenMP][OMPIRBuilder] Add Directives (master and critical) to OMPBuilder.

2020-02-03 Thread Johannes Doerfert via cfe-commits

Author: Fady Ghanim
Date: 2020-02-03T08:44:23-06:00
New Revision: 1ca740387b9bbdc142ac81c8bdd6370a8813e328

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

LOG: [OpenMP][OMPIRBuilder] Add Directives (master and critical) to OMPBuilder.

Add support for Master and Critical directive in the OMPIRBuilder. Both make 
use of a new common interface for emitting inlined OMP regions called 
`emitInlinedRegion` which was added in this patch as well.

Also this patch modifies clang to use the new directives when  
`-fopenmp-enable-irbuilder` commandline option is passed.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/critical_codegen.cpp
clang/test/OpenMP/master_codegen.cpp
llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
llvm/lib/Frontend/OpenMP/OMPConstants.cpp
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index f64efd035dd7..64b9effdb605 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -3130,11 +3130,147 @@ static void emitMaster(CodeGenFunction &CGF, const 
OMPExecutableDirective &S) {
 }
 
 void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) {
+  if (llvm::OpenMPIRBuilder *OMPBuilder = CGM.getOpenMPIRBuilder()) {
+using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
+
+const CapturedStmt *CS = S.getInnermostCapturedStmt();
+const Stmt *MasterRegionBodyStmt = CS->getCapturedStmt();
+
+// TODO: Replace with a generic helper function for finalization
+auto FiniCB = [this](InsertPointTy IP) {
+  CGBuilderTy::InsertPointGuard IPG(Builder);
+  assert(IP.getBlock()->end() != IP.getPoint() &&
+ "OpenMP IR Builder should cause terminated block!");
+
+  llvm::BasicBlock *IPBB = IP.getBlock();
+  llvm::BasicBlock *DestBB = IPBB->getUniqueSuccessor();
+  assert(DestBB && "Finalization block should have one successor!");
+
+  // erase and replace with cleanup branch.
+  IPBB->getTerminator()->eraseFromParent();
+  Builder.SetInsertPoint(IPBB);
+  CodeGenFunction::JumpDest Dest = getJumpDestInCurrentScope(DestBB);
+  EmitBranchThroughCleanup(Dest);
+};
+
+// TODO: Replace with a generic helper function for emitting body
+auto BodyGenCB = [MasterRegionBodyStmt, this](InsertPointTy AllocaIP,
+  InsertPointTy CodeGenIP,
+  llvm::BasicBlock &FiniBB) {
+  // Alloca insertion block should be in the entry block of the containing
+  // function So it expects an empty AllocaIP in which case will reuse the
+  // old alloca insertion point, or a new AllocaIP in the same block as the
+  // old one
+  assert((!AllocaIP.isSet() ||
+  AllocaInsertPt->getParent() == AllocaIP.getBlock()) &&
+ "Insertion point should be in the entry block of containing "
+ "function!");
+  auto OldAllocaIP = AllocaInsertPt;
+  if (AllocaIP.isSet())
+AllocaInsertPt = &*AllocaIP.getPoint();
+  auto OldReturnBlock = ReturnBlock;
+  ReturnBlock = getJumpDestInCurrentScope(&FiniBB);
+
+  llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
+  if (llvm::Instruction *CodeGenIPBBTI = CodeGenIPBB->getTerminator())
+CodeGenIPBBTI->eraseFromParent();
+
+  Builder.SetInsertPoint(CodeGenIPBB);
+
+  EmitStmt(MasterRegionBodyStmt);
+
+  if (Builder.saveIP().isSet())
+Builder.CreateBr(&FiniBB);
+
+  AllocaInsertPt = OldAllocaIP;
+  ReturnBlock = OldReturnBlock;
+};
+CGCapturedStmtInfo CGSI(*CS, CR_OpenMP);
+CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(*this, &CGSI);
+Builder.restoreIP(OMPBuilder->CreateMaster(Builder, BodyGenCB, FiniCB));
+
+return;
+  }
   OMPLexicalScope Scope(*this, S, OMPD_unknown);
   emitMaster(*this, S);
 }
 
 void CodeGenFunction::EmitOMPCriticalDirective(const OMPCriticalDirective &S) {
+  if (llvm::OpenMPIRBuilder *OMPBuilder = CGM.getOpenMPIRBuilder()) {
+using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
+
+const CapturedStmt *CS = S.getInnermostCapturedStmt();
+const Stmt *CriticalRegionBodyStmt = CS->getCapturedStmt();
+const Expr *Hint = nullptr;
+if (const auto *HintClause = S.getSingleClause())
+  Hint = HintClause->getHint();
+
+// TODO: This is slightly 
diff erent from what's currently being done in
+/

[PATCH] D73891: [RISCV] Support experimental/unratified extensions

2020-02-03 Thread Simon Cook via Phabricator via cfe-commits
simoncook created this revision.
simoncook added reviewers: asb, lenary, PaoloS, s.egerton.
Herald added subscribers: cfe-commits, luismarques, apazos, sameer.abuasal, 
pzheng, Jim, benna, psnobl, jocewei, PkmX, rkruppe, the_o, brucehoult, 
MartinMosbeck, rogfer01, edward-jones, zzheng, MaskRay, jrtc27, shiva0217, 
kito-cheng, niosHD, sabuasal, johnrusso, rbar.
Herald added a project: clang.
simoncook added a parent revision: D65649: [RISCV] Add MC encodings and tests 
of the Bit Manipulation extension.

This adds support for enabling experimental/unratified RISC-V ISA
extensions in the -march string in the case where an explicit version
number has been declared, and the -menable-experimental-extensions flag
has been provided.

This follows the design as discussed on the mailing lists in the
following RFC: http://lists.llvm.org/pipermail/llvm-dev/2020-January/138364.html

Since the RISCV ToolChain definition currently rejects any extension
with an explicit version number, the parsing logic has been tweaked to
support this, and to allow standard extensions to have their versions
checked in future patches.

Support for the bitmanip 'b' extension has been added as a first example,
it should be clear how to extend this should vector 'v' land first.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73891

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-arch.c

Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -327,3 +327,22 @@
 // RUN: %clang -target riscv64-unknown-elf -march=rv64i -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
 // RV64-TARGET: "-triple" "riscv64-unknown-unknown-elf"
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ib -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-NOFLAG %s
+// RV32-EXPERIMENTAL-NOFLAG: error: invalid arch name 'rv32ib'
+// RV32-EXPERIMENTAL-NOFLAG: requires '-menable-experimental-extensions'
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ib -menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-NOVERS %s
+// RV32-EXPERIMENTAL-NOVERS: error: invalid arch name 'rv32ib'
+// RV32-EXPERIMENTAL-NOVERS: experimental extension requires explicit version number
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ib0p1 -menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-BADVERS %s
+// RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32ib0p1'
+// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.1 for experimental extension
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ib0p92 -menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-GOODVERS %s
+// RV32-EXPERIMENTAL-GOODVERS: "-target-feature" "+b"
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -47,20 +47,32 @@
   return false;
 }
 
+static bool isExperimentalExtension(StringRef Ext) {
+  // Currently 'b' is the only supported experimental extension
+  if (Ext == "b")
+return true;
+  return false;
+}
+
+static std::pair
+getExperimentalExtensionVersion(StringRef Ext) {
+  if (Ext == "b")
+return {"0", "92"};
+  return {"", ""};
+}
+
 // Extensions may have a version number, and may be separated by
 // an underscore '_' e.g.: rv32i2_m2.
 // Version number is divided into major and minor version numbers,
 // separated by a 'p'. If the minor version is 0 then 'p0' can be
 // omitted from the version string. E.g., rv32i2p0, rv32i2, rv32i2p1.
-static bool getExtensionVersion(const Driver &D, StringRef MArch,
-StringRef Ext, StringRef In,
+static bool getExtensionVersion(const Driver &D, const ArgList &Args,
+StringRef MArch, StringRef Ext, StringRef In,
 std::string &Major, std::string &Minor) {
   Major = std::string(In.take_while(isDigit));
   In = In.substr(Major.size());
-  if (Major.empty())
-return true;
 
-  if (In.consume_front("p")) {
+  if (Major.size() && In.consume_front("p")) {
 Minor = std::string(In.take_while(isDigit));
 In = In.substr(Major.size());
 
@@ -74,7 +86,43 @@
 }
   }
 
-  // TODO: Handle extensions with version number.
+  // If experimental extension, require use of current version number number
+  if (isExperimentalExtension(Ext)) {
+if (!Args.hasArg(options::OPT_menable_experimental_extensions)) {
+  std::string Error =
+  "requires '-menable-experimental-extensions' for experimental extension";
+  D.Diag(diag:

[PATCH] D72304: [OpenMP][OMPIRBuilder] Add Directives (master and critical) to OMPBuilder.

2020-02-03 Thread Johannes Doerfert via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1ca740387b9b: [OpenMP][OMPIRBuilder] Add Directives (master 
and critical) to OMPBuilder. (authored by fghanim, committed by jdoerfert).

Changed prior to commit:
  https://reviews.llvm.org/D72304?vs=238858&id=242060#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72304

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/critical_codegen.cpp
  clang/test/OpenMP/master_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPConstants.cpp
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -613,4 +613,161 @@
   }
 }
 
+TEST_F(OpenMPIRBuilderTest, MasterDirective) {
+  using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
+  OpenMPIRBuilder OMPBuilder(*M);
+  OMPBuilder.initialize();
+  F->setName("func");
+  IRBuilder<> Builder(BB);
+
+  OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
+
+  AllocaInst *PrivAI = nullptr;
+
+  BasicBlock *EntryBB = nullptr;
+  BasicBlock *ExitBB = nullptr;
+  BasicBlock *ThenBB = nullptr;
+
+  auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
+   BasicBlock &FiniBB) {
+if (AllocaIP.isSet())
+  Builder.restoreIP(AllocaIP);
+else
+  Builder.SetInsertPoint(&*(F->getEntryBlock().getFirstInsertionPt()));
+PrivAI = Builder.CreateAlloca(F->arg_begin()->getType());
+Builder.CreateStore(F->arg_begin(), PrivAI);
+
+llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
+llvm::Instruction *CodeGenIPInst = &*CodeGenIP.getPoint();
+EXPECT_EQ(CodeGenIPBB->getTerminator(), CodeGenIPInst);
+
+Builder.restoreIP(CodeGenIP);
+
+// collect some info for checks later
+ExitBB = FiniBB.getUniqueSuccessor();
+ThenBB = Builder.GetInsertBlock();
+EntryBB = ThenBB->getUniquePredecessor();
+
+// simple instructions for body
+Value *PrivLoad = Builder.CreateLoad(PrivAI, "local.use");
+Builder.CreateICmpNE(F->arg_begin(), PrivLoad);
+  };
+
+  auto FiniCB = [&](InsertPointTy IP) {
+BasicBlock *IPBB = IP.getBlock();
+EXPECT_NE(IPBB->end(), IP.getPoint());
+  };
+
+  Builder.restoreIP(OMPBuilder.CreateMaster(Builder, BodyGenCB, FiniCB));
+  Value *EntryBBTI = EntryBB->getTerminator();
+  EXPECT_NE(EntryBBTI, nullptr);
+  EXPECT_TRUE(isa(EntryBBTI));
+  BranchInst *EntryBr = cast(EntryBB->getTerminator());
+  EXPECT_TRUE(EntryBr->isConditional());
+  EXPECT_EQ(EntryBr->getSuccessor(0), ThenBB);
+  EXPECT_EQ(ThenBB->getUniqueSuccessor(), ExitBB);
+  EXPECT_EQ(EntryBr->getSuccessor(1), ExitBB);
+
+  CmpInst *CondInst = cast(EntryBr->getCondition());
+  EXPECT_TRUE(isa(CondInst->getOperand(0)));
+
+  CallInst *MasterEntryCI = cast(CondInst->getOperand(0));
+  EXPECT_EQ(MasterEntryCI->getNumArgOperands(), 2U);
+  EXPECT_EQ(MasterEntryCI->getCalledFunction()->getName(), "__kmpc_master");
+  EXPECT_TRUE(isa(MasterEntryCI->getArgOperand(0)));
+
+  CallInst *MasterEndCI = nullptr;
+  for (auto &FI : *ThenBB) {
+Instruction *cur = &FI;
+if (isa(cur)) {
+  MasterEndCI = cast(cur);
+  if (MasterEndCI->getCalledFunction()->getName() == "__kmpc_end_master")
+break;
+  MasterEndCI = nullptr;
+}
+  }
+  EXPECT_NE(MasterEndCI, nullptr);
+  EXPECT_EQ(MasterEndCI->getNumArgOperands(), 2U);
+  EXPECT_TRUE(isa(MasterEndCI->getArgOperand(0)));
+  EXPECT_EQ(MasterEndCI->getArgOperand(1), MasterEntryCI->getArgOperand(1));
+}
+
+TEST_F(OpenMPIRBuilderTest, CriticalDirective) {
+  using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
+  OpenMPIRBuilder OMPBuilder(*M);
+  OMPBuilder.initialize();
+  F->setName("func");
+  IRBuilder<> Builder(BB);
+
+  OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
+
+  AllocaInst *PrivAI = Builder.CreateAlloca(F->arg_begin()->getType());
+
+  BasicBlock *EntryBB = nullptr;
+
+  auto BodyGenCB = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
+   BasicBlock &FiniBB) {
+// collect some info for checks later
+EntryBB = FiniBB.getUniquePredecessor();
+
+// actual start for bodyCB
+llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
+llvm::Instruction *CodeGenIPInst = &*CodeGenIP.getPoint();
+EXPECT_EQ(CodeGenIPBB->getTerminator(), CodeGenIPInst);
+EXPECT_EQ(EntryBB, CodeGenIPBB);
+
+// body begin
+Builder.restoreIP(CodeGenIP);
+Builder.CreateStore(F->arg_begin(), PrivAI);
+Value *PrivLoad = Builder.CreateLoad(PrivAI, "local.use");
+Builder.CreateICmpNE(F->arg_

[clang] 84959ae - [Concepts] Instantiate invented template type parameter type-constraint along with function parameters

2020-02-03 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-02-03T16:51:49+02:00
New Revision: 84959ae47f447fca9d56a9c61e8c46e993d0387a

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

LOG: [Concepts] Instantiate invented template type parameter type-constraint 
along with function parameters

We previously instantiated type-constraints of template type parameters along 
with the type parameter itself,
this caused problems when the type-constraints created by abbreviated templates 
refreneced other parameters
in the abbreviated templates.

When encountering a template type parameter with a type constraint, if it is 
implicit, delay instantiation of
the type-constraint until the function parameter which created the invented 
template type parameter is
instantiated.

Reland after fixing bug caused by another flow reaching SubstParmVarDecl and 
instantiating the TypeConstraint
a second time.

Added: 
clang/test/SemaTemplate/instantiate-abbreviated-template.cpp

Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index dff336f2ff2d..a9357ede700e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/PrettyDeclStackTrace.h"
+#include "clang/AST/TypeVisitor.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Stack.h"
 #include "clang/Sema/DeclSpec.h"
@@ -2145,6 +2146,94 @@ void Sema::SubstExceptionSpec(FunctionDecl *New, const 
FunctionProtoType *Proto,
   UpdateExceptionSpec(New, ESI);
 }
 
+namespace {
+
+  struct GetContainedInventedTypeParmVisitor :
+public TypeVisitor {
+using TypeVisitor::Visit;
+
+TemplateTypeParmDecl *Visit(QualType T) {
+  if (T.isNull())
+return nullptr;
+  return Visit(T.getTypePtr());
+}
+// The deduced type itself.
+TemplateTypeParmDecl *VisitTemplateTypeParmType(
+const TemplateTypeParmType *T) {
+  if (!T->getDecl()->isImplicit())
+return nullptr;
+  return T->getDecl();
+}
+
+// Only these types can contain 'auto' types, and subsequently be replaced
+// by references to invented parameters.
+
+TemplateTypeParmDecl *VisitElaboratedType(const ElaboratedType *T) {
+  return Visit(T->getNamedType());
+}
+
+TemplateTypeParmDecl *VisitPointerType(const PointerType *T) {
+  return Visit(T->getPointeeType());
+}
+
+TemplateTypeParmDecl *VisitBlockPointerType(const BlockPointerType *T) {
+  return Visit(T->getPointeeType());
+}
+
+TemplateTypeParmDecl *VisitReferenceType(const ReferenceType *T) {
+  return Visit(T->getPointeeTypeAsWritten());
+}
+
+TemplateTypeParmDecl *VisitMemberPointerType(const MemberPointerType *T) {
+  return Visit(T->getPointeeType());
+}
+
+TemplateTypeParmDecl *VisitArrayType(const ArrayType *T) {
+  return Visit(T->getElementType());
+}
+
+TemplateTypeParmDecl *VisitDependentSizedExtVectorType(
+  const DependentSizedExtVectorType *T) {
+  return Visit(T->getElementType());
+}
+
+TemplateTypeParmDecl *VisitVectorType(const VectorType *T) {
+  return Visit(T->getElementType());
+}
+
+TemplateTypeParmDecl *VisitFunctionProtoType(const FunctionProtoType *T) {
+  return VisitFunctionType(T);
+}
+
+TemplateTypeParmDecl *VisitFunctionType(const FunctionType *T) {
+  return Visit(T->getReturnType());
+}
+
+TemplateTypeParmDecl *VisitParenType(const ParenType *T) {
+  return Visit(T->getInnerType());
+}
+
+TemplateTypeParmDecl *VisitAttributedType(const AttributedType *T) {
+  return Visit(T->getModifiedType());
+}
+
+TemplateTypeParmDecl *VisitMacroQualifiedType(const MacroQualifiedType *T) 
{
+  return Visit(T->getUnderlyingType());
+}
+
+TemplateTypeParmDecl *VisitAdjustedType(const AdjustedType *T) {
+  return Visit(T->getOriginalType());
+}
+
+TemplateTypeParmDecl *VisitPackExpansionType(const PackExpansionType *T) {
+  return Visit(T->getPattern());
+}
+  };
+
+} // namespace
+
 ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
 const MultiLevelTemplateArgumentList &TemplateArgs,
 int indexAdjustment,
@@ -2192,6 +2281,46 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
 return nullptr;
   }
 
+  // In abbreviated templates, TemplateTypeParmDecls with possible
+  // TypeConstraints are created when the parameter list is originally parsed.
+  // The TypeConstraints can therefore reference other 

[PATCH] D73742: [Clang][Driver] After default -fintegrated-cc1, fix report_fatal_error no longer generates preprocessed source + reproducer.sh

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

> Evidently I can cut the patch in smaller pieces, let me know.

Yes, I think this would be good. There's a lot going on in this patch, and it 
would be good to separate the simple stuff from the tricky parts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73742



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


[clang] 9dcfc7c - Revert "[OpenMP][OMPIRBuilder] Add Directives (master and critical) to OMPBuilder."

2020-02-03 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2020-02-03T08:59:14-06:00
New Revision: 9dcfc7cd64abb301124cafaa95661b76a1fc5032

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

LOG: Revert "[OpenMP][OMPIRBuilder] Add Directives (master and critical) to 
OMPBuilder."

This reverts commit 1ca740387b9bbdc142ac81c8bdd6370a8813e328.

The bots break [0], investigation is needed.

[0] http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/22899

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/critical_codegen.cpp
clang/test/OpenMP/master_codegen.cpp
llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
llvm/lib/Frontend/OpenMP/OMPConstants.cpp
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 64b9effdb605..f64efd035dd7 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -3130,147 +3130,11 @@ static void emitMaster(CodeGenFunction &CGF, const 
OMPExecutableDirective &S) {
 }
 
 void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) {
-  if (llvm::OpenMPIRBuilder *OMPBuilder = CGM.getOpenMPIRBuilder()) {
-using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
-
-const CapturedStmt *CS = S.getInnermostCapturedStmt();
-const Stmt *MasterRegionBodyStmt = CS->getCapturedStmt();
-
-// TODO: Replace with a generic helper function for finalization
-auto FiniCB = [this](InsertPointTy IP) {
-  CGBuilderTy::InsertPointGuard IPG(Builder);
-  assert(IP.getBlock()->end() != IP.getPoint() &&
- "OpenMP IR Builder should cause terminated block!");
-
-  llvm::BasicBlock *IPBB = IP.getBlock();
-  llvm::BasicBlock *DestBB = IPBB->getUniqueSuccessor();
-  assert(DestBB && "Finalization block should have one successor!");
-
-  // erase and replace with cleanup branch.
-  IPBB->getTerminator()->eraseFromParent();
-  Builder.SetInsertPoint(IPBB);
-  CodeGenFunction::JumpDest Dest = getJumpDestInCurrentScope(DestBB);
-  EmitBranchThroughCleanup(Dest);
-};
-
-// TODO: Replace with a generic helper function for emitting body
-auto BodyGenCB = [MasterRegionBodyStmt, this](InsertPointTy AllocaIP,
-  InsertPointTy CodeGenIP,
-  llvm::BasicBlock &FiniBB) {
-  // Alloca insertion block should be in the entry block of the containing
-  // function So it expects an empty AllocaIP in which case will reuse the
-  // old alloca insertion point, or a new AllocaIP in the same block as the
-  // old one
-  assert((!AllocaIP.isSet() ||
-  AllocaInsertPt->getParent() == AllocaIP.getBlock()) &&
- "Insertion point should be in the entry block of containing "
- "function!");
-  auto OldAllocaIP = AllocaInsertPt;
-  if (AllocaIP.isSet())
-AllocaInsertPt = &*AllocaIP.getPoint();
-  auto OldReturnBlock = ReturnBlock;
-  ReturnBlock = getJumpDestInCurrentScope(&FiniBB);
-
-  llvm::BasicBlock *CodeGenIPBB = CodeGenIP.getBlock();
-  if (llvm::Instruction *CodeGenIPBBTI = CodeGenIPBB->getTerminator())
-CodeGenIPBBTI->eraseFromParent();
-
-  Builder.SetInsertPoint(CodeGenIPBB);
-
-  EmitStmt(MasterRegionBodyStmt);
-
-  if (Builder.saveIP().isSet())
-Builder.CreateBr(&FiniBB);
-
-  AllocaInsertPt = OldAllocaIP;
-  ReturnBlock = OldReturnBlock;
-};
-CGCapturedStmtInfo CGSI(*CS, CR_OpenMP);
-CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(*this, &CGSI);
-Builder.restoreIP(OMPBuilder->CreateMaster(Builder, BodyGenCB, FiniCB));
-
-return;
-  }
   OMPLexicalScope Scope(*this, S, OMPD_unknown);
   emitMaster(*this, S);
 }
 
 void CodeGenFunction::EmitOMPCriticalDirective(const OMPCriticalDirective &S) {
-  if (llvm::OpenMPIRBuilder *OMPBuilder = CGM.getOpenMPIRBuilder()) {
-using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
-
-const CapturedStmt *CS = S.getInnermostCapturedStmt();
-const Stmt *CriticalRegionBodyStmt = CS->getCapturedStmt();
-const Expr *Hint = nullptr;
-if (const auto *HintClause = S.getSingleClause())
-  Hint = HintClause->getHint();
-
-// TODO: This is slightly 
diff erent from what's currently being done in
-// clang. Fix the Int32Ty to IntPtrTy (pointer width size) when everything
-// about typing is final.
-llvm::Value *HintInst = nullptr;
-if (Hint)
-  HintInst =
-  Builder.CreateIntCast(E

[PATCH] D73876: [clang-tidy] Fix a false positive about C++17 deduced class template types in unused-using-decl check.

2020-02-03 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp:10
+};
+// Deduction hint (CTAD)
+template  Foo(T t) -> Foo;

s/hint/guide/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73876



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


[PATCH] D73742: [Clang][Driver] After default -fintegrated-cc1, fix report_fatal_error no longer generates preprocessed source + reproducer.sh

2020-02-03 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

In D73742#1854773 , @hans wrote:

> > Evidently I can cut the patch in smaller pieces, let me know.
>
> Yes, I think this would be good. There's a lot going on in this patch, and it 
> would be good to separate the simple stuff from the tricky parts.


@hans It was only so you can have the big picture. Does it make sense overall?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73742



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


[PATCH] D72304: [OpenMP][OMPIRBuilder] Add Directives (master and critical) to OMPBuilder.

2020-02-03 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert reopened this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

Reverted in 9dcfc7cd64abb301124cafaa95661b76a1fc5032 
 because 
of breakages and warnings:
http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/22899


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72304



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


[PATCH] D72705: [clang][checkers] Added new checker 'alpha.unix.ErrorReturn'.

2020-02-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 242064.
balazske added a comment.

- Bug fixes in the generic code.
- Added new check types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72705

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/ErrorReturnChecker.cpp
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/error-return.c

Index: clang/test/Analysis/error-return.c
===
--- /dev/null
+++ clang/test/Analysis/error-return.c
@@ -0,0 +1,520 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.unix.ErrorReturn -verify %s
+
+#include "Inputs/system-header-simulator.h"
+
+/*
+Functions from CERT ERR33-C that should be checked for error:
+https://wiki.sei.cmu.edu/confluence/display/c/ERR33-C.+Detect+and+handle+standard+library+errors
+
+void *aligned_alloc( size_t alignment, size_t size );
+errno_t asctime_s(char *buf, rsize_t bufsz, const struct tm *time_ptr);
+int at_quick_exit( void (*func)(void) );
+int atexit( void (*func)(void) );
+void* bsearch( const void *key, const void *ptr, size_t count, size_t size,
+   int (*comp)(const void*, const void*) );
+void* bsearch_s( const void *key, const void *ptr, rsize_t count, rsize_t size,
+ int (*comp)(const void *, const void *, void *),
+ void *context );
+wint_t btowc( int c );
+size_t c16rtomb( char * restrict s, char16_t c16, mbstate_t * restrict ps );
+size_t c32rtomb( char * restrict s, char32_t c32, mbstate_t * restrict ps );
+void* calloc( size_t num, size_t size );
+clock_t clock(void);
+int cnd_broadcast( cnd_t *cond );
+int cnd_init( cnd_t* cond );
+int cnd_signal( cnd_t *cond );
+int cnd_timedwait( cnd_t* restrict cond, mtx_t* restrict mutex,
+   const struct timespec* restrict time_point );
+int cnd_wait( cnd_t* cond, mtx_t* mutex );
+errno_t ctime_s(char *buffer, rsize_t bufsz, const time_t *time);
+int fclose( FILE *stream );
+int fflush( FILE *stream );
+int fgetc( FILE *stream );
+int fgetpos( FILE *restrict stream, fpos_t *restrict pos );
+char *fgets( char *restrict str, int count, FILE *restrict stream );
+wint_t fgetwc( FILE *stream );
+FILE *fopen( const char *restrict filename, const char *restrict mode );
+errno_t fopen_s(FILE *restrict *restrict streamptr,
+const char *restrict filename,
+const char *restrict mode);
+int fprintf( FILE *restrict stream, const char *restrict format, ... );
+int fprintf_s(FILE *restrict stream, const char *restrict format, ...);
+int fputc( int ch, FILE *stream );
+int fputs( const char *restrict str, FILE *restrict stream );
+wint_t fputwc( wchar_t ch, FILE *stream );
+int fputws( const wchar_t * restrict str, FILE * restrict stream );
+size_t fread( void *restrict buffer, size_t size, size_t count,
+  FILE *restrict stream );
+FILE *freopen( const char *restrict filename, const char *restrict mode,
+   FILE *restrict stream );
+errno_t freopen_s(FILE *restrict *restrict newstreamptr,
+  const char *restrict filename, const char *restrict mode,
+  FILE *restrict stream);
+int fscanf( FILE *restrict stream, const char *restrict format, ... );
+int fscanf_s(FILE *restrict stream, const char *restrict format, ...);
+int fseek( FILE *stream, long offset, int origin );
+int fsetpos( FILE *stream, const fpos_t *pos );
+long ftell( FILE *stream );
+int fwprintf( FILE *restrict stream,
+  const wchar_t *restrict format, ... );
+int fwprintf_s( FILE *restrict stream,
+const wchar_t *restrict format, ...);
+size_t fwrite( const void *restrict buffer, size_t size, size_t count,
+   FILE *restrict stream ); // more exact error return: < count
+int fwscanf( FILE *restrict stream,
+ const wchar_t *restrict format, ... );
+int fwscanf_s( FILE *restrict stream,
+   const wchar_t *restrict format, ...);
+int getc( FILE *stream );
+int getchar(void);
+char *getenv( const char *name );
+errno_t getenv_s( size_t *restrict len, char *restrict value,
+  rsize_t valuesz, const char *restrict name );
+char *gets_s( char *str, rsize_t n );
+wint_t getwc( FILE *stream );
+wint_t getwchar(void);
+struct tm *gmtime( const time_t *time );
+struct tm *gmtime_s(const time_t *restrict time, struct tm *restrict result);
+struct tm *localtime( const time_t *time );
+struct tm *localtime_s(const time_t *restrict time, struct tm *restrict result);
+void* malloc( size_t size );
+int mblen( const char* s, size_t n );
+size_t mbrlen( const char *restrict s, size_t n, mbstate_t *restrict ps );
+size_t mbrtoc16( char16_t * restrict pc16, const char * restrict s,
+ size_t n, mbstate_t * restrict ps );
+size_t mbrtoc32( char32_t restrict 

[PATCH] D73775: [clang-tidy] Cover cases like (b && c && b) in the redundant expression check

2020-02-03 Thread Alexey Romanov via Phabricator via cfe-commits
alexeyr marked an inline comment as done.
alexeyr added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp:114
   if (P.a[X++] != P.a[X++]) return 1;
+  if (X && X++ && X) return 1;
 

aaron.ballman wrote:
> What do you think about the following?
> ```
> bool foo(int&);
> bool bar();
> 
> int i;
> if (foo(i) && bar() && foo(i)) return 1;
> ```
> I think that this should not be warned on (under the assumption that the 
> reference variable can be modified by the call and thus may or may not be 
> duplicate), but didn't see a test covering it.
> 
> It also brings up an interesting question about what to do if those were 
> non-const pointers rather than references, because the data being pointed to 
> could be modified as well.
> 
> (If you think this should be done separately from this review, that's totally 
> fine by me, it looks like it would be an issue with the original code as 
> well.)
> 
> One thing that is missing from this review are tests for the overloaded 
> operator functionality.
This is actually handled correctly, by the same logic as `(X && X++ && X)`, so 
I don't think it needs a separate test. The drawback is that:

1. it's too conservative, `X && bar() && X` isn't warned on either, because I 
don't know a way to check that `bar()` doesn't have side effects //on `X`// and 
so just test `HasSideEffects` 
(https://stackoverflow.com/questions/60035219/check-which-variables-can-be-side-effected-by-expression-evaluation-in-clang-ast).

2. the original code does have the same issue and I didn't fix it, so `foo(X) 
&& foo(X)` and `X++ && X++` do get a warning. 

I'll add overloaded operator tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73775



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


[PATCH] D73742: [Clang][Driver] After default -fintegrated-cc1, fix report_fatal_error no longer generates preprocessed source + reproducer.sh

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

I think so, but I need to look closer at the CrashRecoveryContext changes, and 
it would help to do that separately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73742



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


[PATCH] D73876: [clang-tidy] Fix a false positive about C++17 deduced class template types in unused-using-decl check.

2020-02-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 242065.
hokein marked an inline comment as done.
hokein added a comment.

address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73876

Files:
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp
@@ -0,0 +1,30 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s misc-unused-using-decls %t -- 
-- -fno-delayed-template-parsing -isystem %S/Inputs/
+
+namespace ns {
+
+template  class Foo {
+public:
+  Foo(T);
+};
+// Deduction guide (CTAD)
+template  Foo(T t) -> Foo;
+
+template  class Bar {
+public:
+  Bar(T);
+};
+
+template  class Unused {};
+
+} // namespace ns
+
+using ns::Bar;
+using ns::Foo;
+using ns::Unused; // Unused
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using decl 'Unused' is unused
+// CHECK-FIXES: {{^}}// Unused
+
+void f() {
+  Foo(123);
+  Bar(1);
+}
Index: clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -38,6 +38,13 @@
   *Builder = std::move(Result);
   return Matched;
 }
+
+AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl,
+  clang::ast_matchers::internal::Matcher, DeclMatcher) {
+  if (const auto *TD = Node.getTemplateName().getAsTemplateDecl())
+return DeclMatcher.matches(*TD, Finder, Builder);
+  return false;
+}
 } // namespace
 
 // A function that helps to tell whether a TargetDecl in a UsingDecl will be
@@ -56,6 +63,9 @@
   Finder->addMatcher(loc(enumType(DeclMatcher)), this);
   Finder->addMatcher(loc(recordType(DeclMatcher)), this);
   Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
+  Finder->addMatcher(loc(deducedTemplateSpecializationType(
+ refsToTemplatedDecl(namedDecl().bind("used",
+ this);
   Finder->addMatcher(declRefExpr().bind("used"), this);
   Finder->addMatcher(callExpr(callee(unresolvedLookupExpr().bind("used"))),
  this);


Index: clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp
@@ -0,0 +1,30 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s misc-unused-using-decls %t -- -- -fno-delayed-template-parsing -isystem %S/Inputs/
+
+namespace ns {
+
+template  class Foo {
+public:
+  Foo(T);
+};
+// Deduction guide (CTAD)
+template  Foo(T t) -> Foo;
+
+template  class Bar {
+public:
+  Bar(T);
+};
+
+template  class Unused {};
+
+} // namespace ns
+
+using ns::Bar;
+using ns::Foo;
+using ns::Unused; // Unused
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using decl 'Unused' is unused
+// CHECK-FIXES: {{^}}// Unused
+
+void f() {
+  Foo(123);
+  Bar(1);
+}
Index: clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -38,6 +38,13 @@
   *Builder = std::move(Result);
   return Matched;
 }
+
+AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl,
+  clang::ast_matchers::internal::Matcher, DeclMatcher) {
+  if (const auto *TD = Node.getTemplateName().getAsTemplateDecl())
+return DeclMatcher.matches(*TD, Finder, Builder);
+  return false;
+}
 } // namespace
 
 // A function that helps to tell whether a TargetDecl in a UsingDecl will be
@@ -56,6 +63,9 @@
   Finder->addMatcher(loc(enumType(DeclMatcher)), this);
   Finder->addMatcher(loc(recordType(DeclMatcher)), this);
   Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
+  Finder->addMatcher(loc(deducedTemplateSpecializationType(
+ refsToTemplatedDecl(namedDecl().bind("used",
+ this);
   Finder->addMatcher(declRefExpr().bind("used"), this);
   Finder->addMatcher(callExpr(callee(unresolvedLookupExpr().bind("used"))),
  this);
___
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-02-03 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3412-3414
+def fsycl : Flag<["-"], "fsycl">, Group,
+  HelpText<"Enable SYCL kernels compilation for device">;
+def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group, 
Flags<[CC1Option]>,

Better to split this into 2 parts: the first for `-fsycl` and the second for 
`-sycl-std=`.


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] D72954: [clang-doc] Improving Markdown Output

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

Fixing build error


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

https://reviews.llvm.org/D72954



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


[PATCH] D72705: [clang][checkers] Added new checker 'alpha.unix.ErrorReturn'.

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

In D72705#1854641 , 
@baloghadamsoftware wrote:

> Please add tests for all the functions in the list.


How to handle the combinatoric explosion in test code?
It is too much code to add all functions to `system-header-simulator.h` and 
then all functions with all cases to the test files.
Even for now, all cases with all kinds of check types can result in too big 
test code.
This is possible only with automatic code generation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72705



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


[PATCH] D72954: [clang-doc] Improving Markdown Output

2020-02-03 Thread Clayton Wilkinson via Phabricator via cfe-commits
Clayton updated this revision to Diff 242066.
Clayton added a comment.

build error fixed.


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

https://reviews.llvm.org/D72954

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/assets/index.js
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -294,8 +294,9 @@
   }
 
   doc::Info *I = Reduced.get().get();
-  auto InfoPath = getInfoOutputFile(OutDirectory, I->Path, I->extractName(),
-"." + Format);
+  auto InfoPath =
+  getInfoOutputFile(OutDirectory, I->getRelativeFilePath(""),
+I->getFileBaseName(), "." + Format);
   if (!InfoPath) {
 llvm::errs() << toString(InfoPath.takeError()) << "\n";
 Error = true;
@@ -304,9 +305,9 @@
   std::error_code FileErr;
   llvm::raw_fd_ostream InfoOS(InfoPath.get(), FileErr,
   llvm::sys::fs::OF_None);
-  if (FileErr != OK) {
-llvm::errs() << "Error opening info file: " << FileErr.message()
- << "\n";
+  if (FileErr) {
+llvm::errs() << "Error opening info file " << InfoPath.get() << ": "
+ << FileErr.message() << "\n";
 return;
   }
 
Index: clang-tools-extra/clang-doc/assets/index.js
===
--- clang-tools-extra/clang-doc/assets/index.js
+++ clang-tools-extra/clang-doc/assets/index.js
@@ -31,7 +31,11 @@
 
 function genLink(Ref, CurrentDirectory) {
   var Path = computeRelativePath(Ref.Path, CurrentDirectory);
-  Path = append(Path, Ref.Name + ".html")
+  if (Ref.RefType == "namespace")
+Path = append(Path, "index.html");
+  else
+Path = append(Path, Ref.Name + ".html")
+
   ANode = document.createElement("a");
   ANode.setAttribute("href", Path);
   var TextNode = document.createTextNode(Ref.Name);
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -135,6 +135,12 @@
   bool mergeable(const Reference &Other);
   void merge(Reference &&I);
 
+  /// Returns the path for this Reference relative to CurrentPath.
+  llvm::SmallString<64> getRelativeFilePath(const StringRef &CurrentPath) const;
+
+  /// Returns the basename that should be used for this Reference.
+  llvm::SmallString<16> getFileBaseName() const;
+
   SymbolID USR = SymbolID(); // Unique identifier for referenced decl
   SmallString<16> Name;  // Name of type (possibly unresolved).
   InfoType RefType = InfoType::IT_default; // Indicates the type of this
@@ -262,6 +268,12 @@
 
   llvm::SmallString<16> extractName() const;
 
+  /// Returns the file path for this Info relative to CurrentPath.
+  llvm::SmallString<64> getRelativeFilePath(const StringRef &CurrentPath) const;
+
+  /// Returns the basename that should be used for this Info.
+  llvm::SmallString<16> getFileBaseName() const;
+
   // Returns a reference to the parent scope (that is, the immediate parent
   // namespace or class in which this decl resides).
   llvm::Expected getEnclosingScope();
Index: clang-tools-extra/clang-doc/Representation.cpp
===
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -114,6 +114,52 @@
   }
 }
 
+static llvm::SmallString<64>
+calculateRelativeFilePath(const InfoType &Type, const StringRef &Path,
+  const StringRef &Name, const StringRef &CurrentPath) {
+  llvm::SmallString<64> FilePath;
+
+  if (CurrentPath != Path) {
+// iterate back to the top
+for (llvm::sys::path::const_iterator I =
+ llvm::sys::path::begin(CurrentPath);
+ I != llvm::sys::path::end(CurrentPath); ++I)
+  llvm::sys::path::append(FilePath, "..");
+llvm::sys::path::append(FilePath, Path);
+  }
+
+  // Namespace references have a Path to the parent namespace, but
+  // the file is actually in the subdirectory for the namespace.
+  if (Type == doc::InfoType::IT_namespace)
+llvm::sys::path::append(FilePath, Name);
+
+  return llvm::sys::path::relative_path(FilePath);
+}
+
+llvm::SmallString<64>
+Reference::getRelativeFilePath(const StringRef &CurrentPath) const {
+  return calculateRelativeFilePath(RefType, Path, Name, CurrentPath);
+}
+
+llvm::SmallString<16> Reference::getFileBaseName() const {
+  if (RefType == InfoType::IT_namespace)
+return

[clang-tools-extra] 7d4c23b - [clang-tidy] Fix a false positive about C++17 deduced class template types in unused-using-decl check.

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

Author: Haojian Wu
Date: 2020-02-03T16:25:10+01:00
New Revision: 7d4c23b349f8d0575304182650850f2594935d7c

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

LOG: [clang-tidy] Fix a false positive about C++17 deduced class template types 
in unused-using-decl check.

Reviewers: gribozavr2

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Added: 
clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp

Modified: 
clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index dafd32ed41c7..96055c29ffa8 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -38,6 +38,13 @@ AST_POLYMORPHIC_MATCHER_P(
   *Builder = std::move(Result);
   return Matched;
 }
+
+AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl,
+  clang::ast_matchers::internal::Matcher, DeclMatcher) {
+  if (const auto *TD = Node.getTemplateName().getAsTemplateDecl())
+return DeclMatcher.matches(*TD, Finder, Builder);
+  return false;
+}
 } // namespace
 
 // A function that helps to tell whether a TargetDecl in a UsingDecl will be
@@ -56,6 +63,9 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder 
*Finder) {
   Finder->addMatcher(loc(enumType(DeclMatcher)), this);
   Finder->addMatcher(loc(recordType(DeclMatcher)), this);
   Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
+  Finder->addMatcher(loc(deducedTemplateSpecializationType(
+ refsToTemplatedDecl(namedDecl().bind("used",
+ this);
   Finder->addMatcher(declRefExpr().bind("used"), this);
   Finder->addMatcher(callExpr(callee(unresolvedLookupExpr().bind("used"))),
  this);

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp
new file mode 100644
index ..ca17e44be8e6
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp
@@ -0,0 +1,30 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s misc-unused-using-decls %t -- 
-- -fno-delayed-template-parsing -isystem %S/Inputs/
+
+namespace ns {
+
+template  class Foo {
+public:
+  Foo(T);
+};
+// Deduction guide (CTAD)
+template  Foo(T t) -> Foo;
+
+template  class Bar {
+public:
+  Bar(T);
+};
+
+template  class Unused {};
+
+} // namespace ns
+
+using ns::Bar;
+using ns::Foo;
+using ns::Unused; // Unused
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using decl 'Unused' is unused
+// CHECK-FIXES: {{^}}// Unused
+
+void f() {
+  Foo(123);
+  Bar(1);
+}



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


[PATCH] D73876: [clang-tidy] Fix a false positive about C++17 deduced class template types in unused-using-decl check.

2020-02-03 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7d4c23b349f8: [clang-tidy] Fix a false positive about C++17 
deduced class template types in… (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73876

Files:
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp
@@ -0,0 +1,30 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s misc-unused-using-decls %t -- 
-- -fno-delayed-template-parsing -isystem %S/Inputs/
+
+namespace ns {
+
+template  class Foo {
+public:
+  Foo(T);
+};
+// Deduction guide (CTAD)
+template  Foo(T t) -> Foo;
+
+template  class Bar {
+public:
+  Bar(T);
+};
+
+template  class Unused {};
+
+} // namespace ns
+
+using ns::Bar;
+using ns::Foo;
+using ns::Unused; // Unused
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using decl 'Unused' is unused
+// CHECK-FIXES: {{^}}// Unused
+
+void f() {
+  Foo(123);
+  Bar(1);
+}
Index: clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -38,6 +38,13 @@
   *Builder = std::move(Result);
   return Matched;
 }
+
+AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl,
+  clang::ast_matchers::internal::Matcher, DeclMatcher) {
+  if (const auto *TD = Node.getTemplateName().getAsTemplateDecl())
+return DeclMatcher.matches(*TD, Finder, Builder);
+  return false;
+}
 } // namespace
 
 // A function that helps to tell whether a TargetDecl in a UsingDecl will be
@@ -56,6 +63,9 @@
   Finder->addMatcher(loc(enumType(DeclMatcher)), this);
   Finder->addMatcher(loc(recordType(DeclMatcher)), this);
   Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
+  Finder->addMatcher(loc(deducedTemplateSpecializationType(
+ refsToTemplatedDecl(namedDecl().bind("used",
+ this);
   Finder->addMatcher(declRefExpr().bind("used"), this);
   Finder->addMatcher(callExpr(callee(unresolvedLookupExpr().bind("used"))),
  this);


Index: clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-unused-using-decls-cxx17.cpp
@@ -0,0 +1,30 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s misc-unused-using-decls %t -- -- -fno-delayed-template-parsing -isystem %S/Inputs/
+
+namespace ns {
+
+template  class Foo {
+public:
+  Foo(T);
+};
+// Deduction guide (CTAD)
+template  Foo(T t) -> Foo;
+
+template  class Bar {
+public:
+  Bar(T);
+};
+
+template  class Unused {};
+
+} // namespace ns
+
+using ns::Bar;
+using ns::Foo;
+using ns::Unused; // Unused
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using decl 'Unused' is unused
+// CHECK-FIXES: {{^}}// Unused
+
+void f() {
+  Foo(123);
+  Bar(1);
+}
Index: clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -38,6 +38,13 @@
   *Builder = std::move(Result);
   return Matched;
 }
+
+AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl,
+  clang::ast_matchers::internal::Matcher, DeclMatcher) {
+  if (const auto *TD = Node.getTemplateName().getAsTemplateDecl())
+return DeclMatcher.matches(*TD, Finder, Builder);
+  return false;
+}
 } // namespace
 
 // A function that helps to tell whether a TargetDecl in a UsingDecl will be
@@ -56,6 +63,9 @@
   Finder->addMatcher(loc(enumType(DeclMatcher)), this);
   Finder->addMatcher(loc(recordType(DeclMatcher)), this);
   Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
+  Finder->addMatcher(loc(deducedTemplateSpecializationType(
+ refsToTemplatedDecl(namedDecl().bind("used",
+ this);
   Finder->addMatcher(declRefExpr().bind("used"), this);
   Finder->addMatcher(callExpr(callee(unresolvedLookupExpr().bind("used"))),
  this);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73876: [clang-tidy] Fix a false positive about C++17 deduced class template types in unused-using-decl check.

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

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

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

{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-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73876



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


[PATCH] D71155: [analyzer] CERT: STR30-C

2020-02-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Let's separate `CStringChecker` improvements into a separate patch and have a 
separate set of tests for it.




Comment at: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp:2097-2098
 
+void CStringChecker::evalCharPtrCommon(CheckerContext &C,
+   const CallExpr *CE) const {
+  CurrentFunctionDescription = "char pointer returning function";

Ok, so this whole thing is trying to evaluate `strchr`-like functions, right? 
I've no idea what it does but the problem is much more trivial that what you're 
trying to do here.

Branch 1:
1. Conjure the offset.
2. Add it to the original pointer (using `evalBinOp`).
3. Bind the result.
Branch 2:
1. Bind null.

And you probably should drop branch 2 completely because usually there's no 
indication that the character may in fact be missing in the string, and i don't 
want more null dereference false alarms. So it's just branch 1.

So the whole function should be 3 lines of code (maybe with a couple line 
breaks).

Well, maybe you should also handle the case where the original pointer is null 
(not sure if it's an immediate UB or not).

This could be improved by actually taking into account the contents of the 
string, but you don't seem to be trying to do this here.



Comment at: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp:2101-2103
+  SValBuilder &SVB = C.getSValBuilder();
+  ProgramStateRef State, StateNull;
+  std::tie(StateNull, State) = C.getState()->assume(SVB.makeNull());

So, like, `StateNull` is the state in which it is assumed that `0` is non-zero 
and `State` is the state in which it is assumed that `0` is zero?

I mean, apart from the naming flip-flop - i can tell you in advance that `0` is 
zero, it's not a matter of assumptions.



Comment at: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp:2127-2128
+  if (const auto *SL = dyn_cast(SrcExpr->IgnoreImpCasts())) {
+const StringRegion *ResultMR =
+C.getStoreManager().getRegionManager().getStringRegion(SL);
+SVal ResultV = loc::MemRegionVal(ResultMR);

This is guaranteed to return the string region that you already have as the 
value of that expression.


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

https://reviews.llvm.org/D71155



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


[PATCH] D73891: [RISCV] Support experimental/unratified extensions

2020-02-03 Thread Simon Cook via Phabricator via cfe-commits
simoncook updated this revision to Diff 242080.
simoncook added a comment.

Don't put option in m_riscv_Features_Group, we don't want it being handled like 
a feature.


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

https://reviews.llvm.org/D73891

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-arch.c

Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -327,3 +327,22 @@
 // RUN: %clang -target riscv64-unknown-elf -march=rv64i -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s
 // RV64-TARGET: "-triple" "riscv64-unknown-unknown-elf"
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ib -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-NOFLAG %s
+// RV32-EXPERIMENTAL-NOFLAG: error: invalid arch name 'rv32ib'
+// RV32-EXPERIMENTAL-NOFLAG: requires '-menable-experimental-extensions'
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ib -menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-NOVERS %s
+// RV32-EXPERIMENTAL-NOVERS: error: invalid arch name 'rv32ib'
+// RV32-EXPERIMENTAL-NOVERS: experimental extension requires explicit version number
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ib0p1 -menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-BADVERS %s
+// RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32ib0p1'
+// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.1 for experimental extension
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ib0p92 -menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-GOODVERS %s
+// RV32-EXPERIMENTAL-GOODVERS: "-target-feature" "+b"
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -47,20 +47,32 @@
   return false;
 }
 
+static bool isExperimentalExtension(StringRef Ext) {
+  // Currently 'b' is the only supported experimental extension
+  if (Ext == "b")
+return true;
+  return false;
+}
+
+static std::pair
+getExperimentalExtensionVersion(StringRef Ext) {
+  if (Ext == "b")
+return {"0", "92"};
+  return {"", ""};
+}
+
 // Extensions may have a version number, and may be separated by
 // an underscore '_' e.g.: rv32i2_m2.
 // Version number is divided into major and minor version numbers,
 // separated by a 'p'. If the minor version is 0 then 'p0' can be
 // omitted from the version string. E.g., rv32i2p0, rv32i2, rv32i2p1.
-static bool getExtensionVersion(const Driver &D, StringRef MArch,
-StringRef Ext, StringRef In,
+static bool getExtensionVersion(const Driver &D, const ArgList &Args,
+StringRef MArch, StringRef Ext, StringRef In,
 std::string &Major, std::string &Minor) {
   Major = std::string(In.take_while(isDigit));
   In = In.substr(Major.size());
-  if (Major.empty())
-return true;
 
-  if (In.consume_front("p")) {
+  if (Major.size() && In.consume_front("p")) {
 Minor = std::string(In.take_while(isDigit));
 In = In.substr(Major.size());
 
@@ -74,7 +86,43 @@
 }
   }
 
-  // TODO: Handle extensions with version number.
+  // If experimental extension, require use of current version number number
+  if (isExperimentalExtension(Ext)) {
+if (!Args.hasArg(options::OPT_menable_experimental_extensions)) {
+  std::string Error =
+  "requires '-menable-experimental-extensions' for experimental extension";
+  D.Diag(diag::err_drv_invalid_riscv_ext_arch_name)
+  << MArch << Error << Ext;
+  return false;
+} else if (Major.empty() && Minor.empty()) {
+  std::string Error =
+  "experimental extension requires explicit version number";
+  D.Diag(diag::err_drv_invalid_riscv_ext_arch_name)
+  << MArch << Error << Ext;
+  return false;
+}
+auto SupportedVers = getExperimentalExtensionVersion(Ext);
+if (Major != SupportedVers.first || Minor != SupportedVers.second) {
+  std::string Error =
+  "unsupported version number " + Major;
+  if (!Minor.empty())
+Error += "." + Minor;
+  Error += " for experimental extension (this compiler supports "
++ SupportedVers.first.str() + "."
++ SupportedVers.second.str() + ")";
+
+  D.Diag(diag::err_drv_invalid_riscv_ext_arch_name)
+  << MArch << Error << Ext;
+  return false;
+}
+return true;
+  }
+
+  // Allow extensions to declare no version number
+  if (Major.empty() && Minor.empty())
+return true;
+
+  //

[PATCH] D71433: [analyzer] CERT: POS34-C

2020-02-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/cert/PutenvWithAutoChecker.cpp:57-58
+bugreporter::trackExpressionValue(Report->getErrorNode(), ArgExpr, 
*Report);
+  } else if (const SymbolRef Sym =
+ ArgV.getAsSymbol()) { // It is a `HeapSpaceRegion`
+Report->addVisitor(allocation_state::getMallocBRVisitor(Sym));

This is impossible because `StackSpaceRegion` and `HeapSpaceRegion` do not 
overlap and above you checked that it's the former.



Comment at: clang/test/Analysis/cert/pos34-c.cpp:6
+// Examples from the CERT rule's page.
+// 
https://wiki.sei.cmu.edu/confluence/display/c/POS34-C.+Do+not+call+putenv%28%29+with+a+pointer+to+an+automatic+variable+as+the+argument
+

Btw - CERT has minified links!

{F11286962}

{F11286963}


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

https://reviews.llvm.org/D71433



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


[PATCH] D71553: [RISCV] Add Clang frontend support for Bitmanip extension

2020-02-03 Thread Simon Cook via Phabricator via cfe-commits
simoncook updated this revision to Diff 242082.
simoncook added a comment.

Rebase changes on top of experimental feature support (D73891 
)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71553

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/test/Preprocessor/riscv-target-features.c


Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -7,6 +7,7 @@
 // CHECK-NOT: __riscv_mul
 // CHECK-NOT: __riscv_muldiv
 // CHECK-NOT: __riscv_compressed
+// CHECK-NOT: __riscv_bitmanip
 // CHECK-NOT: __riscv_flen
 // CHECK-NOT: __riscv_fdiv
 // CHECK-NOT: __riscv_fsqrt
@@ -48,6 +49,12 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s
 // CHECK-C-EXT: __riscv_compressed 1
 
+// RUN: %clang -target riscv32-unknown-linux-gnu 
-menable-experimental-extensions -march=rv32ib0p92 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu 
-menable-experimental-extensions -march=rv64ib0p92 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
+// CHECK-B-EXT: __riscv_bitmanip 1
+
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ifd -mabi=ilp32 -x 
c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-SOFT %s
 // RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ifd -mabi=lp64 -x 
c -E -dM %s \
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -30,11 +30,12 @@
   bool HasF;
   bool HasD;
   bool HasC;
+  bool HasB;
 
 public:
   RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
   : TargetInfo(Triple), HasM(false), HasA(false), HasF(false),
-HasD(false), HasC(false) {
+HasD(false), HasC(false), HasB(false) {
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::IEEEquad();
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -125,6 +125,10 @@
 
   if (HasC)
 Builder.defineMacro("__riscv_compressed");
+
+  if (HasB) {
+Builder.defineMacro("__riscv_bitmanip");
+  }
 }
 
 /// Return true if has this feature, need to sync with handleTargetFeatures.
@@ -139,6 +143,7 @@
   .Case("f", HasF)
   .Case("d", HasD)
   .Case("c", HasC)
+  .Case("b", HasB)
   .Default(false);
 }
 
@@ -156,6 +161,8 @@
   HasD = true;
 else if (Feature == "+c")
   HasC = true;
+else if (Feature == "+b")
+  HasB = true;
   }
 
   return true;


Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -7,6 +7,7 @@
 // CHECK-NOT: __riscv_mul
 // CHECK-NOT: __riscv_muldiv
 // CHECK-NOT: __riscv_compressed
+// CHECK-NOT: __riscv_bitmanip
 // CHECK-NOT: __riscv_flen
 // CHECK-NOT: __riscv_fdiv
 // CHECK-NOT: __riscv_fsqrt
@@ -48,6 +49,12 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s
 // CHECK-C-EXT: __riscv_compressed 1
 
+// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32ib0p92 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64ib0p92 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
+// CHECK-B-EXT: __riscv_bitmanip 1
+
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ifd -mabi=ilp32 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-SOFT %s
 // RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ifd -mabi=lp64 -x c -E -dM %s \
Index: clang/lib/Basic/Targets/RISCV.h
===
--- clang/lib/Basic/Targets/RISCV.h
+++ clang/lib/Basic/Targets/RISCV.h
@@ -30,11 +30,12 @@
   bool HasF;
   bool HasD;
   bool HasC;
+  bool HasB;
 
 public:
   RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
   : TargetInfo(Triple), HasM(false), HasA(false), HasF(false),
-HasD(false), HasC(false) {
+HasD(false), HasC(false), HasB(false) {
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::IEEEquad();
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -125,6 +125,10 @@
 
   if (HasC)
 Builder.defi

[PATCH] D72901: [OpenMP] [DOCS] Update OMP5.0 feature status table [NFC]

2020-02-03 Thread Kelvin Li via Phabricator via cfe-commits
kkwli0 added a comment.

Ping


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

https://reviews.llvm.org/D72901



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


[PATCH] D73520: [analyzer] BugReporterVisitors: Refactor and documentation

2020-02-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h:195
+
+  static const char *getTag() { return "FindLastStore"; }
+

Charusso wrote:
> I have made every tag a small-string.
This way it's harder to be sure that the tags are unique. And non-unique tags 
may cause terrible pain while debugging.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h:203
+ID.AddBoolean(EnableNullFPSuppression);
+  }
 };

Charusso wrote:
> I have put every Profile into the header, so it is easier to see which 
> members are not added to the Profile. I think the root cause of 
> https://bugs.llvm.org/show_bug.cgi?id=42938 could be some issue with 
> differentiating between visitors.
I like this!


Repository:
  rC Clang

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

https://reviews.llvm.org/D73520



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


[PATCH] D73897: [analyzer] StdLibraryFunctionsChecker refactor: remove macros

2020-02-03 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added a reviewer: NoQ.
Herald added subscribers: cfe-commits, Charusso, gamesh411, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, 
xazax.hun, whisperity.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73897

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

Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -160,15 +160,29 @@
   /// The complete list of ranges that defines a single branch.
   typedef std::vector ValueRangeSet;
 
+  using ArgTypesTy = std::vector;
+  using RetTypeTy = QualType;
+  using RangesTy = std::vector;
+
   /// Includes information about function prototype (which is necessary to
   /// ensure we're modeling the right function and casting values properly),
   /// approach to invalidation, and a list of branches - essentially, a list
   /// of list of ranges - essentially, a list of lists of lists of segments.
   struct FunctionSummaryTy {
-const std::vector ArgTypes;
-const QualType RetType;
+const ArgTypesTy ArgTypes;
+const RetTypeTy RetType;
 const InvalidationKindTy InvalidationKind;
-const std::vector Ranges;
+RangesTy Ranges;
+
+FunctionSummaryTy(ArgTypesTy ArgTypes, RetTypeTy RetType,
+  InvalidationKindTy InvalidationKind)
+: ArgTypes(ArgTypes), RetType(RetType),
+  InvalidationKind(InvalidationKind) {}
+
+FunctionSummaryTy &Specification(ValueRangeSet VRS) {
+  Ranges.push_back(VRS);
+  return *this;
+}
 
   private:
 static void assertTypeSuitableForSummary(QualType T) {
@@ -517,538 +531,286 @@
   //
   // Please update the list of functions in the header after editing!
   //
-  // The format is as follows:
+
+  // Below are helper functions to create the summaries.
   //
+  // The format is as follows:
   //{ "function name",
-  //  { spec:
+  //  { variant0:
   //{ argument types list, ... },
-  //return type, purity, { range set list:
+  //return type, purity, { specification list:
   //  { range list:
   //{ argument index, within or out of, {{from, to}, ...} },
   //{ argument index, compares to argument, {{how, which}} },
   //...
   //  }
   //}
+  //  },
+  //  { variant1:
+  //...
   //  }
   //}
+  using Summary = FunctionSummaryTy;
+  auto ArgumentCondition = [](ArgNoTy ArgNo, ValueRangeKindTy Kind,
+  IntRangeVectorTy Ranges) -> ValueRange {
+ValueRange VR{ArgNo, Kind, Ranges};
+return VR;
+  };
+  auto ReturnValueCondition = [](ValueRangeKindTy Kind,
+ IntRangeVectorTy Ranges) -> ValueRange {
+ValueRange VR{Ret, Kind, Ranges};
+return VR;
+  };
+  auto Range = [](RangeIntTy b, RangeIntTy e) {
+return IntRangeVectorTy{std::pair{b, e}};
+  };
+  auto SingleValue = [](RangeIntTy v) {
+return IntRangeVectorTy{std::pair{v, v}};
+  };
+  auto IsLessThan = [](ArgNoTy ArgNo) {
+return IntRangeVectorTy{{BO_LE, ArgNo}};
+  };
 
-#define SUMMARY_WITH_VARIANTS(identifier) {#identifier, {
-#define END_SUMMARY_WITH_VARIANTS }},
-#define VARIANT(argument_types, return_type, invalidation_approach)\
-  { argument_types, return_type, invalidation_approach, {
-#define END_VARIANT } },
-#define SUMMARY(identifier, argument_types, return_type,   \
-invalidation_approach) \
-  { #identifier, { { argument_types, return_type, invalidation_approach, {
-#define END_SUMMARY } } } },
-#define ARGUMENT_TYPES(...) { __VA_ARGS__ }
-#define RETURN_TYPE(x) x
-#define INVALIDATION_APPROACH(x) x
-#define CASE {
-#define END_CASE },
-#define ARGUMENT_CONDITION(argument_number, condition_kind)\
-  { argument_number, condition_kind, {
-#define END_ARGUMENT_CONDITION }},
-#define RETURN_VALUE_CONDITION(condition_kind) \
-  { Ret, condition_kind, {
-#define END_RETURN_VALUE_CONDITION }},
-#define ARG_NO(x) x##U
-#define RANGE(x, y) { x, y },
-#define SINGLE_VALUE(x) RANGE(x, x)
-#define IS_LESS_THAN(arg) { BO_LE, arg }
+  // Templates for summaries that are reused by many functions.
+  auto GetcT = [&]() {
+return Summary(ArgTypesTy{Irrelevant}, RetTypeTy(IntTy), NoEvalCall)
+.Specification({ReturnValueCondition(WithinRange, Range(-1, 255))});
+  };
+  auto ReadT = [&](RetTypeTy R, RangeIntTy Max) {
+return Summary(ArgTypesTy{Irrelevant, Irrelevant, SizeTy}, RetTypeTy(R),
+   NoEvalCall)
+.Specification({ReturnValueCondition(ComparesToArgument, IsLessThan(2)),
+ReturnValueCondition(WithinR

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

2020-02-03 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added a reviewer: NoQ.
Herald added subscribers: cfe-commits, Charusso, gamesh411, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, 
xazax.hun, whisperity.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73898

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c

Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- /dev/null
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -0,0 +1,22 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -triple x86_64-unknown-linux-gnu
+
+void clang_analyzer_eval(int);
+
+int glob;
+
+typedef struct FILE FILE;
+#define EOF -1
+
+int isalnum(int);
+void test_alnum_concrete() {
+  int ret = isalnum(256); // expected-warning{{Function argument constraint is not satisfied}}
+  (void)ret;
+}
+void test_alnum_symbolic(int x) {
+  int ret = isalnum(x);
+  (void)ret;
+  clang_analyzer_eval(EOF <= x && x <= 255); // expected-warning{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -51,6 +51,7 @@
 //===--===//
 
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
@@ -60,7 +61,8 @@
 using namespace clang::ento;
 
 namespace {
-class StdLibraryFunctionsChecker : public Checker {
+class StdLibraryFunctionsChecker
+: public Checker {
   /// Below is a series of typedefs necessary to define function specs.
   /// We avoid nesting types here because each additional qualifier
   /// would need to be repeated in every function spec.
@@ -142,6 +144,10 @@
 applyAsComparesToArgument(ProgramStateRef State, const CallEvent &Call,
   const FunctionSummaryTy &Summary) const;
 
+void checkAsWithinRange(ProgramStateRef State, const CallEvent &Call,
+const FunctionSummaryTy &Summary, const BugType &BT,
+CheckerContext &C) const;
+
   public:
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
   const FunctionSummaryTy &Summary) const {
@@ -155,6 +161,21 @@
   }
   llvm_unreachable("Unknown ValueRange kind!");
 }
+
+void check(ProgramStateRef State, const CallEvent &Call,
+   const FunctionSummaryTy &Summary, const BugType &BT,
+   CheckerContext &C) const {
+  switch (Kind) {
+  case OutOfRange:
+llvm_unreachable("Not implemented yet!");
+  case WithinRange:
+checkAsWithinRange(State, Call, Summary, BT, C);
+return;
+  case ComparesToArgument:
+llvm_unreachable("Not implemented yet!");
+  }
+  llvm_unreachable("Unknown ValueRange kind!");
+}
   };
 
   /// The complete list of ranges that defines a single branch.
@@ -164,15 +185,21 @@
   using RetTypeTy = QualType;
   using RangesTy = std::vector;
 
-  /// Includes information about function prototype (which is necessary to
-  /// ensure we're modeling the right function and casting values properly),
-  /// approach to invalidation, and a list of branches - essentially, a list
-  /// of list of ranges - essentially, a list of lists of lists of segments.
+  /// Includes information about
+  ///   * function prototype (which is necessary to
+  /// ensure we're modeling the right function and casting values properly),
+  ///   * approach to invalidation,
+  ///   * a list of branches - a list of list of ranges -
+  /// i.e. a list of lists of lists of segments,
+  ///   * a list of argument constraints, that must be true on every branch.
+  /// If these constraints are not satisfied that means a fatal error
+  /// usually resulting in undefined behaviour.
   struct FunctionSummaryTy {
 const ArgTypesTy ArgTypes;
 const RetTypeTy RetType;
 const InvalidationKindTy InvalidationKind;
 RangesTy Ranges;
+ValueRangeSet ArgConstraints;
 
 FunctionSummaryTy(ArgTypesTy ArgTypes, RetTypeTy RetType,
   InvalidationKindTy InvalidationKind)
@@ -183,6 +210,10 @@
   Ranges.push_back(VRS);
   return *this;
 }
+FunctionSummaryTy &ArgConstraint(ValueRange VR) {
+  ArgConstraint

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

2020-02-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Other than the packaging debate, i think this check looks good!




Comment at: clang/include/clang/StaticAnalyzer/Checkers/Checkers.td:641
 
-} // end: "optin.cplusplus"
-
-let ParentPackage = CplusplusAlpha in {
-
-def ContainerModeling : Checker<"ContainerModeling">,
-  HelpText<"Models C++ containers">,
-  Documentation,
-  Hidden;
-
-def DeleteWithNonVirtualDtorChecker : Checker<"DeleteWithNonVirtualDtor">,
-  HelpText<"Reports destructions of polymorphic objects with a non-virtual "
-   "destructor in their base class">,
-  Documentation;
-
-def EnumCastOutOfRangeChecker : Checker<"EnumCastOutOfRange">,
-  HelpText<"Check integer to enumeration casts for out of range values">,
-  Documentation;
-
-def IteratorModeling : Checker<"IteratorModeling">,
-  HelpText<"Models iterators of C++ containers">,
+def STLAlgorithmModeling : Checker<"STLAlgorithmModeling">,
+  HelpText<"Models the algorithm library of the C++ STL.">,

STL algorithm modeling, as such, doesn't need to be opt-in.

That said, as i mentioned, i strongly prefer the state split on `std::find` to 
be opt-in, because there's usually no obvious indication in the code that the 
search is expected to fail.

Let's move the checker to `cplusplus` and add an option to it ("aggressive 
std::find modeling" or something like that) that'll enable exploration of the 
failure branch. I prefer it as an option because there definitely is a chance 
that we'll actually want it on by default (like we did with the move-checker 
for locals - it's still wonky but it seems to work really well in practice), 
and if we do that, i'd prefer not to have to rename a checker.



Comment at: clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp:27-32
+  mutable IdentifierInfo *II_find = nullptr, *II_find_end = nullptr,
+ *II_find_first_of = nullptr, *II_find_if = nullptr,
+ *II_find_if_not = nullptr, *II_lower_bound = nullptr,
+ *II_upper_bound = nullptr, *II_search = nullptr,
+ *II_search_n = nullptr;
+

Dead code?



Comment at: clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp:126
+  // assume that in case of successful search the position of the found element
+  // is ahed of it.
+  const auto *Pos = getIteratorPosition(State, SecondParam);

Typo: *ahead.



Comment at: clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp:138-139
+  SVB.getConditionType());
+assert(Less.getAs() &&
+   "Symbol comparison must be a `DefinedSVal`");
+StateFound = StateFound->assume(Less.castAs(), true);

Is this because you only have atomic conjured symbols in your map? Because 
otherwise the assertion will fail every time we reach a maximum symbol 
complexity during `evalBinOp`.

I'd rather make the code defensive and handle the `UnknownVal` case. That said, 
you can be sure it's not `UndefinedVal`.


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

https://reviews.llvm.org/D70818



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


[PATCH] D72901: [OpenMP] [DOCS] Update OMP5.0 feature status table [NFC]

2020-02-03 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/docs/OpenMPSupport.rst:194
 
+--+--+--+---+
-| device extension | requires directive (unified shared memory)
   | :good:`done` | 
  |
+| device extension | requires directive
   | :good:`done` | 
  |
 
+--+--+--+---+

jdoerfert wrote:
> kkwli0 wrote:
> > jdoerfert wrote:
> > > ABataev wrote:
> > > > We have support only for unified memory, so must be `partial`
> > > Let's keep the explicit ` (unified shared memory) -> done ` line and add 
> > > one for the others as not done.
> > @abataev It makes sense to make it `partial`.
> > 
> > @jdoerfert  Keeping that line can be confusing.  Line 196 is clear to 
> > indicate that the unified_address and unified_shared_memory parts of the 
> > requires directive is done.
> Fair point. thx.
As far as I understand we only support parsing/sema for `unified_address`.



Comment at: clang/docs/OpenMPSupport.rst:216
 
+--+--+--+---+
+| device extension | pointer attachment
   | :none:`unclaimed`| 
  |
++--+--+--+---+

kkwli0 wrote:
> jdoerfert wrote:
> > ABataev wrote:
> > > Is this for Fortran?
> > No also C/C++.
> Yep, it is not Fortran only.  We clarify some pointer attachment behavior in 
> 5.0.
Could add a reference to the section in the standard?



Comment at: clang/docs/OpenMPSupport.rst:238
 
+--+--+--+---+
-| misc extensions  | pointer/reference to pointer based array 
reductions  | :none:`unclaimed`|
   |
+| misc extension   | pointer/reference to pointer based array 
reductions  | :none:`unclaimed`|
   |
++--+--+--+---+

Could you add a reference to the standard?


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

https://reviews.llvm.org/D72901



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


[PATCH] D73720: [Analyzer] Use note tags to track container begin and and changes

2020-02-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Also, yay, thanks for using the new API!




Comment at: clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp:41
 const SVal &OldCont = UndefinedVal()) const;
-  void handleAssign(CheckerContext &C, const SVal &Cont) const;
-  void handleClear(CheckerContext &C, const SVal &Cont) const;
-  void handlePushBack(CheckerContext &C, const SVal &Cont) const;
-  void handlePopBack(CheckerContext &C, const SVal &Cont) const;
-  void handlePushFront(CheckerContext &C, const SVal &Cont) const;
-  void handlePopFront(CheckerContext &C, const SVal &Cont) const;
+  void handleAssign(CheckerContext &C, const SVal &Cont,
+   const Expr *ContE) const;

While we're at it, let's not pass `SVal`s by reference? They're small 
value-types by design.


Repository:
  rC Clang

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

https://reviews.llvm.org/D73720



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


[PATCH] D73720: [Analyzer] Use note tags to track container begin and and changes

2020-02-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp:731
+  }
+  return C.getNoteTag([Text, Name](BugReport &BR) -> std::string {
+  SmallString<256> Msg;

You'll need to check whether the container is actually of interest to the bug 
report. We don't want notes to be added about changes to irrelevant containers.

You can use a combination of "Report `BR` was emitted by one of the iterator 
checkers" and "The memory region of the container is marked as interesting" 
(while also actually marking it as interesting in the checker).

Ideally we should instead make a new generic storage inside the `BugReport` 
object, in order to pass down the interesting information from the call site of 
`emitReport` ("Hi, i'm an iterator checker who emitted this report and i'm 
interested in changes made to the size of this container").


Repository:
  rC Clang

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

https://reviews.llvm.org/D73720



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


[PATCH] D71830: [OpenMP][Part 2] Use reusable OpenMP context/traits handling

2020-02-03 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

Had a quick look today. Will spend some more time tomorrow.
Please see a few comments inline.




Comment at: clang/include/clang/AST/OpenMPClause.h:6429
+/// and an ordered collection of properties.
+struct OpenMPTraitInfo {
+  struct OpenMPTraitProperty {

Not clear from this file what should be named starting with OMP or OpenMP. I 
see more classes/structs strating with OMP.



Comment at: clang/include/clang/Serialization/ASTRecordReader.h:272
+
+  template <> OpenMPTraitInfo *readUserType() { return readOpenMPTraitInfo(); }
+

Compiler throws up this error.
error: explicit specialization in non-namespace scope ‘class 
clang::ASTRecordReader’



Comment at: clang/include/clang/Serialization/ASTRecordWriter.h:277
+
+  template <> void writeUserType(OpenMPTraitInfo *TI) {
+writeOpenMPTraitInfo(TI);

Compiler throws up this error.
error: explicit specialization in non-namespace scope ‘class 
clang::ASTRecordWriter’



Comment at: clang/lib/Parse/ParseOpenMP.cpp:853
+llvm::omp::TraitSelector Selector, llvm::StringMap &Seen) {
+  const unsigned Lvl = 2;
+  TIProperty.Kind = TraitProperty::invalid;

Would it be better to add the value of this variable also to the name? Like 
Lvl_TWO or something? Same question for the 5 other const Lvl variables in this 
patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71830



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


[PATCH] D69781: [analyzer] Add test directory for scan-build

2020-02-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ reopened this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

I'll try to re-land this. I heard there were a lot more issues than just 
honoring `CLANG_INSTALL_SCANBUILD=NO` (which i'll do my best to test before 
pushing), so i'll monitor the buildbots carefully and try to unbreak everything 
quickly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69781



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


[PATCH] D71830: [OpenMP][Part 2] Use reusable OpenMP context/traits handling

2020-02-03 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert marked 4 inline comments as done.
jdoerfert added a comment.

In D71830#1854989 , @kiranchandramohan 
wrote:

> Had a quick look today. Will spend some more time tomorrow.
>  Please see a few comments inline.


Thanks! I'll rebase asap to address your comments.




Comment at: clang/include/clang/AST/OpenMPClause.h:6429
+/// and an ordered collection of properties.
+struct OpenMPTraitInfo {
+  struct OpenMPTraitProperty {

kiranchandramohan wrote:
> Not clear from this file what should be named starting with OMP or OpenMP. I 
> see more classes/structs strating with OMP.
I will go for OMP everywhere.



Comment at: clang/include/clang/Serialization/ASTRecordReader.h:272
+
+  template <> OpenMPTraitInfo *readUserType() { return readOpenMPTraitInfo(); }
+

kiranchandramohan wrote:
> Compiler throws up this error.
> error: explicit specialization in non-namespace scope ‘class 
> clang::ASTRecordReader’
Oh, my compiler was happy. Let me rebase and see what the pre-merge bots say so 
I might get some insight into the problem.



Comment at: clang/include/clang/Serialization/ASTRecordWriter.h:277
+
+  template <> void writeUserType(OpenMPTraitInfo *TI) {
+writeOpenMPTraitInfo(TI);

kiranchandramohan wrote:
> Compiler throws up this error.
> error: explicit specialization in non-namespace scope ‘class 
> clang::ASTRecordWriter’
Same as above I guess.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:853
+llvm::omp::TraitSelector Selector, llvm::StringMap &Seen) {
+  const unsigned Lvl = 2;
+  TIProperty.Kind = TraitProperty::invalid;

kiranchandramohan wrote:
> Would it be better to add the value of this variable also to the name? Like 
> Lvl_TWO or something? Same question for the 5 other const Lvl variables in 
> this patch.
Yes, that would be better. Will fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71830



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


[PATCH] D73900: [BPF] use base lvalue type for preserve_{struct,union}_access_index metadata

2020-02-03 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song created this revision.
yonghong-song added reviewers: ast, anakryiko.
Herald added subscribers: cfe-commits, arphaman.
Herald added a project: clang.

Linux commit

  
https://github.com/torvalds/linux/commit/1cf5b23988ea0086a252a5c8b005b075f1e9b030#diff-289313b9fec99c6f0acfea19d9cfd949

uses "#pragma clang attribute push (__attribute__((preserve_access_index)),

  apply_to = record)"

to apply CO-RE relocations to all records including the following pattern:

  #pragma clang attribute push (__attribute__((preserve_access_index)), 
apply_to = record)
  typedef struct {
int a;
  } __t;
  #pragma clang attribute pop 
  int test(__t *arg) { return arg->a; }

The current approach to use struct type in the relocation record will
result in an anonymous struct, which make later type matching difficult

  in bpf loader. In fact, current BPF backend will fail the above program

with assertion:

  clang: ../lib/Target/BPF/BPFAbstractMemberAccess.cpp:796: ... 
 Assertion `TypeName.size()' failed.

The patch use the base lvalue type for the "base" value to annotate
preservee_{struct,union}_access_index intrinsics. In the above example,
the type will be "__t" which preserved the type name.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73900

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/builtin-preserve-access-index-typedef.c


Index: clang/test/CodeGen/builtin-preserve-access-index-typedef.c
===
--- /dev/null
+++ clang/test/CodeGen/builtin-preserve-access-index-typedef.c
@@ -0,0 +1,24 @@
+// REQUIRES: bpf-registered-target
+// RUN: %clang -target bpf -emit-llvm -S -g %s -o - | FileCheck %s
+
+#pragma clang attribute push (__attribute__((preserve_access_index)), apply_to 
= record)
+typedef struct {
+   int a;
+} __t;
+typedef union {
+   int b;
+} __u;
+#pragma clang attribute pop
+
+int test1(__t *arg) { return arg->a; }
+int test2(const __u *arg) { return arg->b; }
+
+
+// CHECK: define dso_local i32 @test1
+// CHECK: call i32* 
@llvm.preserve.struct.access.index.p0i32.p0s_struct.__ts(%struct.__t* 
%{{[0-9a-z]+}}, i32 0, i32 0), !dbg !{{[0-9]+}}, !llvm.preserve.access.index 
![[TYPEDEF_STRUCT:[0-9]+]]
+// CHECK: define dso_local i32 @test2
+// CHECK: call %union.__u* 
@llvm.preserve.union.access.index.p0s_union.__us.p0s_union.__us(%union.__u* 
%{{[0-9a-z]+}}, i32 0), !dbg !{{[0-9]+}}, !llvm.preserve.access.index 
![[CONST_TYPEDEF:[0-9]+]]
+//
+// CHECK: ![[TYPEDEF_STRUCT]] = !DIDerivedType(tag: DW_TAG_typedef, name: "__t"
+// CHECK: ![[CONST_TYPEDEF]] = !DIDerivedType(tag: DW_TAG_const_type, 
baseType: ![[TYPEDEF_UNION:[0-9]+]]
+// CHECK: ![[TYPEDEF_UNION]] = !DIDerivedType(tag: DW_TAG_typedef, name: "__u"
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -4024,17 +4024,17 @@
   return CGF.Builder.CreateStructGEP(base, idx, field->getName());
 }
 
-static Address emitPreserveStructAccess(CodeGenFunction &CGF, Address base,
-const FieldDecl *field) {
+static Address emitPreserveStructAccess(CodeGenFunction &CGF, LValue base,
+Address addr, const FieldDecl *field) {
   const RecordDecl *rec = field->getParent();
-  llvm::DIType *DbgInfo = CGF.getDebugInfo()->getOrCreateRecordType(
-  CGF.getContext().getRecordType(rec), rec->getLocation());
+  llvm::DIType *DbgInfo = CGF.getDebugInfo()->getOrCreateStandaloneType(
+  base.getType(), rec->getLocation());
 
   unsigned idx =
   CGF.CGM.getTypes().getCGRecordLayout(rec).getLLVMFieldNo(field);
 
   return CGF.Builder.CreatePreserveStructAccessIndex(
-  base, idx, CGF.getDebugInfoFIndex(rec, field->getFieldIndex()), DbgInfo);
+  addr, idx, CGF.getDebugInfoFIndex(rec, field->getFieldIndex()), DbgInfo);
 }
 
 static bool hasAnyVptr(const QualType Type, const ASTContext &Context) {
@@ -4158,8 +4158,8 @@
 if (IsInPreservedAIRegion ||
 (getDebugInfo() && rec->hasAttr())) {
   // Remember the original union field index
-  llvm::DIType *DbgInfo = getDebugInfo()->getOrCreateRecordType(
-  getContext().getRecordType(rec), rec->getLocation());
+  llvm::DIType *DbgInfo = 
getDebugInfo()->getOrCreateStandaloneType(base.getType(),
+  rec->getLocation());
   addr = Address(
   Builder.CreatePreserveUnionAccessIndex(
   addr.getPointer(), getDebugInfoFIndex(rec, 
field->getFieldIndex()), DbgInfo),
@@ -4176,7 +4176,7 @@
   addr = emitAddrOfFieldStorage(*this, addr, field);
 else
   // Remember the original struct field index
-  addr = emitPreserveStructAccess(*this, addr, field);
+  addr = emitPreserveStructAccess(*this, base, addr, field);
   }
 
   // If this is a reference field, load the reference right now.


Index: clang/test/CodeGen/builtin-preserve-access-index-t

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

2020-02-03 Thread Alexey Bader via Phabricator via cfe-commits
bader marked an inline comment as done.
bader added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3412-3414
+def fsycl : Flag<["-"], "fsycl">, Group,
+  HelpText<"Enable SYCL kernels compilation for device">;
+def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group, 
Flags<[CC1Option]>,

ABataev wrote:
> Better to split this into 2 parts: the first for `-fsycl` and the second for 
> `-sycl-std=`.
Okay. Just one question: 

Do you know if it's okay to have two commits per review request (like the first 
version of the "patch" in this review - it was split as you suggest)? Or I 
should create two separate review requests?


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] D73903: [AArch64][SVE] Add remaining SVE2 intrinsics for widening DSP operations

2020-02-03 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin created this revision.
kmclaughlin added reviewers: sdesmalen, dancgr, efriedma, c-rhodes.
Herald added subscribers: psnobl, rkruppe, hiraditya, kristof.beyls, tschuett.
Herald added a reviewer: rengolin.
Herald added a project: LLVM.
kmclaughlin added a parent revision: D73719: [AArch64][SVE] Add SVE2 intrinsics 
for widening DSP operations.

Implements the following intrinsics:

- llvm.aarch64.sve.[s|u]mullb_lane
- llvm.aarch64.sve.[s|u]mullt_lane
- llvm.aarch64.sve.sqdmullb_lane
- llvm.aarch64.sve.sqdmullt_lane
- llvm.aarch64.sve.[s|u]addwb
- llvm.aarch64.sve.[s|u]addwt
- llvm.aarch64.sve.[s|u]shllb
- llvm.aarch64.sve.[s|u]shllt
- llvm.aarch64.sve.[s|u]subwb
- llvm.aarch64.sve.[s|u]subwt


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73903

Files:
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
  llvm/lib/Target/AArch64/SVEInstrFormats.td
  llvm/test/CodeGen/AArch64/sve2-intrinsics-widening-dsp.ll

Index: llvm/test/CodeGen/AArch64/sve2-intrinsics-widening-dsp.ll
===
--- llvm/test/CodeGen/AArch64/sve2-intrinsics-widening-dsp.ll
+++ llvm/test/CodeGen/AArch64/sve2-intrinsics-widening-dsp.ll
@@ -193,6 +193,69 @@
 }
 
 ;
+; SADDWB
+;
+
+define  @saddwb_b( %a,  %b) {
+; CHECK-LABEL: saddwb_b:
+; CHECK: saddwb z0.h, z0.h, z1.b
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.saddwb.nxv8i16( %a,
+   %b)
+  ret  %out
+}
+
+define  @saddwb_h( %a,  %b) {
+; CHECK-LABEL: saddwb_h:
+; CHECK: saddwb z0.s, z0.s, z1.h
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.saddwb.nxv4i32( %a,
+   %b)
+  ret  %out
+}
+
+define  @saddwb_s( %a,  %b) {
+; CHECK-LABEL: saddwb_s:
+; CHECK: saddwb z0.d, z0.d, z1.s
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.saddwb.nxv2i64( %a,
+   %b)
+  ret  %out
+}
+
+;
+; SADDWT
+;
+
+define  @saddwt_b( %a,  %b) {
+; CHECK-LABEL: saddwt_b:
+; CHECK: saddwt z0.h, z0.h, z1.b
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.saddwt.nxv8i16( %a,
+   %b)
+  ret  %out
+}
+
+define  @saddwt_h( %a,  %b) {
+; CHECK-LABEL: saddwt_h:
+; CHECK: saddwt z0.s, z0.s, z1.h
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.saddwt.nxv4i32( %a,
+   %b)
+  ret  %out
+}
+
+define  @saddwt_s( %a,  %b) {
+; CHECK-LABEL: saddwt_s:
+; CHECK: saddwt z0.d, z0.d, z1.s
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.saddwt.nxv2i64( %a,
+   %b)
+  ret  %out
+}
+
+
+;
 ; SMULLB (Vectors)
 ;
 
@@ -224,6 +287,30 @@
 }
 
 ;
+; SMULLB (Indexed)
+;
+
+define  @smullb_lane_h( %a,  %b) {
+; CHECK-LABEL: smullb_lane_h:
+; CHECK: smullb z0.s, z0.h, z1.h[4]
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.smullb.lane.nxv4i32( %a,
+%b,
+   i32 4)
+  ret  %out
+}
+
+define  @smullb_lane_s( %a,  %b) {
+; CHECK-LABEL: smullb_lane_s:
+; CHECK: smullb z0.d, z0.s, z1.s[3]
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.smullb.lane.nxv2i64( %a,
+%b,
+   i32 3)
+  ret  %out
+}
+
+;
 ; SMULLT (Vectors)
 ;
 
@@ -255,6 +342,30 @@
 }
 
 ;
+; SMULLT (Indexed)
+;
+
+define  @smullt_lane_h( %a,  %b) {
+; CHECK-LABEL: smullt_lane_h:
+; CHECK: smullt z0.s, z0.h, z1.h[5]
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.smullt.lane.nxv4i32( %a,
+%b,
+   i32 5)
+  ret  %out
+}
+
+define  @smullt_lane_s( %a,  %b) {
+; CHECK-LABEL: smullt_lane_s:
+; CHECK: smullt z0.d, z0.s, z1.s[2]
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.smullt.lane.nxv2i64( %a,
+%b,
+   i32 2)
+  ret  %out
+}
+
+;
 ; SQDMULLB (Vectors)
 ;
 
@@ -286,6 +397,30 @@
 }
 
 ;
+; SQDMULLB (Indexed)
+;
+
+define  @sqdmullb_lane_h( %a,  %b) {
+; CHECK-LABEL: sqdmullb_lane_h:
+; CHECK: sqdmullb z0.s, z0.h, z1.h[2]
+; CHECK-NEXT: ret
+  %out = call  @llvm.aarch64.sve.sqdmullb.lane.nxv4i32( %a,
+  %b,
+ i32 2)
+  ret  %out
+}
+
+define  @sqdmullb_lane_s( %a,  %b) {
+; CHECK-LABEL: sqdmullb_lane_s:
+; CHECK: sqdmullb z0.d, z0.s, z1.s[1]
+; CHECK-N

[PATCH] D73904: [clang] stop baremetal driver to append .a to lib

2020-02-03 Thread Christof Douma via Phabricator via cfe-commits
christof created this revision.
christof added reviewers: peter.smith, jroelofs.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When the clang baremetal driver selects the rt.builtins static library it 
prefix with "-l" and appends ".a". The result is a nonsense option which lld 
refuses to accept.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73904

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


Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -157,7 +157,7 @@
 void BareMetal::AddLinkRuntimeLib(const ArgList &Args,
   ArgStringList &CmdArgs) const {
   CmdArgs.push_back(Args.MakeArgString("-lclang_rt.builtins-" +
-   getTriple().getArchName() + ".a"));
+   getTriple().getArchName()));
 }
 
 void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA,


Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -157,7 +157,7 @@
 void BareMetal::AddLinkRuntimeLib(const ArgList &Args,
   ArgStringList &CmdArgs) const {
   CmdArgs.push_back(Args.MakeArgString("-lclang_rt.builtins-" +
-   getTriple().getArchName() + ".a"));
+   getTriple().getArchName()));
 }
 
 void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69591: Devirtualize a call on alloca without waiting for post inline cleanup and next DevirtSCCRepeatedPass iteration.

2020-02-03 Thread Hiroshi Yamauchi via Phabricator via cfe-commits
yamauchi updated this revision to Diff 242103.
yamauchi added a comment.

Fix typo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69591

Files:
  clang/test/CodeGenCXX/member-function-pointer-calls.cpp
  llvm/lib/Transforms/IPO/Inliner.cpp
  llvm/test/Transforms/Inline/devirtualize-4.ll

Index: llvm/test/Transforms/Inline/devirtualize-4.ll
===
--- /dev/null
+++ llvm/test/Transforms/Inline/devirtualize-4.ll
@@ -0,0 +1,214 @@
+; RUN: opt < %s -passes='cgscc(devirt<4>(inline)),function(sroa,early-cse)' -S | FileCheck %s
+; RUN: opt < %s -passes='default' -S | FileCheck %s
+
+; Check that DoNotOptimize is inlined into Test.
+; CHECK: @_Z4Testv()
+; CHECK-NOT: ret void
+; CHECK: call void asm
+; CHECK: ret void
+
+;template 
+;void DoNotOptimize(const T& var) {
+;  asm volatile("" : "+m"(const_cast(var)));
+;}
+;
+;class Interface {
+; public:
+;  virtual void Run() = 0;
+;};
+;
+;class Impl : public Interface {
+; public:
+;  Impl() : f(3) {}
+;  void Run() { DoNotOptimize(this); }
+;
+; private:
+;  int f;
+;};
+;
+;static void IndirectRun(Interface& o) { o.Run(); }
+;
+;void Test() {
+;  Impl o;
+;  IndirectRun(o);
+;}
+
+%class.Impl = type <{ %class.Interface, i32, [4 x i8] }>
+%class.Interface = type { i32 (...)** }
+
+@_ZTV4Impl = linkonce_odr dso_local unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* bitcast ({ i8*, i8*, i8* }* @_ZTI4Impl to i8*), i8* bitcast (void (%class.Impl*)* @_ZN4Impl3RunEv to i8*)] }, align 8
+@_ZTVN10__cxxabiv120__si_class_type_infoE = external dso_local global i8*
+@_ZTS4Impl = linkonce_odr dso_local constant [6 x i8] c"4Impl\00", align 1
+@_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global i8*
+@_ZTS9Interface = linkonce_odr dso_local constant [11 x i8] c"9Interface\00", align 1
+@_ZTI9Interface = linkonce_odr dso_local constant { i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv117__class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @_ZTS9Interface, i32 0, i32 0) }, align 8
+@_ZTI4Impl = linkonce_odr dso_local constant { i8*, i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @_ZTS4Impl, i32 0, i32 0), i8* bitcast ({ i8*, i8* }* @_ZTI9Interface to i8*) }, align 8
+@_ZTV9Interface = linkonce_odr dso_local unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI9Interface to i8*), i8* bitcast (void ()* @__cxa_pure_virtual to i8*)] }, align 8
+
+define dso_local void @_Z4Testv() local_unnamed_addr {
+entry:
+  %o = alloca %class.Impl, align 8
+  %0 = bitcast %class.Impl* %o to i8*
+  call void @llvm.lifetime.start.p0i8(i64 16, i8* nonnull %0)
+  call void @_ZN4ImplC2Ev(%class.Impl* nonnull %o)
+  %1 = getelementptr inbounds %class.Impl, %class.Impl* %o, i64 0, i32 0
+  call fastcc void @_ZL11IndirectRunR9Interface(%class.Interface* nonnull dereferenceable(8) %1)
+  call void @llvm.lifetime.end.p0i8(i64 16, i8* nonnull %0)
+  ret void
+}
+
+declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
+
+define linkonce_odr dso_local void @_ZN4ImplC2Ev(%class.Impl* %this) unnamed_addr align 2 {
+entry:
+  %0 = getelementptr %class.Impl, %class.Impl* %this, i64 0, i32 0
+  call void @_ZN9InterfaceC2Ev(%class.Interface* %0)
+  %1 = getelementptr %class.Impl, %class.Impl* %this, i64 0, i32 0, i32 0
+  store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV4Impl, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %1, align 8
+  %f = getelementptr inbounds %class.Impl, %class.Impl* %this, i64 0, i32 1
+  store i32 3, i32* %f, align 8
+  ret void
+}
+
+define internal fastcc void @_ZL11IndirectRunR9Interface(%class.Interface* dereferenceable(8) %o) unnamed_addr {
+entry:
+  %0 = bitcast %class.Interface* %o to void (%class.Interface*)***
+  %vtable = load void (%class.Interface*)**, void (%class.Interface*)*** %0, align 8
+  %1 = load void (%class.Interface*)*, void (%class.Interface*)** %vtable, align 8
+  call void %1(%class.Interface* nonnull %o)
+  ret void
+}
+
+declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)
+
+define linkonce_odr dso_local void @_ZN9InterfaceC2Ev(%class.Interface* %this) unnamed_addr align 2 {
+entry:
+  %0 = getelementptr %class.Interface, %class.Interface* %this, i64 0, i32 0
+  store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV9Interface, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
+  ret void
+}
+
+define linkonce_odr dso_local void @_ZN4Impl3RunEv(%class.Impl* %this) unnamed_addr align 2 {
+entry:
+  %ref.tmp = alloca %class.Impl*, align 8
+  %0 = bitcast %class.Impl** %ref.tmp to i8*
+  call void @llvm.lifetime.start.p0i8(i64 8, i8* 

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

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

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

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

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

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


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73898



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


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

2020-02-03 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3412-3414
+def fsycl : Flag<["-"], "fsycl">, Group,
+  HelpText<"Enable SYCL kernels compilation for device">;
+def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group, 
Flags<[CC1Option]>,

bader wrote:
> ABataev wrote:
> > Better to split this into 2 parts: the first for `-fsycl` and the second 
> > for `-sycl-std=`.
> Okay. Just one question: 
> 
> Do you know if it's okay to have two commits per review request (like the 
> first version of the "patch" in this review - it was split as you suggest)? 
> Or I should create two separate review requests?
Separate patches must have separate review requests


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] D73897: [analyzer] StdLibraryFunctionsChecker refactor: remove macros

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

{icon times-circle color=red} Unit tests: fail. 62099 tests passed, 5 failed 
and 784 were skipped.

  failed: libc++.std/language_support/cmp/cmp_partialord/partialord.pass.cpp
  failed: libc++.std/language_support/cmp/cmp_strongeq/cmp.strongeq.pass.cpp
  failed: libc++.std/language_support/cmp/cmp_strongord/strongord.pass.cpp
  failed: libc++.std/language_support/cmp/cmp_weakeq/cmp.weakeq.pass.cpp
  failed: libc++.std/language_support/cmp/cmp_weakord/weakord.pass.cpp

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

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

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


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73897



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


[clang] a781521 - [OPENMP50]Codegen support for order(concurrent) clause.

2020-02-03 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-02-03T12:27:33-05:00
New Revision: a781521867e9952e8d5856e10bf900b37f8ec4e8

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

LOG: [OPENMP50]Codegen support for order(concurrent) clause.

Emit llvm parallel access metadata for the loops if they are marked as
order(concurrent).

Added: 
clang/test/OpenMP/target_teams_distribute_parallel_for_order_codegen.cpp

Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/for_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index a84f2fe3f23f..827ea213bf4e 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1931,6 +1931,9 @@ void CodeGenFunction::EmitOMPSimdInit(const 
OMPLoopDirective &D,
   LoopStack.setParallel(!IsMonotonic);
   LoopStack.setVectorizeEnable();
   emitSimdlenSafelenClause(*this, D, IsMonotonic);
+  if (const auto *C = D.getSingleClause())
+if (C->getKind() == OMPC_ORDER_concurrent)
+  LoopStack.setParallel(/*Enable=*/true);
 }
 
 void CodeGenFunction::EmitOMPSimdFinal(
@@ -2202,10 +2205,14 @@ void CodeGenFunction::EmitOMPOuterLoop(
   [&S, IsMonotonic](CodeGenFunction &CGF, PrePostActionTy &) {
 // Generate !llvm.loop.parallel metadata for loads and stores for loops
 // with dynamic/guided scheduling and without ordered clause.
-if (!isOpenMPSimdDirective(S.getDirectiveKind()))
+if (!isOpenMPSimdDirective(S.getDirectiveKind())) {
   CGF.LoopStack.setParallel(!IsMonotonic);
-else
+  if (const auto *C = S.getSingleClause())
+if (C->getKind() == OMPC_ORDER_concurrent)
+  CGF.LoopStack.setParallel(/*Enable=*/true);
+} else {
   CGF.EmitOMPSimdInit(S, IsMonotonic);
+}
   },
   [&S, &LoopArgs, LoopExit, &CodeGenLoop, IVSize, IVSigned, 
&CodeGenOrdered,
&LoopScope](CodeGenFunction &CGF, PrePostActionTy &) {
@@ -2720,8 +2727,12 @@ bool CodeGenFunction::EmitOMPWorksharingLoop(
 emitCommonSimdLoop(
 *this, S,
 [&S](CodeGenFunction &CGF, PrePostActionTy &) {
-  if (isOpenMPSimdDirective(S.getDirectiveKind()))
+  if (isOpenMPSimdDirective(S.getDirectiveKind())) {
 CGF.EmitOMPSimdInit(S, /*IsMonotonic=*/true);
+  } else if (const auto *C = S.getSingleClause()) {
+if (C->getKind() == OMPC_ORDER_concurrent)
+  CGF.LoopStack.setParallel(/*Enable=*/true);
+  }
 },
 [IVSize, IVSigned, Ordered, IL, LB, UB, ST, StaticChunkedOne, 
Chunk,
  &S, ScheduleKind, LoopExit,

diff  --git a/clang/test/OpenMP/for_codegen.cpp 
b/clang/test/OpenMP/for_codegen.cpp
index a837a4a04d7b..9082eaaf878f 100644
--- a/clang/test/OpenMP/for_codegen.cpp
+++ b/clang/test/OpenMP/for_codegen.cpp
@@ -743,28 +743,28 @@ void body_f();
 // OMP5-LABEL: imperfectly_nested_loop
 void imperfectly_nested_loop() {
   // OMP5: call void @__kmpc_for_static_init_4(
-#pragma omp for collapse(3)
+#pragma omp for collapse(3) order(concurrent)
   for (int i = 0; i < 10; ++i) {
 {
   int a, d;
   // OMP5: invoke void @{{.+}}first{{.+}}()
   first();
-  // OMP5: load i32
-  // OMP5: store i32
+  // OMP5: load i32{{.*}}!llvm.access.group ![[AG:[0-9]+]]
+  // OMP5: store i32{{.*}}!llvm.access.group ![[AG]]
   a = d;
   for (int j = 0; j < 10; ++j) {
 int a, d;
 // OMP5: invoke void @{{.+}}inner_f{{.+}}()
 inner_f();
-// OMP5: load i32
-// OMP5: store i32
+// OMP5: load i32{{.*}}!llvm.access.group ![[AG]]
+// OMP5: store i32{{.*}}!llvm.access.group ![[AG]]
 a = d;
 for (int k = 0; k < 10; ++k) {
   int a, d;
   // OMP5: invoke void @{{.+}}body_f{{.+}}()
   body_f();
-  // OMP5: load i32
-  // OMP5: store i32
+  // OMP5: load i32{{.*}}!llvm.access.group ![[AG]]
+  // OMP5: store i32{{.*}}!llvm.access.group ![[AG]]
   a = d;
 }
 // OMP5: invoke void @{{.+}}inner_l{{.+}}()
@@ -776,6 +776,10 @@ void imperfectly_nested_loop() {
   }
   // OMP5: call void @__kmpc_for_static_fini(
 }
+
+// OMP5: ![[AG]] = distinct !{}
+// OMP5: !{!"llvm.loop.parallel_accesses", ![[AG]]}
+
 #endif
 
 #endif // HEADER

diff  --git 
a/clang/test/OpenMP/target_teams_distribute_parallel_for_order_codegen.cpp 
b/clang/test/OpenMP/target_teams_distribute_parallel_for_order_codegen.cpp
new file mode 100644
index ..201c19e2ed5b
--- /dev/null
+++ b/clang/test/OpenMP/target_teams_distribute_parallel_for_order_codegen.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp

[clang] 6c3252e - [OPENMP][DOCS]Update status of conditional lastprivate, NFC.

2020-02-03 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-02-03T12:43:40-05:00
New Revision: 6c3252e5211b0c6ce6eb4a1123d60bb74faec0be

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

LOG: [OPENMP][DOCS]Update status of conditional lastprivate, NFC.

Added: 


Modified: 
clang/docs/OpenMPSupport.rst

Removed: 




diff  --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index d3050e009a4c..3a28adb2f444 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -197,7 +197,7 @@ implementation.
 
+--+--+--+---+
 | device extension | clause: reverse_offload   
   | :none:`unclaimed parts`  | D52780  
  |
 
+--+--+--+---+
-| device extension | clause: atomic_default_mem_order  
   | :none:`unclaimed parts`  | D53513  
  |
+| device extension | clause: atomic_default_mem_rrder  
   | :none:`unclaimed parts`  | D53513  
  |
 
+--+--+--+---+
 | device extension | clause: dynamic_allocators
   | :none:`unclaimed parts`  | D53079  
  |
 
+--+--+--+---+
@@ -227,7 +227,7 @@ implementation.
 
+--+--+--+---+
 | misc extension   | metadirectives
   | :none:`worked on`| 
  |
 
+--+--+--+---+
-| misc extension   | conditional modifier for lastprivate clause   
   | :part:`worked on`| 
  |
+| misc extension   | conditional modifier for lastprivate clause   
   | :good:`done` | 
  |
 
+--+--+--+---+
 | misc extension   | user-defined function variants
   | :part:`worked on`| D67294, D64095  
  |
 
+--+--+--+---+



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


[PATCH] D73897: [analyzer] StdLibraryFunctionsChecker refactor: remove macros

2020-02-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

This looks fantastic, i didn't think of this originally. All hail type safety!
Nits below.




Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:182
+
+FunctionSummaryTy &Specification(ValueRangeSet VRS) {
+  Ranges.push_back(VRS);

Let's keep calling them "cases" because iirc this was a matter of discussion 
(https://reviews.llvm.org/D20811?id=71510#inline-211441).



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:537-551
+  // The format is as follows:
   //{ "function name",
-  //  { spec:
+  //  { variant0:
   //{ argument types list, ... },
-  //return type, purity, { range set list:
+  //return type, purity, { specification list:
   //  { range list:
   //{ argument index, within or out of, {{from, to}, ...} },

I suspect that this comment would need a lot more updates.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:553
   //}
+  using Summary = FunctionSummaryTy;
+  auto ArgumentCondition = [](ArgNoTy ArgNo, ValueRangeKindTy Kind,

There seems to be a lot of inconsistency in the use of `T`, `Ty`, and 
lack-of-suffix.

I'd prefer to have one of them reserved for `QualType`s (eg., `IntTy`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73897



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


[PATCH] D73906: [ARM] Make ARM::ArchExtKind use 64-bit underlying type, NFCI

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

This patch changes the underlying type of the ARM::ArchExtKind
enumeration to uint64_t and adjusts the related code.

The goal of the patch is to prepare the code base for a new
architecture extension.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73906

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  llvm/include/llvm/Support/ARMTargetParser.h
  llvm/lib/Support/ARMTargetParser.cpp
  llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -32,7 +32,7 @@
 };
 
 bool testARMCPU(StringRef CPUName, StringRef ExpectedArch,
-StringRef ExpectedFPU, unsigned ExpectedFlags,
+StringRef ExpectedFPU, uint64_t ExpectedFlags,
 StringRef CPUAttr) {
   ARM::ArchKind AK = ARM::parseCPUArch(CPUName);
   bool pass = ARM::getArchName(AK).equals(ExpectedArch);
@@ -565,7 +565,7 @@
 }
 
 TEST(TargetParserTest, ARMExtensionFeatures) {
-  std::map> Extensions;
+  std::map> Extensions;
 
   for (auto &Ext : ARM::ARCHExtNames) {
 if (Ext.Feature && Ext.NegFeature)
Index: llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
===
--- llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -11726,7 +11726,7 @@
   // when we start to table-generate them, and we can use the ARM
   // flags below, that were generated by table-gen.
   static const struct {
-const unsigned Kind;
+const uint64_t Kind;
 const FeatureBitset ArchCheck;
 const FeatureBitset Features;
   } Extensions[] = {
@@ -11775,7 +11775,7 @@
 EnableFeature = false;
 Name = Name.substr(2);
   }
-  unsigned FeatureKind = ARM::parseArchExt(Name);
+  uint64_t FeatureKind = ARM::parseArchExt(Name);
   if (FeatureKind == ARM::AEK_INVALID)
 return Error(ExtLoc, "unknown architectural extension: " + Name);
 
Index: llvm/lib/Support/ARMTargetParser.cpp
===
--- llvm/lib/Support/ARMTargetParser.cpp
+++ llvm/lib/Support/ARMTargetParser.cpp
@@ -367,7 +367,7 @@
.Default(ARM::FK_INVALID);
 }
 
-unsigned ARM::getDefaultExtensions(StringRef CPU, ARM::ArchKind AK) {
+uint64_t ARM::getDefaultExtensions(StringRef CPU, ARM::ArchKind AK) {
   if (CPU == "generic")
 return ARM::ARCHNames[static_cast(AK)].ArchBaseExtensions;
 
@@ -380,7 +380,7 @@
   .Default(ARM::AEK_INVALID);
 }
 
-bool ARM::getHWDivFeatures(unsigned HWDivKind,
+bool ARM::getHWDivFeatures(uint64_t HWDivKind,
std::vector &Features) {
 
   if (HWDivKind == AEK_INVALID)
@@ -399,7 +399,7 @@
   return true;
 }
 
-bool ARM::getExtensionFeatures(unsigned Extensions,
+bool ARM::getExtensionFeatures(uint64_t Extensions,
std::vector &Features) {
 
   if (Extensions == AEK_INVALID)
@@ -431,7 +431,7 @@
   return ARCHNames[static_cast(AK)].ArchAttr;
 }
 
-StringRef ARM::getArchExtName(unsigned ArchExtKind) {
+StringRef ARM::getArchExtName(uint64_t ArchExtKind) {
   for (const auto AE : ARCHExtNames) {
 if (ArchExtKind == AE.ID)
   return AE.getName();
@@ -532,7 +532,7 @@
   return StartingNumFeatures != Features.size();
 }
 
-StringRef ARM::getHWDivName(unsigned HWDivKind) {
+StringRef ARM::getHWDivName(uint64_t HWDivKind) {
   for (const auto D : HWDivNames) {
 if (HWDivKind == D.ID)
   return D.getName();
@@ -555,7 +555,7 @@
   return "generic";
 }
 
-unsigned ARM::parseHWDiv(StringRef HWDiv) {
+uint64_t ARM::parseHWDiv(StringRef HWDiv) {
   StringRef Syn = getHWDivSynonym(HWDiv);
   for (const auto D : HWDivNames) {
 if (Syn == D.getName())
@@ -564,7 +564,7 @@
   return AEK_INVALID;
 }
 
-unsigned ARM::parseArchExt(StringRef ArchExt) {
+uint64_t ARM::parseArchExt(StringRef ArchExt) {
   for (const auto A : ARCHExtNames) {
 if (ArchExt == A.getName())
   return A.ID;
Index: llvm/include/llvm/Support/ARMTargetParser.h
===
--- llvm/include/llvm/Support/ARMTargetParser.h
+++ llvm/include/llvm/Support/ARMTargetParser.h
@@ -24,7 +24,7 @@
 
 // Arch extension modifiers for CPUs.
 // Note that this is not the same as the AArch64 list
-enum ArchExtKind : unsigned {
+enum ArchExtKind : uint64_t {
   AEK_INVALID = 0,
   AEK_NONE =1,
   AEK_CRC = 1 << 1,
@@ -47,11 +47,11 @@
   AEK_FP_DP   = 1 << 18,
   AEK_LOB = 1 << 19,
   // Unsupported extensions.
-  AEK_OS = 0x800,
-  AEK_IWMMXT = 0x1000

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

2020-02-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:411
+  if (ExplodedNode *N = C.generateErrorNode(State)) {
+// FIXME Add detailed diagnostic.
+std::string Msg = "Function argument constraint is not satisfied";

Yeah, a must-have for this check to be enabled by default would be to be able 
to provide a specific warning message for every function. I guess we could 
include them in the summaries as an extra argument of `ArgConstraint`.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:414
+auto R = std::make_unique(BT, Msg, N);
+bugreporter::trackExpressionValue(N, Call.getArgExpr(0), *R);
+C.emitReport(std::move(R));

Let's test our notes.

That'll be especially important when we get to non-concrete values, because the 
visitor might need to be expanded (or we might need a completely new visitor).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73898



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


[PATCH] D73900: [BPF] use base lvalue type for preserve_{struct,union}_access_index metadata

2020-02-03 Thread Andrii Nakryiko via Phabricator via cfe-commits
anakryiko accepted this revision.
anakryiko 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/D73900/new/

https://reviews.llvm.org/D73900



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


[PATCH] D73904: [clang] stop baremetal driver to append .a to lib

2020-02-03 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

I think this is the right thing to do. According to 
https://sourceware.org/binutils/docs/ld/Options.html#Options

  Add the archive or object file specified by namespec to the list of files to 
link. This option may be used any number of times. If namespec is of the form 
:filename, ld will search the library path for a file called filename, 
otherwise it will search the library path for a file called libnamespec.a.

An argument could be made that LLD could be a bit cleverer and only add the .a 
when it doesn't exist, although that would fail in the contrived case that 
someone had explicitly named their library lib name.a.a however it would be 
good to fix this in clang so that older versions of LLD will work.

Please could you add a test to clang/test/Driver/arm-compiler-rt.c for the 
arm-none-eabi target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73904



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


  1   2   >