[PATCH] D87350: [AST][RecoveryExpr] Fix a crash on undeduced type.

2020-09-21 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:12880
 
   return Result.getValueOr(QualType());
 }

sammccall wrote:
> Wouldn't we be better to handle undeduced type here rather than in the loop?
> 
> Not sure if it practically matters, but given: `auto f(); double f(int); 
> f(0,0);`
> the code in this patch will discard auto and yield `double`, while treating 
> this as multiple candidates --> unknown return type seems more correct.
> 
I feel like yield `double` is better in your given example -- in this case, 
double is the only candidate, so it is reasonable to preserve the `double` type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87350

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


[PATCH] D87749: [SyntaxTree][Synthesis] Implement `deepCopy`

2020-09-21 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 293085.
eduucaldas marked 3 inline comments as done.
eduucaldas added a comment.

- `deepCopy` returns `nullptr` if copy code with Macro expansions.
- `deepCopy` also deep copies the Tokens.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87749

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -163,6 +163,50 @@
   )txt"));
 }
 
+TEST_P(SynthesisTest, DeepCopy_Synthesized) {
+  buildTree("", GetParam());
+
+  auto *LeafContinue = createLeaf(*Arena, tok::kw_continue);
+  auto *LeafSemiColon = createLeaf(*Arena, tok::semi);
+  auto *StatementContinue = createTree(*Arena,
+   {{LeafContinue, NodeRole::LiteralToken},
+{LeafSemiColon, NodeRole::Unknown}},
+   NodeKind::ContinueStatement);
+
+  auto *Copy = deepCopy(*Arena, StatementContinue);
+  EXPECT_TRUE(
+  treeDumpEqual(Copy, StatementContinue->dump(Arena->getSourceManager(;
+  // FIXME: Test that copy is independent of original, once the Mutations API is
+  // more developed.
+}
+
+TEST_P(SynthesisTest, DeepCopy_Original) {
+  auto *OriginalTree = buildTree("int a;", GetParam());
+
+  auto *Copy = deepCopy(*Arena, OriginalTree);
+  EXPECT_TRUE(treeDumpEqual(Copy, R"txt(
+TranslationUnit Detached synthesized
+`-SimpleDeclaration synthesized
+  |-'int' synthesized
+  |-SimpleDeclarator Declarator synthesized
+  | `-'a' synthesized
+  `-';' synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, DeepCopy_Child) {
+  auto *OriginalTree = buildTree("int a;", GetParam());
+
+  auto *Copy = deepCopy(*Arena, OriginalTree->getFirstChild());
+  EXPECT_TRUE(treeDumpEqual(Copy, R"txt(
+SimpleDeclaration Detached synthesized
+|-'int' synthesized
+|-SimpleDeclarator Declarator synthesized
+| `-'a' synthesized
+`-';' synthesized
+  )txt"));
+}
+
 TEST_P(SynthesisTest, Statement_EmptyStatement) {
   buildTree("", GetParam());
 
Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -28,10 +28,12 @@
   }
 };
 
+// FIXME: `createLeaf` is based on `syntax::tokenize` internally, as such it
+// doesn't support digraphs or line continuations.
 syntax::Leaf *clang::syntax::createLeaf(syntax::Arena &A, tok::TokenKind K,
 StringRef Spelling) {
   auto Tokens =
-  FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBuffer(Spelling))
+  FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBufferCopy(Spelling))
   .second;
   assert(Tokens.size() == 1);
   assert(Tokens.front().kind() == K &&
@@ -184,6 +186,7 @@
   }
   llvm_unreachable("unknown node kind");
 }
+
 } // namespace
 
 syntax::Tree *clang::syntax::createTree(
@@ -192,14 +195,52 @@
 syntax::NodeKind K) {
   auto *T = allocateTree(A, K);
   FactoryImpl::setCanModify(T);
-  for (auto ChildIt = Children.rbegin(); ChildIt != Children.rend();
-   std::advance(ChildIt, 1))
+  for (auto ChildIt = Children.rbegin(); ChildIt != Children.rend(); ++ChildIt)
 FactoryImpl::prependChildLowLevel(T, ChildIt->first, ChildIt->second);
 
   T->assertInvariants();
   return T;
 }
 
+namespace {
+bool canModifyAllDescendants(const syntax::Node *N) {
+  if (const auto *L = dyn_cast(N))
+return L->canModify();
+
+  const auto *T = cast(N);
+
+  if (!T->canModify())
+return false;
+  for (const auto *Child = T->getFirstChild(); Child;
+   Child = Child->getNextSibling())
+if (!Child->canModify())
+  return false;
+
+  return true;
+}
+
+syntax::Node *deepCopyImpl(syntax::Arena &A, const syntax::Node *N) {
+  if (const auto *L = dyn_cast(N))
+return createLeaf(A, L->getToken()->kind(),
+  L->getToken()->text(A.getSourceManager()));
+
+  const auto *T = cast(N);
+  auto Children = std::vector>();
+  for (const auto *Child = T->getFirstChild(); Child;
+   Child = Child->getNextSibling())
+Children.push_back({deepCopy(A, Child), Child->getRole()});
+
+  return createTree(A, Children, N->getKind());
+}
+} // namespace
+
+syntax::Node *clang::syntax::deepCopy(syntax::Arena &A, const Node *N) {
+  if (!canModifyAllDescendants(N))
+return nullptr;
+
+  return deepCopyImpl(A, N);
+}
+
 syntax::EmptyStatement *clang::syntax::createEmptyStatement(syntax::Arena &A) {
   return cast(
   createTree(A, {{createLeaf(A, tok::semi), NodeRole::Unknown}},
Index: clang/include/clang/Tooling/Syntax/BuildTree.h
===

[PATCH] D88002: [clang-cl] Always interpret the LIB env var as separated with semicolons

2020-09-21 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added reviewers: rnk, amccarth, thakis, hans.
Herald added subscribers: llvm-commits, hiraditya.
Herald added projects: clang, LLVM.
mstorsjo requested review of this revision.

When cross compiling with clang-cl, clang splits the INCLUDE env variable 
around semicolons (clang/lib/Driver/ToolChains/MSVC.cpp, 
MSVCToolChain::AddClangSystemIncludeArgs) and lld splits the LIB variable 
similarly (lld/COFF/Driver.cpp, LinkerDriver::addLibSearchPaths). Therefore, 
the consensus for cross compilation with clang-cl and lld-link seems to be to 
use semicolons, despite path lists normally being separated by colons on unix 
and EnvPathSeparator being set to that.

Therefore, handle the LIB variable similarly in Clang, when handling lib file 
arguments when driving linking via Clang.

This fixes commands like "clang-cl test.c -Fetest.exe kernel32.lib" in a cross 
compilation setting. Normally, most users call (lld-)link directly, but meson 
happens to use this command syntax for has_function() tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88002

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/cl-inputs.c
  llvm/include/llvm/Support/Process.h
  llvm/lib/Support/Process.cpp


Index: llvm/lib/Support/Process.cpp
===
--- llvm/lib/Support/Process.cpp
+++ llvm/lib/Support/Process.cpp
@@ -28,21 +28,22 @@
 //===  independent code.
 
//===--===//
 
-Optional Process::FindInEnvPath(StringRef EnvName,
- StringRef FileName) {
-  return FindInEnvPath(EnvName, FileName, {});
+Optional
+Process::FindInEnvPath(StringRef EnvName, StringRef FileName, char Separator) {
+  return FindInEnvPath(EnvName, FileName, {}, Separator);
 }
 
 Optional Process::FindInEnvPath(StringRef EnvName,
  StringRef FileName,
- ArrayRef IgnoreList) 
{
+ ArrayRef IgnoreList,
+ char Separator) {
   assert(!path::is_absolute(FileName));
   Optional FoundPath;
   Optional OptPath = Process::GetEnv(EnvName);
   if (!OptPath.hasValue())
 return FoundPath;
 
-  const char EnvPathSeparatorStr[] = {EnvPathSeparator, '\0'};
+  const char EnvPathSeparatorStr[] = {Separator, '\0'};
   SmallVector Dirs;
   SplitString(OptPath.getValue(), Dirs, EnvPathSeparatorStr);
 
Index: llvm/include/llvm/Support/Process.h
===
--- llvm/include/llvm/Support/Process.h
+++ llvm/include/llvm/Support/Process.h
@@ -29,6 +29,7 @@
 #include "llvm/Support/Chrono.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/Program.h"
 #include 
 
 namespace llvm {
@@ -107,10 +108,12 @@
   /// considered.
   static Optional FindInEnvPath(StringRef EnvName,
  StringRef FileName,
- ArrayRef IgnoreList);
+ ArrayRef IgnoreList,
+ char Separator = 
EnvPathSeparator);
 
   static Optional FindInEnvPath(StringRef EnvName,
- StringRef FileName);
+ StringRef FileName,
+ char Separator = 
EnvPathSeparator);
 
   // This functions ensures that the standard file descriptors (input, output,
   // and error) are properly mapped to a file descriptor before we use any of
Index: clang/test/Driver/cl-inputs.c
===
--- clang/test/Driver/cl-inputs.c
+++ clang/test/Driver/cl-inputs.c
@@ -32,7 +32,9 @@
 // WARN-NOT: note
 
 // MSYS2_ARG_CONV_EXCL tells MSYS2 to skip conversion of the specified 
argument.
-// RUN: env LIB=%S/Inputs/cl-libs MSYS2_ARG_CONV_EXCL="/TP;/c" %clang_cl /c 
/TP cl-test.lib -### 2>&1 | FileCheck -check-prefix=TPlib %s
+// Add a dummy "other" entry to the path as well, to check that it's split
+// around semicolons even on unix.
+// RUN: env LIB="other;%S/Inputs/cl-libs" MSYS2_ARG_CONV_EXCL="/TP;/c" 
%clang_cl /c /TP cl-test.lib -### 2>&1 | FileCheck -check-prefix=TPlib %s
 // TPlib: warning: cl-test.lib: 'linker' input unused
 // TPlib: warning: argument unused during compilation: '/TP'
 // TPlib-NOT: cl-test.lib
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2085,7 +2085,7 @@
 
   if (IsCLMode()) {
 if (!llvm::sys::path::is_absolute(Twine(Value)) &&
-llvm::sys::Process::FindInEnvPath("LIB", Value))
+llvm::sys::Process::FindInEnvPath("LIB", Value, ';'))
   

[PATCH] D87749: [SyntaxTree][Synthesis] Implement `deepCopy`

2020-09-21 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/lib/Tooling/Syntax/Synthesis.cpp:216
+   Child = Child->getNextSibling())
+if (!Child->canModify())
+  return false;

Shouldn't we call canModifyAllDescendants recursively?



Comment at: clang/lib/Tooling/Syntax/Synthesis.cpp:228
+  const auto *T = cast(N);
+  auto Children = std::vector>();
+  for (const auto *Child = T->getFirstChild(); Child;





Comment at: clang/lib/Tooling/Syntax/Synthesis.cpp:239
+  if (!canModifyAllDescendants(N))
+return nullptr;
+

Could you add tests for deepCopy returning nullptr?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87749

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


[PATCH] D87350: [AST][RecoveryExpr] Fix a crash on undeduced type.

2020-09-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:12880
 
   return Result.getValueOr(QualType());
 }

hokein wrote:
> sammccall wrote:
> > Wouldn't we be better to handle undeduced type here rather than in the loop?
> > 
> > Not sure if it practically matters, but given: `auto f(); double f(int); 
> > f(0,0);`
> > the code in this patch will discard auto and yield `double`, while treating 
> > this as multiple candidates --> unknown return type seems more correct.
> > 
> I feel like yield `double` is better in your given example -- in this case, 
> double is the only candidate, so it is reasonable to preserve the `double` 
> type.
There are two overloads, one with `double` and one with an unknown type. 
They're both candidates for the function being called, and I'm not sure we have 
any reason to believe the first is more likely.

Two counterarguments I can think of:
 - the unknown type is probably also double, as overloads tend to have the same 
return type
 - the cost of being wrong isn't so high, so it's OK to not be totally sure

And maybe there are others... these are probably OK justifications but subtle 
so I'd like to see a comment tothat effect.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87350

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


[PATCH] D87749: [SyntaxTree][Synthesis] Implement `deepCopy`

2020-09-21 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/Synthesis.cpp:237
+
+syntax::Node *clang::syntax::deepCopy(syntax::Arena &A, const Node *N) {
+  if (!canModifyAllDescendants(N))

We are ignoring nullability of pointers.

The casting machinery asserts that on `dyn_cast` we don't have `nullptr`. So 
this code crashes on `nullptr`. 

From what I understand `dyn_cast` et al. are intended to be used on pointers. 
Are there other alternatives to this approach? I would like to encode the 
non-nullability in types instead of in asserts



Comment at: clang/lib/Tooling/Syntax/Synthesis.cpp:205
+  if (L->canModify())
+syntax::FactoryImpl::setCanModify(Leaf);
+

gribozavr2 wrote:
> Since we are creating new leaves, why prohibit their mutation sometimes?
> 
> I also don't quite understand the implications of having multiple leaves in a 
> tree that are backed by the same token. I think the algorithm that produces 
> edits can be confused by that.
> 
> If you agree, please change the implementation to use `createLeaf` (or call 
> it directly from `deepCopy`).
> Since we are creating new leaves, why prohibit their mutation sometimes?

The `canModify` says whether the leaf is backed by a macro.

Since the tokens coming from macros are expanded they would be expanded in the 
deepCopy as well. We agreed that this shouldn't be the default behaviour. We 
can have `deepCopyExpandingMacros`, if the user wants this behaviour, but I 
think `deepCopy` should simply forbid macros.

WDYT about `deepCopyExpandingMacros`?

> having multiple leaves in a tree that are backed by the same token

We think the current algorithm wouldn't be confused by that.
However it's easier to reason about `Leaf`s each with their `Token`, and we 
don't think creating additional `Leaf` nodes would affect performance largely.

So we'll call `createLeaf` instead to create a fresh Leaf with the same Token 
as the previous one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87749

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


[PATCH] D87080: [AST] Reduce the size of TemplateArgumentLocInfo.

2020-09-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/include/clang/AST/Expr.h:963
 };
+static_assert(llvm::PointerLikeTypeTraits::SpecializationForExpr,
+  "Specialization in TemplateBase.h must be seen here");

I think this is it:
```
// PointerLikeTypeTraits is specialized so it can be used with a forward-decl 
of Expr.
// Verify that we got it right.
static_assert((1 << PointerLikeTypeTraits::NumLowBitsAvailable) == 
alignof(Expr), "PointerLikeTypeTraits assumes too much alignment");
```

(Or just `% alignof(Expr) == 0` if you want a weaker condition)



Comment at: clang/include/clang/AST/TemplateBase.h:43
+// the dependency.
+template <> struct PointerLikeTypeTraits {
+  static inline void *getAsVoidPointer(clang::Expr *P) { return P; }

rsmith wrote:
> hokein wrote:
> > sammccall wrote:
> > > At first glance this is unsafe: you could have two different definitions 
> > > of the same specialization in different files.
> > > 
> > > In fact it's OK, the default one can now never be instantiated, because 
> > > Expr.h includes this file and so anyone that can see the definition can 
> > > see this specialization.
> > > 
> > > But this is subtle/fragile: at least it needs to be spelled out 
> > > explicitly in the comment.
> > > I'd also suggest adding a static assert below the definition of Expr that 
> > > it is compatible with this specialization (because it is sufficiently 
> > > aligned).
> > > 
> > > (I can't think of a better alternative - use of PointerUnion is a win, 
> > > partly *because* it validates the alignment)
> > yes, exactly. 
> > 
> > do you have a better idea on how the static_assert should look like? The 
> > way I can think of is to add a new flag in this specialization, and use 
> > `static_assert(PointerLikeTypeTraits::flag, "...")`.
> This may be included from `Expr.h` right now, but really doesn't seem like 
> the right header to hold this specialization. Perhaps we should consider 
> adding something like an `AST/ForwardDecls.h`, containing forward 
> declarations and specializations such as this one, and include that from 
> `Expr.h` and from here?
I also had this thought but wasn't sure. @hokein maybe a trivial followup patch 
rather than inline here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87080

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


[PATCH] D88003: Fix typos in ASTMatchers.h

2020-09-21 Thread YangZhihui via Phabricator via cfe-commits
YangZhihui created this revision.
YangZhihui added a reviewer: aprantl.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
YangZhihui requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88003

Files:
  clang/include/clang/ASTMatchers/ASTMatchers.h


Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1162,7 +1162,7 @@
   return Node.getKind() == TemplateArgument::Integral;
 }
 
-/// Matches a TemplateArgument that referes to an integral type.
+/// Matches a TemplateArgument that refers to an integral type.
 ///
 /// Given
 /// \code
@@ -6572,7 +6572,7 @@
 /// \endcode
 extern const AstTypeMatcher decayedType;
 
-/// Matches the decayed type, whos decayed type matches \c InnerMatcher
+/// Matches the decayed type, whose decayed type matches \c InnerMatcher
 AST_MATCHER_P(DecayedType, hasDecayedType, internal::Matcher,
   InnerType) {
   return InnerType.matches(Node.getDecayedType(), Finder, Builder);


Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1162,7 +1162,7 @@
   return Node.getKind() == TemplateArgument::Integral;
 }
 
-/// Matches a TemplateArgument that referes to an integral type.
+/// Matches a TemplateArgument that refers to an integral type.
 ///
 /// Given
 /// \code
@@ -6572,7 +6572,7 @@
 /// \endcode
 extern const AstTypeMatcher decayedType;
 
-/// Matches the decayed type, whos decayed type matches \c InnerMatcher
+/// Matches the decayed type, whose decayed type matches \c InnerMatcher
 AST_MATCHER_P(DecayedType, hasDecayedType, internal::Matcher,
   InnerType) {
   return InnerType.matches(Node.getDecayedType(), Finder, Builder);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87749: [SyntaxTree][Synthesis] Implement `deepCopy`

2020-09-21 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 293089.
eduucaldas marked 3 inline comments as done.
eduucaldas added a comment.

Fix canModifyAllDescendants, add tests for it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87749

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -163,6 +163,63 @@
   )txt"));
 }
 
+TEST_P(SynthesisTest, DeepCopy_Synthesized) {
+  buildTree("", GetParam());
+
+  auto *LeafContinue = createLeaf(*Arena, tok::kw_continue);
+  auto *LeafSemiColon = createLeaf(*Arena, tok::semi);
+  auto *StatementContinue = createTree(*Arena,
+   {{LeafContinue, NodeRole::LiteralToken},
+{LeafSemiColon, NodeRole::Unknown}},
+   NodeKind::ContinueStatement);
+
+  auto *Copy = deepCopy(*Arena, StatementContinue);
+  EXPECT_TRUE(
+  treeDumpEqual(Copy, StatementContinue->dump(Arena->getSourceManager(;
+  // FIXME: Test that copy is independent of original, once the Mutations API is
+  // more developed.
+}
+
+TEST_P(SynthesisTest, DeepCopy_Original) {
+  auto *OriginalTree = buildTree("int a;", GetParam());
+
+  auto *Copy = deepCopy(*Arena, OriginalTree);
+  EXPECT_TRUE(treeDumpEqual(Copy, R"txt(
+TranslationUnit Detached synthesized
+`-SimpleDeclaration synthesized
+  |-'int' synthesized
+  |-SimpleDeclarator Declarator synthesized
+  | `-'a' synthesized
+  `-';' synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, DeepCopy_Child) {
+  auto *OriginalTree = buildTree("int a;", GetParam());
+
+  auto *Copy = deepCopy(*Arena, OriginalTree->getFirstChild());
+  EXPECT_TRUE(treeDumpEqual(Copy, R"txt(
+SimpleDeclaration Detached synthesized
+|-'int' synthesized
+|-SimpleDeclarator Declarator synthesized
+| `-'a' synthesized
+`-';' synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, DeepCopy_Macro) {
+  auto *OriginalTree = buildTree(R"cpp(
+#define HALF_IF if (1+
+#define HALF_IF_2 1) {}
+void test() {
+  HALF_IF HALF_IF_2 else {}
+})cpp",
+ GetParam());
+
+  auto *Copy = deepCopy(*Arena, OriginalTree);
+  EXPECT_TRUE(Copy == nullptr);
+}
+
 TEST_P(SynthesisTest, Statement_EmptyStatement) {
   buildTree("", GetParam());
 
Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -28,10 +28,12 @@
   }
 };
 
+// FIXME: `createLeaf` is based on `syntax::tokenize` internally, as such it
+// doesn't support digraphs or line continuations.
 syntax::Leaf *clang::syntax::createLeaf(syntax::Arena &A, tok::TokenKind K,
 StringRef Spelling) {
   auto Tokens =
-  FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBuffer(Spelling))
+  FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBufferCopy(Spelling))
   .second;
   assert(Tokens.size() == 1);
   assert(Tokens.front().kind() == K &&
@@ -184,6 +186,7 @@
   }
   llvm_unreachable("unknown node kind");
 }
+
 } // namespace
 
 syntax::Tree *clang::syntax::createTree(
@@ -192,14 +195,52 @@
 syntax::NodeKind K) {
   auto *T = allocateTree(A, K);
   FactoryImpl::setCanModify(T);
-  for (auto ChildIt = Children.rbegin(); ChildIt != Children.rend();
-   std::advance(ChildIt, 1))
+  for (auto ChildIt = Children.rbegin(); ChildIt != Children.rend(); ++ChildIt)
 FactoryImpl::prependChildLowLevel(T, ChildIt->first, ChildIt->second);
 
   T->assertInvariants();
   return T;
 }
 
+namespace {
+bool canModifyAllDescendants(const syntax::Node *N) {
+  if (const auto *L = dyn_cast(N))
+return L->canModify();
+
+  const auto *T = cast(N);
+
+  if (!T->canModify())
+return false;
+  for (const auto *Child = T->getFirstChild(); Child;
+   Child = Child->getNextSibling())
+if (!canModifyAllDescendants(Child))
+  return false;
+
+  return true;
+}
+
+syntax::Node *deepCopyImpl(syntax::Arena &A, const syntax::Node *N) {
+  if (const auto *L = dyn_cast(N))
+return createLeaf(A, L->getToken()->kind(),
+  L->getToken()->text(A.getSourceManager()));
+
+  const auto *T = cast(N);
+  std::vector> Children;
+  for (const auto *Child = T->getFirstChild(); Child;
+   Child = Child->getNextSibling())
+Children.push_back({deepCopyImpl(A, Child), Child->getRole()});
+
+  return createTree(A, Children, N->getKind());
+}
+} // namespace
+
+syntax::Node *clang::syntax::deepCopy(syntax::Arena &A, const Node *N) {
+  if (!canModifyAllDescendants(N))
+return nullptr;
+
+  return deepCo

[PATCH] D82445: [analyzer][solver] Track symbol equivalence

2020-09-21 Thread Gabor Marton via Phabricator via cfe-commits
martong added a subscriber: steakhal.
martong added a comment.

Hi Valery,

Together with @steakhal we have found a serious issue.
The below code crashes if you compile with `-DEXPENSIVE_CHECKS`.
The analyzer goes on an unfeasible path, the State has a contradiction.

We think that `getRange(Sym("a != b")` should return a set that does not 
contain `0`.
https://github.com/llvm/llvm-project/blob/e63b488f2755f91e8147fd678ed525cf6ba007cc/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp#L2064
Currently that goes down to `infer(QualType("int"))` which results a 
`RangeSet[INT_MIN, INT_MAX]`.
Stach trace attached.

  // RUN: %clang_analyze_cc1 %s \
  // RUN:   -analyzer-checker=core \
  // RUN:   -analyzer-checker=debug.ExprInspection \
  // RUN:   -triple x86_64-unknown-linux \
  // RUN:   -verify
  
  // expected-no-diagnostics
  
  void f(int a, int b) {
int c = b - a;
if (c <= 0)
  return;
// c > 0
// b - a > 0
// b > a
if (a != b)
  return;
// a == b
// This is an unfeasible path, the State has a contradiction.
if (c < 0) // crash here
  ;
  }



  #0  (anonymous 
namespace)::SymbolicRangeInferrer::inferRange 
(BV=..., F=..., State=..., Origin=0x55b9979bed08) at 
../../git/llvm-project/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:715
  #1  0x7fa2314dddc9 in (anonymous 
namespace)::RangeConstraintManager::getRange (this=0x55b99791ab10, State=..., 
Sym=0x55b9979bed08) at 
../../git/llvm-project/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:2012
  #2  0x7fa2314de1e9 in (anonymous 
namespace)::RangeConstraintManager::assumeSymEQ (this=0x55b99791ab10, St=..., 
Sym=0x55b9979bed08, Int=..., Adjustment=...) at 
../../git/llvm-project/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:2064
  #3  0x7fa23150470d in 
clang::ento::RangedConstraintManager::assumeSymUnsupported 
(this=0x55b99791ab10, State=..., Sym=0x55b9979bed08, Assumption=false) at 
../../git/llvm-project/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp:136
  #4  0x7fa2315353a9 in clang::ento::SimpleConstraintManager::assumeAux 
(this=0x55b99791ab10, State=..., Cond=..., Assumption=false) at 
../../git/llvm-project/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:62
  #5  0x7fa23153518b in clang::ento::SimpleConstraintManager::assume 
(this=0x55b99791ab10, State=..., Cond=..., Assumption=false) at 
../../git/llvm-project/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:46
  #6  0x7fa2315350e5 in clang::ento::SimpleConstraintManager::assume 
(this=0x55b99791ab10, State=..., Cond=..., Assumption=false) at 
../../git/llvm-project/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:41
  #7  0x7fa2313d39b3 in clang::ento::ConstraintManager::assumeDual 
(this=0x55b99791ab10, State=..., Cond=...) at 
../../git/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h:105
  #8  0x7fa2313d3bfc in clang::ento::ProgramState::assume 
(this=0x55b9979beef8, Cond=...) at 
../../git/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h:681
  #9  0x7fa231436b8a in 
clang::ento::ExprEngine::evalEagerlyAssumeBinOpBifurcation 
(this=0x7fffdf9ce9d0, Dst=..., Src=..., Ex=0x55b9979893f0) at 
../../git/llvm-project/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:3058


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82445

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


[PATCH] D85118: [clang][AArch64] Correct return type of Neon vqmovun intrinsics

2020-09-21 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett updated this revision to Diff 293090.
DavidSpickett added a comment.

Rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85118

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/test/CodeGen/aarch64-neon-intrinsics.c
  clang/test/CodeGen/aarch64-neon-misc.c
  clang/test/Sema/arm64-neon-header.c


Index: clang/test/Sema/arm64-neon-header.c
===
--- clang/test/Sema/arm64-neon-header.c
+++ clang/test/Sema/arm64-neon-header.c
@@ -2,6 +2,6 @@
 
 #include 
 
-int16x8_t foo(int8x8_t p0, int16x8_t p1) {
+int16x8_t foo(uint8x8_t p0, int16x8_t p1) {
   return vqmovun_high_s16(p0, p1); // expected-warning {{incompatible vector 
types returning 'uint8x16_t'}}
 }
Index: clang/test/CodeGen/aarch64-neon-misc.c
===
--- clang/test/CodeGen/aarch64-neon-misc.c
+++ clang/test/CodeGen/aarch64-neon-misc.c
@@ -1908,7 +1908,7 @@
 // CHECK:   [[VQMOVUN_V1_I_I:%.*]] = call <8 x i8> 
@llvm.aarch64.neon.sqxtun.v8i8(<8 x i16> %b)
 // CHECK:   [[SHUFFLE_I_I:%.*]] = shufflevector <8 x i8> %a, <8 x i8> 
[[VQMOVUN_V1_I_I]], <16 x i32> 
 // CHECK:   ret <16 x i8> [[SHUFFLE_I_I]]
-int8x16_t test_vqmovun_high_s16(int8x8_t a, int16x8_t b) {
+uint8x16_t test_vqmovun_high_s16(uint8x8_t a, int16x8_t b) {
   return vqmovun_high_s16(a, b);
 }
 
@@ -1918,7 +1918,7 @@
 // CHECK:   [[VQMOVUN_V2_I_I:%.*]] = bitcast <4 x i16> [[VQMOVUN_V1_I_I]] to 
<8 x i8>
 // CHECK:   [[SHUFFLE_I_I:%.*]] = shufflevector <4 x i16> %a, <4 x i16> 
[[VQMOVUN_V1_I_I]], <8 x i32> 
 // CHECK:   ret <8 x i16> [[SHUFFLE_I_I]]
-int16x8_t test_vqmovun_high_s32(int16x4_t a, int32x4_t b) {
+uint16x8_t test_vqmovun_high_s32(uint16x4_t a, int32x4_t b) {
   return vqmovun_high_s32(a, b);
 }
 
@@ -1928,7 +1928,7 @@
 // CHECK:   [[VQMOVUN_V2_I_I:%.*]] = bitcast <2 x i32> [[VQMOVUN_V1_I_I]] to 
<8 x i8>
 // CHECK:   [[SHUFFLE_I_I:%.*]] = shufflevector <2 x i32> %a, <2 x i32> 
[[VQMOVUN_V1_I_I]], <4 x i32> 
 // CHECK:   ret <4 x i32> [[SHUFFLE_I_I]]
-int32x4_t test_vqmovun_high_s64(int32x2_t a, int64x2_t b) {
+uint32x4_t test_vqmovun_high_s64(uint32x2_t a, int64x2_t b) {
   return vqmovun_high_s64(a, b);
 }
 
Index: clang/test/CodeGen/aarch64-neon-intrinsics.c
===
--- clang/test/CodeGen/aarch64-neon-intrinsics.c
+++ clang/test/CodeGen/aarch64-neon-intrinsics.c
@@ -14094,8 +14094,8 @@
 // CHECK:   [[VQMOVUNH_S16_I:%.*]] = call <8 x i8> 
@llvm.aarch64.neon.sqxtun.v8i8(<8 x i16> [[TMP0]])
 // CHECK:   [[TMP1:%.*]] = extractelement <8 x i8> [[VQMOVUNH_S16_I]], i64 0
 // CHECK:   ret i8 [[TMP1]]
-int8_t test_vqmovunh_s16(int16_t a) {
-  return (int8_t)vqmovunh_s16(a);
+uint8_t test_vqmovunh_s16(int16_t a) {
+  return (uint8_t)vqmovunh_s16(a);
 }
 
 // CHECK-LABEL: @test_vqmovuns_s32(
@@ -14103,15 +14103,15 @@
 // CHECK:   [[VQMOVUNS_S32_I:%.*]] = call <4 x i16> 
@llvm.aarch64.neon.sqxtun.v4i16(<4 x i32> [[TMP0]])
 // CHECK:   [[TMP1:%.*]] = extractelement <4 x i16> [[VQMOVUNS_S32_I]], i64 0
 // CHECK:   ret i16 [[TMP1]]
-int16_t test_vqmovuns_s32(int32_t a) {
-  return (int16_t)vqmovuns_s32(a);
+uint16_t test_vqmovuns_s32(int32_t a) {
+  return (uint16_t)vqmovuns_s32(a);
 }
 
 // CHECK-LABEL: @test_vqmovund_s64(
 // CHECK:   [[VQMOVUND_S64_I:%.*]] = call i32 
@llvm.aarch64.neon.scalar.sqxtun.i32.i64(i64 %a)
 // CHECK:   ret i32 [[VQMOVUND_S64_I]]
-int32_t test_vqmovund_s64(int64_t a) {
-  return (int32_t)vqmovund_s64(a);
+uint32_t test_vqmovund_s64(int64_t a) {
+  return (uint32_t)vqmovund_s64(a);
 }
 
 // CHECK-LABEL: @test_vqmovnh_s16(
Index: clang/include/clang/Basic/arm_neon.td
===
--- clang/include/clang/Basic/arm_neon.td
+++ clang/include/clang/Basic/arm_neon.td
@@ -830,7 +830,7 @@
 
 

 // Signed integer saturating extract and unsigned narrow to high
-def SQXTUN2 : SOpInst<"vqmovun_high", "(;
+def SQXTUN2 : SOpInst<"vqmovun_high", "(;
 
 

 // Integer saturating extract and narrow to high
@@ -1498,7 +1498,7 @@
 
 

 // Scalar Signed Saturating Extract Unsigned Narrow
-def SCALAR_SQXTUN : SInst<"vqmovun", "(1<)1", "SsSiSl">;
+def SCALAR_SQXTUN : SInst<"vqmovun", "(U1<)1", "SsSiSl">;
 
 

 // Scalar Signed Saturating Extract Narrow


Index: clang/test/Sema/arm64-neon-header.c
===
--- clang/test/Sema/arm64-neon-header.c
+++ clang/test/Sema/arm64-neon-header.c
@@ -2,6 +2,6 @@
 
 #include 
 
-int16x8_t foo(int8x8_t p0, int16x8_t p1) {
+int16x8_t foo(uint8x

[PATCH] D85118: [clang][AArch64] Correct return type of Neon vqmovun intrinsics

2020-09-21 Thread David Spickett via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG349af8054218: [clang][AArch64] Correct return type of Neon 
vqmovun intrinsics (authored by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85118

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/test/CodeGen/aarch64-neon-intrinsics.c
  clang/test/CodeGen/aarch64-neon-misc.c
  clang/test/Sema/arm64-neon-header.c


Index: clang/test/Sema/arm64-neon-header.c
===
--- clang/test/Sema/arm64-neon-header.c
+++ clang/test/Sema/arm64-neon-header.c
@@ -2,6 +2,6 @@
 
 #include 
 
-int16x8_t foo(int8x8_t p0, int16x8_t p1) {
+int16x8_t foo(uint8x8_t p0, int16x8_t p1) {
   return vqmovun_high_s16(p0, p1); // expected-warning {{incompatible vector 
types returning 'uint8x16_t'}}
 }
Index: clang/test/CodeGen/aarch64-neon-misc.c
===
--- clang/test/CodeGen/aarch64-neon-misc.c
+++ clang/test/CodeGen/aarch64-neon-misc.c
@@ -1908,7 +1908,7 @@
 // CHECK:   [[VQMOVUN_V1_I_I:%.*]] = call <8 x i8> 
@llvm.aarch64.neon.sqxtun.v8i8(<8 x i16> %b)
 // CHECK:   [[SHUFFLE_I_I:%.*]] = shufflevector <8 x i8> %a, <8 x i8> 
[[VQMOVUN_V1_I_I]], <16 x i32> 
 // CHECK:   ret <16 x i8> [[SHUFFLE_I_I]]
-int8x16_t test_vqmovun_high_s16(int8x8_t a, int16x8_t b) {
+uint8x16_t test_vqmovun_high_s16(uint8x8_t a, int16x8_t b) {
   return vqmovun_high_s16(a, b);
 }
 
@@ -1918,7 +1918,7 @@
 // CHECK:   [[VQMOVUN_V2_I_I:%.*]] = bitcast <4 x i16> [[VQMOVUN_V1_I_I]] to 
<8 x i8>
 // CHECK:   [[SHUFFLE_I_I:%.*]] = shufflevector <4 x i16> %a, <4 x i16> 
[[VQMOVUN_V1_I_I]], <8 x i32> 
 // CHECK:   ret <8 x i16> [[SHUFFLE_I_I]]
-int16x8_t test_vqmovun_high_s32(int16x4_t a, int32x4_t b) {
+uint16x8_t test_vqmovun_high_s32(uint16x4_t a, int32x4_t b) {
   return vqmovun_high_s32(a, b);
 }
 
@@ -1928,7 +1928,7 @@
 // CHECK:   [[VQMOVUN_V2_I_I:%.*]] = bitcast <2 x i32> [[VQMOVUN_V1_I_I]] to 
<8 x i8>
 // CHECK:   [[SHUFFLE_I_I:%.*]] = shufflevector <2 x i32> %a, <2 x i32> 
[[VQMOVUN_V1_I_I]], <4 x i32> 
 // CHECK:   ret <4 x i32> [[SHUFFLE_I_I]]
-int32x4_t test_vqmovun_high_s64(int32x2_t a, int64x2_t b) {
+uint32x4_t test_vqmovun_high_s64(uint32x2_t a, int64x2_t b) {
   return vqmovun_high_s64(a, b);
 }
 
Index: clang/test/CodeGen/aarch64-neon-intrinsics.c
===
--- clang/test/CodeGen/aarch64-neon-intrinsics.c
+++ clang/test/CodeGen/aarch64-neon-intrinsics.c
@@ -14094,8 +14094,8 @@
 // CHECK:   [[VQMOVUNH_S16_I:%.*]] = call <8 x i8> 
@llvm.aarch64.neon.sqxtun.v8i8(<8 x i16> [[TMP0]])
 // CHECK:   [[TMP1:%.*]] = extractelement <8 x i8> [[VQMOVUNH_S16_I]], i64 0
 // CHECK:   ret i8 [[TMP1]]
-int8_t test_vqmovunh_s16(int16_t a) {
-  return (int8_t)vqmovunh_s16(a);
+uint8_t test_vqmovunh_s16(int16_t a) {
+  return (uint8_t)vqmovunh_s16(a);
 }
 
 // CHECK-LABEL: @test_vqmovuns_s32(
@@ -14103,15 +14103,15 @@
 // CHECK:   [[VQMOVUNS_S32_I:%.*]] = call <4 x i16> 
@llvm.aarch64.neon.sqxtun.v4i16(<4 x i32> [[TMP0]])
 // CHECK:   [[TMP1:%.*]] = extractelement <4 x i16> [[VQMOVUNS_S32_I]], i64 0
 // CHECK:   ret i16 [[TMP1]]
-int16_t test_vqmovuns_s32(int32_t a) {
-  return (int16_t)vqmovuns_s32(a);
+uint16_t test_vqmovuns_s32(int32_t a) {
+  return (uint16_t)vqmovuns_s32(a);
 }
 
 // CHECK-LABEL: @test_vqmovund_s64(
 // CHECK:   [[VQMOVUND_S64_I:%.*]] = call i32 
@llvm.aarch64.neon.scalar.sqxtun.i32.i64(i64 %a)
 // CHECK:   ret i32 [[VQMOVUND_S64_I]]
-int32_t test_vqmovund_s64(int64_t a) {
-  return (int32_t)vqmovund_s64(a);
+uint32_t test_vqmovund_s64(int64_t a) {
+  return (uint32_t)vqmovund_s64(a);
 }
 
 // CHECK-LABEL: @test_vqmovnh_s16(
Index: clang/include/clang/Basic/arm_neon.td
===
--- clang/include/clang/Basic/arm_neon.td
+++ clang/include/clang/Basic/arm_neon.td
@@ -830,7 +830,7 @@
 
 

 // Signed integer saturating extract and unsigned narrow to high
-def SQXTUN2 : SOpInst<"vqmovun_high", "(;
+def SQXTUN2 : SOpInst<"vqmovun_high", "(;
 
 

 // Integer saturating extract and narrow to high
@@ -1498,7 +1498,7 @@
 
 

 // Scalar Signed Saturating Extract Unsigned Narrow
-def SCALAR_SQXTUN : SInst<"vqmovun", "(1<)1", "SsSiSl">;
+def SCALAR_SQXTUN : SInst<"vqmovun", "(U1<)1", "SsSiSl">;
 
 

 // Scalar Signed Saturating Extract Narrow


Index: clang/test/Sema/arm64-neon-header.c
===
--- clang/te

[clang] 349af80 - [clang][AArch64] Correct return type of Neon vqmovun intrinsics

2020-09-21 Thread David Spickett via cfe-commits

Author: David Spickett
Date: 2020-09-21T09:21:51+01:00
New Revision: 349af8054218017a2ac0c4bfeddd63e6ccbf4a21

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

LOG: [clang][AArch64] Correct return type of Neon vqmovun intrinsics

Neon intrinsics vqmovunh_s16, vqmovuns_s32, vqmovund_s64
should have unsigned return types.

See 
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vqmovun

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

Reviewed By: efriedma

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

Added: 


Modified: 
clang/include/clang/Basic/arm_neon.td
clang/test/CodeGen/aarch64-neon-intrinsics.c
clang/test/CodeGen/aarch64-neon-misc.c
clang/test/Sema/arm64-neon-header.c

Removed: 




diff  --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index d0269f31c32d..6369e5a8e342 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -830,7 +830,7 @@ def XTN2 : SOpInst<"vmovn_high", "(;
 
 

 // Signed integer saturating extract and unsigned narrow to high
-def SQXTUN2 : SOpInst<"vqmovun_high", "(;
+def SQXTUN2 : SOpInst<"vqmovun_high", "(;
 
 

 // Integer saturating extract and narrow to high
@@ -1498,7 +1498,7 @@ def SCALAR_SQDMULL : SInst<"vqdmull", "(1>)11", "SsSi">;
 
 

 // Scalar Signed Saturating Extract Unsigned Narrow
-def SCALAR_SQXTUN : SInst<"vqmovun", "(1<)1", "SsSiSl">;
+def SCALAR_SQXTUN : SInst<"vqmovun", "(U1<)1", "SsSiSl">;
 
 

 // Scalar Signed Saturating Extract Narrow

diff  --git a/clang/test/CodeGen/aarch64-neon-intrinsics.c 
b/clang/test/CodeGen/aarch64-neon-intrinsics.c
index de7e77025605..89632fcd0a98 100644
--- a/clang/test/CodeGen/aarch64-neon-intrinsics.c
+++ b/clang/test/CodeGen/aarch64-neon-intrinsics.c
@@ -14094,8 +14094,8 @@ int64_t test_vqdmulls_s32(int32_t a, int32_t b) {
 // CHECK:   [[VQMOVUNH_S16_I:%.*]] = call <8 x i8> 
@llvm.aarch64.neon.sqxtun.v8i8(<8 x i16> [[TMP0]])
 // CHECK:   [[TMP1:%.*]] = extractelement <8 x i8> [[VQMOVUNH_S16_I]], i64 0
 // CHECK:   ret i8 [[TMP1]]
-int8_t test_vqmovunh_s16(int16_t a) {
-  return (int8_t)vqmovunh_s16(a);
+uint8_t test_vqmovunh_s16(int16_t a) {
+  return (uint8_t)vqmovunh_s16(a);
 }
 
 // CHECK-LABEL: @test_vqmovuns_s32(
@@ -14103,15 +14103,15 @@ int8_t test_vqmovunh_s16(int16_t a) {
 // CHECK:   [[VQMOVUNS_S32_I:%.*]] = call <4 x i16> 
@llvm.aarch64.neon.sqxtun.v4i16(<4 x i32> [[TMP0]])
 // CHECK:   [[TMP1:%.*]] = extractelement <4 x i16> [[VQMOVUNS_S32_I]], i64 0
 // CHECK:   ret i16 [[TMP1]]
-int16_t test_vqmovuns_s32(int32_t a) {
-  return (int16_t)vqmovuns_s32(a);
+uint16_t test_vqmovuns_s32(int32_t a) {
+  return (uint16_t)vqmovuns_s32(a);
 }
 
 // CHECK-LABEL: @test_vqmovund_s64(
 // CHECK:   [[VQMOVUND_S64_I:%.*]] = call i32 
@llvm.aarch64.neon.scalar.sqxtun.i32.i64(i64 %a)
 // CHECK:   ret i32 [[VQMOVUND_S64_I]]
-int32_t test_vqmovund_s64(int64_t a) {
-  return (int32_t)vqmovund_s64(a);
+uint32_t test_vqmovund_s64(int64_t a) {
+  return (uint32_t)vqmovund_s64(a);
 }
 
 // CHECK-LABEL: @test_vqmovnh_s16(

diff  --git a/clang/test/CodeGen/aarch64-neon-misc.c 
b/clang/test/CodeGen/aarch64-neon-misc.c
index 14b5a357f61e..88020a1a69c2 100644
--- a/clang/test/CodeGen/aarch64-neon-misc.c
+++ b/clang/test/CodeGen/aarch64-neon-misc.c
@@ -1908,7 +1908,7 @@ int32x2_t test_vqmovun_s64(int64x2_t a) {
 // CHECK:   [[VQMOVUN_V1_I_I:%.*]] = call <8 x i8> 
@llvm.aarch64.neon.sqxtun.v8i8(<8 x i16> %b)
 // CHECK:   [[SHUFFLE_I_I:%.*]] = shufflevector <8 x i8> %a, <8 x i8> 
[[VQMOVUN_V1_I_I]], <16 x i32> 
 // CHECK:   ret <16 x i8> [[SHUFFLE_I_I]]
-int8x16_t test_vqmovun_high_s16(int8x8_t a, int16x8_t b) {
+uint8x16_t test_vqmovun_high_s16(uint8x8_t a, int16x8_t b) {
   return vqmovun_high_s16(a, b);
 }
 
@@ -1918,7 +1918,7 @@ int8x16_t test_vqmovun_high_s16(int8x8_t a, int16x8_t b) {
 // CHECK:   [[VQMOVUN_V2_I_I:%.*]] = bitcast <4 x i16> [[VQMOVUN_V1_I_I]] to 
<8 x i8>
 // CHECK:   [[SHUFFLE_I_I:%.*]] = shufflevector <4 x i16> %a, <4 x i16> 
[[VQMOVUN_V1_I_I]], <8 x i32> 
 // CHECK:   ret <8 x i16> [[SHUFFLE_I_I]]
-int16x8_t test_vqmovun_high_s32(int16x4_t a, int32x4_t b) {
+uint16x8_t test_vqmovun_high_s32(uint16x4_t a, int32x4_t b) {
   return vqmovun_high_s32(a, b);
 }
 
@@ -1928,7 +1928,7 @@ int16x8_t test_vqmovun_high_s32(int16x4_t a, int32x4_t b) 
{
 // CHECK:   [[VQMOVUN_V2_I_I:%.*]] = bitcast <2 x i32> [[VQMOVUN_V1_I_I]] to 
<8 x i8>
 // CHECK

[PATCH] D86629: [AVR][clang] Pass the address of the data section to the linker for ATmega328

2020-09-21 Thread Dylan McKay via Phabricator via cfe-commits
dylanmckay added a comment.

Hey @aykevl, could you please confirm that this patch looks okay?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86629

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


[PATCH] D87256: [clangd] Avoid relations being overwritten in a header shard

2020-09-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/FileIndex.cpp:152
+  // Attribute relations to both their subject's and object's locations.
+  // See https://github.com/clangd/clangd/issues/510 for discussion of why.
   if (Index.Relations) {

instead of (or in addition to) providing the link, can we give a short summary? 
e.g.

```
Subject and/or Object files might be part of multiple TUs. In such cases there 
will be a race
and last TU to write the shard will win and all the other relations will be 
lost. We are storing
relations in both places, as we do for symbols, to reduce such races. Note that 
they might still
happen if same translation unit produces different relations under different 
configurations
but that's something clangd doesn't handle in general. 
```



Comment at: clang-tools-extra/clangd/index/FileIndex.cpp:350
   AllRelations.push_back(R);
+// Sort relations and remove duplicates that could arise due to
+// relations being stored in both the shards containing their

can you move this outside of the for loop, so that we do it only once.



Comment at: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp:232
 
+TEST_F(BackgroundIndexTest, RelationsMultiFile) {
+  MockFS FS;

do we still need this test?



Comment at: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp:396
   SymbolID B = findSymbol(*ShardSource->Symbols, "B_CC").ID;
-  EXPECT_THAT(*ShardHeader->Relations,
+  EXPECT_THAT(*ShardSource->Relations,
+  UnorderedElementsAre(Relation{A, RelationKind::BaseOf, B}));

s/ShardSource/ShardHeader



Comment at: clang-tools-extra/clangd/unittests/FileIndexTests.cpp:571
 B.insert(Relation{Sym2.ID, RelationKind::BaseOf, Sym1.ID});
-// Dangling relation should be dropped.
-B.insert(Relation{symbol("3").ID, RelationKind::BaseOf, Sym1.ID});
+// Should be stored in a.h even though it's dangling
+B.insert(Relation{Sym3.ID, RelationKind::BaseOf, Sym1.ID});

maybe mention that `Sym1` belongs to `a.h` in the comment. `stored in a.h 
(where Sym1 is stored) even tho the reference is dangling as Sym3 is unknown `


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87256

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


[PATCH] D87080: [AST] Reduce the size of TemplateArgumentLocInfo.

2020-09-21 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 293094.
hokein marked 2 inline comments as done.
hokein added a comment.

address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87080

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp

Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -7095,15 +7095,15 @@
 NestedNameSpecifierLoc QualifierLoc =
   readNestedNameSpecifierLoc();
 SourceLocation TemplateNameLoc = readSourceLocation();
-return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
-   SourceLocation());
+return TemplateArgumentLocInfo(getASTContext(), QualifierLoc,
+   TemplateNameLoc, SourceLocation());
   }
   case TemplateArgument::TemplateExpansion: {
 NestedNameSpecifierLoc QualifierLoc = readNestedNameSpecifierLoc();
 SourceLocation TemplateNameLoc = readSourceLocation();
 SourceLocation EllipsisLoc = readSourceLocation();
-return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
-   EllipsisLoc);
+return TemplateArgumentLocInfo(getASTContext(), QualifierLoc,
+   TemplateNameLoc, EllipsisLoc);
   }
   case TemplateArgument::Null:
   case TemplateArgument::Integral:
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3546,12 +3546,12 @@
 }
 
 case TemplateArgument::Template:
-  return TemplateArgumentLoc(TemplateArgument(
-  Pattern.getArgument().getAsTemplate(),
-  NumExpansions),
- Pattern.getTemplateQualifierLoc(),
- Pattern.getTemplateNameLoc(),
- EllipsisLoc);
+  return TemplateArgumentLoc(
+  SemaRef.Context,
+  TemplateArgument(Pattern.getArgument().getAsTemplate(),
+   NumExpansions),
+  Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
+  EllipsisLoc);
 
 case TemplateArgument::Null:
 case TemplateArgument::Integral:
@@ -4289,8 +4289,8 @@
 if (Template.isNull())
   return true;
 
-Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
- Input.getTemplateNameLoc());
+Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
+ QualifierLoc, Input.getTemplateNameLoc());
 return false;
   }
 
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1095,7 +1095,7 @@
   case TemplateArgument::TemplateExpansion:
 Ellipsis = OrigLoc.getTemplateEllipsisLoc();
 NumExpansions = Argument.getNumTemplateExpansions();
-return TemplateArgumentLoc(Argument.getPackExpansionPattern(),
+return TemplateArgumentLoc(Context, Argument.getPackExpansionPattern(),
OrigLoc.getTemplateQualifierLoc(),
OrigLoc.getTemplateNameLoc());
 
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2915,7 +2915,7 @@
 if (!TName.isNull())
   Param->setDefaultArgument(
   SemaRef.Context,
-  TemplateArgumentLoc(TemplateArgument(TName),
+  TemplateArgumentLoc(SemaRef.Context, TemplateArgument(TName),
   D->getDefaultArgument().getTemplateQualifierLoc(),
   D->getDefaultArgument().getTemplateNameLoc()));
   }
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2670,11 +2670,11 @@
 Builder.MakeTrivial(Context, QTN->getQualifier(), Loc);
 
   if (Arg.getKind() == TemplateArgument::Template)
-return TemplateArgumentLoc(Arg, Builder.getWithLocInContext(Context),
-

[PATCH] D87080: [AST] Reduce the size of TemplateArgumentLocInfo.

2020-09-21 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/AST/Expr.h:963
 };
+static_assert(llvm::PointerLikeTypeTraits::SpecializationForExpr,
+  "Specialization in TemplateBase.h must be seen here");

sammccall wrote:
> I think this is it:
> ```
> // PointerLikeTypeTraits is specialized so it can be used with a forward-decl 
> of Expr.
> // Verify that we got it right.
> static_assert((1 << PointerLikeTypeTraits::NumLowBitsAvailable) == 
> alignof(Expr), "PointerLikeTypeTraits assumes too much alignment");
> ```
> 
> (Or just `% alignof(Expr) == 0` if you want a weaker condition)
Ah, thanks. `alignof(Expr)` is 8, I feel like comparing the Numbits directly 
seems more easy to understand. 



Comment at: clang/include/clang/AST/TemplateBase.h:43
+// the dependency.
+template <> struct PointerLikeTypeTraits {
+  static inline void *getAsVoidPointer(clang::Expr *P) { return P; }

sammccall wrote:
> rsmith wrote:
> > hokein wrote:
> > > sammccall wrote:
> > > > At first glance this is unsafe: you could have two different 
> > > > definitions of the same specialization in different files.
> > > > 
> > > > In fact it's OK, the default one can now never be instantiated, because 
> > > > Expr.h includes this file and so anyone that can see the definition can 
> > > > see this specialization.
> > > > 
> > > > But this is subtle/fragile: at least it needs to be spelled out 
> > > > explicitly in the comment.
> > > > I'd also suggest adding a static assert below the definition of Expr 
> > > > that it is compatible with this specialization (because it is 
> > > > sufficiently aligned).
> > > > 
> > > > (I can't think of a better alternative - use of PointerUnion is a win, 
> > > > partly *because* it validates the alignment)
> > > yes, exactly. 
> > > 
> > > do you have a better idea on how the static_assert should look like? The 
> > > way I can think of is to add a new flag in this specialization, and use 
> > > `static_assert(PointerLikeTypeTraits::flag, "...")`.
> > This may be included from `Expr.h` right now, but really doesn't seem like 
> > the right header to hold this specialization. Perhaps we should consider 
> > adding something like an `AST/ForwardDecls.h`, containing forward 
> > declarations and specializations such as this one, and include that from 
> > `Expr.h` and from here?
> I also had this thought but wasn't sure. @hokein maybe a trivial followup 
> patch rather than inline here?
that sounds good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87080

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


[PATCH] D88004: [SyntaxTree][NFC] follow naming convention + remove auto on empty vector declaration

2020-09-21 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88004

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/lib/Tooling/Syntax/Tree.cpp

Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -153,7 +153,7 @@
 
 static void dumpNode(raw_ostream &OS, const syntax::Node *N,
  const SourceManager &SM, std::vector IndentMask) {
-  auto dumpExtraInfo = [&OS](const syntax::Node *N) {
+  auto DumpExtraInfo = [&OS](const syntax::Node *N) {
 if (N->getRole() != syntax::NodeRole::Unknown)
   OS << " " << N->getRole();
 if (!N->isOriginal())
@@ -167,14 +167,14 @@
 OS << "'";
 dumpLeaf(OS, L, SM);
 OS << "'";
-dumpExtraInfo(N);
+DumpExtraInfo(N);
 OS << "\n";
 return;
   }
 
   const auto *T = cast(N);
   OS << T->getKind();
-  dumpExtraInfo(N);
+  DumpExtraInfo(N);
   OS << "\n";
 
   for (const auto *It = T->getFirstChild(); It; It = It->getNextSibling()) {
@@ -302,20 +302,20 @@
   if (!getFirstChild())
 return {};
 
-  auto children = std::vector>();
-  syntax::Node *elementWithoutDelimiter = nullptr;
+  std::vector> Children;
+  syntax::Node *ElementWithoutDelimiter = nullptr;
   for (auto *C = getFirstChild(); C; C = C->getNextSibling()) {
 switch (C->getRole()) {
 case syntax::NodeRole::ListElement: {
-  if (elementWithoutDelimiter) {
-children.push_back({elementWithoutDelimiter, nullptr});
+  if (ElementWithoutDelimiter) {
+Children.push_back({ElementWithoutDelimiter, nullptr});
   }
-  elementWithoutDelimiter = C;
+  ElementWithoutDelimiter = C;
   break;
 }
 case syntax::NodeRole::ListDelimiter: {
-  children.push_back({elementWithoutDelimiter, cast(C)});
-  elementWithoutDelimiter = nullptr;
+  Children.push_back({ElementWithoutDelimiter, cast(C)});
+  ElementWithoutDelimiter = nullptr;
   break;
 }
 default:
@@ -326,19 +326,19 @@
 
   switch (getTerminationKind()) {
   case syntax::List::TerminationKind::Separated: {
-children.push_back({elementWithoutDelimiter, nullptr});
+Children.push_back({ElementWithoutDelimiter, nullptr});
 break;
   }
   case syntax::List::TerminationKind::Terminated:
   case syntax::List::TerminationKind::MaybeTerminated: {
-if (elementWithoutDelimiter) {
-  children.push_back({elementWithoutDelimiter, nullptr});
+if (ElementWithoutDelimiter) {
+  Children.push_back({ElementWithoutDelimiter, nullptr});
 }
 break;
   }
   }
 
-  return children;
+  return Children;
 }
 
 // Almost the same implementation of `getElementsAsNodesAndDelimiters` but
@@ -347,20 +347,20 @@
   if (!getFirstChild())
 return {};
 
-  auto children = std::vector();
-  syntax::Node *elementWithoutDelimiter = nullptr;
+  std::vector Children;
+  syntax::Node *ElementWithoutDelimiter = nullptr;
   for (auto *C = getFirstChild(); C; C = C->getNextSibling()) {
 switch (C->getRole()) {
 case syntax::NodeRole::ListElement: {
-  if (elementWithoutDelimiter) {
-children.push_back(elementWithoutDelimiter);
+  if (ElementWithoutDelimiter) {
+Children.push_back(ElementWithoutDelimiter);
   }
-  elementWithoutDelimiter = C;
+  ElementWithoutDelimiter = C;
   break;
 }
 case syntax::NodeRole::ListDelimiter: {
-  children.push_back(elementWithoutDelimiter);
-  elementWithoutDelimiter = nullptr;
+  Children.push_back(ElementWithoutDelimiter);
+  ElementWithoutDelimiter = nullptr;
   break;
 }
 default:
@@ -370,19 +370,19 @@
 
   switch (getTerminationKind()) {
   case syntax::List::TerminationKind::Separated: {
-children.push_back(elementWithoutDelimiter);
+Children.push_back(ElementWithoutDelimiter);
 break;
   }
   case syntax::List::TerminationKind::Terminated:
   case syntax::List::TerminationKind::MaybeTerminated: {
-if (elementWithoutDelimiter) {
-  children.push_back(elementWithoutDelimiter);
+if (ElementWithoutDelimiter) {
+  Children.push_back(ElementWithoutDelimiter);
 }
 break;
   }
   }
 
-  return children;
+  return Children;
 }
 
 clang::tok::TokenKind syntax::List::getDelimiterTokenKind() const {
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -226,23 +226,23 @@
 // vector
 std::vector
 syntax::NestedNameSpecifier::getSpecifiers() {
-  auto specifiersAsNodes = getElementsAsNodes();
+  auto SpecifiersAsNodes = getElementsAsNodes();
   std::vector Children;
-  for (const auto &element : specifiersAsNodes) {
-Children.push_back(llvm

[PATCH] D87816: [clang] Fix incorrect call to TextDiagnostic::printDiagnosticMessage

2020-09-21 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Thanks for reviewing @sanwou01 ! No new comments, so I'll submit as is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87816

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


[PATCH] D88005: [clang] [MinGW] Add an implicit .exe suffix even when crosscompiling

2020-09-21 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added reviewers: rnk, amccarth.
Herald added a project: clang.
mstorsjo requested review of this revision.

GCC 8 changed behaviour wrt this, and made it consistent for cross compilation 
cases. While it's a change, it's a more sensible behaviour going forward.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88005

Files:
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/test/Driver/mingw-implicit-extension-cross.c
  clang/test/Driver/mingw-implicit-extension-windows.c


Index: clang/test/Driver/mingw-implicit-extension-windows.c
===
--- clang/test/Driver/mingw-implicit-extension-windows.c
+++ clang/test/Driver/mingw-implicit-extension-windows.c
@@ -1,8 +1,4 @@
-// Test how an implicit .exe extension is added. If running the compiler
-// on windows, an implicit extension is added if none is provided in the
-// given name. (Therefore, this test is skipped when not running on windows.)
-
-// REQUIRES: system-windows
+// Test how an implicit .exe extension is added.
 
 // RUN: %clang -target i686-windows-gnu -### 
--sysroot=%S/Inputs/mingw_clang_tree/mingw32 %s -o outputname 2>&1 | FileCheck 
%s --check-prefix=CHECK-OUTPUTNAME-EXE
 
Index: clang/test/Driver/mingw-implicit-extension-cross.c
===
--- clang/test/Driver/mingw-implicit-extension-cross.c
+++ /dev/null
@@ -1,9 +0,0 @@
-// Test how an implicit .exe extension is added. If not running the compiler
-// on windows, no implicit extension is added. (Therefore, this test is skipped
-// when running on windows.)
-
-// UNSUPPORTED: system-windows
-
-// RUN: %clang -target i686-windows-gnu -### 
--sysroot=%S/Inputs/mingw_clang_tree/mingw32 %s -o outputname 2>&1 | FileCheck 
%s
-
-// CHECK: "-o" "outputname"
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -164,17 +164,13 @@
   CmdArgs.push_back("-o");
   const char *OutputFile = Output.getFilename();
   // GCC implicitly adds an .exe extension if it is given an output file name
-  // that lacks an extension. However, GCC only does this when actually
-  // running on windows, not when operating as a cross compiler. As some users
-  // have come to rely on this behaviour, try to replicate it.
-#ifdef _WIN32
+  // that lacks an extension.
+  // GCC used to do this only when the compiler itself runs on windows, but
+  // since GCC 8 it does the same when cross compiling as well.
   if (!llvm::sys::path::has_extension(OutputFile))
 CmdArgs.push_back(Args.MakeArgString(Twine(OutputFile) + ".exe"));
   else
 CmdArgs.push_back(OutputFile);
-#else
-  CmdArgs.push_back(OutputFile);
-#endif
 
   Args.AddAllArgs(CmdArgs, options::OPT_e);
   // FIXME: add -N, -n flags


Index: clang/test/Driver/mingw-implicit-extension-windows.c
===
--- clang/test/Driver/mingw-implicit-extension-windows.c
+++ clang/test/Driver/mingw-implicit-extension-windows.c
@@ -1,8 +1,4 @@
-// Test how an implicit .exe extension is added. If running the compiler
-// on windows, an implicit extension is added if none is provided in the
-// given name. (Therefore, this test is skipped when not running on windows.)
-
-// REQUIRES: system-windows
+// Test how an implicit .exe extension is added.
 
 // RUN: %clang -target i686-windows-gnu -### --sysroot=%S/Inputs/mingw_clang_tree/mingw32 %s -o outputname 2>&1 | FileCheck %s --check-prefix=CHECK-OUTPUTNAME-EXE
 
Index: clang/test/Driver/mingw-implicit-extension-cross.c
===
--- clang/test/Driver/mingw-implicit-extension-cross.c
+++ /dev/null
@@ -1,9 +0,0 @@
-// Test how an implicit .exe extension is added. If not running the compiler
-// on windows, no implicit extension is added. (Therefore, this test is skipped
-// when running on windows.)
-
-// UNSUPPORTED: system-windows
-
-// RUN: %clang -target i686-windows-gnu -### --sysroot=%S/Inputs/mingw_clang_tree/mingw32 %s -o outputname 2>&1 | FileCheck %s
-
-// CHECK: "-o" "outputname"
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -164,17 +164,13 @@
   CmdArgs.push_back("-o");
   const char *OutputFile = Output.getFilename();
   // GCC implicitly adds an .exe extension if it is given an output file name
-  // that lacks an extension. However, GCC only does this when actually
-  // running on windows, not when operating as a cross compiler. As some users
-  // have come to rely on this behaviour, try to replicate it.
-#ifdef _WIN32
+  // that lacks an extension.
+  // GCC used to do this only when the compiler itself runs on windows, but
+  // sinc

[clang] 4eae6fc - [clang] Fix incorrect call to TextDiagnostic::printDiagnosticMessage

2020-09-21 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2020-09-21T09:41:39+01:00
New Revision: 4eae6fc95f95563a73a510a8b09cfce01004930a

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

LOG: [clang] Fix incorrect call to TextDiagnostic::printDiagnosticMessage

As per the documentation, the 2nd argument in printDiagnosticMessage
should be a bool that specifies whether the underlying message is a
continuation note diagnostic or not. More specifically, it should be:
```
Level == DiagnosticsEngine::Note
```
instead of:
```
Level
```

This change means that `no input file` in the following scenario will be
now correctly printed in bold:
```
$ bin/clang
clang: error: no input files
```
In terminals that don't support text formatting the behaviour doesn't
change.

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

Added: 


Modified: 
clang/lib/Frontend/TextDiagnosticPrinter.cpp

Removed: 




diff  --git a/clang/lib/Frontend/TextDiagnosticPrinter.cpp 
b/clang/lib/Frontend/TextDiagnosticPrinter.cpp
index 0c0a44a1388b..9feb3c64039f 100644
--- a/clang/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/clang/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -135,10 +135,10 @@ void 
TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
   if (!Info.getLocation().isValid()) {
 TextDiagnostic::printDiagnosticLevel(OS, Level, DiagOpts->ShowColors,
  DiagOpts->CLFallbackMode);
-TextDiagnostic::printDiagnosticMessage(OS, Level, DiagMessageStream.str(),
-   OS.tell() - StartOfLocationInfo,
-   DiagOpts->MessageLength,
-   DiagOpts->ShowColors);
+TextDiagnostic::printDiagnosticMessage(
+OS, /*IsSupplemental=*/Level == DiagnosticsEngine::Note,
+DiagMessageStream.str(), OS.tell() - StartOfLocationInfo,
+DiagOpts->MessageLength, DiagOpts->ShowColors);
 OS.flush();
 return;
   }



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


[PATCH] D87816: [clang] Fix incorrect call to TextDiagnostic::printDiagnosticMessage

2020-09-21 Thread Andrzej Warzynski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4eae6fc95f95: [clang] Fix incorrect call to 
TextDiagnostic::printDiagnosticMessage (authored by awarzynski).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87816

Files:
  clang/lib/Frontend/TextDiagnosticPrinter.cpp


Index: clang/lib/Frontend/TextDiagnosticPrinter.cpp
===
--- clang/lib/Frontend/TextDiagnosticPrinter.cpp
+++ clang/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -135,10 +135,10 @@
   if (!Info.getLocation().isValid()) {
 TextDiagnostic::printDiagnosticLevel(OS, Level, DiagOpts->ShowColors,
  DiagOpts->CLFallbackMode);
-TextDiagnostic::printDiagnosticMessage(OS, Level, DiagMessageStream.str(),
-   OS.tell() - StartOfLocationInfo,
-   DiagOpts->MessageLength,
-   DiagOpts->ShowColors);
+TextDiagnostic::printDiagnosticMessage(
+OS, /*IsSupplemental=*/Level == DiagnosticsEngine::Note,
+DiagMessageStream.str(), OS.tell() - StartOfLocationInfo,
+DiagOpts->MessageLength, DiagOpts->ShowColors);
 OS.flush();
 return;
   }


Index: clang/lib/Frontend/TextDiagnosticPrinter.cpp
===
--- clang/lib/Frontend/TextDiagnosticPrinter.cpp
+++ clang/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -135,10 +135,10 @@
   if (!Info.getLocation().isValid()) {
 TextDiagnostic::printDiagnosticLevel(OS, Level, DiagOpts->ShowColors,
  DiagOpts->CLFallbackMode);
-TextDiagnostic::printDiagnosticMessage(OS, Level, DiagMessageStream.str(),
-   OS.tell() - StartOfLocationInfo,
-   DiagOpts->MessageLength,
-   DiagOpts->ShowColors);
+TextDiagnostic::printDiagnosticMessage(
+OS, /*IsSupplemental=*/Level == DiagnosticsEngine::Note,
+DiagMessageStream.str(), OS.tell() - StartOfLocationInfo,
+DiagOpts->MessageLength, DiagOpts->ShowColors);
 OS.flush();
 return;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86077: [clangd] Add a way for exporting memory usage metrics

2020-09-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet planned changes to this revision.
kadircet added a comment.

In D86077#2281218 , @sammccall wrote:

> Just for the record, as I think Kadir and Adam are both aware...
>
> We discussed making this a bit richer and less reliant on static state.
> We'd build a tree-shaped profile by passing a tree-builder recursively into 
> various components.
> Then the metrics would be exported at the top level, but we'd also want to 
> expose it via debugging actions. (The tree edges from e.g. dynamic index to 
> individual files would probably be optional - collapsed for metrics but 
> present for debugging)
>
> LMK if I have this wrong and you want to move forward with a simpler approch.

No that aligns perfectly with what I have in my mind as well. I just didn't 
have time to get back to this yet. Thanks a lot for summarizing offline 
discussions here!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86077

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


[PATCH] D82445: [analyzer][solver] Track symbol equivalence

2020-09-21 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

In D82445#2284680 , @martong wrote:

> Hi Valery,
>
> Together with @steakhal we have found a serious issue.
> The below code crashes if you compile with `-DEXPENSIVE_CHECKS`.
> The analyzer goes on an unfeasible path, the State has a contradiction.
>
> We think that `getRange(Sym("a != b")` should return a set that does not 
> contain `0`.
> https://github.com/llvm/llvm-project/blob/e63b488f2755f91e8147fd678ed525cf6ba007cc/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp#L2064
> Currently that goes down to `infer(QualType("int"))` which results a 
> `RangeSet[INT_MIN, INT_MAX]`.
> Stach trace attached.
>
>   // RUN: %clang_analyze_cc1 %s \
>   // RUN:   -analyzer-checker=core \
>   // RUN:   -analyzer-checker=debug.ExprInspection \
>   // RUN:   -triple x86_64-unknown-linux \
>   // RUN:   -verify
>   
>   // expected-no-diagnostics
>   
>   void f(int a, int b) {
> int c = b - a;
> if (c <= 0)
>   return;
> // c > 0
> // b - a > 0
> // b > a
> if (a != b)
>   return;
> // a == b
> // This is an unfeasible path, the State has a contradiction.
> if (c < 0) // crash here
>   ;
>   }
>
>
>
>   #0  (anonymous 
> namespace)::SymbolicRangeInferrer::inferRange 
> (BV=..., F=..., State=..., Origin=0x55b9979bed08) at 
> ../../git/llvm-project/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:715
>   #1  0x7fa2314dddc9 in (anonymous 
> namespace)::RangeConstraintManager::getRange (this=0x55b99791ab10, State=..., 
> Sym=0x55b9979bed08) at 
> ../../git/llvm-project/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:2012
>   #2  0x7fa2314de1e9 in (anonymous 
> namespace)::RangeConstraintManager::assumeSymEQ (this=0x55b99791ab10, St=..., 
> Sym=0x55b9979bed08, Int=..., Adjustment=...) at 
> ../../git/llvm-project/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:2064
>   #3  0x7fa23150470d in 
> clang::ento::RangedConstraintManager::assumeSymUnsupported 
> (this=0x55b99791ab10, State=..., Sym=0x55b9979bed08, Assumption=false) at 
> ../../git/llvm-project/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp:136
>   #4  0x7fa2315353a9 in clang::ento::SimpleConstraintManager::assumeAux 
> (this=0x55b99791ab10, State=..., Cond=..., Assumption=false) at 
> ../../git/llvm-project/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:62
>   #5  0x7fa23153518b in clang::ento::SimpleConstraintManager::assume 
> (this=0x55b99791ab10, State=..., Cond=..., Assumption=false) at 
> ../../git/llvm-project/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:46
>   #6  0x7fa2315350e5 in clang::ento::SimpleConstraintManager::assume 
> (this=0x55b99791ab10, State=..., Cond=..., Assumption=false) at 
> ../../git/llvm-project/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:41
>   #7  0x7fa2313d39b3 in clang::ento::ConstraintManager::assumeDual 
> (this=0x55b99791ab10, State=..., Cond=...) at 
> ../../git/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h:105
>   #8  0x7fa2313d3bfc in clang::ento::ProgramState::assume 
> (this=0x55b9979beef8, Cond=...) at 
> ../../git/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h:681
>   #9  0x7fa231436b8a in 
> clang::ento::ExprEngine::evalEagerlyAssumeBinOpBifurcation 
> (this=0x7fffdf9ce9d0, Dst=..., Src=..., Ex=0x55b9979893f0) at 
> ../../git/llvm-project/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:3058

Hi Gabor,

I'll take a look at this problem ASAP!

Thanks for such a thorough analysis of the issue!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82445

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


[PATCH] D87749: [SyntaxTree][Synthesis] Implement `deepCopy`

2020-09-21 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 293101.
eduucaldas added a comment.

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87749

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -163,6 +163,63 @@
   )txt"));
 }
 
+TEST_P(SynthesisTest, DeepCopy_Synthesized) {
+  buildTree("", GetParam());
+
+  auto *LeafContinue = createLeaf(*Arena, tok::kw_continue);
+  auto *LeafSemiColon = createLeaf(*Arena, tok::semi);
+  auto *StatementContinue = createTree(*Arena,
+   {{LeafContinue, NodeRole::LiteralToken},
+{LeafSemiColon, NodeRole::Unknown}},
+   NodeKind::ContinueStatement);
+
+  auto *Copy = deepCopy(*Arena, StatementContinue);
+  EXPECT_TRUE(
+  treeDumpEqual(Copy, StatementContinue->dump(Arena->getSourceManager(;
+  // FIXME: Test that copy is independent of original, once the Mutations API is
+  // more developed.
+}
+
+TEST_P(SynthesisTest, DeepCopy_Original) {
+  auto *OriginalTree = buildTree("int a;", GetParam());
+
+  auto *Copy = deepCopy(*Arena, OriginalTree);
+  EXPECT_TRUE(treeDumpEqual(Copy, R"txt(
+TranslationUnit Detached synthesized
+`-SimpleDeclaration synthesized
+  |-'int' synthesized
+  |-SimpleDeclarator Declarator synthesized
+  | `-'a' synthesized
+  `-';' synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, DeepCopy_Child) {
+  auto *OriginalTree = buildTree("int a;", GetParam());
+
+  auto *Copy = deepCopy(*Arena, OriginalTree->getFirstChild());
+  EXPECT_TRUE(treeDumpEqual(Copy, R"txt(
+SimpleDeclaration Detached synthesized
+|-'int' synthesized
+|-SimpleDeclarator Declarator synthesized
+| `-'a' synthesized
+`-';' synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, DeepCopy_Macro) {
+  auto *OriginalTree = buildTree(R"cpp(
+#define HALF_IF if (1+
+#define HALF_IF_2 1) {}
+void test() {
+  HALF_IF HALF_IF_2 else {}
+})cpp",
+ GetParam());
+
+  auto *Copy = deepCopy(*Arena, OriginalTree);
+  EXPECT_TRUE(Copy == nullptr);
+}
+
 TEST_P(SynthesisTest, Statement_EmptyStatement) {
   buildTree("", GetParam());
 
Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -28,10 +28,12 @@
   }
 };
 
+// FIXME: `createLeaf` is based on `syntax::tokenize` internally, as such it
+// doesn't support digraphs or line continuations.
 syntax::Leaf *clang::syntax::createLeaf(syntax::Arena &A, tok::TokenKind K,
 StringRef Spelling) {
   auto Tokens =
-  FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBuffer(Spelling))
+  FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBufferCopy(Spelling))
   .second;
   assert(Tokens.size() == 1);
   assert(Tokens.front().kind() == K &&
@@ -192,14 +194,52 @@
 syntax::NodeKind K) {
   auto *T = allocateTree(A, K);
   FactoryImpl::setCanModify(T);
-  for (auto ChildIt = Children.rbegin(); ChildIt != Children.rend();
-   std::advance(ChildIt, 1))
+  for (auto ChildIt = Children.rbegin(); ChildIt != Children.rend(); ++ChildIt)
 FactoryImpl::prependChildLowLevel(T, ChildIt->first, ChildIt->second);
 
   T->assertInvariants();
   return T;
 }
 
+namespace {
+bool canModifyAllDescendants(const syntax::Node *N) {
+  if (const auto *L = dyn_cast(N))
+return L->canModify();
+
+  const auto *T = cast(N);
+
+  if (!T->canModify())
+return false;
+  for (const auto *Child = T->getFirstChild(); Child;
+   Child = Child->getNextSibling())
+if (!canModifyAllDescendants(Child))
+  return false;
+
+  return true;
+}
+
+syntax::Node *deepCopyImpl(syntax::Arena &A, const syntax::Node *N) {
+  if (const auto *L = dyn_cast(N))
+return createLeaf(A, L->getToken()->kind(),
+  L->getToken()->text(A.getSourceManager()));
+
+  const auto *T = cast(N);
+  std::vector> Children;
+  for (const auto *Child = T->getFirstChild(); Child;
+   Child = Child->getNextSibling())
+Children.push_back({deepCopyImpl(A, Child), Child->getRole()});
+
+  return createTree(A, Children, N->getKind());
+}
+} // namespace
+
+syntax::Node *clang::syntax::deepCopy(syntax::Arena &A, const Node *N) {
+  if (!canModifyAllDescendants(N))
+return nullptr;
+
+  return deepCopyImpl(A, N);
+}
+
 syntax::EmptyStatement *clang::syntax::createEmptyStatement(syntax::Arena &A) {
   return cast(
   createTree(A, {{createLeaf(A, tok::semi), NodeRole::Unknown}},
Index: clang/include/clang/Tooling/

[PATCH] D87785: [analyzer][StdLibraryFunctionsChecker] Fix a BufferSize constraint crash

2020-09-21 Thread Gabor Marton via Phabricator via cfe-commits
martong abandoned this revision.
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:694
   // execution continues on a code whose behaviour is undefined.
   assert(SuccessSt);
   NewState = SuccessSt;

martong wrote:
> This is where we crashed before this fix.
`assert(SuccessSt);` should not ever fail. Seems like the logic is not flawed 
in `negate` rather there is an issue in the underlying 
`RangeConstraintManager`: the analyzer goes on with an unfeasible path.

See the post-commit comments here: https://reviews.llvm.org/D82445


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87785

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


[clang] 4a5cc38 - [SyntaxTree][Synthesis] Implement `deepCopy`

2020-09-21 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-09-21T09:27:15Z
New Revision: 4a5cc389c51d267f39286a9a8c58c32f758b9d4b

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

LOG: [SyntaxTree][Synthesis] Implement `deepCopy`

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/BuildTree.h
clang/lib/Tooling/Syntax/Synthesis.cpp
clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/BuildTree.h 
b/clang/include/clang/Tooling/Syntax/BuildTree.h
index 452edf580ae1..7b36dff123f6 100644
--- a/clang/include/clang/Tooling/Syntax/BuildTree.h
+++ b/clang/include/clang/Tooling/Syntax/BuildTree.h
@@ -45,6 +45,17 @@ createTree(syntax::Arena &A,
 // Synthesis of Syntax Nodes
 syntax::EmptyStatement *createEmptyStatement(syntax::Arena &A);
 
+/// Creates a completely independent copy of `N` (a deep copy).
+///
+/// The copy is:
+/// * Detached, i.e. `Parent == NextSibling == nullptr` and
+/// `Role == Detached`.
+/// * Synthesized, i.e. `Original == false`.
+///
+/// `N` might be backed by source code but if any descendants of `N` are
+/// unmodifiable returns `nullptr`.
+syntax::Node *deepCopy(syntax::Arena &A, const syntax::Node *N);
+
 } // namespace syntax
 } // namespace clang
 #endif

diff  --git a/clang/lib/Tooling/Syntax/Synthesis.cpp 
b/clang/lib/Tooling/Syntax/Synthesis.cpp
index f171d26512d9..c8fcac27e0d5 100644
--- a/clang/lib/Tooling/Syntax/Synthesis.cpp
+++ b/clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -28,10 +28,12 @@ class clang::syntax::FactoryImpl {
   }
 };
 
+// FIXME: `createLeaf` is based on `syntax::tokenize` internally, as such it
+// doesn't support digraphs or line continuations.
 syntax::Leaf *clang::syntax::createLeaf(syntax::Arena &A, tok::TokenKind K,
 StringRef Spelling) {
   auto Tokens =
-  FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBuffer(Spelling))
+  FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBufferCopy(Spelling))
   .second;
   assert(Tokens.size() == 1);
   assert(Tokens.front().kind() == K &&
@@ -192,14 +194,52 @@ syntax::Tree *clang::syntax::createTree(
 syntax::NodeKind K) {
   auto *T = allocateTree(A, K);
   FactoryImpl::setCanModify(T);
-  for (auto ChildIt = Children.rbegin(); ChildIt != Children.rend();
-   std::advance(ChildIt, 1))
+  for (auto ChildIt = Children.rbegin(); ChildIt != Children.rend(); ++ChildIt)
 FactoryImpl::prependChildLowLevel(T, ChildIt->first, ChildIt->second);
 
   T->assertInvariants();
   return T;
 }
 
+namespace {
+bool canModifyAllDescendants(const syntax::Node *N) {
+  if (const auto *L = dyn_cast(N))
+return L->canModify();
+
+  const auto *T = cast(N);
+
+  if (!T->canModify())
+return false;
+  for (const auto *Child = T->getFirstChild(); Child;
+   Child = Child->getNextSibling())
+if (!canModifyAllDescendants(Child))
+  return false;
+
+  return true;
+}
+
+syntax::Node *deepCopyImpl(syntax::Arena &A, const syntax::Node *N) {
+  if (const auto *L = dyn_cast(N))
+return createLeaf(A, L->getToken()->kind(),
+  L->getToken()->text(A.getSourceManager()));
+
+  const auto *T = cast(N);
+  std::vector> Children;
+  for (const auto *Child = T->getFirstChild(); Child;
+   Child = Child->getNextSibling())
+Children.push_back({deepCopyImpl(A, Child), Child->getRole()});
+
+  return createTree(A, Children, N->getKind());
+}
+} // namespace
+
+syntax::Node *clang::syntax::deepCopy(syntax::Arena &A, const Node *N) {
+  if (!canModifyAllDescendants(N))
+return nullptr;
+
+  return deepCopyImpl(A, N);
+}
+
 syntax::EmptyStatement *clang::syntax::createEmptyStatement(syntax::Arena &A) {
   return cast(
   createTree(A, {{createLeaf(A, tok::semi), NodeRole::Unknown}},

diff  --git a/clang/unittests/Tooling/Syntax/SynthesisTest.cpp 
b/clang/unittests/Tooling/Syntax/SynthesisTest.cpp
index 8d9fb706eac3..2af1fcf8f317 100644
--- a/clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ b/clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -163,6 +163,63 @@ BinaryOperatorExpression Detached synthesized
   )txt"));
 }
 
+TEST_P(SynthesisTest, DeepCopy_Synthesized) {
+  buildTree("", GetParam());
+
+  auto *LeafContinue = createLeaf(*Arena, tok::kw_continue);
+  auto *LeafSemiColon = createLeaf(*Arena, tok::semi);
+  auto *StatementContinue = createTree(*Arena,
+   {{LeafContinue, NodeRole::LiteralToken},
+{LeafSemiColon, NodeRole::Unknown}},
+   NodeKind::ContinueStatement);
+
+  auto *Copy = deepCopy(*Arena, StatementContinue);
+  EXPECT_TRUE(
+  treeDumpEqual(Copy, StatementCont

[PATCH] D87749: [SyntaxTree][Synthesis] Implement `deepCopy`

2020-09-21 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4a5cc389c51d: [SyntaxTree][Synthesis] Implement `deepCopy` 
(authored by eduucaldas).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87749

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -163,6 +163,63 @@
   )txt"));
 }
 
+TEST_P(SynthesisTest, DeepCopy_Synthesized) {
+  buildTree("", GetParam());
+
+  auto *LeafContinue = createLeaf(*Arena, tok::kw_continue);
+  auto *LeafSemiColon = createLeaf(*Arena, tok::semi);
+  auto *StatementContinue = createTree(*Arena,
+   {{LeafContinue, NodeRole::LiteralToken},
+{LeafSemiColon, NodeRole::Unknown}},
+   NodeKind::ContinueStatement);
+
+  auto *Copy = deepCopy(*Arena, StatementContinue);
+  EXPECT_TRUE(
+  treeDumpEqual(Copy, StatementContinue->dump(Arena->getSourceManager(;
+  // FIXME: Test that copy is independent of original, once the Mutations API is
+  // more developed.
+}
+
+TEST_P(SynthesisTest, DeepCopy_Original) {
+  auto *OriginalTree = buildTree("int a;", GetParam());
+
+  auto *Copy = deepCopy(*Arena, OriginalTree);
+  EXPECT_TRUE(treeDumpEqual(Copy, R"txt(
+TranslationUnit Detached synthesized
+`-SimpleDeclaration synthesized
+  |-'int' synthesized
+  |-SimpleDeclarator Declarator synthesized
+  | `-'a' synthesized
+  `-';' synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, DeepCopy_Child) {
+  auto *OriginalTree = buildTree("int a;", GetParam());
+
+  auto *Copy = deepCopy(*Arena, OriginalTree->getFirstChild());
+  EXPECT_TRUE(treeDumpEqual(Copy, R"txt(
+SimpleDeclaration Detached synthesized
+|-'int' synthesized
+|-SimpleDeclarator Declarator synthesized
+| `-'a' synthesized
+`-';' synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, DeepCopy_Macro) {
+  auto *OriginalTree = buildTree(R"cpp(
+#define HALF_IF if (1+
+#define HALF_IF_2 1) {}
+void test() {
+  HALF_IF HALF_IF_2 else {}
+})cpp",
+ GetParam());
+
+  auto *Copy = deepCopy(*Arena, OriginalTree);
+  EXPECT_TRUE(Copy == nullptr);
+}
+
 TEST_P(SynthesisTest, Statement_EmptyStatement) {
   buildTree("", GetParam());
 
Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -28,10 +28,12 @@
   }
 };
 
+// FIXME: `createLeaf` is based on `syntax::tokenize` internally, as such it
+// doesn't support digraphs or line continuations.
 syntax::Leaf *clang::syntax::createLeaf(syntax::Arena &A, tok::TokenKind K,
 StringRef Spelling) {
   auto Tokens =
-  FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBuffer(Spelling))
+  FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBufferCopy(Spelling))
   .second;
   assert(Tokens.size() == 1);
   assert(Tokens.front().kind() == K &&
@@ -192,14 +194,52 @@
 syntax::NodeKind K) {
   auto *T = allocateTree(A, K);
   FactoryImpl::setCanModify(T);
-  for (auto ChildIt = Children.rbegin(); ChildIt != Children.rend();
-   std::advance(ChildIt, 1))
+  for (auto ChildIt = Children.rbegin(); ChildIt != Children.rend(); ++ChildIt)
 FactoryImpl::prependChildLowLevel(T, ChildIt->first, ChildIt->second);
 
   T->assertInvariants();
   return T;
 }
 
+namespace {
+bool canModifyAllDescendants(const syntax::Node *N) {
+  if (const auto *L = dyn_cast(N))
+return L->canModify();
+
+  const auto *T = cast(N);
+
+  if (!T->canModify())
+return false;
+  for (const auto *Child = T->getFirstChild(); Child;
+   Child = Child->getNextSibling())
+if (!canModifyAllDescendants(Child))
+  return false;
+
+  return true;
+}
+
+syntax::Node *deepCopyImpl(syntax::Arena &A, const syntax::Node *N) {
+  if (const auto *L = dyn_cast(N))
+return createLeaf(A, L->getToken()->kind(),
+  L->getToken()->text(A.getSourceManager()));
+
+  const auto *T = cast(N);
+  std::vector> Children;
+  for (const auto *Child = T->getFirstChild(); Child;
+   Child = Child->getNextSibling())
+Children.push_back({deepCopyImpl(A, Child), Child->getRole()});
+
+  return createTree(A, Children, N->getKind());
+}
+} // namespace
+
+syntax::Node *clang::syntax::deepCopy(syntax::Arena &A, const Node *N) {
+  if (!canModifyAllDescendants(N))
+return nullptr;
+
+  return deepCopyImpl(A, N);
+}
+
 syntax::EmptyStatement *clang::syntax::createEm

[PATCH] D77792: [analyzer] Extend constraint manager to be able to compare simple SymSymExprs

2020-09-21 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 293111.
baloghadamsoftware added a comment.

Tests updated: some execution paths merged by refactoring assertions.


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

https://reviews.llvm.org/D77792

Files:
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  clang/test/Analysis/constraint-manager-sym-sym.c

Index: clang/test/Analysis/constraint-manager-sym-sym.c
===
--- /dev/null
+++ clang/test/Analysis/constraint-manager-sym-sym.c
@@ -0,0 +1,205 @@
+// RUN: %clang_analyze_cc1 -verify -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false %s
+
+void clang_analyzer_eval(int);
+
+extern void __assert_fail(__const char *__assertion, __const char *__file,
+  unsigned int __line, __const char *__function)
+__attribute__((__noreturn__));
+#define assert(expr) \
+  ((expr) ? (void)(0) : __assert_fail(#expr, __FILE__, __LINE__, __func__))
+
+// Given [a1,a2] and [b1,b2] intervals.
+// Pin the [b1,b2] interval to eg. [5,10]
+// Choose the a1,a2 points from 0,2,5,7,10,12 where a1 < a2.
+// There will be 5+4+3+2+1 cases.
+
+// [0,2] and [5,10]
+void test_range1(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(0 <= l && l <= 2);
+  clang_analyzer_eval(l < r);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(l <= r); // expected-warning{{TRUE}}
+  clang_analyzer_eval(l > r);  // expected-warning{{FALSE}}
+  clang_analyzer_eval(l >= r); // expected-warning{{FALSE}}
+}
+
+// [0,5] and [5,10]
+void test_range2(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(0 <= l && l <= 5);
+  clang_analyzer_eval(l < r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r); // expected-warning{{TRUE}}
+  clang_analyzer_eval(l > r);  // expected-warning{{FALSE}}
+  clang_analyzer_eval(l >= r); // expected-warning{{UNKNOWN}}
+}
+
+// [0,7] and [5,10]
+void test_range3(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(0 <= l && l <= 7);
+  clang_analyzer_eval(l < r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l > r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l >= r); // expected-warning{{UNKNOWN}}
+}
+
+// [0,10] and [5,10]
+void test_range4(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(0 <= l && l <= 10);
+  clang_analyzer_eval(l < r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l > r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l >= r); // expected-warning{{UNKNOWN}}
+}
+
+// [0,12] and [5,10]
+void test_range5(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(0 <= l && l <= 12);
+  clang_analyzer_eval(l < r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l > r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l >= r); // expected-warning{{UNKNOWN}}
+}
+
+// [2,5] and [5,10] omitted because it is the same as the '[0,5] and [5,10]'
+
+// [2,7] and [5,10]
+void test_range7(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(2 <= l && l <= 7);
+  clang_analyzer_eval(l < r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l > r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l >= r); // expected-warning{{UNKNOWN}}
+}
+
+// [2,10] and [5,10]
+void test_range8(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(2 <= l && l <= 10);
+  clang_analyzer_eval(l < r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l > r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l >= r); // expected-warning{{UNKNOWN}}
+}
+
+// [2,12] and [5,10]
+void test_range9(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(2 <= l && l <= 12);
+  clang_analyzer_eval(l < r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l > r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l >= r); // expected-warning{{UNKNOWN}}
+}
+
+// [5,7] and [5,10]
+void test_range10(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(5 <= l && l <= 7);
+  clang_analyzer_eval(l < r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l > r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l >= r); // expected-warning{{UNKNOWN}}
+}
+
+// [5,10] and [5,10]
+void test_range11(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(5 <= l && l <= 10);
+  clang_analyzer_eval(l < r);  // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r

[PATCH] D87080: [AST] Reduce the size of TemplateArgumentLocInfo.

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

Forgot to mention, 3% memory saving is huge, way more than I expected (was 
mostly just hoping for no regression).
Nice work!




Comment at: clang/include/clang/AST/TemplateBase.h:428
+  TemplateArgumentLocInfo(Expr *E) { Pointer = E; }
+  // Ctx is used for allocation.
+  TemplateArgumentLocInfo(ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,

I'd extend this comment a bit to explain why: "This case is unusually large and 
also rare, so we store the payload out-of-line."


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87080

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


[PATCH] D87749: [SyntaxTree][Synthesis] Implement `deepCopy`

2020-09-21 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/lib/Tooling/Syntax/Synthesis.cpp:205
+  if (L->canModify())
+syntax::FactoryImpl::setCanModify(Leaf);
+

eduucaldas wrote:
> gribozavr2 wrote:
> > Since we are creating new leaves, why prohibit their mutation sometimes?
> > 
> > I also don't quite understand the implications of having multiple leaves in 
> > a tree that are backed by the same token. I think the algorithm that 
> > produces edits can be confused by that.
> > 
> > If you agree, please change the implementation to use `createLeaf` (or call 
> > it directly from `deepCopy`).
> > Since we are creating new leaves, why prohibit their mutation sometimes?
> 
> The `canModify` says whether the leaf is backed by a macro.
> 
> Since the tokens coming from macros are expanded they would be expanded in 
> the deepCopy as well. We agreed that this shouldn't be the default behaviour. 
> We can have `deepCopyExpandingMacros`, if the user wants this behaviour, but 
> I think `deepCopy` should simply forbid macros.
> 
> WDYT about `deepCopyExpandingMacros`?
> 
> > having multiple leaves in a tree that are backed by the same token
> 
> We think the current algorithm wouldn't be confused by that.
> However it's easier to reason about `Leaf`s each with their `Token`, and we 
> don't think creating additional `Leaf` nodes would affect performance largely.
> 
> So we'll call `createLeaf` instead to create a fresh Leaf with the same Token 
> as the previous one.
> WDYT about deepCopyExpandingMacros?

That could be a useful operation that we can provide.



Comment at: clang/lib/Tooling/Syntax/Synthesis.cpp:237
+
+syntax::Node *clang::syntax::deepCopy(syntax::Arena &A, const Node *N) {
+  if (!canModifyAllDescendants(N))

eduucaldas wrote:
> We are ignoring nullability of pointers.
> 
> The casting machinery asserts that on `dyn_cast` we don't have `nullptr`. So 
> this code crashes on `nullptr`. 
> 
> From what I understand `dyn_cast` et al. are intended to be used on pointers. 
> Are there other alternatives to this approach? I would like to encode the 
> non-nullability in types instead of in asserts
I don't think it is idiomatic in the LLVM/Clang style to use references for AST 
nodes and similar things. Beyond that, there is the issue that references are 
non-rebindable.



Comment at: clang/unittests/Tooling/Syntax/SynthesisTest.cpp:220
+  auto *Copy = deepCopy(*Arena, OriginalTree);
+  EXPECT_TRUE(Copy == nullptr);
+}

Does EXPECT_EQ work?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87749

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


[PATCH] D88009: [AArch64] Fix return type of Neon scalar comparison intrinsics

2020-09-21 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett created this revision.
Herald added subscribers: cfe-commits, danielkiss, kristof.beyls.
Herald added a project: clang.
DavidSpickett requested review of this revision.

The following should have unsigned return types
but were signed:
vceqd_s64 vceqzd_s64 vcged_s64 vcgezd_s64
vcgtd_s64 vcgtzd_s64 vcled_s64 vclezd_s64
vcltd_s64 vcltzd_s64 vtstd_s64

See https://developer.arm.com/documentation/ihi0073/latest


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88009

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/test/CodeGen/aarch64-neon-intrinsics.c

Index: clang/test/CodeGen/aarch64-neon-intrinsics.c
===
--- clang/test/CodeGen/aarch64-neon-intrinsics.c
+++ clang/test/CodeGen/aarch64-neon-intrinsics.c
@@ -13746,8 +13746,8 @@
 // CHECK:   [[TMP0:%.*]] = icmp eq i64 %a, %b
 // CHECK:   [[VCEQD_I:%.*]] = sext i1 [[TMP0]] to i64
 // CHECK:   ret i64 [[VCEQD_I]]
-int64_t test_vceqd_s64(int64_t a, int64_t b) {
-  return (int64_t)vceqd_s64(a, b);
+uint64_t test_vceqd_s64(int64_t a, int64_t b) {
+  return (uint64_t)vceqd_s64(a, b);
 }
 
 // CHECK-LABEL: @test_vceqd_u64(
@@ -13762,8 +13762,8 @@
 // CHECK:   [[TMP0:%.*]] = icmp eq i64 %a, 0
 // CHECK:   [[VCEQZ_I:%.*]] = sext i1 [[TMP0]] to i64
 // CHECK:   ret i64 [[VCEQZ_I]]
-int64_t test_vceqzd_s64(int64_t a) {
-  return (int64_t)vceqzd_s64(a);
+uint64_t test_vceqzd_s64(int64_t a) {
+  return (uint64_t)vceqzd_s64(a);
 }
 
 // CHECK-LABEL: @test_vceqzd_u64(
@@ -13778,8 +13778,8 @@
 // CHECK:   [[TMP0:%.*]] = icmp sge i64 %a, %b
 // CHECK:   [[VCEQD_I:%.*]] = sext i1 [[TMP0]] to i64
 // CHECK:   ret i64 [[VCEQD_I]]
-int64_t test_vcged_s64(int64_t a, int64_t b) {
-  return (int64_t)vcged_s64(a, b);
+uint64_t test_vcged_s64(int64_t a, int64_t b) {
+  return (uint64_t)vcged_s64(a, b);
 }
 
 // CHECK-LABEL: @test_vcged_u64(
@@ -13794,16 +13794,16 @@
 // CHECK:   [[TMP0:%.*]] = icmp sge i64 %a, 0
 // CHECK:   [[VCGEZ_I:%.*]] = sext i1 [[TMP0]] to i64
 // CHECK:   ret i64 [[VCGEZ_I]]
-int64_t test_vcgezd_s64(int64_t a) {
-  return (int64_t)vcgezd_s64(a);
+uint64_t test_vcgezd_s64(int64_t a) {
+  return (uint64_t)vcgezd_s64(a);
 }
 
 // CHECK-LABEL: @test_vcgtd_s64(
 // CHECK:   [[TMP0:%.*]] = icmp sgt i64 %a, %b
 // CHECK:   [[VCEQD_I:%.*]] = sext i1 [[TMP0]] to i64
 // CHECK:   ret i64 [[VCEQD_I]]
-int64_t test_vcgtd_s64(int64_t a, int64_t b) {
-  return (int64_t)vcgtd_s64(a, b);
+uint64_t test_vcgtd_s64(int64_t a, int64_t b) {
+  return (uint64_t)vcgtd_s64(a, b);
 }
 
 // CHECK-LABEL: @test_vcgtd_u64(
@@ -13818,16 +13818,16 @@
 // CHECK:   [[TMP0:%.*]] = icmp sgt i64 %a, 0
 // CHECK:   [[VCGTZ_I:%.*]] = sext i1 [[TMP0]] to i64
 // CHECK:   ret i64 [[VCGTZ_I]]
-int64_t test_vcgtzd_s64(int64_t a) {
-  return (int64_t)vcgtzd_s64(a);
+uint64_t test_vcgtzd_s64(int64_t a) {
+  return (uint64_t)vcgtzd_s64(a);
 }
 
 // CHECK-LABEL: @test_vcled_s64(
 // CHECK:   [[TMP0:%.*]] = icmp sle i64 %a, %b
 // CHECK:   [[VCEQD_I:%.*]] = sext i1 [[TMP0]] to i64
 // CHECK:   ret i64 [[VCEQD_I]]
-int64_t test_vcled_s64(int64_t a, int64_t b) {
-  return (int64_t)vcled_s64(a, b);
+uint64_t test_vcled_s64(int64_t a, int64_t b) {
+  return (uint64_t)vcled_s64(a, b);
 }
 
 // CHECK-LABEL: @test_vcled_u64(
@@ -13842,16 +13842,16 @@
 // CHECK:   [[TMP0:%.*]] = icmp sle i64 %a, 0
 // CHECK:   [[VCLEZ_I:%.*]] = sext i1 [[TMP0]] to i64
 // CHECK:   ret i64 [[VCLEZ_I]]
-int64_t test_vclezd_s64(int64_t a) {
-  return (int64_t)vclezd_s64(a);
+uint64_t test_vclezd_s64(int64_t a) {
+  return (uint64_t)vclezd_s64(a);
 }
 
 // CHECK-LABEL: @test_vcltd_s64(
 // CHECK:   [[TMP0:%.*]] = icmp slt i64 %a, %b
 // CHECK:   [[VCEQD_I:%.*]] = sext i1 [[TMP0]] to i64
 // CHECK:   ret i64 [[VCEQD_I]]
-int64_t test_vcltd_s64(int64_t a, int64_t b) {
-  return (int64_t)vcltd_s64(a, b);
+uint64_t test_vcltd_s64(int64_t a, int64_t b) {
+  return (uint64_t)vcltd_s64(a, b);
 }
 
 // CHECK-LABEL: @test_vcltd_u64(
@@ -13866,8 +13866,8 @@
 // CHECK:   [[TMP0:%.*]] = icmp slt i64 %a, 0
 // CHECK:   [[VCLTZ_I:%.*]] = sext i1 [[TMP0]] to i64
 // CHECK:   ret i64 [[VCLTZ_I]]
-int64_t test_vcltzd_s64(int64_t a) {
-  return (int64_t)vcltzd_s64(a);
+uint64_t test_vcltzd_s64(int64_t a) {
+  return (uint64_t)vcltzd_s64(a);
 }
 
 // CHECK-LABEL: @test_vtstd_s64(
@@ -13875,8 +13875,8 @@
 // CHECK:   [[TMP1:%.*]] = icmp ne i64 [[TMP0]], 0
 // CHECK:   [[VTSTD_I:%.*]] = sext i1 [[TMP1]] to i64
 // CHECK:   ret i64 [[VTSTD_I]]
-int64_t test_vtstd_s64(int64_t a, int64_t b) {
-  return (int64_t)vtstd_s64(a, b);
+uint64_t test_vtstd_s64(int64_t a, int64_t b) {
+  return (uint64_t)vtstd_s64(a, b);
 }
 
 // CHECK-LABEL: @test_vtstd_u64(
Index: clang/include/clang/Basic/arm_neon.td
===
--- clang/include/clang/Basic/arm_neon.td
+++ clang/include/clang/Basic/arm_neon.td
@@ -1419,19 +1419,19 @@
 
 
 // Scalar I

[PATCH] D88005: [clang] [MinGW] Add an implicit .exe suffix even when crosscompiling

2020-09-21 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 added a comment.

LGTM
Confirmed that GCC 9 still adds `.exe`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88005

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


[PATCH] D88009: [AArch64] Fix return type of Neon scalar comparison intrinsics

2020-09-21 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a reviewer: efriedma.
DavidSpickett added a comment.

Links instead of searching the document:
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vceqd_s64
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vceqzd_s64
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vcged_s64
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vcgezd_s64
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vcgtd_s64
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vcgtzd_s64
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vcled_s64
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vclezd_s64
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vcltd_s64
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vcltzd_s64
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vtstd_s64

There should be one more set of fixes like this, then I'll get a proper types 
test added. (at least for base Neon)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88009

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


[PATCH] D88013: [AArch64] Correct parameter type for Neon scalar shift intrinsics

2020-09-21 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett created this revision.
Herald added subscribers: cfe-commits, danielkiss, kristof.beyls.
Herald added a project: clang.
DavidSpickett requested review of this revision.

In the following intrinsics the shift amount
(parameter 2) should be signed.

vqshlh_u16  vqshls_u32  vqshld_u64
vqrshlh_u16 vqrshls_u32 vqrshld_u64
vqshlb_u8
vqrshlb_u8
vshld_u64
vrshld_u64

See https://developer.arm.com/documentation/ihi0073/latest


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88013

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/test/CodeGen/aarch64-neon-intrinsics.c

Index: clang/test/CodeGen/aarch64-neon-intrinsics.c
===
--- clang/test/CodeGen/aarch64-neon-intrinsics.c
+++ clang/test/CodeGen/aarch64-neon-intrinsics.c
@@ -8548,7 +8548,7 @@
 // CHECK-LABEL: @test_vshld_u64(
 // CHECK:   [[VSHLD_U64_I:%.*]] = call i64 @llvm.aarch64.neon.ushl.i64(i64 %a, i64 %b)
 // CHECK:   ret i64 [[VSHLD_U64_I]]
-uint64_t test_vshld_u64(uint64_t a, uint64_t b) {
+uint64_t test_vshld_u64(uint64_t a, int64_t b) {
   return vshld_u64(a, b);
 }
 
@@ -8592,7 +8592,7 @@
 // CHECK:   [[VQSHLB_U8_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.uqshl.v8i8(<8 x i8> [[TMP0]], <8 x i8> [[TMP1]])
 // CHECK:   [[TMP2:%.*]] = extractelement <8 x i8> [[VQSHLB_U8_I]], i64 0
 // CHECK:   ret i8 [[TMP2]]
-uint8_t test_vqshlb_u8(uint8_t a, uint8_t b) {
+uint8_t test_vqshlb_u8(uint8_t a, int8_t b) {
   return vqshlb_u8(a, b);
 }
 
@@ -8602,21 +8602,21 @@
 // CHECK:   [[VQSHLH_U16_I:%.*]] = call <4 x i16> @llvm.aarch64.neon.uqshl.v4i16(<4 x i16> [[TMP0]], <4 x i16> [[TMP1]])
 // CHECK:   [[TMP2:%.*]] = extractelement <4 x i16> [[VQSHLH_U16_I]], i64 0
 // CHECK:   ret i16 [[TMP2]]
-uint16_t test_vqshlh_u16(uint16_t a, uint16_t b) {
+uint16_t test_vqshlh_u16(uint16_t a, int16_t b) {
   return vqshlh_u16(a, b);
 }
 
 // CHECK-LABEL: @test_vqshls_u32(
 // CHECK:   [[VQSHLS_U32_I:%.*]] = call i32 @llvm.aarch64.neon.uqshl.i32(i32 %a, i32 %b)
 // CHECK:   ret i32 [[VQSHLS_U32_I]]
-uint32_t test_vqshls_u32(uint32_t a, uint32_t b) {
+uint32_t test_vqshls_u32(uint32_t a, int32_t b) {
   return vqshls_u32(a, b);
 }
 
 // CHECK-LABEL: @test_vqshld_u64(
 // CHECK:   [[VQSHLD_U64_I:%.*]] = call i64 @llvm.aarch64.neon.uqshl.i64(i64 %a, i64 %b)
 // CHECK:   ret i64 [[VQSHLD_U64_I]]
-uint64_t test_vqshld_u64(uint64_t a, uint64_t b) {
+uint64_t test_vqshld_u64(uint64_t a, int64_t b) {
   return vqshld_u64(a, b);
 }
 
@@ -8630,7 +8630,7 @@
 // CHECK-LABEL: @test_vrshld_u64(
 // CHECK:   [[VRSHLD_U64_I:%.*]] = call i64 @llvm.aarch64.neon.urshl.i64(i64 %a, i64 %b)
 // CHECK:   ret i64 [[VRSHLD_U64_I]]
-uint64_t test_vrshld_u64(uint64_t a, uint64_t b) {
+uint64_t test_vrshld_u64(uint64_t a, int64_t b) {
   return vrshld_u64(a, b);
 }
 
@@ -8674,7 +8674,7 @@
 // CHECK:   [[VQRSHLB_U8_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.uqrshl.v8i8(<8 x i8> [[TMP0]], <8 x i8> [[TMP1]])
 // CHECK:   [[TMP2:%.*]] = extractelement <8 x i8> [[VQRSHLB_U8_I]], i64 0
 // CHECK:   ret i8 [[TMP2]]
-uint8_t test_vqrshlb_u8(uint8_t a, uint8_t b) {
+uint8_t test_vqrshlb_u8(uint8_t a, int8_t b) {
   return vqrshlb_u8(a, b);
 }
 
@@ -8684,21 +8684,21 @@
 // CHECK:   [[VQRSHLH_U16_I:%.*]] = call <4 x i16> @llvm.aarch64.neon.uqrshl.v4i16(<4 x i16> [[TMP0]], <4 x i16> [[TMP1]])
 // CHECK:   [[TMP2:%.*]] = extractelement <4 x i16> [[VQRSHLH_U16_I]], i64 0
 // CHECK:   ret i16 [[TMP2]]
-uint16_t test_vqrshlh_u16(uint16_t a, uint16_t b) {
+uint16_t test_vqrshlh_u16(uint16_t a, int16_t b) {
   return vqrshlh_u16(a, b);
 }
 
 // CHECK-LABEL: @test_vqrshls_u32(
 // CHECK:   [[VQRSHLS_U32_I:%.*]] = call i32 @llvm.aarch64.neon.uqrshl.i32(i32 %a, i32 %b)
 // CHECK:   ret i32 [[VQRSHLS_U32_I]]
-uint32_t test_vqrshls_u32(uint32_t a, uint32_t b) {
+uint32_t test_vqrshls_u32(uint32_t a, int32_t b) {
   return vqrshls_u32(a, b);
 }
 
 // CHECK-LABEL: @test_vqrshld_u64(
 // CHECK:   [[VQRSHLD_U64_I:%.*]] = call i64 @llvm.aarch64.neon.uqrshl.i64(i64 %a, i64 %b)
 // CHECK:   ret i64 [[VQRSHLD_U64_I]]
-uint64_t test_vqrshld_u64(uint64_t a, uint64_t b) {
+uint64_t test_vqrshld_u64(uint64_t a, int64_t b) {
   return vqrshld_u64(a, b);
 }
 
Index: clang/include/clang/Basic/arm_neon.td
===
--- clang/include/clang/Basic/arm_neon.td
+++ clang/include/clang/Basic/arm_neon.td
@@ -1263,13 +1263,13 @@
 
 // Scalar Shift
 // Scalar Shift Left
-def SCALAR_SHL: SInst<"vshl", "111", "SlSUl">;
+def SCALAR_SHL: SInst<"vshl", "11(S1)", "SlSUl">;
 // Scalar Saturating Shift Left
-def SCALAR_QSHL: SInst<"vqshl", "111", "ScSsSiSlSUcSUsSUiSUl">;
+def SCALAR_QSHL: SInst<"vqshl", "11(S1)", "ScSsSiSlSUcSUsSUiSUl">;
 // Scalar Saturating Rounding Shift Left
-def SCALAR_QRSHL: SInst<"vqrshl", "111", "ScSsSiSlSUcSUsSUiSUl">;
+def SCALAR_QRSHL: SInst<"vqrshl", "11(S1)", "ScSsSiSlSUcSUsSUiSUl">;
 // Scalar Shift

[PATCH] D87394: [PowerPC][Power10] Implementation of 128-bit Binary Vector Mod and Sign Extend builtins

2020-09-21 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.

The nits can be addressed when committing the code. LGTM otherwise.




Comment at: llvm/lib/Target/PowerPC/PPCInstrAltivec.td:1452
 // Vector Extend Sign
-def VEXTSB2W : VX_VT5_EO5_VB5<1538, 16, "vextsb2w", []>;
-def VEXTSH2W : VX_VT5_EO5_VB5<1538, 17, "vextsh2w", []>;
-def VEXTSB2D : VX_VT5_EO5_VB5<1538, 24, "vextsb2d", []>;
-def VEXTSH2D : VX_VT5_EO5_VB5<1538, 25, "vextsh2d", []>;
-def VEXTSW2D : VX_VT5_EO5_VB5<1538, 26, "vextsw2d", []>;
+def VEXTSB2W : VX_VT5_EO5_VB5<1538, 16, "vextsb2w", [(set v4i32:$vD,
+  (int_ppc_altivec_vextsb2w v16i8:$vB))]>;

The indentation is off on all of these. Should probably be something like:
```
def VEXTSB2W :
  VX_VT5_EO5_VB5<1538, 16, "vextsb2w",
 [(set v4i32:$vD, (int_ppc_altivec_vextsb2w v16i8:$vB))]>;
```



Comment at: llvm/test/CodeGen/PowerPC/p10-vector-sign-extend.ll:1
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \

Nit: only one of these requires P10. The others are P9 instructions. You have 
split the tests for the front end changes, please split the back end test as 
well.


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

https://reviews.llvm.org/D87394

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


[PATCH] D88013: [AArch64] Correct parameter type for Neon scalar shift intrinsics

2020-09-21 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a reviewer: efriedma.
DavidSpickett added a comment.

Links to save combing the document:
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vqshlh_u16
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vqshls_u32
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vqshld_u64
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vqrshlh_u16
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vqrshls_u32
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vqrshld_u64
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vqshlb_u8
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vqrshlb_u8
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vshld_u64
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics?search=vrshld_u64


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88013

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


[clang] af29591 - [AST] Reduce the size of TemplateArgumentLocInfo.

2020-09-21 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-09-21T13:08:53+02:00
New Revision: af29591650c43bd3bdc380c9d47b8bfd0f1664a2

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

LOG: [AST] Reduce the size of TemplateArgumentLocInfo.

allocate the underlying data of Template kind separately, this would reduce AST
memory usage

- TemplateArgumentLocInfo 24 => 8 bytes
- TemplateArgumentLoc  48 => 32 bytes
- DynTypeNode 56 => 40 bytes

ASTContext::.getASTAllocatedMemory changes:
  SemaDecl.cpp 255.5 MB => 247.5MB
  SemaExpr.cpp 293.5 MB => 283.5MB

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

Added: 


Modified: 
clang/include/clang/AST/Expr.h
clang/include/clang/AST/TemplateBase.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/TemplateBase.cpp
clang/lib/AST/TypeLoc.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/SemaTemplateVariadic.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 1672fd707c6d..1ea454514b2f 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -960,6 +960,11 @@ class Expr : public ValueStmt {
T->getStmtClass() <= lastExprConstant;
   }
 };
+// PointerLikeTypeTraits is specialized so it can be used with a forward-decl 
of
+// Expr. Verify that we got it right.
+static_assert(llvm::PointerLikeTypeTraits::NumLowBitsAvailable <=
+  llvm::detail::ConstantLog2::value,
+  "PointerLikeTypeTraits assumes too much alignment.");
 
 
//===--===//
 // Wrapper Expressions.

diff  --git a/clang/include/clang/AST/TemplateBase.h 
b/clang/include/clang/AST/TemplateBase.h
index 51fd8ba51034..b7af5c7d7bd9 100644
--- a/clang/include/clang/AST/TemplateBase.h
+++ b/clang/include/clang/AST/TemplateBase.h
@@ -36,6 +36,17 @@ namespace llvm {
 
 class FoldingSetNodeID;
 
+// Provide PointerLikeTypeTraits for clang::Expr*, this default one requires a
+// full definition of Expr, but this file only sees a forward del because of
+// the dependency.
+template <> struct PointerLikeTypeTraits {
+  static inline void *getAsVoidPointer(clang::Expr *P) { return P; }
+  static inline clang::Expr *getFromVoidPointer(void *P) {
+return static_cast(P);
+  }
+  static constexpr int NumLowBitsAvailable = 2;
+};
+
 } // namespace llvm
 
 namespace clang {
@@ -393,7 +404,7 @@ class TemplateArgument {
 /// Location information for a TemplateArgument.
 struct TemplateArgumentLocInfo {
 private:
-  struct T {
+  struct TemplateTemplateArgLocInfo {
 // FIXME: We'd like to just use the qualifier in the TemplateName,
 // but template arguments get canonicalized too quickly.
 NestedNameSpecifier *Qualifier;
@@ -402,47 +413,42 @@ struct TemplateArgumentLocInfo {
 unsigned EllipsisLoc;
   };
 
-  union {
-struct T Template;
-Expr *Expression;
-TypeSourceInfo *Declarator;
-  };
-
-public:
-  constexpr TemplateArgumentLocInfo() : Template({nullptr, nullptr, 0, 0}) {}
+  llvm::PointerUnion
+  Pointer;
 
-  TemplateArgumentLocInfo(TypeSourceInfo *TInfo) : Declarator(TInfo) {}
+  TemplateTemplateArgLocInfo *getTemplate() const {
+return Pointer.get();
+  }
 
-  TemplateArgumentLocInfo(Expr *E) : Expression(E) {}
+public:
+  constexpr TemplateArgumentLocInfo() {}
+  TemplateArgumentLocInfo(TypeSourceInfo *Declarator) { Pointer = Declarator; }
 
-  TemplateArgumentLocInfo(NestedNameSpecifierLoc QualifierLoc,
+  TemplateArgumentLocInfo(Expr *E) { Pointer = E; }
+  // Ctx is used for allocation -- this case is unusually large and also rare,
+  // so we store the payload out-of-line.
+  TemplateArgumentLocInfo(ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
   SourceLocation TemplateNameLoc,
-  SourceLocation EllipsisLoc) {
-Template.Qualifier = QualifierLoc.getNestedNameSpecifier();
-Template.QualifierLocData = QualifierLoc.getOpaqueData();
-Template.TemplateNameLoc = TemplateNameLoc.getRawEncoding();
-Template.EllipsisLoc = EllipsisLoc.getRawEncoding();
-  }
+  SourceLocation EllipsisLoc);
 
   TypeSourceInfo *getAsTypeSourceInfo() const {
-return Declarator;
+return Pointer.get();
   }
 
-  Expr *getAsExpr() const {
-return Expression;
-  }
+  Expr *getAsExpr() const { return Pointer.get(); }
 
   NestedNameSpecifierLoc getTemplateQualifierLoc() const {
-return NestedNameSpecifierLoc(Template.Qualifier,
-  Template.QualifierLocData);
+const auto *Template = getTemplate(

[PATCH] D87080: [AST] Reduce the size of TemplateArgumentLocInfo.

2020-09-21 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rGaf29591650c4: [AST] Reduce the size of 
TemplateArgumentLocInfo. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D87080?vs=293094&id=293133#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87080

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp

Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -7095,15 +7095,15 @@
 NestedNameSpecifierLoc QualifierLoc =
   readNestedNameSpecifierLoc();
 SourceLocation TemplateNameLoc = readSourceLocation();
-return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
-   SourceLocation());
+return TemplateArgumentLocInfo(getASTContext(), QualifierLoc,
+   TemplateNameLoc, SourceLocation());
   }
   case TemplateArgument::TemplateExpansion: {
 NestedNameSpecifierLoc QualifierLoc = readNestedNameSpecifierLoc();
 SourceLocation TemplateNameLoc = readSourceLocation();
 SourceLocation EllipsisLoc = readSourceLocation();
-return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
-   EllipsisLoc);
+return TemplateArgumentLocInfo(getASTContext(), QualifierLoc,
+   TemplateNameLoc, EllipsisLoc);
   }
   case TemplateArgument::Null:
   case TemplateArgument::Integral:
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3546,12 +3546,12 @@
 }
 
 case TemplateArgument::Template:
-  return TemplateArgumentLoc(TemplateArgument(
-  Pattern.getArgument().getAsTemplate(),
-  NumExpansions),
- Pattern.getTemplateQualifierLoc(),
- Pattern.getTemplateNameLoc(),
- EllipsisLoc);
+  return TemplateArgumentLoc(
+  SemaRef.Context,
+  TemplateArgument(Pattern.getArgument().getAsTemplate(),
+   NumExpansions),
+  Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
+  EllipsisLoc);
 
 case TemplateArgument::Null:
 case TemplateArgument::Integral:
@@ -4289,8 +4289,8 @@
 if (Template.isNull())
   return true;
 
-Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
- Input.getTemplateNameLoc());
+Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
+ QualifierLoc, Input.getTemplateNameLoc());
 return false;
   }
 
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1095,7 +1095,7 @@
   case TemplateArgument::TemplateExpansion:
 Ellipsis = OrigLoc.getTemplateEllipsisLoc();
 NumExpansions = Argument.getNumTemplateExpansions();
-return TemplateArgumentLoc(Argument.getPackExpansionPattern(),
+return TemplateArgumentLoc(Context, Argument.getPackExpansionPattern(),
OrigLoc.getTemplateQualifierLoc(),
OrigLoc.getTemplateNameLoc());
 
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2915,7 +2915,7 @@
 if (!TName.isNull())
   Param->setDefaultArgument(
   SemaRef.Context,
-  TemplateArgumentLoc(TemplateArgument(TName),
+  TemplateArgumentLoc(SemaRef.Context, TemplateArgument(TName),
   D->getDefaultArgument().getTemplateQualifierLoc(),
   D->getDefaultArgument().getTemplateNameLoc()));
   }
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2670,11 +2670,11 @@
 Bu

[PATCH] D86632: [Fixed Point] Add codegen for conversion between fixed-point and floating point.

2020-09-21 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added a comment.

Ping. Any further comments?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86632

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


[PATCH] D71199: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

2020-09-21 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 293139.
baloghadamsoftware added a comment.

Updated according to the comments.


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

https://reviews.llvm.org/D71199

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-prefer-member-initializer.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-modernize-use-default-member-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
@@ -0,0 +1,490 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-prefer-member-initializer %t -- -- -fcxx-exceptions
+
+extern void __assert_fail (__const char *__assertion, __const char *__file,
+unsigned int __line, __const char *__function)
+ __attribute__ ((__noreturn__));
+#define assert(expr) \
+  ((expr)  ? (void)(0)  : __assert_fail (#expr, __FILE__, __LINE__, __func__))
+
+class Simple1 {
+  int n;
+  double x;
+
+public:
+  Simple1() {
+// CHECK-FIXES: Simple1() : n(0), x(0.0) {
+n = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+x = 0.0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple1(int nn, double xx) {
+// CHECK-FIXES: Simple1(int nn, double xx) : n(nn), x(xx) {
+n = nn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+x = xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple1() = default;
+};
+
+class Simple2 {
+  int n;
+  double x;
+
+public:
+  Simple2() : n(0) {
+// CHECK-FIXES: Simple2() : n(0), x(0.0) {
+x = 0.0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple2(int nn, double xx) : n(nn) {
+// CHECK-FIXES: Simple2(int nn, double xx) : n(nn), x(xx) {
+x = xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple2() = default;
+};
+
+class Simple3 {
+  int n;
+  double x;
+
+public:
+  Simple3() : x(0.0) {
+// CHECK-FIXES: Simple3() : n(0), x(0.0) {
+n = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple3(int nn, double xx) : x(xx) {
+// CHECK-FIXES: Simple3(int nn, double xx) : n(nn), x(xx) {
+n = nn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple3() = default;
+};
+
+int something_int();
+double something_double();
+
+class Simple4 {
+  int n;
+
+public:
+  Simple4() {
+// CHECK-FIXES: Simple4() : n(something_int()) {
+n = something_int();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple4() = default;
+};
+
+static bool dice();
+
+class Complex1 {
+  int n;
+  int m;
+
+public:
+  Complex1() : n(0) {
+if (dice())
+  m = 1;
+// NO-MESSAGES: initialization of 'm' is nested in a conditional expression
+  }
+
+  ~Complex1() = default;
+};
+
+class Complex2 {
+  int n;
+  int m;
+
+public:
+  Complex2() : n(0) {
+if (!dice())
+  return;
+m = 1;
+// NO-MESSAGES: initialization of 'm' fo

[PATCH] D71199: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

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

Prerequeisite patch is committed, the check is tested now on the //LLVM 
Project//. @lebedev.ri, @aaron.ballman can I recommit it?


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

https://reviews.llvm.org/D71199

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


[PATCH] D71199: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

2020-09-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri resigned from this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

In D71199#2285076 , 
@baloghadamsoftware wrote:

> Prerequeisite patch is committed, the check is tested now on the //LLVM 
> Project//. @lebedev.ri, @aaron.ballman can I recommit it?

Thank you! SGTM.


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

https://reviews.llvm.org/D71199

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


[clang] 41a8bba - Fix buildbot.

2020-09-21 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-09-21T13:40:00+02:00
New Revision: 41a8bbad5e52a94a485c5bfe3d7871784fe6d8ed

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

LOG: Fix buildbot.

TemplateArgumentLocInfo cannot result in a constant expression anymore
after D87080.

Added: 


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

Removed: 




diff  --git a/clang/include/clang/AST/TemplateBase.h 
b/clang/include/clang/AST/TemplateBase.h
index b7af5c7d7bd9..c158cde3580e 100644
--- a/clang/include/clang/AST/TemplateBase.h
+++ b/clang/include/clang/AST/TemplateBase.h
@@ -421,7 +421,7 @@ struct TemplateArgumentLocInfo {
   }
 
 public:
-  constexpr TemplateArgumentLocInfo() {}
+  TemplateArgumentLocInfo() {}
   TemplateArgumentLocInfo(TypeSourceInfo *Declarator) { Pointer = Declarator; }
 
   TemplateArgumentLocInfo(Expr *E) { Pointer = E; }
@@ -459,7 +459,7 @@ class TemplateArgumentLoc {
   TemplateArgumentLocInfo LocInfo;
 
 public:
-  constexpr TemplateArgumentLoc() {}
+  TemplateArgumentLoc() {}
 
   TemplateArgumentLoc(const TemplateArgument &Argument,
   TemplateArgumentLocInfo Opaque)



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


[PATCH] D88004: [SyntaxTree][NFC] follow naming convention + remove auto on empty vector declaration

2020-09-21 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG87f0b51d68de: [SyntaxTree][NFC] follow naming convention + 
remove auto on empty vector… (authored by eduucaldas).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88004

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/lib/Tooling/Syntax/Tree.cpp

Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -153,7 +153,7 @@
 
 static void dumpNode(raw_ostream &OS, const syntax::Node *N,
  const SourceManager &SM, std::vector IndentMask) {
-  auto dumpExtraInfo = [&OS](const syntax::Node *N) {
+  auto DumpExtraInfo = [&OS](const syntax::Node *N) {
 if (N->getRole() != syntax::NodeRole::Unknown)
   OS << " " << N->getRole();
 if (!N->isOriginal())
@@ -167,14 +167,14 @@
 OS << "'";
 dumpLeaf(OS, L, SM);
 OS << "'";
-dumpExtraInfo(N);
+DumpExtraInfo(N);
 OS << "\n";
 return;
   }
 
   const auto *T = cast(N);
   OS << T->getKind();
-  dumpExtraInfo(N);
+  DumpExtraInfo(N);
   OS << "\n";
 
   for (const auto *It = T->getFirstChild(); It; It = It->getNextSibling()) {
@@ -302,20 +302,20 @@
   if (!getFirstChild())
 return {};
 
-  auto children = std::vector>();
-  syntax::Node *elementWithoutDelimiter = nullptr;
+  std::vector> Children;
+  syntax::Node *ElementWithoutDelimiter = nullptr;
   for (auto *C = getFirstChild(); C; C = C->getNextSibling()) {
 switch (C->getRole()) {
 case syntax::NodeRole::ListElement: {
-  if (elementWithoutDelimiter) {
-children.push_back({elementWithoutDelimiter, nullptr});
+  if (ElementWithoutDelimiter) {
+Children.push_back({ElementWithoutDelimiter, nullptr});
   }
-  elementWithoutDelimiter = C;
+  ElementWithoutDelimiter = C;
   break;
 }
 case syntax::NodeRole::ListDelimiter: {
-  children.push_back({elementWithoutDelimiter, cast(C)});
-  elementWithoutDelimiter = nullptr;
+  Children.push_back({ElementWithoutDelimiter, cast(C)});
+  ElementWithoutDelimiter = nullptr;
   break;
 }
 default:
@@ -326,19 +326,19 @@
 
   switch (getTerminationKind()) {
   case syntax::List::TerminationKind::Separated: {
-children.push_back({elementWithoutDelimiter, nullptr});
+Children.push_back({ElementWithoutDelimiter, nullptr});
 break;
   }
   case syntax::List::TerminationKind::Terminated:
   case syntax::List::TerminationKind::MaybeTerminated: {
-if (elementWithoutDelimiter) {
-  children.push_back({elementWithoutDelimiter, nullptr});
+if (ElementWithoutDelimiter) {
+  Children.push_back({ElementWithoutDelimiter, nullptr});
 }
 break;
   }
   }
 
-  return children;
+  return Children;
 }
 
 // Almost the same implementation of `getElementsAsNodesAndDelimiters` but
@@ -347,20 +347,20 @@
   if (!getFirstChild())
 return {};
 
-  auto children = std::vector();
-  syntax::Node *elementWithoutDelimiter = nullptr;
+  std::vector Children;
+  syntax::Node *ElementWithoutDelimiter = nullptr;
   for (auto *C = getFirstChild(); C; C = C->getNextSibling()) {
 switch (C->getRole()) {
 case syntax::NodeRole::ListElement: {
-  if (elementWithoutDelimiter) {
-children.push_back(elementWithoutDelimiter);
+  if (ElementWithoutDelimiter) {
+Children.push_back(ElementWithoutDelimiter);
   }
-  elementWithoutDelimiter = C;
+  ElementWithoutDelimiter = C;
   break;
 }
 case syntax::NodeRole::ListDelimiter: {
-  children.push_back(elementWithoutDelimiter);
-  elementWithoutDelimiter = nullptr;
+  Children.push_back(ElementWithoutDelimiter);
+  ElementWithoutDelimiter = nullptr;
   break;
 }
 default:
@@ -370,19 +370,19 @@
 
   switch (getTerminationKind()) {
   case syntax::List::TerminationKind::Separated: {
-children.push_back(elementWithoutDelimiter);
+Children.push_back(ElementWithoutDelimiter);
 break;
   }
   case syntax::List::TerminationKind::Terminated:
   case syntax::List::TerminationKind::MaybeTerminated: {
-if (elementWithoutDelimiter) {
-  children.push_back(elementWithoutDelimiter);
+if (ElementWithoutDelimiter) {
+  Children.push_back(ElementWithoutDelimiter);
 }
 break;
   }
   }
 
-  return children;
+  return Children;
 }
 
 clang::tok::TokenKind syntax::List::getDelimiterTokenKind() const {
Index: clang/lib/Tooling/Syntax/Nodes.cpp
===
--- clang/lib/Tooling/Syntax/Nodes.cpp
+++ clang/lib/Tooling/Syntax/Nodes.cpp
@@ -226,23 +226,23 @@
 // vector
 std::vector
 syntax::NestedNameSpecifier::getSpecifiers() {
-  auto specifiersAsNodes = getElementsAsNodes();
+  auto SpecifiersAsNodes = get

[PATCH] D88019: [analyzer][solver] Fix issue with symbol non-equality tracking

2020-09-21 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: vsavchenko, steakhal, NoQ.
Herald added subscribers: cfe-commits, ASDenysPetrov, Charusso, gamesh411, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
baloghadamsoftware, xazax.hun, whisperity.
Herald added a reviewer: Szelethus.
Herald added a project: clang.
martong requested review of this revision.

We should track non-equivalency (disequality) in case of greater-then or
less-then assumptions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88019

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/equality_tracking.c


Index: clang/test/Analysis/equality_tracking.c
===
--- clang/test/Analysis/equality_tracking.c
+++ clang/test/Analysis/equality_tracking.c
@@ -185,3 +185,37 @@
 }
   }
 }
+
+void avoidInfeasibleConstraintforGT(int a, int b) {
+  int c = b - a;
+  if (c <= 0)
+return;
+  // c > 0
+  // b - a > 0
+  // b > a
+  if (a != b) {
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+return;
+  }
+  clang_analyzer_warnIfReached(); // no warning
+  // a == b
+  if (c < 0)
+;
+}
+
+void avoidInfeasibleConstraintforLT(int a, int b) {
+  int c = b - a;
+  if (c >= 0)
+return;
+  // c < 0
+  // b - a < 0
+  // b < a
+  if (a != b) {
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+return;
+  }
+  clang_analyzer_warnIfReached(); // no warning
+  // a == b
+  if (c < 0)
+;
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2104,7 +2104,12 @@
 const llvm::APSInt &Int,
 const llvm::APSInt &Adjustment) {
   RangeSet New = getSymLTRange(St, Sym, Int, Adjustment);
-  return New.isEmpty() ? nullptr : setConstraint(St, Sym, New);
+  if (New.isEmpty())
+// this is infeasible assumption
+return nullptr;
+
+  ProgramStateRef NewState = setConstraint(St, Sym, New);
+  return trackNE(NewState, Sym, Int, Adjustment);
 }
 
 RangeSet RangeConstraintManager::getSymGTRange(ProgramStateRef St,
@@ -2140,7 +2145,12 @@
 const llvm::APSInt &Int,
 const llvm::APSInt &Adjustment) {
   RangeSet New = getSymGTRange(St, Sym, Int, Adjustment);
-  return New.isEmpty() ? nullptr : setConstraint(St, Sym, New);
+  if (New.isEmpty())
+// this is infeasible assumption
+return nullptr;
+
+  ProgramStateRef NewState = setConstraint(St, Sym, New);
+  return trackNE(NewState, Sym, Int, Adjustment);
 }
 
 RangeSet RangeConstraintManager::getSymGERange(ProgramStateRef St,


Index: clang/test/Analysis/equality_tracking.c
===
--- clang/test/Analysis/equality_tracking.c
+++ clang/test/Analysis/equality_tracking.c
@@ -185,3 +185,37 @@
 }
   }
 }
+
+void avoidInfeasibleConstraintforGT(int a, int b) {
+  int c = b - a;
+  if (c <= 0)
+return;
+  // c > 0
+  // b - a > 0
+  // b > a
+  if (a != b) {
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+return;
+  }
+  clang_analyzer_warnIfReached(); // no warning
+  // a == b
+  if (c < 0)
+;
+}
+
+void avoidInfeasibleConstraintforLT(int a, int b) {
+  int c = b - a;
+  if (c >= 0)
+return;
+  // c < 0
+  // b - a < 0
+  // b < a
+  if (a != b) {
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+return;
+  }
+  clang_analyzer_warnIfReached(); // no warning
+  // a == b
+  if (c < 0)
+;
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2104,7 +2104,12 @@
 const llvm::APSInt &Int,
 const llvm::APSInt &Adjustment) {
   RangeSet New = getSymLTRange(St, Sym, Int, Adjustment);
-  return New.isEmpty() ? nullptr : setConstraint(St, Sym, New);
+  if (New.isEmpty())
+// this is infeasible assumption
+return nullptr;
+
+  ProgramStateRef NewState = setConstraint(St, Sym, New);
+  return trackNE(NewState, Sym, Int, Adjustment);
 }
 
 RangeSet RangeConstraintManager::getSymGTRange(ProgramStateRef St,
@@ -2140,7 +2145,12 @@
 const llvm::APSInt &Int,
 const llvm::APSInt &Adjustment) {
   RangeSet New = getSymGTRange(St, Sym, Int, Adjustment);
-  return New.isEmpty() ? nullptr : setConstraint(St, Sym, New);
+  if (New.isEmpty())
+// this is infeasible assumption
+return nullptr;
+
+  ProgramS

[clang] 87f0b51 - [SyntaxTree][NFC] follow naming convention + remove auto on empty vector declaration

2020-09-21 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-09-21T11:45:15Z
New Revision: 87f0b51d68de40e7106be89d934b5191d983e3d5

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

LOG: [SyntaxTree][NFC] follow naming convention + remove auto on empty vector 
declaration

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 3e0573ac4ffc..4d365090abf1 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -155,10 +155,10 @@ struct GetStartLoc : TypeLocVisitor {
 } // namespace
 
 static CallExpr::arg_range dropDefaultArgs(CallExpr::arg_range Args) {
-  auto firstDefaultArg = std::find_if(Args.begin(), Args.end(), [](auto it) {
-return isa(it);
+  auto FirstDefaultArg = std::find_if(Args.begin(), Args.end(), [](auto It) {
+return isa(It);
   });
-  return llvm::make_range(Args.begin(), firstDefaultArg);
+  return llvm::make_range(Args.begin(), FirstDefaultArg);
 }
 
 static syntax::NodeKind getOperatorNodeKind(const CXXOperatorCallExpr &E) {
@@ -954,12 +954,12 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc QualifierLoc) {
 if (!QualifierLoc)
   return true;
-for (auto it = QualifierLoc; it; it = it.getPrefix()) {
-  auto *NS = buildNameSpecifier(it);
+for (auto It = QualifierLoc; It; It = It.getPrefix()) {
+  auto *NS = buildNameSpecifier(It);
   if (!NS)
 return false;
   Builder.markChild(NS, syntax::NodeRole::ListElement);
-  Builder.markChildToken(it.getEndLoc(), syntax::NodeRole::ListDelimiter);
+  Builder.markChildToken(It.getEndLoc(), syntax::NodeRole::ListDelimiter);
 }
 Builder.foldNode(Builder.getRange(QualifierLoc.getSourceRange()),
  new (allocator()) syntax::NestedNameSpecifier,

diff  --git a/clang/lib/Tooling/Syntax/Nodes.cpp 
b/clang/lib/Tooling/Syntax/Nodes.cpp
index bb63585cbd7c..24b7a8596382 100644
--- a/clang/lib/Tooling/Syntax/Nodes.cpp
+++ b/clang/lib/Tooling/Syntax/Nodes.cpp
@@ -226,23 +226,23 @@ raw_ostream &syntax::operator<<(raw_ostream &OS, NodeRole 
R) {
 // vector
 std::vector
 syntax::NestedNameSpecifier::getSpecifiers() {
-  auto specifiersAsNodes = getElementsAsNodes();
+  auto SpecifiersAsNodes = getElementsAsNodes();
   std::vector Children;
-  for (const auto &element : specifiersAsNodes) {
-Children.push_back(llvm::cast(element));
+  for (const auto &Element : SpecifiersAsNodes) {
+Children.push_back(llvm::cast(Element));
   }
   return Children;
 }
 
 std::vector>
 syntax::NestedNameSpecifier::getSpecifiersAndDoubleColons() {
-  auto specifiersAsNodesAndDoubleColons = getElementsAsNodesAndDelimiters();
+  auto SpecifiersAsNodesAndDoubleColons = getElementsAsNodesAndDelimiters();
   std::vector>
   Children;
-  for (const auto &specifierAndDoubleColon : specifiersAsNodesAndDoubleColons) 
{
+  for (const auto &SpecifierAndDoubleColon : SpecifiersAsNodesAndDoubleColons) 
{
 Children.push_back(
-{llvm::cast(specifierAndDoubleColon.element),
- specifierAndDoubleColon.delimiter});
+{llvm::cast(SpecifierAndDoubleColon.element),
+ SpecifierAndDoubleColon.delimiter});
   }
   return Children;
 }

diff  --git a/clang/lib/Tooling/Syntax/Tree.cpp 
b/clang/lib/Tooling/Syntax/Tree.cpp
index 1edd2583105a..2c77e8f64944 100644
--- a/clang/lib/Tooling/Syntax/Tree.cpp
+++ b/clang/lib/Tooling/Syntax/Tree.cpp
@@ -153,7 +153,7 @@ static void dumpLeaf(raw_ostream &OS, const syntax::Leaf *L,
 
 static void dumpNode(raw_ostream &OS, const syntax::Node *N,
  const SourceManager &SM, std::vector IndentMask) {
-  auto dumpExtraInfo = [&OS](const syntax::Node *N) {
+  auto DumpExtraInfo = [&OS](const syntax::Node *N) {
 if (N->getRole() != syntax::NodeRole::Unknown)
   OS << " " << N->getRole();
 if (!N->isOriginal())
@@ -167,14 +167,14 @@ static void dumpNode(raw_ostream &OS, const syntax::Node 
*N,
 OS << "'";
 dumpLeaf(OS, L, SM);
 OS << "'";
-dumpExtraInfo(N);
+DumpExtraInfo(N);
 OS << "\n";
 return;
   }
 
   const auto *T = cast(N);
   OS << T->getKind();
-  dumpExtraInfo(N);
+  DumpExtraInfo(N);
   OS << "\n";
 
   for (const auto *It = T->getFirstChild(); It; It = It->getNextSibling()) {
@@ -302,20 +302,20 @@ syntax::List::getElementsAsNodesAndDelimiters() {
   if (!getFirstChild())
 return {};
 
-  auto children = std::vector>();
-  syntax::Node *elementWithoutDelimiter = nullptr;
+  std::vector> Children;
+  syntax::Node *Elemen

[PATCH] D82445: [analyzer][solver] Track symbol equivalence

2020-09-21 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

We came up with a quick fix, let us know what you think:
https://reviews.llvm.org/D88019


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82445

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


[PATCH] D88019: [analyzer][solver] Fix issue with symbol non-equality tracking

2020-09-21 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

@steakhal, thank you for your time and huge effort in debugging this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88019

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


[PATCH] D88019: [analyzer][solver] Fix issue with symbol non-equality tracking

2020-09-21 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

I came up with exactly the same fix! Great job!
I just wanted to refactor it and not having

  if (New.isEmpty())
// this is infeasible assumption
return nullptr;
  
  ProgramStateRef NewState = setConstraint(St, Sym, New);
  return trackNE(NewState, Sym, Int, Adjustment);

repeated in different places


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88019

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


[clang-tools-extra] 4fc0214 - [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

2020-09-21 Thread Adam Balogh via cfe-commits

Author: Adam Balogh
Date: 2020-09-21T14:42:58+02:00
New Revision: 4fc0214a10140fa77449677e8094ea22d3d17701

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

LOG: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

Finds member initializations in the constructor body which can be placed
into the initialization list instead. This does not only improves the
readability of the code but also affects positively its performance.
Class-member assignments inside a control statement or following the
first control statement are ignored.

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

Added: 

clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.h

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-prefer-member-initializer.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-modernize-use-default-member-init-assignment.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-modernize-use-default-member-init.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp

Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
index 39c2c552eb73..a9f5b3e0c15b 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
@@ -13,6 +13,7 @@ add_clang_library(clangTidyCppCoreGuidelinesModule
   NarrowingConversionsCheck.cpp
   NoMallocCheck.cpp
   OwningMemoryCheck.cpp
+  PreferMemberInitializerCheck.cpp
   ProBoundsArrayToPointerDecayCheck.cpp
   ProBoundsConstantArrayIndexCheck.cpp
   ProBoundsPointerArithmeticCheck.cpp

diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
index 4cb5022888d3..bf613109f0eb 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -22,6 +22,7 @@
 #include "NarrowingConversionsCheck.h"
 #include "NoMallocCheck.h"
 #include "OwningMemoryCheck.h"
+#include "PreferMemberInitializerCheck.h"
 #include "ProBoundsArrayToPointerDecayCheck.h"
 #include "ProBoundsConstantArrayIndexCheck.h"
 #include "ProBoundsPointerArithmeticCheck.h"
@@ -66,6 +67,8 @@ class CppCoreGuidelinesModule : public ClangTidyModule {
 "cppcoreguidelines-non-private-member-variables-in-classes");
 CheckFactories.registerCheck(
 "cppcoreguidelines-owning-memory");
+CheckFactories.registerCheck(
+"cppcoreguidelines-prefer-member-initializer");
 CheckFactories.registerCheck(
 "cppcoreguidelines-pro-bounds-array-to-pointer-decay");
 CheckFactories.registerCheck(

diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
new file mode 100644
index ..bc0a3b98ac7a
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -0,0 +1,246 @@
+//===--- PreferMemberInitializerCheck.cpp - clang-tidy ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "PreferMemberInitializerCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+static bool isControlStatement(const Stmt *S) {
+  return isa(S);
+}
+
+static bool isNoReturnCallStatement(const Stmt *S) {
+  const auto *Call = dyn_cast(S);
+  if (!Call)
+return false;
+
+  const FunctionDecl *Func = Call->getDirectCallee();
+  if (!Func)
+return false;
+
+  return Func->isNoReturn();
+}
+
+static bool isLiteral(const Expr *E) {
+  return isa(E);
+}
+
+static bool isUnaryExprOfLiteral(const Expr *E) {
+  if (const auto *UnOp = dyn_cast(E))
+return isLiteral(UnOp->getSubExpr());
+  return false;
+}
+
+static 

[PATCH] D71199: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

2020-09-21 Thread Balogh , Ádám via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4fc0214a1014: [clang-tidy] New check 
cppcoreguidelines-prefer-member-initializer (authored by baloghadamsoftware).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71199

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-prefer-member-initializer.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-modernize-use-default-member-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
@@ -0,0 +1,490 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-prefer-member-initializer %t -- -- -fcxx-exceptions
+
+extern void __assert_fail (__const char *__assertion, __const char *__file,
+unsigned int __line, __const char *__function)
+ __attribute__ ((__noreturn__));
+#define assert(expr) \
+  ((expr)  ? (void)(0)  : __assert_fail (#expr, __FILE__, __LINE__, __func__))
+
+class Simple1 {
+  int n;
+  double x;
+
+public:
+  Simple1() {
+// CHECK-FIXES: Simple1() : n(0), x(0.0) {
+n = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+x = 0.0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple1(int nn, double xx) {
+// CHECK-FIXES: Simple1(int nn, double xx) : n(nn), x(xx) {
+n = nn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+x = xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple1() = default;
+};
+
+class Simple2 {
+  int n;
+  double x;
+
+public:
+  Simple2() : n(0) {
+// CHECK-FIXES: Simple2() : n(0), x(0.0) {
+x = 0.0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple2(int nn, double xx) : n(nn) {
+// CHECK-FIXES: Simple2(int nn, double xx) : n(nn), x(xx) {
+x = xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple2() = default;
+};
+
+class Simple3 {
+  int n;
+  double x;
+
+public:
+  Simple3() : x(0.0) {
+// CHECK-FIXES: Simple3() : n(0), x(0.0) {
+n = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple3(int nn, double xx) : x(xx) {
+// CHECK-FIXES: Simple3(int nn, double xx) : n(nn), x(xx) {
+n = nn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple3() = default;
+};
+
+int something_int();
+double something_double();
+
+class Simple4 {
+  int n;
+
+public:
+  Simple4() {
+// CHECK-FIXES: Simple4() : n(something_int()) {
+n = something_int();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple4() = default;
+};
+
+static bool dice();
+
+class Complex1 {
+  int n;
+  int m;
+
+public:
+  Complex1() : n(0) {
+if (dice())
+  m = 1;
+// NO-MESSAGES: initialization of 'm' is nested in a conditional expression
+  }
+
+  ~Complex1() = default;
+};
+
+class Complex2 {
+  int n;
+  int m;
+
+pub

[PATCH] D88019: [analyzer][solver] Fix issue with symbol non-equality tracking

2020-09-21 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

After this "accepted" and a huge thank you 😄




Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1350-1371
   ProgramStateRef trackEQ(ProgramStateRef State, SymbolRef Sym,
   const llvm::APSInt &Int,
   const llvm::APSInt &Adjustment) {
 if (auto Equality = EqualityInfo::extract(Sym, Int, Adjustment)) {
   // Extract function assumes that we gave it Sym + Adjustment != Int,
   // so the result should be opposite.
   Equality->invert();

I suggest to change these two functions this way, so we can avoid the same 
pattern in 4 different functions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88019

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


[PATCH] D88021: [clang] Fix a misleading variable name. NFC.

2020-09-21 Thread Igor Kudrin via Phabricator via cfe-commits
ikudrin created this revision.
ikudrin added reviewers: thakis, hans, MaskRay.
ikudrin added projects: LLVM, clang.
ikudrin requested review of this revision.

The variable is true when frame pointers should be omitted in leaf functions, 
not kept.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88021

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


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -604,12 +604,12 @@
   bool OmitFP = A && A->getOption().matches(options::OPT_fomit_frame_pointer);
   bool NoOmitFP =
   A && A->getOption().matches(options::OPT_fno_omit_frame_pointer);
-  bool KeepLeaf = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
-   options::OPT_mno_omit_leaf_frame_pointer,
-   Triple.isAArch64() || Triple.isPS4CPU());
+  bool OmitLeafFP = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
+ options::OPT_mno_omit_leaf_frame_pointer,
+ Triple.isAArch64() || Triple.isPS4CPU());
   if (NoOmitFP || mustUseNonLeafFramePointerForTarget(Triple) ||
   (!OmitFP && useFramePointerForTargetByDefault(Args, Triple))) {
-if (KeepLeaf)
+if (OmitLeafFP)
   return CodeGenOptions::FramePointerKind::NonLeaf;
 return CodeGenOptions::FramePointerKind::All;
   }


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -604,12 +604,12 @@
   bool OmitFP = A && A->getOption().matches(options::OPT_fomit_frame_pointer);
   bool NoOmitFP =
   A && A->getOption().matches(options::OPT_fno_omit_frame_pointer);
-  bool KeepLeaf = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
-   options::OPT_mno_omit_leaf_frame_pointer,
-   Triple.isAArch64() || Triple.isPS4CPU());
+  bool OmitLeafFP = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
+ options::OPT_mno_omit_leaf_frame_pointer,
+ Triple.isAArch64() || Triple.isPS4CPU());
   if (NoOmitFP || mustUseNonLeafFramePointerForTarget(Triple) ||
   (!OmitFP && useFramePointerForTargetByDefault(Args, Triple))) {
-if (KeepLeaf)
+if (OmitLeafFP)
   return CodeGenOptions::FramePointerKind::NonLeaf;
 return CodeGenOptions::FramePointerKind::All;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87972: [OldPM] Pass manager: run SROA after (simple) loop unrolling

2020-09-21 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

I assume this makes 1f4e7463b5e3ff654c84371527767830e51db10d 
 redundant?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87972

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


[PATCH] D87972: [OldPM] Pass manager: run SROA after (simple) loop unrolling

2020-09-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D87972#2285176 , @arsenm wrote:

> I assume this makes 1f4e7463b5e3ff654c84371527767830e51db10d 
>  
> redundant?

Yes, see `llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp` change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87972

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


[PATCH] D87972: [OldPM] Pass manager: run SROA after (simple) loop unrolling

2020-09-21 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: clang/test/Misc/loop-opt-setup.c:2
+// RUN: %clang -O1 -fexperimental-new-pass-manager -fno-unroll-loops -S -o - 
%s -emit-llvm | FileCheck %s -check-prefixes=CHECK-ALL,CHECK-NEWPM
+// RUN: %clang -O1 -fno-experimental-new-pass-manager -fno-unroll-loops -S -o 
- %s -emit-llvm | FileCheck %s -check-prefixes=CHECK-ALL,CHECK-NEWPM
 extern int a[16];

OLDPM?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87972

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


[PATCH] D83004: [UpdateCCTestChecks] Include generated functions if asked

2020-09-21 Thread Momchil Velikov via Phabricator via cfe-commits
chill added a comment.

Some tests started failing: 
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-ubuntu/builds/9071


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83004

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


[PATCH] D88003: Fix typos in ASTMatchers.h

2020-09-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added a comment.

Thank you for the fixes! Please regenerate the AST matcher documentation by 
running `clang/docs/tools/dump_ast_matchers.py` so that the public 
documentation picks up the typo fixes as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88003

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


[PATCH] D87942: [Analyzer] GNU named variadic macros in Plister

2020-09-21 Thread Chris Hamilton via Phabricator via cfe-commits
chrish_ericsson_atx updated this revision to Diff 293154.
chrish_ericsson_atx added a comment.

Addressed feedback from @Szelethus


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87942

Files:
  clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  
clang/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
  clang/test/Analysis/plist-macros-with-expansion.cpp

Index: clang/test/Analysis/plist-macros-with-expansion.cpp
===
--- clang/test/Analysis/plist-macros-with-expansion.cpp
+++ clang/test/Analysis/plist-macros-with-expansion.cpp
@@ -529,3 +529,17 @@
 // FIXME: Stringify and escape __VA_ARGS__ correctly.
 // CHECK: nameSTRINGIFIED_VA_ARGS
 // CHECK-NEXT: expansionvariadicCFunction(x, "Additional supply depots required.", ")";x = 0;
+
+// bz44493: Support GNU-style named variadic arguments in plister
+#define BZ44493_GNUVA(i, args...)  --(i);
+
+int bz44493(void) {
+  int a = 2;
+  BZ44493_GNUVA(a);
+  BZ44493_GNUVA(a, "arg2");
+  (void)(10 / a); // expected-warning{{Division by zero}}
+  return 0;
+}
+
+// CHECK: nameBZ44493_GNUVA
+// CHECK-NEXT: expansion--(a);
Index: clang/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
===
--- clang/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
+++ clang/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
@@ -6787,6 +6787,142 @@

   
   
+  
+   path
+   
+
+ kindcontrol
+ edges
+  
+   
+start
+ 
+  
+   line537
+   col3
+   file0
+  
+  
+   line537
+   col5
+   file0
+  
+ 
+end
+ 
+  
+   line539
+   col3
+   file0
+  
+  
+   line539
+   col15
+   file0
+  
+ 
+   
+  
+
+
+ kindevent
+ location
+ 
+  line539
+  col3
+  file0
+ 
+ ranges
+ 
+   
+
+ line539
+ col3
+ file0
+
+
+ line539
+ col26
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ The value 0 is assigned to 'a'
+ message
+ The value 0 is assigned to 'a'
+
+
+ kindevent
+ location
+ 
+  line540
+  col13
+  file0
+ 
+ ranges
+ 
+   
+
+ line540
+ col10
+ file0
+
+
+ line540
+ col15
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ Division by zero
+ message
+ Division by zero
+
+   
+   macro_expansions
+   
+
+ location
+ 
+  line539
+  col3
+  file0
+ 
+ nameBZ44493_GNUVA
+ expansion--(a);
+
+   
+   descriptionDivision by zero
+   categoryLogic error
+   typeDivision by zero
+   check_namecore.DivideZero
+   
+   issue_hash_content_of_line_in_context21c6d180d8c8c30cf730b7a7136980a9
+  issue_context_kindfunction
+  issue_contextbz44493
+  issue_hash_function_offset4
+  location
+  
+   line540
+   col13
+   file0
+  
+  ExecutedLines
+  
+   0
+   
+536
+537
+538
+539
+540
+   
+  
+  
  
  files
  
Index: clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -1132,7 +1132,7 @@
   std::string MacroName = PP.getSpelling(TheTok);
 
   const auto *II = PP.getIdentifierInfo(MacroName);
-  assert(II && "Failed to acquire the IndetifierInfo for the macro!");
+  assert(II && "Failed to acquire the IdentifierInfo for the macro!");
 
   const MacroInfo *MI = getMacroInfoForLocation(PP, SM, II, ExpanLoc);
   // assert(MI && "The macro must've been defined at it's expansion location!");
@@ -1180,9 +1180,16 @@
   //   * > 1, then tok::comma is a part of the current arg.
   int ParenthesesDepth = 1;
 
-  // If we encounter __VA_ARGS__, we will lex until the closing tok::r_paren,
-  // even if we lex a tok::comma and ParanthesesDepth == 1.
-  const IdentifierInfo *__VA_ARGS__II = PP.getIdentifierInfo("__VA_ARGS__");
+  // If we encounter the variadic arg, we will lex until the closing
+  // tok::r_paren, even if we lex a tok::comma and ParanthesesDepth == 1.
+  const IdentifierInfo *VariadicParamII = PP.getIdentifierInfo("__VA_ARGS__");
+  if (MI->isGNUVarargs()) {
+// If macro uses GNU-style variadic args, the param name is user-supplied,
+// an not "__VA_ARGS__".  E.g.:
+//   #define FOO(a, b, myvargs...)
+// In this case, just use the last parameter:
+VariadicParamII = *(MacroParams.rbegin());
+  }
 
   for (c

[PATCH] D87942: [Analyzer] GNU named variadic macros in Plister

2020-09-21 Thread Chris Hamilton via Phabricator via cfe-commits
chrish_ericsson_atx marked 2 inline comments as done.
chrish_ericsson_atx added a comment.

Thanks for the quick feedback, Kristof!  I changed the macro to be just a 
decrement operator, and triggered DBZ with that.  Added the checks as you 
suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87942

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


[PATCH] D79388: [clang-format] Fix AlignConsecutive on PP blocks

2020-09-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

@JakeMerdichAMD  this has caused a regression 
https://bugs.llvm.org/show_bug.cgi?id=47589


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79388

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


[PATCH] D79388: [clang-format] Fix AlignConsecutive on PP blocks

2020-09-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2996
 Line->Tokens.back().Tok->MustBreakBefore = true;
+Line->Tokens.back().Tok->MustBreakAlignBefore = true;
 MustBreakBeforeNextToken = false;

If the line ends with a comment and we have align trailing comments turned on 
then I think this breaks the alignment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79388

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


[PATCH] D87394: [PowerPC][Power10] Implementation of 128-bit Binary Vector Mod and Sign Extend builtins

2020-09-21 Thread Amy Kwan via Phabricator via cfe-commits
amyk accepted this revision.
amyk added a comment.
This revision is now accepted and ready to land.

Thanks for open coding. Aside from Nemanja's nits, I believe all my concerns 
have been addressed. LGTM.


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

https://reviews.llvm.org/D87394

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


[PATCH] D87910: [PowerPC] Implement the 128-bit vec_[all|any]_[eq | ne | lt | gt | le | ge] builtins in Clang/LLVM

2020-09-21 Thread Amy Kwan via Phabricator via cfe-commits
amyk updated this revision to Diff 293161.
amyk added a comment.

Updated identation/formatting of code in `CGExprScalar.cpp` and `altivec.h`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87910

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-p10vector.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/vec_cmpq.ll

Index: llvm/test/CodeGen/PowerPC/vec_cmpq.ll
===
--- llvm/test/CodeGen/PowerPC/vec_cmpq.ll
+++ llvm/test/CodeGen/PowerPC/vec_cmpq.ll
@@ -231,3 +231,31 @@
 ; CHECK-LABEL: test_vcmpgtuq
 ; CHECK: vcmpgtuq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
 }
+
+declare i32 @llvm.ppc.altivec.vcmpequq.p(i32, <1 x i128>, <1 x i128>) nounwind readnone
+declare i32 @llvm.ppc.altivec.vcmpgtsq.p(i32, <1 x i128>, <1 x i128>) nounwind readnone
+declare i32 @llvm.ppc.altivec.vcmpgtuq.p(i32, <1 x i128>, <1 x i128>) nounwind readnone
+
+define i32 @test_vcmpequq_p(<1 x i128> %x, <1 x i128> %y) {
+  %tmp = tail call i32 @llvm.ppc.altivec.vcmpequq.p(i32 2, <1 x i128> %x, <1 x i128> %y)
+  ret i32 %tmp
+; CHECK-LABEL: test_vcmpequq_p:
+; CHECK: vcmpequq. {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: blr
+}
+
+define i32 @test_vcmpgtsq_p(<1 x i128> %x, <1 x i128> %y) {
+  %tmp = tail call i32 @llvm.ppc.altivec.vcmpgtsq.p(i32 2, <1 x i128> %x, <1 x i128> %y)
+  ret i32 %tmp
+; CHECK-LABEL: test_vcmpgtsq_p
+; CHECK: vcmpgtsq. {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: blr
+}
+
+define i32 @test_vcmpgtuq_p(<1 x i128> %x, <1 x i128> %y) {
+  %tmp = tail call i32 @llvm.ppc.altivec.vcmpgtuq.p(i32 2, <1 x i128> %x, <1 x i128> %y)
+  ret i32 %tmp
+; CHECK-LABEL: test_vcmpgtuq_p
+; CHECK: vcmpgtuq. {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: blr
+}
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -10323,6 +10323,26 @@
   break;
 }
 break;
+  case Intrinsic::ppc_altivec_vcmpequq_p:
+  case Intrinsic::ppc_altivec_vcmpgtsq_p:
+  case Intrinsic::ppc_altivec_vcmpgtuq_p:
+if (!Subtarget.isISA3_1())
+  return false;
+switch (IntrinsicID) {
+default:
+  llvm_unreachable("Unknown comparison intrinsic.");
+case Intrinsic::ppc_altivec_vcmpequq_p:
+  CompareOpc = 455;
+  break;
+case Intrinsic::ppc_altivec_vcmpgtsq_p:
+  CompareOpc = 903;
+  break;
+case Intrinsic::ppc_altivec_vcmpgtuq_p:
+  CompareOpc = 647;
+  break;
+}
+isDot = true;
+break;
   }
   return true;
 }
@@ -15189,16 +15209,19 @@
 case Intrinsic::ppc_altivec_vcmpequh_p:
 case Intrinsic::ppc_altivec_vcmpequw_p:
 case Intrinsic::ppc_altivec_vcmpequd_p:
+case Intrinsic::ppc_altivec_vcmpequq_p:
 case Intrinsic::ppc_altivec_vcmpgefp_p:
 case Intrinsic::ppc_altivec_vcmpgtfp_p:
 case Intrinsic::ppc_altivec_vcmpgtsb_p:
 case Intrinsic::ppc_altivec_vcmpgtsh_p:
 case Intrinsic::ppc_altivec_vcmpgtsw_p:
 case Intrinsic::ppc_altivec_vcmpgtsd_p:
+case Intrinsic::ppc_altivec_vcmpgtsq_p:
 case Intrinsic::ppc_altivec_vcmpgtub_p:
 case Intrinsic::ppc_altivec_vcmpgtuh_p:
 case Intrinsic::ppc_altivec_vcmpgtuw_p:
 case Intrinsic::ppc_altivec_vcmpgtud_p:
+case Intrinsic::ppc_altivec_vcmpgtuq_p:
   Known.Zero = ~1U;  // All bits but the low one are known to be zero.
   break;
 }
Index: llvm/include/llvm/IR/IntrinsicsPowerPC.td
===
--- llvm/include/llvm/IR/IntrinsicsPowerPC.td
+++ llvm/include/llvm/IR/IntrinsicsPowerPC.td
@@ -370,6 +370,18 @@
   def int_ppc_altivec_vcmpgtuq : GCCBuiltin<"__builtin_altivec_vcmpgtuq">,
   Intrinsic<[llvm_v1i128_ty], [llvm_v1i128_ty, llvm_v1i128_ty],
 [IntrNoMem]>;
+  def int_ppc_altivec_vcmpequq_p : GCCBuiltin<"__builtin_altivec_vcmpequq_p">,
+  Intrinsic<[llvm_i32_ty],
+[llvm_i32_ty,llvm_v1i128_ty,llvm_v1i128_ty],
+[IntrNoMem]>;
+  def int_ppc_altivec_vcmpgtsq_p : GCCBuiltin<"__builtin_altivec_vcmpgtsq_p">,
+  Intrinsic<[llvm_i32_ty],
+[llvm_i32_ty,llvm_v1i128_ty,llvm_v1i128_ty],
+[IntrNoMem]>;
+  def int_ppc_altivec_vcmpgtuq_p : GCCBuiltin<"__builtin_altivec_vcmpgtuq_p">,
+  Intrinsic<[llvm_i32_ty],
+[llvm_i32_ty,llvm_v1i128_ty,llvm_v1i128_ty],
+[IntrNoMem]>;
 
   // Predicate Comparisons.  The first operand specifies interpretation of CR6.
   def int_ppc_altivec_vcmpbfp_p : GCCBuiltin<"__builtin_altivec_vcmpbfp_p">,
Index: clang/test/Cod

[PATCH] D87779: [SyntaxTree] Test `findFirstLeaf` and `findLastLeaf`

2020-09-21 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 293163.
eduucaldas marked 3 inline comments as done.
eduucaldas added a comment.

- Answer Review
- Change names in `generateAllTreesWithShape`
- `auto x = vector()` -> `vector x;`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87779

Files:
  clang/lib/Tooling/Syntax/Tree.cpp
  clang/unittests/Tooling/Syntax/CMakeLists.txt
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -0,0 +1,123 @@
+//===- TreeTest.cpp -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/Syntax/Tree.h"
+#include "TreeTestBase.h"
+#include "clang/Tooling/Syntax/BuildTree.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace clang::syntax;
+
+namespace {
+
+class TreeTest : public SyntaxTreeTest {
+private:
+  Tree *createTree(ArrayRef Children) {
+std::vector> ChildrenWithRoles;
+ChildrenWithRoles.reserve(Children.size());
+for (const auto *Child : Children) {
+  ChildrenWithRoles.push_back(
+  std::make_pair(deepCopy(*Arena, Child), NodeRole::Unknown));
+}
+return clang::syntax::createTree(*Arena, ChildrenWithRoles,
+ NodeKind::UnknownExpression);
+  }
+
+  // Generate Forests by combining `Children` into `ParentCount` Trees.
+  //
+  // We do this recursively.
+  std::vector>
+  generateAllForests(ArrayRef Children, unsigned ParentCount) {
+assert(ParentCount > 0);
+// If there is only one Parent node, then combine `Children` under
+// this Parent.
+if (ParentCount == 1)
+  return {{createTree(Children)}};
+
+// Otherwise, combine `ChildrenCount` children under the last parent and
+// solve the smaller problem without these children and this parent. Do this
+// for every `ChildrenCount` and combine the results.
+std::vector> AllForests;
+for (unsigned ChildrenCount = 0; ChildrenCount <= Children.size();
+ ++ChildrenCount) {
+  auto *LastParent = createTree(Children.take_back(ChildrenCount));
+  for (auto &Forest : generateAllForests(Children.drop_back(ChildrenCount),
+ ParentCount - 1)) {
+Forest.push_back(LastParent);
+AllForests.push_back(Forest);
+  }
+}
+return AllForests;
+  }
+
+protected:
+  // Generates all trees with a `Base` of `Node`s and `NodeCountPerLayer`
+  // `Node`s per layer. An example of Tree with `Base` = {`(`, `)`} and
+  // `NodeCountPerLayer` = {2, 2}:
+  //  Tree
+  //  |-Tree
+  //  `-Tree
+  //|-Tree
+  //| `-'('
+  //`-Tree
+  //  `-')'
+  std::vector
+  generateAllTreesWithShape(ArrayRef Base,
+ArrayRef NodeCountPerLayer) {
+auto GenerateNextLayer = [this](ArrayRef> Layer,
+unsigned NextLayerNodeCount) {
+  std::vector> NextLayer;
+  for (const auto &Base : Layer) {
+for (const auto &NextBase :
+ generateAllForests(Base, NextLayerNodeCount)) {
+  NextLayer.push_back(
+  std::vector(NextBase.begin(), NextBase.end()));
+}
+  }
+  return NextLayer;
+};
+
+std::vector> Layer = {Base};
+for (auto NodeCount : NodeCountPerLayer) {
+  Layer = GenerateNextLayer(Layer, NodeCount);
+}
+
+std::vector AllTrees;
+AllTrees.reserve(Layer.size());
+for (const auto &Base : Layer) {
+  AllTrees.push_back(createTree(Base));
+}
+return AllTrees;
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(TreeTests, TreeTest,
+::testing::ValuesIn(allTestClangConfigs()), );
+
+TEST_P(TreeTest, FirstLeaf) {
+  buildTree("", GetParam());
+  std::vector Leafs = {createLeaf(*Arena, tok::l_paren),
+ createLeaf(*Arena, tok::r_paren)};
+  for (const auto *Tree : generateAllTreesWithShape(Leafs, {3u})) {
+ASSERT_TRUE(Tree->findFirstLeaf() != nullptr);
+EXPECT_EQ(Tree->findFirstLeaf()->getToken()->kind(), tok::l_paren);
+  }
+}
+
+TEST_P(TreeTest, LastLeaf) {
+  buildTree("", GetParam());
+  std::vector Leafs = {createLeaf(*Arena, tok::l_paren),
+ createLeaf(*Arena, tok::r_paren)};
+  for (const auto *Tree : generateAllTreesWithShape(Leafs, {3u})) {
+ASSERT_TRUE(Tree->findLastLeaf() != nullptr);
+EXPECT_EQ(Tree->findLastLeaf()->getToken()->kind(), tok::r_paren);
+  }
+}
+
+} // namespace
Index: clang/unittests/Tooling/Syntax/C

[PATCH] D87914: [AIX][Clang][Driver] Add handling of shared option

2020-09-21 Thread Jason Liu via Phabricator via cfe-commits
jasonliu accepted this revision.
jasonliu 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/D87914/new/

https://reviews.llvm.org/D87914

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


[PATCH] D87779: [SyntaxTree] Test `findFirstLeaf` and `findLastLeaf`

2020-09-21 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 293167.
eduucaldas added a comment.

Comment `generateAllTreesWithShape`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87779

Files:
  clang/lib/Tooling/Syntax/Tree.cpp
  clang/unittests/Tooling/Syntax/CMakeLists.txt
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -0,0 +1,125 @@
+//===- TreeTest.cpp -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/Syntax/Tree.h"
+#include "TreeTestBase.h"
+#include "clang/Tooling/Syntax/BuildTree.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace clang::syntax;
+
+namespace {
+
+class TreeTest : public SyntaxTreeTest {
+private:
+  Tree *createTree(ArrayRef Children) {
+std::vector> ChildrenWithRoles;
+ChildrenWithRoles.reserve(Children.size());
+for (const auto *Child : Children) {
+  ChildrenWithRoles.push_back(
+  std::make_pair(deepCopy(*Arena, Child), NodeRole::Unknown));
+}
+return clang::syntax::createTree(*Arena, ChildrenWithRoles,
+ NodeKind::UnknownExpression);
+  }
+
+  // Generate Forests by combining `Children` into `ParentCount` Trees.
+  //
+  // We do this recursively.
+  std::vector>
+  generateAllForests(ArrayRef Children, unsigned ParentCount) {
+assert(ParentCount > 0);
+// If there is only one Parent node, then combine `Children` under
+// this Parent.
+if (ParentCount == 1)
+  return {{createTree(Children)}};
+
+// Otherwise, combine `ChildrenCount` children under the last parent and
+// solve the smaller problem without these children and this parent. Do this
+// for every `ChildrenCount` and combine the results.
+std::vector> AllForests;
+for (unsigned ChildrenCount = 0; ChildrenCount <= Children.size();
+ ++ChildrenCount) {
+  auto *LastParent = createTree(Children.take_back(ChildrenCount));
+  for (auto &Forest : generateAllForests(Children.drop_back(ChildrenCount),
+ ParentCount - 1)) {
+Forest.push_back(LastParent);
+AllForests.push_back(Forest);
+  }
+}
+return AllForests;
+  }
+
+protected:
+  // Generates all trees with a `Base` of `Node`s and `NodeCountPerLayer`
+  // `Node`s per layer. An example of Tree with `Base` = {`(`, `)`} and
+  // `NodeCountPerLayer` = {2, 2}:
+  //  Tree
+  //  |-Tree
+  //  `-Tree
+  //|-Tree
+  //| `-'('
+  //`-Tree
+  //  `-')'
+  std::vector
+  generateAllTreesWithShape(ArrayRef Base,
+ArrayRef NodeCountPerLayer) {
+// We compute the solution per layer. A layer is a collection of bases,
+// where each base has the same number of nodes, given by
+// `NodeCountPerLayer`.
+auto GenerateNextLayer = [this](ArrayRef> Layer,
+unsigned NextLayerNodeCount) {
+  std::vector> NextLayer;
+  for (const auto &Base : Layer) {
+for (const auto &NextBase :
+ generateAllForests(Base, NextLayerNodeCount)) {
+  NextLayer.push_back(
+  std::vector(NextBase.begin(), NextBase.end()));
+}
+  }
+  return NextLayer;
+};
+
+std::vector> Layer = {Base};
+for (auto NodeCount : NodeCountPerLayer)
+  Layer = GenerateNextLayer(Layer, NodeCount);
+
+std::vector AllTrees;
+AllTrees.reserve(Layer.size());
+for (const auto &Base : Layer)
+  AllTrees.push_back(createTree(Base));
+
+return AllTrees;
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(TreeTests, TreeTest,
+::testing::ValuesIn(allTestClangConfigs()), );
+
+TEST_P(TreeTest, FirstLeaf) {
+  buildTree("", GetParam());
+  std::vector Leafs = {createLeaf(*Arena, tok::l_paren),
+ createLeaf(*Arena, tok::r_paren)};
+  for (const auto *Tree : generateAllTreesWithShape(Leafs, {3u})) {
+ASSERT_TRUE(Tree->findFirstLeaf() != nullptr);
+EXPECT_EQ(Tree->findFirstLeaf()->getToken()->kind(), tok::l_paren);
+  }
+}
+
+TEST_P(TreeTest, LastLeaf) {
+  buildTree("", GetParam());
+  std::vector Leafs = {createLeaf(*Arena, tok::l_paren),
+ createLeaf(*Arena, tok::r_paren)};
+  for (const auto *Tree : generateAllTreesWithShape(Leafs, {3u})) {
+ASSERT_TRUE(Tree->findLastLeaf() != nullptr);
+EXPECT_EQ(Tree->findLastLeaf()->getToken()->kind(), tok::r_paren);
+  }
+}
+
+} // name

[PATCH] D88019: [analyzer][solver] Fix issue with symbol non-equality tracking

2020-09-21 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Thanks for the quick review!
I updated according to your suggestion, so we avoid the same pattern.




Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1350-1371
   ProgramStateRef trackEQ(ProgramStateRef State, SymbolRef Sym,
   const llvm::APSInt &Int,
   const llvm::APSInt &Adjustment) {
 if (auto Equality = EqualityInfo::extract(Sym, Int, Adjustment)) {
   // Extract function assumes that we gave it Sym + Adjustment != Int,
   // so the result should be opposite.
   Equality->invert();

vsavchenko wrote:
> I suggest to change these two functions this way, so we can avoid the same 
> pattern in 4 different functions
> I suggest to change these two functions this way, so we can avoid the same 
> pattern in 4 different functions




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88019

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


[PATCH] D88019: [analyzer][solver] Fix issue with symbol non-equality tracking

2020-09-21 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 293168.
martong marked an inline comment as done.
martong added a comment.

- Avoid same pattern when checking whether the assumption is infeasible


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88019

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/equality_tracking.c

Index: clang/test/Analysis/equality_tracking.c
===
--- clang/test/Analysis/equality_tracking.c
+++ clang/test/Analysis/equality_tracking.c
@@ -185,3 +185,37 @@
 }
   }
 }
+
+void avoidInfeasibleConstraintforGT(int a, int b) {
+  int c = b - a;
+  if (c <= 0)
+return;
+  // c > 0
+  // b - a > 0
+  // b > a
+  if (a != b) {
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+return;
+  }
+  clang_analyzer_warnIfReached(); // no warning
+  // a == b
+  if (c < 0)
+;
+}
+
+void avoidInfeasibleConstraintforLT(int a, int b) {
+  int c = b - a;
+  if (c >= 0)
+return;
+  // c < 0
+  // b - a < 0
+  // b < a
+  if (a != b) {
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+return;
+  }
+  clang_analyzer_warnIfReached(); // no warning
+  // a == b
+  if (c < 0)
+;
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1347,27 +1347,35 @@
   // Equality tracking implementation
   //===--===//
 
-  ProgramStateRef trackEQ(ProgramStateRef State, SymbolRef Sym,
-  const llvm::APSInt &Int,
+  ProgramStateRef trackEQ(RangeSet NewConstraint, ProgramStateRef State,
+  SymbolRef Sym, const llvm::APSInt &Int,
   const llvm::APSInt &Adjustment) {
-if (auto Equality = EqualityInfo::extract(Sym, Int, Adjustment)) {
-  // Extract function assumes that we gave it Sym + Adjustment != Int,
-  // so the result should be opposite.
-  Equality->invert();
-  return track(State, *Equality);
-}
-
-return State;
+return track(NewConstraint, State, Sym, Int, Adjustment);
   }
 
-  ProgramStateRef trackNE(ProgramStateRef State, SymbolRef Sym,
-  const llvm::APSInt &Int,
+  ProgramStateRef trackNE(RangeSet NewConstraint, ProgramStateRef State,
+  SymbolRef Sym, const llvm::APSInt &Int,
   const llvm::APSInt &Adjustment) {
+return track(NewConstraint, State, Sym, Int, Adjustment);
+  }
+
+  template 
+  ProgramStateRef track(RangeSet NewConstraint, ProgramStateRef State,
+SymbolRef Sym, const llvm::APSInt &Int,
+const llvm::APSInt &Adjustment) {
+if (NewConstraint.isEmpty())
+  // This is an infeasible assumption.
+  return nullptr;
+
+ProgramStateRef NewState = setConstraint(State, Sym, NewConstraint);
 if (auto Equality = EqualityInfo::extract(Sym, Int, Adjustment)) {
-  return track(State, *Equality);
+  // If the original assumption is not Sym + Adjustment !=/ Int,
+  // we should invert IsEquality flag.
+  Equality->IsEquality = Equality->IsEquality != EQ;
+  return track(NewState, *Equality);
 }
 
-return State;
+return NewState;
   }
 
   ProgramStateRef track(ProgramStateRef State, EqualityInfo ToTrack) {
@@ -2042,12 +2050,7 @@
 
   RangeSet New = getRange(St, Sym).Delete(getBasicVals(), F, Point);
 
-  if (New.isEmpty())
-// this is infeasible assumption
-return nullptr;
-
-  ProgramStateRef NewState = setConstraint(St, Sym, New);
-  return trackNE(NewState, Sym, Int, Adjustment);
+  return trackNE(New, St, Sym, Int, Adjustment);
 }
 
 ProgramStateRef
@@ -2063,12 +2066,7 @@
   llvm::APSInt AdjInt = AdjustmentType.convert(Int) - Adjustment;
   RangeSet New = getRange(St, Sym).Intersect(getBasicVals(), F, AdjInt, AdjInt);
 
-  if (New.isEmpty())
-// this is infeasible assumption
-return nullptr;
-
-  ProgramStateRef NewState = setConstraint(St, Sym, New);
-  return trackEQ(NewState, Sym, Int, Adjustment);
+  return trackEQ(New, St, Sym, Int, Adjustment);
 }
 
 RangeSet RangeConstraintManager::getSymLTRange(ProgramStateRef St,
@@ -2104,7 +2102,7 @@
 const llvm::APSInt &Int,
 const llvm::APSInt &Adjustment) {
   RangeSet New = getSymLTRange(St, Sym, Int, Adjustment);
-  return New.isEmpty() ? nullptr : setConstraint(St, Sym, New);
+  return trackNE(New, St, Sym, Int, Adjustment);
 }
 
 RangeSet RangeConstraintManager::getSymGTRange(ProgramStateRef St,
@@ -2140,7 +2138,7 @@
 const llvm::APSInt &Int,

[PATCH] D88019: [analyzer][solver] Fix issue with symbol non-equality tracking

2020-09-21 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko accepted this revision.
vsavchenko added a comment.
This revision is now accepted and ready to land.

Amazing!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88019

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


[clang] 7c4575e - [ASTImporter] Refactor IsStructurallyEquivalent's Decl overloads to be more consistent

2020-09-21 Thread Raphael Isemann via cfe-commits

Author: Raphael Isemann
Date: 2020-09-21T16:41:00+02:00
New Revision: 7c4575e15f065312ad40ebe0d1ec1e1ffa4c6628

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

LOG: [ASTImporter] Refactor IsStructurallyEquivalent's Decl overloads to be 
more consistent

There are several `::IsStructurallyEquivalent` overloads for Decl subclasses
that are used for comparing declarations. There is also one overload that takes
just two Decl pointers which ends up queuing the passed Decls to be later
compared in `CheckKindSpecificEquivalence`.

`CheckKindSpecificEquivalence` implements the dispatch logic for the different
Decl subclasses. It is supposed to hand over the queued Decls to the
subclass-specific `::IsStructurallyEquivalent` overload that will actually
compare the Decl instance. It also seems to implement a few pieces of actual
node comparison logic inbetween the dispatch code.

This implementation causes that the different overloads of
`::IsStructurallyEquivalent` do different (and sometimes no) comparisons
depending on which overload of `::IsStructurallyEquivalent` ends up being
called.

For example, if I want to compare two FieldDecl instances, then I could either
call the `::IsStructurallyEquivalent` with `Decl *` or with `FieldDecl *`
parameters. The overload that takes FieldDecls is doing a correct comparison.
However, the `Decl *` overload just queues the Decl pair.
`CheckKindSpecificEquivalence` has no dispatch logic for `FieldDecl`, so it
always returns true and never does any actual comparison.

On the other hand, if I try to compare two FunctionDecl instances the two
possible overloads of `::IsStructurallyEquivalent` have the opposite behaviour:
The overload that takes `FunctionDecl` pointers isn't comparing the names of the
FunctionDecls while the overload taking a plain `Decl` ends up comparing the
function names (as the comparison logic for that is implemented in
`CheckKindSpecificEquivalence`).

This patch tries to make this set of functions more consistent by making
`CheckKindSpecificEquivalence` a pure dispatch function without any
subclass-specific comparison logic. Also the dispatch logic is now autogenerated
so it can no longer miss certain subclasses.

The comparison code from `CheckKindSpecificEquivalence` is moved to the
respective `::IsStructurallyEquivalent` overload so that the comparison result
no longer depends if one calls the `Decl *` overload or the overload for the
specific subclass. The only difference is now that the `Decl *` overload is
queuing the parameter while the subclass-specific overload is directly doing the
comparison.

`::IsStructurallyEquivalent` is an implementation detail and I don't think the
behaviour causes any bugs in the current implementation (as carefully calling
the right overload for the different classes works around the issue), so the
test for this change is that I added some new code for comparing `MemberExpr`.
The new comparison code always calls the dispatching overload and it previously
failed as the dispatch didn't support FieldDecls.

Reviewed By: martong, a_sidorin

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

Added: 


Modified: 
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/unittests/AST/StructuralEquivalenceTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index fafcfce269d7..98e1b7eeb8c4 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -66,6 +66,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclFriend.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/DeclOpenMP.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprConcepts.h"
@@ -242,6 +243,11 @@ class StmtComparer {
 return E1->getValue() == E2->getValue();
   }
 
+  bool IsStmtEquivalent(const MemberExpr *E1, const MemberExpr *E2) {
+return IsStructurallyEquivalent(Context, E1->getFoundDecl(),
+E2->getFoundDecl());
+  }
+
   bool IsStmtEquivalent(const ObjCStringLiteral *E1,
 const ObjCStringLiteral *E2) {
 // Just wraps a StringLiteral child.
@@ -1364,6 +1370,17 @@ 
IsStructurallyEquivalentLambdas(StructuralEquivalenceContext &Context,
 /// Determine structural equivalence of two records.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  RecordDecl *D1, RecordDecl *D2) {
+
+  // Check for equivalent structure names.
+  IdentifierInfo *Name1 = D1->getIdentifier();
+  if (!Name1 && D1->getTypedefNameForAnonDecl())
+Name1 = D1->getTypedefNameForAnonDecl()->getIdentifier();
+  IdentifierInfo *Name2 = D2->getIdentifier(

[PATCH] D87619: [ASTImporter] Refactor IsStructurallyEquivalent's Decl overloads to be more consistent

2020-09-21 Thread Raphael Isemann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7c4575e15f06: [ASTImporter] Refactor 
IsStructurallyEquivalent's Decl overloads to be more… (authored by 
teemperor).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87619

Files:
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1586,6 +1586,22 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, MemberExpr) {
+  std::string ClassSrc = "struct C { int a; int b; };";
+  auto t = makeStmts(ClassSrc + "int wrapper() { C c; return c.a; }",
+ ClassSrc + "int wrapper() { C c; return c.a; }",
+ Lang_CXX03, memberExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, MemberExprDifferentMember) {
+  std::string ClassSrc = "struct C { int a; int b; };";
+  auto t = makeStmts(ClassSrc + "int wrapper() { C c; return c.a; }",
+ ClassSrc + "int wrapper() { C c; return c.b; }",
+ Lang_CXX03, memberExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceStmtTest, ObjCStringLiteral) {
   auto t =
   makeWrappedStmts("@\"a\"", "@\"a\"", Lang_OBJCXX, fallbackExprMatcher());
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -66,6 +66,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclFriend.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/DeclOpenMP.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprConcepts.h"
@@ -242,6 +243,11 @@
 return E1->getValue() == E2->getValue();
   }
 
+  bool IsStmtEquivalent(const MemberExpr *E1, const MemberExpr *E2) {
+return IsStructurallyEquivalent(Context, E1->getFoundDecl(),
+E2->getFoundDecl());
+  }
+
   bool IsStmtEquivalent(const ObjCStringLiteral *E1,
 const ObjCStringLiteral *E2) {
 // Just wraps a StringLiteral child.
@@ -1364,6 +1370,17 @@
 /// Determine structural equivalence of two records.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  RecordDecl *D1, RecordDecl *D2) {
+
+  // Check for equivalent structure names.
+  IdentifierInfo *Name1 = D1->getIdentifier();
+  if (!Name1 && D1->getTypedefNameForAnonDecl())
+Name1 = D1->getTypedefNameForAnonDecl()->getIdentifier();
+  IdentifierInfo *Name2 = D2->getIdentifier();
+  if (!Name2 && D2->getTypedefNameForAnonDecl())
+Name2 = D2->getTypedefNameForAnonDecl()->getIdentifier();
+  if (!IsStructurallyEquivalent(Name1, Name2))
+return false;
+
   if (D1->isUnion() != D2->isUnion()) {
 if (Context.Complain) {
   Context.Diag2(D2->getLocation(), Context.getApplicableDiagnostic(
@@ -1598,6 +1615,16 @@
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  EnumDecl *D1, EnumDecl *D2) {
 
+  // Check for equivalent enum names.
+  IdentifierInfo *Name1 = D1->getIdentifier();
+  if (!Name1 && D1->getTypedefNameForAnonDecl())
+Name1 = D1->getTypedefNameForAnonDecl()->getIdentifier();
+  IdentifierInfo *Name2 = D2->getIdentifier();
+  if (!Name2 && D2->getTypedefNameForAnonDecl())
+Name2 = D2->getTypedefNameForAnonDecl()->getIdentifier();
+  if (!IsStructurallyEquivalent(Name1, Name2))
+return false;
+
   // Compare the definitions of these two enums. If either or both are
   // incomplete (i.e. forward declared), we assume that they are equivalent.
   D1 = D1->getDefinition();
@@ -1823,8 +1850,27 @@
   return false;
 }
 
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ TypedefNameDecl *D1, TypedefNameDecl *D2) {
+  if (!IsStructurallyEquivalent(D1->getIdentifier(), D2->getIdentifier()))
+return false;
+
+  return IsStructurallyEquivalent(Context, D1->getUnderlyingType(),
+  D2->getUnderlyingType());
+}
+
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  FunctionDecl *D1, FunctionDecl *D2) {
+  if (!IsStructurallyEquivalent(D1->getIdentifier(), D2->getIdentifier()))
+return false;
+
+  if (D1->isOverloadedOperator()) {
+if (!D2->isOverloadedOperator())
+  return false;
+if (D1->getOverloadedOperator() != D2->

[clang] 699089f - [AIX][Clang][Driver] Add handling of nostartfiles option

2020-09-21 Thread David Tenty via cfe-commits

Author: David Tenty
Date: 2020-09-21T10:42:46-04:00
New Revision: 699089f2a9702baa987dc2dbe915a2c845c7027f

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

LOG: [AIX][Clang][Driver] Add handling of nostartfiles option

Reviewed By: jasonliu

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/AIX.cpp
clang/test/Driver/aix-ld.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index bc130a5557e9..e492cd7d196f 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -123,7 +123,7 @@ void aix::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   return IsArch32Bit ? "crt0.o" : "crt0_64.o";
   };
 
-  if (!Args.hasArg(options::OPT_nostdlib)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
 CmdArgs.push_back(
 Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename(;
   }

diff  --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c
index 7b3710ca21ef..695260bbe2bd 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -331,6 +331,38 @@
 // CHECK-LD64-NOSTDLIBXX-LCXX-NOT: "-lc++"
 // CHECK-LD64-NOSTDLIBXX-LCXX: "-lc"
 
+// Check powerpc64-ibm-aix7.1.0.0, 32-bit. -nostartfiles.
+// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
+// RUN:-nostartfiles \
+// RUN:-target powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-NOSTARTFILES-LCXX %s
+// CHECK-LD32-NOSTARTFILES-LCXX: {{.*}}clang{{.*}}" "-cc1" "-triple" 
"powerpc-ibm-aix7.1.0.0"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD32-NOSTARTFILES-LCXX: "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-b32"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-bpT:0x1000" "-bpD:0x2000"
+// CHECK-LD32-NOSTARTFILES-LCXX-NOT: "[[SYSROOT]]/usr/lib{{/|}}crt0.o"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD32-NOSTARTFILES-LCXX  "-lc++"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-lc"
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -nostartfiles.
+// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
+// RUN:-nostartfiles \
+// RUN:-target powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-NOSTARTFILES-LCXX %s
+// CHECK-LD64-NOSTARTFILES-LCXX: {{.*}}clang{{.*}}" "-cc1" "-triple" 
"powerpc64-ibm-aix7.1.0.0"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD64-NOSTARTFILES-LCXX: "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-b64"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-bpT:0x1" "-bpD:0x11000"
+// CHECK-LD64-NOSTARTFILES-LCXX-NOT: "[[SYSROOT]]/usr/lib{{/|}}crt0_64.o"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-lc++"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-lc"
+
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. -stdlib=libstdc++ invokes fatal error.
 // RUN: not --crash %clangxx -no-canonical-prefixes %s 2>&1 -### \
 // RUN:-target powerpc-ibm-aix7.1.0.0 \



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


[PATCH] D87904: [AIX][Clang][Driver] Add handling of nostartfiles option

2020-09-21 Thread David Tenty via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG699089f2a970: [AIX][Clang][Driver] Add handling of 
nostartfiles option (authored by daltenty).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87904

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


Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -331,6 +331,38 @@
 // CHECK-LD64-NOSTDLIBXX-LCXX-NOT: "-lc++"
 // CHECK-LD64-NOSTDLIBXX-LCXX: "-lc"
 
+// Check powerpc64-ibm-aix7.1.0.0, 32-bit. -nostartfiles.
+// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
+// RUN:-nostartfiles \
+// RUN:-target powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-NOSTARTFILES-LCXX %s
+// CHECK-LD32-NOSTARTFILES-LCXX: {{.*}}clang{{.*}}" "-cc1" "-triple" 
"powerpc-ibm-aix7.1.0.0"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD32-NOSTARTFILES-LCXX: "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-b32"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-bpT:0x1000" "-bpD:0x2000"
+// CHECK-LD32-NOSTARTFILES-LCXX-NOT: "[[SYSROOT]]/usr/lib{{/|}}crt0.o"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD32-NOSTARTFILES-LCXX  "-lc++"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-lc"
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -nostartfiles.
+// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
+// RUN:-nostartfiles \
+// RUN:-target powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-NOSTARTFILES-LCXX %s
+// CHECK-LD64-NOSTARTFILES-LCXX: {{.*}}clang{{.*}}" "-cc1" "-triple" 
"powerpc64-ibm-aix7.1.0.0"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD64-NOSTARTFILES-LCXX: "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-b64"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-bpT:0x1" "-bpD:0x11000"
+// CHECK-LD64-NOSTARTFILES-LCXX-NOT: "[[SYSROOT]]/usr/lib{{/|}}crt0_64.o"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-lc++"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-lc"
+
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. -stdlib=libstdc++ invokes fatal error.
 // RUN: not --crash %clangxx -no-canonical-prefixes %s 2>&1 -### \
 // RUN:-target powerpc-ibm-aix7.1.0.0 \
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -123,7 +123,7 @@
   return IsArch32Bit ? "crt0.o" : "crt0_64.o";
   };
 
-  if (!Args.hasArg(options::OPT_nostdlib)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
 CmdArgs.push_back(
 Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename(;
   }


Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -331,6 +331,38 @@
 // CHECK-LD64-NOSTDLIBXX-LCXX-NOT: "-lc++"
 // CHECK-LD64-NOSTDLIBXX-LCXX: "-lc"
 
+// Check powerpc64-ibm-aix7.1.0.0, 32-bit. -nostartfiles.
+// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
+// RUN:-nostartfiles \
+// RUN:-target powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-NOSTARTFILES-LCXX %s
+// CHECK-LD32-NOSTARTFILES-LCXX: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD32-NOSTARTFILES-LCXX: "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-b32"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-bpT:0x1000" "-bpD:0x2000"
+// CHECK-LD32-NOSTARTFILES-LCXX-NOT: "[[SYSROOT]]/usr/lib{{/|}}crt0.o"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD32-NOSTARTFILES-LCXX  "-lc++"
+// CHECK-LD32-NOSTARTFILES-LCXX: "-lc"
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -nostartfiles.
+// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
+// RUN:-nostartfiles \
+// RUN:-target powerpc-ibm-aix7.1.0.0 \
+// RUN:--sysroot %S/Inputs/aix_ppc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-NOSTARTFILES-LCXX %s
+// CHECK-LD64-NOSTARTFILES-LCXX: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD64-NOSTARTFILES-LCXX: "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-b64"
+// CHECK-LD64-NOSTARTFILES-LCXX: "-bpT:0x1" "-bpD:0x11

[PATCH] D87972: [OldPM] Pass manager: run SROA after (simple) loop unrolling

2020-09-21 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

In D87972#2284096 , @lebedev.ri wrote:

> In D87972#2284064 , @xbolva00 wrote:
>
>> In D87972#2284060 , @MaskRay wrote:
>>
>>> I have tested this patch internally and seen gains and losses. On one 
>>> document search related benchmark 3~5% improvement. One zippy (snappy) 
>>> there is 3~5% regression. Perhaps we do need a conditional extra SROA run.
>>
>> Snappy  - you mean public https://github.com/google/snappy?
>>
>> Well, it should be possible to analyze it...
>
>
>
>> @lebedev.ri any perf data from testsuite/rawspeed?
>
> I did look. F13016699: sroa-after-unroll.rsbench.txt 
> 
> This suggests that geomean is `-0.8%` runtime improvement,
> with ups&downs. F13016722: image.png 
>
> But as i have said in the patch's description, i stumbled into this when 
> writing new code, where the effect is //much// larger.

We probably need to collect more performance data of more benchmarks on more 
platforms (different targets) to understand the impact. I hesitate to add 
https://reviews.llvm.org/rG1f4e7463b5e3ff654c84371527767830e51db10d as a 
generic one as some targets may have regressions due to potentially very 
different memory access patterns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87972

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


[PATCH] D88024: [SyntaxTree][Nit] Take `ArrayRef` instead of `std::vector` as argument for `createTree`

2020-09-21 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
eduucaldas added a reviewer: gribozavr2.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

I also assured that there are no other functions unnecessarily using 
std::vector as argument.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88024

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp


Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -190,7 +190,7 @@
 
 syntax::Tree *clang::syntax::createTree(
 syntax::Arena &A,
-std::vector> Children,
+ArrayRef> Children,
 syntax::NodeKind K) {
   auto *T = allocateTree(A, K);
   FactoryImpl::setCanModify(T);
Index: clang/include/clang/Tooling/Syntax/BuildTree.h
===
--- clang/include/clang/Tooling/Syntax/BuildTree.h
+++ clang/include/clang/Tooling/Syntax/BuildTree.h
@@ -39,7 +39,7 @@
 /// Returns it as a pointer to the base class `Tree`.
 syntax::Tree *
 createTree(syntax::Arena &A,
-   std::vector> Children,
+   ArrayRef> Children,
syntax::NodeKind K);
 
 // Synthesis of Syntax Nodes


Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -190,7 +190,7 @@
 
 syntax::Tree *clang::syntax::createTree(
 syntax::Arena &A,
-std::vector> Children,
+ArrayRef> Children,
 syntax::NodeKind K) {
   auto *T = allocateTree(A, K);
   FactoryImpl::setCanModify(T);
Index: clang/include/clang/Tooling/Syntax/BuildTree.h
===
--- clang/include/clang/Tooling/Syntax/BuildTree.h
+++ clang/include/clang/Tooling/Syntax/BuildTree.h
@@ -39,7 +39,7 @@
 /// Returns it as a pointer to the base class `Tree`.
 syntax::Tree *
 createTree(syntax::Arena &A,
-   std::vector> Children,
+   ArrayRef> Children,
syntax::NodeKind K);
 
 // Synthesis of Syntax Nodes
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0c4f91f - [analyzer][solver] Fix issue with symbol non-equality tracking

2020-09-21 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2020-09-21T16:59:18+02:00
New Revision: 0c4f91f84b2efe8975848a7a13c08d7479abe752

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

LOG: [analyzer][solver] Fix issue with symbol non-equality tracking

We should track non-equivalency (disequality) in case of greater-then or
less-then assumptions.

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
clang/test/Analysis/equality_tracking.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 32766d796add..a481bde1651b 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1347,27 +1347,35 @@ class RangeConstraintManager : public 
RangedConstraintManager {
   // Equality tracking implementation
   //===--===//
 
-  ProgramStateRef trackEQ(ProgramStateRef State, SymbolRef Sym,
-  const llvm::APSInt &Int,
+  ProgramStateRef trackEQ(RangeSet NewConstraint, ProgramStateRef State,
+  SymbolRef Sym, const llvm::APSInt &Int,
   const llvm::APSInt &Adjustment) {
-if (auto Equality = EqualityInfo::extract(Sym, Int, Adjustment)) {
-  // Extract function assumes that we gave it Sym + Adjustment != Int,
-  // so the result should be opposite.
-  Equality->invert();
-  return track(State, *Equality);
-}
-
-return State;
+return track(NewConstraint, State, Sym, Int, Adjustment);
   }
 
-  ProgramStateRef trackNE(ProgramStateRef State, SymbolRef Sym,
-  const llvm::APSInt &Int,
+  ProgramStateRef trackNE(RangeSet NewConstraint, ProgramStateRef State,
+  SymbolRef Sym, const llvm::APSInt &Int,
   const llvm::APSInt &Adjustment) {
+return track(NewConstraint, State, Sym, Int, Adjustment);
+  }
+
+  template 
+  ProgramStateRef track(RangeSet NewConstraint, ProgramStateRef State,
+SymbolRef Sym, const llvm::APSInt &Int,
+const llvm::APSInt &Adjustment) {
+if (NewConstraint.isEmpty())
+  // This is an infeasible assumption.
+  return nullptr;
+
+ProgramStateRef NewState = setConstraint(State, Sym, NewConstraint);
 if (auto Equality = EqualityInfo::extract(Sym, Int, Adjustment)) {
-  return track(State, *Equality);
+  // If the original assumption is not Sym + Adjustment !=/ Int,
+  // we should invert IsEquality flag.
+  Equality->IsEquality = Equality->IsEquality != EQ;
+  return track(NewState, *Equality);
 }
 
-return State;
+return NewState;
   }
 
   ProgramStateRef track(ProgramStateRef State, EqualityInfo ToTrack) {
@@ -2042,12 +2050,7 @@ RangeConstraintManager::assumeSymNE(ProgramStateRef St, 
SymbolRef Sym,
 
   RangeSet New = getRange(St, Sym).Delete(getBasicVals(), F, Point);
 
-  if (New.isEmpty())
-// this is infeasible assumption
-return nullptr;
-
-  ProgramStateRef NewState = setConstraint(St, Sym, New);
-  return trackNE(NewState, Sym, Int, Adjustment);
+  return trackNE(New, St, Sym, Int, Adjustment);
 }
 
 ProgramStateRef
@@ -2063,12 +2066,7 @@ RangeConstraintManager::assumeSymEQ(ProgramStateRef St, 
SymbolRef Sym,
   llvm::APSInt AdjInt = AdjustmentType.convert(Int) - Adjustment;
   RangeSet New = getRange(St, Sym).Intersect(getBasicVals(), F, AdjInt, 
AdjInt);
 
-  if (New.isEmpty())
-// this is infeasible assumption
-return nullptr;
-
-  ProgramStateRef NewState = setConstraint(St, Sym, New);
-  return trackEQ(NewState, Sym, Int, Adjustment);
+  return trackEQ(New, St, Sym, Int, Adjustment);
 }
 
 RangeSet RangeConstraintManager::getSymLTRange(ProgramStateRef St,
@@ -2104,7 +2102,7 @@ RangeConstraintManager::assumeSymLT(ProgramStateRef St, 
SymbolRef Sym,
 const llvm::APSInt &Int,
 const llvm::APSInt &Adjustment) {
   RangeSet New = getSymLTRange(St, Sym, Int, Adjustment);
-  return New.isEmpty() ? nullptr : setConstraint(St, Sym, New);
+  return trackNE(New, St, Sym, Int, Adjustment);
 }
 
 RangeSet RangeConstraintManager::getSymGTRange(ProgramStateRef St,
@@ -2140,7 +2138,7 @@ RangeConstraintManager::assumeSymGT(ProgramStateRef St, 
SymbolRef Sym,
 const llvm::APSInt &Int,
 const llvm::APSInt &Adjustment) {
   RangeSet New = getSymGTRange(St, Sym, Int, Adjustment);
-  return New.isEmpty() ? nullptr : setConstraint(St, Sym, New);
+  return trackN

[PATCH] D88019: [analyzer][solver] Fix issue with symbol non-equality tracking

2020-09-21 Thread Gabor Marton via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0c4f91f84b2e: [analyzer][solver] Fix issue with symbol 
non-equality tracking (authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88019

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/equality_tracking.c

Index: clang/test/Analysis/equality_tracking.c
===
--- clang/test/Analysis/equality_tracking.c
+++ clang/test/Analysis/equality_tracking.c
@@ -185,3 +185,37 @@
 }
   }
 }
+
+void avoidInfeasibleConstraintforGT(int a, int b) {
+  int c = b - a;
+  if (c <= 0)
+return;
+  // c > 0
+  // b - a > 0
+  // b > a
+  if (a != b) {
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+return;
+  }
+  clang_analyzer_warnIfReached(); // no warning
+  // a == b
+  if (c < 0)
+;
+}
+
+void avoidInfeasibleConstraintforLT(int a, int b) {
+  int c = b - a;
+  if (c >= 0)
+return;
+  // c < 0
+  // b - a < 0
+  // b < a
+  if (a != b) {
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+return;
+  }
+  clang_analyzer_warnIfReached(); // no warning
+  // a == b
+  if (c < 0)
+;
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1347,27 +1347,35 @@
   // Equality tracking implementation
   //===--===//
 
-  ProgramStateRef trackEQ(ProgramStateRef State, SymbolRef Sym,
-  const llvm::APSInt &Int,
+  ProgramStateRef trackEQ(RangeSet NewConstraint, ProgramStateRef State,
+  SymbolRef Sym, const llvm::APSInt &Int,
   const llvm::APSInt &Adjustment) {
-if (auto Equality = EqualityInfo::extract(Sym, Int, Adjustment)) {
-  // Extract function assumes that we gave it Sym + Adjustment != Int,
-  // so the result should be opposite.
-  Equality->invert();
-  return track(State, *Equality);
-}
-
-return State;
+return track(NewConstraint, State, Sym, Int, Adjustment);
   }
 
-  ProgramStateRef trackNE(ProgramStateRef State, SymbolRef Sym,
-  const llvm::APSInt &Int,
+  ProgramStateRef trackNE(RangeSet NewConstraint, ProgramStateRef State,
+  SymbolRef Sym, const llvm::APSInt &Int,
   const llvm::APSInt &Adjustment) {
+return track(NewConstraint, State, Sym, Int, Adjustment);
+  }
+
+  template 
+  ProgramStateRef track(RangeSet NewConstraint, ProgramStateRef State,
+SymbolRef Sym, const llvm::APSInt &Int,
+const llvm::APSInt &Adjustment) {
+if (NewConstraint.isEmpty())
+  // This is an infeasible assumption.
+  return nullptr;
+
+ProgramStateRef NewState = setConstraint(State, Sym, NewConstraint);
 if (auto Equality = EqualityInfo::extract(Sym, Int, Adjustment)) {
-  return track(State, *Equality);
+  // If the original assumption is not Sym + Adjustment !=/ Int,
+  // we should invert IsEquality flag.
+  Equality->IsEquality = Equality->IsEquality != EQ;
+  return track(NewState, *Equality);
 }
 
-return State;
+return NewState;
   }
 
   ProgramStateRef track(ProgramStateRef State, EqualityInfo ToTrack) {
@@ -2042,12 +2050,7 @@
 
   RangeSet New = getRange(St, Sym).Delete(getBasicVals(), F, Point);
 
-  if (New.isEmpty())
-// this is infeasible assumption
-return nullptr;
-
-  ProgramStateRef NewState = setConstraint(St, Sym, New);
-  return trackNE(NewState, Sym, Int, Adjustment);
+  return trackNE(New, St, Sym, Int, Adjustment);
 }
 
 ProgramStateRef
@@ -2063,12 +2066,7 @@
   llvm::APSInt AdjInt = AdjustmentType.convert(Int) - Adjustment;
   RangeSet New = getRange(St, Sym).Intersect(getBasicVals(), F, AdjInt, AdjInt);
 
-  if (New.isEmpty())
-// this is infeasible assumption
-return nullptr;
-
-  ProgramStateRef NewState = setConstraint(St, Sym, New);
-  return trackEQ(NewState, Sym, Int, Adjustment);
+  return trackEQ(New, St, Sym, Int, Adjustment);
 }
 
 RangeSet RangeConstraintManager::getSymLTRange(ProgramStateRef St,
@@ -2104,7 +2102,7 @@
 const llvm::APSInt &Int,
 const llvm::APSInt &Adjustment) {
   RangeSet New = getSymLTRange(St, Sym, Int, Adjustment);
-  return New.isEmpty() ? nullptr : setConstraint(St, Sym, New);
+  return trackNE(New, St, Sym, Int, Adjustment);
 }
 
 RangeSet RangeConstraintManager::getSymGTRange(ProgramStateRef St,
@@ -2140,7 +2138,7 @@
   

[PATCH] D87029: [AIX] Implement AIX special bitfield related alignment rules

2020-09-21 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added a comment.

I think it would help the review if we could put the NFC portion(e.g. TypeSize 
-> StorageUnitSize) to a new patch, and give some rationale about the NFC 
change.




Comment at: clang/lib/AST/RecordLayoutBuilder.cpp:624
   /// a byte, but larger units are used if IsMsStruct.
   unsigned char UnfilledBitsInLastUnit;
+  /// LastBitfieldStorageUnitSize - If IsMsStruct, represents the size of the




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

https://reviews.llvm.org/D87029

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


[PATCH] D79388: [clang-format] Fix AlignConsecutive on PP blocks

2020-09-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2996
 Line->Tokens.back().Tok->MustBreakBefore = true;
+Line->Tokens.back().Tok->MustBreakAlignBefore = true;
 MustBreakBeforeNextToken = false;

MyDeveloperDay wrote:
> If the line ends with a comment and we have align trailing comments turned on 
> then I think this breaks the alignment
If I comment out this line, then all the tests pass! and  
https://bugs.llvm.org/show_bug.cgi?id=47589 is resolved. I think we need to 
understand why we are putting this here?

```
void UnwrappedLineParser::pushToken(FormatToken *Tok) {
  Line->Tokens.push_back(UnwrappedLineNode(Tok));
  if (MustBreakBeforeNextToken) {
Line->Tokens.back().Tok->MustBreakBefore = true;
// Line->Tokens.back().Tok->MustBreakAlignBefore = true;
MustBreakBeforeNextToken = false;
  }
}
```



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79388

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


[PATCH] D77792: [analyzer] Extend constraint manager to be able to compare simple SymSymExprs

2020-09-21 Thread Gabor Marton via Phabricator via cfe-commits
martong added a reviewer: vsavchenko.
martong added a comment.

Adding Valeriy as a reviewer. He's been working with the solver recently, so 
his insights might be really useful here.


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

https://reviews.llvm.org/D77792

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


[PATCH] D76604: [Analyzer] Model `size()` member function of containers

2020-09-21 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 293183.
baloghadamsoftware added a comment.

New test cases added.


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

https://reviews.llvm.org/D76604

Files:
  clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
  clang/lib/StaticAnalyzer/Checkers/Iterator.h
  clang/test/Analysis/container-modeling.cpp

Index: clang/test/Analysis/container-modeling.cpp
===
--- clang/test/Analysis/container-modeling.cpp
+++ clang/test/Analysis/container-modeling.cpp
@@ -14,6 +14,7 @@
 void clang_analyzer_denote(long, const char*);
 void clang_analyzer_express(long);
 void clang_analyzer_eval(bool);
+void clang_analyzer_dump(std::size_t);
 void clang_analyzer_warnIfReached();
 
 extern void __assert_fail (__const char *__assertion, __const char *__file,
@@ -104,6 +105,125 @@
   // expected-note@-3   {{FALSE}}
 }
 
+// size()
+
+void size0(const std::vector& V) {
+  assert(V.size() == 0); // expected-note 2{{'?' condition is true}}
+ // expected-note@-1 2{{Assuming the condition is true}}
+
+  clang_analyzer_eval(clang_analyzer_container_end(V) ==
+  clang_analyzer_container_begin(V));
+  // expected-warning@-2{{TRUE}}
+  // expected-note@-3   {{TRUE}}
+
+  clang_analyzer_dump(V.size()); // expected-warning{{0}}
+ // expected-note@-1{{0}}
+}
+
+void size1(const std::vector& V) {
+  assert(V.size() == 1); // expected-note 2{{'?' condition is true}}
+ // expected-note@-1 2{{Assuming the condition is true}}
+
+  clang_analyzer_eval(clang_analyzer_container_end(V) ==
+  clang_analyzer_container_begin(V) + 1);
+  // expected-warning@-2{{TRUE}}
+  // expected-note@-3   {{TRUE}}
+
+  clang_analyzer_dump(V.size()); // expected-warning{{1}}
+ // expected-note@-1{{1}}
+}
+
+void size2(std::vector& V) {
+  assert(V.size() == 1); // expected-note 2{{'?' condition is true}}
+ // expected-note@-1 2{{Assuming the condition is true}}
+
+  V.push_back(1);
+
+  clang_analyzer_eval(clang_analyzer_container_end(V) ==
+  clang_analyzer_container_begin(V) + 2);
+  // expected-warning@-2{{TRUE}}
+  // expected-note@-3   {{TRUE}}
+
+  clang_analyzer_dump(V.size()); // expected-warning{{2}}
+ // expected-note@-1{{2}}
+}
+
+void size3(std::vector& V) {
+  assert(V.size() <= 10); // expected-note 6{{'?' condition is true}}
+ // expected-note@-1 6{{Assuming the condition is true}}
+
+  clang_analyzer_eval(clang_analyzer_container_end(V) + 1 ==
+  clang_analyzer_container_begin(V));
+  // expected-warning@-2{{FALSE}}
+  // expected-note@-3   {{FALSE}}
+
+  clang_analyzer_eval(clang_analyzer_container_end(V) ==
+  clang_analyzer_container_begin(V));
+  // expected-warning@-2{{TRUE}} expected-warning@-2{{FALSE}}
+  // expected-note@-3   {{TRUE}} expected-note@-3   {{FALSE}}
+  // expected-note@-4  {{Assuming the condition is true}}
+  // expected-note@-5 4{{Assuming the condition is false}}
+
+  clang_analyzer_eval(clang_analyzer_container_end(V) ==
+  clang_analyzer_container_begin(V) + 10);
+  // expected-warning@-2{{TRUE}} expected-warning@-2{{FALSE}}
+  // expected-note@-3   {{TRUE}} expected-note@-3   {{FALSE}}
+  // expected-note@-4  {{Assuming the condition is true}}
+  // expected-note@-5 2{{Assuming the condition is false}}
+
+  clang_analyzer_eval(clang_analyzer_container_end(V) ==
+  clang_analyzer_container_begin(V) + 11);
+  // expected-warning@-2{{FALSE}}
+  // expected-note@-3   {{FALSE}}
+}
+
+void size4(std::vector& V) {
+  assert(V.size() >= 10); // expected-note 6{{'?' condition is true}}
+ // expected-note@-1 6{{Assuming the condition is true}}
+
+  clang_analyzer_eval(clang_analyzer_container_end(V) + 1 ==
+  clang_analyzer_container_begin(V));
+  // expected-warning@-2{{FALSE}}
+  // expected-note@-3   {{FALSE}}
+
+  clang_analyzer_eval(clang_analyzer_container_end(V) ==
+  clang_analyzer_container_begin(V));
+  // expected-warning@-2{{FALSE}}
+  // expected-note@-3   {{FALSE}}
+
+  clang_analyzer_eval(clang_analyzer_container_end(V) ==
+  clang_analyzer_container_begin(V) + 10);
+  // expected-warning@-2{{TRUE}} expected-warning@-2{{FALSE}}
+  // expected-note@-3   {{TRUE}} expected-note@-3   {{FALSE}}
+  // expected-note@-4  {{Assuming the condition is true}}
+  // expected-note@-5 3{{Assuming the condition is false}}
+
+  clang_analyzer_eval(clang_analyzer_container_end(V) ==
+  clang_analyzer_container_begin(V) + 11);
+  // expected-warning@-2{{TRUE}} expected-warning@-2{{FALSE}}
+  // expected-note@-3   {{TRUE}} expected-n

[PATCH] D77792: [analyzer] Extend constraint manager to be able to compare simple SymSymExprs

2020-09-21 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

Hi @baloghadamsoftware

Great job!  I also wanted to support more operations for range-based logic.

However, I don't think that this is the right place to make this kind of 
assumptions.  A couple months ago, I added the `SymbolicRangeInferrer` 
component to aggregate all of the reasoning we have about range constraints and 
I strongly believe that the logic from this patch should be integrated in that 
component.


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

https://reviews.llvm.org/D77792

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


[PATCH] D70378: [LLD][COFF] Cover usage of LLD as a library

2020-09-21 Thread Adrian McCarthy via Phabricator via cfe-commits
amccarth accepted this revision.
amccarth added a comment.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70378

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


[PATCH] D79388: [clang-format] Fix AlignConsecutive on PP blocks

2020-09-21 Thread Jake Merdich via Phabricator via cfe-commits
JakeMerdichAMD added a comment.

I'd be very surprised if any of the tests included in this change pass with 
that line commented it's meant so that things like #if and #else properly 
separate alignment after the first preprocessor run, where the whitespace 
manager doesn't have the full context of things between it.

This will break with any PP statement though, not just if-elif-else-endif. I'll 
try moving it to somewhere more specific like the cases in parsePPDirective and 
put out a fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79388

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


[PATCH] D87949: [ThinLTO] Option to bypass function importing.

2020-09-21 Thread Mircea Trofin via Phabricator via cfe-commits
mtrofin updated this revision to Diff 293189.
mtrofin marked 2 inline comments as done.
mtrofin added a comment.

feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87949

Files:
  clang/include/clang/CodeGen/BackendUtil.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/thinlto_embed_bitcode.ll
  llvm/include/llvm/LTO/LTOBackend.h
  llvm/lib/LTO/LTOBackend.cpp

Index: llvm/lib/LTO/LTOBackend.cpp
===
--- llvm/lib/LTO/LTOBackend.cpp
+++ llvm/lib/LTO/LTOBackend.cpp
@@ -69,6 +69,11 @@
   "Embed post merge, but before optimizations")),
 cl::desc("Embed LLVM bitcode in object files produced by LTO"));
 
+static cl::opt ThinLTOAssumeMerged(
+"thinlto-assume-merged", cl::init(false),
+cl::desc("Assume the input has already undergone ThinLTO function "
+ "importing and the other pre-optimization pipeline changes."));
+
 LLVM_ATTRIBUTE_NORETURN static void reportOpenError(StringRef Path, Twine Msg) {
   errs() << "failed to open " << Path << ": " << Msg << '\n';
   errs().flush();
@@ -583,6 +588,21 @@
   if (Conf.PreOptModuleHook && !Conf.PreOptModuleHook(Task, Mod))
 return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
 
+  auto OptimizeAndCodegen =
+  [&](Module &Mod, TargetMachine *TM,
+  std::unique_ptr DiagnosticOutputFile) {
+if (!opt(Conf, TM, Task, Mod, /*IsThinLTO=*/true,
+ /*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex,
+ CmdArgs))
+  return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
+
+codegen(Conf, TM, AddStream, Task, Mod, CombinedIndex);
+return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
+  };
+
+  if (ThinLTOAssumeMerged)
+return OptimizeAndCodegen(Mod, TM.get(), std::move(DiagnosticOutputFile));
+
   // When linking an ELF shared object, dso_local should be dropped. We
   // conservatively do this for -fpic.
   bool ClearDSOLocalOnDeclarations =
@@ -623,11 +643,81 @@
   if (Conf.PostImportModuleHook && !Conf.PostImportModuleHook(Task, Mod))
 return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
 
-  if (!opt(Conf, TM.get(), Task, Mod, /*IsThinLTO=*/true,
-   /*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex,
-   CmdArgs))
-return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
+  return OptimizeAndCodegen(Mod, TM.get(), std::move(DiagnosticOutputFile));
+}
+
+BitcodeModule *lto::findThinLTOModule(MutableArrayRef BMs) {
+  if (ThinLTOAssumeMerged && BMs.size() == 1)
+return BMs.begin();
 
-  codegen(Conf, TM.get(), AddStream, Task, Mod, CombinedIndex);
-  return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
+  for (BitcodeModule &BM : BMs) {
+Expected LTOInfo = BM.getLTOInfo();
+if (LTOInfo && LTOInfo->IsThinLTO)
+  return &BM;
+  }
+  return nullptr;
 }
+
+Expected lto::findThinLTOModule(MemoryBufferRef MBRef) {
+  Expected> BMsOrErr = getBitcodeModuleList(MBRef);
+  if (!BMsOrErr)
+return BMsOrErr.takeError();
+
+  // The bitcode file may contain multiple modules, we want the one that is
+  // marked as being the ThinLTO module.
+  if (const BitcodeModule *Bm = lto::findThinLTOModule(*BMsOrErr))
+return *Bm;
+
+  return make_error("Could not find module summary",
+ inconvertibleErrorCode());
+}
+
+bool lto::loadReferencedModules(
+const Module &M, const ModuleSummaryIndex &CombinedIndex,
+FunctionImporter::ImportMapTy &ImportList,
+MapVector &ModuleMap,
+std::vector>
+&OwnedImportsLifetimeManager) {
+  if (ThinLTOAssumeMerged)
+return true;
+  // We can simply import the values mentioned in the combined index, since
+  // we should only invoke this using the individual indexes written out
+  // via a WriteIndexesThinBackend.
+  for (auto &GlobalList : CombinedIndex) {
+// Ignore entries for undefined references.
+if (GlobalList.second.SummaryList.empty())
+  continue;
+
+auto GUID = GlobalList.first;
+for (auto &Summary : GlobalList.second.SummaryList) {
+  // Skip the summaries for the importing module. These are included to
+  // e.g. record required linkage changes.
+  if (Summary->modulePath() == M.getModuleIdentifier())
+continue;
+  // Add an entry to provoke importing by thinBackend.
+  ImportList[Summary->modulePath()].insert(GUID);
+}
+  }
+
+  for (auto &I : ImportList) {
+ErrorOr> MBOrErr =
+llvm::MemoryBuffer::getFile(I.first());
+if (!MBOrErr) {
+  errs() << "Error loading imported file '" << I.first()
+ << "': " << MBOrErr.getError().message() << "\n";
+  return false;
+}
+
+Expected BMOrErr = findThinLTOModule(**MBOrErr);
+if (!B

[PATCH] D88021: [clang] Fix a misleading variable name. NFC.

2020-09-21 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Looks great! (I did notice this but I forgot to update it)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88021

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


[PATCH] D88002: [clang-cl] Always interpret the LIB env var as separated with semicolons

2020-09-21 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk 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/D88002/new/

https://reviews.llvm.org/D88002

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


[clang] 474d527 - [clang] Fix a misleading variable name. NFC.

2020-09-21 Thread Igor Kudrin via cfe-commits

Author: Igor Kudrin
Date: 2020-09-21T22:59:34+07:00
New Revision: 474d527c28f4e88ffda7b82e93e351aec2602380

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

LOG: [clang] Fix a misleading variable name. NFC.

The variable is true when frame pointers should be omitted in leaf
functions, not kept.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0c03a90b8566..8ce59f5ba580 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -604,12 +604,12 @@ getFramePointerKind(const ArgList &Args, const 
llvm::Triple &Triple) {
   bool OmitFP = A && A->getOption().matches(options::OPT_fomit_frame_pointer);
   bool NoOmitFP =
   A && A->getOption().matches(options::OPT_fno_omit_frame_pointer);
-  bool KeepLeaf = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
-   options::OPT_mno_omit_leaf_frame_pointer,
-   Triple.isAArch64() || Triple.isPS4CPU());
+  bool OmitLeafFP = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
+ options::OPT_mno_omit_leaf_frame_pointer,
+ Triple.isAArch64() || Triple.isPS4CPU());
   if (NoOmitFP || mustUseNonLeafFramePointerForTarget(Triple) ||
   (!OmitFP && useFramePointerForTargetByDefault(Args, Triple))) {
-if (KeepLeaf)
+if (OmitLeafFP)
   return CodeGenOptions::FramePointerKind::NonLeaf;
 return CodeGenOptions::FramePointerKind::All;
   }



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


[PATCH] D88021: [clang] Fix a misleading variable name. NFC.

2020-09-21 Thread Igor Kudrin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG474d527c28f4: [clang] Fix a misleading variable name. NFC. 
(authored by ikudrin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88021

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


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -604,12 +604,12 @@
   bool OmitFP = A && A->getOption().matches(options::OPT_fomit_frame_pointer);
   bool NoOmitFP =
   A && A->getOption().matches(options::OPT_fno_omit_frame_pointer);
-  bool KeepLeaf = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
-   options::OPT_mno_omit_leaf_frame_pointer,
-   Triple.isAArch64() || Triple.isPS4CPU());
+  bool OmitLeafFP = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
+ options::OPT_mno_omit_leaf_frame_pointer,
+ Triple.isAArch64() || Triple.isPS4CPU());
   if (NoOmitFP || mustUseNonLeafFramePointerForTarget(Triple) ||
   (!OmitFP && useFramePointerForTargetByDefault(Args, Triple))) {
-if (KeepLeaf)
+if (OmitLeafFP)
   return CodeGenOptions::FramePointerKind::NonLeaf;
 return CodeGenOptions::FramePointerKind::All;
   }


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -604,12 +604,12 @@
   bool OmitFP = A && A->getOption().matches(options::OPT_fomit_frame_pointer);
   bool NoOmitFP =
   A && A->getOption().matches(options::OPT_fno_omit_frame_pointer);
-  bool KeepLeaf = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
-   options::OPT_mno_omit_leaf_frame_pointer,
-   Triple.isAArch64() || Triple.isPS4CPU());
+  bool OmitLeafFP = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
+ options::OPT_mno_omit_leaf_frame_pointer,
+ Triple.isAArch64() || Triple.isPS4CPU());
   if (NoOmitFP || mustUseNonLeafFramePointerForTarget(Triple) ||
   (!OmitFP && useFramePointerForTargetByDefault(Args, Triple))) {
-if (KeepLeaf)
+if (OmitLeafFP)
   return CodeGenOptions::FramePointerKind::NonLeaf;
 return CodeGenOptions::FramePointerKind::All;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f91f28c - [Sema] Split special builtin type lookups into a separate function

2020-09-21 Thread Raul Tambre via cfe-commits

Author: Raul Tambre
Date: 2020-09-21T19:12:29+03:00
New Revision: f91f28c350df6815d37c521e8f3dc0641a3ca467

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

LOG: [Sema] Split special builtin type lookups into a separate function

In case further such cases appear in the future we've got a generic function to 
add them to.
Additionally changed the ObjC special case to check the language and the 
identifier builtin ID instead of the name.

Addresses the cleanup suggestion from D87917.

Reviewed By: rjmccall

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaLookup.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 12943f2bd5bd..5ca1634d57f9 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3813,6 +3813,7 @@ class Sema final {
   RedeclarationKind Redecl
 = NotForRedeclaration);
   bool LookupBuiltin(LookupResult &R);
+  void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID);
   bool LookupName(LookupResult &R, Scope *S,
   bool AllowBuiltinCreation = false);
   bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 81d377cebb32..2d09138a8b43 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2035,24 +2035,6 @@ Scope *Sema::getNonFieldDeclScope(Scope *S) {
   return S;
 }
 
-/// Looks up the declaration of "struct objc_super" and
-/// saves it for later use in building builtin declaration of
-/// objc_msgSendSuper and objc_msgSendSuper_stret. If no such
-/// pre-existing declaration exists no action takes place.
-static void LookupPredefedObjCSuperType(Sema &ThisSema, Scope *S,
-IdentifierInfo *II) {
-  if (!II->isStr("objc_msgSendSuper"))
-return;
-  ASTContext &Context = ThisSema.Context;
-
-  LookupResult Result(ThisSema, &Context.Idents.get("objc_super"),
-  SourceLocation(), Sema::LookupTagName);
-  ThisSema.LookupName(Result, S);
-  if (Result.getResultKind() == LookupResult::Found)
-if (const TagDecl *TD = Result.getAsSingle())
-  Context.setObjCSuperType(Context.getTagDeclType(TD));
-}
-
 static StringRef getHeaderName(Builtin::Context &BuiltinInfo, unsigned ID,
ASTContext::GetBuiltinTypeError Error) {
   switch (Error) {
@@ -2113,7 +2095,7 @@ FunctionDecl *Sema::CreateBuiltin(IdentifierInfo *II, 
QualType Type,
 NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
  Scope *S, bool ForRedeclaration,
  SourceLocation Loc) {
-  LookupPredefedObjCSuperType(*this, S, II);
+  LookupNecessaryTypesForBuiltin(S, ID);
 
   ASTContext::GetBuiltinTypeError Error;
   QualType R = Context.GetBuiltinType(ID, Error);
@@ -9671,7 +9653,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
 NewFD->addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID));
   } else {
 ASTContext::GetBuiltinTypeError Error;
-LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier());
+LookupNecessaryTypesForBuiltin(S, BuiltinID);
 QualType BuiltinType = Context.GetBuiltinType(BuiltinID, Error);
 
 if (!Error && !BuiltinType.isNull() &&
@@ -10880,7 +10862,7 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 // declaration against the expected type for the builtin.
 if (unsigned BuiltinID = NewFD->getBuiltinID()) {
   ASTContext::GetBuiltinTypeError Error;
-  LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier());
+  LookupNecessaryTypesForBuiltin(S, BuiltinID);
   QualType T = Context.GetBuiltinType(BuiltinID, Error);
   // If the type of the builtin 
diff ers only in its exception
   // specification, that's OK.

diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 7da938cb8c38..cf3ae7ae5d05 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -907,6 +907,24 @@ bool Sema::LookupBuiltin(LookupResult &R) {
   return false;
 }
 
+/// Looks up the declaration of "struct objc_super" and
+/// saves it for later use in building builtin declaration of
+/// objc_msgSendSuper and objc_msgSendSuper_stret.
+static void LookupPredefedObjCSuperType(Sema &Sema, Scope *S) {
+  ASTContext &Context = Sema.Context;
+  LookupResult Result(Sema, &Context.Idents.get("objc_super"), 
SourceLocation(),
+  Sem

[PATCH] D87983: [Sema] Split special builtin type lookups into a separate function

2020-09-21 Thread Raul Tambre via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
tambre marked an inline comment as done.
Closed by commit rGf91f28c350df: [Sema] Split special builtin type lookups into 
a separate function (authored by tambre).

Changed prior to commit:
  https://reviews.llvm.org/D87983?vs=293008&id=293193#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87983

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaLookup.cpp


Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -907,6 +907,24 @@
   return false;
 }
 
+/// Looks up the declaration of "struct objc_super" and
+/// saves it for later use in building builtin declaration of
+/// objc_msgSendSuper and objc_msgSendSuper_stret.
+static void LookupPredefedObjCSuperType(Sema &Sema, Scope *S) {
+  ASTContext &Context = Sema.Context;
+  LookupResult Result(Sema, &Context.Idents.get("objc_super"), 
SourceLocation(),
+  Sema::LookupTagName);
+  Sema.LookupName(Result, S);
+  if (Result.getResultKind() == LookupResult::Found)
+if (const TagDecl *TD = Result.getAsSingle())
+  Context.setObjCSuperType(Context.getTagDeclType(TD));
+}
+
+void Sema::LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID) {
+  if (ID == Builtin::BIobjc_msgSendSuper)
+LookupPredefedObjCSuperType(*this, S);
+}
+
 /// Determine whether we can declare a special member function within
 /// the class at this point.
 static bool CanDeclareSpecialMemberFunction(const CXXRecordDecl *Class) {
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -2035,24 +2035,6 @@
   return S;
 }
 
-/// Looks up the declaration of "struct objc_super" and
-/// saves it for later use in building builtin declaration of
-/// objc_msgSendSuper and objc_msgSendSuper_stret. If no such
-/// pre-existing declaration exists no action takes place.
-static void LookupPredefedObjCSuperType(Sema &ThisSema, Scope *S,
-IdentifierInfo *II) {
-  if (!II->isStr("objc_msgSendSuper"))
-return;
-  ASTContext &Context = ThisSema.Context;
-
-  LookupResult Result(ThisSema, &Context.Idents.get("objc_super"),
-  SourceLocation(), Sema::LookupTagName);
-  ThisSema.LookupName(Result, S);
-  if (Result.getResultKind() == LookupResult::Found)
-if (const TagDecl *TD = Result.getAsSingle())
-  Context.setObjCSuperType(Context.getTagDeclType(TD));
-}
-
 static StringRef getHeaderName(Builtin::Context &BuiltinInfo, unsigned ID,
ASTContext::GetBuiltinTypeError Error) {
   switch (Error) {
@@ -2113,7 +2095,7 @@
 NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
  Scope *S, bool ForRedeclaration,
  SourceLocation Loc) {
-  LookupPredefedObjCSuperType(*this, S, II);
+  LookupNecessaryTypesForBuiltin(S, ID);
 
   ASTContext::GetBuiltinTypeError Error;
   QualType R = Context.GetBuiltinType(ID, Error);
@@ -9671,7 +9653,7 @@
 NewFD->addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID));
   } else {
 ASTContext::GetBuiltinTypeError Error;
-LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier());
+LookupNecessaryTypesForBuiltin(S, BuiltinID);
 QualType BuiltinType = Context.GetBuiltinType(BuiltinID, Error);
 
 if (!Error && !BuiltinType.isNull() &&
@@ -10880,7 +10862,7 @@
 // declaration against the expected type for the builtin.
 if (unsigned BuiltinID = NewFD->getBuiltinID()) {
   ASTContext::GetBuiltinTypeError Error;
-  LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier());
+  LookupNecessaryTypesForBuiltin(S, BuiltinID);
   QualType T = Context.GetBuiltinType(BuiltinID, Error);
   // If the type of the builtin differs only in its exception
   // specification, that's OK.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -3813,6 +3813,7 @@
   RedeclarationKind Redecl
 = NotForRedeclaration);
   bool LookupBuiltin(LookupResult &R);
+  void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID);
   bool LookupName(LookupResult &R, Scope *S,
   bool AllowBuiltinCreation = false);
   bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,


Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -90

[PATCH] D87983: [Sema] Split special builtin type lookups into a separate function

2020-09-21 Thread Raul Tambre via Phabricator via cfe-commits
tambre added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:924
+void Sema::LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID) {
+  if (getLangOpts().ObjC && ID == Builtin::BIobjc_msgSendSuper)
+LookupPredefedObjCSuperType(*this, S);

rjmccall wrote:
> I'm pretty sure this builtin only exists in ObjC mode, so there's no need to 
> separately check the language mode.  (Even if you did want to check it, it 
> would be better to check the builtin mode first, as that's a very trivial 
> check.)
Fixed, thanks for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87983

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


[PATCH] D87923: [MS] On x86_32, pass overaligned, non-copyable arguments indirectly

2020-09-21 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks accepted this revision.
aeubanks 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/D87923/new/

https://reviews.llvm.org/D87923

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


[PATCH] D78075: [WIP][Clang][OpenMP] Added support for nowait target in CodeGen

2020-09-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 293195.
tianshilei1992 added a comment.

Continued to fix the case `target_parallel_for_codegen.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78075

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_mapper_codegen.cpp
  clang/test/OpenMP/target_codegen.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp

Index: clang/test/OpenMP/target_parallel_for_codegen.cpp
===
--- clang/test/OpenMP/target_parallel_for_codegen.cpp
+++ clang/test/OpenMP/target_parallel_for_codegen.cpp
@@ -74,7 +74,12 @@
 #ifndef HEADER
 #define HEADER
 
-// CHECK-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
+// CHECK-DAG: [[IDENT_T:%.+]] = type { i32, i32, i32, i32, i8* }
+// CHECK-DAG: [[ANON_T:%.+]] = type { i16, i32, i32 }
+// CHECK-DAG: [[KMP_TASK_T_WITH_PRIVATES:%.+]] = type { [[KMP_TASK_T:%.+]], [[KMP_PRIVATES_T:%.+]] }
+// CHECK-DAG: [[KMP_TASK_T]] = type { i8*, i32 (i32, i8*)*, i32, {{%[^,]+}}, {{%[^,]+}} }
+// CHECK-32-DAG: [[KMP_PRIVATES_T]] = type { [3 x i64], [3 x i8*], [3 x i8*], [3 x i8*], i16 }
+// CHECL-64-DAG: [[KMP_PRIVATES_T]] = type { [3 x i8*], [3 x i8*], [3 x i64], [3 x i8*], i16 }
 // CHECK-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
 // CHECK-DAG: [[DEF_LOC:@.+]] = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
 
@@ -158,34 +163,47 @@
 a += 1;
   }
 
-  // CHECK-DAG:   [[RET:%.+]] = call i32 @__tgt_target_teams_nowait_mapper(i64 -1, i8* @{{[^,]+}}, i32 3, i8** [[BP:%[^,]+]], i8** [[P:%[^,]+]], i64* getelementptr inbounds ([3 x i64], [3 x i64]* [[SIZET2]], i32 0, i32 0), i64* getelementptr inbounds ([3 x i64], [3 x i64]* [[MAPT2]], i32 0, i32 0), i8** null, i32 1, i32 0)
-  // CHECK-DAG:   [[BP]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR:%[^,]+]], i32 0, i32 0
-  // CHECK-DAG:   [[P]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR:%[^,]+]], i32 0, i32 0
-  // CHECK-DAG:   [[BPADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 0
-  // CHECK-DAG:   [[PADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 0
-  // CHECK-DAG:   [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] [[VAL0:%.+]], i[[SZ]]* [[CBPADDR0]],
-  // CHECK-DAG:   store i[[SZ]] [[VAL0]], i[[SZ]]* [[CPADDR0]],
-  // CHECK-DAG:   [[BPADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 1
-  // CHECK-DAG:   [[PADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 1
-  // CHECK-DAG:   [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] [[VAL1:%.+]], i[[SZ]]* [[CBPADDR1]],
-  // CHECK-DAG:   store i[[SZ]] [[VAL1]], i[[SZ]]* [[CPADDR1]],
-  // CHECK-DAG:   [[BPADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BPR]], i32 0, i32 1
-  // CHECK-DAG:   [[PADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PR]], i32 0, i32 1
-  // CHECK-DAG:   [[CBPADDR2:%.+]] = bitcast i8** [[BPADDR2]] to i[[SZ]]*
-  // CHECK-DAG:   [[CPADDR2:%.+]] = bitcast i8** [[PADDR2]] to i[[SZ]]*
-  // CHECK-DAG:   store i[[SZ]] [[VAL2:%.+]], i[[SZ]]* [[CBPADDR2]],
-  // CHECK-DAG:   store i[[SZ]] [[VAL2]], i[[SZ]]* [[CPADDR2]],
-
-  // CHECK-NEXT:  [[ERROR:%.+]] = icmp ne i32 [[RET]], 0
-  // CHECK-NEXT:  br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]
-  // CHECK:   [[FAIL]]
-  // CHECK:   call void [[HVT2:@.+]](i[[SZ]] {{[^,]+}}, i[[SZ]] {{[^)]+}})
-  // CHECK-NEXT:  br label %[[END]]
-  // CHECK:   [[END]]
+  // CHECK-DAG:   call i32 @__kmpc_omp_task([[IDENT_T:%[^,]+]]* {{@[^,]+}}, i32 {{%[^,]+}}, i8* [[TASK:%[0-9]+]])
+  // CHECK-32-DAG:   [[TASK]] = call i8* @__kmpc_omp_target_task_alloc([[IDENT_T]]* {{@[^,]+}}, i32 {{%[^,]+}}, i32 1, i32 84, i32 12, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T_WITH_PRIVATES]]*)* [[OMP_TASK_ENTRY:@.+]] to i32 (i32, i8*)*), i64 -1)
+  // CHECK-64-DAG:   [[TASK]] = call i8* @__kmpc_omp_target_task_alloc([[IDENT_T]]* {{@[^,]+}}, i32 {{%[^,]+}}, i32 1, i64 144, i64 12, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T_WITH_PRIVATES]]*)* [[OMP_TASK_ENTRY:@.+]] to i32 (i32, i8*)*), i64 -1)
+  // CHECK-DAG:   [[TASK_WITH_PRIVATES_CAST:%.+]] = bitcast i8* [[TASK]] to [[KMP_TASK_T_WITH_PRIVATES]]*
+  // CHECK-DAG:   [[KMP_PRIVATES:%.+]] = getelementptr inbounds [[KMP_TASK_T_WITH_PRIVATES]], [[KMP_TASK_T_WITH_PRIVATES]]* [[TASK_WITH_PRIVATES_CAST]], i32 0, i32 1
+  // CHECK-32-DAG:   [[FPSIZEGEP:%.+]] = getelementptr inbounds [[KMP_PRIVATES_T]], [[K

[PATCH] D87737: Add -fprofile-update={atomic,prefer-atomic,single}

2020-09-21 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87737

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


[clang] 6950db3 - The wrong placement of add pass with optimizations led to -funique-internal-linkage-names being disabled.

2020-09-21 Thread Sriraman Tallam via cfe-commits

Author: Sriraman Tallam
Date: 2020-09-21T10:00:12-07:00
New Revision: 6950db36d33d85d18e3241ab6c87494c05ebe0fb

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

LOG: The wrong placement of add pass with optimizations led to 
-funique-internal-linkage-names being disabled.

Fixed the placement of the MPM.addpass for UniqueInternalLinkageNames to make
it work correctly with -O2 and new pass manager. Updated the tests to
explicitly check O0 and O2.

Previously, the addPass was placed before BackendUtil.cpp#L1373 which is wrong
as MPM gets assigned at this point and any additions to the pass vector before
this is wrong. This change just moves it after MPM is assigned and places it at
a point where O0 and O0+ can share it.

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

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/unique-internal-linkage-names.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 01f7e239f790..07c476218bb0 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1262,12 +1262,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
 MPM.addPass(createModuleToFunctionPassAdaptor(BoundsCheckingPass()));
 
-  // Add UniqueInternalLinkageNames Pass which renames internal linkage
-  // symbols with unique names.
-  if (CodeGenOpts.UniqueInternalLinkageNames) {
-MPM.addPass(UniqueInternalLinkageNamesPass());
-  }
-
   // Lastly, add semantically necessary passes for LTO.
   if (IsLTO || IsThinLTO) {
 MPM.addPass(CanonicalizeAliasesPass());
@@ -1363,12 +1357,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   MPM.addPass(InstrProfiling(*Options, false));
 });
 
-  // Add UniqueInternalLinkageNames Pass which renames internal linkage
-  // symbols with unique names.
-  if (CodeGenOpts.UniqueInternalLinkageNames) {
-MPM.addPass(UniqueInternalLinkageNamesPass());
-  }
-
   if (IsThinLTO) {
 MPM = PB.buildThinLTOPreLinkDefaultPipeline(
 Level, CodeGenOpts.DebugPassManager);
@@ -1385,6 +1373,11 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   }
 }
 
+// Add UniqueInternalLinkageNames Pass which renames internal linkage
+// symbols with unique names.
+if (CodeGenOpts.UniqueInternalLinkageNames)
+  MPM.addPass(UniqueInternalLinkageNamesPass());
+
 if (CodeGenOpts.MemProf) {
   MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
   MPM.addPass(ModuleMemProfilerPass());

diff  --git a/clang/test/CodeGen/unique-internal-linkage-names.cpp 
b/clang/test/CodeGen/unique-internal-linkage-names.cpp
index 271d30e4e6fb..6bef338b5f1d 100644
--- a/clang/test/CodeGen/unique-internal-linkage-names.cpp
+++ b/clang/test/CodeGen/unique-internal-linkage-names.cpp
@@ -1,8 +1,10 @@
 // This test checks if internal linkage symbols get unique names with
 // -funique-internal-linkage-names option.
 // RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -o - < %s | FileCheck 
%s --check-prefix=PLAIN
-// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
-// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUEO1
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUEO1
 
 static int glob;
 static int foo() {
@@ -59,3 +61,7 @@ int mver_call() {
 // UNIQUE: define weak_odr i32 ()* @_ZL4mverv.resolver()
 // UNIQUE: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
 // UNIQUE: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}
+// UNIQUEO1: define internal i32 @_ZL3foov.{{[0-9a-f]+}}()
+// UNIQUEO1: define weak_odr i32 ()* @_ZL4mverv.resolver()
+// UNIQUEO1: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
+// UNIQUEO1: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
htt

[PATCH] D87921: Fix -funique-internal-linkage-names to work with -O2 and new pass manager

2020-09-21 Thread Sriraman Tallam via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6950db36d33d: The wrong placement of add pass with 
optimizations led to -funique-internal… (authored by tmsriram).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D87921?vs=292852&id=293208#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87921

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/unique-internal-linkage-names.cpp


Index: clang/test/CodeGen/unique-internal-linkage-names.cpp
===
--- clang/test/CodeGen/unique-internal-linkage-names.cpp
+++ clang/test/CodeGen/unique-internal-linkage-names.cpp
@@ -1,8 +1,10 @@
 // This test checks if internal linkage symbols get unique names with
 // -funique-internal-linkage-names option.
 // RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -o - < %s | FileCheck 
%s --check-prefix=PLAIN
-// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
-// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUEO1
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUEO1
 
 static int glob;
 static int foo() {
@@ -59,3 +61,7 @@
 // UNIQUE: define weak_odr i32 ()* @_ZL4mverv.resolver()
 // UNIQUE: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
 // UNIQUE: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}
+// UNIQUEO1: define internal i32 @_ZL3foov.{{[0-9a-f]+}}()
+// UNIQUEO1: define weak_odr i32 ()* @_ZL4mverv.resolver()
+// UNIQUEO1: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
+// UNIQUEO1: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1262,12 +1262,6 @@
   if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
 MPM.addPass(createModuleToFunctionPassAdaptor(BoundsCheckingPass()));
 
-  // Add UniqueInternalLinkageNames Pass which renames internal linkage
-  // symbols with unique names.
-  if (CodeGenOpts.UniqueInternalLinkageNames) {
-MPM.addPass(UniqueInternalLinkageNamesPass());
-  }
-
   // Lastly, add semantically necessary passes for LTO.
   if (IsLTO || IsThinLTO) {
 MPM.addPass(CanonicalizeAliasesPass());
@@ -1363,12 +1357,6 @@
   MPM.addPass(InstrProfiling(*Options, false));
 });
 
-  // Add UniqueInternalLinkageNames Pass which renames internal linkage
-  // symbols with unique names.
-  if (CodeGenOpts.UniqueInternalLinkageNames) {
-MPM.addPass(UniqueInternalLinkageNamesPass());
-  }
-
   if (IsThinLTO) {
 MPM = PB.buildThinLTOPreLinkDefaultPipeline(
 Level, CodeGenOpts.DebugPassManager);
@@ -1385,6 +1373,11 @@
   }
 }
 
+// Add UniqueInternalLinkageNames Pass which renames internal linkage
+// symbols with unique names.
+if (CodeGenOpts.UniqueInternalLinkageNames)
+  MPM.addPass(UniqueInternalLinkageNamesPass());
+
 if (CodeGenOpts.MemProf) {
   MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
   MPM.addPass(ModuleMemProfilerPass());


Index: clang/test/CodeGen/unique-internal-linkage-names.cpp
===
--- clang/test/CodeGen/unique-internal-linkage-names.cpp
+++ clang/test/CodeGen/unique-internal-linkage-names.cpp
@@ -1,8 +1,10 @@
 // This test checks if internal linkage symbols get unique names with
 // -funique-internal-linkage-names option.
 // RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -o - < %s | FileCheck %s --check-prefix=PLAIN
-// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
-// RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm -funique-internal-linkage-names -o - < %s | FileCheck %s --check-

[PATCH] D88034: [SyntaxTree][Synthesis] Implement `deepCopyExpandingMacros`

2020-09-21 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88034

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -217,7 +217,53 @@
  GetParam());
 
   auto *Copy = deepCopy(*Arena, OriginalTree);
-  EXPECT_TRUE(Copy == nullptr);
+  EXPECT_EQ(Copy, nullptr);
+}
+
+TEST_P(SynthesisTest, DeepCopy_MacroExpanding) {
+  auto *OriginalTree = buildTree(R"cpp(
+#define HALF_IF if (1+
+#define HALF_IF_2 1) {}
+void test() {
+  HALF_IF HALF_IF_2 else {}
+})cpp",
+ GetParam());
+
+  auto *Copy = deepCopyExpandingMacros(*Arena, OriginalTree);
+
+  // The syntax tree stores expanded Tokens already, as a result we can only see
+  // the macro expansion when computing replacements. The dump does show that
+  // nodes are `modifiable` now.
+  EXPECT_TRUE(treeDumpEqual(Copy, R"txt(
+TranslationUnit Detached synthesized
+`-SimpleDeclaration synthesized
+  |-'void' synthesized
+  |-SimpleDeclarator Declarator synthesized
+  | |-'test' synthesized
+  | `-ParametersAndQualifiers synthesized
+  |   |-'(' OpenParen synthesized
+  |   `-')' CloseParen synthesized
+  `-CompoundStatement synthesized
+|-'{' OpenParen synthesized
+|-IfStatement Statement synthesized
+| |-'if' IntroducerKeyword synthesized
+| |-'(' synthesized
+| |-BinaryOperatorExpression synthesized
+| | |-IntegerLiteralExpression LeftHandSide synthesized
+| | | `-'1' LiteralToken synthesized
+| | |-'+' OperatorToken synthesized
+| | `-IntegerLiteralExpression RightHandSide synthesized
+| |   `-'1' LiteralToken synthesized
+| |-')' synthesized
+| |-CompoundStatement ThenStatement synthesized
+| | |-'{' OpenParen synthesized
+| | `-'}' CloseParen synthesized
+| |-'else' ElseKeyword synthesized
+| `-CompoundStatement ElseStatement synthesized
+|   |-'{' OpenParen synthesized
+|   `-'}' CloseParen synthesized
+`-'}' CloseParen synthesized
+  )txt"));
 }
 
 TEST_P(SynthesisTest, Statement_EmptyStatement) {
Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -218,8 +218,13 @@
   return true;
 }
 
-syntax::Node *deepCopyImpl(syntax::Arena &A, const syntax::Node *N) {
+} // namespace
+
+syntax::Node *clang::syntax::deepCopyExpandingMacros(syntax::Arena &A,
+ const syntax::Node *N) {
   if (const auto *L = dyn_cast(N))
+// For original nodes `L->getToken()` gives us the expanded token,
+// thus we implicitly expand any macros here.
 return createLeaf(A, L->getToken()->kind(),
   L->getToken()->text(A.getSourceManager()));
 
@@ -227,17 +232,16 @@
   std::vector> Children;
   for (const auto *Child = T->getFirstChild(); Child;
Child = Child->getNextSibling())
-Children.push_back({deepCopyImpl(A, Child), Child->getRole()});
+Children.push_back({deepCopyExpandingMacros(A, Child), Child->getRole()});
 
   return createTree(A, Children, N->getKind());
 }
-} // namespace
 
 syntax::Node *clang::syntax::deepCopy(syntax::Arena &A, const Node *N) {
   if (!canModifyAllDescendants(N))
 return nullptr;
 
-  return deepCopyImpl(A, N);
+  return deepCopyExpandingMacros(A, N);
 }
 
 syntax::EmptyStatement *clang::syntax::createEmptyStatement(syntax::Arena &A) {
Index: clang/include/clang/Tooling/Syntax/BuildTree.h
===
--- clang/include/clang/Tooling/Syntax/BuildTree.h
+++ clang/include/clang/Tooling/Syntax/BuildTree.h
@@ -56,6 +56,16 @@
 /// unmodifiable returns `nullptr`.
 syntax::Node *deepCopy(syntax::Arena &A, const syntax::Node *N);
 
+/// Creates a completely independent copy of `N` with its macros expanded.
+///
+/// Like `deepCopy` the copy is:
+/// * Detached, i.e. `Parent == NextSibling == nullptr` and
+/// `Role == Detached`.
+/// * Synthesized, i.e. `Original == false`.
+///
+/// However, `N` might have descendants coming from macros, in this case those
+/// macros are expanded.
+syntax::Node *deepCopyExpandingMacros(syntax::Arena &A, const syntax::Node *N);
 } // namespace syntax
 } // namespace clang
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >