[PATCH] D75914: systemz: allow configuring default CLANG_SYSTEMZ_ARCH

2020-03-31 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand added a comment.

Thanks for working on this, @thakis !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75914



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


[PATCH] D76922: [Syntax] Remove delayed folding from tree building.

2020-03-31 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko updated this revision to Diff 253787.
hlopko marked an inline comment as done.
hlopko added a comment.

Remove unnecessary cast


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76922

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -224,6 +224,59 @@
 )txt");
 }
 
+TEST_F(SyntaxTreeTest, SimpleVariable) {
+  expectTreeDumpEqual(
+  R"cpp(
+int a;
+int b = 42;
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | `-a
+| `-;
+`-SimpleDeclaration
+  |-int
+  |-SimpleDeclarator
+  | |-b
+  | |-=
+  | `-UnknownExpression
+  |   `-42
+  `-;
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, SimpleFunction) {
+  expectTreeDumpEqual(
+  R"cpp(
+void foo(int a, int b) {}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-foo
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+`-}
+)txt");
+}
+
 TEST_F(SyntaxTreeTest, If) {
   expectTreeDumpEqual(
   R"cpp(
@@ -541,20 +594,32 @@
 TEST_F(SyntaxTreeTest, MultipleDeclaratorsGrouping) {
   expectTreeDumpEqual(
   R"cpp(
-  int *a, b;
+  int *a, b; int *c, d;
   )cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-*
+| | `-a
+| |-,
+| |-SimpleDeclarator
+| | `-b
+| `-;
 `-SimpleDeclaration
   |-int
   |-SimpleDeclarator
   | |-*
-  | `-a
+  | `-c
   |-,
   |-SimpleDeclarator
-  | `-b
+  | `-d
   `-;
   )txt");
+}
+
+TEST_F(SyntaxTreeTest, MultipleDeclaratorsGroupingTypedef) {
   expectTreeDumpEqual(
   R"cpp(
 typedef int *a, b;
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -710,8 +710,8 @@
 }
 
 std::string syntax::Token::dumpForTests(const SourceManager &SM) const {
-  return std::string(
-  llvm::formatv("{0}   {1}", tok::getTokenName(kind()), text(SM)));
+  return std::string(llvm::formatv("Token(`{0}`, {1}, length = {2})", text(SM),
+   tok::getTokenName(kind()), length()));
 }
 
 std::string TokenBuffer::dumpForTests() const {
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -44,15 +44,6 @@
 LLVM_ATTRIBUTE_UNUSED
 static bool isImplicitExpr(clang::Expr *E) { return E->IgnoreImplicit() != E; }
 
-static SourceLocation getQualifiedNameStart(DeclaratorDecl *D) {
-  auto DN = D->getDeclName();
-  bool IsAnonymous = DN.isIdentifier() && !DN.getAsIdentifierInfo();
-  if (IsAnonymous)
-return SourceLocation();
-  return D->getQualifierLoc() ? D->getQualifierLoc().getBeginLoc()
-  : D->getLocation();
-}
-
 namespace {
 /// Get start location of the Declarator from the TypeLoc.
 /// E.g.:
@@ -142,8 +133,9 @@
   End = Name;
   }
   if (Initializer.isValid()) {
-assert(SM.isBeforeInTranslationUnit(End, Initializer.getEnd()));
-End = Initializer.getEnd();
+auto InitializerEnd = Initializer.getEnd();
+assert(SM.isBeforeInTranslationUnit(End, InitializerEnd) || End == InitializerEnd);
+End = InitializerEnd;
   }
   return SourceRange(Start, End);
 }
@@ -212,10 +204,6 @@
 foldNode(Range, New, nullptr);
   }
 
-  /// Must be called with the range of each `DeclaratorDecl`. Ensures the
-  /// corresponding declarator nodes are covered by `SimpleDeclaration`.
-  void noticeDeclRange(llvm::ArrayRef Range);
-
   /// Notifies that we should not consume trailing semicolon when computing
   /// token range of \p D.
   void noticeDeclWithoutSemicolon(Decl *D);
@@ -237,11 +225,6 @@
   void markChild(syntax::Node *N, NodeRole R);
   /// Set role for the syntax node matching \p N.
   void markChild(ASTPtr N, NodeRole R);
-  /// Set role for the delayed node that spans exactly \p Range.
-  void markDelayedChild(llvm::ArrayRef Range, NodeRole R);
-  /// Set role for the node that may or may not be delayed. Node must span
-  /// exactly \p Range.
-  void markMaybeDelayedChild(llvm::ArrayRef Range, NodeRole R);
 
   /// Finish building the tree and consume the root node.
   syntax::TranslationUnit *finalize() && {
@@ -285,7 +268,38 @@
 return maybeAppendSemicolon(Tokens, D);
   }
 
-  llvm::ArrayRef getDeclRange(const Decl *D) const {

[PATCH] D73521: [analyzer] add-new-checker.py: Introduction

2020-03-31 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

Will this utility affect Visual Studio builds?


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

https://reviews.llvm.org/D73521



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


[PATCH] D76922: [Syntax] Remove delayed folding from tree building.

2020-03-31 Thread Marcel Hlopko via Phabricator via cfe-commits
hlopko added a comment.

I propose adding those tests in a separate patch to keep this one focused. 
Those tests are currently failing, because:

- we assume initializer, if present, is extending the declarator range, but 
`struct P {} p;` has initializer ending where declarator ended already.
- UnknownExpressions finds its way inside SimpleDeclarator for p in `struct P 
{} p, *pp`;
- typedefs also fail, unable to find the end of declarator properly. I didn't 
investigate further.

Fixing those seems worthy of a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76922



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


[clang] cdce2fe - [Syntax] Remove delayed folding from tree building.

2020-03-31 Thread Dmitri Gribenko via cfe-commits

Author: Marcel Hlopko
Date: 2020-03-31T09:47:50+02:00
New Revision: cdce2fe561eb6e63d77d1d589e521a8e2afb1eef

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

LOG: [Syntax] Remove delayed folding from tree building.

Summary:
This patch removes delayed folding and replaces it with forward peeking.

Delayed folding was previously used as a solution to the problem that
declaration doesn't have a representation in the AST. For example following
code:

```
int a,b;
```

is expressed in the AST as:

```
TranslationUnitDecl
|-...
|-VarDecl `int a`
`-VarDecl `int b`
```

And in the syntax tree we need:

```
*: TranslationUnit
`-SimpleDeclaration
  |-int
  |-SimpleDeclarator
  | `-a
  |-,
  |-SimpleDeclarator
  | `-b
  |-;
```

So in words, we need to create SimpleDeclaration to be a parent of
SimpleDeclarator nodes. Previously we used delayed folding to make sure 
SimpleDeclarations will be
eventually created. And in case multiple declarators requested declaration
creation, declaration range was extended to cover all declarators.

This design started to be hard to reason about, so we decided to replace it with
forward peeking. The last declarator node in the chain is responsible for 
creating
SimpleDeclaration for the whole chain. Range of the declaration corresponds to
the source range of the declarator node. Declarator decides whether its the last
one by peeking to the next AST node (see `isResponsibleForCreatingDeclaration`).

This patch does following:
* Removed delayed folding logic
* Tweaks Token.dumpForTests
* Moves getQualifiedNameStart inside BuildTreeVisitor
* Extracts BuildTreeVisitor.ProcessDeclaratorAndDeclaration
* Renames Builder.getDeclRange to Builder.getDeclarationRange and uses the
  method in all places.
* Adds a bunch of tests

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/lib/Tooling/Syntax/Tokens.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/BuildTree.cpp 
b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 82c87ba02b74..11058edec615 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -44,15 +44,6 @@ using namespace clang;
 LLVM_ATTRIBUTE_UNUSED
 static bool isImplicitExpr(clang::Expr *E) { return E->IgnoreImplicit() != E; }
 
-static SourceLocation getQualifiedNameStart(DeclaratorDecl *D) {
-  auto DN = D->getDeclName();
-  bool IsAnonymous = DN.isIdentifier() && !DN.getAsIdentifierInfo();
-  if (IsAnonymous)
-return SourceLocation();
-  return D->getQualifierLoc() ? D->getQualifierLoc().getBeginLoc()
-  : D->getLocation();
-}
-
 namespace {
 /// Get start location of the Declarator from the TypeLoc.
 /// E.g.:
@@ -142,8 +133,9 @@ static SourceRange getDeclaratorRange(const SourceManager 
&SM, TypeLoc T,
   End = Name;
   }
   if (Initializer.isValid()) {
-assert(SM.isBeforeInTranslationUnit(End, Initializer.getEnd()));
-End = Initializer.getEnd();
+auto InitializerEnd = Initializer.getEnd();
+assert(SM.isBeforeInTranslationUnit(End, InitializerEnd) || End == 
InitializerEnd);
+End = InitializerEnd;
   }
   return SourceRange(Start, End);
 }
@@ -212,10 +204,6 @@ class syntax::TreeBuilder {
 foldNode(Range, New, nullptr);
   }
 
-  /// Must be called with the range of each `DeclaratorDecl`. Ensures the
-  /// corresponding declarator nodes are covered by `SimpleDeclaration`.
-  void noticeDeclRange(llvm::ArrayRef Range);
-
   /// Notifies that we should not consume trailing semicolon when computing
   /// token range of \p D.
   void noticeDeclWithoutSemicolon(Decl *D);
@@ -237,11 +225,6 @@ class syntax::TreeBuilder {
   void markChild(syntax::Node *N, NodeRole R);
   /// Set role for the syntax node matching \p N.
   void markChild(ASTPtr N, NodeRole R);
-  /// Set role for the delayed node that spans exactly \p Range.
-  void markDelayedChild(llvm::ArrayRef Range, NodeRole R);
-  /// Set role for the node that may or may not be delayed. Node must span
-  /// exactly \p Range.
-  void markMaybeDelayedChild(llvm::ArrayRef Range, NodeRole R);
 
   /// Finish building the tree and consume the root node.
   syntax::TranslationUnit *finalize() && {
@@ -285,7 +268,38 @@ class syntax::TreeBuilder {
 return maybeAppendSemicolon(Tokens, D);
   }
 
-  llvm::ArrayRef getDeclRange(const Decl *D) const {
+  /// Returns true if \p D is the last declarator in a chain and is thus
+  /// reponsible for creating SimpleDeclaration for the whole chain.
+  template 
+  bool isResponsibleForCreatingDeclaration(const T *D) const {
+static_assert((std:

[PATCH] D76996: [analyzer] Improve PlacementNewChecker

2020-03-31 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/test/Analysis/placement-new.cpp:265
+
+  // bad 2(custom align) + 1(index '2' offset)
+  ::new (&Xi.b[1]) long; // expected-warning{{Storage type is aligned to 3 
bytes but allocated type is aligned to 8 bytes}} expected-note 1 {{}}

Maybe it is just me, but the contents of the parens here and above seems a bit 
muddled `(index '2' offset)`. This should be `(index '1' offset)`, shouldn't it?
What is the exact meaning of the number in the hyphens (`'2'` in this case), 
could you please elaborate?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76996



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


[PATCH] D77119: [AVR] Fix function pointer address space

2020-03-31 Thread Vlastimil Labsky via Phabricator via cfe-commits
vlastik created this revision.
vlastik added a reviewer: dylanmckay.
Herald added subscribers: cfe-commits, Jim.
Herald added a project: clang.

Function pointers should be created with program address space.
This fixes function pointers on AVR.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77119

Files:
  clang/lib/CodeGen/CodeGenTypes.cpp


Index: clang/lib/CodeGen/CodeGenTypes.cpp
===
--- clang/lib/CodeGen/CodeGenTypes.cpp
+++ clang/lib/CodeGen/CodeGenTypes.cpp
@@ -595,7 +595,11 @@
 llvm::Type *PointeeType = ConvertTypeForMem(ETy);
 if (PointeeType->isVoidTy())
   PointeeType = llvm::Type::getInt8Ty(getLLVMContext());
-unsigned AS = Context.getTargetAddressSpace(ETy);
+
+unsigned AS = PointeeType->isFunctionTy()
+  ? getDataLayout().getProgramAddressSpace()
+  : Context.getTargetAddressSpace(ETy);
+
 ResultType = llvm::PointerType::get(PointeeType, AS);
 break;
   }


Index: clang/lib/CodeGen/CodeGenTypes.cpp
===
--- clang/lib/CodeGen/CodeGenTypes.cpp
+++ clang/lib/CodeGen/CodeGenTypes.cpp
@@ -595,7 +595,11 @@
 llvm::Type *PointeeType = ConvertTypeForMem(ETy);
 if (PointeeType->isVoidTy())
   PointeeType = llvm::Type::getInt8Ty(getLLVMContext());
-unsigned AS = Context.getTargetAddressSpace(ETy);
+
+unsigned AS = PointeeType->isFunctionTy()
+  ? getDataLayout().getProgramAddressSpace()
+  : Context.getTargetAddressSpace(ETy);
+
 ResultType = llvm::PointerType::get(PointeeType, AS);
 break;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76922: [Syntax] Remove delayed folding from tree building.

2020-03-31 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcdce2fe561eb: [Syntax] Remove delayed folding from tree 
building. (authored by hlopko, committed by gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76922

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -224,6 +224,59 @@
 )txt");
 }
 
+TEST_F(SyntaxTreeTest, SimpleVariable) {
+  expectTreeDumpEqual(
+  R"cpp(
+int a;
+int b = 42;
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | `-a
+| `-;
+`-SimpleDeclaration
+  |-int
+  |-SimpleDeclarator
+  | |-b
+  | |-=
+  | `-UnknownExpression
+  |   `-42
+  `-;
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, SimpleFunction) {
+  expectTreeDumpEqual(
+  R"cpp(
+void foo(int a, int b) {}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-foo
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   |-,
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-b
+  |   `-)
+  `-CompoundStatement
+|-{
+`-}
+)txt");
+}
+
 TEST_F(SyntaxTreeTest, If) {
   expectTreeDumpEqual(
   R"cpp(
@@ -541,20 +594,32 @@
 TEST_F(SyntaxTreeTest, MultipleDeclaratorsGrouping) {
   expectTreeDumpEqual(
   R"cpp(
-  int *a, b;
+  int *a, b; int *c, d;
   )cpp",
   R"txt(
 *: TranslationUnit
+|-SimpleDeclaration
+| |-int
+| |-SimpleDeclarator
+| | |-*
+| | `-a
+| |-,
+| |-SimpleDeclarator
+| | `-b
+| `-;
 `-SimpleDeclaration
   |-int
   |-SimpleDeclarator
   | |-*
-  | `-a
+  | `-c
   |-,
   |-SimpleDeclarator
-  | `-b
+  | `-d
   `-;
   )txt");
+}
+
+TEST_F(SyntaxTreeTest, MultipleDeclaratorsGroupingTypedef) {
   expectTreeDumpEqual(
   R"cpp(
 typedef int *a, b;
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -710,8 +710,8 @@
 }
 
 std::string syntax::Token::dumpForTests(const SourceManager &SM) const {
-  return std::string(
-  llvm::formatv("{0}   {1}", tok::getTokenName(kind()), text(SM)));
+  return std::string(llvm::formatv("Token(`{0}`, {1}, length = {2})", text(SM),
+   tok::getTokenName(kind()), length()));
 }
 
 std::string TokenBuffer::dumpForTests() const {
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -44,15 +44,6 @@
 LLVM_ATTRIBUTE_UNUSED
 static bool isImplicitExpr(clang::Expr *E) { return E->IgnoreImplicit() != E; }
 
-static SourceLocation getQualifiedNameStart(DeclaratorDecl *D) {
-  auto DN = D->getDeclName();
-  bool IsAnonymous = DN.isIdentifier() && !DN.getAsIdentifierInfo();
-  if (IsAnonymous)
-return SourceLocation();
-  return D->getQualifierLoc() ? D->getQualifierLoc().getBeginLoc()
-  : D->getLocation();
-}
-
 namespace {
 /// Get start location of the Declarator from the TypeLoc.
 /// E.g.:
@@ -142,8 +133,9 @@
   End = Name;
   }
   if (Initializer.isValid()) {
-assert(SM.isBeforeInTranslationUnit(End, Initializer.getEnd()));
-End = Initializer.getEnd();
+auto InitializerEnd = Initializer.getEnd();
+assert(SM.isBeforeInTranslationUnit(End, InitializerEnd) || End == InitializerEnd);
+End = InitializerEnd;
   }
   return SourceRange(Start, End);
 }
@@ -212,10 +204,6 @@
 foldNode(Range, New, nullptr);
   }
 
-  /// Must be called with the range of each `DeclaratorDecl`. Ensures the
-  /// corresponding declarator nodes are covered by `SimpleDeclaration`.
-  void noticeDeclRange(llvm::ArrayRef Range);
-
   /// Notifies that we should not consume trailing semicolon when computing
   /// token range of \p D.
   void noticeDeclWithoutSemicolon(Decl *D);
@@ -237,11 +225,6 @@
   void markChild(syntax::Node *N, NodeRole R);
   /// Set role for the syntax node matching \p N.
   void markChild(ASTPtr N, NodeRole R);
-  /// Set role for the delayed node that spans exactly \p Range.
-  void markDelayedChild(llvm::ArrayRef Range, NodeRole R);
-  /// Set role for the node that may or may not be delayed. Node must span
-  /// exactly \p Range.
-  void markMaybeDelayedChild(llvm::ArrayRef Range, NodeRole R);
 
   /// Finish building the tree and consume the root node.
   syntax::TranslationUnit *finalize() && {
@@ -285,7 +268,38 @@
 return maybeAppendSemicolon(Tok

[PATCH] D77119: [AVR] Fix function pointer address space

2020-03-31 Thread Vlastimil Labsky via Phabricator via cfe-commits
vlastik updated this revision to Diff 253802.
vlastik added a comment.

Fix formatting


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

https://reviews.llvm.org/D77119

Files:
  clang/lib/CodeGen/CodeGenTypes.cpp


Index: clang/lib/CodeGen/CodeGenTypes.cpp
===
--- clang/lib/CodeGen/CodeGenTypes.cpp
+++ clang/lib/CodeGen/CodeGenTypes.cpp
@@ -595,7 +595,11 @@
 llvm::Type *PointeeType = ConvertTypeForMem(ETy);
 if (PointeeType->isVoidTy())
   PointeeType = llvm::Type::getInt8Ty(getLLVMContext());
-unsigned AS = Context.getTargetAddressSpace(ETy);
+
+unsigned AS = PointeeType->isFunctionTy()
+  ? getDataLayout().getProgramAddressSpace()
+  : Context.getTargetAddressSpace(ETy);
+
 ResultType = llvm::PointerType::get(PointeeType, AS);
 break;
   }


Index: clang/lib/CodeGen/CodeGenTypes.cpp
===
--- clang/lib/CodeGen/CodeGenTypes.cpp
+++ clang/lib/CodeGen/CodeGenTypes.cpp
@@ -595,7 +595,11 @@
 llvm::Type *PointeeType = ConvertTypeForMem(ETy);
 if (PointeeType->isVoidTy())
   PointeeType = llvm::Type::getInt8Ty(getLLVMContext());
-unsigned AS = Context.getTargetAddressSpace(ETy);
+
+unsigned AS = PointeeType->isFunctionTy()
+  ? getDataLayout().getProgramAddressSpace()
+  : Context.getTargetAddressSpace(ETy);
+
 ResultType = llvm::PointerType::get(PointeeType, AS);
 break;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75844: [clang] Set begin loc on GNU attribute parsed attrs

2020-03-31 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Sorry for taking so long but it seems like I've went down a rabbit hole a bit. 
My previous patch sets the range in `parseGNUAttributes()` unconditionally, but 
that seems to trigger cases such as

  // FixItLoc = possible correct location for the attributes
  void ProhibitAttributes(ParsedAttributesWithRange &Attrs,
  SourceLocation FixItLoc = SourceLocation()) {
if (Attrs.Range.isInvalid())
  return;
DiagnoseProhibitedAttributes(Attrs.Range, FixItLoc);
Attrs.clear();
  }

in Parser.h. Because now the attributes have a valid range, clang emits lots of 
errors where it previously did not.

Do you have a suggestion of what to do here, should I rather go back to a more 
local fix for the issue?


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

https://reviews.llvm.org/D75844



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


[PATCH] D76996: [analyzer] Improve PlacementNewChecker

2020-03-31 Thread Karasev Nikita via Phabricator via cfe-commits
f00kat updated this revision to Diff 253803.
f00kat marked an inline comment as done.
f00kat added a comment.

Fixed comments in tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76996

Files:
  clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
  clang/test/Analysis/placement-new.cpp

Index: clang/test/Analysis/placement-new.cpp
===
--- clang/test/Analysis/placement-new.cpp
+++ clang/test/Analysis/placement-new.cpp
@@ -155,3 +155,147 @@
   (void)dp;
 }
 } // namespace testHierarchy
+
+namespace testArrayTypesAllocation {
+void f1() {
+  struct S {
+short a;
+  };
+
+  // bad (not enough space).
+  const unsigned N = 32;
+  alignas(S) unsigned char buffer1[sizeof(S) * N]; // expected-note {{'buffer1' initialized here}}
+  ::new (buffer1) S[N];// expected-warning{{Storage provided to placement new is only 64 bytes, whereas the allocated array type requires more space for internal needs}} expected-note 1 {{}}
+}
+
+void f2() {
+  struct S {
+short a;
+  };
+
+  // maybe ok but we need to warn.
+  const unsigned N = 32;
+  alignas(S) unsigned char buffer2[sizeof(S) * N + sizeof(int)]; // expected-note {{'buffer2' initialized here}}
+  ::new (buffer2) S[N];  // expected-warning{{68 bytes is possibly not enough for array allocation which requires 64 bytes. Current overhead requires the size of 4 bytes}} expected-note 1 {{}}
+}
+} // namespace testArrayTypesAllocation
+
+namespace testStructAlign {
+void f1() {
+  struct X {
+char a[9];
+  } Xi; // expected-note {{'Xi' initialized here}}
+
+  // bad (struct X is aligned to char).
+  ::new (&Xi.a) long; // expected-warning{{Storage type is aligned to 1 bytes but allocated type is aligned to 8 bytes}} expected-note 1 {{}}
+}
+
+void f2() {
+  struct X {
+char a;
+char b;
+long c;
+  } Xi;
+
+  // ok (struct X is aligned to long).
+  ::new (&Xi.a) long;
+}
+
+void f3() {
+  struct X {
+char a;
+char b;
+long c;
+  } Xi; // expected-note {{'Xi' initialized here}}
+
+  // bad (struct X is aligned to long but field 'b' is aligned to 1 because of its offset)
+  ::new (&Xi.b) long; // expected-warning{{Storage type is aligned to 1 bytes but allocated type is aligned to 8 bytes}} expected-note 1 {{}}
+}
+
+void f4() {
+  struct X {
+char a;
+struct alignas(alignof(short)) Y {
+  char b;
+  char c;
+} y;
+long d;
+  } Xi; // expected-note {{'Xi' initialized here}}
+
+  // bad. 'b' is aligned to short
+  ::new (&Xi.y.b) long; // expected-warning{{Storage type is aligned to 2 bytes but allocated type is aligned to 8 bytes}} expected-note 1 {{}}
+}
+
+void f5() {
+  short b[10]; // expected-note {{'b' initialized here}}
+
+  ::new (&b) long; // expected-warning{{Storage type is aligned to 2 bytes but allocated type is aligned to 8 bytes}} expected-note 1 {{}}
+}
+
+void f6() {
+  short b[10]; // expected-note {{'b' initialized here}}
+
+  // bad (same as previous but checks ElementRegion case)
+  ::new (&b[0]) long; // expected-warning{{Storage type is aligned to 2 bytes but allocated type is aligned to 8 bytes}} expected-note 1 {{}}
+}
+
+void f7() {
+  short b[10];
+
+  // ok. 2(short align) + 3*2(index '3' offset)
+  ::new (&b[3]) long;
+}
+
+void f8() {
+  short b[10]; // expected-note {{'b' initialized here}}
+
+  // bad. 2(short align) + 2*2(index '2' offset)
+  ::new (&b[2]) long; // expected-warning{{Storage type is aligned to 6 bytes but allocated type is aligned to 8 bytes}} expected-note 1 {{}}
+}
+
+void f9() {
+  struct X {
+char a;
+alignas(alignof(short)) char b[20];
+  } Xi; // expected-note {{'Xi' initialized here}}
+
+  // ok 2(custom align) + 6*1(index '6' offset)
+  ::new (&Xi.b[6]) long;
+
+  // bad 2(custom align) + 1*1(index '1' offset)
+  ::new (&Xi.b[1]) long; // expected-warning{{Storage type is aligned to 3 bytes but allocated type is aligned to 8 bytes}} expected-note 1 {{}}
+}
+
+void f10() {
+  struct X {
+char a[8];
+alignas(2) char b;
+  } Xi; // expected-note {{'Xi' initialized here}}
+
+  // bad (struct X is aligned to 2).
+  ::new (&Xi.a) long; // expected-warning{{Storage type is aligned to 2 bytes but allocated type is aligned to 8 bytes}} expected-note 1 {{}}
+}
+
+void f11() {
+  struct X {
+char a;
+char b;
+struct Y {
+  long c;
+} d;
+  } Xi;
+
+  // ok (struct X is aligned to long).
+  ::new (&Xi.a) long;
+}
+
+void f12() {
+  struct alignas(alignof(long)) X {
+char a;
+char b;
+  } Xi;
+
+  // ok (struct X is aligned to long).
+  ::new (&Xi.a) long;
+}
+} // namespace testStructAlign
Index: clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
+++ clang/lib/StaticAnalyzer/Checkers

[PATCH] D77039: [clang-format] Don't break multi block parameters on ObjCBreakBeforeNestedBlockParam

2020-03-31 Thread Jacek Olesiak via Phabricator via cfe-commits
jolesiak accepted this revision.
jolesiak added a comment.
This revision is now accepted and ready to land.

Makes sense, thanks for patching this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77039



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


[PATCH] D77041: [AST] Fix a crash on invalid constexpr Ctorinitializer when building RecoveryExpr.

2020-03-31 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

> This makes me nervous, marking the constructor as invalid seems much safer. 
> Can you show tests it regresses?

Yeah, the first version of the patch doesn't seem to fix all crashes (X().Y 
would lead another crash)...

so if we mark the CtorDecl as invalid

1. whenever `CtorInitializer->init()->containsError`, we don't have failure 
tests
2. whenever there is any kind of errors (including the containsError case 
above) in CtorInitailizer, we have three failing tests 
(SemaCXX/constant-expression-cxx11.cpp, SemaCXX/constructor-initializer.cpp, 
SemaTemplate/constexpr-instantiate.cpp).

though 1) passes all existing tests, I think it just means current tests don't 
have enough coverage for recoveryExpr cases. But given the current state, 1) 
looks most promising -- fixes the crashes, retains broken expressions in 
CtorInitializer rather than dropping them, doesn't regress the diagnostics a 
lot (only for CtorInitializer->init()->containsError` case).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77041



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


[PATCH] D77041: [AST] Fix a crash on invalid constexpr Ctorinitializer when building RecoveryExpr.

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

- mark CtorDecl as invalid when the Initializer init expr contains errors
- add a testcase that would crash the previous version of the patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77041

Files:
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/invalid-constructor-init.cpp


Index: clang/test/SemaCXX/invalid-constructor-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-constructor-init.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -frecovery-ast -verify %s
+
+struct X {// expected-note 2{{candidate constructor }}
+  int Y;
+  constexpr X() : Y(foo()) {} // expected-error {{use of undeclared identifier 
'foo'}}
+};
+// no crash on evaluating the constexpr ctor.
+// FIXME: get rid of the bogus diagnostic below.
+constexpr int Z = X().Y; // expected-error {{no matching constructor for 
initialization of 'X'}}
+
+struct X2 {
+  int Y = foo(); // expected-error {{use of undeclared identifier 'foo'}} \
+ // expected-note {{subexpression not valid in a constant 
expression}}
+  constexpr X2() {} // expected-error {{constexpr constructor never produces a 
constant expression}}
+};
+
+struct CycleDelegate {
+  int Y;
+  CycleDelegate(int) : Y(foo()) {} // expected-error {{use of undeclared 
identifier 'foo'}}
+  // FIXME: get rid of the bogus "delegation cycle" diagnostic
+  // CycleDeclegate(int) is marked as invalid.
+  CycleDelegate(float) : CycleDelegate(1) {} // expected-error {{creates a 
delegation cycle}}
+};
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -1685,6 +1685,7 @@
 // This implements C++11 [dcl.constexpr]p3,4, as amended by DR1360.
 bool Sema::CheckConstexprFunctionDefinition(const FunctionDecl *NewFD,
 CheckConstexprKind Kind) {
+  assert(!NewFD->isInvalidDecl());
   const CXXMethodDecl *MD = dyn_cast(NewFD);
   if (MD && MD->isInstance()) {
 // C++11 [dcl.constexpr]p4:
@@ -5000,7 +5001,8 @@
 
   for (unsigned i = 0; i < Initializers.size(); i++) {
 CXXCtorInitializer *Member = Initializers[i];
-
+if (Member->getInit() && Member->getInit()->containsErrors())
+  Constructor->setInvalidDecl();
 if (Member->isBaseInitializer())
   Info.AllBaseFields[Member->getBaseClass()->getAs()] = Member;
 else {
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -45,6 +45,7 @@
 #include "clang/Sema/Template.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/Support/Casting.h"
 #include 
 #include 
 #include 
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -3454,9 +3454,12 @@
 }
 
 MemInitResult MemInit = ParseMemInitializer(ConstructorDecl);
-if (!MemInit.isInvalid())
+if (!MemInit.isInvalid()) {
   MemInitializers.push_back(MemInit.get());
-else
+  if (MemInit.get()->getInit() &&
+  MemInit.get()->getInit()->containsErrors())
+AnyErrors = true;
+} else
   AnyErrors = true;
 
 if (Tok.is(tok::comma))


Index: clang/test/SemaCXX/invalid-constructor-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-constructor-init.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -frecovery-ast -verify %s
+
+struct X {// expected-note 2{{candidate constructor }}
+  int Y;
+  constexpr X() : Y(foo()) {} // expected-error {{use of undeclared identifier 'foo'}}
+};
+// no crash on evaluating the constexpr ctor.
+// FIXME: get rid of the bogus diagnostic below.
+constexpr int Z = X().Y; // expected-error {{no matching constructor for initialization of 'X'}}
+
+struct X2 {
+  int Y = foo(); // expected-error {{use of undeclared identifier 'foo'}} \
+ // expected-note {{subexpression not valid in a constant expression}}
+  constexpr X2() {} // expected-error {{constexpr constructor never produces a constant expression}}
+};
+
+struct CycleDelegate {
+  int Y;
+  CycleDelegate(int) : Y(foo()) {} // expected-error {{use of undeclared identifier 'foo'}}
+  // FIXME: get rid of the bogus "delegation cycle" diagnostic
+  // CycleDeclegate(int) is marked as invalid.
+  CycleDelegate(float) : CycleDelegate(1) {} // expected-error {{creates a delegation cycle}}
+};
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clan

[PATCH] D62627: [NFC] Do not run CGProfilePass when not using integrated assembler

2020-03-31 Thread Bill Wendling via Phabricator via cfe-commits
void edited subscribers, added: manojgupta; removed: cfe-commits.
void added a comment.

Friendly ping. :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62627



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


[PATCH] D77125: [Analyzer] Model return values of container insert and delete operations

2020-03-31 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added reviewers: NoQ, Szelethus.
baloghadamsoftware added a project: clang.
Herald added subscribers: ASDenysPetrov, martong, steakhal, Charusso, 
gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
xazax.hun, whisperity.

Insert and delete operations of `insert()`, `erase()` (plus `insert_after()` 
and `erase_after()` for `std::forward_list`-like containers were not modeled 
yet. This patch fixes this issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77125

Files:
  clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  clang/test/Analysis/Inputs/system-header-simulator-cxx.h
  clang/test/Analysis/diagnostics/explicit-suppression.cpp
  clang/test/Analysis/iterator-modeling.cpp

Index: clang/test/Analysis/iterator-modeling.cpp
===
--- clang/test/Analysis/iterator-modeling.cpp
+++ clang/test/Analysis/iterator-modeling.cpp
@@ -868,8 +868,8 @@
   clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
 
   clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning{{$L.begin()}}
-  // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $L.begin() - 1
   clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning{{$L.end()}}
+  clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$L.begin()}}
 }
 
 void list_insert_behind_begin(std::list &L, int n) {
@@ -884,10 +884,10 @@
   clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
   clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
 
-  clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning{{$L.begin()}} FIXME: Should be $L.begin() - 1
+  clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning{{$L.begin()}}
   clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning{{$L.begin() + 1}}
-  // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.begin()
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$L.end()}}
+  clang_analyzer_express(clang_analyzer_iterator_position(i3)); // expected-warning{{$L.begin()}}
 }
 
 template  Iter return_any_iterator(const Iter &It);
@@ -907,8 +907,8 @@
 
   clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning{{$L.begin()}}
   clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning{{$i1}}
-  // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i - 1
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$L.end()}}
+  clang_analyzer_express(clang_analyzer_iterator_position(i3)); // expected-warning{{$i1}}
 }
 
 void list_insert_ahead_of_end(std::list &L, int n) {
@@ -926,7 +926,7 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning{{$L.begin()}}
   clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning{{$L.end() - 1}}
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$L.end()}}
-  // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.end() - 2
+  clang_analyzer_express(clang_analyzer_iterator_position(i3)); // expected-warning{{$L.end() - 1}}
 }
 
 void list_insert_end(std::list &L, int n) {
@@ -942,9 +942,9 @@
   clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
 
   clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning{{$L.begin()}}
-  clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning{{$L.end() - 1}} FIXME: should be $L.end() - 2
+  clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning{{$L.end() - 1}}
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$L.end()}}
-  // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.end() - 1
+  clang_analyzer_express(clang_analyzer_iterator_position(i3)); // expected-warning{{$L.end()}}
 }
 
 /// std::vector-like containers: Only the iterators before the insertion point
@@ -962,7 +962,7 @@
   clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
   clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
 
-  // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $V.begin() - 1
+  clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$V.begin()}}
 }
 
 void vector_insert_behind_begin(std::vector &V, int n) {
@@ -977,8 +977,8 @@
   clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALS

[PATCH] D76996: [analyzer] Improve PlacementNewChecker

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

LGTM! Thanks! But I am not that confident with the element regions and field 
regions, so @NoQ could you please take another look?




Comment at: clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp:82
   CharUnits TypeSize = AstContext.getTypeSizeInChars(ElementType);
-  if (NE->isArray()) {
+  if (IsArray = NE->isArray()) {
 const Expr *SizeExpr = *NE->getArraySize();

This will break build-bots that run with -Werror.
```
../../git/llvm-project/clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp:82:15:
 warning: suggest parentheses around assignment used as truth value 
[-Wparentheses]
   if (IsArray = NE->isArray()) {
```



Comment at: clang/test/Analysis/placement-new.cpp:256
+
+void f9() {
+  struct X {

First I was wondering if we indeed handle correctly structs with nested arrays 
whose element's type is a structs with nested arrays (... and so on).

So, I tried the below test, and it seems okay. Thus I think it might be worth 
to add something similar to it.

```
void f9_1() {
  struct Y {
char a;
alignas(alignof(short)) char b[20];
  };
  struct X {
char e;
Y f[20];
  } Xi; // expected-note {{'Xi' initialized here}}

  // ok 2(custom align) + 6*1(index '6' offset)
  ::new (&Xi.f[6].b[6]) long;

  // bad 2(custom align) + 1*1(index '1' offset)
  ::new (&Xi.f[1].b[1]) long; // expected-warning{{Storage type is aligned to 3 
bytes but allocated type is aligned to 8 bytes}} expected-note 1 {{}}
}

```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76996



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


[PATCH] D75169: [ARM] Enforcing calling convention for half-precision FP arguments and returns for big-endian AArch32

2020-03-31 Thread Lucas Prates via Phabricator via cfe-commits
pratlucas added a comment.

> Why not just make half as an argument do the right thing for that case?

That would be the ideal approach, but currently there's a limitation on the 
backend's calling convention lowering that gets in the way.
The lowering of calls in `SelectionDAGBuilder` includes a target-independent 
step that is responsible for spliting or promoting each argument into "legal 
registers" and takes place before the targets' calling convention lowering.
As `f16` is not a legal type on many of the `AAPCS_VFP` targets, it gets 
promoted to `f32` before the target's lowering code has a chance to define how 
to handle it.
Ideally, this stpe should only take place if lowering calling conventions after 
type legalization - there's a FIXME there already capturing that -, but that 
would involve a major rewriting that would impact multiple targets.
Inserting a hacky target-dependent fix in this step also didn't look very good.
Do you see other alternatives for handling it? If not, which approach would you 
suggest?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75169



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


[PATCH] D76663: [clangd] Support new semanticTokens request from LSP 3.16.

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

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76663



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


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

2020-03-31 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.
Herald added a subscriber: ASDenysPetrov.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72705



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


[PATCH] D77131: [clang] Move branch-protection from CodeGenOptions to LangOptions

2020-03-31 Thread Tamas Petz via Phabricator via cfe-commits
tamas.petz created this revision.
tamas.petz added a reviewer: momchil.velikov.
tamas.petz added a project: clang.
Herald added a subscriber: cfe-commits.
danielkiss added a comment.
tamas.petz marked an inline comment as done.

just a nit, LGTM otherwise.




Comment at: clang/include/clang/Basic/CodeGenOptions.def:402
 #undef VALUE_CODEGENOPT
-

is this change necessary? 



Comment at: clang/include/clang/Basic/CodeGenOptions.def:402
 #undef VALUE_CODEGENOPT
-

danielkiss wrote:
> is this change necessary? 
I think there should be one new line at the end of the file, not two.


Reason: the option has an effect on preprocessing.

Also see thread: http://lists.llvm.org/pipermail/cfe-dev/2020-March/065014.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77131

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1386,38 +1386,6 @@
 
   Opts.Addrsig = Args.hasArg(OPT_faddrsig);
 
-  if (Arg *A = Args.getLastArg(OPT_msign_return_address_EQ)) {
-StringRef SignScope = A->getValue();
-
-if (SignScope.equals_lower("none"))
-  Opts.setSignReturnAddress(CodeGenOptions::SignReturnAddressScope::None);
-else if (SignScope.equals_lower("all"))
-  Opts.setSignReturnAddress(CodeGenOptions::SignReturnAddressScope::All);
-else if (SignScope.equals_lower("non-leaf"))
-  Opts.setSignReturnAddress(
-  CodeGenOptions::SignReturnAddressScope::NonLeaf);
-else
-  Diags.Report(diag::err_drv_invalid_value)
-  << A->getAsString(Args) << SignScope;
-
-if (Arg *A = Args.getLastArg(OPT_msign_return_address_key_EQ)) {
-  StringRef SignKey = A->getValue();
-  if (!SignScope.empty() && !SignKey.empty()) {
-if (SignKey.equals_lower("a_key"))
-  Opts.setSignReturnAddressKey(
-  CodeGenOptions::SignReturnAddressKeyValue::AKey);
-else if (SignKey.equals_lower("b_key"))
-  Opts.setSignReturnAddressKey(
-  CodeGenOptions::SignReturnAddressKeyValue::BKey);
-else
-  Diags.Report(diag::err_drv_invalid_value)
-  << A->getAsString(Args) << SignKey;
-  }
-}
-  }
-
-  Opts.BranchTargetEnforcement = Args.hasArg(OPT_mbranch_target_enforce);
-
   Opts.KeepStaticConsts = Args.hasArg(OPT_fkeep_static_consts);
 
   Opts.SpeculativeLoadHardening = Args.hasArg(OPT_mspeculative_load_hardening);
@@ -3347,6 +3315,40 @@
   Opts.BuildingPCHWithObjectFile = Args.hasArg(OPT_building_pch_with_obj);
 
   Opts.MaxTokens = getLastArgIntValue(Args, OPT_fmax_tokens_EQ, 0, Diags);
+
+  if (Arg *A = Args.getLastArg(OPT_msign_return_address_EQ)) {
+StringRef SignScope = A->getValue();
+
+if (SignScope.equals_lower("none"))
+  Opts.setSignReturnAddressScope(
+  LangOptions::SignReturnAddressScopeKind::None);
+else if (SignScope.equals_lower("all"))
+  Opts.setSignReturnAddressScope(
+  LangOptions::SignReturnAddressScopeKind::All);
+else if (SignScope.equals_lower("non-leaf"))
+  Opts.setSignReturnAddressScope(
+  LangOptions::SignReturnAddressScopeKind::NonLeaf);
+else
+  Diags.Report(diag::err_drv_invalid_value)
+  << A->getAsString(Args) << SignScope;
+
+if (Arg *A = Args.getLastArg(OPT_msign_return_address_key_EQ)) {
+  StringRef SignKey = A->getValue();
+  if (!SignScope.empty() && !SignKey.empty()) {
+if (SignKey.equals_lower("a_key"))
+  Opts.setSignReturnAddressKey(
+  LangOptions::SignReturnAddressKeyKind::AKey);
+else if (SignKey.equals_lower("b_key"))
+  Opts.setSignReturnAddressKey(
+  LangOptions::SignReturnAddressKeyKind::BKey);
+else
+  Diags.Report(diag::err_drv_invalid_value)
+  << A->getAsString(Args) << SignKey;
+  }
+}
+  }
+
+  Opts.BranchTargetEnforcement = Args.hasArg(OPT_mbranch_target_enforce);
 }
 
 static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -5107,9 +5107,11 @@
 if (!FD)
   return;
 
-CodeGenOptions::SignReturnAddressScope Scope = CGM.getCodeGenOpts().getSignReturnAddress();
-CodeGenOptions::SignReturnAddressKeyValue Key = CGM.getCodeGenOpts().getSignReturnAddressKey();
-bool BranchTar

[PATCH] D77134: [clang][AARCH64] Add __ARM_FEATURE_{PAC, BTI}_DEFAULT defines

2020-03-31 Thread Tamas Petz via Phabricator via cfe-commits
tamas.petz created this revision.
tamas.petz added a reviewer: momchil.velikov.
tamas.petz added a project: clang.
Herald added subscribers: cfe-commits, danielkiss.
tamas.petz added a comment.

Depends on: https://reviews.llvm.org/D77131


As defined by Arm C Language Extensions (ACLE) these macro defines
should be set to specific values depending on -mbranch-protection.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77134

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/Basic/Targets/AArch64.cpp
  clang/test/Preprocessor/aarch64-target-features.c

Index: clang/test/Preprocessor/aarch64-target-features.c
===
--- clang/test/Preprocessor/aarch64-target-features.c
+++ clang/test/Preprocessor/aarch64-target-features.c
@@ -39,6 +39,8 @@
 // CHECK-NOT: __ARM_SIZEOF_WCHAR_T 2
 // CHECK-NOT: __ARM_FEATURE_SVE
 // CHECK-NOT: __ARM_FEATURE_DOTPROD
+// CHECK-NOT: __ARM_FEATURE_PAC_DEFAULT
+// CHECK-NOT: __ARM_FEATURE_BTI_DEFAULT
 
 // RUN: %clang -target aarch64-none-linux-gnu -march=armv8-a+crypto -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-CRYPTO %s
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+crypto -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-CRYPTO %s
@@ -334,3 +336,33 @@
 // == Check Memory Tagging Extensions (MTE).
 // RUN: %clang -target arm64-none-linux-gnu -march=armv8.5-a+memtag -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MEMTAG %s
 // CHECK-MEMTAG: __ARM_FEATURE_MEMORY_TAGGING 1
+
+// == Check Pointer Authentication Extension (PAuth).
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8.5-a -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=none -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=bti -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=standard -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=pac-ret -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=pac-ret+b-key -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-BKEY %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=pac-ret+leaf -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-ALL %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=pac-ret+leaf+b-key -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-PAUTH-BKEY-ALL %s
+// CHECK-PAUTH-OFF-NOT:  __ARM_FEATURE_PAC_DEFAULT
+// CHECK-PAUTH:  #define __ARM_FEATURE_PAC_DEFAULT 1
+// CHECK-PAUTH-BKEY: #define __ARM_FEATURE_PAC_DEFAULT 2
+// CHECK-PAUTH-ALL:  #define __ARM_FEATURE_PAC_DEFAULT 5
+// CHECK-PAUTH-BKEY-ALL: #define __ARM_FEATURE_PAC_DEFAULT 6
+
+// == Check Branch Target Identification (BTI).
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-BTI-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8.5-a -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-BTI-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=none -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-BTI-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=pac-ret -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-BTI-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=pac-ret+leaf -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-BTI-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=pac-ret+b-key -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-BTI-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=pac-ret+leaf+b-key -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-BTI-OFF %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=standard -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-BTI %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=bti -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-BTI %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a -mbranch-protection=pac-ret+bti -x c -E -dM %s -o - | FileCheck -check-prefix=CHECK-BTI %s
+// CHECK-BTI-OFF-NOT: __ARM_FEATURE_BTI_DEFAULT
+// CHECK-BTI: #define __ARM_FEATURE_BTI_DEFAULT 1
Index: clang/lib/Basic/Targets/AArch64.cpp
=

[PATCH] D77134: [clang][AARCH64] Add __ARM_FEATURE_{PAC, BTI}_DEFAULT defines

2020-03-31 Thread Tamas Petz via Phabricator via cfe-commits
tamas.petz added a comment.

Depends on: https://reviews.llvm.org/D77131


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77134



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


[PATCH] D77131: [clang] Move branch-protection from CodeGenOptions to LangOptions

2020-03-31 Thread Daniel Kiss via Phabricator via cfe-commits
danielkiss added a comment.

just a nit, LGTM otherwise.




Comment at: clang/include/clang/Basic/CodeGenOptions.def:402
 #undef VALUE_CODEGENOPT
-

is this change necessary? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77131



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


[PATCH] D77131: [clang] Move branch-protection from CodeGenOptions to LangOptions

2020-03-31 Thread Tamas Petz via Phabricator via cfe-commits
tamas.petz marked an inline comment as done.
tamas.petz added inline comments.



Comment at: clang/include/clang/Basic/CodeGenOptions.def:402
 #undef VALUE_CODEGENOPT
-

danielkiss wrote:
> is this change necessary? 
I think there should be one new line at the end of the file, not two.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77131



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


[PATCH] D77074: [FPEnv][AArch64] Platform-specific builtin constrained FP enablement

2020-03-31 Thread Diogo N. Sampaio via Phabricator via cfe-commits
dnsampaio added inline comments.



Comment at: clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c:288
+
+// XXX FIXME do we need to check for both w and x registers?
+// COMMON-LABEL: test_vceq_f64

kpn wrote:
> Anyone? I'm not an ARM expert.
The is variants of the `cset` instruction for both `w` and `x`. But I believe 
that for these tests it should be stable enough to accept only one of them.



Comment at: clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c:889
+
+// FIXME why the unused bitcast? There are several of them!
+// COMMON-LABEL: test_vrnda_f64

kpn wrote:
> ???
It is a known issue. I believe no-one dug through the neon-emmiter machinery to 
find out why yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77074



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


[PATCH] D73521: [analyzer] add-new-checker.py: Introduction

2020-03-31 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

In D73521#1951776 , @ASDenysPetrov 
wrote:

> Will this utility affect Visual Studio builds?


The community owns like 50 build-bots, so it should affect all of them by 
default. I am hoping it will just work.


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

https://reviews.llvm.org/D73521



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


[PATCH] D77119: [AVR] Fix function pointer address space

2020-03-31 Thread Dylan McKay via Phabricator via cfe-commits
dylanmckay added a comment.

Nice work @vlastik, do you need someone to commit this for you?


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

https://reviews.llvm.org/D77119



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


[clang-tools-extra] 3807079 - [clang-tidy] Fix crash in readability-redundant-string-cstr

2020-03-31 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-03-31T13:27:32+01:00
New Revision: 3807079d705fe04c5c3bde8f848ec922b5771f15

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

LOG: [clang-tidy] Fix crash in readability-redundant-string-cstr

Summary: Addresses [[ https://bugs.llvm.org/show_bug.cgi?id=45286 | 
clang-tidy-11: Crash in DynTypedMatcher::matches during 
readability-redundant-string-cstr check ]]

Reviewers: aaron.ballman, alexfh, gribozavr2

Reviewed By: gribozavr2

Subscribers: xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-cstr.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
index 8975f294373c..e41cdfcc08d8 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -61,53 +61,8 @@ formatDereference(const 
ast_matchers::MatchFinder::MatchResult &Result,
   return (llvm::Twine("*") + Text).str();
 }
 
-// Trying to get CallExpr in which CxxConstructExpr is called.
-static const clang::CallExpr *
-tryGetCallExprAncestorForCxxConstructExpr(const Expr *TheExpr,
-  ASTContext &Context) {
-  // We skip nodes such as CXXBindTemporaryExpr, MaterializeTemporaryExpr.
-  for (ast_type_traits::DynTypedNode DynParent : Context.getParents(*TheExpr)) 
{
-if (const auto *Parent = DynParent.get()) {
-  if (const auto *TheCallExpr = dyn_cast(Parent))
-return TheCallExpr;
-
-  if (const clang::CallExpr *TheCallExpr =
-  tryGetCallExprAncestorForCxxConstructExpr(Parent, Context))
-return TheCallExpr;
-}
-  }
-
-  return nullptr;
-}
-
-// Check that ParamDecl of CallExprDecl has rvalue type.
-static bool checkParamDeclOfAncestorCallExprHasRValueRefType(
-const Expr *TheCxxConstructExpr, ASTContext &Context) {
-  if (const clang::CallExpr *TheCallExpr =
-  tryGetCallExprAncestorForCxxConstructExpr(TheCxxConstructExpr,
-Context)) {
-for (unsigned i = 0; i < TheCallExpr->getNumArgs(); ++i) {
-  const Expr *Arg = TheCallExpr->getArg(i);
-  if (Arg->getSourceRange() == TheCxxConstructExpr->getSourceRange()) {
-if (const auto *TheCallExprFuncProto =
-TheCallExpr->getCallee()
-->getType()
-->getPointeeType()
-->getAs()) {
-  if (TheCallExprFuncProto->getParamType(i)->isRValueReferenceType())
-return true;
-}
-  }
-}
-  }
-
-  return false;
-}
-
-AST_MATCHER(CXXConstructExpr,
-matchedParamDeclOfAncestorCallExprHasRValueRefType) {
-  return checkParamDeclOfAncestorCallExprHasRValueRefType(
-  &Node, Finder->getASTContext());
+AST_MATCHER(MaterializeTemporaryExpr, isBoundToLValue) {
+  return Node.isBoundToLvalueReference();
 }
 
 } // end namespace
@@ -141,11 +96,11 @@ void RedundantStringCStrCheck::registerMatchers(
   // Detect redundant 'c_str()' calls through a string constructor.
   // If CxxConstructExpr is the part of some CallExpr we need to
   // check that matched ParamDecl of the ancestor CallExpr is not rvalue.
-  Finder->addMatcher(
-  cxxConstructExpr(
-  StringConstructorExpr, hasArgument(0, StringCStrCallExpr),
-  unless(matchedParamDeclOfAncestorCallExprHasRValueRefType())),
-  this);
+  Finder->addMatcher(cxxConstructExpr(StringConstructorExpr,
+  hasArgument(0, StringCStrCallExpr),
+  
unless(hasParent(materializeTemporaryExpr(
+  unless(isBoundToLValue()),
+ this);
 
   // Detect: 's == str.c_str()'  ->  's == str'
   Finder->addMatcher(

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-cstr.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-cstr.cpp
index 1773dc57a8d8..2561b81805bd 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-cstr.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-cstr.cpp
@@ -220,3 +220,27 @@ void m1(std::string&&) {
   m1tp m1p2 = m1;
   m1p2(s.c_str());  
 }
+
+namespace PR45286 {
+struct Foo {
+  void func(const std::string &) {}
+  void func2(std::string &&) {}
+};
+
+void bar() {
+  std::string Str{"aaa"};
+  Foo Foo;
+  Foo.f

[PATCH] D76761: [clang-tidy] Fix crash in readability-redundant-string-cstr

2020-03-31 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3807079d705f: [clang-tidy] Fix crash in 
readability-redundant-string-cstr (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76761

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-cstr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-cstr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-cstr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-cstr.cpp
@@ -220,3 +220,27 @@
   m1tp m1p2 = m1;
   m1p2(s.c_str());  
 }
+
+namespace PR45286 {
+struct Foo {
+  void func(const std::string &) {}
+  void func2(std::string &&) {}
+};
+
+void bar() {
+  std::string Str{"aaa"};
+  Foo Foo;
+  Foo.func(Str.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}Foo.func(Str);{{$}}
+
+  // Ensure it doesn't transform Binding to r values
+  Foo.func2(Str.c_str());
+
+  // Ensure its not confused by parens
+  Foo.func((Str.c_str()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}Foo.func((Str));{{$}}
+  Foo.func2((Str.c_str()));
+}
+} // namespace PR45286
Index: clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -61,53 +61,8 @@
   return (llvm::Twine("*") + Text).str();
 }
 
-// Trying to get CallExpr in which CxxConstructExpr is called.
-static const clang::CallExpr *
-tryGetCallExprAncestorForCxxConstructExpr(const Expr *TheExpr,
-  ASTContext &Context) {
-  // We skip nodes such as CXXBindTemporaryExpr, MaterializeTemporaryExpr.
-  for (ast_type_traits::DynTypedNode DynParent : Context.getParents(*TheExpr)) {
-if (const auto *Parent = DynParent.get()) {
-  if (const auto *TheCallExpr = dyn_cast(Parent))
-return TheCallExpr;
-
-  if (const clang::CallExpr *TheCallExpr =
-  tryGetCallExprAncestorForCxxConstructExpr(Parent, Context))
-return TheCallExpr;
-}
-  }
-
-  return nullptr;
-}
-
-// Check that ParamDecl of CallExprDecl has rvalue type.
-static bool checkParamDeclOfAncestorCallExprHasRValueRefType(
-const Expr *TheCxxConstructExpr, ASTContext &Context) {
-  if (const clang::CallExpr *TheCallExpr =
-  tryGetCallExprAncestorForCxxConstructExpr(TheCxxConstructExpr,
-Context)) {
-for (unsigned i = 0; i < TheCallExpr->getNumArgs(); ++i) {
-  const Expr *Arg = TheCallExpr->getArg(i);
-  if (Arg->getSourceRange() == TheCxxConstructExpr->getSourceRange()) {
-if (const auto *TheCallExprFuncProto =
-TheCallExpr->getCallee()
-->getType()
-->getPointeeType()
-->getAs()) {
-  if (TheCallExprFuncProto->getParamType(i)->isRValueReferenceType())
-return true;
-}
-  }
-}
-  }
-
-  return false;
-}
-
-AST_MATCHER(CXXConstructExpr,
-matchedParamDeclOfAncestorCallExprHasRValueRefType) {
-  return checkParamDeclOfAncestorCallExprHasRValueRefType(
-  &Node, Finder->getASTContext());
+AST_MATCHER(MaterializeTemporaryExpr, isBoundToLValue) {
+  return Node.isBoundToLvalueReference();
 }
 
 } // end namespace
@@ -141,11 +96,11 @@
   // Detect redundant 'c_str()' calls through a string constructor.
   // If CxxConstructExpr is the part of some CallExpr we need to
   // check that matched ParamDecl of the ancestor CallExpr is not rvalue.
-  Finder->addMatcher(
-  cxxConstructExpr(
-  StringConstructorExpr, hasArgument(0, StringCStrCallExpr),
-  unless(matchedParamDeclOfAncestorCallExprHasRValueRefType())),
-  this);
+  Finder->addMatcher(cxxConstructExpr(StringConstructorExpr,
+  hasArgument(0, StringCStrCallExpr),
+  unless(hasParent(materializeTemporaryExpr(
+  unless(isBoundToLValue()),
+ this);
 
   // Detect: 's == str.c_str()'  ->  's == str'
   Finder->addMatcher(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69088: [Lex] #pragma clang transform

2020-03-31 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69088



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


[PATCH] D76342: [OpenMP] Implement '#pragma omp tile'

2020-03-31 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76342



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


[PATCH] D77119: [AVR] Fix function pointer address space

2020-03-31 Thread Vlastimil Labsky via Phabricator via cfe-commits
vlastik added a comment.

In D77119#1952293 , @dylanmckay wrote:

> Nice work @vlastik, do you need someone to commit this for you?


Thanks, yes please I need someone to commit the patch


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

https://reviews.llvm.org/D77119



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


[clang-tools-extra] 71177ac - [clangd] Support new semanticTokens request from LSP 3.16.

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

Author: Sam McCall
Date: 2020-03-31T15:14:35+02:00
New Revision: 71177ac16801ceced4b7dcdd21b05345416f31df

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

LOG: [clangd] Support new semanticTokens request from LSP 3.16.

Summary:
This is a simpler request/response protocol.

Reference: 
https://github.com/microsoft/vscode-languageserver-node/blob/master/protocol/src/protocol.semanticTokens.proposed.ts

No attempt to support incremental formatting (yet).

Reviewers: hokein

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

Tags: #clang

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

Added: 
clang-tools-extra/clangd/test/semantic-tokens.test

Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/SemanticHighlighting.h
clang-tools-extra/clangd/test/initialize-params.test
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 9be449660eb0..310c1fec17dd 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -458,6 +458,14 @@ void ClangdLSPServer::notify(llvm::StringRef Method, 
llvm::json::Value Params) {
   Transp.notify(Method, std::move(Params));
 }
 
+static std::vector semanticTokenTypes() {
+  std::vector Types;
+  for (unsigned I = 0; I <= static_cast(HighlightingKind::LastKind);
+   ++I)
+Types.push_back(toSemanticTokenType(static_cast(I)));
+  return Types;
+}
+
 void ClangdLSPServer::onInitialize(const InitializeParams &Params,
Callback Reply) {
   // Determine character encoding first as it affects constructed ClangdServer.
@@ -569,6 +577,14 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
  // trigger on '->' and '::'.
  {"triggerCharacters", {".", ">", ":"}},
  }},
+{"semanticTokensProvider",
+ llvm::json::Object{
+ {"documentProvider", true},
+ {"rangeProvider", false},
+ {"legend",
+  llvm::json::Object{{"tokenTypes", semanticTokenTypes()},
+ {"tokenModifiers", llvm::json::Array()}}},
+ }},
 {"signatureHelpProvider",
  llvm::json::Object{
  {"triggerCharacters", {"(", ","}},
@@ -1220,6 +1236,20 @@ void ClangdLSPServer::onDocumentLink(
   });
 }
 
+void ClangdLSPServer::onSemanticTokens(const SemanticTokensParams &Params,
+   Callback CB) {
+  Server->semanticHighlights(
+  Params.textDocument.uri.file(),
+  [CB(std::move(CB))](
+  llvm::Expected> Toks) mutable {
+if (!Toks)
+  return CB(Toks.takeError());
+SemanticTokens Result;
+Result.data = toSemanticTokens(*Toks);
+CB(std::move(Result));
+  });
+}
+
 ClangdLSPServer::ClangdLSPServer(
 class Transport &Transp, const FileSystemProvider &FSProvider,
 const clangd::CodeCompleteOptions &CCOpts,
@@ -1267,6 +1297,7 @@ ClangdLSPServer::ClangdLSPServer(
   MsgHandler->bind("typeHierarchy/resolve", 
&ClangdLSPServer::onResolveTypeHierarchy);
   MsgHandler->bind("textDocument/selectionRange", 
&ClangdLSPServer::onSelectionRange);
   MsgHandler->bind("textDocument/documentLink", 
&ClangdLSPServer::onDocumentLink);
+  MsgHandler->bind("textDocument/semanticTokens", 
&ClangdLSPServer::onSemanticTokens);
   // clang-format on
 }
 

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index c4e9e5fb679c..ff67bf772b7f 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -119,6 +119,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
 Callback>);
   void onDocumentLink(const DocumentLinkParams &,
   Callback>);
+  void onSemanticTokens(const SemanticTokensParams &, 
Callback);
 
   std::vector getFixes(StringRef File, const clangd::Diagnostic &D);
 

diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index acfaa81dbf29..36af6c98d18b 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -685,6 +685,18 @@ void ClangdServer::documentLinks(PathRe

[PATCH] D77041: [AST] Fix a crash on invalid constexpr Ctorinitializer when building RecoveryExpr.

2020-03-31 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:5004
 CXXCtorInitializer *Member = Initializers[i];
-
+if (Member->getInit() && Member->getInit()->containsErrors())
+  Constructor->setInvalidDecl();

what's the case where this gets hit rather than anyerrors=true?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77041



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


[PATCH] D76831: [AST] Preserve the DeclRefExpr when it refers to an invalid decl.

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

I like the idea, but it seems to regress quite a lot of diagnostics... e.g. 
where we fail to deduce auto and then say it's not a pointer.

Also this is regressing things in the -fno-recovery-ast case, because of the 
changes to CheckDeclInExpr with the existing callsites that allow invalid 
decls. (I'm not sure what passing AcceptInvalid actually *did* before)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76831



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


[PATCH] D76663: [clangd] Support new semanticTokens request from LSP 3.16.

2020-03-31 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG71177ac16801: [clangd] Support new semanticTokens request 
from LSP 3.16. (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76663

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/test/initialize-params.test
  clang-tools-extra/clangd/test/semantic-tokens.test
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -720,6 +720,41 @@
   ASSERT_EQ(Counter.Count, 1);
 }
 
+TEST(SemanticHighlighting, toSemanticTokens) {
+  auto CreatePosition = [](int Line, int Character) -> Position {
+Position Pos;
+Pos.line = Line;
+Pos.character = Character;
+return Pos;
+  };
+
+  std::vector Tokens = {
+  {HighlightingKind::Variable,
+   Range{CreatePosition(1, 1), CreatePosition(1, 5)}},
+  {HighlightingKind::Function,
+   Range{CreatePosition(3, 4), CreatePosition(3, 7)}},
+  {HighlightingKind::Variable,
+   Range{CreatePosition(3, 8), CreatePosition(3, 12)}},
+  };
+
+  std::vector Results = toSemanticTokens(Tokens);
+  EXPECT_EQ(Tokens.size(), Results.size());
+  EXPECT_EQ(Results[0].tokenType, unsigned(HighlightingKind::Variable));
+  EXPECT_EQ(Results[0].deltaLine, 1u);
+  EXPECT_EQ(Results[0].deltaStart, 1u);
+  EXPECT_EQ(Results[0].length, 4u);
+
+  EXPECT_EQ(Results[1].tokenType, unsigned(HighlightingKind::Function));
+  EXPECT_EQ(Results[1].deltaLine, 2u);
+  EXPECT_EQ(Results[1].deltaStart, 4u);
+  EXPECT_EQ(Results[1].length, 3u);
+
+  EXPECT_EQ(Results[2].tokenType, unsigned(HighlightingKind::Variable));
+  EXPECT_EQ(Results[2].deltaLine, 0u);
+  EXPECT_EQ(Results[2].deltaStart, 4u);
+  EXPECT_EQ(Results[2].length, 4u);
+}
+
 TEST(SemanticHighlighting, toTheiaSemanticHighlightingInformation) {
   auto CreatePosition = [](int Line, int Character) -> Position {
 Position Pos;
Index: clang-tools-extra/clangd/test/semantic-tokens.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/semantic-tokens.test
@@ -0,0 +1,22 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.cpp","languageId":"cpp","text":"int x = 2;"}}}
+---
+{"jsonrpc":"2.0","id":1,"method":"textDocument/semanticTokens","params":{"textDocument":{"uri":"test:///foo.cpp"}}}
+# CHECK:   "id": 1,
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": {
+# CHECK-NEXT:"data": [
+#  First line, char 5, variable, no modifiers.
+# CHECK-NEXT:  0,
+# CHECK-NEXT:  4,
+# CHECK-NEXT:  1,
+# CHECK-NEXT:  0,
+# CHECK-NEXT:  0
+# CHECK-NEXT:]
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","id":2,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: clang-tools-extra/clangd/test/initialize-params.test
===
--- clang-tools-extra/clangd/test/initialize-params.test
+++ clang-tools-extra/clangd/test/initialize-params.test
@@ -38,6 +38,16 @@
 # CHECK-NEXT:  "referencesProvider": true,
 # CHECK-NEXT:  "renameProvider": true,
 # CHECK-NEXT:  "selectionRangeProvider": true,
+# CHECK-NEXT:  "semanticTokensProvider": {
+# CHECK-NEXT:"documentProvider": true,
+# CHECK-NEXT:"legend": {
+# CHECK-NEXT:  "tokenModifiers": [],
+# CHECK-NEXT:  "tokenTypes": [
+# CHECK-NEXT:"variable",
+# CHECK:   ]
+# CHECK-NEXT:},
+# CHECK-NEXT:"rangeProvider": false
+# CHECK-NEXT:  },
 # CHECK-NEXT:  "signatureHelpProvider": {
 # CHECK-NEXT:"triggerCharacters": [
 # CHECK-NEXT:  "(",
Index: clang-tools-extra/clangd/SemanticHighlighting.h
===
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -6,8 +6,21 @@
 //
 //===--===//
 //
-// An implementation of semantic highlighting based on this proposal:
-// https://github.com/microsoft/vscode-languageserver-node/pull/367 in clangd.
+// Thi

[PATCH] D76862: HIP: Ensure new denormal mode attributes are set

2020-03-31 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

ping


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

https://reviews.llvm.org/D76862



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


[PATCH] D77056: RFC: [Sema][SVE] Allow non-member operators for SVE types

2020-03-31 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm updated this revision to Diff 253867.
rsandifo-arm edited the summary of this revision.
rsandifo-arm added a comment.

Require operators to be defined as static or inside a namespace

Also remove redundant brackets and add more tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77056

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/sizeless-1.cpp

Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -3,6 +3,10 @@
 // RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=c++17 %s
 // RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=gnu++17 %s
 
+#if __ARM_FEATURE_SVE_NONMEMBER_OPERATORS != 1
+#error "__ARM_FEATURE_SVE_NONMEMBER_OPERATORS should be defined"
+#endif
+
 namespace std {
 struct type_info;
 }
@@ -450,7 +454,7 @@
   local_int16 = wrapper(); // expected-error {{assigning to 'svint16_t' (aka '__SVInt16_t') from incompatible type 'wrapper'}}
 
   svint8_t &ref_int8 = local_int8;
-  ref_int8 = ref_int8; // expected-warning {{explicitly assigning value of variable of type 'svint8_t' (aka '__SVInt8_t') to itself}}
+  ref_int8 = ref_int8; // expected-warning + {{explicitly assigning value of variable of type 'svint8_t' (aka '__SVInt8_t') to itself}}
   ref_int8 = local_int8;
   local_int8 = ref_int8;
 
@@ -602,3 +606,247 @@
 #if __cplusplus >= 201103L
 svint8_t ret_bad_conv() { return explicit_conv(); } // expected-error {{no viable conversion from returned value of type 'explicit_conv' to function return type 'svint8_t'}}
 #endif
+
+struct struct1 {};
+struct struct2 {};
+
+svint8_t operator()(svint8_t);// expected-error {{must be a non-static member function}}
+svint8_t operator()(svint8_t, int, int, int); // expected-error {{must be a non-static member function}}
+svint8_t operator[](svint8_t, int);   // expected-error {{must be a non-static member function}}
+svint8_t operator->(svint8_t);// expected-error {{must be a non-static member function}}
+static svint8_t operator~(svint8_t);
+namespace {
+svint8_t operator!(svint8_t);
+}
+namespace operators {
+svint8_t operator+(svint8_t); // expected-note + {{not viable}}
+svint8_t operator-(svint8_t); // expected-note + {{not viable}}
+svint8_t operator&(svint8_t &);
+svint8_t operator+(svint8_t, svint8_t);  // expected-note + {{not viable}}
+svint8_t operator-(svint8_t, int);   // expected-note + {{not viable}}
+svint8_t operator-(int, svint8_t);   // expected-note + {{not viable}}
+svint8_t operator*(svint8_t, int);   // expected-note + {{not viable}}
+svint8_t operator*(svint8_t, svint16_t); // expected-note + {{not viable}}
+svint8_t operator/(svint8_t, svint8_t);
+svint8_t operator/(svint8_t, svint16_t); // expected-note + {{not viable}}
+svint8_t operator/(svint16_t, svint8_t); // expected-note + {{not viable}}
+svint8_t operator%(svint8_t, svint8_t);
+svint8_t operator%(svint8_t, svint16_t);
+svint8_t operator%(svint16_t, svint8_t);
+svint8_t operator%(svint16_t, svint16_t);
+svint8_t operator^(svint8_t, svint8_t);
+svint8_t operator&(svint8_t, svint8_t);
+svint8_t operator|(svint8_t, svint8_t);
+svint8_t &operator=(svint8_t &, svint8_t); // expected-error {{must be a non-static member function}}
+svint8_t &operator+=(svint8_t &, int); // expected-note + {{not viable}}
+svint8_t &operator-=(svint8_t &, int);
+svint8_t &operator*=(svint8_t &, svint16_t);
+svint8_t &operator/=(svint8_t &, svint8_t);
+svint8_t &operator%=(svint8_t &, svint8_t);
+svint8_t &operator^=(svint8_t &, svint8_t);
+svint8_t &operator&=(svint8_t &, svint8_t);
+svint8_t &operator|=(svint8_t &, svint8_t);
+bool operator==(svint8_t, svint8_t);  // expected-note + {{not viable}}
+bool operator!=(svint8_t, svint16_t); // expected-note + {{not viable}}
+bool operator<(svint8_t, svint8_t);
+bool operator<(svint8_t, svint16_t);
+bool operator>(svint8_t, svint8_t);
+bool operator>(svint8_t, svint16_t);
+bool operator<=(svint8_t, svint8_t);
+bool operator>=(svint8_t, svint8_t);
+svint8_t operator<<(svint8_t, svint8_t);
+svint8_t operator<<(int, svint8_t);
+svint8_t operator>>(svint8_t, svint8_t);
+svint8_t operator>>(int, svint8_t);
+svint8_t &operator<<=(svint8_t &, svint8_t); // expected-note + {{not viable}}
+svint8_t &operator>>=(svint8_t &, int);  // expected-note + {{not viable}}
+svint8_t &operator++(svint8_t &);
+svint8_t &operator--(svint8_t &, int);
+int operator,(svint8_t, svint8_t);
+} // namespace operators
+
+svint8_t operator-(svint8_t); // expected

[PATCH] D77142: [clangd] Add a flag to turn on recovery-expr.

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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77142

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp

Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -57,6 +57,7 @@
   Inputs.Contents = Code;
   Inputs.FS = buildTestFS(Files);
   Inputs.Opts = ParseOptions();
+  Inputs.Opts.BuildRecoveryAST = true;
   Inputs.Opts.ClangTidyOpts.Checks = ClangTidyChecks;
   Inputs.Opts.ClangTidyOpts.WarningsAsErrors = ClangTidyWarningsAsErrors;
   Inputs.Index = ExternalIndex;
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -132,6 +132,16 @@
   EXPECT_DECLS("CXXOperatorCallExpr", "void operator()(int n)");
 }
 
+TEST_F(TargetDeclTest, Recovery) {
+  Code = R"cpp(
+// error-ok: testing behavior on broken code
+int f();
+int f(int, int);
+int x = [[f]](42);
+  )cpp";
+  EXPECT_DECLS("UnresolvedLookupExpr", "int f()", "int f(int, int)");
+}
+
 TEST_F(TargetDeclTest, UsingDecl) {
   Code = R"cpp(
 namespace foo {
@@ -685,6 +695,15 @@
 )cpp",
 "0: targets = {x}\n"
 "1: targets = {X::a}\n"},
+   {R"cpp(
+// error-ok: testing with broken code
+int bar();
+int foo() {
+  return $0^bar() + $1^bar(42);
+}
+)cpp",
+"0: targets = {bar}\n"
+"1: targets = {bar}\n"},
// Namespaces and aliases.
{R"cpp(
   namespace ns {}
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -281,6 +281,15 @@
 Hidden,
 };
 
+opt RecoveryAST{
+"recovery-ast",
+cat(Features),
+desc("Preserve expressions in AST for broken code. Note that "
+ "this feature is experimental and may lead to crashes"),
+init(false),
+Hidden,
+};
+
 opt WorkerThreadsCount{
 "j",
 cat(Misc),
@@ -629,6 +638,7 @@
   }
   Opts.StaticIndex = StaticIdx.get();
   Opts.AsyncThreadsCount = WorkerThreadsCount;
+  Opts.BuildRecoveryAST = RecoveryAST;
 
   clangd::CodeCompleteOptions CCOpts;
   CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -132,6 +132,8 @@
   // to read back. We rely on dynamic index for the comments instead.
   CI.getPreprocessorOpts().WriteCommentListToPCH = false;
 
+  CI.getLangOpts()->RecoveryAST = Inputs.Opts.BuildRecoveryAST;
+
   CppFilePreambleCallbacks SerializedDeclsCollector(FileName, PreambleCallback);
   if (Inputs.FS->setCurrentWorkingDirectory(Inputs.CompileCommand.Directory)) {
 log("Couldn't set working directory when building the preamble.");
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -253,6 +253,8 @@
   const PrecompiledPreamble *PreamblePCH =
   Preamble ? &Preamble->Preamble : nullptr;
 
+  CI->getLangOpts()->RecoveryAST = Opts.BuildRecoveryAST;
+
   StoreDiags ASTDiags;
   std::string Content = std::string(Buffer->getBuffer());
   std::string Filename =
Index: clang-tools-extra/clangd/Compiler.h
===
--- clang-tools-extra/clangd/Compiler.h
+++ clang-tools-extra/clangd/Compiler.h
@@ -38,6 +38,7 @@
 struct ParseOptions {
   tidy::ClangTidyOptions ClangTidyOpts;
   bool SuggestMissingIncludes = false;
+  bool BuildRecoveryAST = false;
 };
 
 /// Information required to run clang, e.g. to parse AST or do code completion.
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -118,6 +118,9 @@
 /// enabled.
 ClangTidyOptionsBuilder GetClangTidyOptions;
 
+/// If true, turn on the `-frecovery-ast` clang flag.
+bool BuildRecoveryAST = false;

[PATCH] D77041: [AST] Fix a crash on invalid constexpr Ctorinitializer when building RecoveryExpr.

2020-03-31 Thread Haojian Wu via Phabricator via cfe-commits
hokein marked an inline comment as done.
hokein added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:5004
 CXXCtorInitializer *Member = Initializers[i];
-
+if (Member->getInit() && Member->getInit()->containsErrors())
+  Constructor->setInvalidDecl();

sammccall wrote:
> what's the case where this gets hit rather than anyerrors=true?
no cases, if `Member->getInit()->containsErrors()` is true, then `anyerrors` is 
always true (this is done in `ParseDeclCXX.cpp`).

the reason why we added the check here is that we mark the constructor as 
invalid only for case `Member->getInit()->containsErrors()` (not for other 
cases leading `anyerrors` to true)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77041



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


[PATCH] D76130: [PPC][AIX] Implement variadic function handling in LowerFormalArguments_AIX

2020-03-31 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA planned changes to this revision.
ZarkoCA added a comment.

Fixing test case issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76130



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


[PATCH] D77115: [WebAssembly] Emit .llvmcmd and .llvmbc as custom sections

2020-03-31 Thread Alex Crichton via Phabricator via cfe-commits
alexcrichton added a comment.

Seems reasonable to me! In my testing though if these existed as custom 
sections they'd still make their way to the final binary through LLD, so could 
LLD skip over these sectiosn by default?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77115



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


[PATCH] D76812: [X86] Add Indirect Thunk Support to X86 to mitigate Load Value Injection (LVI) [3/3]

2020-03-31 Thread Scott Constable via Phabricator via cfe-commits
sconstab updated this revision to Diff 253888.
sconstab added a comment.

Added a comment to the header of X86IndirectThunks.cpp to indicate support for 
LVI thunks.


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

https://reviews.llvm.org/D76812

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/X86.cpp
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86IndirectThunks.cpp
  llvm/lib/Target/X86/X86Subtarget.h
  llvm/test/CodeGen/X86/lvi-hardening-indirectbr.ll

Index: llvm/test/CodeGen/X86/lvi-hardening-indirectbr.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/lvi-hardening-indirectbr.ll
@@ -0,0 +1,281 @@
+; RUN: llc -verify-machineinstrs -mtriple=x86_64-unknown -mattr=+lvi-cfi < %s | FileCheck %s --check-prefix=X64
+; RUN: llc -verify-machineinstrs -mtriple=x86_64-unknown -mattr=+lvi-cfi -O0 < %s | FileCheck %s --check-prefix=X64FAST
+;
+; Note that a lot of this code was lifted from retpoline.ll.
+
+declare void @bar(i32)
+
+; Test a simple indirect call and tail call.
+define void @icall_reg(void (i32)* %fp, i32 %x) {
+entry:
+  tail call void @bar(i32 %x)
+  tail call void %fp(i32 %x)
+  tail call void @bar(i32 %x)
+  tail call void %fp(i32 %x)
+  ret void
+}
+
+; X64-LABEL: icall_reg:
+; X64-DAG:   movq %rdi, %[[fp:[^ ]*]]
+; X64-DAG:   movl %esi, %[[x:[^ ]*]]
+; X64:   movl %esi, %edi
+; X64:   callq bar
+; X64-DAG:   movl %[[x]], %edi
+; X64-DAG:   movq %[[fp]], %r11
+; X64:   callq __llvm_lvi_thunk_r11
+; X64:   movl %[[x]], %edi
+; X64:   callq bar
+; X64-DAG:   movl %[[x]], %edi
+; X64-DAG:   movq %[[fp]], %r11
+; X64:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+
+; X64FAST-LABEL: icall_reg:
+; X64FAST:   callq bar
+; X64FAST:   callq __llvm_lvi_thunk_r11
+; X64FAST:   callq bar
+; X64FAST:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+
+
+@global_fp = external global void (i32)*
+
+; Test an indirect call through a global variable.
+define void @icall_global_fp(i32 %x, void (i32)** %fpp) #0 {
+  %fp1 = load void (i32)*, void (i32)** @global_fp
+  call void %fp1(i32 %x)
+  %fp2 = load void (i32)*, void (i32)** @global_fp
+  tail call void %fp2(i32 %x)
+  ret void
+}
+
+; X64-LABEL: icall_global_fp:
+; X64-DAG:   movl %edi, %[[x:[^ ]*]]
+; X64-DAG:   movq global_fp(%rip), %r11
+; X64:   callq __llvm_lvi_thunk_r11
+; X64-DAG:   movl %[[x]], %edi
+; X64-DAG:   movq global_fp(%rip), %r11
+; X64:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+
+; X64FAST-LABEL: icall_global_fp:
+; X64FAST:   movq global_fp(%rip), %r11
+; X64FAST:   callq __llvm_lvi_thunk_r11
+; X64FAST:   movq global_fp(%rip), %r11
+; X64FAST:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+
+
+%struct.Foo = type { void (%struct.Foo*)** }
+
+; Test an indirect call through a vtable.
+define void @vcall(%struct.Foo* %obj) #0 {
+  %vptr_field = getelementptr %struct.Foo, %struct.Foo* %obj, i32 0, i32 0
+  %vptr = load void (%struct.Foo*)**, void (%struct.Foo*)*** %vptr_field
+  %vslot = getelementptr void(%struct.Foo*)*, void(%struct.Foo*)** %vptr, i32 1
+  %fp = load void(%struct.Foo*)*, void(%struct.Foo*)** %vslot
+  tail call void %fp(%struct.Foo* %obj)
+  tail call void %fp(%struct.Foo* %obj)
+  ret void
+}
+
+; X64-LABEL: vcall:
+; X64:   movq %rdi, %[[obj:[^ ]*]]
+; X64:   movq (%rdi), %[[vptr:[^ ]*]]
+; X64:   movq 8(%[[vptr]]), %[[fp:[^ ]*]]
+; X64:   movq %[[fp]], %r11
+; X64:   callq __llvm_lvi_thunk_r11
+; X64-DAG:   movq %[[obj]], %rdi
+; X64-DAG:   movq %[[fp]], %r11
+; X64:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+
+; X64FAST-LABEL: vcall:
+; X64FAST:   callq __llvm_lvi_thunk_r11
+; X64FAST:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+
+
+declare void @direct_callee()
+
+define void @direct_tail() #0 {
+  tail call void @direct_callee()
+  ret void
+}
+
+; X64-LABEL: direct_tail:
+; X64:   jmp direct_callee # TAILCALL
+; X64FAST-LABEL: direct_tail:
+; X64FAST:   jmp direct_callee # TAILCALL
+
+
+declare void @nonlazybind_callee() #1
+
+define void @nonlazybind_caller() #0 {
+  call void @nonlazybind_callee()
+  tail call void @nonlazybind_callee()
+  ret void
+}
+
+; X64-LABEL: nonlazybind_caller:
+; X64:   movq nonlazybind_callee@GOTPCREL(%rip), %[[REG:.*]]
+; X64:   movq %[[REG]], %r11
+; X64:   callq __llvm_lvi_thunk_r11
+; X64:   movq %[[REG]], %r11
+; X64:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+; X64FAST-LABEL: nonlazybind_caller:
+; X64FAST:   movq nonlazybind_callee@GOTPCREL(%rip), %r11
+; X64FAST:   callq __llvm_lvi_thunk_r11
+; X64FAST:   movq nonlazybind_callee@GOTPCREL(%rip), %r11
+; X64FAST:   jmp __llvm_lvi_thunk_r11 # TAILCALL
+
+
+; Check that a switch gets lowered using a jump table
+define void @switch_jumptable(i32* %ptr, i64* %sink) #0 {
+; X64-LABEL: switch_jumptable:
+; X64_NOT:  jmpq *
+entry:
+  br label %header
+
+header:
+  %i = load volatile i32, i32* %p

[PATCH] D15469: Expose cxx constructor and method properties through libclang and python bindings.

2020-03-31 Thread Alberto Mardegan via Phabricator via cfe-commits
mardy added a comment.

In D15469#396582 , @jbcoe wrote:

> I'll submit a new patch for `isDeleted` on its own. The rest of this patch 
> seems uncontentious.
>
> I hope to find time this week to make the changes.


Was the patch for isDeleted ever submitted? If not, I can try to get my hands 
dirty with it :-)


Repository:
  rL LLVM

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

https://reviews.llvm.org/D15469



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


[PATCH] D77148: [analyzer] ApiModeling: Add buffer size arg constraint with multiplier involved

2020-03-31 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: Szelethus, NoQ, steakhal.
Herald added subscribers: cfe-commits, ASDenysPetrov, Charusso, gamesh411, 
dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
baloghadamsoftware, xazax.hun, whisperity.
Herald added a project: clang.
martong added a parent revision: D77066: [analyzer] ApiModeling: Add buffer 
size arg constraint.

Further develop the buffer size argumentum constraint so it can handle sizes
that we can get by multiplying two variables.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77148

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

Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -141,3 +141,27 @@
   // bugpath-note{{TRUE}} \
   // bugpath-note{{'s' is <= 2}}
 }
+int __buf_size_arg_constraint_mul(const void *, size_t, size_t);
+void test_buf_size_concrete_with_multiplication() {
+  short buf[3]; // bugpath-note{{'buf' initialized here}}
+  __buf_size_arg_constraint_mul(buf, 4, sizeof(short)); // \
+  // report-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-note{{Function argument constraint is not satisfied}}
+}
+void test_buf_size_symbolic_with_multiplication(size_t s) {
+  short buf[3];
+  __buf_size_arg_constraint_mul(buf, s, sizeof(short));
+  clang_analyzer_eval(s * sizeof(short) <= 6); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}}
+}
+void test_buf_size_symbolic_and_offset_with_multiplication(size_t s) {
+  short buf[3];
+  __buf_size_arg_constraint_mul(buf + 1, s, sizeof(short));
+  clang_analyzer_eval(s * sizeof(short) <= 4); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -212,9 +212,16 @@
   // Represents a buffer argument with an additional size argument.
   // E.g. the first two arguments here:
   //   ctime_s(char *buffer, rsize_t bufsz, const time_t *time);
+  // Another example:
+  //   size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
+  //   // Here, ptr is the buffer, and its minimum size is `size * nmemb`.
   class BufferSizeConstraint : public ValueConstraint {
 // The argument which holds the size of the buffer.
 ArgNo SizeArgN;
+// The argument which is a multiplier to size. This is set in case of
+// `fread` like functions where the size is computed as a multiplication of
+// two arguments.
+llvm::Optional SizeMultiplierArgN;
 // The operator we use in apply. This is negated in negate().
 BinaryOperator::Opcode Op = BO_LE;
 
@@ -222,17 +229,27 @@
 BufferSizeConstraint(ArgNo BufArgN, ArgNo SizeArgN)
 : ValueConstraint(BufArgN), SizeArgN(SizeArgN) {}
 
+BufferSizeConstraint(ArgNo BufArgN, ArgNo SizeArgN, ArgNo SizeMulArgN)
+: ValueConstraint(BufArgN), SizeArgN(SizeArgN),
+  SizeMultiplierArgN(SizeMulArgN) {}
+
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
   const Summary &Summary,
   CheckerContext &C) const override {
+  SValBuilder &SvalBuilder = C.getSValBuilder();
   // The buffer argument.
   SVal BufV = getArgSVal(Call, getArgNo());
   // The size argument.
   SVal SizeV = getArgSVal(Call, SizeArgN);
+  // Multiply with another argument if given.
+  if (SizeMultiplierArgN) {
+SVal SizeMulV = getArgSVal(Call, *SizeMultiplierArgN);
+SizeV = SvalBuilder.evalBinOp(State, BO_Mul, SizeV, SizeMulV,
+  Summary.getArgType(SizeArgN));
+  }
   // The dynamic size of the buffer argument, got from the analyzer engine.
   SVal BufDynSize = getBufferDynamicSize(BufV, State, C);
 
-  SValBuilder &SvalBuilder = C.getSValBuilder();
   SVal Feasible = SvalBuilder.evalBinOp(State, Op, SizeV, BufDynSize,
 SvalBuilder.getContext().BoolTy);
   if (auto F = Feasible.getAs())
@@ -739,8 +756,8 @@
   IntRangeVector Ranges) {
 return std::make_shared(ArgN, Kind, Ranges);
   };
-  auto BufferSize = [](ArgNo BufArgN, ArgNo SizeArgN) {
-return std::make_shared(BufArgN, SizeArgN);
+  auto BufferSize = [](auto ...Args) {
+return std::make_shared(Args...);
   };
   struct {
 auto ope

[PATCH] D74387: [SYCL] Defer __float128 type usage diagnostics

2020-03-31 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 253910.
Fznamznon added a comment.

Apply comments, rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74387

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/CMakeLists.txt
  clang/lib/Sema/SemaAvailability.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaSYCL.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaSYCL/float128.cpp

Index: clang/test/SemaSYCL/float128.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/float128.cpp
@@ -0,0 +1,95 @@
+// RUN: %clang_cc1 -triple spir64 -fsycl -fsycl-is-device -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsycl -fsycl-is-device -fsyntax-only %s
+
+template 
+class Z {
+public:
+  // TODO: If T is __float128 This might be a problem
+  T field;
+  // expected-note@+1 2{{declaration is unavailable because it uses type '__float128' that is not supported on this target}}
+  __float128 field1;
+};
+
+void host_ok(void) {
+  __float128 A;
+  int B = sizeof(__float128);
+  Z<__float128> C;
+  C.field1 = A;
+}
+
+void usage() {
+  // expected-error@+2 {{'__float128' is not supported on this target}}
+  // expected-note@+1 4{{declaration is unavailable because it uses type '__float128' that is not supported on this target}}
+  __float128 A;
+  Z<__float128> C;
+  // expected-error@+2 {{'A' is unavailable}}
+  // expected-error@+1 {{'field1' is unavailable}}
+  C.field1 = A;
+  // expected-error@+1 {{'A' is unavailable}}
+  decltype(A) D;
+
+  // expected-error@+1 {{'A' is unavailable}}
+  auto foo1 = [=]() {
+// expected-error@+1 {{'__float128' is not supported on this target}}
+__float128 AA;
+// expected-error@+1 {{'A' is unavailable}}
+auto BB = A;
+BB += 1;
+  };
+
+  // expected-note@+1 {{called by 'usage'}}
+  foo1();
+}
+
+template 
+void foo2(){};
+
+// expected-note@+1 {{declaration is unavailable because it uses type '__float128 (__float128)' that is not supported on this target}}
+__float128 foo(__float128 P) { return P; }
+
+template 
+__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
+  // expected-note@+1 5{{called by 'kernel}}
+  kernelFunc();
+  // expected-error@+1 {{'__float128' is not supported on this target}}
+  __float128 A;
+}
+
+int main() {
+  // expected-note@+1 2{{declaration is unavailable because it uses type '__float128' that is not supported on this target}}
+  __float128 CapturedToDevice = 1;
+  host_ok();
+  kernel([=]() {
+// expected-error@+1 {{'CapturedToDevice' is unavailable}}
+decltype(CapturedToDevice) D;
+// expected-error@+1 {{'CapturedToDevice' is unavailable}}
+auto C = CapturedToDevice;
+// expected-error@+1 {{'__float128' is not supported on this target}}
+__float128 ;
+Z<__float128> S;
+// expected-error@+1 {{'field1' is unavailable}}
+S.field1 += 1;
+S.field = 1;
+  });
+
+  kernel([=]() {
+// expected-note@+1 2{{called by 'operator()'}}
+usage();
+// expected-error@+2 {{'__float128' is not supported on this target}}
+// expected-note@+1 {{declaration is unavailable because it uses type '__float128' that is not supported on this target}}
+__float128 ;
+// expected-error@+2 {{'' is unavailable}}
+// expected-error@+1 {{'foo' is unavailable}}
+auto A = foo();
+  });
+
+  kernel([=]() {
+Z<__float128> S;
+foo2<__float128>();
+// TODO: this shouldn't be diagnosed
+// expected-error@+1 {{'__float128' is not supported on this target}}
+int E = sizeof(__float128);
+  });
+
+  return 0;
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -1517,10 +1517,21 @@
 break;
   case DeclSpec::TST_float128:
 if (!S.Context.getTargetInfo().hasFloat128Type() &&
+!S.getLangOpts().SYCLIsDevice &&
 !(S.getLangOpts().OpenMP && S.getLangOpts().OpenMPIsDevice))
   S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
 << "__float128";
 Result = Context.Float128Ty;
+if (!S.Context.getTargetInfo().hasFloat128Type() &&
+S.getLangOpts().SYCLIsDevice &&
+S.DelayedDiagnostics.shouldDelayDiagnostics()) {
+  S.DelayedDiagnostics.add(sema::DelayedDiagnostic::makeForbiddenType(
+  DS.getTypeSpecTypeLoc(), diag::err_type_unsupported, Result,
+  /*ignored*/ 0));
+  S.SYCLDiagIfDeviceCode(DS.getTypeSpecTypeLoc(),
+ diag::err_type_unsupported)
+  << Result;
+}
 break;
   case DeclSpec::TST_bool: Result = Context.BoolTy; break; // _Bool or bool
 break;
Index: clang/lib/Sem

[PATCH] D77150: [Analyzer] New Option for ContainerModeling: AggressiveEraseModeling

2020-03-31 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added reviewers: NoQ, Szelethus.
baloghadamsoftware added a project: clang.
Herald added subscribers: ASDenysPetrov, martong, steakhal, Charusso, 
gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
xazax.hun, whisperity.

A typical (bad) algorithm for erasing elements of a list is the following:

  for(auto i = L.begin(); i != L.end(); ++i) {
 if (condition(*i))
   i = L.erase(i);
  }

If `condition()` returns true for the last element, then `erase()` returns the 
past-the-end iterator which the loop tries to increment which leads to 
undefined behavior. However, the iterator range checker does not find this bug 
because the "loop iteration before that last iteration" cannot be recognized by 
the analyzer. Instead we added an option in this patch to `ContainerModeling` 
which enables the modeling checker to assume after every erase that the result 
is the past-the-end iterator (if this case is possible).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77150

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  clang/test/Analysis/analyzer-config.c

Index: clang/test/Analysis/analyzer-config.c
===
--- clang/test/Analysis/analyzer-config.c
+++ clang/test/Analysis/analyzer-config.c
@@ -7,6 +7,7 @@
 // CHECK-NEXT: alpha.clone.CloneChecker:IgnoredFilesPattern = ""
 // CHECK-NEXT: alpha.clone.CloneChecker:MinimumCloneComplexity = 50
 // CHECK-NEXT: alpha.clone.CloneChecker:ReportNormalClones = true
+// CHECK-NEXT: alpha.cplusplus.ContainerModeling:AggressiveEraseModeling = false
 // CHECK-NEXT: alpha.cplusplus.STLAlgorithmModeling:AggressiveStdFindModeling = false
 // CHECK-NEXT: alpha.security.MmapWriteExec:MmapProtExec = 0x04
 // CHECK-NEXT: alpha.security.MmapWriteExec:MmapProtRead = 0x01
@@ -100,4 +101,4 @@
 // CHECK-NEXT: unroll-loops = false
 // CHECK-NEXT: widen-loops = false
 // CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 97
+// CHECK-NEXT: num-entries = 98
Index: clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
@@ -65,6 +65,8 @@
 public:
   ContainerModeling() = default;
 
+  DefaultBool AggressiveEraseModeling;
+
   void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
   void checkLiveSymbols(ProgramStateRef State, SymbolReaper &SR) const;
   void checkDeadSymbols(SymbolReaper &SR, CheckerContext &C) const;
@@ -606,7 +608,7 @@
   auto RetPos =
 IteratorPosition::getPosition(Pos->getContainer(), Pos->getOffset());
   State = setIteratorPosition(State, RetVal, RetPos);
-  
+
   C.addTransition(State);
 }
 
@@ -632,7 +634,7 @@
   SymMgr.getType(Pos->getOffset())).getAsSymbol();
   auto RetPos = IteratorPosition::getPosition(Pos->getContainer(), RetOffset);
   State = setIteratorPosition(State, RetVal, RetPos);
-  
+
   C.addTransition(State);
 }
 
@@ -677,7 +679,29 @@
   SymMgr.getType(Pos->getOffset())).getAsSymbol();
   auto RetPos = IteratorPosition::getPosition(Pos->getContainer(), RetOffset);
   State = setIteratorPosition(State, RetVal, RetPos);
-  
+
+  if (AggressiveEraseModeling) {
+if (const auto *CData = getContainerData(State, ContReg)) {
+  if (const SymbolRef EndSym = CData->getEnd()) {
+const auto RetEnd =
+  SVB.evalBinOp(State, BO_EQ, nonloc::SymbolVal(RetOffset),
+nonloc::SymbolVal(EndSym), SVB.getConditionType())
+  .getAs();
+if (RetEnd) {
+  ProgramStateRef StateEnd, StateNotEnd;
+  std::tie(StateEnd, StateNotEnd) = State->assume(*RetEnd);
+  if (StateEnd) {
+C.addTransition(StateEnd);
+  }
+  if (StateNotEnd) {
+C.addTransition(StateNotEnd);
+  }
+  return;
+}
+  }
+}
+  }
+
   C.addTransition(State);
 }
 
@@ -725,6 +749,11 @@
 
 void ContainerModeling::handleEraseAfter(CheckerContext &C, SVal Cont,
  SVal Iter, SVal RetVal) const {
+  const auto *ContReg = Cont.getAsRegion();
+  if (!ContReg)
+return;
+
+  ContReg = ContReg->getMostDerivedObjectRegion();
   auto State = C.getState();
   const auto *Pos = getIteratorPosition(State, Iter);
   if (!Pos)
@@ -748,6 +777,28 @@
   auto RetPos = IteratorPosition::getPosition(Pos->getContainer(), RetOffset);
   State = setIteratorPosition(State, RetVal, RetPos);
 
+  if (AggressiveEraseModeling) {
+if (const auto *CData = getContainerData(State, ContReg)) {
+  if (const SymbolRef EndSym = CData->getEnd()) {
+const auto RetEnd =
+  SVB.evalBinOp(State, BO_EQ, nonloc::SymbolVal(RetOffset),
+nonloc::Symb

[PATCH] D76725: [clangd] Build ASTs only with fresh preambles or after building a new preamble

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

Had some discussion offline.

- having ASTWorker not worry about preamble validity before dispatching to 
preambleworker seems like a win
- for this, preambleworker needs to call preambleReady whether it's new or not, 
so ASTWorker can produce diagnostics
- AST reuse from diagnostics->request seems much more useful than the other way 
around (e.g. it reduces request latency), so don't bother with the latter. (And 
we can drop diagnostic computation in some cases)

This yields pseudocode like:

  ASTWorker::update(): enqueue({
currentInputs = inputs
preambleworker::update(inputs)
  })
  ASTWorker::runWithAST(): enqueue({
ast = cache.get()
if (!ast) patch preamble and build ast
action(ast)
cache.put(ast)
  })
  PreambleWorker::update(): enqueue({
if (!preamble.compatible(inputs))
  build preamble
ASTWorker::preambleReady(preamble)
  })
  ASTWorker::preambleReady(): enqueue({
preamble = p
build ast
publish ast.diagnostics
if (inputs == currentInputs) cache.put(ast)
else if (preamble != oldPreamble) cache.get() // force next read to use 
this preamble
  })

(I'm not sure how simple the actual code can be. I do think defining the 
methods in that order may help readability)




Comment at: clang-tools-extra/clangd/TUScheduler.cpp:8
 
//===--===//
-// For each file, managed by TUScheduler, we create a single ASTWorker that
-// manages an AST for that file. All operations that modify or read the AST are
-// run on a separate dedicated thread asynchronously in FIFO order.
+// TUScheduler stores a worker per active file. This worker is called ASTWorker
+// and manages updates(modifications to file contents) and reads(actions

nit: just "This ASTWorker manages updates..."



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:8
 
//===--===//
-// For each file, managed by TUScheduler, we create a single ASTWorker that
-// manages an AST for that file. All operations that modify or read the AST are
-// run on a separate dedicated thread asynchronously in FIFO order.
+// TUScheduler stores a worker per active file. This worker is called ASTWorker
+// and manages updates(modifications to file contents) and reads(actions

sammccall wrote:
> nit: just "This ASTWorker manages updates..."
uber-nit: I'd say the scheduler *manages* workers and the worker *processes* 
updates.
(Just to avoid mixing metaphors)



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:9
+// TUScheduler stores a worker per active file. This worker is called ASTWorker
+// and manages updates(modifications to file contents) and reads(actions
+// performed on preamble/AST) to the file.

nit: space before open parens (not a big deal, but occurs several times)



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:16
 //
-// The processing thread of the ASTWorker is also responsible for building the
-// preamble. However, unlike AST, the same preamble can be read concurrently, 
so
-// we run each of async preamble reads on its own thread.
+// An update request changes latest inputs to ensure any subsequent read sees
+// the version of the file they were requested. In addition to that it might

changes latest inputs -> replaces the current parser inputs

("changes" suggests some tricky mutation, and inputs isn't defined here)



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:17
+// An update request changes latest inputs to ensure any subsequent read sees
+// the version of the file they were requested. In addition to that it might
+// result in publishing diagnostics.

You need to mention "building an AST" here, as you reference it below.



Comment at: clang-tools-extra/clangd/TUScheduler.cpp:25
 //
-// Rationale for cancelling updates.
-// LSP clients can send updates to clangd on each keystroke. Some files take
-// significant time to parse (e.g. a few seconds) and clangd can get starved by
-// the updates to those files. Therefore we try to process only the last 
update,
-// if possible.
-// Our current strategy to do that is the following:
-// - For each update we immediately schedule rebuild of the AST.
-// - Rebuild of the AST checks if it was cancelled before doing any actual 
work.
-//   If it was, it does not do an actual rebuild, only reports llvm::None to 
the
-//   callback
-// - When adding an update, we cancel the last update in the queue if it didn't
-//   have any reads.
-// There is probably a optimal ways to do that. One approach we might take is
-// the following:
-// - For each update we remember the pending inputs, but delay rebuild of the
-//   AST for some timeout.
-// - If subsequent updates come before rebuild was started, we repl

[PATCH] D74387: [SYCL] Defer __float128 type usage diagnostics

2020-03-31 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon marked an inline comment as done.
Fznamznon added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:12248
+  ///   SYCLDiagIfDeviceCode(Loc, diag::err_type_unsupported) << "__float128";
+  DeviceDiagBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, unsigned DiagID);
+

rjmccall wrote:
> Fznamznon wrote:
> > rjmccall wrote:
> > > Will this collect notes associated with the diagnostic correctly?
> > Could you please make your question a bit more concrete?
> > This function is supposed to work in the same way as 
> > `Sema::CUDADiagIfDeviceCode` and `Sema::diagIfOpenMPDeviceCode` . It emits 
> > given diagnostic if the current context is known as "device code" and makes 
> > this diagnostic deferred otherwise. It uses the `DeviceDiagBuilder` which 
> > was implemented earlier. This `DeviceDiagBuilder` also tries to emit 
> > callstack notes for the given diagnostics. Do you mean these callstack 
> > notes or something else?
> Logically, notes that are emitted after a warning or error are considered to 
> be part of that diagnostic.  A custom `DiagBuilder` that only redirects the 
> main diagnostic but allows the notes to still be emitted will effectively 
> cause those notes to misleadingly follow whatever previous diagnostic might 
> have been emitted.
> 
> I call this out specifically because some of the places where you're using 
> this still seem to try to emit notes afterwards, at least in some cases.  
> It's possible that `CUDADiagIfDeviceCode` happens to not be used in such a 
> way.  Really I'm not sure this conditional `DiagBuilder` approach was a good 
> idea the first time, and I think we should probably reconsider rather than 
> duplicating it.
I think if there are some notes associated with the main diagnostic and we want 
to make this diagnostic deferred by using `SYCLDiagIfDeviceCode`, we have to 
use this function `SYCLDiagIfDeviceCode` for notes as well. In my changes I 
didn't do so because I didn't expect notes emitted after new diagnostic.
In our SYCL implementation we find function like `SYCLDiagIfDeviceCode` pretty 
useful because we don't know where is device code until templates are 
instantiated. We need some mechanism to defer diagnostics pointing to 
unsupported features used in device code.
Do you have better approach in mind?



Comment at: clang/lib/Sema/SemaAvailability.cpp:479
+case UnavailableAttr::IR_SYCLForbiddenType:
+  diag_available_here = diag::err_type_unsupported;
+  break;

rjmccall wrote:
> Fznamznon wrote:
> > rjmccall wrote:
> > > All of the other cases are setting this to a note, not an error, so I 
> > > suspect this will read wrong.
> > Yes, this is not a note. For such samples:
> > 
> > ```
> > int main() {
> >   __float128 CapturedToDevice = 1;
> >   kernel([=]() {
> > decltype(CapturedToDevice) D;
> >   });
> > }
> > ```
> > It looks like this:
> > ```
> > float128.cpp:63:14: error: 'CapturedToDevice' is unavailable
> > decltype(CapturedToDevice) D;
> >  ^
> > float128.cpp:59:14: error: '__float128' is not supported on this target   
> > /// This emitted instead of note 
> >   __float128 CapturedToDevice = 1;
> >  ^
> > ```
> > I had feeling that it should probably be a note. But there is no 
> > implemented note for unsupported types. I think I can add a new one if it 
> > will make it better. Should I?
> Yeah, this should be a note, like "note: variable is unavailable because it 
> uses a type '__float128' that is not supported on this target".  You should 
> add that.
Okay, done.



Comment at: clang/lib/Sema/SemaAvailability.cpp:534
+if (S.getLangOpts().SYCLIsDevice)
+  S.SYCLDiagIfDeviceCode(Loc, diag) << ReferringDecl;
+else

rjmccall wrote:
> Fznamznon wrote:
> > rjmccall wrote:
> > > Are you sure you want to be applying this to all of the possible 
> > > diagnostics here, rather than just for SYCLForbiddenType unavailable 
> > > attributes?
> > I suppose it is reasonable if we want to reuse unavaliable attribute for 
> > other SYCL use cases. Plus, In SYCL we don't know where is device code 
> > until we instantiate templates, it happens late, so we have to defer any 
> > diagnostic while compiling for device, otherwise we can point to host code 
> > where much more is allowed.
> My point is actually the reverse of that.  This code path is also used for 
> normal `unavailable` attributes, not just the special ones you're 
> synthesizing.  Diagnostics from the use of explicitly-unavailable 
> declarations shouldn't get any special treatment here, no more than you'd 
> give special treatment to a diagnostic arising from an attempt to assign a 
> pointer into a `float`.  In the logic above where you recognize 
> `IR_SYCLForbiddenType`, I think you should just check whether you should 
> transitively defer the diagnostic and, if so, do so and then bail out of this 
> fun

[PATCH] D77125: [Analyzer] Model return values of container insert and delete operations

2020-03-31 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

It seems like we could model here `emplace` and `emplace_after` exactly the 
same way we do with `insert` and `insert_after`, couldn't we? Perhaps that 
could go into this patch too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77125



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


[clang] a76e68c - [CodeComplete] Member completion for concept-constrained types.

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

Author: Sam McCall
Date: 2020-03-31T18:43:24+02:00
New Revision: a76e68c9704fb5b3faf25bb8d51e405b5310ff08

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

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

Summary:
The basic idea is to walk through the concept definition, looking for
t.foo() where t has the constrained type.

In this patch:
 - nested types are recognized and offered after ::
 - variable/function members are recognized and offered after the correct
   dot/arrow/colon trigger
 - member functions are recognized (anything directly called). parameter
   types are presumed to be the argument types. parameters are unnamed.
 - result types are available when a requirement has a type constraint.
   These are printed as constraints, except same_as which prints as T.

Not in this patch:
 - support for merging/overloading when two locations describe the same member.
   The last one wins, for any given name. This is probably important...
 - support for nested template members (T::x)
 - support for completing members of (instantiations of) template template 
parameters

Reviewers: nridge, saar.raz

Subscribers: mgrang, cfe-commits

Tags: #clang

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

Added: 
clang/test/CodeCompletion/concepts.cpp

Modified: 
clang/include/clang/Sema/Scope.h
clang/lib/Sema/CodeCompleteConsumer.cpp
clang/lib/Sema/SemaCodeComplete.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Scope.h 
b/clang/include/clang/Sema/Scope.h
index 6133425a42a6..169ca175eed2 100644
--- a/clang/include/clang/Sema/Scope.h
+++ b/clang/include/clang/Sema/Scope.h
@@ -320,9 +320,7 @@ class Scope {
 
   /// isDeclScope - Return true if this is the scope that the specified decl is
   /// declared in.
-  bool isDeclScope(Decl *D) {
-return DeclsInScope.count(D) != 0;
-  }
+  bool isDeclScope(const Decl *D) const { return DeclsInScope.count(D) != 0; }
 
   DeclContext *getEntity() const { return Entity; }
   void setEntity(DeclContext *E) { Entity = E; }

diff  --git a/clang/lib/Sema/CodeCompleteConsumer.cpp 
b/clang/lib/Sema/CodeCompleteConsumer.cpp
index b88ff9dd64cd..2402d896faac 100644
--- a/clang/lib/Sema/CodeCompleteConsumer.cpp
+++ b/clang/lib/Sema/CodeCompleteConsumer.cpp
@@ -570,29 +570,10 @@ void 
PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(
 if (const char *BriefComment = CCS->getBriefComment())
   OS << " : " << BriefComment;
   }
-  for (const FixItHint &FixIt : Results[I].FixIts) {
-const SourceLocation BLoc = FixIt.RemoveRange.getBegin();
-const SourceLocation ELoc = FixIt.RemoveRange.getEnd();
-
-SourceManager &SM = SemaRef.SourceMgr;
-std::pair BInfo = SM.getDecomposedLoc(BLoc);
-std::pair EInfo = SM.getDecomposedLoc(ELoc);
-// Adjust for token ranges.
-if (FixIt.RemoveRange.isTokenRange())
-  EInfo.second += Lexer::MeasureTokenLength(ELoc, SM, 
SemaRef.LangOpts);
-
-OS << " (requires fix-it:"
-   << " {" << SM.getLineNumber(BInfo.first, BInfo.second) << ':'
-   << SM.getColumnNumber(BInfo.first, BInfo.second) << '-'
-   << SM.getLineNumber(EInfo.first, EInfo.second) << ':'
-   << SM.getColumnNumber(EInfo.first, EInfo.second) << "}"
-   << " to \"" << FixIt.CodeToInsert << "\")";
-  }
-  OS << '\n';
   break;
 
 case CodeCompletionResult::RK_Keyword:
-  OS << Results[I].Keyword << '\n';
+  OS << Results[I].Keyword;
   break;
 
 case CodeCompletionResult::RK_Macro:
@@ -602,13 +583,31 @@ void 
PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(
   includeBriefComments())) {
 OS << " : " << CCS->getAsString();
   }
-  OS << '\n';
   break;
 
 case CodeCompletionResult::RK_Pattern:
-  OS << "Pattern : " << Results[I].Pattern->getAsString() << '\n';
+  OS << "Pattern : " << Results[I].Pattern->getAsString();
   break;
 }
+for (const FixItHint &FixIt : Results[I].FixIts) {
+  const SourceLocation BLoc = FixIt.RemoveRange.getBegin();
+  const SourceLocation ELoc = FixIt.RemoveRange.getEnd();
+
+  SourceManager &SM = SemaRef.SourceMgr;
+  std::pair BInfo = SM.getDecomposedLoc(BLoc);
+  std::pair EInfo = SM.getDecomposedLoc(ELoc);
+  // Adjust for token ranges.
+  if (FixIt.RemoveRange.isTokenRange())
+EInfo.second += Lexer::MeasureTokenLength(ELoc, SM, SemaRef.LangOpts);
+
+  OS << " (requires fix-it:"
+ << " {" << SM.getLineNumber(BInfo.first, BInfo.second) << ':'
+ << SM.getColumnNumber(BInfo.first, BInfo.second) << '-'
+ << SM.getLineNumber(EInfo.first, EInfo.second) << ':'
+ << SM.getColumnNumber(EInfo.first, EIn

[PATCH] D77142: [clangd] Add a flag to turn on recovery-expr.

2020-03-31 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/Preamble.cpp:135
 
+  CI.getLangOpts()->RecoveryAST = Inputs.Opts.BuildRecoveryAST;
+

There's no prospect of this working for C at the moment. We should make this 
conditional on C++ (and mention C++ in the desc)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77142



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


[PATCH] D76432: [clangd] Add a tweak for adding "using" statement.

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

Still LG, should I land this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76432



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


[PATCH] D77103: Add a new -fglobal-isel option and make -fexperimental-isel an alias for it.

2020-03-31 Thread Daniel Sanders via Phabricator via cfe-commits
dsanders accepted this revision.
dsanders 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/D77103/new/

https://reviews.llvm.org/D77103



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


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

2020-03-31 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa76e68c9704f: [CodeComplete] Member completion for 
concept-constrained types. (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73649

Files:
  clang/include/clang/Sema/Scope.h
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/concepts.cpp

Index: clang/test/CodeCompletion/concepts.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/concepts.cpp
@@ -0,0 +1,59 @@
+template  concept convertible_to = true;
+template  concept same_as = true;
+template  concept integral = true;
+
+template 
+concept W = requires(A a, B b) {
+  { b.www } noexcept -> integral;
+};
+
+template  concept X = requires(T t) {
+  t.xxx(42);
+  typename T::xxx_t;
+  T::xyz::member;
+};
+
+template 
+concept Y = requires(T t, U u) { t.yyy(u); };
+
+template 
+concept Z = requires(T t) {
+  { t.zzz() } -> same_as;
+  requires W;
+};
+
+// Concept constraints in all three slots require X, Y, Z, and ad-hoc stuff.
+template 
+requires Y && requires(T *t) { { t->aaa() } -> convertible_to; }
+void foo(T t) requires Z || requires(T &t) { t.bbb(); t->bb(); } {
+  t.x;
+  t->x;
+  T::x;
+
+  // RUN: %clang_cc1 -std=c++2a -code-completion-with-fixits -code-completion-at=%s:29:5 %s \
+  // RUN: | FileCheck %s -check-prefix=DOT -implicit-check-not=xxx_t
+  // DOT: Pattern : [#convertible_to#]aaa()
+  // DOT: Pattern : bb() (requires fix-it: {{.*}} to "->")
+  // DOT: Pattern : bbb()
+  // DOT: Pattern : [#integral#]www
+  // DOT: Pattern : xxx(<#int#>)
+  // FIXME: it would be nice to have int instead of U here.
+  // DOT: Pattern : yyy(<#U#>)
+  // DOT: Pattern : [#int#]zzz()
+
+  // RUN: %clang_cc1 -std=c++2a -code-completion-with-fixits -code-completion-at=%s:30:6 %s \
+  // RUN: | FileCheck %s -check-prefix=ARROW -implicit-check-not=xxx_t
+  // ARROW: Pattern : [#convertible_to#]aaa() (requires fix-it: {{.*}} to ".")
+  // ARROW: Pattern : bb()
+  // ARROW: Pattern : bbb() (requires fix-it
+  // ARROW: Pattern : [#integral#]www (requires fix-it
+  // ARROW: Pattern : xxx(<#int#>) (requires fix-it
+  // ARROW: Pattern : yyy(<#U#>) (requires fix-it
+  // ARROW: Pattern : [#int#]zzz() (requires fix-it
+
+  // RUN: %clang_cc1 -std=c++2a -code-completion-with-fixits -code-completion-at=%s:31:6 %s \
+  // RUN: | FileCheck %s -check-prefix=COLONS -implicit-check-not=yyy
+  // COLONS: Pattern : xxx_t
+  // COLONS: Pattern : xyz
+}
+
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -9,6 +9,7 @@
 //  This file defines the code-completion semantic actions.
 //
 //===--===//
+#include "clang/AST/ASTConcept.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
@@ -16,8 +17,11 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
 #include "clang/AST/ExprObjC.h"
+#include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/QualTypeNames.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/Specifiers.h"
@@ -4746,6 +4750,369 @@
   return nullptr;
 }
 
+namespace {
+// Collects completion-relevant information about a concept-constrainted type T.
+// In particular, examines the constraint expressions to find members of T.
+//
+// The design is very simple: we walk down each constraint looking for
+// expressions of the form T.foo().
+// If we're extra lucky, the return type is specified.
+// We don't do any clever handling of && or || in constraint expressions, we
+// take members from both branches.
+//
+// For example, given:
+//   template  concept X = requires (T t, string& s) { t.print(s); };
+//   template  void foo(U u) { u.^ }
+// We want to suggest the inferred member function 'print(string)'.
+// We see that u has type U, so X holds.
+// X requires t.print(s) to be valid, where t has type U (substituted for T).
+// By looking at the CallExpr we find the signature of print().
+//
+// While we tend to know in advance which kind of members (access via . -> ::)
+// we want, it's simpler just to gather them all and post-filter.
+//
+// FIXME: some of this machinery could be used for non-concept type-parms too,
+// enabling completion for type parameters based on other uses of that param.
+//
+// FIXME: there are other cases where a type can be constrained by a concept,
+// e.g. inside `if constexpr(ConceptSpecializationExpr) { ... }`
+class ConceptInfo {
+public:
+  // Describes a likely member of a type, inferred by concept 

[clang] 753a324 - Make FunctionDecl::isDefined non-virtual, NFC

2020-03-31 Thread Reid Kleckner via cfe-commits

Author: Reid Kleckner
Date: 2020-03-31T10:12:05-07:00
New Revision: 753a3245f7231ffd86b8af02e57da6ceb2ec5669

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

LOG: Make FunctionDecl::isDefined non-virtual, NFC

This convenience wrapper was made virtual when it was introduced. I see
no overrides and no reason for it to be virtual, so make it non-virtual.

Added: 


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

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 841e24e527eb..2af1189511a3 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2030,7 +2030,7 @@ class FunctionDecl : public DeclaratorDecl,
   /// declaration to the declaration that is a definition (if there is one).
   bool isDefined(const FunctionDecl *&Definition) const;
 
-  virtual bool isDefined() const {
+  bool isDefined() const {
 const FunctionDecl* Definition;
 return isDefined(Definition);
   }



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


[clang] 94d9122 - [NFC] Do not run CGProfilePass when not using integrated assembler

2020-03-31 Thread via cfe-commits

Author: zhizhouy
Date: 2020-03-31T10:31:31-07:00
New Revision: 94d912296de21e965198ba1ddd1ca6714b3e4722

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

LOG: [NFC] Do not run CGProfilePass when not using integrated assembler

Summary:
CGProfilePass is run by default in certain new pass manager optimization 
pipeline. Assemblers other than llvm as (such as gnu as) cannot recognize the 
.cgprofile entries generated and emitted from this pass, causing build time 
error.

This patch adds new options in clang CodeGenOpts and PassBuilder options so 
that we can turn cgprofile off when not using integrated assembler.

Reviewers: Bigcheese, xur, george.burgess.iv, chandlerc, manojgupta

Reviewed By: manojgupta

Subscribers: manojgupta, void, hiraditya, dexonsmith, llvm-commits, tcwang, 
llozano

Tags: #llvm, #clang

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

Added: 
llvm/test/Other/new-pm-cgprofile.ll

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Frontend/CompilerInvocation.cpp
llvm/include/llvm/Passes/PassBuilder.h
llvm/lib/Passes/PassBuilder.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 5b59954fae7b..a62cf5e729db 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -254,6 +254,7 @@ CODEGENOPT(UnwindTables  , 1, 0) ///< Emit unwind 
tables.
 CODEGENOPT(VectorizeLoop , 1, 0) ///< Run loop vectorizer.
 CODEGENOPT(VectorizeSLP  , 1, 0) ///< Run SLP vectorizer.
 CODEGENOPT(ProfileSampleAccurate, 1, 0) ///< Sample profile is accurate.
+CODEGENOPT(CallGraphProfile  , 1, 0) ///< Run call graph profile.
 
   /// Attempt to use register sized accesses to bit-fields in structures, when
   /// possible.

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 97b97276521d..4e8b722eea34 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1108,6 +1108,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   PTO.LoopInterleaving = CodeGenOpts.UnrollLoops;
   PTO.LoopVectorization = CodeGenOpts.VectorizeLoop;
   PTO.SLPVectorization = CodeGenOpts.VectorizeSLP;
+  PTO.CallGraphProfile = CodeGenOpts.CallGraphProfile;
   PTO.Coroutines = LangOpts.Coroutines;
 
   PassInstrumentationCallbacks PIC;
@@ -1518,6 +1519,7 @@ static void runThinLTOBackend(ModuleSummaryIndex 
*CombinedIndex, Module *M,
   Conf.PTO.LoopInterleaving = CGOpts.UnrollLoops;
   Conf.PTO.LoopVectorization = CGOpts.VectorizeLoop;
   Conf.PTO.SLPVectorization = CGOpts.VectorizeSLP;
+  Conf.PTO.CallGraphProfile = CGOpts.CallGraphProfile;
 
   // Context sensitive profile.
   if (CGOpts.hasProfileCSIRInstr()) {

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index dc5e932c9460..46ba46df8999 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -823,6 +823,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList 
&Args, InputKind IK,
   Opts.RerollLoops = Args.hasArg(OPT_freroll_loops);
 
   Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
+  Opts.CallGraphProfile = !Opts.DisableIntegratedAS;
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile =
   std::string(Args.getLastArgValue(OPT_fprofile_sample_use_EQ));

diff  --git a/llvm/include/llvm/Passes/PassBuilder.h 
b/llvm/include/llvm/Passes/PassBuilder.h
index 38af89622977..12e914d44ba3 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -105,6 +105,10 @@ class PipelineTuningOptions {
   /// Tuning option to disable promotion to scalars in LICM with MemorySSA, if
   /// the number of access is too large.
   unsigned LicmMssaNoAccForPromotionCap;
+
+  /// Tuning option to enable/disable call graph profile. Its default value is
+  /// that of the flag: `-enable-npm-call-graph-profile`.
+  bool CallGraphProfile;
 };
 
 /// This class provides access to building LLVM's passes.

diff  --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 32d0a380ae3a..57c510b8cbfd 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -237,6 +237,10 @@ static cl::opt
 EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden,
   cl::desc("Enable control height reduction optimization (CHR)"));
 
+static cl::opt EnableCallGraphProfile(
+"enable-npm-call-graph-profile", cl::init(true), cl::Hidden,
+cl::desc("Enable call graph profile pass for the new PM (default = on)"));
+
 PipelineTuningOptions::PipelineTuningOptions(

[PATCH] D77115: [WebAssembly] Emit .llvmcmd and .llvmbc as custom sections

2020-03-31 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 added a comment.

In D77115#1952536 , @alexcrichton 
wrote:

> Seems reasonable to me! In my testing though if these existed as custom 
> sections they'd still make their way to the final binary through LLD, so 
> could LLD skip over these sectiosn by default?


I'll take a look at that.

Can you confirm that you tools are able to find and use the sections in the 
same way they do for ELF files?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77115



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


[PATCH] D77150: [Analyzer] New Option for ContainerModeling: AggressiveEraseModeling

2020-03-31 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Do you have a lit test as well? It would be useful to have one that is similar 
to the one you mention in the review's summary.




Comment at: clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp:780
 
+  if (AggressiveEraseModeling) {
+if (const auto *CData = getContainerData(State, ContReg)) {

This seems to be very similar to the hunk we have in `handleErase`, so this 
suggests some unnecessary code duplication. I presume we could create a 
function which is called from both callers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77150



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


[PATCH] D76932: [AIX] emit .extern and .weak directive linkage

2020-03-31 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added inline comments.



Comment at: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1498
+  }
+  emitLinkage(&F, Name);
+  continue;

jasonliu wrote:
> I'm surprised we do not enter here for `foo_ext_weak()`. The result of that 
> is we need to do something in `lowerConstant()`, which I would want to avoid 
> if possible. 
> Should we look into why `isDeclarationForLinker()` returns false for 
> `foo_ext_weak()` here?
> My guess is we returned false for `!F->isMaterializable()`. And I'm not sure 
> if `foo_ext_weak` is materializable is the correct answer here. 
Sorry, ignore the above comment. I think we did entered here for emitLinkage 
for `foo_ext_weak`. But the hasContainingCsect query blocked the emission 
there. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76932



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


[PATCH] D77064: [clang-format] Correct line breaks in C# generic type constraints

2020-03-31 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe updated this revision to Diff 253925.
jbcoe added a comment.

Fix failing test by preventing inconsistent states from being constructed where 
canBreak is false and mustBreak is true.


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

https://reviews.llvm.org/D77064

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


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -564,7 +564,7 @@
 
 TEST_F(FormatTestCSharp, CSharpArrayInitializers) {
   FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
-  
+
   verifyFormat(R"(//
 private MySet[] setPoints = {
   new Point(),
@@ -710,6 +710,15 @@
   IAnotherInterfaceStill {})",
Style);
 
+  Style.ColumnLimit = 50; // Force lines to be wrapped.
+  verifyFormat(R"(//
+class ItemFactory
+where T : new(),
+  IAnInterface,
+  IAnotherInterface,
+  IAnotherInterfaceStill {})",
+   Style);
+
   // In other languages `where` can be used as a normal identifier.
   // This example is in C++!
   verifyFormat(R"(//
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2340,6 +2340,12 @@
   }
   if (FormatTok->Tok.is(tok::semi))
 return;
+  if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {
+addUnwrappedLine();
+nextToken();
+parseCSharpGenericTypeConstraint();
+break;
+  }
   nextToken();
 }
   }
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1060,15 +1060,20 @@
   }
 
   void parseCSharpGenericTypeConstraint() {
+int OpenAngleBracketsCount = 0;
 while (CurrentToken) {
   if (CurrentToken->is(tok::less)) {
 // parseAngle is too greedy and will consume the whole line.
 CurrentToken->Type = TT_TemplateOpener;
+++OpenAngleBracketsCount;
 next();
   } else if (CurrentToken->is(tok::greater)) {
 CurrentToken->Type = TT_TemplateCloser;
+--OpenAngleBracketsCount;
 next();
-  } else if (CurrentToken->is(tok::comma)) {
+  } else if (CurrentToken->is(tok::comma) && OpenAngleBracketsCount == 0) {
+// We allow line breaks after GenericTypeConstraintComma's
+// so do not flag commas in Generics as GenericTypeConstraintComma's.
 CurrentToken->Type = TT_CSharpGenericTypeConstraintComma;
 next();
   } else if (CurrentToken->is(Keywords.kw_where)) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -346,6 +346,11 @@
   Current.startsSequence(TT_SelectorName, tok::colon, tok::caret)) {
 return true;
   }
+  // Avoid producing inconsistent states by requiring breaks where they are not
+  // permitted for C# generic type constraints.
+  if (State.Stack.back().IsCSharpGenericTypeConstraint &&
+  Previous.isNot(TT_CSharpGenericTypeConstraintComma))
+return false;
   if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
(Previous.is(TT_TemplateCloser) && Current.is(TT_StartOfName) &&
 Style.isCpp() &&


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -564,7 +564,7 @@
 
 TEST_F(FormatTestCSharp, CSharpArrayInitializers) {
   FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
-  
+
   verifyFormat(R"(//
 private MySet[] setPoints = {
   new Point(),
@@ -710,6 +710,15 @@
   IAnotherInterfaceStill {})",
Style);
 
+  Style.ColumnLimit = 50; // Force lines to be wrapped.
+  verifyFormat(R"(//
+class ItemFactory
+where T : new(),
+  IAnInterface,
+  IAnotherInterface,
+  IAnotherInterfaceStill {})",
+   Style);
+
   // In other languages `where` can be used as a normal identifier.
   // This example is in C++!
   verifyFormat(R"(//
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2340,6 +2340,12 @@
   }
   if (FormatTok->Tok.is(tok::semi))
 return;
+  if (Style.isCSharp() && FormatTok->is

[PATCH] D76932: [AIX] emit .extern and .weak directive linkage

2020-03-31 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added inline comments.



Comment at: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1492
+
+if (MAI->hasDotExternDirective()) {
+  MCSymbol *Name = getSymbol(&F);

This query asked if the target supports .extern. However, .extern is not the 
only directive that could get emitted here. We could also emit .weak.



Comment at: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1498
+  }
+  emitLinkage(&F, Name);
+  continue;

I'm surprised we do not enter here for `foo_ext_weak()`. The result of that is 
we need to do something in `lowerConstant()`, which I would want to avoid if 
possible. 
Should we look into why `isDeclarationForLinker()` returns false for 
`foo_ext_weak()` here?
My guess is we returned false for `!F->isMaterializable()`. And I'm not sure if 
`foo_ext_weak` is materializable is the correct answer here. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76932



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


[PATCH] D77064: [clang-format] Correct line breaks in C# generic type constraints

2020-03-31 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.

Awesome!


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

https://reviews.llvm.org/D77064



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


[PATCH] D72872: [ObjC generics] Fix not inheriting type bounds in categories/extensions.

2020-03-31 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72872



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


[PATCH] D76083: [clang-tidy] Expand the list of functions in bugprone-unused-return-value

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



Comment at: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp:98
+   "::access;"
+   "::bind;"
+   "::connect;"

jranieri-grammatech wrote:
> alexfh wrote:
> > bind has a side effect and returns a success status. Thus, the result being 
> > unused isn't necessarily a bug. Same for `connect`. And probably for 
> > `setjmp` as well.
> In terms of bind, connect, and setjmp: while I personally would say that code 
> not using the return value is bugprone, the data suggests that the vast 
> majority of developers are using these functions in the intended manner and 
> the false-positive rate should be low.
I think we have sufficient statistical data to suggest that these APIs should 
be on the list because the majority of programmers *do not* use them solely for 
side effects without using the return value, so my preference is to keep them 
in the list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76083



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


[PATCH] D76932: [AIX] emit .extern and .weak directive linkage

2020-03-31 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added inline comments.



Comment at: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp:1548
+
+  if (XCOFFSym->hasContainingCsect()) {
+MCSymbolXCOFF *QualName =

I hope we can find a better solution here. IMO, we don't even want to override 
this function in this patch. 
GVSym should be the right one from what caller passed in. It's caller's 
responsibility to pass in the right GVSym. 
When caller calls emitLinkage, we should emitLinkage. It's weird when 
emitLinkage is called, but none is emitted (when hasContainingCsect() returns 
false).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76932



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


[PATCH] D75561: Remove const qualifier from Modules returned by ExternalASTSource. (NFC)

2020-03-31 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

I am fine with this if we *really* need it for D75488 
. So far the only direct place where we do 
need the module to be non-const was some redundant assignment for Name (I added 
a comment in D75488 ), but if that is removed 
I believe the rest of the code should work with a const Module.


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

https://reviews.llvm.org/D75561



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


[PATCH] D77081: [MS] Mark vbase dtors ref'd when ref'ing dtor

2020-03-31 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 253933.
rnk added a comment.

- Remove definition data bit tracking, use destructor isUsed bit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77081

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/class.access/p4.cpp
  clang/test/CodeGenCXX/microsoft-abi-vbase-dtor.cpp
  clang/test/SemaCXX/ms-implicit-complete-dtor.cpp

Index: clang/test/SemaCXX/ms-implicit-complete-dtor.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ms-implicit-complete-dtor.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -std=c++17 -verify -Wno-defaulted-function-deleted %s -triple x86_64-windows-msvc
+
+// MSVC emits the complete destructor as if it were its own special member.
+// Clang attempts to do the same. This affects the diagnostics clang emits,
+// because deleting a type with a user declared constructor implicitly
+// references the destructors of virtual bases, which might be deleted or access
+// controlled.
+
+namespace t1 {
+struct A {
+  ~A() = delete; // expected-note {{deleted here}}
+};
+struct B { // expected-error {{attempt to use a deleted function}}
+  B() = default;
+  A o; // expected-note {{destructor of 'B' is implicitly deleted because field 'o' has a deleted destructor}}
+};
+struct C : virtual B {
+  ~C();
+};
+void delete1(C *p) { delete p; } // expected-note {{in implicit destructor for 't1::C' first required here}}
+void delete2(C *p) { delete p; }
+}
+
+namespace t2 {
+struct A {
+private:
+  ~A();
+};
+struct B { // expected-error {{attempt to use a deleted function}}
+  B() = default;
+  A o; // expected-note {{destructor of 'B' is implicitly deleted because field 'o' has an inaccessible destructor}}
+};
+struct C : virtual B {
+  ~C();
+};
+void useCompleteDtor(C *p) { delete p; } // expected-note {{in implicit destructor for 't2::C' first required here}}
+}
+
+namespace t3 {
+template 
+class Base { ~Base(); }; // expected-note 1{{declared private here}}
+// No diagnostic.
+class Derived0 : virtual Base<0> { ~Derived0(); };
+class Derived1 : virtual Base<1> {};
+// Emitting complete dtor causes a diagnostic.
+struct Derived2 : // expected-error {{inherited virtual base class 'Base<2>' has private destructor}}
+  virtual Base<2> {
+  ~Derived2();
+};
+void useCompleteDtor(Derived2 *p) { delete p; } // expected-note {{in implicit destructor for 't3::Derived2' first required here}}
+}
Index: clang/test/CodeGenCXX/microsoft-abi-vbase-dtor.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/microsoft-abi-vbase-dtor.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c++17 -emit-llvm %s -triple x86_64-windows-msvc -o - | FileCheck %s
+
+// Make sure virtual base base destructors get referenced and emitted if
+// necessary when the complete ("vbase") destructor is emitted. In this case,
+// clang previously did not emit ~DefaultedDtor.
+struct HasDtor { ~HasDtor(); };
+struct DefaultedDtor {
+  ~DefaultedDtor() = default;
+  HasDtor o;
+};
+struct HasCompleteDtor : virtual DefaultedDtor {
+  ~HasCompleteDtor();
+};
+void useCompleteDtor(HasCompleteDtor *p) { delete p; }
+
+// CHECK-LABEL: define dso_local void @"?useCompleteDtor@@YAXPEAUHasCompleteDtor@@@Z"(%struct.HasCompleteDtor* %p)
+// CHECK: call void @"??_DHasCompleteDtor@@QEAAXXZ"({{.*}})
+
+// CHECK-LABEL: define linkonce_odr dso_local void @"??_DHasCompleteDtor@@QEAAXXZ"(%struct.HasCompleteDtor* %this)
+// CHECK: call void @"??1HasCompleteDtor@@QEAA@XZ"({{.*}})
+// CHECK: call void @"??1DefaultedDtor@@QEAA@XZ"({{.*}})
+
+// CHECK-LABEL: define linkonce_odr dso_local void @"??1DefaultedDtor@@QEAA@XZ"(%struct.DefaultedDtor* %this)
+// CHECK: call void @"??1HasDtor@@QEAA@XZ"(%struct.HasDtor* %{{.*}})
+
Index: clang/test/CXX/class.access/p4.cpp
===
--- clang/test/CXX/class.access/p4.cpp
+++ clang/test/CXX/class.access/p4.cpp
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++98 %s
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++98 %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-compatibility-version=19 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++98 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-compatibility-version=19 -fcxx-exceptions -fexceptions -fsyntax-only -verify -

[PATCH] D77081: [MS] Mark vbase dtors ref'd when ref'ing dtor

2020-03-31 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I'm glad to report that your suggestion worked out well!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77081



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


[PATCH] D77115: [WebAssembly] Emit .llvmcmd and .llvmbc as custom sections

2020-03-31 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 updated this revision to Diff 253935.
sbc100 added a comment.

strip in linker


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77115

Files:
  clang/test/Driver/embed-bitcode-wasm.c
  clang/test/Driver/fembed-bitcode.c
  lld/wasm/Writer.cpp
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/MC/WasmObjectWriter.cpp

Index: llvm/lib/MC/WasmObjectWriter.cpp
===
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -436,10 +436,6 @@
   uint64_t FixupOffset = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
   MCContext &Ctx = Asm.getContext();
 
-  // The .init_array isn't translated as data, so don't do relocations in it.
-  if (FixupSection.getSectionName().startswith(".init_array"))
-return;
-
   if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
 // To get here the A - B expression must have failed evaluateAsRelocatable.
 // This means either A or B must be undefined and in WebAssembly we can't
@@ -502,6 +498,10 @@
 SymA->setUsedInReloc();
   }
 
+  // The .init_array isn't translated as data, so don't do relocations in it.
+  if (FixupSection.getSectionName().startswith(".init_array"))
+return;
+
   if (RefA->getKind() == MCSymbolRefExpr::VK_GOT)
 SymA->setUsedInGOT();
 
@@ -1090,10 +1090,7 @@
   if (Sym.isComdat() && !Sym.isDefined())
 return false;
 
-  if (Sym.isTemporary() && Sym.getName().empty())
-return false;
-
-  if (Sym.isTemporary() && Sym.isData() && !Sym.getSize())
+  if (Sym.isTemporary())
 return false;
 
   if (Sym.isSection())
@@ -1565,7 +1562,7 @@
 report_fatal_error("fixups in .init_array should be symbol references");
   const auto &TargetSym = cast(SymRef->getSymbol());
   if (TargetSym.getIndex() == InvalidIndex)
-report_fatal_error("symbols in .init_array should exist in symbtab");
+report_fatal_error("symbols in .init_array should exist in symtab");
   if (!TargetSym.isFunction())
 report_fatal_error("symbols in .init_array should be for functions");
   InitFuncs.push_back(
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1765,6 +1765,14 @@
 
   StringRef Name = GO->getSection();
 
+  // Certain data sections we treat as named custom sections rather than
+  // segments within the data section.
+  // This could be avoided if all data segements (the wasm sense) were
+  // represented as thier own sections (in the llvm sense).
+  // TODO(sbc): https://github.com/WebAssembly/tool-conventions/issues/138
+  if (Name == ".llvmcmd" || Name == ".llvmbc")
+Kind = SectionKind::getMetadata();
+
   StringRef Group = "";
   if (const Comdat *C = getWasmComdat(GO)) {
 Group = C->getName();
Index: lld/wasm/Writer.cpp
===
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -110,13 +110,21 @@
 for (InputSection *section : file->customSections) {
   StringRef name = section->getName();
   // These custom sections are known the linker and synthesized rather than
-  // blindly copied
+  // blindly copied.
   if (name == "linking" || name == "name" || name == "producers" ||
   name == "target_features" || name.startswith("reloc."))
 continue;
-  // .. or it is a debug section
+  // These custom sections are generated by `clang -fembed-bitcode`.
+  // These are used by the rust toolchain to ship LTO data along with
+  // compiled object code, but they don't want this included in the linker
+  // output.
+  if (name == ".llvmbc" || name == ".llvmcmd")
+continue;
+  // Strip debug section in that option was specified.
   if (stripDebug && name.startswith(".debug_"))
 continue;
+  // Otherwise include custom sections by default and concatenate their
+  // contents.
   customSectionMapping[name].push_back(section);
 }
   }
Index: clang/test/Driver/fembed-bitcode.c
===
--- clang/test/Driver/fembed-bitcode.c
+++ clang/test/Driver/fembed-bitcode.c
@@ -30,3 +30,12 @@
 // RUN: | FileCheck --check-prefix=CHECK-HEXAGON %s
 // CHECK-HEXAGON: "-target-feature"
 // CHECK-HEXAGON: "+reserved-r19"
+//
+// RUN: %clang -target wasm32-unknown-unknown -fembed-bitcode=all -pthread -c %s -o /dev/null -### 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WASM %s
+
+// CHECK-WASM: "-cc1"
+// CHECK-WASM: "-target-feature" "+atomics"
+
+// CHECK-WASM: "-cc1"
+// CHECK-WASM: "-target-feature" "+atomics"
Index: clang/test/Driver/embed-bitcode-wasm.c
===
--- /dev/

[PATCH] D76932: [AIX] emit .extern and .weak directive linkage

2020-03-31 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added inline comments.



Comment at: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp:1589
 : getObjFileLowering().getSectionForFunctionDescriptor(F, TM));
-
+if (F->isDeclaration()) {
+  MCSymbolXCOFF *FSym = cast(getSymbol(F));

If it's possible, I would like to not emitLinkage here. I don't think it's the 
right place. Could we emitLinkage for the symbols needed in 
AsmPrinter::doFinalization instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76932



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


[clang] d1b412a - [clang-format] Correct line breaks in C# generic type constraints

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

Author: Jonathan Coe
Date: 2020-03-31T19:27:01+01:00
New Revision: d1b412ae389e4e30706c326ddec192ffb2e272cf

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

LOG: [clang-format] Correct line breaks in C# generic type constraints

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

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

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestCSharp.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index d2397dbfeb87..ba42ba0ca050 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -346,6 +346,11 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   Current.startsSequence(TT_SelectorName, tok::colon, tok::caret)) {
 return true;
   }
+  // Avoid producing inconsistent states by requiring breaks where they are not
+  // permitted for C# generic type constraints.
+  if (State.Stack.back().IsCSharpGenericTypeConstraint &&
+  Previous.isNot(TT_CSharpGenericTypeConstraintComma))
+return false;
   if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
(Previous.is(TT_TemplateCloser) && Current.is(TT_StartOfName) &&
 Style.isCpp() &&

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 8f40fc7bdcb6..a3cd4f42f8f8 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1060,15 +1060,20 @@ class AnnotatingParser {
   }
 
   void parseCSharpGenericTypeConstraint() {
+int OpenAngleBracketsCount = 0;
 while (CurrentToken) {
   if (CurrentToken->is(tok::less)) {
 // parseAngle is too greedy and will consume the whole line.
 CurrentToken->Type = TT_TemplateOpener;
+++OpenAngleBracketsCount;
 next();
   } else if (CurrentToken->is(tok::greater)) {
 CurrentToken->Type = TT_TemplateCloser;
+--OpenAngleBracketsCount;
 next();
-  } else if (CurrentToken->is(tok::comma)) {
+  } else if (CurrentToken->is(tok::comma) && OpenAngleBracketsCount == 0) {
+// We allow line breaks after GenericTypeConstraintComma's
+// so do not flag commas in Generics as GenericTypeConstraintComma's.
 CurrentToken->Type = TT_CSharpGenericTypeConstraintComma;
 next();
   } else if (CurrentToken->is(Keywords.kw_where)) {

diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index d8202bd61458..18899314512e 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2340,6 +2340,12 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   }
   if (FormatTok->Tok.is(tok::semi))
 return;
+  if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {
+addUnwrappedLine();
+nextToken();
+parseCSharpGenericTypeConstraint();
+break;
+  }
   nextToken();
 }
   }

diff  --git a/clang/unittests/Format/FormatTestCSharp.cpp 
b/clang/unittests/Format/FormatTestCSharp.cpp
index f5e0bab1cb31..b0e4e76cefe7 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -564,7 +564,7 @@ var myDict = new Dictionary {
 
 TEST_F(FormatTestCSharp, CSharpArrayInitializers) {
   FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
-  
+
   verifyFormat(R"(//
 private MySet[] setPoints = {
   new Point(),
@@ -710,6 +710,15 @@ class ItemFactory
   IAnotherInterfaceStill {})",
Style);
 
+  Style.ColumnLimit = 50; // Force lines to be wrapped.
+  verifyFormat(R"(//
+class ItemFactory
+where T : new(),
+  IAnInterface,
+  IAnotherInterface,
+  IAnotherInterfaceStill {})",
+   Style);
+
   // In other languages `where` can be used as a normal identifier.
   // This example is in C++!
   verifyFormat(R"(//



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


[clang] 28518d9 - [InlineFunction] Handle return attributes on call within inlined body

2020-03-31 Thread Anna Thomas via cfe-commits

Author: Anna Thomas
Date: 2020-03-31T14:35:40-04:00
New Revision: 28518d9ae39ff5c6044e230d58b6ae28b0252cae

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

LOG: [InlineFunction] Handle return attributes on call within inlined body

Consider a callee function that has a call (C) within it which feeds
into the return.  When we inline that callee into a callsite that has
return attributes, we can backward propagate those attributes to the
call (C) within that inlined callee body.

This is safe to do so only if we can guarantee transfer of execution to
successor in the window of instructions between return value (i.e. the
call C) and the return instruction.

See added test cases.

Reviewed-By: reames, jdoerfert

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

Added: 
llvm/test/Transforms/Inline/ret_attr_update.ll

Modified: 
clang/test/CodeGen/builtins-systemz-zvector.c
clang/test/CodeGen/builtins-systemz-zvector2.c
clang/test/CodeGen/movbe-builtins.c
clang/test/CodeGen/rot-intrinsics.c
llvm/lib/Transforms/Utils/InlineFunction.cpp

Removed: 




diff  --git a/clang/test/CodeGen/builtins-systemz-zvector.c 
b/clang/test/CodeGen/builtins-systemz-zvector.c
index da0e720c9fae..6cba71098792 100644
--- a/clang/test/CodeGen/builtins-systemz-zvector.c
+++ b/clang/test/CodeGen/builtins-systemz-zvector.c
@@ -3665,31 +3665,31 @@ void test_integer(void) {
   // CHECK-ASM: vsumqg
 
   idx = vec_test_mask(vsc, vuc);
-  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vuc, vuc);
-  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vss, vus);
-  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vus, vus);
-  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vsi, vui);
-  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vui, vui);
-  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vsl, vul);
-  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vul, vul);
-  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vd, vul);
-  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
   // CHECK-ASM: vtm
 }
 

diff  --git a/clang/test/CodeGen/builtins-systemz-zvector2.c 
b/clang/test/CodeGen/builtins-systemz-zvector2.c
index a4f791e6019b..1880fed64dbc 100644
--- a/clang/test/CodeGen/builtins-systemz-zvector2.c
+++ b/clang/test/CodeGen/builtins-systemz-zvector2.c
@@ -654,10 +654,10 @@ void test_integer(void) {
   // CHECK-ASM: vsrlb
 
   idx = vec_test_mask(vf, vui);
-  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vd, vul);
-  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
   // CHECK-ASM: vtm
 
   vuc = vec_msum_u128(vul, vul, vuc, 0);

diff  --git a/clang/test/CodeGen/movbe-builtins.c 
b/clang/test/CodeGen/movbe-builtins.c
index 342f66391388..15f49b84ec67 100644
--- a/clang/test/CodeGen/movbe-builtins.c
+++ b/clang/test/CodeGen/movbe-builtins.c
@@ -7,7 +7,7 @@
 short test_loadbe_i16(const short *P) {
   // CHECK-LABEL: @test_loadbe_i16
   // CHECK: [[LOAD:%.*]] = load i16, i16* %{{.*}}, align 1
-  // CHECK: call i16 @llvm.bswap.i16(i16 [[LOAD]])
+  // CHECK: call signext i16 @llvm.bswap.i16(i16 [[LOAD]])
   return _loadbe_i16(P);
 }
 

diff  --git a/clang/test/CodeGen/rot-intrinsics.c 
b/clang/test/CodeGen/rot-intrinsics.c
index dcdc54c4585a..7b1

[PATCH] D77115: [WebAssembly] Emit .llvmcmd and .llvmbc as custom sections

2020-03-31 Thread Alex Crichton via Phabricator via cfe-commits
alexcrichton accepted this revision.
alexcrichton added a comment.
This revision is now accepted and ready to land.

At least from my POV looks good :)

Thanks for the quick patch!

Should this link 

 also be updated to handle the special section names?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77115



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


[PATCH] D77077: [clang] CodeGen: Make getOrEmitProtocol public for Swift

2020-03-31 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer updated this revision to Diff 253938.
aschwaighofer added a comment.

- Remove callback. Swift can inspect the generated IR and update it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77077

Files:
  clang/include/clang/CodeGen/CodeGenABITypes.h
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/CodeGen/CGObjCRuntime.h

Index: clang/lib/CodeGen/CGObjCRuntime.h
===
--- clang/lib/CodeGen/CGObjCRuntime.h
+++ clang/lib/CodeGen/CGObjCRuntime.h
@@ -211,6 +211,11 @@
   /// implementations.
   virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
 
+  /// GetOrEmitProtocol - Get the protocol object for the given
+  /// declaration, emitting it if necessary. The return value has type
+  /// ProtocolPtrTy.
+  virtual llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD) = 0;
+
   /// Generate a function preamble for a method with the specified
   /// types.
 
Index: clang/lib/CodeGen/CGObjCRuntime.cpp
===
--- clang/lib/CodeGen/CGObjCRuntime.cpp
+++ clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -13,14 +13,15 @@
 //===--===//
 
 #include "CGObjCRuntime.h"
-#include "CGCleanup.h"
 #include "CGCXXABI.h"
+#include "CGCleanup.h"
 #include "CGRecordLayout.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
+#include "clang/CodeGen/CodeGenABITypes.h"
 #include "llvm/Support/SaveAndRestore.h"
 
 using namespace clang;
@@ -383,3 +384,9 @@
 CGM.getTypes().GetFunctionType(argsInfo)->getPointerTo();
   return MessageSendInfo(argsInfo, signatureType);
 }
+
+llvm::Constant *
+clang::CodeGen::emitObjCProtocolObject(CodeGenModule &CGM,
+   const ObjCProtocolDecl *protocol) {
+  return CGM.getObjCRuntime().GetOrEmitProtocol(protocol);
+}
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -1107,11 +1107,6 @@
 
   void GenerateProtocol(const ObjCProtocolDecl *PD) override;
 
-  /// GetOrEmitProtocol - Get the protocol object for the given
-  /// declaration, emitting it if necessary. The return value has type
-  /// ProtocolPtrTy.
-  virtual llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD)=0;
-
   /// GetOrEmitProtocolRef - Get a forward reference to the protocol
   /// object for the given declaration, emitting it if needed. These
   /// forward references will be filled in with empty bodies if no
Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -617,6 +617,11 @@
   llvm::Value *GenerateProtocolRef(CodeGenFunction &CGF,
const ObjCProtocolDecl *PD) override;
   void GenerateProtocol(const ObjCProtocolDecl *PD) override;
+
+  llvm::Constant *GetOrEmitProtocol(const ObjCProtocolDecl *PD) override {
+llvm_unreachable("not implemented");
+  }
+
   llvm::Function *ModuleInitFunction() override;
   llvm::FunctionCallee GetPropertyGetFunction() override;
   llvm::FunctionCallee GetPropertySetFunction() override;
Index: clang/include/clang/CodeGen/CodeGenABITypes.h
===
--- clang/include/clang/CodeGen/CodeGenABITypes.h
+++ clang/include/clang/CodeGen/CodeGenABITypes.h
@@ -28,11 +28,12 @@
 #include "clang/CodeGen/CGFunctionInfo.h"
 
 namespace llvm {
-  class DataLayout;
-  class Module;
-  class Function;
-  class FunctionType;
-  class Type;
+class Constant;
+class DataLayout;
+class Module;
+class Function;
+class FunctionType;
+class Type;
 }
 
 namespace clang {
@@ -44,6 +45,7 @@
 class DiagnosticsEngine;
 class HeaderSearchOptions;
 class ObjCMethodDecl;
+class ObjCProtocolDecl;
 class PreprocessorOptions;
 
 namespace CodeGen {
@@ -137,6 +139,13 @@
CharUnits DstAlignment,
bool IsVolatile, QualType QT);
 
+/// Get a pointer to a protocol object for the given declaration, emitting it if
+/// it hasn't already been emitted in this translation unit. Note that the ABI
+/// for emitting a protocol reference in code (e.g. for a protocol expression)
+/// in most runtimes is not as simple as just materializing a pointer to this
+/// object.
+llvm::Constant *emitObjCProtocolObject(CodeGenModule &CGM,
+   const ObjCProtocolDecl *p);
 }  // end namespace CodeGen
 }  // end namespace clang
 
_

[PATCH] D76862: HIP: Ensure new denormal mode attributes are set

2020-03-31 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

Are there any other clang options affecting flushing denormals? If so, are they 
working properly after this change? Do we need to have tests for them? Thanks.


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

https://reviews.llvm.org/D76862



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


[PATCH] D77077: [clang] CodeGen: Make getOrEmitProtocol public for Swift

2020-03-31 Thread Arnold Schwaighofer via Phabricator via cfe-commits
aschwaighofer marked an inline comment as done.
aschwaighofer added inline comments.



Comment at: clang/include/clang/CodeGen/CodeGenABITypes.h:148
+ llvm::function_ref
+ createProtocolReference);
 }  // end namespace CodeGen

rjmccall wrote:
> aschwaighofer wrote:
> > rjmccall wrote:
> > > I would call this `emitObjCProtocolObject` or something, and maybe say in 
> > > the comment:
> > > 
> > > > Get a pointer to a protocol object for the given declaration, emitting 
> > > > it if it hasn't already been emitted in this translation unit.  Note 
> > > > that the ABI for emitting a protocol reference in code (e.g. for a 
> > > > `@protocol` expression) in most runtimes is not as simple as just 
> > > > materializing a pointer to this object.
> > > 
> > > Can you explain the need for the callback?   Are you expecting to use 
> > > this for Swift-declared protocols by synthesizing an ObjC protocol 
> > > declaration for them?  I can see why you'd need a callback in that case.
> > > Can you explain the need for the callback? Are you expecting to use this 
> > > for Swift-declared protocols by synthesizing an ObjC protocol declaration 
> > > for them? I can see why you'd need a callback in that case.
> > 
> > The objective C protocol references other protocols in its inherited list. 
> > Swift has an internal list that keeps track of those protocols references 
> > and makes sure to initialized them for the debugger and also makes sure 
> > that the underlying protocol structure is emitted. The call back is to keep 
> > this list in sync.
> The problem is that this is really, really intertwined with the ABI logic.  
> This callback basically has to know exactly how the caller is calling it and 
> and what it's expected to build in response.
> 
> Swift code can use arbitrary inline Objective-C functions and therefore emit 
> arbitrary Objective-C code.  Is there an approach that handles that while 
> also being less invasive for Clang IRGen?  Can we, e.g., inspect the built 
> llvm::Module to figure out retroactively what protocol refs we need to update 
> dynamically instead of trying to track them during the build?
Yes. I think you are right. Swift can inspect the generated IR and update it.

https://github.com/aschwaighofer/swift/commit/d29daf41ec3a51405df31591dad6fea97dbc58e0

I have removed the callback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77077



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


[PATCH] D77115: [WebAssembly] Emit .llvmcmd and .llvmbc as custom sections

2020-03-31 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 updated this revision to Diff 253941.
sbc100 added a comment.

Avoid resuing IsUsedInReloc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77115

Files:
  clang/test/Driver/embed-bitcode-wasm.c
  clang/test/Driver/fembed-bitcode.c
  lld/wasm/Writer.cpp
  llvm/include/llvm/MC/MCSymbolWasm.h
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/MC/WasmObjectWriter.cpp

Index: llvm/lib/MC/WasmObjectWriter.cpp
===
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -436,10 +436,6 @@
   uint64_t FixupOffset = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
   MCContext &Ctx = Asm.getContext();
 
-  // The .init_array isn't translated as data, so don't do relocations in it.
-  if (FixupSection.getSectionName().startswith(".init_array"))
-return;
-
   if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
 // To get here the A - B expression must have failed evaluateAsRelocatable.
 // This means either A or B must be undefined and in WebAssembly we can't
@@ -456,6 +452,12 @@
   const MCSymbolRefExpr *RefA = Target.getSymA();
   const auto *SymA = cast(&RefA->getSymbol());
 
+  // The .init_array isn't translated as data, so don't do relocations in it.
+  if (FixupSection.getSectionName().startswith(".init_array")) {
+SymA->setUsedInInitArray();
+return;
+  }
+
   if (SymA->isVariable()) {
 const MCExpr *Expr = SymA->getVariableValue();
 const auto *Inner = cast(Expr);
@@ -1084,16 +1086,13 @@
 }
 
 static bool isInSymtab(const MCSymbolWasm &Sym) {
-  if (Sym.isUsedInReloc())
+  if (Sym.isUsedInReloc() || Sym.isUsedInInitArray())
 return true;
 
   if (Sym.isComdat() && !Sym.isDefined())
 return false;
 
-  if (Sym.isTemporary() && Sym.getName().empty())
-return false;
-
-  if (Sym.isTemporary() && Sym.isData() && !Sym.getSize())
+  if (Sym.isTemporary())
 return false;
 
   if (Sym.isSection())
@@ -1565,7 +1564,7 @@
 report_fatal_error("fixups in .init_array should be symbol references");
   const auto &TargetSym = cast(SymRef->getSymbol());
   if (TargetSym.getIndex() == InvalidIndex)
-report_fatal_error("symbols in .init_array should exist in symbtab");
+report_fatal_error("symbols in .init_array should exist in symtab");
   if (!TargetSym.isFunction())
 report_fatal_error("symbols in .init_array should be for functions");
   InitFuncs.push_back(
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1765,6 +1765,14 @@
 
   StringRef Name = GO->getSection();
 
+  // Certain data sections we treat as named custom sections rather than
+  // segments within the data section.
+  // This could be avoided if all data segements (the wasm sense) were
+  // represented as thier own sections (in the llvm sense).
+  // TODO(sbc): https://github.com/WebAssembly/tool-conventions/issues/138
+  if (Name == ".llvmcmd" || Name == ".llvmbc")
+Kind = SectionKind::getMetadata();
+
   StringRef Group = "";
   if (const Comdat *C = getWasmComdat(GO)) {
 Group = C->getName();
Index: llvm/include/llvm/MC/MCSymbolWasm.h
===
--- llvm/include/llvm/MC/MCSymbolWasm.h
+++ llvm/include/llvm/MC/MCSymbolWasm.h
@@ -18,6 +18,7 @@
   bool IsWeak = false;
   bool IsHidden = false;
   bool IsComdat = false;
+  mutable bool IsUsedInInitArray = false;
   mutable bool IsUsedInGOT = false;
   Optional ImportModule;
   Optional ImportName;
@@ -104,6 +105,9 @@
   void setUsedInGOT() const { IsUsedInGOT = true; }
   bool isUsedInGOT() const { return IsUsedInGOT; }
 
+  void setUsedInInitArray() const { IsUsedInInitArray = true; }
+  bool isUsedInInitArray() const { return IsUsedInInitArray; }
+
   const wasm::WasmSignature *getSignature() const { return Signature; }
   void setSignature(wasm::WasmSignature *Sig) { Signature = Sig; }
 
Index: lld/wasm/Writer.cpp
===
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -110,13 +110,21 @@
 for (InputSection *section : file->customSections) {
   StringRef name = section->getName();
   // These custom sections are known the linker and synthesized rather than
-  // blindly copied
+  // blindly copied.
   if (name == "linking" || name == "name" || name == "producers" ||
   name == "target_features" || name.startswith("reloc."))
 continue;
-  // .. or it is a debug section
+  // These custom sections are generated by `clang -fembed-bitcode`.
+  // These are used by the rust toolchain to ship LTO data along with
+  // compiled object code, but they don't want this in

[PATCH] D77064: [clang-format] Correct line breaks in C# generic type constraints

2020-03-31 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd1b412ae389e: [clang-format] Correct line breaks in C# 
generic type constraints (authored by Jonathan Coe ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77064

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


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -564,7 +564,7 @@
 
 TEST_F(FormatTestCSharp, CSharpArrayInitializers) {
   FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
-  
+
   verifyFormat(R"(//
 private MySet[] setPoints = {
   new Point(),
@@ -710,6 +710,15 @@
   IAnotherInterfaceStill {})",
Style);
 
+  Style.ColumnLimit = 50; // Force lines to be wrapped.
+  verifyFormat(R"(//
+class ItemFactory
+where T : new(),
+  IAnInterface,
+  IAnotherInterface,
+  IAnotherInterfaceStill {})",
+   Style);
+
   // In other languages `where` can be used as a normal identifier.
   // This example is in C++!
   verifyFormat(R"(//
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2340,6 +2340,12 @@
   }
   if (FormatTok->Tok.is(tok::semi))
 return;
+  if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {
+addUnwrappedLine();
+nextToken();
+parseCSharpGenericTypeConstraint();
+break;
+  }
   nextToken();
 }
   }
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1060,15 +1060,20 @@
   }
 
   void parseCSharpGenericTypeConstraint() {
+int OpenAngleBracketsCount = 0;
 while (CurrentToken) {
   if (CurrentToken->is(tok::less)) {
 // parseAngle is too greedy and will consume the whole line.
 CurrentToken->Type = TT_TemplateOpener;
+++OpenAngleBracketsCount;
 next();
   } else if (CurrentToken->is(tok::greater)) {
 CurrentToken->Type = TT_TemplateCloser;
+--OpenAngleBracketsCount;
 next();
-  } else if (CurrentToken->is(tok::comma)) {
+  } else if (CurrentToken->is(tok::comma) && OpenAngleBracketsCount == 0) {
+// We allow line breaks after GenericTypeConstraintComma's
+// so do not flag commas in Generics as GenericTypeConstraintComma's.
 CurrentToken->Type = TT_CSharpGenericTypeConstraintComma;
 next();
   } else if (CurrentToken->is(Keywords.kw_where)) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -346,6 +346,11 @@
   Current.startsSequence(TT_SelectorName, tok::colon, tok::caret)) {
 return true;
   }
+  // Avoid producing inconsistent states by requiring breaks where they are not
+  // permitted for C# generic type constraints.
+  if (State.Stack.back().IsCSharpGenericTypeConstraint &&
+  Previous.isNot(TT_CSharpGenericTypeConstraintComma))
+return false;
   if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
(Previous.is(TT_TemplateCloser) && Current.is(TT_StartOfName) &&
 Style.isCpp() &&


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -564,7 +564,7 @@
 
 TEST_F(FormatTestCSharp, CSharpArrayInitializers) {
   FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
-  
+
   verifyFormat(R"(//
 private MySet[] setPoints = {
   new Point(),
@@ -710,6 +710,15 @@
   IAnotherInterfaceStill {})",
Style);
 
+  Style.ColumnLimit = 50; // Force lines to be wrapped.
+  verifyFormat(R"(//
+class ItemFactory
+where T : new(),
+  IAnInterface,
+  IAnotherInterface,
+  IAnotherInterfaceStill {})",
+   Style);
+
   // In other languages `where` can be used as a normal identifier.
   // This example is in C++!
   verifyFormat(R"(//
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2340,6 +2340,12 @@
   }
   if (FormatTok->Tok.is(tok:

[PATCH] D77156: [CMAKE] Plumb include_directories() into tablegen()

2020-03-31 Thread Stephen Neuendorffer via Phabricator via cfe-commits
stephenneuendorffer created this revision.
Herald added subscribers: cfe-commits, grosul1, Joonsoo, liufengdb, aartbik, 
lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, 
burmako, jpienaar, rriddle, mehdi_amini, mgorny.
Herald added a project: clang.
stephenneuendorffer added reviewers: mehdi_amini, tstellar.

Previously, the tablegen() cmake command, which defines custom
commands for running tablegen, included several hardcoded paths.  This
becomes unwieldy as there are more users for which these paths are
insufficient.  For most targets, cmake uses include_directories() and
the INCLUDE_DIRECTORIES directory property to specify include paths.
This change picks up the INCLUDE_DIRECTORIES property and adds it
to the include path used when running tablegen.  As a side effect, this
allows us to remove several hard coded paths to tablegen that are redundant
with specified include_directories().

I haven't removed the hardcoded path to CMAKE_CURRENT_SOURCE_DIR, which
seems generically useful.  There are several users in clang which apparently
don't have the current directory as an include_directories().  This could
be considered separately.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77156

Files:
  clang/cmake/modules/AddClang.cmake
  llvm/cmake/modules/TableGen.cmake
  mlir/cmake/modules/AddMLIR.cmake
  mlir/examples/toy/Ch3/CMakeLists.txt
  mlir/examples/toy/Ch4/CMakeLists.txt
  mlir/examples/toy/Ch4/include/toy/CMakeLists.txt
  mlir/examples/toy/Ch5/CMakeLists.txt
  mlir/examples/toy/Ch5/include/toy/CMakeLists.txt
  mlir/examples/toy/Ch6/CMakeLists.txt
  mlir/examples/toy/Ch6/include/toy/CMakeLists.txt
  mlir/examples/toy/Ch7/CMakeLists.txt
  mlir/examples/toy/Ch7/include/toy/CMakeLists.txt

Index: mlir/examples/toy/Ch7/include/toy/CMakeLists.txt
===
--- mlir/examples/toy/Ch7/include/toy/CMakeLists.txt
+++ mlir/examples/toy/Ch7/include/toy/CMakeLists.txt
@@ -1,6 +1,6 @@
 set(LLVM_TARGET_DEFINITIONS Ops.td)
-mlir_tablegen(Ops.h.inc -gen-op-decls "-I${CMAKE_CURRENT_SOURCE_DIR}/..")
-mlir_tablegen(Ops.cpp.inc -gen-op-defs "-I${CMAKE_CURRENT_SOURCE_DIR}/..")
+mlir_tablegen(Ops.h.inc -gen-op-decls)
+mlir_tablegen(Ops.cpp.inc -gen-op-defs)
 add_public_tablegen_target(ToyCh7OpsIncGen)
 
 set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td)
Index: mlir/examples/toy/Ch7/CMakeLists.txt
===
--- mlir/examples/toy/Ch7/CMakeLists.txt
+++ mlir/examples/toy/Ch7/CMakeLists.txt
@@ -1,3 +1,4 @@
+include_directories(include)
 add_subdirectory(include)
 
 set(LLVM_LINK_COMPONENTS
@@ -6,7 +7,7 @@
   )
 
 set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td)
-mlir_tablegen(ToyCombine.inc -gen-rewriters "-I${CMAKE_CURRENT_SOURCE_DIR}/include")
+mlir_tablegen(ToyCombine.inc -gen-rewriters)
 add_public_tablegen_target(ToyCh7CombineIncGen)
 
 add_toy_chapter(toyc-ch7
@@ -25,7 +26,6 @@
   ToyCh7CombineIncGen
   )
 
-include_directories(include/)
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
 get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
Index: mlir/examples/toy/Ch6/include/toy/CMakeLists.txt
===
--- mlir/examples/toy/Ch6/include/toy/CMakeLists.txt
+++ mlir/examples/toy/Ch6/include/toy/CMakeLists.txt
@@ -1,6 +1,6 @@
 set(LLVM_TARGET_DEFINITIONS Ops.td)
-mlir_tablegen(Ops.h.inc -gen-op-decls "-I${CMAKE_CURRENT_SOURCE_DIR}/..")
-mlir_tablegen(Ops.cpp.inc -gen-op-defs "-I${CMAKE_CURRENT_SOURCE_DIR}/..")
+mlir_tablegen(Ops.h.inc -gen-op-decls)
+mlir_tablegen(Ops.cpp.inc -gen-op-defs)
 add_public_tablegen_target(ToyCh6OpsIncGen)
 
 set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td)
Index: mlir/examples/toy/Ch6/CMakeLists.txt
===
--- mlir/examples/toy/Ch6/CMakeLists.txt
+++ mlir/examples/toy/Ch6/CMakeLists.txt
@@ -1,3 +1,4 @@
+include_directories(include)
 add_subdirectory(include)
 
 set(LLVM_LINK_COMPONENTS
@@ -6,7 +7,7 @@
   )
 
 set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td)
-mlir_tablegen(ToyCombine.inc -gen-rewriters "-I${CMAKE_CURRENT_SOURCE_DIR}/include")
+mlir_tablegen(ToyCombine.inc -gen-rewriters)
 add_public_tablegen_target(ToyCh6CombineIncGen)
 
 add_toy_chapter(toyc-ch6
@@ -25,7 +26,6 @@
   ToyCh6CombineIncGen
   )
 
-include_directories(include/)
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
 get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
Index: mlir/examples/toy/Ch5/include/toy/CMakeLists.txt
===
--- mlir/examples/toy/Ch5/include/toy/CMakeLists.txt
+++ mlir/examples/toy/Ch5/include/toy/CMakeLists.txt
@@ -1,6 +1,6 @@
 set(LLVM_TARGET_DEFINITIONS Ops.td)
-mlir_tablegen(Ops.h.inc -gen-op-decls "-I${CMAKE_CURRENT_

[PATCH] D76140: [InlineFunction] update attributes during inlining

2020-03-31 Thread Anna Thomas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG28518d9ae39f: [InlineFunction] Handle return attributes on 
call within inlined body (authored by anna).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76140

Files:
  clang/test/CodeGen/builtins-systemz-zvector.c
  clang/test/CodeGen/builtins-systemz-zvector2.c
  clang/test/CodeGen/movbe-builtins.c
  clang/test/CodeGen/rot-intrinsics.c
  llvm/lib/Transforms/Utils/InlineFunction.cpp
  llvm/test/Transforms/Inline/ret_attr_update.ll

Index: llvm/test/Transforms/Inline/ret_attr_update.ll
===
--- /dev/null
+++ llvm/test/Transforms/Inline/ret_attr_update.ll
@@ -0,0 +1,159 @@
+; RUN: opt < %s -inline-threshold=0 -always-inline -S | FileCheck %s
+; RUN: opt < %s -passes=always-inline -S | FileCheck %s
+
+declare i8* @foo(i8*) argmemonly nounwind
+
+define i8* @callee(i8 *%p) alwaysinline {
+; CHECK: @callee(
+; CHECK: call i8* @foo(i8* noalias %p)
+  %r = call i8* @foo(i8* noalias %p)
+  ret i8* %r
+}
+
+define i8* @caller(i8* %ptr, i64 %x) {
+; CHECK-LABEL: @caller
+; CHECK: call nonnull i8* @foo(i8* noalias
+  %gep = getelementptr inbounds i8, i8* %ptr, i64 %x
+  %p = call nonnull i8* @callee(i8* %gep)
+  ret i8* %p
+}
+
+declare void @llvm.experimental.guard(i1,...)
+; Cannot add nonnull attribute to foo
+; because the guard is a throwing call
+define internal i8* @callee_with_throwable(i8* %p) alwaysinline {
+; CHECK-NOT: callee_with_throwable
+  %r = call i8* @foo(i8* %p)
+  %cond = icmp ne i8* %r, null
+  call void (i1, ...) @llvm.experimental.guard(i1 %cond) [ "deopt"() ]
+  ret i8* %r
+}
+
+declare i8* @bar(i8*) readonly nounwind
+; Here also we cannot add nonnull attribute to the call bar.
+define internal i8* @callee_with_explicit_control_flow(i8* %p) alwaysinline {
+; CHECK-NOT: callee_with_explicit_control_flow
+  %r = call i8* @bar(i8* %p)
+  %cond = icmp ne i8* %r, null
+  br i1 %cond, label %ret, label %orig
+
+ret:
+  ret i8* %r
+
+orig:
+  ret i8* %p
+}
+
+define i8* @caller2(i8* %ptr, i64 %x, i1 %cond) {
+; CHECK-LABEL: @caller2
+; CHECK: call i8* @foo
+; CHECK: call i8* @bar
+  %gep = getelementptr inbounds i8, i8* %ptr, i64 %x
+  %p = call nonnull i8* @callee_with_throwable(i8* %gep)
+  %q = call nonnull i8* @callee_with_explicit_control_flow(i8* %gep)
+  br i1 %cond, label %pret, label %qret
+
+pret:
+  ret i8* %p
+
+qret:
+  ret i8* %q
+}
+
+define internal i8* @callee3(i8 *%p) alwaysinline {
+; CHECK-NOT: callee3
+  %r = call noalias i8* @foo(i8* %p)
+  ret i8* %r
+}
+
+; add the deref attribute to the existing attributes on foo.
+define i8* @caller3(i8* %ptr, i64 %x) {
+; CHECK-LABEL: caller3
+; CHECK: call noalias dereferenceable_or_null(12) i8* @foo
+  %gep = getelementptr inbounds i8, i8* %ptr, i64 %x
+  %p = call dereferenceable_or_null(12) i8* @callee3(i8* %gep)
+  ret i8* %p
+}
+
+declare i8* @inf_loop_call(i8*) nounwind
+; We cannot propagate attributes to foo because we do not know whether inf_loop_call
+; will return execution.
+define internal i8* @callee_with_sideeffect_callsite(i8* %p) alwaysinline {
+; CHECK-NOT: callee_with_sideeffect_callsite
+  %r = call i8* @foo(i8* %p)
+  %v = call i8* @inf_loop_call(i8* %p)
+  ret i8* %r
+}
+
+; do not add deref attribute to foo
+define i8* @test4(i8* %ptr, i64 %x) {
+; CHECK-LABEL: test4
+; CHECK: call i8* @foo
+  %gep = getelementptr inbounds i8, i8* %ptr, i64 %x
+  %p = call dereferenceable_or_null(12) i8* @callee_with_sideeffect_callsite(i8* %gep)
+  ret i8* %p
+}
+
+declare i8* @baz(i8*) nounwind readonly
+define internal i8* @callee5(i8* %p) alwaysinline {
+; CHECK-NOT: callee5
+  %r = call i8* @foo(i8* %p)
+  %v = call i8* @baz(i8* %p)
+  ret i8* %r
+}
+
+; add the deref attribute to foo.
+define i8* @test5(i8* %ptr, i64 %x) {
+; CHECK-LABEL: test5
+; CHECK: call dereferenceable_or_null(12) i8* @foo
+  %gep = getelementptr inbounds i8, i8* %ptr, i64 %x
+  %s = call dereferenceable_or_null(12) i8* @callee5(i8* %gep)
+  ret i8* %s
+}
+
+; deref attributes have different values on the callee and the call feeding into
+; the return.
+; AttrBuilder chooses the already existing value and does not overwrite it.
+define internal i8* @callee6(i8* %p) alwaysinline {
+; CHECK-NOT: callee6
+  %r = call dereferenceable_or_null(16) i8* @foo(i8* %p)
+  %v = call i8* @baz(i8* %p)
+  ret i8* %r
+}
+
+
+define i8* @test6(i8* %ptr, i64 %x) {
+; CHECK-LABEL: test6
+; CHECK: call dereferenceable_or_null(16) i8* @foo
+  %gep = getelementptr inbounds i8, i8* %ptr, i64 %x
+  %s = call dereferenceable_or_null(12) i8* @callee6(i8* %gep)
+  ret i8* %s
+}
+
+; We add the attributes from the callee to both the calls below.
+define internal i8* @callee7(i8 *%ptr, i1 %cond) alwaysinline {
+; CHECK-NOT: @callee7(
+  br i1 %cond, label %pass, label %fail
+
+pass:
+  %r = call i8* @foo(i8* noalias %ptr)
+  ret i8* %r
+
+fail:

[clang] e8f13f4 - Replace std::string::find == 0 with StringRef::startswith

2020-03-31 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2020-03-31T21:01:09+02:00
New Revision: e8f13f4f62f52067cadb55f3c746ccf9d26ee2ce

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

LOG: Replace std::string::find == 0 with StringRef::startswith

This is both more readable and faster. Found by clang-tidy's
abseil-string-find-startswith.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
clang/unittests/Analysis/CloneDetectionTest.cpp
lldb/source/Core/Module.cpp

lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/source/Symbol/Variable.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index dc31a5ab7b0f..b21cfac6e7ed 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -140,7 +140,8 @@ getAArch64MicroArchFeaturesFromMtune(const Driver &D, 
StringRef Mtune,
   // Handle CPU name is 'native'.
   if (MtuneLowerCase == "native")
 MtuneLowerCase = std::string(llvm::sys::getHostCPUName());
-  if (MtuneLowerCase == "cyclone" || MtuneLowerCase.find("apple") == 0) {
+  if (MtuneLowerCase == "cyclone" ||
+  StringRef(MtuneLowerCase).startswith("apple")) {
 Features.push_back("+zcm");
 Features.push_back("+zcz");
   }

diff  --git a/clang/unittests/Analysis/CloneDetectionTest.cpp 
b/clang/unittests/Analysis/CloneDetectionTest.cpp
index 03b63c400434..e09d0733f044 100644
--- a/clang/unittests/Analysis/CloneDetectionTest.cpp
+++ b/clang/unittests/Analysis/CloneDetectionTest.cpp
@@ -42,7 +42,7 @@ class NoBarFunctionConstraint {
   for (const StmtSequence &Arg : {A, B}) {
 if (const auto *D =
 dyn_cast(Arg.getContainingDecl())) {
-  if (D->getNameAsString().find("bar") == 0)
+  if (StringRef(D->getNameAsString()).startswith("bar"))
 return false;
 }
   }

diff  --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index cff74dc9d518..fefc23a9b1c5 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1414,7 +1414,7 @@ void Module::SetSymbolFileFileSpec(const FileSpec &file) {
 if (FileSystem::Instance().IsDirectory(file)) {
   std::string new_path(file.GetPath());
   std::string old_path(obj_file->GetFileSpec().GetPath());
-  if (old_path.find(new_path) == 0) {
+  if (llvm::StringRef(old_path).startswith(new_path)) {
 // We specified the same bundle as the symbol file that we already
 // have
 return;

diff  --git 
a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp 
b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
index 47c7ae8c8d63..83cf9f8bd269 100644
--- 
a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
+++ 
b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
@@ -88,7 +88,7 @@ ObjectContainerBSDArchive::Object::Extract(const 
DataExtractor &data,
 return LLDB_INVALID_OFFSET;
 
   str.assign((const char *)data.GetData(&offset, 16), 16);
-  if (str.find("#1/") == 0) {
+  if (llvm::StringRef(str).startswith("#1/")) {
 // If the name is longer than 16 bytes, or contains an embedded space then
 // it will use this format where the length of the name is here and the
 // name characters are after this header.

diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index f5c84c6a6151..5044bed309dc 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5140,10 +5140,10 @@ uint32_t 
ObjectFileMachO::GetDependentModules(FileSpecList &files) {
   std::string loader_path("@loader_path");
   std::string executable_path("@executable_path");
   for (auto &rpath : rpath_paths) {
-if (rpath.find(loader_path) == 0) {
+if (llvm::StringRef(rpath).startswith(loader_path)) {
   rpath.erase(0, loader_path.size());
   rpath.insert(0, this_file_spec.GetDirectory().GetCString());
-} else if (rpath.find(executable_path) == 0) {
+} else if (llvm::StringRef(rpath).startswith(executable_path)) {
   rpath.erase(0, executable_path.size());
   rpath.insert(0, this_file_spec.GetDirectory().GetCString());
 }

diff  --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp 
b/lldb/source/Plugins/Process/gdb-remote/ProcessGD

[clang] 7f1ea92 - Add a new -fglobal-isel option and make -fexperimental-isel an alias for it.

2020-03-31 Thread Amara Emerson via cfe-commits

Author: Amara Emerson
Date: 2020-03-31T12:06:11-07:00
New Revision: 7f1ea924c695f3293ff48f662cd1ec5f44bc1ab6

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

LOG: Add a new -fglobal-isel option and make -fexperimental-isel an alias for 
it.

Since GlobalISel is maturing and is already on at -O0 for AArch64, it's not
completely "experimental". Create a more appropriate driver flag and make
the older option an alias for it.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/global-isel.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 27ffd562c6de..e35ca843ff56 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -452,13 +452,13 @@ def note_drv_verify_prefix_spelling : Note<
   "-verify prefixes must start with a letter and contain only alphanumeric"
   " characters, hyphens, and underscores">;
 
-def warn_drv_experimental_isel_incomplete : Warning<
-  "-fexperimental-isel support for the '%0' architecture is incomplete">,
-  InGroup;
+def warn_drv_global_isel_incomplete : Warning<
+  "-fglobal-isel support for the '%0' architecture is incomplete">,
+  InGroup;
 
-def warn_drv_experimental_isel_incomplete_opt : Warning<
-  "-fexperimental-isel support is incomplete for this architecture at the 
current optimization level">,
-  InGroup;
+def warn_drv_global_isel_incomplete_opt : Warning<
+  "-fglobal-isel support is incomplete for this architecture at the current 
optimization level">,
+  InGroup;
 
 def warn_drv_moutline_unsupported_opt : Warning<
   "The '%0' architecture does not support -moutline; flag ignored">,

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 4d930dcd0462..1175476d609b 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1154,8 +1154,8 @@ def UnknownArgument : DiagGroup<"unknown-argument">;
 // compiling OpenCL C/C++ but which is not compatible with the SPIR spec.
 def SpirCompat : DiagGroup<"spir-compat">;
 
-// Warning for the experimental-isel options.
-def ExperimentalISel : DiagGroup<"experimental-isel">;
+// Warning for the GlobalISel options.
+def GlobalISel : DiagGroup<"global-isel">;
 
 // A warning group specifically for warnings related to function
 // multiversioning.

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2e8d4b1d2363..635fe67095ff 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1249,8 +1249,10 @@ def finline_functions : Flag<["-"], 
"finline-functions">, Group,
 def finline_hint_functions: Flag<["-"], "finline-hint-functions">, 
Group, Flags<[CC1Option]>,
   HelpText<"Inline functions which are (explicitly or implicitly) marked 
inline">;
 def finline : Flag<["-"], "finline">, Group;
+def fglobal_isel : Flag<["-"], "fglobal-isel">, Group, 
+  HelpText<"Enables the global instruction selector">;
 def fexperimental_isel : Flag<["-"], "fexperimental-isel">, 
Group,
-  HelpText<"Enables the experimental global instruction selector">;
+  Alias;
 def fexperimental_new_pass_manager : Flag<["-"], 
"fexperimental-new-pass-manager">,
   Group, Flags<[CC1Option]>,
   HelpText<"Enables an experimental new pass manager in LLVM.">;
@@ -1530,8 +1532,10 @@ def fno_exceptions : Flag<["-"], "fno-exceptions">, 
Group;
 def fno_gnu_keywords : Flag<["-"], "fno-gnu-keywords">, Group, 
Flags<[CC1Option]>;
 def fno_inline_functions : Flag<["-"], "fno-inline-functions">, 
Group, Flags<[CC1Option]>;
 def fno_inline : Flag<["-"], "fno-inline">, Group, 
Flags<[CC1Option]>;
+def fno_global_isel : Flag<["-"], "fno-global-isel">, Group,
+  HelpText<"Disables the global instruction selector">;
 def fno_experimental_isel : Flag<["-"], "fno-experimental-isel">, 
Group,
-  HelpText<"Disables the experimental global instruction selector">;
+  Alias;
 def fno_experimental_new_pass_manager : Flag<["-"], 
"fno-experimental-new-pass-manager">,
   Group, Flags<[CC1Option]>,
   HelpText<"Disables an experimental new pass manager in LLVM.">;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 80a957bf4579..f22e1082357d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6062,10 +6062,10 @@ void Clang::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (SplitLTO

[PATCH] D77159: [pch] Honour -fallow-pch-with-compiler-errors for overall compilation status

2020-03-31 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir created this revision.
benlangmuir added a reviewer: akyrtzi.
Herald added subscribers: cfe-commits, arphaman, dexonsmith.
Herald added a project: clang.

  Previously we would emit a PCH with errors, but fail the overall
  compilation. If run using the driver, that would result in removing the
  just-produced PCH. Instead, we should have the compilation result match
  whether we were able to emit the PCH.
  
  rdar://61110294


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77159

Files:
  clang/lib/Serialization/GeneratePCH.cpp
  clang/test/Index/pch-with-errors.c


Index: clang/test/Index/pch-with-errors.c
===
--- clang/test/Index/pch-with-errors.c
+++ clang/test/Index/pch-with-errors.c
@@ -42,3 +42,6 @@
 
 // RUN: not c-index-test -write-pch %t.pch foobar.c 2>&1 | FileCheck 
-check-prefix=NONEXISTENT %s
 // NONEXISTENT: Unable to load translation unit
+
+// RUN: %clang -x c-header %s -o %t-clang.h.pch -Xclang 
-detailed-preprocessing-record -Xclang -fallow-pch-with-compiler-errors
+// RUN: c-index-test -index-file %s -include %t-clang.h -Xclang 
-detailed-preprocessing-record | FileCheck -check-prefix=CHECK-INDEX %s
Index: clang/lib/Serialization/GeneratePCH.cpp
===
--- clang/lib/Serialization/GeneratePCH.cpp
+++ clang/lib/Serialization/GeneratePCH.cpp
@@ -57,6 +57,11 @@
 }
   }
 
+  // Errors that do not prevent the PCH from being written should not cause the
+  // overall compilation to fail either.
+  if (AllowASTWithErrors)
+PP.getDiagnostics().getClient()->clear();
+
   // Emit the PCH file to the Buffer.
   assert(SemaPtr && "No Sema?");
   Buffer->Signature =


Index: clang/test/Index/pch-with-errors.c
===
--- clang/test/Index/pch-with-errors.c
+++ clang/test/Index/pch-with-errors.c
@@ -42,3 +42,6 @@
 
 // RUN: not c-index-test -write-pch %t.pch foobar.c 2>&1 | FileCheck -check-prefix=NONEXISTENT %s
 // NONEXISTENT: Unable to load translation unit
+
+// RUN: %clang -x c-header %s -o %t-clang.h.pch -Xclang -detailed-preprocessing-record -Xclang -fallow-pch-with-compiler-errors
+// RUN: c-index-test -index-file %s -include %t-clang.h -Xclang -detailed-preprocessing-record | FileCheck -check-prefix=CHECK-INDEX %s
Index: clang/lib/Serialization/GeneratePCH.cpp
===
--- clang/lib/Serialization/GeneratePCH.cpp
+++ clang/lib/Serialization/GeneratePCH.cpp
@@ -57,6 +57,11 @@
 }
   }
 
+  // Errors that do not prevent the PCH from being written should not cause the
+  // overall compilation to fail either.
+  if (AllowASTWithErrors)
+PP.getDiagnostics().getClient()->clear();
+
   // Emit the PCH file to the Buffer.
   assert(SemaPtr && "No Sema?");
   Buffer->Signature =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76862: HIP: Ensure new denormal mode attributes are set

2020-03-31 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D76862#1953013 , @yaxunl wrote:

> Are there any other clang options affecting flushing denormals? If so, are 
> they working properly after this change? Do we need to have tests for them? 
> Thanks.


I already ensured these are correct for OpenCL, so those already have tests. I 
didn't realize the HIP toolchain was totally separate, so this fixes it.


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

https://reviews.llvm.org/D76862



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


[PATCH] D77103: Add a new -fglobal-isel option and make -fexperimental-isel an alias for it.

2020-03-31 Thread Amara Emerson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7f1ea924c695: Add a new -fglobal-isel option and make 
-fexperimental-isel an alias for it. (authored by aemerson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77103

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/global-isel.c

Index: clang/test/Driver/global-isel.c
===
--- clang/test/Driver/global-isel.c
+++ clang/test/Driver/global-isel.c
@@ -1,24 +1,35 @@
 // REQUIRES: x86-registered-target,aarch64-registered-target
 
+// RUN: %clang -fglobal-isel -S -### %s 2>&1 | FileCheck --check-prefix=ENABLED %s
+// RUN: %clang -fno-global-isel -S -### %s 2>&1 | FileCheck --check-prefix=DISABLED %s
+
+// RUN: %clang -target aarch64 -fglobal-isel -S %s -### 2>&1 | FileCheck --check-prefix=ARM64-DEFAULT %s
+// RUN: %clang -target aarch64 -fglobal-isel -S -O0 %s -### 2>&1 | FileCheck --check-prefix=ARM64-O0 %s
+// RUN: %clang -target aarch64 -fglobal-isel -S -O2 %s -### 2>&1 | FileCheck --check-prefix=ARM64-O2 %s
+// RUN: %clang -target aarch64 -fglobal-isel -Wno-global-isel -S -O2 %s -### 2>&1 | FileCheck --check-prefix=ARM64-O2-NOWARN %s
+
+// RUN: %clang -target x86_64 -fglobal-isel -S %s -### 2>&1 | FileCheck --check-prefix=X86_64 %s
+
+// Now test the aliases.
+
 // RUN: %clang -fexperimental-isel -S -### %s 2>&1 | FileCheck --check-prefix=ENABLED %s
 // RUN: %clang -fno-experimental-isel -S -### %s 2>&1 | FileCheck --check-prefix=DISABLED %s
 
 // RUN: %clang -target aarch64 -fexperimental-isel -S %s -### 2>&1 | FileCheck --check-prefix=ARM64-DEFAULT %s
 // RUN: %clang -target aarch64 -fexperimental-isel -S -O0 %s -### 2>&1 | FileCheck --check-prefix=ARM64-O0 %s
 // RUN: %clang -target aarch64 -fexperimental-isel -S -O2 %s -### 2>&1 | FileCheck --check-prefix=ARM64-O2 %s
-// RUN: %clang -target aarch64 -fexperimental-isel -Wno-experimental-isel -S -O2 %s -### 2>&1 | FileCheck --check-prefix=ARM64-O2-NOWARN %s
 
 // RUN: %clang -target x86_64 -fexperimental-isel -S %s -### 2>&1 | FileCheck --check-prefix=X86_64 %s
 
 // ENABLED: "-mllvm" "-global-isel=1"
 // DISABLED: "-mllvm" "-global-isel=0"
 
-// ARM64-DEFAULT-NOT: warning: -fexperimental-sel
+// ARM64-DEFAULT-NOT: warning: -fglobal-isel
 // ARM64-DEFAULT-NOT: "-global-isel-abort=2"
-// ARM64-O0-NOT: warning: -fexperimental-sel
-// ARM64-O2: warning: -fexperimental-isel support is incomplete for this architecture at the current optimization level
+// ARM64-O0-NOT: warning: -fglobal-isel
+// ARM64-O2: warning: -fglobal-isel support is incomplete for this architecture at the current optimization level
 // ARM64-O2: "-mllvm" "-global-isel-abort=2"
-// ARM64-O2-NOWARN-NOT: warning: -fexperimental-isel
+// ARM64-O2-NOWARN-NOT: warning: -fglobal-isel
 
-// X86_64: -fexperimental-isel support for the 'x86_64' architecture is incomplete
+// X86_64: -fglobal-isel support for the 'x86_64' architecture is incomplete
 // X86_64: "-mllvm" "-global-isel-abort=2"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6062,10 +6062,10 @@
   if (SplitLTOUnit)
 CmdArgs.push_back("-fsplit-lto-unit");
 
-  if (Arg *A = Args.getLastArg(options::OPT_fexperimental_isel,
-   options::OPT_fno_experimental_isel)) {
+  if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
+   options::OPT_fno_global_isel)) {
 CmdArgs.push_back("-mllvm");
-if (A->getOption().matches(options::OPT_fexperimental_isel)) {
+if (A->getOption().matches(options::OPT_fglobal_isel)) {
   CmdArgs.push_back("-global-isel=1");
 
   // GISel is on by default on AArch64 -O0, so don't bother adding
@@ -6084,9 +6084,9 @@
 CmdArgs.push_back("-global-isel-abort=2");
 
 if (!IsArchSupported)
-  D.Diag(diag::warn_drv_experimental_isel_incomplete) << Triple.getArchName();
+  D.Diag(diag::warn_drv_global_isel_incomplete) << Triple.getArchName();
 else
-  D.Diag(diag::warn_drv_experimental_isel_incomplete_opt);
+  D.Diag(diag::warn_drv_global_isel_incomplete_opt);
   }
 } else {
   CmdArgs.push_back("-global-isel=0");
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1249,8 +1249,10 @@
 def finline_hint_functions: Flag<["-"], "finline-hint-functions">, Group, Flags<[CC1Option]>,
   HelpText<"Inline functions which are (explicitly or implicitly) marked inline">;
 def finline : Flag<["-"], "f

[PATCH] D76862: HIP: Ensure new denormal mode attributes are set

2020-03-31 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!


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

https://reviews.llvm.org/D76862



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


[PATCH] D76140: [InlineFunction] update attributes during inlining

2020-03-31 Thread Anna Thomas via Phabricator via cfe-commits
anna added a comment.

I got a failure in one of the binaryFormats:
lib/BinaryFormat/CMakeFiles/LLVMBinaryFormat.dir/MsgPackReader.cpp

  Attributes 'zeroext and signext' are incompatible!
%rev.i.i.i.i.i.i.i.i = tail call signext zeroext i16 @llvm.bswap.i16(i16 
%ret.0.copyload.i.i.i.i) #6
  in function _ZN4llvm7msgpack6Reader7readIntIsEENS_8ExpectedIbEERNS0_6ObjectE
  fatal error: error in backend: Broken function found, compilation aborted!

I believe this just showcases undefined behaviour since we were having a 
returnValue (i.e. call) with an incomptable attribute compared to the return 
attribute on the callsite.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76140



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


[PATCH] D77081: [MS] Mark vbase dtors ref'd when ref'ing dtor

2020-03-31 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 253972.
rnk added a comment.

- finish refactoring, build & test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77081

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/class.access/p4.cpp
  clang/test/CodeGenCXX/microsoft-abi-vbase-dtor.cpp
  clang/test/SemaCXX/ms-implicit-complete-dtor.cpp

Index: clang/test/SemaCXX/ms-implicit-complete-dtor.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ms-implicit-complete-dtor.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -std=c++17 -verify -Wno-defaulted-function-deleted %s -triple x86_64-windows-msvc
+
+// MSVC emits the complete destructor as if it were its own special member.
+// Clang attempts to do the same. This affects the diagnostics clang emits,
+// because deleting a type with a user declared constructor implicitly
+// references the destructors of virtual bases, which might be deleted or access
+// controlled.
+
+namespace t1 {
+struct A {
+  ~A() = delete; // expected-note {{deleted here}}
+};
+struct B {
+  B() = default;
+  A o; // expected-note {{destructor of 'B' is implicitly deleted because field 'o' has a deleted destructor}}
+};
+struct C : virtual B {
+  ~C(); // expected-error {{attempt to use a deleted function}}
+};
+void delete1(C *p) { delete p; } // expected-note {{in implicit destructor for 't1::C' first required here}}
+void delete2(C *p) { delete p; }
+}
+
+namespace t2 {
+struct A {
+private:
+  ~A();
+};
+struct B {
+  B() = default;
+  A o; // expected-note {{destructor of 'B' is implicitly deleted because field 'o' has an inaccessible destructor}}
+};
+struct C : virtual B {
+  ~C(); // expected-error {{attempt to use a deleted function}}
+};
+void useCompleteDtor(C *p) { delete p; } // expected-note {{in implicit destructor for 't2::C' first required here}}
+}
+
+namespace t3 {
+template 
+class Base { ~Base(); }; // expected-note 1{{declared private here}}
+// No diagnostic.
+class Derived0 : virtual Base<0> { ~Derived0(); };
+class Derived1 : virtual Base<1> {};
+// Emitting complete dtor causes a diagnostic.
+struct Derived2 : // expected-error {{inherited virtual base class 'Base<2>' has private destructor}}
+  virtual Base<2> {
+  ~Derived2();
+};
+void useCompleteDtor(Derived2 *p) { delete p; } // expected-note {{in implicit destructor for 't3::Derived2' first required here}}
+}
Index: clang/test/CodeGenCXX/microsoft-abi-vbase-dtor.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/microsoft-abi-vbase-dtor.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c++17 -emit-llvm %s -triple x86_64-windows-msvc -o - | FileCheck %s
+
+// Make sure virtual base base destructors get referenced and emitted if
+// necessary when the complete ("vbase") destructor is emitted. In this case,
+// clang previously did not emit ~DefaultedDtor.
+struct HasDtor { ~HasDtor(); };
+struct DefaultedDtor {
+  ~DefaultedDtor() = default;
+  HasDtor o;
+};
+struct HasCompleteDtor : virtual DefaultedDtor {
+  ~HasCompleteDtor();
+};
+void useCompleteDtor(HasCompleteDtor *p) { delete p; }
+
+// CHECK-LABEL: define dso_local void @"?useCompleteDtor@@YAXPEAUHasCompleteDtor@@@Z"(%struct.HasCompleteDtor* %p)
+// CHECK: call void @"??_DHasCompleteDtor@@QEAAXXZ"({{.*}})
+
+// CHECK-LABEL: define linkonce_odr dso_local void @"??_DHasCompleteDtor@@QEAAXXZ"(%struct.HasCompleteDtor* %this)
+// CHECK: call void @"??1HasCompleteDtor@@QEAA@XZ"({{.*}})
+// CHECK: call void @"??1DefaultedDtor@@QEAA@XZ"({{.*}})
+
+// CHECK-LABEL: define linkonce_odr dso_local void @"??1DefaultedDtor@@QEAA@XZ"(%struct.DefaultedDtor* %this)
+// CHECK: call void @"??1HasDtor@@QEAA@XZ"(%struct.HasDtor* %{{.*}})
+
Index: clang/test/CXX/class.access/p4.cpp
===
--- clang/test/CXX/class.access/p4.cpp
+++ clang/test/CXX/class.access/p4.cpp
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++98 %s
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++98 %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-compatibility-version=19 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++98 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-compatibility-version=19 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_c

[PATCH] D77041: [AST] Fix a crash on invalid constexpr Ctorinitializer when building RecoveryExpr.

2020-03-31 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:3459-3461
+  if (MemInit.get()->getInit() &&
+  MemInit.get()->getInit()->containsErrors())
+AnyErrors = true;

The parser should not be inspecting properties of `Expr`s -- that's a layering 
violation. Can you move this logic into `ActOnMemInitializers` instead?



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:1688
 CheckConstexprKind Kind) {
+  assert(!NewFD->isInvalidDecl());
   const CXXMethodDecl *MD = dyn_cast(NewFD);

Instead of asserting this, please just return false on an invalid declaration. 
There's nothing fundamentally wrong with calling this function on an invalid 
declaration, but as usual, if we encounter something invalid, we should 
suppress follow-on diagnostics.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:5005
+if (Member->getInit() && Member->getInit()->containsErrors())
+  Constructor->setInvalidDecl();
 if (Member->isBaseInitializer())

This is inappropriate. The "invalid" bit on a declaration indicates whether the 
declaration is invalid, not whether the definition is invalid.

What we should do is add a "contains errors" bit to `Stmt`, and mark the 
function body as containing errors if it has an initializer that contains an 
error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77041



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


[PATCH] D77041: [AST] Fix a crash on invalid constexpr Ctorinitializer when building RecoveryExpr.

2020-03-31 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:5005
+if (Member->getInit() && Member->getInit()->containsErrors())
+  Constructor->setInvalidDecl();
 if (Member->isBaseInitializer())

rsmith wrote:
> This is inappropriate. The "invalid" bit on a declaration indicates whether 
> the declaration is invalid, not whether the definition is invalid.
> 
> What we should do is add a "contains errors" bit to `Stmt`, and mark the 
> function body as containing errors if it has an initializer that contains an 
> error.
As an example of why this distinction matters: the "contains errors" bit 
indicates whether external users of the declaration should ignore it / suppress 
errors on it, or whether they can still treat it as a regular declaration. It's 
not ideal for an error in the body of a function to affect the diagnostic 
behavior of a caller to that function, since the body is (typically) irrelevant 
to the validity of that caller.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77041



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


[clang] 58a0567 - Revert "[InlineFunction] Handle return attributes on call within inlined body"

2020-03-31 Thread Anna Thomas via cfe-commits

Author: Anna Thomas
Date: 2020-03-31T16:16:34-04:00
New Revision: 58a05675daf46b2e9c336dd13ae6ac6dbfdc2c72

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

LOG: Revert "[InlineFunction] Handle return attributes on call within inlined 
body"

This reverts commit 28518d9ae39ff5c6044e230d58b6ae28b0252cae.
There is a failure in MsgPackReader.cpp when built with clang. It
complains about "signext and zeroext" are incompatible. Investigating
offline if it is infact a UB in the MsgPackReader code.

Added: 


Modified: 
clang/test/CodeGen/builtins-systemz-zvector.c
clang/test/CodeGen/builtins-systemz-zvector2.c
clang/test/CodeGen/movbe-builtins.c
clang/test/CodeGen/rot-intrinsics.c
llvm/lib/Transforms/Utils/InlineFunction.cpp

Removed: 
llvm/test/Transforms/Inline/ret_attr_update.ll



diff  --git a/clang/test/CodeGen/builtins-systemz-zvector.c 
b/clang/test/CodeGen/builtins-systemz-zvector.c
index 6cba71098792..da0e720c9fae 100644
--- a/clang/test/CodeGen/builtins-systemz-zvector.c
+++ b/clang/test/CodeGen/builtins-systemz-zvector.c
@@ -3665,31 +3665,31 @@ void test_integer(void) {
   // CHECK-ASM: vsumqg
 
   idx = vec_test_mask(vsc, vuc);
-  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
+  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vuc, vuc);
-  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
+  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vss, vus);
-  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
+  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vus, vus);
-  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
+  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vsi, vui);
-  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
+  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vui, vui);
-  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
+  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vsl, vul);
-  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
+  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vul, vul);
-  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
+  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vd, vul);
-  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
+  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   // CHECK-ASM: vtm
 }
 

diff  --git a/clang/test/CodeGen/builtins-systemz-zvector2.c 
b/clang/test/CodeGen/builtins-systemz-zvector2.c
index 1880fed64dbc..a4f791e6019b 100644
--- a/clang/test/CodeGen/builtins-systemz-zvector2.c
+++ b/clang/test/CodeGen/builtins-systemz-zvector2.c
@@ -654,10 +654,10 @@ void test_integer(void) {
   // CHECK-ASM: vsrlb
 
   idx = vec_test_mask(vf, vui);
-  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
+  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   // CHECK-ASM: vtm
   idx = vec_test_mask(vd, vul);
-  // CHECK: call signext i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> 
%{{.*}})
+  // CHECK: call i32 @llvm.s390.vtm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   // CHECK-ASM: vtm
 
   vuc = vec_msum_u128(vul, vul, vuc, 0);

diff  --git a/clang/test/CodeGen/movbe-builtins.c 
b/clang/test/CodeGen/movbe-builtins.c
index 15f49b84ec67..342f66391388 100644
--- a/clang/test/CodeGen/movbe-builtins.c
+++ b/clang/test/CodeGen/movbe-builtins.c
@@ -7,7 +7,7 @@
 short test_loadbe_i16(const short *P) {
   // CHECK-LABEL: @test_loadbe_i16
   // CHECK: [[LOAD:%.*]] = load i16, i16* %{{.*}}, align 1
-  // CHECK: call signext i16 @llvm.bswap.i16(i16 [[LOAD]])
+  // CHECK: call i16 @llvm.bswap.i16(i16 [[LOAD]])
   return _loadbe_i16(P);
 }
 

diff  --git a/clang/test/CodeGen/rot-intrinsics.c 
b/clang/test/CodeGen/rot-intrinsics.c
index 7b1ffb6ae3a6..dcdc54c4585a 100644
--- a/clang/test/CodeGen/rot-intrinsics.c
+++ b/clang/test/CodeGen/rot-intrinsics.c
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -ffreestanding -triple i686--linux -emit-llvm -mllvm 
-update-return-attrs=false %s -o - | FileCheck %s --check-prefixes 
CHECK,CHECK-32BIT-

[clang] 9a6a696 - [cmake] Link libc++ tests against static libc++/libc++abi in CrossWinToARMLinux.cmake

2020-03-31 Thread Sergej Jaskiewicz via cfe-commits

Author: Sergej Jaskiewicz
Date: 2020-03-31T23:36:36+03:00
New Revision: 9a6a696817bd6322d62db21aa17fe395af41f8ae

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

LOG: [cmake] Link libc++ tests against static libc++/libc++abi in 
CrossWinToARMLinux.cmake

Summary: Now that D72687 has landed, we can enable this setting in our cache 
file.

Reviewers: vvereschaka

Reviewed By: vvereschaka

Subscribers: mgorny, kristof.beyls, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/cmake/caches/CrossWinToARMLinux.cmake

Removed: 




diff  --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index 0d359a1609a5..3d1e961ada8d 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -86,6 +86,8 @@ set(LIBCXXABI_TARGET_TRIPLE 
"${CMAKE_C_COMPILER_TARGET}" CACHE S
 set(LIBCXXABI_SYSROOT   "${DEFAULT_SYSROOT}" CACHE STRING 
"")
 set(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI OFF CACHE BOOL "")
 set(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXOFF CACHE BOOL "")
+set(LIBCXX_LINK_TESTS_WITH_SHARED_LIBCXXABIOFF CACHE BOOL "")
+set(LIBCXX_LINK_TESTS_WITH_SHARED_LIBCXX   OFF CACHE BOOL "")
 
 set(LIBCXX_USE_COMPILER_RT  ON CACHE BOOL "")
 set(LIBCXX_TARGET_TRIPLE"${CMAKE_C_COMPILER_TARGET}" CACHE 
STRING "")



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


[PATCH] D77066: [analyzer] ApiModeling: Add buffer size arg constraint

2020-03-31 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

Please avoid to stuff in `CheckerContext` because this facility should be used 
by ExprEngine/Store as well.
Let us reword your API: `getDynamicSizeWithOffset(ProgramStateRef, SVal, 
SValBuilder &)`. Of course we are trying to obtain some buffer-ish size, that 
is the purpose of the entire API.
I also could imagine something like `getDynamicSizeMul(ProgramStateRef, const 
MemRegion &, const MemRegion &, SValBuilder &)`, as it is very common.

May it would make sense to use the API like:

  getDynamicSizeWithOffset(State, MR, SVB) {
Offset = State->getStoreManager().getStaticOffset(MR, SVB);
...
  }

This idea is similar to `MemRegionManager::getStaticSize(MR, SVB)`. Hopefully 
no-one needs dynamic offsets.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77066



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


[PATCH] D77022: [analyzer] Use IgnoreImpCasts() instead of reimplementing it.

2020-03-31 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso accepted this revision.
Charusso marked an inline comment as done.
Charusso added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp:512
+  return E->IgnoreImpCasts();
 }
 

thakis wrote:
> NoQ wrote:
> > Charusso wrote:
> > > I think it would make sense to remove the helper-function completely. 
> > > (Being used 2 times.)
> > Yup.
> I didn't do that because I liked the comment that this is for the _Nonnull 
> implicit ARC casts – if I inline the function I have to duplicate the comment.
Well, if you really like that, sure. I believe it is so common to avoid 
implicit casts we do not need to express it why.


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

https://reviews.llvm.org/D77022



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


[PATCH] D76384: Move FPFeatures from BinaryOperator bitfields to Trailing storage

2020-03-31 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 253983.
mibintc added a comment.

Here's another revision, I believe this handles all of @rjmccall 's requests.  
Thank you, John, for your review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76384

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/StmtVisitor.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/Analysis/CFG.cpp
  clang/lib/Analysis/ReachableCode.cpp
  clang/lib/Analysis/ThreadSafetyCommon.cpp
  clang/lib/Basic/LangOptions.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
  clang/lib/Frontend/Rewrite/RewriteObjC.cpp
  clang/lib/Index/IndexBody.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaPseudoObject.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/AST/ast-dump-expr-json.c
  clang/test/AST/ast-dump-expr.c
  clang/test/AST/dump.cpp
  clang/test/Import/compound-assign-op/test.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -431,10 +431,6 @@
 K = CXCursor_BinaryOperator;
 break;
 
-  case Stmt::CompoundAssignOperatorClass:
-K = CXCursor_CompoundAssignOperator;
-break;
-
   case Stmt::ConditionalOperatorClass:
 K = CXCursor_ConditionalOperator;
 break;
Index: clang/test/Import/compound-assign-op/test.cpp
===
--- clang/test/Import/compound-assign-op/test.cpp
+++ clang/test/Import/compound-assign-op/test.cpp
@@ -2,42 +2,42 @@
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '+='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '-='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '*='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '/='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '&='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '^='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '<<='
 
 // CHECK: VarDecl
 // CHECK-NEXT: Integer
-// CHECK-NEXT: CompoundAssignOperator
+// CHECK-NEXT: BinaryOperator
 // CHECK-SAME: '>>='
 
 void expr() {
Index: clang/test/AST/dump.cpp
===
--- clang/test/AST/dump.cpp
+++ clang/test/AST/dump.cpp
@@ -14,14 +14,14 @@
 #pragma omp declare reduction(fun : float : omp_out += omp_in) initializer(omp_priv = omp_orig + 15)
 
 // CHECK:  |-OMPDeclareReductionDecl {{.+}}  col:35 operator+ 'int' combiner 0x{{.+}}
-// CHECK-NEXT: | |-CompoundAssignOperator {{.+}}  'int' lvalue '*=' ComputeLHSTy='int' ComputeResultTy='int'
+// CHECK-NEXT: | |-BinaryOperator {{.+}}  'int' lvalue '*=' ComputeLHSTy='int' ComputeResultTy='int'
 // CHECK-NEXT: | | |-DeclRefExpr {{.+}}  'int' lvalue Var {{.+}} 'omp_out' 'int'
 // CHECK-NEXT: | | `-ImplicitCastExpr {{.+}}  'int' 
 // CHECK-NEXT: | |   `-DeclRefExpr {{.+}}  'int' lvalue Var {{.+}} 'omp_in' 'int'
 // CH

[PATCH] D77058: [Clang] Add llvm.loop.unroll.disable to loops with -fno-unroll-loops.

2020-03-31 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In D77058#1950019 , @tejohnson wrote:

> I think this is a good approach, rather than a per-function attribute, since 
> as mentioned this will be preserved through inlining.
>  @dexonsmith, does that seem reasonable to you? I missed the original patch 
> and agree with you that we don't want to fix this in LTO by passing the 
> option through to LTO.


SGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77058



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


[PATCH] D77168: Add a flag to debug automatic variable initialization

2020-03-31 Thread Jian Cai via Phabricator via cfe-commits
jcai19 created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add -ftrivial-auto-var-init-stop-after= to limit the number of times
stack variables are initialized when -ftrivial-auto-var-init= is used to
initialize stack variables to zero or a pattern. This flag can be used
to bisect uninitialized uses of a stack variable exposed by automatic
variable initialization, such as http://crrev.com/c/2020401.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77168

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3273,6 +3273,11 @@
   Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val;
   }
 
+  if (Arg *A = Args.getLastArg(OPT_ftrivial_auto_var_init_stop_after)) {
+unsigned Val = (unsigned)std::stoi(A->getValue());
+Opts.TrivialAutoVarInitStopAfter = Val;
+  }
+
   // Parse -fsanitize= arguments.
   parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
   Diags, Opts.Sanitize);
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3088,6 +3088,13 @@
 CmdArgs.push_back(
 Args.MakeArgString("-ftrivial-auto-var-init=" + TrivialAutoVarInit));
   }
+
+  if (Arg *A = 
Args.getLastArg(options::OPT_ftrivial_auto_var_init_stop_after)) {
+A->claim();
+StringRef Val = A->getValue();
+CmdArgs.push_back(
+Args.MakeArgString("-ftrivial-auto-var-init-stop-after=" + Val));
+  }
 }
 
 static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs) {
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1809,6 +1809,19 @@
 LangOptions::TrivialAutoVarInitKind::Uninitialized)
   return;
 
+unsigned StopAfter = 
getContext().getLangOpts().TrivialAutoVarInitStopAfter;
+if (StopAfter) {
+  static unsigned Counter = 0;
+  if (Counter >= StopAfter)
+return;
+  if (Counter++ == StopAfter - 1) {
+const DeclContext * CD = D.getParentFunctionOrMethod ();
+std::string FunctionName = 
(cast(CD))->getNameInfo().getAsString();
+StringRef SourceFileName = CGM.getModule().getSourceFileName();
+llvm::errs() << "The last variable initialized is " << D.getName() << 
" of function " << FunctionName << " in " << SourceFileName << "\n";
+  }
+}
+
 // Only initialize a __block's storage: we always initialize the header.
 if (emission.IsEscapingByRef && !locIsByrefHeader)
   Loc = emitBlockByrefAddress(Loc, &D, /*follow=*/false);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1799,6 +1799,8 @@
 def enable_trivial_var_init_zero : Flag<["-"], 
"enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
   Flags<[CC1Option, CoreOption]>,
   HelpText<"Trivial automatic variable initialization to zero is only here for 
benchmarks, it'll eventually be removed, and I'm OK with that because I'm only 
using it to benchmark">;
+def ftrivial_auto_var_init_stop_after : Joined<["-"], 
"ftrivial-auto-var-init-stop-after=">, Group,
+  Flags<[CC1Option, CoreOption]>, HelpText<"Stop initializing trivial 
automatic stack variables after the specified number of instances">;
 def fstandalone_debug : Flag<["-"], "fstandalone-debug">, Group, 
Flags<[CoreOption]>,
   HelpText<"Emit full debug info for all types used by the program">;
 def fno_standalone_debug : Flag<["-"], "fno-standalone-debug">, 
Group, Flags<[CoreOption]>,
Index: clang/include/clang/Basic/LangOptions.def
===
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -293,6 +293,8 @@
  "stack protector mode")
 ENUM_LANGOPT(TrivialAutoVarInit, TrivialAutoVarInitKind, 2, 
TrivialAutoVarInitKind::Uninitialized,
  "trivial automatic variable initialization")
+VALUE_LANGOPT(TrivialAutoVarInitStopAfter, 32, 0,
+ "stop trivial automatic variable initialization after the 
specified number of instances")
 ENUM_LANGOPT(SignedOverflowBehavior, SignedOverflowBehaviorTy, 2, 
SOB_Undefined,
  "signed integer overflow handling")
 


Index: clang/lib/Frontend/CompilerInvocation.cpp

[PATCH] D76323: [AST] Fix handling of long double and bool in __builtin_bit_cast

2020-03-31 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:6364-6371
+const llvm::fltSemantics &Semantics = Info.Ctx.getFloatTypeSemantics(Ty);
+unsigned NumBits = APFloat::semanticsSizeInBits(Semantics);
+assert(NumBits % 8 == 0);
+CharUnits Width = CharUnits::fromQuantity(NumBits / 8);
+SmallVector Bytes(Width.getQuantity());
+llvm::StoreIntToMemory(AsInt, &*Bytes.begin(), Width.getQuantity());
+Buffer.writeObject(Offset, Bytes);

rsmith wrote:
> This appears more complex than necessary. `bitcastToAPInt` already returned 
> the correct number of bits (eg, 80 for x86 fp80) so you don't need to compute 
> that yourself. How about leaving this function alone and changing `visitInt` 
> to store the number of (value representation) bits in the `APSInt` rather 
> than the full (object representation) width of the type? As is, `visitInt` 
> would also be wrong in the same way if the integer type had any full bytes of 
> padding.
Sure, this causes us to have to handle `bool` in visitInt, but I think we 
should have been doing that anyways.


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

https://reviews.llvm.org/D76323



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


  1   2   >