[PATCH] D85193: [clang] Do not use an invalid expression to update the initializer.

2020-08-12 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX updated this revision to Diff 284987.
ArcsinX added a comment.

Update comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85193

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/init-invalid-struct-array.c


Index: clang/test/Sema/init-invalid-struct-array.c
===
--- /dev/null
+++ clang/test/Sema/init-invalid-struct-array.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+struct S {
+  Unknown u; // expected-error {{unknown type name 'Unknown'}}
+  int i;
+};
+// Should not crash
+struct S s[] = {[0].i = 0, [1].i = 1, {}};
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -1585,10 +1585,7 @@
   IList->setInit(Index, ResultExpr);
 }
   }
-  if (hadError)
-++StructuredIndex;
-  else
-UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
+  UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
   ++Index;
 }
 
@@ -1643,10 +1640,7 @@
   if (!VerifyOnly && expr)
 IList->setInit(Index, expr);
 
-  if (hadError)
-++StructuredIndex;
-  else
-UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
+  UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
   ++Index;
 }
 
@@ -1697,11 +1691,7 @@
   IList->setInit(Index, ResultExpr);
 }
   }
-  if (hadError)
-++StructuredIndex;
-  else
-UpdateStructuredListElement(StructuredList, StructuredIndex,
-ResultExpr);
+  UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
   ++Index;
   return;
 }
@@ -3100,8 +3090,10 @@
 
   if (Expr *PrevInit = StructuredList->updateInit(SemaRef.Context,
   StructuredIndex, expr)) {
-// This initializer overwrites a previous initializer. Warn.
-diagnoseInitOverride(PrevInit, expr->getSourceRange());
+// This initializer overwrites a previous initializer.
+// Emit warning if `expr` is valid.
+if (expr)
+  diagnoseInitOverride(PrevInit, expr->getSourceRange());
   }
 
   ++StructuredIndex;


Index: clang/test/Sema/init-invalid-struct-array.c
===
--- /dev/null
+++ clang/test/Sema/init-invalid-struct-array.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+struct S {
+  Unknown u; // expected-error {{unknown type name 'Unknown'}}
+  int i;
+};
+// Should not crash
+struct S s[] = {[0].i = 0, [1].i = 1, {}};
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -1585,10 +1585,7 @@
   IList->setInit(Index, ResultExpr);
 }
   }
-  if (hadError)
-++StructuredIndex;
-  else
-UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
+  UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
   ++Index;
 }
 
@@ -1643,10 +1640,7 @@
   if (!VerifyOnly && expr)
 IList->setInit(Index, expr);
 
-  if (hadError)
-++StructuredIndex;
-  else
-UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
+  UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
   ++Index;
 }
 
@@ -1697,11 +1691,7 @@
   IList->setInit(Index, ResultExpr);
 }
   }
-  if (hadError)
-++StructuredIndex;
-  else
-UpdateStructuredListElement(StructuredList, StructuredIndex,
-ResultExpr);
+  UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
   ++Index;
   return;
 }
@@ -3100,8 +3090,10 @@
 
   if (Expr *PrevInit = StructuredList->updateInit(SemaRef.Context,
   StructuredIndex, expr)) {
-// This initializer overwrites a previous initializer. Warn.
-diagnoseInitOverride(PrevInit, expr->getSourceRange());
+// This initializer overwrites a previous initializer.
+// Emit warning if `expr` is valid.
+if (expr)
+  diagnoseInitOverride(PrevInit, expr->getSourceRange());
   }
 
   ++StructuredIndex;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85750: [SyntaxTree] Unbox operators into tokens for nodes generated from `CXXOperatorCallExpr`

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

use arguments instead of children


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85750

Files:
  clang/lib/Tooling/Syntax/BuildTree.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
@@ -2592,9 +2592,7 @@
 | | |-IdExpression
 | | | `-UnqualifiedId
 | | |   `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-=
+| | |-=
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2605,9 +2603,7 @@
 | | | `-IdExpression
 | | |   `-UnqualifiedId
 | | | `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-+
+| | |-+
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2617,9 +2613,7 @@
 | | |-IdExpression
 | | | `-UnqualifiedId
 | | |   `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-<
+| | |-<
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2629,9 +2623,7 @@
 | | |-IdExpression
 | | | `-UnqualifiedId
 | | |   `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-<<
+| | |-<<
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2641,9 +2633,7 @@
 | | |-IdExpression
 | | | `-UnqualifiedId
 | | |   `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-,
+| | |-,
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2730,27 +2720,21 @@
 |-{
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-++
+| | |-++
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-x
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-!
+| | |-!
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-x
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-&
+| | |-&
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-x
@@ -2809,9 +2793,7 @@
 | | |-IdExpression
 | | | `-UnqualifiedId
 | | |   `-x
-| | `-IdExpression
-| |   `-UnqualifiedId
-| | `-++
+| | `-++
 | `-;
 `-}
 )txt"));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1007,23 +1007,26 @@
   }
 
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
-if (getOperatorNodeKind(*S) ==
-syntax::NodeKind::PostfixUnaryOperatorExpression) {
+// To construct a syntax tree of the same shape for calls to built-in and
+// user-defined operators, ignore the `DeclRefExpr` that refers to the
+// operator and treat it as a simple token. Do that by traversing
+// arguments instead of children.
+for (auto *child : S->arguments()) {
   // A postfix unary operator is declared as taking two operands. The
   // second operand is used to distinguish from its prefix counterpart. In
   // the semantic AST this "phantom" operand is represented as a
   // `IntegerLiteral` with invalid `SourceLocation`. We skip visiting this
   // operand because it does not correspond to anything written in source
-  // code
-  for (auto *child : S->children()) {
-if (child->getSourceRange().isInvalid())
-  continue;
-if (!TraverseStmt(child))
-  return false;
+  // code.
+  if (child->getSourceRange().isInvalid()) {
+assert(getOperatorNodeKind(*S) ==
+   syntax::NodeKind::PostfixUnaryOperatorExpression);
+continue;
   }
-  return WalkUpFromCXXOperatorCallExpr(S);
-} else
-  return RecursiveASTVisitor::TraverseCXXOperatorCallExpr(S);
+  if (!TraverseStmt(child))
+return false;
+}
+return WalkUpFromCXXOperatorCallExpr(S);
   }
 
   bool WalkUpFromCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85750: [SyntaxTree] Unbox operators into tokens for nodes generated from `CXXOperatorCallExpr`

2020-08-12 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:1024
+  // representation of built-in and user-defined operators.
+  if (child->getBeginLoc() == S->getOperatorLoc())
+continue;

gribozavr2 wrote:
> eduucaldas wrote:
> > Here we want to check if this child is just a DeclRefExpr to an operator - 
> > as opposed to an operand.
> > Is comparing SourceLocation generally safe?
> > Is there a better way of figuring out if the child DeclRefExpr refers to an 
> > operator?
> Comparing SourceLocations should work, but you're right that it is a 
> questionable pattern.
> 
> Iterating only over `S->arguments()` instead of all children could work here.
Very good tip!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85750

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


[PATCH] D85645: [AST] Fix the CXXFoldExpr source range when parentheses range is invalid.

2020-08-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/AST/ExprCXX.h:4582
+if (isLeftFold())
+  return getEllipsisLoc();
+return getLHS()->getBeginLoc();

nridge wrote:
> Can this case (left fold and no parenthesis) ever happen? It would be 
> interesting to see an example.
I think in theory it should not happen. Doing it here is for completeness, it 
seems a bit odd we only do the change for `getEndLoc`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85645

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


[PATCH] D85645: [AST] Fix the CXXFoldExpr source range when parentheses range is invalid.

2020-08-12 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdc7b1e9db581: [AST] Fix the CXXFoldExpr source range when 
parentheses range is invalid. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85645

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/test/AST/ast-dump-concepts.cpp


Index: clang/test/AST/ast-dump-concepts.cpp
===
--- clang/test/AST/ast-dump-concepts.cpp
+++ clang/test/AST/ast-dump-concepts.cpp
@@ -12,6 +12,9 @@
 template 
 concept binary_concept = true;
 
+template 
+concept variadic_concept = true;
+
 template 
 struct Foo {
   // CHECK:  TemplateTypeParmDecl {{.*}} referenced Concept {{.*}} 
'binary_concept'
@@ -37,4 +40,12 @@
   template 
   Foo(R, char) requires unary_concept {
   }
+
+  // CHECK: CXXFoldExpr {{.*}} 
+  template 
+  Foo();
+
+  // CHECK: CXXFoldExpr {{.*}} 
+  template ... Ts>
+  Foo();
 };
Index: clang/include/clang/AST/ExprCXX.h
===
--- clang/include/clang/AST/ExprCXX.h
+++ clang/include/clang/AST/ExprCXX.h
@@ -4575,9 +4575,21 @@
 return None;
   }
 
-  SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
+  SourceLocation getBeginLoc() const LLVM_READONLY {
+if (LParenLoc.isValid())
+  return LParenLoc;
+if (isLeftFold())
+  return getEllipsisLoc();
+return getLHS()->getBeginLoc();
+  }
 
-  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
+  SourceLocation getEndLoc() const LLVM_READONLY {
+if (RParenLoc.isValid())
+  return RParenLoc;
+if (isRightFold())
+  return getEllipsisLoc();
+return getRHS()->getEndLoc();
+  }
 
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == CXXFoldExprClass;


Index: clang/test/AST/ast-dump-concepts.cpp
===
--- clang/test/AST/ast-dump-concepts.cpp
+++ clang/test/AST/ast-dump-concepts.cpp
@@ -12,6 +12,9 @@
 template 
 concept binary_concept = true;
 
+template 
+concept variadic_concept = true;
+
 template 
 struct Foo {
   // CHECK:  TemplateTypeParmDecl {{.*}} referenced Concept {{.*}} 'binary_concept'
@@ -37,4 +40,12 @@
   template 
   Foo(R, char) requires unary_concept {
   }
+
+  // CHECK: CXXFoldExpr {{.*}} 
+  template 
+  Foo();
+
+  // CHECK: CXXFoldExpr {{.*}} 
+  template ... Ts>
+  Foo();
 };
Index: clang/include/clang/AST/ExprCXX.h
===
--- clang/include/clang/AST/ExprCXX.h
+++ clang/include/clang/AST/ExprCXX.h
@@ -4575,9 +4575,21 @@
 return None;
   }
 
-  SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
+  SourceLocation getBeginLoc() const LLVM_READONLY {
+if (LParenLoc.isValid())
+  return LParenLoc;
+if (isLeftFold())
+  return getEllipsisLoc();
+return getLHS()->getBeginLoc();
+  }
 
-  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
+  SourceLocation getEndLoc() const LLVM_READONLY {
+if (RParenLoc.isValid())
+  return RParenLoc;
+if (isRightFold())
+  return getEllipsisLoc();
+return getRHS()->getEndLoc();
+  }
 
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == CXXFoldExprClass;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] dc7b1e9 - [AST] Fix the CXXFoldExpr source range when parentheses range is invalid.

2020-08-12 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2020-08-12T09:20:23+02:00
New Revision: dc7b1e9db58152273d3232cca3fa95cef721796b

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

LOG: [AST] Fix the CXXFoldExpr source range when parentheses range is invalid.

The CXXFoldExpr's range is invalid if the cxxfoldexpr is formed via the
Concept's TypeContraints (because the parentheses are not written in the
source code). We fallback to use the range from the pattern.

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

Added: 


Modified: 
clang/include/clang/AST/ExprCXX.h
clang/test/AST/ast-dump-concepts.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index b53bb20f7ebc..6b4b57eca9be 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -4575,9 +4575,21 @@ class CXXFoldExpr : public Expr {
 return None;
   }
 
-  SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
+  SourceLocation getBeginLoc() const LLVM_READONLY {
+if (LParenLoc.isValid())
+  return LParenLoc;
+if (isLeftFold())
+  return getEllipsisLoc();
+return getLHS()->getBeginLoc();
+  }
 
-  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
+  SourceLocation getEndLoc() const LLVM_READONLY {
+if (RParenLoc.isValid())
+  return RParenLoc;
+if (isRightFold())
+  return getEllipsisLoc();
+return getRHS()->getEndLoc();
+  }
 
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == CXXFoldExprClass;

diff  --git a/clang/test/AST/ast-dump-concepts.cpp 
b/clang/test/AST/ast-dump-concepts.cpp
index 524ac0f65a06..dff300a55951 100644
--- a/clang/test/AST/ast-dump-concepts.cpp
+++ b/clang/test/AST/ast-dump-concepts.cpp
@@ -12,6 +12,9 @@ concept unary_concept = true;
 template 
 concept binary_concept = true;
 
+template 
+concept variadic_concept = true;
+
 template 
 struct Foo {
   // CHECK:  TemplateTypeParmDecl {{.*}} referenced Concept {{.*}} 
'binary_concept'
@@ -37,4 +40,12 @@ struct Foo {
   template 
   Foo(R, char) requires unary_concept {
   }
+
+  // CHECK: CXXFoldExpr {{.*}} 
+  template 
+  Foo();
+
+  // CHECK: CXXFoldExpr {{.*}} 
+  template ... Ts>
+  Foo();
 };



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


[PATCH] D85105: [doxygen] Fix bad doxygen results for BugReporterVisitors.h

2020-08-12 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

Awesome, thanks!  Bt, maybe we can use `\ref` form, it looks like it's a 
preferred form in the codebase.


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

https://reviews.llvm.org/D85105

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


[PATCH] D85105: [doxygen] Fix bad doxygen results for BugReporterVisitors.h

2020-08-12 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie updated this revision to Diff 284991.
OikawaKirie added a comment.

Ok, I got it. I will pay attention to this in the future submits.


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

https://reviews.llvm.org/D85105

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h


Index: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
===
--- clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
+++ clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
@@ -53,7 +53,7 @@
   /// Note that this function does *not* get run on the very last node
   /// of the report, as the PathDiagnosticPiece associated with the
   /// last node should be unique.
-  /// Use {@code getEndPath} to customize the note associated with the report
+  /// Use \ref getEndPath to customize the note associated with the report
   /// end instead.
   ///
   /// The last parameter can be used to register a new visitor with the given


Index: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
===
--- clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
+++ clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
@@ -53,7 +53,7 @@
   /// Note that this function does *not* get run on the very last node
   /// of the report, as the PathDiagnosticPiece associated with the
   /// last node should be unique.
-  /// Use {@code getEndPath} to customize the note associated with the report
+  /// Use \ref getEndPath to customize the note associated with the report
   /// end instead.
   ///
   /// The last parameter can be used to register a new visitor with the given
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84886: Create LoopNestPass

2020-08-12 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D84886#2212202 , @TaWeiTu wrote:

> @ychen Again, thanks for your comment!
>
> 1. Currently, `LoopInterchange` returns immediately if the loop is not a 
> top-level one. The main purpose of the loop nest pass is to prevent 
> situations like this and possibly save compiling time of uninteresting calls 
> to `run`.

I think it would be good to convert 1 or 2 passes to use the new system and 
evaluate the potential benefits (reduced compile-time, better results).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84886

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


[PATCH] D82657: [AST][RecoveryAST] Preserve the type by default for recovery expression.

2020-08-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 284995.
hokein added a comment.

rebase and adjust more existing diagnostic tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82657

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CXX/temp/temp.constr/temp.constr.order/function-templates.cpp
  clang/test/SemaCXX/abstract.cpp
  clang/test/SemaCXX/decl-expr-ambiguity.cpp
  clang/test/SemaCXX/type-convert-construct.cpp
  clang/test/SemaTemplate/dependent-names.cpp


Index: clang/test/SemaTemplate/dependent-names.cpp
===
--- clang/test/SemaTemplate/dependent-names.cpp
+++ clang/test/SemaTemplate/dependent-names.cpp
@@ -173,7 +173,7 @@
 
 
   namespace O {
-void f(char&); // expected-note {{candidate function not viable}}
+int f(char&); // expected-note {{candidate function not viable}}
 
 template struct C {
   static const int n = f(T()); // expected-error {{no matching function}}
Index: clang/test/SemaCXX/type-convert-construct.cpp
===
--- clang/test/SemaCXX/type-convert-construct.cpp
+++ clang/test/SemaCXX/type-convert-construct.cpp
@@ -6,7 +6,8 @@
   float v1 = float(1);
   int v2 = typeof(int)(1,2); // expected-error {{excess elements in scalar 
initializer}}
   typedef int arr[];
-  int v3 = arr(); // expected-error {{array types cannot be value-initialized}}
+  int v3 = arr(); // expected-error {{array types cannot be 
value-initialized}} \
+ expected-error {{cannot initialize a variable of type 
'int' with an rvalue of type 'arr'}}
   typedef void fn_ty();
   fn_ty(); // expected-error {{cannot create object of function type 'fn_ty'}}
   fn_ty(0); // expected-error {{functional-style cast from 'int' to 'fn_ty'}}
Index: clang/test/SemaCXX/decl-expr-ambiguity.cpp
===
--- clang/test/SemaCXX/decl-expr-ambiguity.cpp
+++ clang/test/SemaCXX/decl-expr-ambiguity.cpp
@@ -12,7 +12,7 @@
   T(a)->m = 7;
   int(a)++; // expected-error {{assignment to cast is illegal}}
   __extension__ int(a)++; // expected-error {{assignment to cast is illegal}}
-  __typeof(int)(a,5)<()));
-// expected-error@-1 {{call to 'f' is ambiguous}}
+// expected-error@-1 {{call to 'f' is ambiguous}} \
+   expected-error@-1 {{invalid application of 'sizeof' to an incomplete type 
'void'}}
 
 template
 concept C3 = true;
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2926,8 +2926,8 @@
   // Recovery AST still heavily relies on dependent-type machinery.
   Opts.RecoveryAST =
   Args.hasFlag(OPT_frecovery_ast, OPT_fno_recovery_ast, Opts.CPlusPlus);
-  Opts.RecoveryASTType =
-  Args.hasFlag(OPT_frecovery_ast_type, OPT_fno_recovery_ast_type, false);
+  Opts.RecoveryASTType = Args.hasFlag(
+  OPT_frecovery_ast_type, OPT_fno_recovery_ast_type, Opts.CPlusPlus);
   Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions);
   Opts.AccessControl = !Args.hasArg(OPT_fno_access_control);
   Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors);


Index: clang/test/SemaTemplate/dependent-names.cpp
===
--- clang/test/SemaTemplate/dependent-names.cpp
+++ clang/test/SemaTemplate/dependent-names.cpp
@@ -173,7 +173,7 @@
 
 
   namespace O {
-void f(char&); // expected-note {{candidate function not viable}}
+int f(char&); // expected-note {{candidate function not viable}}
 
 template struct C {
   static const int n = f(T()); // expected-error {{no matching function}}
Index: clang/test/SemaCXX/type-convert-construct.cpp
===
--- clang/test/SemaCXX/type-convert-construct.cpp
+++ clang/test/SemaCXX/type-convert-construct.cpp
@@ -6,7 +6,8 @@
   float v1 = float(1);
   int v2 = typeof(int)(1,2); // expected-error {{excess elements in scalar initializer}}
   typedef int arr[];
-  int v3 = arr(); // expected-error {{array types cannot be value-initialized}}
+  int v3 = arr(); // expected-error {{array types cannot be value-initialized}} \
+ expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'arr'}}
   typedef void fn_ty();
   fn_ty(); // expected-error {{cannot create object of function type 'fn_ty'}}
   fn_ty(0); // expected-error {{functional-style cast from 'int' to 'fn_ty'}}
Index: clang/test/SemaCXX/decl-expr-ambiguity.cpp
===
--- clang/test/SemaCXX/decl-expr-ambiguity.cpp
+++ clang/test/SemaCXX/decl-expr-ambiguity.cpp
@@ -12,7 +12,7 @@
   T(a)->m = 7;
   int(a)++; // expected-error {{assignment to ca

[PATCH] D82657: [AST][RecoveryAST] Preserve the type by default for recovery expression.

2020-08-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

> As you said, we can't land this before the branch cut, and we shouldn't land 
> this until we've run internal experiments to show it's not horribly crashy.

The internal experiment result is good, I think we're close to land it. After a 
new rebase, we need to adjust more diagnostics, but all of them look like good 
secondary-diagnostic improvements.




Comment at: clang/test/CXX/temp/temp.decls/temp.variadic/fixed-expansion.cpp:129
+  S &s1 = f({}, 0, 0.0); // expected-error {{no matching 
function}} \
+  expected-error {{non-const 
lvalue reference to type 'S' cannot bind to a value of 
unrelated type 'int'}}
 }

sammccall wrote:
> hokein wrote:
> > the secondary diagnostic is technically correct, but I don't quite like it, 
> > it is confusing, ok to leave it as-is? or fix that before landing this 
> > patch?
> I don't think it's technically correct (the `int` fallback is an 
> implementation artifact, albeit one that leaks quite often).
> This example looks pretty obscure though, it'd be nice to fix it at some 
> point but I don't think it's severe enough to block on the fix.
> 
> Fix ideas:
>  - the instantiation of `f` should be invalid, right? Maybe we avoid 
> considering return types for invalid decls when computing recovery type (or 
> always give up in this case).
>  - we could eventually try to replace the use of `int` for these cases
>  - we could special-case `int`, and don't allow RecoveryExprs to have type 
> `int`, reflecting the fact that it's used for these cases
Fixed in D85714.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82657

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


[PATCH] D85728: [Analyzer] Support for the new variadic isa<> and isa_and_not_null<> in CastValueChecker

2020-08-12 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:265
+  SmallVector CastToTyVec;
+  for (unsigned idx = 0; idx < FD->getTemplateSpecializationArgs()->size() - 1;
+   ++idx) {

Do we intentionally skip the last arg with this loop boundary, or is the loop 
variable just off-by-one?


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

https://reviews.llvm.org/D85728

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


[clang] ac37afa - [SyntaxTree] Unbox operators into tokens for nodes generated from `CXXOperatorCallExpr`

2020-08-12 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-08-12T08:01:18Z
New Revision: ac37afa650271d8366b706d79ff8e217fc624cbb

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

LOG: [SyntaxTree] Unbox operators into tokens for nodes generated from 
`CXXOperatorCallExpr`

For an user define `<`, `x < y` would yield the syntax tree:
```
BinaryOperatorExpression
|-IdExpression
| `-UnqualifiedId
|   `-x
|-IdExpression
| `-UnqualifiedId
|   `-<
`-IdExpression
  `-UnqualifiedId
`-y
```
But there is no syntatic difference at call site between call site or
built-in `<`. As such they should generate the same syntax tree, namely:
```
BinaryOperatorExpression
|-IdExpression
| `-UnqualifiedId
|   `-x
|-<
`-IdExpression
  `-UnqualifiedId
`-y
```

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

Added: 


Modified: 
clang/lib/Tooling/Syntax/BuildTree.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 90451539b3b4..11d399730040 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1007,23 +1007,26 @@ class BuildTreeVisitor : public 
RecursiveASTVisitor {
   }
 
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
-if (getOperatorNodeKind(*S) ==
-syntax::NodeKind::PostfixUnaryOperatorExpression) {
+// To construct a syntax tree of the same shape for calls to built-in and
+// user-defined operators, ignore the `DeclRefExpr` that refers to the
+// operator and treat it as a simple token. Do that by traversing
+// arguments instead of children.
+for (auto *child : S->arguments()) {
   // A postfix unary operator is declared as taking two operands. The
   // second operand is used to distinguish from its prefix counterpart. In
   // the semantic AST this "phantom" operand is represented as a
   // `IntegerLiteral` with invalid `SourceLocation`. We skip visiting this
   // operand because it does not correspond to anything written in source
-  // code
-  for (auto *child : S->children()) {
-if (child->getSourceRange().isInvalid())
-  continue;
-if (!TraverseStmt(child))
-  return false;
+  // code.
+  if (child->getSourceRange().isInvalid()) {
+assert(getOperatorNodeKind(*S) ==
+   syntax::NodeKind::PostfixUnaryOperatorExpression);
+continue;
   }
-  return WalkUpFromCXXOperatorCallExpr(S);
-} else
-  return RecursiveASTVisitor::TraverseCXXOperatorCallExpr(S);
+  if (!TraverseStmt(child))
+return false;
+}
+return WalkUpFromCXXOperatorCallExpr(S);
   }
 
   bool WalkUpFromCXXOperatorCallExpr(CXXOperatorCallExpr *S) {

diff  --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp 
b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 46101660df8e..a5d1a4bfcacf 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -2592,9 +2592,7 @@ void test(X x, X y, X* xp, int X::* pmi) {
 | | |-IdExpression
 | | | `-UnqualifiedId
 | | |   `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-=
+| | |-=
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2605,9 +2603,7 @@ void test(X x, X y, X* xp, int X::* pmi) {
 | | | `-IdExpression
 | | |   `-UnqualifiedId
 | | | `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-+
+| | |-+
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2617,9 +2613,7 @@ void test(X x, X y, X* xp, int X::* pmi) {
 | | |-IdExpression
 | | | `-UnqualifiedId
 | | |   `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-<
+| | |-<
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2629,9 +2623,7 @@ void test(X x, X y, X* xp, int X::* pmi) {
 | | |-IdExpression
 | | | `-UnqualifiedId
 | | |   `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-<<
+| | |-<<
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2641,9 +2633,7 @@ void test(X x, X y, X* xp, int X::* pmi) {
 | | |-IdExpression
 | | | `-UnqualifiedId
 | | |   `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-,
+| | |-,
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2730,27 +2720,21 @@ void test(X x) {
 |-{
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-++
+| | |-++
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-x
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperato

[PATCH] D85750: [SyntaxTree] Unbox operators into tokens for nodes generated from `CXXOperatorCallExpr`

2020-08-12 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGac37afa65027: [SyntaxTree] Unbox operators into tokens for 
nodes generated from… (authored by eduucaldas).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85750

Files:
  clang/lib/Tooling/Syntax/BuildTree.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
@@ -2592,9 +2592,7 @@
 | | |-IdExpression
 | | | `-UnqualifiedId
 | | |   `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-=
+| | |-=
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2605,9 +2603,7 @@
 | | | `-IdExpression
 | | |   `-UnqualifiedId
 | | | `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-+
+| | |-+
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2617,9 +2613,7 @@
 | | |-IdExpression
 | | | `-UnqualifiedId
 | | |   `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-<
+| | |-<
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2629,9 +2623,7 @@
 | | |-IdExpression
 | | | `-UnqualifiedId
 | | |   `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-<<
+| | |-<<
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2641,9 +2633,7 @@
 | | |-IdExpression
 | | | `-UnqualifiedId
 | | |   `-x
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-,
+| | |-,
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-y
@@ -2730,27 +2720,21 @@
 |-{
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-++
+| | |-++
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-x
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-!
+| | |-!
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-x
 | `-;
 |-ExpressionStatement
 | |-PrefixUnaryOperatorExpression
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-&
+| | |-&
 | | `-IdExpression
 | |   `-UnqualifiedId
 | | `-x
@@ -2809,9 +2793,7 @@
 | | |-IdExpression
 | | | `-UnqualifiedId
 | | |   `-x
-| | `-IdExpression
-| |   `-UnqualifiedId
-| | `-++
+| | `-++
 | `-;
 `-}
 )txt"));
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1007,23 +1007,26 @@
   }
 
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
-if (getOperatorNodeKind(*S) ==
-syntax::NodeKind::PostfixUnaryOperatorExpression) {
+// To construct a syntax tree of the same shape for calls to built-in and
+// user-defined operators, ignore the `DeclRefExpr` that refers to the
+// operator and treat it as a simple token. Do that by traversing
+// arguments instead of children.
+for (auto *child : S->arguments()) {
   // A postfix unary operator is declared as taking two operands. The
   // second operand is used to distinguish from its prefix counterpart. In
   // the semantic AST this "phantom" operand is represented as a
   // `IntegerLiteral` with invalid `SourceLocation`. We skip visiting this
   // operand because it does not correspond to anything written in source
-  // code
-  for (auto *child : S->children()) {
-if (child->getSourceRange().isInvalid())
-  continue;
-if (!TraverseStmt(child))
-  return false;
+  // code.
+  if (child->getSourceRange().isInvalid()) {
+assert(getOperatorNodeKind(*S) ==
+   syntax::NodeKind::PostfixUnaryOperatorExpression);
+continue;
   }
-  return WalkUpFromCXXOperatorCallExpr(S);
-} else
-  return RecursiveASTVisitor::TraverseCXXOperatorCallExpr(S);
+  if (!TraverseStmt(child))
+return false;
+}
+return WalkUpFromCXXOperatorCallExpr(S);
   }
 
   bool WalkUpFromCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85817: [analyzer] Fix crash with pointer to members values

2020-08-12 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko created this revision.
vsavchenko added reviewers: NoQ, dcoughlin, xazax.hun, Szelethus.
Herald added subscribers: cfe-commits, steakhal, ASDenysPetrov, martong, 
Charusso, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
baloghadamsoftware.
Herald added a project: clang.
vsavchenko requested review of this revision.

This fix unifies all of the different ways we handled pointer to
members into one.  The crash was caused by the fact that the type
of pointer-to-member values was `void *`, and while this works
for the vast majority of cases it breaks when we actually need
to explain the path for the report.

rdar://problem/64202361


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85817

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SVals.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/test/Analysis/PR46264.cpp
  clang/test/Analysis/pointer-to-member.cpp

Index: clang/test/Analysis/pointer-to-member.cpp
===
--- clang/test/Analysis/pointer-to-member.cpp
+++ clang/test/Analysis/pointer-to-member.cpp
@@ -233,39 +233,57 @@
 
 namespace testAnonymousMember {
 struct A {
+  int a;
   struct {
-int x;
+int b;
+int c;
   };
   struct {
 struct {
-  int y;
+  int d;
+  int e;
 };
   };
   struct {
 union {
-  int z;
+  int f;
 };
   };
 };
 
 void test() {
-  clang_analyzer_eval(&A::x); // expected-warning{{TRUE}}
-  clang_analyzer_eval(&A::y); // expected-warning{{TRUE}}
-  clang_analyzer_eval(&A::z); // expected-warning{{TRUE}}
+  clang_analyzer_eval(&A::a); // expected-warning{{TRUE}}
+  clang_analyzer_eval(&A::b); // expected-warning{{TRUE}}
+  clang_analyzer_eval(&A::c); // expected-warning{{TRUE}}
+  clang_analyzer_eval(&A::d); // expected-warning{{TRUE}}
+  clang_analyzer_eval(&A::e); // expected-warning{{TRUE}}
+  clang_analyzer_eval(&A::f); // expected-warning{{TRUE}}
+
+  int A::*ap = &A::a,
+  A::*bp = &A::b,
+  A::*cp = &A::c,
+  A::*dp = &A::d,
+  A::*ep = &A::e,
+  A::*fp = &A::f;
+
+  clang_analyzer_eval(ap); // expected-warning{{TRUE}}
+  clang_analyzer_eval(bp); // expected-warning{{TRUE}}
+  clang_analyzer_eval(cp); // expected-warning{{TRUE}}
+  clang_analyzer_eval(dp); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ep); // expected-warning{{TRUE}}
+  clang_analyzer_eval(fp); // expected-warning{{TRUE}}
 
-  // FIXME: These should be true.
-  int A::*l = &A::x, A::*m = &A::y, A::*n = &A::z;
-  clang_analyzer_eval(l); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(m); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(n); // expected-warning{{UNKNOWN}}
-
-  // FIXME: These should be true as well.
   A a;
-  a.x = 1;
-  clang_analyzer_eval(a.*l == 1); // expected-warning{{UNKNOWN}}
-  a.y = 2;
-  clang_analyzer_eval(a.*m == 2); // expected-warning{{UNKNOWN}}
-  a.z = 3;
-  clang_analyzer_eval(a.*n == 3); // expected-warning{{UNKNOWN}}
+  a.a = 1;
+  a.b = 2;
+  a.c = 3;
+  a.d = 4;
+  a.e = 5;
+
+  clang_analyzer_eval(a.*ap == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(a.*bp == 2); // expected-warning{{TRUE}}
+  clang_analyzer_eval(a.*cp == 3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(a.*dp == 4); // expected-warning{{TRUE}}
+  clang_analyzer_eval(a.*ep == 5); // expected-warning{{TRUE}}
 }
-} // end of testAnonymousMember namespace
+} // namespace testAnonymousMember
Index: clang/test/Analysis/PR46264.cpp
===
--- /dev/null
+++ clang/test/Analysis/PR46264.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
+
+// rdar://problem/64202361
+
+namespace a {
+class b {
+public:
+  typedef int b::*c;
+  operator c() { return &b::d; }
+  int d;
+};
+} // namespace a
+
+using a::b;
+class e {
+  void f();
+  void g();
+  b h;
+};
+
+void e::f() {
+  e *i;
+  if (h)// no crash
+i->g(); // expected-warning{{Called C++ object pointer is uninitialized}}
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -1106,19 +1106,28 @@
 }
 
 SVal SimpleSValBuilder::evalBinOpLN(ProgramStateRef state,
-  BinaryOperator::Opcode op,
-  Loc lhs, NonLoc rhs, QualType resultTy) {
+BinaryOperator::Opcode op, Loc lhs,
+ 

[PATCH] D85752: [Analyzer] Store the pointed/referenced type for dynamic casts

2020-08-12 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

@baloghadamsoftware Maybe there is a typo in the summary of the patch

> then `&B` //is a// `&B`

Shouldn't this be "&A is a &B"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85752

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


[PATCH] D84932: [builtins] Add more test cases for __div[sdt]f3 LibCalls

2020-08-12 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84932

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


[PATCH] D85819: [SyntaxTree] Split tests

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

We do that because:

- Big tests generated big tree dumps that could hardly serve as documentation.
- In most cases the tests didn't share setup, thus there was not much addition 
in lines of code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85819

Files:
  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
@@ -632,26 +632,48 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, UnqualifiedId) {
+TEST_P(SyntaxTreeTest, UnqualifiedIdIdentifier) {
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test(int a) {
+  a;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-a
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdOperatorFunctionId) {
   if (!GetParam().isCXX()) {
 return;
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
 struct X {
-  // TODO: Expose `id-expression` from `Declarator`
   friend X operator+(const X&, const X&);
-  operator int();
 };
-template
-void f(T&);
 void test(X x) {
-  x;  // identifier
-  operator+(x, x);// operator-function-id
-  f(x);// template-id
-  // TODO: Expose `id-expression` from `MemberExpr`
-  x.operator int();   // conversion-funtion-id
-  x.~X(); // ~type-name
+  operator+(x, x);
 }
 )cpp",
   R"txt(
@@ -682,35 +704,8 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
-| |-SimpleDeclaration
-| | |-SimpleDeclarator
-| | | |-operator
-| | | |-int
-| | | `-ParametersAndQualifiers
-| | |   |-(
-| | |   `-)
-| | `-;
 | |-}
 | `-;
-|-TemplateDeclaration
-| |-template
-| |-<
-| |-UnknownDeclaration
-| | |-typename
-| | `-T
-| |->
-| `-SimpleDeclaration
-|   |-void
-|   |-SimpleDeclarator
-|   | |-f
-|   | `-ParametersAndQualifiers
-|   |   |-(
-|   |   |-SimpleDeclaration
-|   |   | |-T
-|   |   | `-SimpleDeclarator
-|   |   |   `-&
-|   |   `-)
-|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -725,11 +720,6 @@
   `-CompoundStatement
 |-{
 |-ExpressionStatement
-| |-IdExpression
-| | `-UnqualifiedId
-| |   `-x
-| `-;
-|-ExpressionStatement
 | |-UnknownExpression
 | | |-IdExpression
 | | | `-UnqualifiedId
@@ -745,20 +735,53 @@
 | | |   `-x
 | | `-)
 | `-;
-|-ExpressionStatement
-| |-UnknownExpression
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   |-f
-| | |   |-<
-| | |   |-X
-| | |   `->
-| | |-(
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-x
-| | `-)
-| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdConversionFunctionId) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  operator int();
+};
+void test(X x) {
+  // TODO: Expose `id-expression` from `MemberExpr`
+  x.operator int();
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-int
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
 |-ExpressionStatement
 | |-UnknownExpression
 | | |-UnknownExpression
@@ -771,6 +794,93 @@
 | | |-(
 | | `-)
 | `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdLiteralOperatorId) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+unsigned operator "" _w(char);
+void test() {
+  operator "" _w('1');
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-char
+| |   `-)
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   |-operator
+| | |   |-""
+| | |   `-_w
+| | |-(
+| | |-CharacterLiteralExpression
+| | | `-'1'
+| | `-)
+| `-;
+`-}
+)txt"));

[PATCH] D85031: [builtins] Unify the softfloat division implementation

2020-08-12 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko added a comment.

On linter diagnostics: error messages are due to linter trying to lint `*.inc` 
file that is not self-contained by design. D85731: [builtins] Make 
softfloat-related errors less noisy  tries to 
make those errors more meaningful, at least.

Some of `readability-identifier-naming` warnings are just due to code style of 
runtime library written in C being different from the most of LLVM C++ code 
base, while some //may// signify actual issues with my variables' names (but 
here the preference was to carry as much hints as possible in names).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85031

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


[PATCH] D85819: [SyntaxTree] Split tests

2020-08-12 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added a comment.

Before we had an UnqualifiedId test that tested for everything in the grammar 
. Now we just split this test and 
test the alternatives separately.




Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:635
 
-TEST_P(SyntaxTreeTest, UnqualifiedId) {
+TEST_P(SyntaxTreeTest, UnqualifiedIdIdentifier) {
+  EXPECT_TRUE(treeDumpEqual(

It seems inappropriate to always repeat `UnqualfiiedId`, do you have any other 
suggestion?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85819

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


[PATCH] D85826: [clang] Make signature help work with dependent args

2020-08-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous.
Herald added a project: clang.
kadircet requested review of this revision.
Herald added a subscriber: ilya-biryukov.

Fixes https://github.com/clangd/clangd/issues/490


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85826

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp

Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5562,22 +5562,38 @@
 
   // FIXME: Provide support for variadic template functions.
   // Ignore type-dependent call expressions entirely.
-  if (!Fn || Fn->isTypeDependent() || anyNullArguments(Args) ||
-  Expr::hasAnyTypeDependentArguments(Args)) {
+  if (!Fn || Fn->isTypeDependent() || anyNullArguments(Args))
 return QualType();
+
+  SmallVector Results;
+
+  Expr *NakedFn = Fn->IgnoreParenCasts();
+  // In presence of dependent args we surface all posible signatures, without
+  // performing any semantic checks on availability. That's to improve user
+  // experience, it is better to see all overloads rather than none.
+  if (Expr::hasAnyTypeDependentArguments(Args)) {
+if (auto ULE = dyn_cast(NakedFn)) {
+  for (auto *D : ULE->decls())
+Results.push_back(ResultCandidate(D->getAsFunction()));
+} else if (auto UME = dyn_cast(NakedFn)) {
+  for (auto *D : UME->decls())
+Results.push_back(ResultCandidate(D->getAsFunction()));
+} else if (auto *ME = dyn_cast(NakedFn)) {
+  if (auto *FD = ME->getMemberDecl()->getAsFunction())
+Results.push_back(ResultCandidate(FD));
+}
+// FIXME: handle function pointers and lambdas.
+return ProduceSignatureHelp(*this, S, Results, Args.size(), OpenParLoc);
   }
 
   // Build an overload candidate set based on the functions we find.
   SourceLocation Loc = Fn->getExprLoc();
   OverloadCandidateSet CandidateSet(Loc, OverloadCandidateSet::CSK_Normal);
 
-  SmallVector Results;
-
-  Expr *NakedFn = Fn->IgnoreParenCasts();
-  if (auto ULE = dyn_cast(NakedFn))
+  if (auto ULE = dyn_cast(NakedFn)) {
 AddOverloadedCallCandidates(ULE, Args, CandidateSet,
 /*PartialOverloading=*/true);
-  else if (auto UME = dyn_cast(NakedFn)) {
+  } else if (auto UME = dyn_cast(NakedFn)) {
 TemplateArgumentListInfo TemplateArgsBuffer, *TemplateArgs = nullptr;
 if (UME->hasExplicitTemplateArgs()) {
   UME->copyTemplateArgumentsInto(TemplateArgsBuffer);
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1166,46 +1166,75 @@
 }
 
 TEST(SignatureHelpTest, OpeningParen) {
-  llvm::StringLiteral Tests[] = {// Recursive function call.
- R"cpp(
-int foo(int a, int b, int c);
-int main() {
-  foo(foo $p^( foo(10, 10, 10), ^ )));
-})cpp",
- // Functional type cast.
- R"cpp(
-struct Foo {
-  Foo(int a, int b, int c);
-};
-int main() {
-  Foo $p^( 10, ^ );
-})cpp",
- // New expression.
- R"cpp(
-struct Foo {
-  Foo(int a, int b, int c);
-};
-int main() {
-  new Foo $p^( 10, ^ );
-})cpp",
- // Macro expansion.
- R"cpp(
-int foo(int a, int b, int c);
-#define FOO foo(
-
-int main() {
-  // Macro expansions.
-  $p^FOO 10, ^ );
-})cpp",
- // Macro arguments.
- R"cpp(
-int foo(int a, int b, int c);
-int main() {
-#define ID(X) X
-  // FIXME: figure out why ID(foo (foo(10), )) doesn't work when preserving
-  // the recovery expression.
-  ID(foo $p^( 10, ^ ))
-})cpp"};
+  llvm::StringLiteral Tests[] = {
+  // Recursive function call.
+  R"cpp(
+int foo(int a, int b, int c);
+int main() {
+  foo(foo $p^( foo(10, 10, 10), ^ )));
+})cpp",
+  // Functional type cast.
+  R"cpp(
+struct Foo {
+  Foo(int a, int b, int c);
+};
+int main() {
+  Foo $p^( 10, ^ );
+})cpp",
+  // New expression.
+  R"cpp(
+struct Foo {
+  Foo(int a, int b, int c);
+};
+int main() {
+  new Foo $p^( 10, ^ );
+})cpp",
+  // Macro expansion.
+  R"cpp(
+int foo(int a, int b, int c);
+#define FOO foo(
+
+int main() {
+  // Macro expansions.
+  $p^FOO 10, ^ );
+})cpp",
+ 

[PATCH] D83224: [clangd] Move clang-tidy check modifications into ClangdServer

2020-08-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:210
 GetClangTidyOptions(*TFS.view(/*CWD=*/llvm::None), File);
+  if (!Opts.ClangTidyOpts.Checks) {
+// If the user hasn't configured clang-tidy checks at all, including

njames93 wrote:
> Should the `!` be removed the branches be swapped? Just looks cleaner imo, 
> WDYT? 
SGTM, will address once we've settled on the idea with Sam.

(and let this be a ping to him :D @sammccall )


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83224

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


[PATCH] D85819: [SyntaxTree] Split tests

2020-08-12 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 285035.
eduucaldas added a comment.

Split tests for `UserDefinedLiteral`
Split tests for `NumericUserDefinedLiteral`
Split tests for `NestedBinaryOperator`
Split tests for `UserDefinedBinaryOperator`
Split tests for `UserDefinedPrefixOperator`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85819

Files:
  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
@@ -632,26 +632,48 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, UnqualifiedId) {
+TEST_P(SyntaxTreeTest, UnqualifiedIdIdentifier) {
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test(int a) {
+  a;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-a
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdOperatorFunctionId) {
   if (!GetParam().isCXX()) {
 return;
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
 struct X {
-  // TODO: Expose `id-expression` from `Declarator`
   friend X operator+(const X&, const X&);
-  operator int();
 };
-template
-void f(T&);
 void test(X x) {
-  x;  // identifier
-  operator+(x, x);// operator-function-id
-  f(x);// template-id
-  // TODO: Expose `id-expression` from `MemberExpr`
-  x.operator int();   // conversion-funtion-id
-  x.~X(); // ~type-name
+  operator+(x, x);
 }
 )cpp",
   R"txt(
@@ -682,35 +704,8 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
-| |-SimpleDeclaration
-| | |-SimpleDeclarator
-| | | |-operator
-| | | |-int
-| | | `-ParametersAndQualifiers
-| | |   |-(
-| | |   `-)
-| | `-;
 | |-}
 | `-;
-|-TemplateDeclaration
-| |-template
-| |-<
-| |-UnknownDeclaration
-| | |-typename
-| | `-T
-| |->
-| `-SimpleDeclaration
-|   |-void
-|   |-SimpleDeclarator
-|   | |-f
-|   | `-ParametersAndQualifiers
-|   |   |-(
-|   |   |-SimpleDeclaration
-|   |   | |-T
-|   |   | `-SimpleDeclarator
-|   |   |   `-&
-|   |   `-)
-|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -725,11 +720,6 @@
   `-CompoundStatement
 |-{
 |-ExpressionStatement
-| |-IdExpression
-| | `-UnqualifiedId
-| |   `-x
-| `-;
-|-ExpressionStatement
 | |-UnknownExpression
 | | |-IdExpression
 | | | `-UnqualifiedId
@@ -745,20 +735,53 @@
 | | |   `-x
 | | `-)
 | `-;
-|-ExpressionStatement
-| |-UnknownExpression
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   |-f
-| | |   |-<
-| | |   |-X
-| | |   `->
-| | |-(
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-x
-| | `-)
-| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdConversionFunctionId) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  operator int();
+};
+void test(X x) {
+  // TODO: Expose `id-expression` from `MemberExpr`
+  x.operator int();
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-int
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
 |-ExpressionStatement
 | |-UnknownExpression
 | | |-UnknownExpression
@@ -771,6 +794,93 @@
 | | |-(
 | | `-)
 | `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdLiteralOperatorId) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+unsigned operator "" _w(char);
+void test() {
+  operator "" _w('1');
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-char
+| |   `-)
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   |-operator
+| | |   |-""
+| | |   `-_w
+| | |-(
+| | |-CharacterLiteralExpression
+| | | `-'1'
+| | `-)
+| `-;
+`-}
+)txt"))

[PATCH] D85752: [Analyzer] Store the pointed/referenced type for dynamic casts

2020-08-12 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 285036.
baloghadamsoftware added a comment.

Updated according to the comments.


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

https://reviews.llvm.org/D85752

Files:
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/lib/StaticAnalyzer/Core/DynamicType.cpp
  clang/test/Analysis/cast-value-state-dump.cpp


Index: clang/test/Analysis/cast-value-state-dump.cpp
===
--- clang/test/Analysis/cast-value-state-dump.cpp
+++ clang/test/Analysis/cast-value-state-dump.cpp
@@ -35,8 +35,8 @@
   // CHECK-NEXT: ],
   // CHECK-NEXT: "dynamic_casts": [
   // CHECK:{ "region": "SymRegion{reg_$0}", "casts": [
-  // CHECK-NEXT: { "from": "const struct clang::Shape *", "to": "const 
class clang::Circle *", "kind": "success" },
-  // CHECK-NEXT: { "from": "const struct clang::Shape *", "to": "const 
class clang::Square *", "kind": "fail" }
+  // CHECK-NEXT: { "from": "struct clang::Shape", "to": "class 
clang::Circle", "kind": "success" },
+  // CHECK-NEXT: { "from": "struct clang::Shape", "to": "class 
clang::Square", "kind": "fail" }
   // CHECK-NEXT:   ] }
 
   (void)(1 / !C);
Index: clang/lib/StaticAnalyzer/Core/DynamicType.cpp
===
--- clang/lib/StaticAnalyzer/Core/DynamicType.cpp
+++ clang/lib/StaticAnalyzer/Core/DynamicType.cpp
@@ -65,6 +65,16 @@
   return State->get(MR);
 }
 
+static void unbox(QualType &Ty) {
+  if (Ty->isReferenceType())
+Ty = Ty.getNonReferenceType();
+  Ty = Ty.getCanonicalType();
+  if (Ty->isPointerType())
+Ty = Ty->getPointeeType();
+  Ty = Ty.getCanonicalType();
+  Ty = Ty.getUnqualifiedType();
+}
+
 const DynamicCastInfo *getDynamicCastInfo(ProgramStateRef State,
   const MemRegion *MR,
   QualType CastFromTy,
@@ -73,6 +83,9 @@
   if (!Lookup)
 return nullptr;
 
+  unbox(CastFromTy);
+  unbox(CastToTy);
+
   for (const DynamicCastInfo &Cast : *Lookup)
 if (Cast.equals(CastFromTy, CastToTy))
   return &Cast;
@@ -112,6 +125,9 @@
 State = State->set(MR, CastToTy);
   }
 
+  unbox(CastFromTy);
+  unbox(CastToTy);
+
   DynamicCastInfo::CastResult ResultKind =
   CastSucceeds ? DynamicCastInfo::CastResult::Success
: DynamicCastInfo::CastResult::Failure;
Index: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
@@ -106,7 +106,7 @@
  QualType CastToTy, const Expr *Object,
  bool CastSucceeds, bool IsKnownCast) {
   std::string CastToName =
-  CastInfo ? CastInfo->to()->getPointeeCXXRecordDecl()->getNameAsString()
+  CastInfo ? CastInfo->to()->getAsCXXRecordDecl()->getNameAsString()
: CastToTy->getPointeeCXXRecordDecl()->getNameAsString();
   Object = Object->IgnoreParenImpCasts();
 


Index: clang/test/Analysis/cast-value-state-dump.cpp
===
--- clang/test/Analysis/cast-value-state-dump.cpp
+++ clang/test/Analysis/cast-value-state-dump.cpp
@@ -35,8 +35,8 @@
   // CHECK-NEXT: ],
   // CHECK-NEXT: "dynamic_casts": [
   // CHECK:{ "region": "SymRegion{reg_$0}", "casts": [
-  // CHECK-NEXT: { "from": "const struct clang::Shape *", "to": "const class clang::Circle *", "kind": "success" },
-  // CHECK-NEXT: { "from": "const struct clang::Shape *", "to": "const class clang::Square *", "kind": "fail" }
+  // CHECK-NEXT: { "from": "struct clang::Shape", "to": "class clang::Circle", "kind": "success" },
+  // CHECK-NEXT: { "from": "struct clang::Shape", "to": "class clang::Square", "kind": "fail" }
   // CHECK-NEXT:   ] }
 
   (void)(1 / !C);
Index: clang/lib/StaticAnalyzer/Core/DynamicType.cpp
===
--- clang/lib/StaticAnalyzer/Core/DynamicType.cpp
+++ clang/lib/StaticAnalyzer/Core/DynamicType.cpp
@@ -65,6 +65,16 @@
   return State->get(MR);
 }
 
+static void unbox(QualType &Ty) {
+  if (Ty->isReferenceType())
+Ty = Ty.getNonReferenceType();
+  Ty = Ty.getCanonicalType();
+  if (Ty->isPointerType())
+Ty = Ty->getPointeeType();
+  Ty = Ty.getCanonicalType();
+  Ty = Ty.getUnqualifiedType();
+}
+
 const DynamicCastInfo *getDynamicCastInfo(ProgramStateRef State,
   const MemRegion *MR,
   QualType CastFromTy,
@@ -73,6 +83,9 @@
   if (!Lookup)
 return nullptr;
 
+  unbox(CastFromTy);
+  unbox(CastToTy);
+
   for (const DynamicCastInfo &Cast : *Lookup)
 if (Cast.equals(CastFromTy, CastToTy))
   return &Cast;
@@ -112,6 +125,9 @@
 State = Sta

[PATCH] D85752: [Analyzer] Store the pointed/referenced type for dynamic casts

2020-08-12 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/DynamicType.cpp:73
+Ty = STTPTy->getReplacementType();
+  if (Ty->isPointerType())
+Ty = Ty->getPointeeType();

xazax.hun wrote:
> Is this doing what you intended? What about a reference to a pointer? 
> Wouldn't you do too much unboxing? 
> 
> Also, I think a function returning a value would be more conventional. 
> 
> Other sugars like typedefs cannot interfere? I think this patch might benefit 
> from additional test coverage. I also see no tests for template substitutions.
Reference to pointer cast using //LLVM//'s cast functions are syntactically 
invalid, they do not compile.

For `QualType` in-place modification is usual, since we use it by value.

I see no test coverage for this particular part of the analyzer specifically, 
it seems that its is only tested indirectly in the tests for `CastValueChecker`.


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

https://reviews.llvm.org/D85752

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


[PATCH] D85753: [clangd] Discard diagnostics from another SourceManager.

2020-08-12 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added inline comments.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:209
   // Update diag to point at include inside main file.
   D.File = SM.getFileEntryForID(SM.getMainFileID())->getName().str();
   D.Range = std::move(R);

kadircet wrote:
> can't we rather record the mainfilename once and make use of it here?
> i believe the rest of the logic operates on the local sourcelocations/files 
> associated with the sourcemanager inside the diagnostic in process.
getMainFileRange() doesn't.

We can easily get main file from the original source manager or record it in 
BeginSourceFile. The thing is that it's not easy to find a place in the main 
file to put this diagnostic at. We can, of course, put it at the top of the 
file, but normally we try to find the #include location in the main file. 
That's done in the getMainFileRange() above and it mixes the location of the 
diagnostic (which is for the new SourceManager) and the main file buffer (which 
is for the OrigSrcMgr).

I'm a bit worried that if we put a diagnostic relating to #include at the top 
of the file, where another #include may be, it will become very confusing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85753

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


[clang-tools-extra] 35bee35 - [clang-tidy] prevent generated checks from triggering assertions on anonymous functions

2020-08-12 Thread David Truby via cfe-commits

Author: Bogdan Serea
Date: 2020-08-12T12:43:40+01:00
New Revision: 35bee3503f4c33d92434a314e49e3e6f4f7419bc

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

LOG: [clang-tidy] prevent generated checks from triggering assertions on 
anonymous functions

Skeleton checks generated by clang-tidy add_check.py cause assertions to fail 
when run over anonymous functions(lambda functions). This patch introduces an 
additional check to verify that the target function is not anonymous before 
calling getName().
The code snippet from the [[ 
https://clang.llvm.org/extra/clang-tidy/Contributing.html | clang-tidy tutorial 
 ]]is also updated.

Reviewed By: alexfh, DavidTruby

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/add_new_check.py
clang-tools-extra/docs/clang-tidy/Contributing.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index 231f43c0b8f3..14fcfe8d49ff 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -136,7 +136,7 @@ def write_implementation(module_path, module, namespace, 
check_name_camel):
 void %(check_name)s::check(const MatchFinder::MatchResult &Result) {
   // FIXME: Add callback implementation.
   const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
-  if (MatchedDecl->getName().startswith("awesome_"))
+  if (!MatchedDecl->getIdentifier() || 
MatchedDecl->getName().startswith("awesome_"))
 return;
   diag(MatchedDecl->getLocation(), "function %%0 is insufficiently awesome")
   << MatchedDecl;

diff  --git a/clang-tools-extra/docs/clang-tidy/Contributing.rst 
b/clang-tools-extra/docs/clang-tidy/Contributing.rst
index 3ed6dadb5e8b..6b7af479804d 100644
--- a/clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ b/clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -202,7 +202,7 @@ can further inspect them and report diagnostics.
 
   void AwesomeFunctionNamesCheck::check(const MatchFinder::MatchResult 
&Result) {
 const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
-if (MatchedDecl->getName().startswith("awesome_"))
+if (!MatchedDecl->getIdentifier() || 
MatchedDecl->getName().startswith("awesome_"))
   return;
 diag(MatchedDecl->getLocation(), "function %0 is insufficiently awesome")
 << MatchedDecl



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


[PATCH] D85218: In clang-tidy base checks prevent anonymous functions from triggering assertions

2020-08-12 Thread David Truby via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG35bee3503f4c: [clang-tidy] prevent generated checks from 
triggering assertions on anonymous… (authored by bogser01, committed by 
DavidTruby).

Changed prior to commit:
  https://reviews.llvm.org/D85218?vs=282940&id=285040#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85218

Files:
  clang-tools-extra/clang-tidy/add_new_check.py
  clang-tools-extra/docs/clang-tidy/Contributing.rst


Index: clang-tools-extra/docs/clang-tidy/Contributing.rst
===
--- clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -202,7 +202,7 @@
 
   void AwesomeFunctionNamesCheck::check(const MatchFinder::MatchResult 
&Result) {
 const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
-if (MatchedDecl->getName().startswith("awesome_"))
+if (!MatchedDecl->getIdentifier() || 
MatchedDecl->getName().startswith("awesome_"))
   return;
 diag(MatchedDecl->getLocation(), "function %0 is insufficiently awesome")
 << MatchedDecl
Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -136,7 +136,7 @@
 void %(check_name)s::check(const MatchFinder::MatchResult &Result) {
   // FIXME: Add callback implementation.
   const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
-  if (MatchedDecl->getName().startswith("awesome_"))
+  if (!MatchedDecl->getIdentifier() || 
MatchedDecl->getName().startswith("awesome_"))
 return;
   diag(MatchedDecl->getLocation(), "function %%0 is insufficiently awesome")
   << MatchedDecl;


Index: clang-tools-extra/docs/clang-tidy/Contributing.rst
===
--- clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -202,7 +202,7 @@
 
   void AwesomeFunctionNamesCheck::check(const MatchFinder::MatchResult &Result) {
 const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
-if (MatchedDecl->getName().startswith("awesome_"))
+if (!MatchedDecl->getIdentifier() || MatchedDecl->getName().startswith("awesome_"))
   return;
 diag(MatchedDecl->getLocation(), "function %0 is insufficiently awesome")
 << MatchedDecl
Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -136,7 +136,7 @@
 void %(check_name)s::check(const MatchFinder::MatchResult &Result) {
   // FIXME: Add callback implementation.
   const auto *MatchedDecl = Result.Nodes.getNodeAs("x");
-  if (MatchedDecl->getName().startswith("awesome_"))
+  if (!MatchedDecl->getIdentifier() || MatchedDecl->getName().startswith("awesome_"))
 return;
   diag(MatchedDecl->getLocation(), "function %%0 is insufficiently awesome")
   << MatchedDecl;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76211: OpenMP Metadirective with user defined condition

2020-08-12 Thread Alok Mishra via Phabricator via cfe-commits
alokmishra.besu added a comment.



In D76211#2212203 , @jdoerfert wrote:

> Are you planning to add support for the actual OpenMP selectors as well? 
> All the other traits, scoring, etc. I left a comment below that points you to 
> the right place as we have almost all of that already ready to be reused.
> On this note, I would recommend you take a look at the OpenMP 5.1 draft, it 
> contains proper wording for a dynamic context extension, and we will need 
> support in the declare variant as well. That means we need to allow dynamic 
> expressions in `OMPTraitInfo` and similar places eventually anyway.

The idea of this patch is to implement user condition for metadirective. 
Anyways I will be adding support for other OpenMP selectors as well. I think 
doing that in a different patch will be a better idea, as there are lots of 
things to consider. 
I do take this point and will update this patch to support future extension to 
other selectors.

> We need more tests:
>
> - verify all parser errors
> - verify semantic errors wrt the directives
> - verify the condition is captured properly, e.g., if it is in a parallel 
> region
> - verify complex conditions work, e.g., globals, calls, constexpr 
> expressions, template arguments, ...
> - verify an "empty" metadirective works
> - verify we exclude directives & conditions that should not be emitted
>
>> Fixed an issue where correct code was not generated if directive variant was 
>> not provided in when/default clause
>
> We need a test for that too.

Will update all these test cases soon.
.

In D76211#2212214 , @jdoerfert wrote:

> Update for @alokmishra.besu via arcanist as the webinterface doesn't allow 
> patches over 2MB

Currently trying to figure out how to use arcanist. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76211

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


[PATCH] D82317: [Clang/Test]: Update tests where `noundef` attribute is necessary

2020-08-12 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D82317#2211643 , @guiand wrote:

> After discussing with @eugenis, for the meantime it might be best to do the 
> following:
>
> - Change the masking attribute to be `-fdisable-noundef-analysis` (name 
> notwithstanding), and have it completely turn off all `noundef`s
> - Change the llvm-lit configuration to use the new codegen flag for all the 
> tests by default
> - Have `noundef` emitted in the frontend by default (when the codegen flag 
> isn't present)

TBH, I don't see how this solves any problem. It just makes it a problem for 
someone in the future...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82317

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


[PATCH] D79219: [CMake] Simplify CMake handling for zlib

2020-08-12 Thread Petr Hosek via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG31e5f7120bdd: [CMake] Simplify CMake handling for zlib 
(authored by phosek).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79219

Files:
  clang/test/CMakeLists.txt
  clang/test/lit.site.cfg.py.in
  compiler-rt/test/lit.common.configured.in
  lld/test/CMakeLists.txt
  lld/test/lit.site.cfg.py.in
  lldb/cmake/modules/LLDBStandalone.cmake
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  llvm/cmake/config-ix.cmake
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/include/llvm/Config/config.h.cmake
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/CRC.cpp
  llvm/lib/Support/Compression.cpp
  llvm/test/CMakeLists.txt
  llvm/test/lit.site.cfg.py.in
  llvm/unittests/Support/CompressionTest.cpp
  llvm/utils/gn/secondary/clang/test/BUILD.gn
  llvm/utils/gn/secondary/compiler-rt/test/BUILD.gn
  llvm/utils/gn/secondary/lld/test/BUILD.gn
  llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
  llvm/utils/gn/secondary/llvm/test/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/test/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/test/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/test/BUILD.gn
@@ -174,9 +174,9 @@
   }
 
   if (llvm_enable_zlib) {
-extra_values += [ "HAVE_LIBZ=1" ]
+extra_values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-extra_values += [ "HAVE_LIBZ=0" ]  # Must be 0.
+extra_values += [ "LLVM_ENABLE_ZLIB=0" ]  # Must be 0.
   }
 }
 
Index: llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
@@ -295,20 +295,10 @@
 values += [ "LLVM_ENABLE_DIA_SDK=" ]
   }
 
-  # FIXME: Once https://reviews.llvm.org/D79219 is in, remove the two
-  # redundant HAVE_ variables.
   if (llvm_enable_zlib) {
-values += [
-  "HAVE_LIBZ=1",
-  "HAVE_ZLIB_H=1",
-  "LLVM_ENABLE_ZLIB=1",
-]
+values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-values += [
-  "HAVE_LIBZ=",
-  "HAVE_ZLIB_H=",
-  "LLVM_ENABLE_ZLIB=",
-]
+values += [ "LLVM_ENABLE_ZLIB=" ]
   }
 
   if (llvm_enable_libxml2) {
Index: llvm/utils/gn/secondary/lld/test/BUILD.gn
===
--- llvm/utils/gn/secondary/lld/test/BUILD.gn
+++ llvm/utils/gn/secondary/lld/test/BUILD.gn
@@ -49,9 +49,9 @@
   }
 
   if (llvm_enable_zlib) {
-extra_values += [ "HAVE_LIBZ=1" ]
+extra_values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-extra_values += [ "HAVE_LIBZ=0" ]  # Must be 0.
+extra_values += [ "LLVM_ENABLE_ZLIB=0" ]  # Must be 0.
   }
 
   if (current_cpu == "x64" || current_cpu == "arm64" ||
Index: llvm/utils/gn/secondary/compiler-rt/test/BUILD.gn
===
--- llvm/utils/gn/secondary/compiler-rt/test/BUILD.gn
+++ llvm/utils/gn/secondary/compiler-rt/test/BUILD.gn
@@ -86,8 +86,8 @@
   }
 
   if (llvm_enable_zlib) {
-values += [ "HAVE_LIBZ=1" ]
+values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-values += [ "HAVE_LIBZ=0" ]
+values += [ "LLVM_ENABLE_ZLIB=0" ]
   }
 }
Index: llvm/utils/gn/secondary/clang/test/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/test/BUILD.gn
+++ llvm/utils/gn/secondary/clang/test/BUILD.gn
@@ -79,9 +79,9 @@
   }
 
   if (llvm_enable_zlib) {
-extra_values += [ "HAVE_LIBZ=1" ]
+extra_values += [ "LLVM_ENABLE_ZLIB=1" ]
   } else {
-extra_values += [ "HAVE_LIBZ=0" ]  # Must be 0.
+extra_values += [ "LLVM_ENABLE_ZLIB=0" ]  # Must be 0.
   }
 
   if (host_cpu == "x64") {
Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -21,7 +21,7 @@
 
 namespace {
 
-#if LLVM_ENABLE_ZLIB == 1 && HAVE_LIBZ
+#if LLVM_ENABLE_ZLIB
 
 void TestZlibCompression(StringRef Input, int Level) {
   SmallString<32> Compressed;
Index: llvm/test/lit.site.cfg.py.in
===
--- llvm/test/lit.site.cfg.py.in
+++ llvm/test/lit.site.cfg.py.in
@@ -33,7 +33,7 @@
 config.host_ldflags = '@HOST_LDFLAGS@'
 config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
-config.have_zlib = @HAVE_LIBZ@
+config.have_zlib = @LLVM_ENABLE_ZLIB@
 config.have_libxar = @HAVE_LIBXAR@
 config.have_dia_sdk = @LLVM_ENABLE_DIA_SDK@
 config.enable_ffi = @LLVM_ENABLE_FFI@

[PATCH] D79219: [CMake] Simplify CMake handling for zlib

2020-08-12 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D79219#2203887 , @lxfind wrote:

> In D79219#2201415 , @phosek wrote:
>
>> This is correct. That target is provided by `find_package(ZLIB)`. In 
>> LLVMConfig.cmake, we invoke `find_package(ZLIB)` when zlib support is 
>> enabled. If you're using `LLVMExports.cmake`, you'll need to invoke 
>> `find_package(ZLIB)` yourself.
>
> @phosek, Thanks for the reply. I am not too familiar with this. Could you 
> please elaborate more on why setting it to `ZLIB::ZLIB` here is more modern? 
> And how one is expected to deal with `ZLIB::ZLIB` that shows up in 
> LLVMExports.cmake` (in the modern way)? Should one string pattern matching 
> for `ZLIB::ZLIB` and invoke `find_package(ZLIB)` again? (previously one could 
> simply concatenate `-l` with the library name in there.

@lxfind `ZLIB::ZLIB` is the name of the imported target that's defined by CMake 
when you invoke `find_dependency(ZLIB)`. Ideally, you'd just use 
`LLVMConfig.cmake` which invokes that for you if needed. 
https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/ has some 
more details.

`ZLIB::ZLIB` includes the correct include and library directory, so you no 
longer have to manually append `-I` or `-l`, all you need is to include 
`ZLIB::ZLIB` in the list of your dependencies, which is one advantage. Another 
advantage is that `ZLIB::ZLIB` can expand to different things, for example some 
users may want to statically link zlib in which case they would configure their 
build accordingly and `ZLIB::ZLIB` would expand into `/path/to/libz.a` (this is 
for example what we do in our toolchain build), others may be fine using the 
default system library in which case `ZLIB::ZLIB` would typically expand to 
just `z`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79219

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


[PATCH] D79219: [CMake] Simplify CMake handling for zlib

2020-08-12 Thread Harmen Stoppels via Phabricator via cfe-commits
haampie added a comment.

Great, one benefit of this is that zlib can now be detected in non-system libs. 
Maybe we should handle ncurses / TERMINFO in a similar manner? It currently has 
similar logic as finding zlib had


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79219

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


[PATCH] D81678: Introduce noundef attribute at call sites for stricter poison analysis

2020-08-12 Thread Gui Andrade via Phabricator via cfe-commits
guiand updated this revision to Diff 284931.
guiand added a comment.

Made the compiler flag non-public


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81678

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/attr-noundef.cpp
  clang/test/CodeGen/indirect-noundef.cpp
  clang/test/lit.cfg.py
  llvm/utils/update_cc_test_checks.py

Index: llvm/utils/update_cc_test_checks.py
===
--- llvm/utils/update_cc_test_checks.py
+++ llvm/utils/update_cc_test_checks.py
@@ -28,9 +28,9 @@
 from UpdateTestChecks import common
 
 SUBST = {
-'%clang': [],
-'%clang_cc1': ['-cc1'],
-'%clangxx': ['--driver-mode=g++'],
+'%clang': ['-Xclang -disable-noundef-analysis'],
+'%clang_cc1': ['-cc1', '-disable-noundef-analysis'],
+'%clangxx': ['--driver-mode=g++', '-disable-noundef-analysis'],
 }
 
 def get_line2spell_and_mangled(args, clang_args):
@@ -161,8 +161,8 @@
   try:
 builtin_include_dir = subprocess.check_output(
   [args.clang, '-print-file-name=include']).decode().strip()
-SUBST['%clang_cc1'] = ['-cc1', '-internal-isystem', builtin_include_dir,
-   '-nostdsysteminc']
+SUBST['%clang_cc1'] += ['-internal-isystem', builtin_include_dir,
+'-nostdsysteminc']
   except subprocess.CalledProcessError:
 common.warn('Could not determine clang builtins directory, some tests '
 'might not update correctly.')
Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -41,7 +41,8 @@
 
 llvm_config.use_default_substitutions()
 
-llvm_config.use_clang()
+llvm_config.use_clang(cc_additional_flags=['-Xclang -disable-noundef-analysis'],
+  cc1_additional_flags=['-disable-noundef-analysis'])
 
 config.substitutions.append(
 ('%src_include_dir', config.clang_src_dir + '/include'))
Index: clang/test/CodeGen/indirect-noundef.cpp
===
--- /dev/null
+++ clang/test/CodeGen/indirect-noundef.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_bin -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -o - %s | FileCheck %s
+
+union u1 {
+  int val;
+};
+
+// CHECK: @indirect_callee_int_ptr = global i32 (i32)*
+int (*indirect_callee_int_ptr)(int);
+// CHECK: @indirect_callee_union_ptr = global i32 (i32)*
+union u1 (*indirect_callee_union_ptr)(union u1);
+
+// CHECK-LABEL: define noundef i32 @{{.*}}indirect_callee_int{{.*}}(i32 noundef %
+int indirect_callee_int(int a) { return a; }
+// CHECK-LABEL: define i32 @{{.*}}indirect_callee_union{{.*}}(i32 %
+union u1 indirect_callee_union(union u1 a) {
+  return a;
+}
+
+int main() {
+  // CHECK: call noundef i32 @{{.*}}indirect_callee_int{{.*}}(i32 noundef 0)
+  indirect_callee_int(0);
+  // CHECK: call i32 @{{.*}}indirect_callee_union{{.*}}(i32 %
+  indirect_callee_union((union u1){0});
+
+  indirect_callee_int_ptr = indirect_callee_int;
+  indirect_callee_union_ptr = indirect_callee_union;
+
+  // CHECK: call noundef i32 %{{.*}}(i32 noundef 0)
+  indirect_callee_int_ptr(0);
+  // CHECK: call i32 %{{.*}}(i32 %
+  indirect_callee_union_ptr((union u1){});
+
+  return 0;
+}
Index: clang/test/CodeGen/attr-noundef.cpp
===
--- /dev/null
+++ clang/test/CodeGen/attr-noundef.cpp
@@ -0,0 +1,163 @@
+// RUN: %clang_bin -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
+// RUN: %clang_bin -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
+// RUN: %clang_bin -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
+
+// Passing structs by value
+// TODO: No structs may currently be marked noundef
+
+namespace check_structs {
+struct Trivial {
+  int a;
+};
+Trivial ret_trivial() { return {}; }
+void pass_trivial(Trivial e) {}
+// CHECK-INTEL: define i32 @{{.*}}ret_trivial
+// CHECK-AARCH: define i64 @{{.*}}ret_trivial
+// CHECK-INTEL: define void @{{.*}}pass_trivial{{.*}}(i32 %
+// CHECK-AARCH: define void @{{.*}}pass_trivial{{.*}}(i64 %
+
+struct NoCopy {
+  int a;
+  NoCopy(NoCopy &) = delete;
+};
+NoCopy ret_nocopy() { return {}; }
+void pass_nocopy(NoCopy e) {}
+// CHECK: define {{(dso_local)?}}void @{{.*}}ret_nocopy{{.*}}(%"struct.check_structs::NoCopy"* noalias sret align 4 %
+// CHECK: define void @{{.*}}pass_nocopy{{.*}}(%"struct.check_structs::NoCopy"* noundef %
+
+struct Huge {
+  int a[1024];
+};
+Huge 

[PATCH] D79219: [CMake] Simplify CMake handling for zlib

2020-08-12 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added a comment.

@phosek sorry for the late reply, the builds on master are still green, so your 
changes are working on Windows as well.

Thank you for the extra work!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79219

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


[PATCH] D85728: [Analyzer] Support for the new variadic isa<> and isa_and_not_null<> in CastValueChecker

2020-08-12 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 285047.
baloghadamsoftware added a comment.

Updated according to the comments.


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

https://reviews.llvm.org/D85728

Files:
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/test/Analysis/Inputs/llvm.h
  clang/test/Analysis/cast-value-logic.cpp
  clang/test/Analysis/cast-value-notes.cpp

Index: clang/test/Analysis/cast-value-notes.cpp
===
--- clang/test/Analysis/cast-value-notes.cpp
+++ clang/test/Analysis/cast-value-notes.cpp
@@ -13,6 +13,8 @@
   const T *getAs() const;
 };
 class Triangle : public Shape {};
+class Rectangle : public Shape {};
+class Hexagon : public Shape {};
 class Circle : public Shape {};
 } // namespace clang
 
@@ -27,7 +29,6 @@
 }
 
 void evalNonNullParamNonNullReturnReference(const Shape &S) {
-  // Unmodeled cast from reference to pointer.
   const auto *C = dyn_cast_or_null(S);
   // expected-note@-1 {{'C' initialized here}}
 
@@ -43,13 +44,37 @@
 return;
   }
 
+  if (dyn_cast_or_null(C)) {
+// expected-note@-1 {{Assuming 'C' is not a 'Rectangle'}}
+// expected-note@-2 {{Taking false branch}}
+return;
+  }
+
+  if (dyn_cast_or_null(C)) {
+// expected-note@-1 {{Assuming 'C' is not a 'Hexagon'}}
+// expected-note@-2 {{Taking false branch}}
+return;
+  }
+
   if (isa(C)) {
 // expected-note@-1 {{'C' is not a 'Triangle'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
-  if (isa(C)) {
+  if (isa(C)) {
+// expected-note@-1 {{'C' is neither a 'Triangle' nor a 'Rectangle'}}
+// expected-note@-2 {{Taking false branch}}
+return;
+  }
+
+  if (isa(C)) {
+// expected-note@-1 {{'C' is neither a 'Triangle' nor a 'Rectangle' nor a 'Hexagon'}}
+// expected-note@-2 {{Taking false branch}}
+return;
+  }
+
+  if (isa(C)) {
 // expected-note@-1 {{'C' is a 'Circle'}}
 // expected-note@-2 {{Taking true branch}}
 
@@ -65,22 +90,57 @@
   // expected-note@-1 {{'S' is a 'Circle'}}
   // expected-note@-2 {{'C' initialized here}}
 
-  if (!isa(C)) {
-// expected-note@-1 {{Assuming 'C' is a 'Triangle'}}
+  if (!dyn_cast_or_null(C)) {
+// expected-note@-1 {{'C' is a 'Circle'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
-  if (!isa(C)) {
-// expected-note@-1 {{'C' is a 'Triangle'}}
+  if (dyn_cast_or_null(C)) {
+// expected-note@-1 {{Assuming 'C' is not a 'Triangle'}}
 // expected-note@-2 {{Taking false branch}}
 return;
   }
 
-  (void)(1 / !C);
-  // expected-note@-1 {{'C' is non-null}}
-  // expected-note@-2 {{Division by zero}}
-  // expected-warning@-3 {{Division by zero}}
+  if (dyn_cast_or_null(C)) {
+// expected-note@-1 {{Assuming 'C' is not a 'Rectangle'}}
+// expected-note@-2 {{Taking false branch}}
+return;
+  }
+
+  if (dyn_cast_or_null(C)) {
+// expected-note@-1 {{Assuming 'C' is not a 'Hexagon'}}
+// expected-note@-2 {{Taking false branch}}
+return;
+  }
+
+  if (isa(C)) {
+// expected-note@-1 {{'C' is not a 'Triangle'}}
+// expected-note@-2 {{Taking false branch}}
+return;
+  }
+
+  if (isa(C)) {
+// expected-note@-1 {{'C' is neither a 'Triangle' nor a 'Rectangle'}}
+// expected-note@-2 {{Taking false branch}}
+return;
+  }
+
+  if (isa(C)) {
+// expected-note@-1 {{'C' is neither a 'Triangle' nor a 'Rectangle' nor a 'Hexagon'}}
+// expected-note@-2 {{Taking false branch}}
+return;
+  }
+
+  if (isa(C)) {
+// expected-note@-1 {{'C' is a 'Circle'}}
+// expected-note@-2 {{Taking true branch}}
+
+(void)(1 / !C);
+// expected-note@-1 {{'C' is non-null}}
+// expected-note@-2 {{Division by zero}}
+// expected-warning@-3 {{Division by zero}}
+  }
 }
 
 void evalNonNullParamNullReturn(const Shape *S) {
Index: clang/test/Analysis/cast-value-logic.cpp
===
--- clang/test/Analysis/cast-value-logic.cpp
+++ clang/test/Analysis/cast-value-logic.cpp
@@ -19,6 +19,8 @@
   virtual double area();
 };
 class Triangle : public Shape {};
+class Rectangle : public Shape {};
+class Hexagon : public Shape {};
 class Circle : public Shape {
 public:
   ~Circle();
@@ -39,6 +41,23 @@
 clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
 }
 
+void test_regions_isa_variadic(const Shape *A, const Shape *B) {
+  if (isa(A) &&
+  !isa(B))
+clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void test_regions_isa_and_nonnull(const Shape *A, const Shape *B) {
+  if (isa_and_nonnull(A) && !isa_and_nonnull(B))
+clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
+void test_regions_isa_and_nonnull_variadic(const Shape *A, const Shape *B) {
+  if (isa_and_nonnull(A) &&
+  !isa_and_nonnull(B))
+clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}
+
 namespace test_cast {
 void

[PATCH] D85778: More accurately compute the ranges of possible values for +, -, *, &, %.

2020-08-12 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

Fixes all the false positives it had reported for LibreOffice (which had all 
involved expressions containing either ~ or +).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85778

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


[PATCH] D85728: [Analyzer] Support for the new variadic isa<> and isa_and_not_null<> in CastValueChecker

2020-08-12 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware marked 3 inline comments as done.
baloghadamsoftware added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:270-272
+default:
+  llvm_unreachable("Invalid template argument for isa<> or "
+   "isa_and_nonnull<>");

NoQ wrote:
> We shouldn't crash when code under analysis doesn't match our expectation.
The question is whether we can get any other template argument kind for 
`llvm::isa<>()` and `llvm::isa_and_nonnull<>()` than `Type` or `Pack`?



Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:315
+if (CastSucceeds) {
+  Success = true;
+  C.addTransition(

NoQ wrote:
> Let's return immediately after the transition instead. Like, generally, it's 
> a good practice to return immediately after a transition if you don't plan 
> any more state splits, because otherwise it's too easy to accidentally 
> introduce unwanted state splits.
Now I inserted a return but only if this is a known conversion. If this is an 
assumption, the we should assume every type in the template argument list.


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

https://reviews.llvm.org/D85728

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


[PATCH] D85193: [clang] Check `expr` inside `InitListChecker::UpdateStructuredListElement()`

2020-08-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I have a suggestion for the added comment, but I also forgot to ask, do you 
need someone to commit on your behalf?




Comment at: clang/lib/Sema/SemaInit.cpp:3094
+// This initializer overwrites a previous initializer.
+// Emit warning if `expr` is valid.
+if (expr)

I was hoping for something that describes the "why" more than the "what". How 
about: `No need to diagnose when expr is null because a more relevant 
diagnostic has already been issued and this diagnostic is potentially noise.`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85193

___
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-08-12 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 285057.
balazske added a comment.

Improved comments, code clean-up.
Improved detection of explicit cast to void.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72705

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

Index: clang/test/Analysis/error-return.c
===
--- /dev/null
+++ clang/test/Analysis/error-return.c
@@ -0,0 +1,211 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.unix.ErrorReturn -verify %s
+
+#include "Inputs/system-header-simulator.h"
+
+FILE *file();
+
+void test_EOFOrNeg_LT_Good() {
+  if (fputs("str", file()) < 0) {
+  }
+}
+
+void test_EOFOrNeg_LT_Bad() {
+  if (fputs("str", file()) < -1) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_GT_Good() {
+  if (fputs("str", file()) > -1) {
+  }
+}
+
+void test_EOFOrNeg_GT_Bad() {
+  if (fputs("str", file()) > 0) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_LE_Good() {
+  if (fputs("str", file()) <= -1) {
+  }
+}
+
+void test_EOFOrNeg_LE_Bad() {
+  if (fputs("str", file()) <= 0) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_GE_Good() {
+  if (fputs("str", file()) >= 0) {
+  }
+}
+
+void test_EOFOrNeg_GE_Bad() {
+  if (fputs("str", file()) >= -1) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_EQ_Good() {
+  if (fputs("str", file()) == -1) {
+  }
+}
+
+void test_EOFOrNeg_EQ_Bad() {
+  if (fputs("str", file()) == 0) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_NE_Good() {
+  if (fputs("str", file()) != -1) {
+  }
+}
+
+void test_EOFOrNeg_NE_Bad() {
+  if (fputs("str", file()) != 0) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_EQ_BadVal() {
+  if (fputs("str", file()) == -2) { // expected-warning{{Use of return value that was not checked}}
+  }
+  if (fputs("str", file()) == 1) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_VarAssign() {
+  int X = fputs("str", file());
+  if (X != 0) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_VarAssignInCond() {
+  int X;
+  if ((X = fputs("str", file())) != 0) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_VarAssign1() {
+  int X = fputs("str", file());
+  int Y = X;
+  if (Y != 0) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void badcheck(int X) {
+  if (X == 0) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_Call() {
+  int X = fputs("str", file());
+  badcheck(X);
+}
+
+void test_EOFOrNeg_Syscall() {
+  int X = fputs("str", file());
+  fakeSystemHeaderCallIntVal(X);// expected-warning{{Use of return value that was not checked}}
+  fakeSystemHeaderCallIntVal(fputs("str", file())); // expected-warning{{Use of return value that was not checked}}
+}
+
+void test_EOFOrNeg_Use_LNot() {
+  int X = fputs("str", file());
+  if (!X) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_Use_Add() {
+  int X = fputs("str", file());
+  int Y = X + 1; // expected-warning{{Use of return value that was not checked}}
+}
+
+void test_EOFOrNeg_If() {
+  int X = fputs("str", file());
+  if (X) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_IfCond() {
+  if (fputs("str", file())) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_ForInit() {
+  for (fputs("str", file());;) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_ForCond() {
+  for (; fputs("str", file());) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_ForInc() {
+  for (;; fputs("str", file())) { // expected-warning{{Use of return value that was not checked}}
+  }
+}
+
+void test_EOFOrNeg_DoCond() {
+  do {
+  } while (fputs("str", file())); // expected-warning{{Use of return value that was not checked}}
+}
+
+void test_EOFOrNeg_WhileCond() {
+  while (fputs("str", file())) { // expected-warning{{Use of return value that was not checked}}
+  };
+}
+
+void unknown1(int);
+
+void test_EOFOrNeg_EscapeCall() {
+  int X = fputs("str", file());
+  unknown1(X);
+  int Y = X + 1;
+}
+
+int GlobalInt;
+
+void test_EOFOrNeg_EscapeGlobalAssign() {
+  GlobalInt = fputs("str", file());
+  int X = GlobalInt + 

[PATCH] D85834: [AST] Fix a crash on calling getASTRecordLayout on an invalid RecordDecl.

2020-08-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: sammccall, rsmith.
Herald added a project: clang.
hokein requested review of this revision.

The getASTRecordLayout method requires a valid decl.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85834

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/alignof.cpp


Index: clang/test/SemaCXX/alignof.cpp
===
--- clang/test/SemaCXX/alignof.cpp
+++ clang/test/SemaCXX/alignof.cpp
@@ -102,3 +102,11 @@
 template 
 using template_alias = aligned_int;
 static_assert(alignof(template_alias) == 16, "Expected alignment of 16" 
);
+
+namespace nocrash {
+struct ForwardDecl; // expected-note {{forward declaration of}}
+struct S {
+  ForwardDecl a; // expected-error {{field has incomplete type}}
+};
+static_assert(__alignof__(S), "");
+}
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2460,11 +2460,13 @@
 if (TI.AlignIsRequired)
   return ABIAlign;
 
-unsigned PreferredAlign = static_cast(
-toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
-assert(PreferredAlign >= ABIAlign &&
-   "PreferredAlign should be at least as large as ABIAlign.");
-return PreferredAlign;
+if (!RT->getDecl()->isInvalidDecl()) {
+  unsigned PreferredAlign = static_cast(
+  toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
+  assert(PreferredAlign >= ABIAlign &&
+ "PreferredAlign should be at least as large as ABIAlign.");
+  return PreferredAlign;
+}
   }
 
   // Double (and, for targets supporting AIX `power` alignment, long double) 
and


Index: clang/test/SemaCXX/alignof.cpp
===
--- clang/test/SemaCXX/alignof.cpp
+++ clang/test/SemaCXX/alignof.cpp
@@ -102,3 +102,11 @@
 template 
 using template_alias = aligned_int;
 static_assert(alignof(template_alias) == 16, "Expected alignment of 16" );
+
+namespace nocrash {
+struct ForwardDecl; // expected-note {{forward declaration of}}
+struct S {
+  ForwardDecl a; // expected-error {{field has incomplete type}}
+};
+static_assert(__alignof__(S), "");
+}
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2460,11 +2460,13 @@
 if (TI.AlignIsRequired)
   return ABIAlign;
 
-unsigned PreferredAlign = static_cast(
-toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
-assert(PreferredAlign >= ABIAlign &&
-   "PreferredAlign should be at least as large as ABIAlign.");
-return PreferredAlign;
+if (!RT->getDecl()->isInvalidDecl()) {
+  unsigned PreferredAlign = static_cast(
+  toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
+  assert(PreferredAlign >= ABIAlign &&
+ "PreferredAlign should be at least as large as ABIAlign.");
+  return PreferredAlign;
+}
   }
 
   // Double (and, for targets supporting AIX `power` alignment, long double) and
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85093: [analyzer] StdLibraryFunctionsChecker: Add support for new functions

2020-08-12 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 for your work!




Comment at: clang/test/Analysis/std-c-library-functions-arg-constraints.c:190
 void test_notnull_symbolic2(FILE *fp, int *buf) {
-  if (!buf) // bugpath-note{{Assuming 'buf' is null}} \
+  if (!buf)  // bugpath-note{{Assuming 'buf' is null}} 
\
 // bugpath-note{{Taking true branch}}

This formatting change seems unrelated, that would not be a problem in itself, 
but it degrades the readability a bit (for me).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85093

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


[PATCH] D85753: [clangd] Discard diagnostics from another SourceManager.

2020-08-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:209
   // Update diag to point at include inside main file.
   D.File = SM.getFileEntryForID(SM.getMainFileID())->getName().str();
   D.Range = std::move(R);

adamcz wrote:
> kadircet wrote:
> > can't we rather record the mainfilename once and make use of it here?
> > i believe the rest of the logic operates on the local sourcelocations/files 
> > associated with the sourcemanager inside the diagnostic in process.
> getMainFileRange() doesn't.
> 
> We can easily get main file from the original source manager or record it in 
> BeginSourceFile. The thing is that it's not easy to find a place in the main 
> file to put this diagnostic at. We can, of course, put it at the top of the 
> file, but normally we try to find the #include location in the main file. 
> That's done in the getMainFileRange() above and it mixes the location of the 
> diagnostic (which is for the new SourceManager) and the main file buffer 
> (which is for the OrigSrcMgr).
> 
> I'm a bit worried that if we put a diagnostic relating to #include at the top 
> of the file, where another #include may be, it will become very confusing.
> getMainFileRange() doesn't.

ah right i forgot about that bit :/

> I'm a bit worried that if we put a diagnostic relating to #include at the top 
> of the file, where another #include may be, it will become very confusing.

I totally agree.

A crazy idea, we can register a callback to PP on `BeginSourceFile` to track 
file changes, than whenever we see a diagnostic from a different sourcemanager, 
we can map it back to last position a filechange was triggered. Ofc, this goes 
with the assumption that we see a filechanged event on `#include "modular.h"` 
line, but I guess we should at least get an includedirective callback or 
something.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85753

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


[PATCH] D85834: [AST] Fix a crash on calling getASTRecordLayout on an invalid RecordDecl.

2020-08-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:2463
 
-unsigned PreferredAlign = static_cast(
-toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
-assert(PreferredAlign >= ABIAlign &&
-   "PreferredAlign should be at least as large as ABIAlign.");
-return PreferredAlign;
+if (!RT->getDecl()->isInvalidDecl()) {
+  unsigned PreferredAlign = static_cast(

another proper fix might be change the `getPreferredTypeAlign` signature to 
support error handling (e.g. return a bool), but that would require a large 
invasive change for its callers, not sure it is worth.

I think the current implementation is OK, as the result doesn't really matter 
for an invalid RecordDecl, and we do similar thing int `getTypeInfoImpl` 
(returning a fake `Align`/`Width` for invalid decl).  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85834

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


[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2020-08-12 Thread Chris Hansen via Phabricator via cfe-commits
hansec removed a reviewer: hansec.
hansec added a comment.

I think I was added to this in error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


[PATCH] D85753: [clangd] Discard diagnostics from another SourceManager.

2020-08-12 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added inline comments.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:209
   // Update diag to point at include inside main file.
   D.File = SM.getFileEntryForID(SM.getMainFileID())->getName().str();
   D.Range = std::move(R);

kadircet wrote:
> adamcz wrote:
> > kadircet wrote:
> > > can't we rather record the mainfilename once and make use of it here?
> > > i believe the rest of the logic operates on the local 
> > > sourcelocations/files associated with the sourcemanager inside the 
> > > diagnostic in process.
> > getMainFileRange() doesn't.
> > 
> > We can easily get main file from the original source manager or record it 
> > in BeginSourceFile. The thing is that it's not easy to find a place in the 
> > main file to put this diagnostic at. We can, of course, put it at the top 
> > of the file, but normally we try to find the #include location in the main 
> > file. That's done in the getMainFileRange() above and it mixes the location 
> > of the diagnostic (which is for the new SourceManager) and the main file 
> > buffer (which is for the OrigSrcMgr).
> > 
> > I'm a bit worried that if we put a diagnostic relating to #include at the 
> > top of the file, where another #include may be, it will become very 
> > confusing.
> > getMainFileRange() doesn't.
> 
> ah right i forgot about that bit :/
> 
> > I'm a bit worried that if we put a diagnostic relating to #include at the 
> > top of the file, where another #include may be, it will become very 
> > confusing.
> 
> I totally agree.
> 
> A crazy idea, we can register a callback to PP on `BeginSourceFile` to track 
> file changes, than whenever we see a diagnostic from a different 
> sourcemanager, we can map it back to last position a filechange was 
> triggered. Ofc, this goes with the assumption that we see a filechanged event 
> on `#include "modular.h"` line, but I guess we should at least get an 
> includedirective callback or something.
Right, that's a good idea, thanks. Sam suggested something like that in 
parallel, during in-person discussion too. I'll look into that in the near 
future.

There's the other issue of only seeing this diagnostics when a module is built, 
but not when a module was loaded from cache, so we will not be consistent 
unless we serialize them somehow.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85753

___
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-08-12 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D72705#2210255 , @balazske wrote:

> More results in CodeChecker: emacs_errorreturn 
> 

These results (and the ones in tmux) seems to be quite convincing, even though 
you have found some false positives. Also, I second @Szelethus 's opinion that 
this is a valuable checker and we should welcome this in the pack as an alpha 
checker :)


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] D72705: [analyzer] Added new checker 'alpha.unix.ErrorReturn'.

2020-08-12 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D72705#2199333 , @balazske wrote:

> Test results for tmux are available here 
> .
>  (Could not manage to get other results uploaded.)
>
> This test was done with an improved version of the checker that detects 
> functions with possible NULL return value. (These functions are listed in the 
> CERT ERR33-C rule, even if it is "impossible" that these fail the rule says 
> that all of these should be checked.) Note tags here are experimental and not 
> finished.

Seems like the findings are mostly related to time management functions. So, it 
would be interesting to see how the results correlate/divergate to the 
StdLibraryFunctionChecker's POSIX time handling patch 
 (this is a task for me to do the 
measurements).


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] D85543: Limit Max Vector alignment on COFF targets to 8192

2020-08-12 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaa4bc1cb7978: Limit Max Vector alignment on COFF targets to 
8192. (authored by erichkeane).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85543

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/X86.h
  clang/test/CodeGen/alignment.c


Index: clang/test/CodeGen/alignment.c
===
--- clang/test/CodeGen/alignment.c
+++ clang/test/CodeGen/alignment.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK,NONCOFF
+// RUN: %clang_cc1 -triple i386-unknown-windows-pc -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK,COFF
 
 __attribute((aligned(16))) float a[128];
 union {int a[4]; __attribute((aligned(16))) float b[4];} b;
@@ -7,7 +8,7 @@
 // CHECK: @b = {{.*}}zeroinitializer, align 16
 
 long long int test5[1024];
-// CHECK-DAG: @test5 = global [1024 x i64] zeroinitializer, align 8
+// CHECK-DAG: @test5 = {{.*}}global [1024 x i64] zeroinitializer, align 8
 
 // PR5279 - Reduced alignment on typedef.
 typedef int myint __attribute__((aligned(1)));
@@ -67,3 +68,11 @@
 }
 // CHECK-LABEL: @test6
 // CHECK:   load <4 x float>, <4 x float>* {{.*}}, align 2
+
+typedef int __attribute__((ext_vector_type(200 * 16))) BigVecTy;
+void test7() {
+  BigVecTy V;
+}
+// CHECK-LABEL: @test7
+// NONCOFF: alloca <3200 x i32>, align 16384
+// COFF: alloca <3200 x i32>, align 8192
Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -144,6 +144,11 @@
 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
 AddrSpaceMap = &X86AddrSpaceMap;
 HasStrictFP = true;
+
+bool IsWinCOFF =
+getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
+if (IsWinCOFF)
+  MaxVectorAlign = MaxTLSAlign = 8192u * getCharWidth();
   }
 
   const char *getLongDoubleMangling() const override {
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -100,8 +100,8 @@
   unsigned char MinGlobalAlign;
 
   unsigned short NewAlign;
-  unsigned short MaxVectorAlign;
-  unsigned short MaxTLSAlign;
+  unsigned MaxVectorAlign;
+  unsigned MaxTLSAlign;
 
   const llvm::fltSemantics *HalfFormat, *BFloat16Format, *FloatFormat,
 *DoubleFormat, *LongDoubleFormat, *Float128Format;
@@ -1271,9 +1271,7 @@
   ///
   /// Gets the maximum alignment (in bits) of a TLS variable on this target.
   /// Returns zero if there is no such constraint.
-  unsigned short getMaxTLSAlign() const {
-return MaxTLSAlign;
-  }
+  unsigned getMaxTLSAlign() const { return MaxTLSAlign; }
 
   /// Whether target supports variable-length arrays.
   bool isVLASupported() const { return VLASupported; }


Index: clang/test/CodeGen/alignment.c
===
--- clang/test/CodeGen/alignment.c
+++ clang/test/CodeGen/alignment.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,NONCOFF
+// RUN: %clang_cc1 -triple i386-unknown-windows-pc -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,COFF
 
 __attribute((aligned(16))) float a[128];
 union {int a[4]; __attribute((aligned(16))) float b[4];} b;
@@ -7,7 +8,7 @@
 // CHECK: @b = {{.*}}zeroinitializer, align 16
 
 long long int test5[1024];
-// CHECK-DAG: @test5 = global [1024 x i64] zeroinitializer, align 8
+// CHECK-DAG: @test5 = {{.*}}global [1024 x i64] zeroinitializer, align 8
 
 // PR5279 - Reduced alignment on typedef.
 typedef int myint __attribute__((aligned(1)));
@@ -67,3 +68,11 @@
 }
 // CHECK-LABEL: @test6
 // CHECK:   load <4 x float>, <4 x float>* {{.*}}, align 2
+
+typedef int __attribute__((ext_vector_type(200 * 16))) BigVecTy;
+void test7() {
+  BigVecTy V;
+}
+// CHECK-LABEL: @test7
+// NONCOFF: alloca <3200 x i32>, align 16384
+// COFF: alloca <3200 x i32>, align 8192
Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -144,6 +144,11 @@
 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
 AddrSpaceMap = &X86AddrSpaceMap;
 HasStrictFP = true;
+
+bool IsWinCOFF =
+getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
+if (IsWinCOFF)
+  MaxVectorAlign = MaxTLSAlign = 8192u * getCharWidth();
 

[clang] aa4bc1c - Limit Max Vector alignment on COFF targets to 8192.

2020-08-12 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2020-08-12T06:35:35-07:00
New Revision: aa4bc1cb7978b87bdbdb75910da0abbd27889800

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

LOG: Limit Max Vector alignment on COFF targets to 8192.

COFF targets have a max object alignment of 8192, so trying to create
one with a larger size results in an unreachable in WinCOFFObjectWriter.

For the reproducer I have uses thread local storage, however other
alignments are likely affected as well.

This patch sets the MaxVectorAlign for COFF to 8192.  Additionally,
though there is no longer a way to reproduce that I could find, it
correctly sets the MaxTLSAlign for COFF to that value as well, so that
if anyone comes up with a situation where this is true, it will cause an
error.

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

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/Targets/X86.h
clang/test/CodeGen/alignment.c

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 004990ee3152..55db7c2d8bf6 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -100,8 +100,8 @@ struct TransferrableTargetInfo {
   unsigned char MinGlobalAlign;
 
   unsigned short NewAlign;
-  unsigned short MaxVectorAlign;
-  unsigned short MaxTLSAlign;
+  unsigned MaxVectorAlign;
+  unsigned MaxTLSAlign;
 
   const llvm::fltSemantics *HalfFormat, *BFloat16Format, *FloatFormat,
 *DoubleFormat, *LongDoubleFormat, *Float128Format;
@@ -1271,9 +1271,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   ///
   /// Gets the maximum alignment (in bits) of a TLS variable on this target.
   /// Returns zero if there is no such constraint.
-  unsigned short getMaxTLSAlign() const {
-return MaxTLSAlign;
-  }
+  unsigned getMaxTLSAlign() const { return MaxTLSAlign; }
 
   /// Whether target supports variable-length arrays.
   bool isVLASupported() const { return VLASupported; }

diff  --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index d99358d6f806..8559ee53dca0 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -144,6 +144,11 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public 
TargetInfo {
 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
 AddrSpaceMap = &X86AddrSpaceMap;
 HasStrictFP = true;
+
+bool IsWinCOFF =
+getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
+if (IsWinCOFF)
+  MaxVectorAlign = MaxTLSAlign = 8192u * getCharWidth();
   }
 
   const char *getLongDoubleMangling() const override {

diff  --git a/clang/test/CodeGen/alignment.c b/clang/test/CodeGen/alignment.c
index ce0c58bee4bb..dc7a57babfc7 100644
--- a/clang/test/CodeGen/alignment.c
+++ b/clang/test/CodeGen/alignment.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK,NONCOFF
+// RUN: %clang_cc1 -triple i386-unknown-windows-pc -emit-llvm %s -o - | 
FileCheck %s --check-prefixes=CHECK,COFF
 
 __attribute((aligned(16))) float a[128];
 union {int a[4]; __attribute((aligned(16))) float b[4];} b;
@@ -7,7 +8,7 @@ union {int a[4]; __attribute((aligned(16))) float b[4];} b;
 // CHECK: @b = {{.*}}zeroinitializer, align 16
 
 long long int test5[1024];
-// CHECK-DAG: @test5 = global [1024 x i64] zeroinitializer, align 8
+// CHECK-DAG: @test5 = {{.*}}global [1024 x i64] zeroinitializer, align 8
 
 // PR5279 - Reduced alignment on typedef.
 typedef int myint __attribute__((aligned(1)));
@@ -67,3 +68,11 @@ void test6(float4align64 *p) {
 }
 // CHECK-LABEL: @test6
 // CHECK:   load <4 x float>, <4 x float>* {{.*}}, align 2
+
+typedef int __attribute__((ext_vector_type(200 * 16))) BigVecTy;
+void test7() {
+  BigVecTy V;
+}
+// CHECK-LABEL: @test7
+// NONCOFF: alloca <3200 x i32>, align 16384
+// COFF: alloca <3200 x i32>, align 8192



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


[PATCH] D84457: [OPENMP]Fix PR37671: Privatize local(private) variables in untied tasks.

2020-08-12 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGec9563c54ed2: [OPENMP]Fix PR37671: Privatize local(private) 
variables in untied tasks. (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84457

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/task_codegen.cpp

Index: clang/test/OpenMP/task_codegen.cpp
===
--- clang/test/OpenMP/task_codegen.cpp
+++ clang/test/OpenMP/task_codegen.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -x c++ -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix UNTIEDRT
 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-apple-darwin10 -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
 //
@@ -258,7 +258,7 @@
 a = 4;
 c = 5;
   }
-// CHECK: [[ORIG_TASK_PTR:%.+]] = call i8* @__kmpc_omp_task_alloc([[IDENT_T]]* @{{.+}}, i32 {{%.*}}, i32 0, i64 40, i64 1, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T]]{{.*}}*)* [[TASK_ENTRY6:@.+]] to i32 (i32, i8*)*))
+// CHECK: [[ORIG_TASK_PTR:%.+]] = call i8* @__kmpc_omp_task_alloc([[IDENT_T]]* @{{.+}}, i32 {{%.*}}, i32 0, i64 48, i64 1, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T]]{{.*}}*)* [[TASK_ENTRY6:@.+]] to i32 (i32, i8*)*))
 // CHECK: call i32 @__kmpc_omp_task([[IDENT_T]]* @{{.+}}, i32 {{%.*}}, i8* [[ORIG_TASK_PTR]])
 #pragma omp task untied
   {
@@ -295,26 +295,54 @@
 // CHECK: store i32 4, i32* [[A_PTR]]
 
 // CHECK: define internal i32 [[TASK_ENTRY6]](i32 %0, [[KMP_TASK_T]]{{.*}}* noalias %1)
-// CHECK: switch i32 %{{.+}}, label
+// UNTIEDRT: [[S1_ADDR_PTR:%.+]] = alloca %struct.S*,
+// UNTIEDRT: call void (i8*, ...) %{{.+}}(i8* %{{.+}}, %struct.S** [[S1_ADDR_PTR]])
+// UNTIEDRT: [[S1_ADDR:%.+]] = load %struct.S*, %struct.S** [[S1_ADDR_PTR]],
+// CHECK: switch i32 %{{.+}}, label %[[DONE:.+]] [
+
+// CHECK: [[DONE]]:
+// CHECK: br label %[[CLEANUP:[^,]+]]
+
 // CHECK: load i32*, i32** %
 // CHECK: store i32 1, i32* %
 // CHECK: call i32 @__kmpc_omp_task(%
+// UNTIEDRT: br label %[[EXIT:[^,]+]]
 
+// UNTIEDRT: call void [[CONSTR:@.+]](%struct.S* [[S1_ADDR]])
 // CHECK: call i8* @__kmpc_omp_task_alloc(
 // CHECK: call i32 @__kmpc_omp_task(%
 // CHECK: load i32*, i32** %
 // CHECK: store i32 2, i32* %
 // CHECK: call i32 @__kmpc_omp_task(%
+// UNTIEDRT: br label %[[EXIT]]
 
 // CHECK: call i32 @__kmpc_omp_taskyield(%
 // CHECK: load i32*, i32** %
 // CHECK: store i32 3, i32* %
 // CHECK: call i32 @__kmpc_omp_task(%
+// UNTIEDRT: br label %[[EXIT]]
+
+// s1 = S();
+// UNTIEDRT: call void [[CONSTR]](%struct.S* [[TMP:%.+]])
+// UNTIEDRT: [[DST:%.+]] = bitcast %struct.S* [[S1_ADDR]] to i8*
+// UNTIEDRT: [[SRC:%.+]] = bitcast %struct.S* [[TMP]] to i8*
+// UNTIEDRT: call void @llvm.memcpy.{{.+}}(i8* {{.*}}[[DST]], i8* {{.*}}[[SRC]], i64 4, i1 false)
+// UNTIEDRT: call void [[DESTR:@.+]](%struct.S* [[TMP]])
 
 // CHECK: call i32 @__kmpc_omp_taskwait(%
 // CHECK: load i32*, i32** %
 // CHECK: store i32 4, i32* %
 // CHECK: call i32 @__kmpc_omp_task(%
+// UNTIEDRT: br label %[[EXIT]]
+
+// UNTIEDRT: call void [[DESTR]](%struct.S* [[S1_ADDR]])
+// CHECK: br label %[[CLEANUP]]
+
+// CHECK: [[CLEANUP]]:
+// UNTIEDRT: br label %[[EXIT]]
+
+// UNTIEDRT:  [[EXIT]]:
+// UNTIEDRT-NEXT: ret i32 0
 
 struct S1 {
   int a;
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -21,6 +21,7 @@
 #include "clang/AST/OpenMPClause.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtOpenMP.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/Basic/OpenMPKinds.h"
 #include "clang/Basic/PrettyStackTrace.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
@@ -3784,6 +3785,42 @@
   checkForLastprivateConditionalUpdate(*this, S);
 }
 
+namespace {
+/// Get the list of variables declared in the context of the untied tasks.
+class CheckVarsEscapingUntiedTaskDeclContext final
+: public ConstStmtVisitor {
+  llvm::SmallVector PrivateDecls;
+
+public:
+  explicit CheckVarsEscapingUntiedTaskDeclContext() = default;
+  virtual ~CheckVarsEscapingUntiedTaskDeclContext() = default;
+  void VisitDeclStmt(const DeclStmt *S) {
+if (!S)
+  return;
+// Need to privatize only local vars, static locals can be processed as is.
+for (const Decl *D : S->decls()) {
+  if (const auto *VD = dyn_cast_or_null(D))
+if (VD->hasLocalStorage())
+  PrivateDecls.push_back(VD);
+}
+  }
+  void VisitOMP

[clang] ec9563c - [OPENMP]Fix PR37671: Privatize local(private) variables in untied tasks.

2020-08-12 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-08-12T09:37:24-04:00
New Revision: ec9563c54ed25e9f9cbe60985399212d50bd801d

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

LOG: [OPENMP]Fix PR37671: Privatize local(private) variables in untied tasks.

Summary:
In untied tasks, need to allocate the space for local variales, declared
in task region, when the memory for task data is allocated. THe function
can be interrupted and we can exit from the function in untied task
switch. Need to keep the state of the local variables in this case.
Also, the compiler should not call cleanup when exiting in untied task
switch until the real exit out of the declaration scope is met during
 execution.

Reviewers: jdoerfert

Subscribers: yaxunl, guansong, cfe-commits, sstefan1, caomhin

Tags: #clang

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntime.h
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/task_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 0582de5ebafe..addf6c34168c 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -180,7 +180,7 @@ class CGOpenMPTaskOutlinedRegionInfo final : public 
CGOpenMPRegionInfo {
 UntiedCodeGen(CGF);
 CodeGenFunction::JumpDest CurPoint =
 CGF.getJumpDestInCurrentScope(".untied.next.");
-CGF.EmitBranchThroughCleanup(CGF.ReturnBlock);
+CGF.EmitBranch(CGF.ReturnBlock.getBlock());
 CGF.EmitBlock(CGF.createBasicBlock(".untied.jmp."));
 
UntiedSwitch->addCase(CGF.Builder.getInt32(UntiedSwitch->getNumCases()),
   CGF.Builder.GetInsertBlock());
@@ -3370,6 +3370,7 @@ struct PrivateHelpersTy {
const VarDecl *PrivateCopy, const VarDecl *PrivateElemInit)
   : OriginalRef(OriginalRef), Original(Original), PrivateCopy(PrivateCopy),
 PrivateElemInit(PrivateElemInit) {}
+  PrivateHelpersTy(const VarDecl *Original) : Original(Original) {}
   const Expr *OriginalRef = nullptr;
   const VarDecl *Original = nullptr;
   const VarDecl *PrivateCopy = nullptr;
@@ -3390,6 +3391,10 @@ createPrivatesRecordDecl(CodeGenModule &CGM, 
ArrayRef Privates) {
 for (const auto &Pair : Privates) {
   const VarDecl *VD = Pair.second.Original;
   QualType Type = VD->getType().getNonReferenceType();
+  // If the private variable is a local variable with lvalue ref type,
+  // allocate the pointer instead of the pointee type.
+  if (!Pair.second.OriginalRef && VD->getType()->isLValueReferenceType())
+Type = C.getPointerType(Type);
   FieldDecl *FD = addFieldToRecordDecl(C, RD, Type);
   if (VD->hasAttrs()) {
 for (specific_attr_iterator I(VD->getAttrs().begin()),
@@ -3643,10 +3648,7 @@ static llvm::Value 
*emitDestructorsFunction(CodeGenModule &CGM,
 /// \endcode
 static llvm::Value *
 emitTaskPrivateMappingFunction(CodeGenModule &CGM, SourceLocation Loc,
-   ArrayRef PrivateVars,
-   ArrayRef FirstprivateVars,
-   ArrayRef LastprivateVars,
-   QualType PrivatesQTy,
+   const OMPTaskDataTy &Data, QualType PrivatesQTy,
ArrayRef Privates) {
   ASTContext &C = CGM.getContext();
   FunctionArgList Args;
@@ -3655,9 +3657,9 @@ emitTaskPrivateMappingFunction(CodeGenModule &CGM, 
SourceLocation Loc,
   C.getPointerType(PrivatesQTy).withConst().withRestrict(),
   ImplicitParamDecl::Other);
   Args.push_back(&TaskPrivatesArg);
-  llvm::DenseMap PrivateVarsPos;
+  llvm::DenseMap, unsigned> PrivateVarsPos;
   unsigned Counter = 1;
-  for (const Expr *E : PrivateVars) {
+  for (const Expr *E : Data.PrivateVars) {
 Args.push_back(ImplicitParamDecl::Create(
 C, /*DC=*/nullptr, Loc, /*Id=*/nullptr,
 C.getPointerType(C.getPointerType(E->getType()))
@@ -3668,7 +3670,7 @@ emitTaskPrivateMappingFunction(CodeGenModule &CGM, 
SourceLocation Loc,
 PrivateVarsPos[VD] = Counter;
 ++Counter;
   }
-  for (const Expr *E : FirstprivateVars) {
+  for (const Expr *E : Data.FirstprivateVars) {
 Args.push_back(ImplicitParamDecl::Create(
 C, /*DC=*/nullptr, Loc, /*Id=*/nullptr,
 C.getPointerType(C.getPointerType(E->getType()))
@@ -3679,7 +3681,7 @@ emitTaskPrivateMappingFunction(CodeGenModule &CGM, 
SourceLocation Loc,
 PrivateVarsPos[VD] = Counter;
 ++Counter;
   }
-  for (const Expr *E : LastprivateVars) {
+  for (const Expr *E : Data.LastprivateVars) {
 Args.push_back(ImplicitParamDecl::Create(
 C

[PATCH] D85753: [clangd] Discard diagnostics from another SourceManager.

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

Yeah I think this is the right approach for now, because the cached modules 
don't include diagnostics and ensuring that they're persisted and available is 
a larger project.




Comment at: clang-tools-extra/clangd/Diagnostics.cpp:568
+  // If the diagnostic was generated for a different SourceManager, skip it.
+  // This can happen when using implicit modules.
+  if (OrigSrcMgr && Info.hasSourceManager() &&

maybe a FIXME: errors from implicitly built modules should be surfaced somehow 
(but then must also be surfaced when the module was cached)



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:568
+  // If the diagnostic was generated for a different SourceManager, skip it.
+  // This can happen when using implicit modules.
+  if (OrigSrcMgr && Info.hasSourceManager() &&

sammccall wrote:
> maybe a FIXME: errors from implicitly built modules should be surfaced 
> somehow (but then must also be surfaced when the module was cached)
Can we be a bit more specific: this happens when an #include causes a module to 
be implicitly built, using a separate SourceManager.



Comment at: clang-tools-extra/clangd/unittests/ModulesTests.cpp:44
+  // Produce a diagnostic while building an implicit module. Use
+  // -fmodules-strick-decluse, but any non-silenced diagnostic will do.
+  TestTU TU = TestTU::withCode(R"cpp(

nit: strict


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85753

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


[PATCH] D85826: [clang] Make signature help work with dependent args

2020-08-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

This looks like a nice improvement.




Comment at: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp:1212
+  R"cpp(
+int foo(int a, int b);
+template  void bar(T t) {

These tests are nice.

But we're changing Sema in this patch, I think we'd better to have these in 
clang, `/test/CodeCompletion/call.cpp` seems to be the place.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:5571
+  Expr *NakedFn = Fn->IgnoreParenCasts();
+  // In presence of dependent args we surface all posible signatures, without
+  // performing any semantic checks on availability. That's to improve user

possible.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:5573
+  // performing any semantic checks on availability. That's to improve user
+  // experience, it is better to see all overloads rather than none.
+  if (Expr::hasAnyTypeDependentArguments(Args)) {

I'm a bit nervous to show all overloads regardlessly, I think we could do some 
smarter things like

1. if there are some prefix non-type-dependent arguments, we could use these 
type information to filter out some unrelated candidates;
2. different overloads may have different number of parameters, this is an 
important signal, e.g. `foo(t, ^t)` should not give `void foo(int)` result;

2 seems quite critical and trivial to implement, maybe we can do it in this 
patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85826

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


[PATCH] D85728: [Analyzer] Support for the new variadic isa<> and isa_and_not_null<> in CastValueChecker

2020-08-12 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:270-272
+default:
+  llvm_unreachable("Invalid template argument for isa<> or "
+   "isa_and_nonnull<>");

baloghadamsoftware wrote:
> NoQ wrote:
> > We shouldn't crash when code under analysis doesn't match our expectation.
> The question is whether we can get any other template argument kind for 
> `llvm::isa<>()` and `llvm::isa_and_nonnull<>()` than `Type` or `Pack`?
I think it is worth to ponder about the below case. What if `isa` is used in a 
dependent context (i.e. it is used inside another template)?
```
/// The template argument is an expression, and we've not resolved it to one
/// of the other forms yet, either because it's dependent or because we're
/// representing a non-canonical template argument (for instance, in a
/// TemplateSpecializationType).
Expression,
```


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

https://reviews.llvm.org/D85728

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


[PATCH] D79431: [analyzer] StdLibraryFunctionsChecker: Add better diagnostics

2020-08-12 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79431

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


[clang] 3651658 - Revert "[OPENMP]Fix PR37671: Privatize local(private) variables in untied tasks."

2020-08-12 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-08-12T09:50:32-04:00
New Revision: 3651658bdd11a085b727783f27495a198c4f3bc5

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

LOG: Revert "[OPENMP]Fix PR37671: Privatize local(private) variables in untied 
tasks."

This reverts commit ec9563c54ed25e9f9cbe60985399212d50bd801d to
investigate compiler crash revelaed by the buildbots.

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntime.h
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/task_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index addf6c34168c8..0582de5ebafee 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -180,7 +180,7 @@ class CGOpenMPTaskOutlinedRegionInfo final : public 
CGOpenMPRegionInfo {
 UntiedCodeGen(CGF);
 CodeGenFunction::JumpDest CurPoint =
 CGF.getJumpDestInCurrentScope(".untied.next.");
-CGF.EmitBranch(CGF.ReturnBlock.getBlock());
+CGF.EmitBranchThroughCleanup(CGF.ReturnBlock);
 CGF.EmitBlock(CGF.createBasicBlock(".untied.jmp."));
 
UntiedSwitch->addCase(CGF.Builder.getInt32(UntiedSwitch->getNumCases()),
   CGF.Builder.GetInsertBlock());
@@ -3370,7 +3370,6 @@ struct PrivateHelpersTy {
const VarDecl *PrivateCopy, const VarDecl *PrivateElemInit)
   : OriginalRef(OriginalRef), Original(Original), PrivateCopy(PrivateCopy),
 PrivateElemInit(PrivateElemInit) {}
-  PrivateHelpersTy(const VarDecl *Original) : Original(Original) {}
   const Expr *OriginalRef = nullptr;
   const VarDecl *Original = nullptr;
   const VarDecl *PrivateCopy = nullptr;
@@ -3391,10 +3390,6 @@ createPrivatesRecordDecl(CodeGenModule &CGM, 
ArrayRef Privates) {
 for (const auto &Pair : Privates) {
   const VarDecl *VD = Pair.second.Original;
   QualType Type = VD->getType().getNonReferenceType();
-  // If the private variable is a local variable with lvalue ref type,
-  // allocate the pointer instead of the pointee type.
-  if (!Pair.second.OriginalRef && VD->getType()->isLValueReferenceType())
-Type = C.getPointerType(Type);
   FieldDecl *FD = addFieldToRecordDecl(C, RD, Type);
   if (VD->hasAttrs()) {
 for (specific_attr_iterator I(VD->getAttrs().begin()),
@@ -3648,7 +3643,10 @@ static llvm::Value 
*emitDestructorsFunction(CodeGenModule &CGM,
 /// \endcode
 static llvm::Value *
 emitTaskPrivateMappingFunction(CodeGenModule &CGM, SourceLocation Loc,
-   const OMPTaskDataTy &Data, QualType PrivatesQTy,
+   ArrayRef PrivateVars,
+   ArrayRef FirstprivateVars,
+   ArrayRef LastprivateVars,
+   QualType PrivatesQTy,
ArrayRef Privates) {
   ASTContext &C = CGM.getContext();
   FunctionArgList Args;
@@ -3657,9 +3655,9 @@ emitTaskPrivateMappingFunction(CodeGenModule &CGM, 
SourceLocation Loc,
   C.getPointerType(PrivatesQTy).withConst().withRestrict(),
   ImplicitParamDecl::Other);
   Args.push_back(&TaskPrivatesArg);
-  llvm::DenseMap, unsigned> PrivateVarsPos;
+  llvm::DenseMap PrivateVarsPos;
   unsigned Counter = 1;
-  for (const Expr *E : Data.PrivateVars) {
+  for (const Expr *E : PrivateVars) {
 Args.push_back(ImplicitParamDecl::Create(
 C, /*DC=*/nullptr, Loc, /*Id=*/nullptr,
 C.getPointerType(C.getPointerType(E->getType()))
@@ -3670,7 +3668,7 @@ emitTaskPrivateMappingFunction(CodeGenModule &CGM, 
SourceLocation Loc,
 PrivateVarsPos[VD] = Counter;
 ++Counter;
   }
-  for (const Expr *E : Data.FirstprivateVars) {
+  for (const Expr *E : FirstprivateVars) {
 Args.push_back(ImplicitParamDecl::Create(
 C, /*DC=*/nullptr, Loc, /*Id=*/nullptr,
 C.getPointerType(C.getPointerType(E->getType()))
@@ -3681,7 +3679,7 @@ emitTaskPrivateMappingFunction(CodeGenModule &CGM, 
SourceLocation Loc,
 PrivateVarsPos[VD] = Counter;
 ++Counter;
   }
-  for (const Expr *E : Data.LastprivateVars) {
+  for (const Expr *E : LastprivateVars) {
 Args.push_back(ImplicitParamDecl::Create(
 C, /*DC=*/nullptr, Loc, /*Id=*/nullptr,
 C.getPointerType(C.getPointerType(E->getType()))
@@ -3692,17 +3690,6 @@ emitTaskPrivateMappingFunction(CodeGenModule &CGM, 
SourceLocation Loc,
 PrivateVarsPos[VD] = Counter;
 ++Counter;
   }
-  for (const VarDecl *VD : Data.PrivateLocals) {
-QualType Ty = VD->getType().getNonReferenceType();
-if (VD->getType()->isLValueReferenceType())
-  Ty = C.getPointerType(Ty);
-Args.push_back(ImplicitPara

[PATCH] D85819: [SyntaxTree] Split tests

2020-08-12 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 285070.
eduucaldas added a comment.

- [SyntaxTree] Split tests for `QualifiedId`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85819

Files:
  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
@@ -632,26 +632,48 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, UnqualifiedId) {
+TEST_P(SyntaxTreeTest, UnqualifiedIdIdentifier) {
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test(int a) {
+  a;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-a
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdOperatorFunctionId) {
   if (!GetParam().isCXX()) {
 return;
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
 struct X {
-  // TODO: Expose `id-expression` from `Declarator`
   friend X operator+(const X&, const X&);
-  operator int();
 };
-template
-void f(T&);
 void test(X x) {
-  x;  // identifier
-  operator+(x, x);// operator-function-id
-  f(x);// template-id
-  // TODO: Expose `id-expression` from `MemberExpr`
-  x.operator int();   // conversion-funtion-id
-  x.~X(); // ~type-name
+  operator+(x, x);
 }
 )cpp",
   R"txt(
@@ -682,35 +704,8 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
-| |-SimpleDeclaration
-| | |-SimpleDeclarator
-| | | |-operator
-| | | |-int
-| | | `-ParametersAndQualifiers
-| | |   |-(
-| | |   `-)
-| | `-;
 | |-}
 | `-;
-|-TemplateDeclaration
-| |-template
-| |-<
-| |-UnknownDeclaration
-| | |-typename
-| | `-T
-| |->
-| `-SimpleDeclaration
-|   |-void
-|   |-SimpleDeclarator
-|   | |-f
-|   | `-ParametersAndQualifiers
-|   |   |-(
-|   |   |-SimpleDeclaration
-|   |   | |-T
-|   |   | `-SimpleDeclarator
-|   |   |   `-&
-|   |   `-)
-|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -725,11 +720,6 @@
   `-CompoundStatement
 |-{
 |-ExpressionStatement
-| |-IdExpression
-| | `-UnqualifiedId
-| |   `-x
-| `-;
-|-ExpressionStatement
 | |-UnknownExpression
 | | |-IdExpression
 | | | `-UnqualifiedId
@@ -745,20 +735,53 @@
 | | |   `-x
 | | `-)
 | `-;
-|-ExpressionStatement
-| |-UnknownExpression
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   |-f
-| | |   |-<
-| | |   |-X
-| | |   `->
-| | |-(
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-x
-| | `-)
-| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdConversionFunctionId) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  operator int();
+};
+void test(X x) {
+  // TODO: Expose `id-expression` from `MemberExpr`
+  x.operator int();
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-int
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
 |-ExpressionStatement
 | |-UnknownExpression
 | | |-UnknownExpression
@@ -771,6 +794,93 @@
 | | |-(
 | | `-)
 | `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdLiteralOperatorId) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+unsigned operator "" _w(char);
+void test() {
+  operator "" _w('1');
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-char
+| |   `-)
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   |-operator
+| | |   |-""
+| | |   `-_w
+| | |-(
+| | |-CharacterLiteralExpression
+| | | `-'1'
+| | `-)
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdDestructor) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X { }

[PATCH] D85819: [SyntaxTree] Split tests

2020-08-12 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 285071.
eduucaldas added a comment.

Rename tests following `TestSuite_TestCase`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85819

Files:
  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
@@ -632,26 +632,48 @@
 )txt"));
 }
 
-TEST_P(SyntaxTreeTest, UnqualifiedId) {
+TEST_P(SyntaxTreeTest, UnqualifiedId_Identifier) {
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+void test(int a) {
+  a;
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-int
+  |   | `-SimpleDeclarator
+  |   |   `-a
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-IdExpression
+| | `-UnqualifiedId
+| |   `-a
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedId_OperatorFunctionId) {
   if (!GetParam().isCXX()) {
 return;
   }
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
 struct X {
-  // TODO: Expose `id-expression` from `Declarator`
   friend X operator+(const X&, const X&);
-  operator int();
 };
-template
-void f(T&);
 void test(X x) {
-  x;  // identifier
-  operator+(x, x);// operator-function-id
-  f(x);// template-id
-  // TODO: Expose `id-expression` from `MemberExpr`
-  x.operator int();   // conversion-funtion-id
-  x.~X(); // ~type-name
+  operator+(x, x);
 }
 )cpp",
   R"txt(
@@ -682,35 +704,8 @@
 | |   |   |   `-&
 | |   |   `-)
 | |   `-;
-| |-SimpleDeclaration
-| | |-SimpleDeclarator
-| | | |-operator
-| | | |-int
-| | | `-ParametersAndQualifiers
-| | |   |-(
-| | |   `-)
-| | `-;
 | |-}
 | `-;
-|-TemplateDeclaration
-| |-template
-| |-<
-| |-UnknownDeclaration
-| | |-typename
-| | `-T
-| |->
-| `-SimpleDeclaration
-|   |-void
-|   |-SimpleDeclarator
-|   | |-f
-|   | `-ParametersAndQualifiers
-|   |   |-(
-|   |   |-SimpleDeclaration
-|   |   | |-T
-|   |   | `-SimpleDeclarator
-|   |   |   `-&
-|   |   `-)
-|   `-;
 `-SimpleDeclaration
   |-void
   |-SimpleDeclarator
@@ -725,11 +720,6 @@
   `-CompoundStatement
 |-{
 |-ExpressionStatement
-| |-IdExpression
-| | `-UnqualifiedId
-| |   `-x
-| `-;
-|-ExpressionStatement
 | |-UnknownExpression
 | | |-IdExpression
 | | | `-UnqualifiedId
@@ -745,20 +735,53 @@
 | | |   `-x
 | | `-)
 | `-;
-|-ExpressionStatement
-| |-UnknownExpression
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   |-f
-| | |   |-<
-| | |   |-X
-| | |   `->
-| | |-(
-| | |-IdExpression
-| | | `-UnqualifiedId
-| | |   `-x
-| | `-)
-| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedId_ConversionFunctionId) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X {
+  operator int();
+};
+void test(X x) {
+  // TODO: Expose `id-expression` from `MemberExpr`
+  x.operator int();
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-int
+| | | `-ParametersAndQualifiers
+| | |   |-(
+| | |   `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   |-SimpleDeclaration
+  |   | |-X
+  |   | `-SimpleDeclarator
+  |   |   `-x
+  |   `-)
+  `-CompoundStatement
+|-{
 |-ExpressionStatement
 | |-UnknownExpression
 | | |-UnknownExpression
@@ -771,6 +794,93 @@
 | | |-(
 | | `-)
 | `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedId_LiteralOperatorId) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+unsigned operator "" _w(char);
+void test() {
+  operator "" _w('1');
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| |   |-(
+| |   |-SimpleDeclaration
+| |   | `-char
+| |   `-)
+| `-;
+`-SimpleDeclaration
+  |-void
+  |-SimpleDeclarator
+  | |-test
+  | `-ParametersAndQualifiers
+  |   |-(
+  |   `-)
+  `-CompoundStatement
+|-{
+|-ExpressionStatement
+| |-UnknownExpression
+| | |-IdExpression
+| | | `-UnqualifiedId
+| | |   |-operator
+| | |   |-""
+| | |   `-_w
+| | |-(
+| | |-CharacterLiteralExpression
+| | | `-'1'
+| | `-)
+| `-;
+`-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedId_Destructor) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqual(
+  R"cpp(
+struct X

[PATCH] D85819: [SyntaxTree] Split tests

2020-08-12 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:1005
+
+TEST_P(SyntaxTreeTest, QualifiedIdWithNamespace) {
+  if (!GetParam().isCXX()) {

Here I didn't merely split the tests, I also changed them a bit. PTAL.




Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:1546-1548
+unsigned operator "" _r(const char*);
+template 
+unsigned operator "" _t();

Same setup for `FloatUserDefinedLiteral`. I think it is justified with the 
Annotations we can constraint the dump just to the expressions being tested



Comment at: clang/unittests/Tooling/Syntax/TreeTest.cpp:635
 
-TEST_P(SyntaxTreeTest, UnqualifiedId) {
+TEST_P(SyntaxTreeTest, UnqualifiedIdIdentifier) {
+  EXPECT_TRUE(treeDumpEqual(

eduucaldas wrote:
> It seems inappropriate to always repeat `UnqualfiiedId`, do you have any 
> other suggestion?
Last commit change names to `TestSuite_TestCase`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85819

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


[PATCH] D84886: Create LoopNestPass

2020-08-12 Thread Whitney Tsang via Phabricator via cfe-commits
Whitney added a comment.

Examples of existing transformations that can be benefited from LoopNestPass:  
LoopInterchange, LoopUnrollAndJam, LoopFusion, LoopIdiom, LoopDistribution, ...
And their corresponding cost model analyses can be benefited from 
LoopNestAnalysis, e.g. LoopCacheCost.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84886

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


[clang] ddbd21d - [OPENMP]Do not add TGT_OMP_TARGET_PARAM flag to non-captured mapped arguments.

2020-08-12 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-08-12T10:06:52-04:00
New Revision: ddbd21d288f6ff7d175f18ddee0ee6407626445a

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

LOG: [OPENMP]Do not add TGT_OMP_TARGET_PARAM flag to non-captured mapped 
arguments.

If the arguments are mapped, but are actually not used in the target
region, the compiler still adds attribute TGT_OMP_TARGET_PARAM for such
arguments. It makes the libomptarget to add such parameters to the list
of arguments, passed to the kernel at the runtime, and may lead to
incorrect results/crashes during execution.

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/target_map_codegen_18.inc
clang/test/OpenMP/target_map_codegen_20.cpp
clang/test/OpenMP/target_map_codegen_31.cpp
clang/test/OpenMP/target_map_codegen_32.cpp
clang/test/OpenMP/target_teams_map_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 0582de5ebafe..19c703623d27 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7911,7 +7911,8 @@ class MappableExprsHandler {
   /// individual struct members.
   void emitCombinedEntry(MapCombinedInfoTy &CombinedInfo,
  MapFlagsArrayTy &CurTypes,
- const StructRangeInfoTy &PartialStruct) const {
+ const StructRangeInfoTy &PartialStruct,
+ bool NotTargetParams = false) const {
 // Base is the base of the struct
 CombinedInfo.BasePointers.push_back(PartialStruct.Base.getPointer());
 // Pointer is the address of the lowest element
@@ -7928,8 +7929,9 @@ class MappableExprsHandler {
 llvm::Value *Size = CGF.Builder.CreateIntCast(Diff, CGF.Int64Ty,
   /*isSigned=*/false);
 CombinedInfo.Sizes.push_back(Size);
-// Map type is always TARGET_PARAM
-CombinedInfo.Types.push_back(OMP_MAP_TARGET_PARAM);
+// Map type is always TARGET_PARAM, if generate info for captures.
+CombinedInfo.Types.push_back(NotTargetParams ? OMP_MAP_NONE
+ : OMP_MAP_TARGET_PARAM);
 // If any element has the present modifier, then make sure the runtime
 // doesn't attempt to allocate the struct.
 if (CurTypes.end() !=
@@ -7955,7 +7957,7 @@ class MappableExprsHandler {
   /// pair of the relevant declaration and index where it occurs is appended to
   /// the device pointers info array.
   void generateAllInfo(
-  MapCombinedInfoTy &CombinedInfo,
+  MapCombinedInfoTy &CombinedInfo, bool NotTargetParams = false,
   const llvm::DenseSet> &SkipVarSet =
   llvm::DenseSet>()) const {
 // We have to process the component lists that relate with the same
@@ -8078,8 +8080,9 @@ class MappableExprsHandler {
   UseDevicePtrCombinedInfo.Pointers.push_back(Ptr);
   UseDevicePtrCombinedInfo.Sizes.push_back(
   llvm::Constant::getNullValue(CGF.Int64Ty));
-  UseDevicePtrCombinedInfo.Types.push_back(OMP_MAP_RETURN_PARAM |
-   OMP_MAP_TARGET_PARAM);
+  UseDevicePtrCombinedInfo.Types.push_back(
+  OMP_MAP_RETURN_PARAM |
+  (NotTargetParams ? OMP_MAP_NONE : OMP_MAP_TARGET_PARAM));
   UseDevicePtrCombinedInfo.Mappers.push_back(nullptr);
 }
   }
@@ -8144,8 +8147,11 @@ class MappableExprsHandler {
 Ptr = CGF.EmitScalarExpr(IE);
   CombinedInfo.BasePointers.emplace_back(Ptr, VD);
   CombinedInfo.Pointers.push_back(Ptr);
-  
CombinedInfo.Sizes.push_back(llvm::Constant::getNullValue(CGF.Int64Ty));
-  CombinedInfo.Types.push_back(OMP_MAP_RETURN_PARAM | 
OMP_MAP_TARGET_PARAM);
+  CombinedInfo.Sizes.push_back(
+  llvm::Constant::getNullValue(CGF.Int64Ty));
+  CombinedInfo.Types.push_back(
+  OMP_MAP_RETURN_PARAM |
+  (NotTargetParams ? OMP_MAP_NONE : OMP_MAP_TARGET_PARAM));
   CombinedInfo.Mappers.push_back(nullptr);
 }
   }
@@ -8154,7 +8160,7 @@ class MappableExprsHandler {
 for (const auto &M : Info) {
   // We need to know when we generate information for the first component
   // associated with a capture, because the mapping flags depend on it.
-  bool IsFirstComponentList = true;
+  bool IsFirstComponentList = !NotTargetParams;
 
   // Temporary generated information.
   MapCombinedInfoTy CurInfo;
@@ -8227,7 +8233,8 @@ class MappableExprsHandler {
   // If there is an entry in PartialStruct it means we have a struct with
   // indi

[PATCH] D85755: [OPENMP]Do not add TGT_OMP_TARGET_PARAM flag to non-captured mapped arguments.

2020-08-12 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGddbd21d288f6: [OPENMP]Do not add TGT_OMP_TARGET_PARAM flag 
to non-captured mapped arguments. (authored by ABataev).

Changed prior to commit:
  https://reviews.llvm.org/D85755?vs=284806&id=285074#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85755

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_codegen_18.inc
  clang/test/OpenMP/target_map_codegen_20.cpp
  clang/test/OpenMP/target_map_codegen_31.cpp
  clang/test/OpenMP/target_map_codegen_32.cpp
  clang/test/OpenMP/target_teams_map_codegen.cpp

Index: clang/test/OpenMP/target_teams_map_codegen.cpp
===
--- clang/test/OpenMP/target_teams_map_codegen.cpp
+++ clang/test/OpenMP/target_teams_map_codegen.cpp
@@ -20,16 +20,16 @@
 #ifndef HEADER
 #define HEADER
 
-// HOST: @[[MAPTYPES_PRIVATE:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
+// HOST: @[[MAPTYPES_PRIVATE:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 3, i64 3]
 // HOST: @[[MAPTYPES_FIRSTPRIVATE:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
 // HOST: @[[MAPTYPES_REDUCTION:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
 // HOST: @[[MAPTYPES_FROM:.offload_maptypes[0-9.]*]] = private {{.*}}constant [1 x i64] [i64 34]
 // HOST: @[[MAPTYPES_TO:.offload_maptypes[0-9.]*]] = private {{.*}}constant [1 x i64] [i64 33]
 // HOST: @[[MAPTYPES_ALLOC:.offload_maptypes[0-9.]*]] = private {{.*}}constant [1 x i64] [i64 32]
-// HOST: @[[MAPTYPES_ARRAY_R0:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 35, i64 35, i64 35]
-// HOST: @[[MAPTYPES_ARRAY_R1:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 33, i64 33, i64 33]
-// HOST-INT128: @[[MAPTYPES_INT128_R0:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 35, i64 35, i64 35]
-// HOST-INT128: @[[MAPTYPES_INT128_R1:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 34, i64 34, i64 34]
+// HOST: @[[MAPTYPES_ARRAY_R0:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 35, i64 35, i64 3]
+// HOST: @[[MAPTYPES_ARRAY_R1:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 33, i64 33, i64 1]
+// HOST-INT128: @[[MAPTYPES_INT128_R0:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 35, i64 35, i64 3]
+// HOST-INT128: @[[MAPTYPES_INT128_R1:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 34, i64 34, i64 2]
 //
 // CHECK: @.omp_offloading.entry_name{{[0-9.]*}} = {{.*}} c"[[OFFLOAD_PRIVATE:__omp_offloading_[^"\\]*mapWithPrivate[^"\\]*]]\00"
 // CHECK: @.omp_offloading.entry_name{{[0-9.]*}} = {{.*}} c"[[OFFLOAD_FIRSTPRIVATE:__omp_offloading_[^"\\]*mapWithFirstprivate[^"\\]*]]\00"
Index: clang/test/OpenMP/target_map_codegen_32.cpp
===
--- clang/test/OpenMP/target_map_codegen_32.cpp
+++ clang/test/OpenMP/target_map_codegen_32.cpp
@@ -40,8 +40,10 @@
 // MEMBER_OF_1=0x1 | PRESENT=0x1000 | FROM=0x2 | TO=0x1 = 0x11003
 
 // CK31B-LABEL: @.__omp_offloading_{{.*}}test_present_members{{.*}}_l{{[0-9]+}}.region_id = weak constant i8 0
-// CK31B: [[MTYPE00:@.+]] = private {{.*}}constant [3 x i64] [i64 [[#0x1020]],
-// CK31B-SAME: {{^}} i64 [[#0x10003]], i64 [[#0x11003]]]
+// CK31B-USE: [[MTYPE00:@.+]] = private {{.*}}constant [3 x i64] [i64 [[#0x1020]],
+// CK31B-NOUSE: [[MTYPE00:@.+]] = private {{.*}}constant [3 x i64] [i64 [[#0x1000]],
+// CK31B-USE-SAME: {{^}} i64 [[#0x10003]], i64 [[#0x11003]]]
+// CK31B-NOUSE-SAME: {{^}} i64 [[#0x10003]], i64 [[#0x11003]]]
 
 struct ST {
   int i;
Index: clang/test/OpenMP/target_map_codegen_31.cpp
===
--- clang/test/OpenMP/target_map_codegen_31.cpp
+++ clang/test/OpenMP/target_map_codegen_31.cpp
@@ -42,23 +42,27 @@
 // CK31A-LABEL: @.__omp_offloading_{{.*}}explicit_maps_single{{.*}}_l{{[0-9]+}}.region_id = weak constant i8 0
 //
 // PRESENT=0x1000 | TARGET_PARAM=0x20 = 0x1020
-// CK31A: [[MTYPE00:@.+]] = private {{.*}}constant [7 x i64] [i64 [[#0x1020]],
+// CK31A-USE: [[MTYPE00:@.+]] = private {{.*}}constant [7 x i64] [i64 [[#0x1020]],
+// CK31A-NOUSE: [[MTYPE00:@.+]] = private {{.*}}constant [7 x i64] [i64 [[#0x1000]],
 //
 // MEMBER_OF_1=0x1 | FROM=0x2 | TO=0x1 = 0x10003
 // MEMBER_OF_1=0x1 | PRESENT=0x1000 | FROM=0x2 | TO=0x1 = 0x11003
 // PRESENT=0x1000 | TARGET_PARAM=0x20 | FROM=0x2 | TO=0x1 = 0x1023
-// CK31A-SAME: {{^}} i64 [[#0x10003]], i64 [[#0x11003]], i64 [[#0x1023]],
+// CK31A-USE-SAME: {{^}} i64 [[#0x10003]], i64 [[#0x11003]], i64 [[#0x1023]],
+// CK31A-NOUSE-SAM

[PATCH] D85093: [analyzer] StdLibraryFunctionsChecker: Add support for new functions

2020-08-12 Thread Zurab Tsinadze via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG25bbe234e4e7: [analyzer] StdLibraryFunctionsChecker: Add 
support for new functions (authored by zukatsinadze).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85093

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
@@ -45,7 +45,6 @@
   // bugpath-note{{TRUE}} \
   // bugpath-note{{Left side of '&&' is true}} \
   // bugpath-note{{'x' is <= 255}}
-
 }
 
 void test_alnum_symbolic2(int x) {
@@ -62,6 +61,114 @@
   }
 }
 
+int toupper(int);
+
+void test_toupper_concrete(int v) {
+  int ret = toupper(256); // \
+  // 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)ret;
+}
+
+void test_toupper_symbolic(int x) {
+  int ret = toupper(x);
+  (void)ret;
+
+  clang_analyzer_eval(EOF <= x && x <= 255); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}} \
+  // bugpath-note{{Left side of '&&' is true}} \
+  // bugpath-note{{'x' is <= 255}}
+}
+
+void test_toupper_symbolic2(int x) {
+  if (x > 255) { // \
+// bugpath-note{{Assuming 'x' is > 255}} \
+// bugpath-note{{Taking true branch}}
+
+int ret = toupper(x); // \
+// 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)ret;
+  }
+}
+
+int tolower(int);
+
+void test_tolower_concrete(int v) {
+  int ret = tolower(256); // \
+  // 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)ret;
+}
+
+void test_tolower_symbolic(int x) {
+  int ret = tolower(x);
+  (void)ret;
+
+  clang_analyzer_eval(EOF <= x && x <= 255); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}} \
+  // bugpath-note{{Left side of '&&' is true}} \
+  // bugpath-note{{'x' is <= 255}}
+}
+
+void test_tolower_symbolic2(int x) {
+  if (x > 255) { // \
+// bugpath-note{{Assuming 'x' is > 255}} \
+// bugpath-note{{Taking true branch}}
+
+int ret = tolower(x); // \
+// 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)ret;
+  }
+}
+
+int toascii(int);
+
+void test_toascii_concrete(int v) {
+  int ret = toascii(256); // \
+  // 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)ret;
+}
+
+void test_toascii_symbolic(int x) {
+  int ret = toascii(x);
+  (void)ret;
+
+  clang_analyzer_eval(EOF <= x && x <= 255); // \
+  // report-warning{{TRUE}} \
+  // bugpath-warning{{TRUE}} \
+  // bugpath-note{{TRUE}} \
+  // bugpath-note{{Left side of '&&' is true}} \
+  // bugpath-note{{'x' is <= 255}}
+}
+
+void test_toascii_symbolic2(int x) {
+  if (x > 255) { // \
+// bugpath-note{{Assuming 'x' is > 255}} \
+// bugpath-note{{Taking true branch}}
+
+int ret = toascii(x); // \
+// 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)ret;
+  }
+}
+
 typedef struct FILE FILE;
 typedef typeof(sizeof(int)) size_t;
 size_t fread(void *restrict, size_t, size_t, FILE *restrict);
@@ -80,7 +187,7 @@
   // bugpath-note{{'buf' is not equal to null}}
 }
 void test_notnull_symbolic2(FILE *fp, int *buf) {
-  if (!buf) // bugpath-note{{Assuming 'buf' is null}} \
+  if (!buf)  // bugpath-note{{Assuming 'buf' is null}} \
 // bugpath-note{{Taking true branch}}
 fread(buf, sizeof(int), 10, fp); // \
 // report-warning{{Function argument constraint is not satisfied}} \
@@ -151,7 +258,7 @@
 }
 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}}
+  short buf[3]; // bugpath-note{{'

[clang] 25bbe23 - [analyzer] StdLibraryFunctionsChecker: Add support for new functions

2020-08-12 Thread Zurab Tsinadze via cfe-commits

Author: Zurab Tsinadze
Date: 2020-08-12T16:20:00+02:00
New Revision: 25bbe234e4e73e6345f4f0b61e680abf5a90d59f

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

LOG: [analyzer] StdLibraryFunctionsChecker: Add support for new functions

`toupper`, `tolower`, `toascii` functions were added to
StdLibraryFunctionsChecker to fully cover CERT STR37-C rule:
https://wiki.sei.cmu.edu/confluence/x/BNcxBQ

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

Added: 


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

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index e437c33bd81a..030f995739e3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -40,12 +40,12 @@
 //
 // The following standard C functions are currently supported:
 //
-//   fgetc  getline   isdigit   isupper
+//   fgetc  getline   isdigit   isupper toascii
 //   fread  isalnum   isgraph   isxdigit
 //   fwrite isalpha   islower   read
 //   getc   isascii   isprint   write
-//   getcharisblank   ispunct
-//   getdelim   iscntrl   isspace
+//   getcharisblank   ispunct   toupper
+//   getdelim   iscntrl   isspace   tolower
 //
 
//===--===//
 
@@ -147,9 +147,7 @@ class StdLibraryFunctionsChecker
 RangeConstraint(ArgNo ArgN, RangeKind Kind, const IntRangeVector &Args)
 : ValueConstraint(ArgN), Kind(Kind), Args(Args) {}
 
-const IntRangeVector &getRanges() const {
-  return Args;
-}
+const IntRangeVector &getRanges() const { return Args; }
 
   private:
 ProgramStateRef applyAsOutOfRange(ProgramStateRef State,
@@ -158,6 +156,7 @@ class StdLibraryFunctionsChecker
 ProgramStateRef applyAsWithinRange(ProgramStateRef State,
const CallEvent &Call,
const Summary &Summary) const;
+
   public:
 ProgramStateRef apply(ProgramStateRef State, const CallEvent &Call,
   const Summary &Summary,
@@ -408,7 +407,7 @@ class StdLibraryFunctionsChecker
   return *this;
 }
 
-Summary &Case(ConstraintSet&& CS) {
+Summary &Case(ConstraintSet &&CS) {
   CaseConstraints.push_back(std::move(CS));
   return *this;
 }
@@ -796,13 +795,13 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   const QualType LongLongTy = ACtx.LongLongTy;
   const QualType SizeTy = ACtx.getSizeType();
 
-  const QualType VoidPtrTy = ACtx.VoidPtrTy; // void *
+  const QualType VoidPtrTy = ACtx.VoidPtrTy;// void *
   const QualType IntPtrTy = ACtx.getPointerType(IntTy); // int *
   const QualType UnsignedIntPtrTy =
   ACtx.getPointerType(UnsignedIntTy); // unsigned int *
   const QualType VoidPtrRestrictTy = getRestrictTy(VoidPtrTy);
   const QualType ConstVoidPtrTy =
-  ACtx.getPointerType(ACtx.VoidTy.withConst()); // const void *
+  ACtx.getPointerType(ACtx.VoidTy.withConst());// const void *
   const QualType CharPtrTy = ACtx.getPointerType(ACtx.CharTy); // char *
   const QualType CharPtrRestrictTy = getRestrictTy(CharPtrTy);
   const QualType ConstCharPtrTy =
@@ -1117,6 +1116,18 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   .Case({ArgumentCondition(0U, OutOfRange,
{{'0', '9'}, {'A', 'F'}, {'a', 'f'}}),
  ReturnValueCondition(WithinRange, SingleValue(0))}));
+  addToFunctionSummaryMap(
+  "toupper", Summary(ArgTypes{IntTy}, RetType{IntTy}, EvalCallAsPure)
+ .ArgConstraint(ArgumentCondition(
+ 0U, WithinRange, {{EOFv, EOFv}, {0, 
UCharRangeMax}})));
+  addToFunctionSummaryMap(
+  "tolower", Summary(ArgTypes{IntTy}, RetType{IntTy}, EvalCallAsPure)
+ .ArgConstraint(ArgumentCondition(
+ 0U, WithinRange, {{EOFv, EOFv}, {0, 
UCharRangeMax}})));
+  addToFunctionSummaryMap(
+  "toascii", Summary(ArgTypes{IntTy}, RetType{IntTy}, EvalCallAsPure)
+ .ArgConstraint(ArgumentCondition(
+ 0U, WithinRange, {{EOFv, EOFv}, {0, 
UCharRangeMax}})));
 
   // The getc() family of functions that returns either a char or an EOF.
   if (FilePtrTy) {
@@ -2033,7 +2044,8 @@ void 
ento::registerStdCLibraryFunctionsChecker(CheckerManager &mgr) {
   mgr.getAnalyzerOptions().getCheckerBooleanOption(Checker, "ModelPOSIX");
 }
 
-bool ento::shouldRegisterStdCLibraryFunctionsC

[PATCH] D83224: [clangd] Move clang-tidy check modifications into ClangdServer

2020-08-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:115
+// either due to crashes or false positives.
+const char *getClangTidyBlacklist() {
+  static const std::string FalsePositives =

njames93 wrote:
> Return by StringRef?
How about `getDisabledClangTidyChecks()` (or literally any other name than 
blacklist)?



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:120
+   // clangd doesn't replay those when using a preamble.
+   "-llvm-header-guard");
+  static const std::string CrashingChecks =

I suspect there are more checks that should be added here. For instance, much 
of `modernize-` is purely stylistic so it's easy to view as being false 
positives (like `modernize-use-trailing-return-types` or whatever it's called).



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:127
+   "-bugprone-use-after-move");
+  static const std::string BlackList =
+  llvm::join_items(", ", FalsePositives, CrashingChecks);

Similarly, rename this. I'd suggest `DisabledChecks`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83224

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


[PATCH] D85834: [AST] Fix a crash on calling getASTRecordLayout on an invalid RecordDecl.

2020-08-12 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/AST/ASTContext.cpp:2463
 
-unsigned PreferredAlign = static_cast(
-toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
-assert(PreferredAlign >= ABIAlign &&
-   "PreferredAlign should be at least as large as ABIAlign.");
-return PreferredAlign;
+if (!RT->getDecl()->isInvalidDecl()) {
+  unsigned PreferredAlign = static_cast(

hokein wrote:
> another proper fix might be change the `getPreferredTypeAlign` signature to 
> support error handling (e.g. return a bool), but that would require a large 
> invasive change for its callers, not sure it is worth.
> 
> I think the current implementation is OK, as the result doesn't really matter 
> for an invalid RecordDecl, and we do similar thing int `getTypeInfoImpl` 
> (returning a fake `Align`/`Width` for invalid decl).  
I think this is fine though it could be clearer/more explicit about how the 
special case is handled.

```
if (RT->getDecl()->isInvalidDecl())
  return ABIAlign;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85834

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


[PATCH] D81865: [clang] Use string tables for static diagnostic descriptions

2020-08-12 Thread Nathan Froyd via Phabricator via cfe-commits
froydnj added a comment.

Ping for an opinion on the recent discussion of how to move forward with this 
patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81865

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


[PATCH] D84637: [AST] Enhance the const expression evaluator to support error-dependent exprs.

2020-08-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

friendly ping @rsmith, the patch is ready for  another round of review. Would 
be nice to have it in clang11.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84637

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


[PATCH] D81272: [clang-tidy] New check `misc-redundant-condition`

2020-08-12 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added inline comments.



Comment at: clang-tools-extra/clang-tidy/misc/RedundantConditionCheck.cpp:73
+  // If the variable has an alias then it can be changed by that alias as well.
+  // FIXME: Track pointers and references.
+  if (hasPtrOrReferenceInFunc(Func, CondVar))

aaron.ballman wrote:
> This FIXME makes me worried that what we really want is a clang static 
> analyzer check, since the check is already flow sensitive and needs to be 
> data sensitive as well. Have you considered implementing this as a static 
> analyzer check?
Actually, it is only a proposal for improvement. Maybe FIXME is not the best 
wording for it. This is not a bug to fix, just a possibility to find more true 
positives. This check is very similar to the infinite loop check which is also 
in Tidy. In the Static Analyzer this check would be too heavyweight and would 
probably produce false positives.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/misc-redundant-condition.cpp:1097
+  }
+}

aaron.ballman wrote:
> Can you add some tests that exercise GNU expression statements, just to make 
> sure we get the behavior correct?
> ```
> if (({foo;})) {
> } else if (({foo;})) {
> }
> 
> if (foo) ({bar;});
> else if (foo) ({bar;});
> ```
> Another thing that's interesting to test is whether the redundant expression 
> is in a subexpression which doesn't contribute to the value of the control 
> expression:
> ```
> if (foo(), val) {
> } else if (foo(), other_val) {
> }
> ```
> (Similar can be tested with GNU statement expressions.)
Do you mean that I should handle these cases as well? (Detect a bug, provide a 
fix.)


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

https://reviews.llvm.org/D81272

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


[clang] 3c8a4ee - [OpenCL] Remove warning for variadic macros in C++ for OpenCL.

2020-08-12 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2020-08-12T16:17:54+01:00
New Revision: 3c8a4ee0764cafb2ba204c7cb7d8b37e6adf72a8

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

LOG: [OpenCL] Remove warning for variadic macros in C++ for OpenCL.

Patch by Ole Strohm (olestrohm)!

Tags: #clang

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

Added: 


Modified: 
clang/lib/Lex/PPDirectives.cpp
clang/test/Preprocessor/macro_variadic.cl

Removed: 




diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 053ef1d2dd18..e4b901a950ae 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -2397,7 +2397,7 @@ bool Preprocessor::ReadMacroParameterList(MacroInfo *MI, 
Token &Tok) {
  diag::ext_variadic_macro);
 
   // OpenCL v1.2 s6.9.e: variadic macros are not supported.
-  if (LangOpts.OpenCL) {
+  if (LangOpts.OpenCL && !LangOpts.OpenCLCPlusPlus) {
 Diag(Tok, diag::ext_pp_opencl_variadic_macros);
   }
 

diff  --git a/clang/test/Preprocessor/macro_variadic.cl 
b/clang/test/Preprocessor/macro_variadic.cl
index cc9458da558e..e58896487121 100644
--- a/clang/test/Preprocessor/macro_variadic.cl
+++ b/clang/test/Preprocessor/macro_variadic.cl
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -verify %s -cl-std=CL1.2
 // RUN: %clang_cc1 -verify %s -pedantic -DPEDANTIC -cl-std=CL1.2
+// RUN: %clang_cc1 -verify %s -cl-std=CLC++
+// RUN: %clang_cc1 -verify %s -pedantic -cl-std=CLC++
 
 
 #define NO_VAR_FUNC(...)  5
@@ -15,6 +17,11 @@ int printf(__constant const char *st, ...);
 
 void foo() {
   NO_VAR_FUNC(1, 2, 3);
-  VAR_FUNC(1, 2, 3); //expected-error{{implicit declaration of function 'func' 
is invalid in OpenCL}}
+  VAR_FUNC(1, 2, 3);
+#if !__OPENCL_CPP_VERSION__
+// expected-error@-2{{implicit declaration of function 'func' is invalid in 
OpenCL}}
+#else
+// expected-error@-4{{use of undeclared identifier 'func'}}
+#endif
   VAR_PRINTF("%i", 1);
 }



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


[PATCH] D85429: [OpenCL] Allow for variadic macros in C++ for OpenCL

2020-08-12 Thread Anastasia Stulova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3c8a4ee0764c: [OpenCL] Remove warning for variadic macros in 
C++ for OpenCL. (authored by Anastasia).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85429

Files:
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/macro_variadic.cl


Index: clang/test/Preprocessor/macro_variadic.cl
===
--- clang/test/Preprocessor/macro_variadic.cl
+++ clang/test/Preprocessor/macro_variadic.cl
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -verify %s -cl-std=CL1.2
 // RUN: %clang_cc1 -verify %s -pedantic -DPEDANTIC -cl-std=CL1.2
+// RUN: %clang_cc1 -verify %s -cl-std=CLC++
+// RUN: %clang_cc1 -verify %s -pedantic -cl-std=CLC++
 
 
 #define NO_VAR_FUNC(...)  5
@@ -15,6 +17,11 @@
 
 void foo() {
   NO_VAR_FUNC(1, 2, 3);
-  VAR_FUNC(1, 2, 3); //expected-error{{implicit declaration of function 'func' 
is invalid in OpenCL}}
+  VAR_FUNC(1, 2, 3);
+#if !__OPENCL_CPP_VERSION__
+// expected-error@-2{{implicit declaration of function 'func' is invalid in 
OpenCL}}
+#else
+// expected-error@-4{{use of undeclared identifier 'func'}}
+#endif
   VAR_PRINTF("%i", 1);
 }
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -2397,7 +2397,7 @@
  diag::ext_variadic_macro);
 
   // OpenCL v1.2 s6.9.e: variadic macros are not supported.
-  if (LangOpts.OpenCL) {
+  if (LangOpts.OpenCL && !LangOpts.OpenCLCPlusPlus) {
 Diag(Tok, diag::ext_pp_opencl_variadic_macros);
   }
 


Index: clang/test/Preprocessor/macro_variadic.cl
===
--- clang/test/Preprocessor/macro_variadic.cl
+++ clang/test/Preprocessor/macro_variadic.cl
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -verify %s -cl-std=CL1.2
 // RUN: %clang_cc1 -verify %s -pedantic -DPEDANTIC -cl-std=CL1.2
+// RUN: %clang_cc1 -verify %s -cl-std=CLC++
+// RUN: %clang_cc1 -verify %s -pedantic -cl-std=CLC++
 
 
 #define NO_VAR_FUNC(...)  5
@@ -15,6 +17,11 @@
 
 void foo() {
   NO_VAR_FUNC(1, 2, 3);
-  VAR_FUNC(1, 2, 3); //expected-error{{implicit declaration of function 'func' is invalid in OpenCL}}
+  VAR_FUNC(1, 2, 3);
+#if !__OPENCL_CPP_VERSION__
+// expected-error@-2{{implicit declaration of function 'func' is invalid in OpenCL}}
+#else
+// expected-error@-4{{use of undeclared identifier 'func'}}
+#endif
   VAR_PRINTF("%i", 1);
 }
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -2397,7 +2397,7 @@
  diag::ext_variadic_macro);
 
   // OpenCL v1.2 s6.9.e: variadic macros are not supported.
-  if (LangOpts.OpenCL) {
+  if (LangOpts.OpenCL && !LangOpts.OpenCLCPlusPlus) {
 Diag(Tok, diag::ext_pp_opencl_variadic_macros);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D81272: [clang-tidy] New check `misc-redundant-condition`

2020-08-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tools-extra/clang-tidy/misc/RedundantConditionCheck.cpp:73
+  // If the variable has an alias then it can be changed by that alias as well.
+  // FIXME: Track pointers and references.
+  if (hasPtrOrReferenceInFunc(Func, CondVar))

baloghadamsoftware wrote:
> aaron.ballman wrote:
> > This FIXME makes me worried that what we really want is a clang static 
> > analyzer check, since the check is already flow sensitive and needs to be 
> > data sensitive as well. Have you considered implementing this as a static 
> > analyzer check?
> Actually, it is only a proposal for improvement. Maybe FIXME is not the best 
> wording for it. This is not a bug to fix, just a possibility to find more 
> true positives. This check is very similar to the infinite loop check which 
> is also in Tidy. In the Static Analyzer this check would be too heavyweight 
> and would probably produce false positives.
Ah, thank you for clarifying (though I think it's interesting that we come down 
on opposite sides of the FP question -- I would argue that the static analyzer 
check would have considerably fewer false positives than the tidy check when 
handling this case).

If the idea is that pointers and references need to be supported in a future 
patch, I think FIXME is a fine comment. If the idea is that pointers and 
references are a potential improvement, I'd probably clarify the comment to 
something more like `FIXME: could potentially support tracking pointers and 
references in the future to improve catching true positives through aliases.`



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/misc-redundant-condition.cpp:1097
+  }
+}

baloghadamsoftware wrote:
> aaron.ballman wrote:
> > Can you add some tests that exercise GNU expression statements, just to 
> > make sure we get the behavior correct?
> > ```
> > if (({foo;})) {
> > } else if (({foo;})) {
> > }
> > 
> > if (foo) ({bar;});
> > else if (foo) ({bar;});
> > ```
> > Another thing that's interesting to test is whether the redundant 
> > expression is in a subexpression which doesn't contribute to the value of 
> > the control expression:
> > ```
> > if (foo(), val) {
> > } else if (foo(), other_val) {
> > }
> > ```
> > (Similar can be tested with GNU statement expressions.)
> Do you mean that I should handle these cases as well? (Detect a bug, provide 
> a fix.)
If the check misses these cases, I think that's reasonable (just comment that 
the tests aren't currently handled). If the check diagnoses these cases but the 
fixit causes an issue, then I think that should be corrected in this patch. If 
it's trivial to support these cases (diagnosing or fixing), it's your call on 
whether you want to do so. I mostly just want the test coverage so I can know 
what to expect.


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

https://reviews.llvm.org/D81272

___
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-08-12 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

In D72705#2210255 , @balazske wrote:

> More results in CodeChecker: emacs_errorreturn 
> 

Something's not quite right, e.g. at 
https://codechecker-demo.eastus.cloudapp.azure.com/Default/report-detail?run=emacs_errorreturn&review-status=Unreviewed&review-status=Confirmed%20bug&detection-status=New&detection-status=Reopened&detection-status=Unresolved&report-id=7258
 there's a bug path element `Function '???' called [...]`. This seems to be the 
case for almost every report... but I found no indication where this "???" 
could come from, in the patch...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72705

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


[clang] f4f3f67 - [OPENMP]Fix PR37671: Privatize local(private) variables in untied tasks.

2020-08-12 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-08-12T11:28:19-04:00
New Revision: f4f3f678f1994d47f745cbfd6a1026f2408425c6

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

LOG: [OPENMP]Fix PR37671: Privatize local(private) variables in untied tasks.

In untied tasks, need to allocate the space for local variales, declared
in task region, when the memory for task data is allocated. THe function
can be interrupted and we can exit from the function in untied task
switch. Need to keep the state of the local variables in this case.
Also, the compiler should not call cleanup when exiting in untied task
switch until the real exit out of the declaration scope is met during
 execution.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntime.h
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/task_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 19c703623d27..66d1b36dbb6a 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -180,7 +180,7 @@ class CGOpenMPTaskOutlinedRegionInfo final : public 
CGOpenMPRegionInfo {
 UntiedCodeGen(CGF);
 CodeGenFunction::JumpDest CurPoint =
 CGF.getJumpDestInCurrentScope(".untied.next.");
-CGF.EmitBranchThroughCleanup(CGF.ReturnBlock);
+CGF.EmitBranch(CGF.ReturnBlock.getBlock());
 CGF.EmitBlock(CGF.createBasicBlock(".untied.jmp."));
 
UntiedSwitch->addCase(CGF.Builder.getInt32(UntiedSwitch->getNumCases()),
   CGF.Builder.GetInsertBlock());
@@ -3370,10 +3370,14 @@ struct PrivateHelpersTy {
const VarDecl *PrivateCopy, const VarDecl *PrivateElemInit)
   : OriginalRef(OriginalRef), Original(Original), PrivateCopy(PrivateCopy),
 PrivateElemInit(PrivateElemInit) {}
+  PrivateHelpersTy(const VarDecl *Original) : Original(Original) {}
   const Expr *OriginalRef = nullptr;
   const VarDecl *Original = nullptr;
   const VarDecl *PrivateCopy = nullptr;
   const VarDecl *PrivateElemInit = nullptr;
+  bool isLocalPrivate() const {
+return !OriginalRef && !PrivateCopy && !PrivateElemInit;
+  }
 };
 typedef std::pair PrivateDataTy;
 } // anonymous namespace
@@ -3390,6 +3394,11 @@ createPrivatesRecordDecl(CodeGenModule &CGM, 
ArrayRef Privates) {
 for (const auto &Pair : Privates) {
   const VarDecl *VD = Pair.second.Original;
   QualType Type = VD->getType().getNonReferenceType();
+  // If the private variable is a local variable with lvalue ref type,
+  // allocate the pointer instead of the pointee type.
+  if (Pair.second.isLocalPrivate() &&
+  VD->getType()->isLValueReferenceType())
+Type = C.getPointerType(Type);
   FieldDecl *FD = addFieldToRecordDecl(C, RD, Type);
   if (VD->hasAttrs()) {
 for (specific_attr_iterator I(VD->getAttrs().begin()),
@@ -3643,10 +3652,7 @@ static llvm::Value 
*emitDestructorsFunction(CodeGenModule &CGM,
 /// \endcode
 static llvm::Value *
 emitTaskPrivateMappingFunction(CodeGenModule &CGM, SourceLocation Loc,
-   ArrayRef PrivateVars,
-   ArrayRef FirstprivateVars,
-   ArrayRef LastprivateVars,
-   QualType PrivatesQTy,
+   const OMPTaskDataTy &Data, QualType PrivatesQTy,
ArrayRef Privates) {
   ASTContext &C = CGM.getContext();
   FunctionArgList Args;
@@ -3655,9 +3661,9 @@ emitTaskPrivateMappingFunction(CodeGenModule &CGM, 
SourceLocation Loc,
   C.getPointerType(PrivatesQTy).withConst().withRestrict(),
   ImplicitParamDecl::Other);
   Args.push_back(&TaskPrivatesArg);
-  llvm::DenseMap PrivateVarsPos;
+  llvm::DenseMap, unsigned> PrivateVarsPos;
   unsigned Counter = 1;
-  for (const Expr *E : PrivateVars) {
+  for (const Expr *E : Data.PrivateVars) {
 Args.push_back(ImplicitParamDecl::Create(
 C, /*DC=*/nullptr, Loc, /*Id=*/nullptr,
 C.getPointerType(C.getPointerType(E->getType()))
@@ -3668,7 +3674,7 @@ emitTaskPrivateMappingFunction(CodeGenModule &CGM, 
SourceLocation Loc,
 PrivateVarsPos[VD] = Counter;
 ++Counter;
   }
-  for (const Expr *E : FirstprivateVars) {
+  for (const Expr *E : Data.FirstprivateVars) {
 Args.push_back(ImplicitParamDecl::Create(
 C, /*DC=*/nullptr, Loc, /*Id=*/nullptr,
 C.getPointerType(C.getPointerType(E->getType()))
@@ -3679,7 +3685,7 @@ emitTaskPrivateMappingFunction(CodeGenModule &CGM, 
SourceLocation Loc,
 PrivateVarsPos[VD] = Counter;
 ++Counter;
   }
-  for

[clang] fbd6d2c - [OPENMP] Fix PR47063: crash when trying to get captured statetment.

2020-08-12 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-08-12T12:05:58-04:00
New Revision: fbd6d2c54e57a4968d29bb22742dd49759b3ecd0

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

LOG: [OPENMP] Fix PR47063: crash when trying to get captured statetment.

Need to call getRawStmt() function instead, when trying to get inner
associated statement for the executable directive. Not all directives
use captured statements.

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/target_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 66d1b36dbb6a..c55403920d8f 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -9801,8 +9801,7 @@ void CGOpenMPRuntime::scanForTargetRegionsFunctions(const 
Stmt *S,
 if (!E->hasAssociatedStmt() || !E->getAssociatedStmt())
   return;
 
-scanForTargetRegionsFunctions(
-E->getInnermostCapturedStmt()->getCapturedStmt(), ParentName);
+scanForTargetRegionsFunctions(E->getRawStmt(), ParentName);
 return;
   }
 

diff  --git a/clang/test/OpenMP/target_codegen.cpp 
b/clang/test/OpenMP/target_codegen.cpp
index 9cec6bfa5a48..55b03aae00a5 100644
--- a/clang/test/OpenMP/target_codegen.cpp
+++ b/clang/test/OpenMP/target_codegen.cpp
@@ -712,6 +712,8 @@ int bar(int n){
 // OMP45:   [[BP:%.+]] = alloca [1 x i8*]
 // OMP45:   [[P:%.+]] = alloca [1 x i8*]
 // OMP45:   [[LOCAL_THIS1:%.+]] = load [[S2]]*, [[S2]]** [[LOCAL_THIS]]
+
+// OMP45:   call void @__kmpc_critical(
 // OMP45:   [[ARR_IDX:%.+]] = getelementptr inbounds [[S2]], [[S2]]* 
[[LOCAL_THIS1]], i[[SZ]] 0
 // OMP45:   [[ARR_IDX2:%.+]] = getelementptr inbounds [[S2]], [[S2]]* 
[[LOCAL_THIS1]], i[[SZ]] 0
 
@@ -731,6 +733,7 @@ int bar(int n){
 // OMP45:   call void [[HVT0:@.+]]([[S2]]* [[LOCAL_THIS1]])
 // OMP45-NEXT:  br label %[[END]]
 // OMP45:   [[END]]
+// OMP45:   call void @__kmpc_end_critical(
 
 // Check that the offloading functions are emitted and that the arguments are
 // correct and loaded correctly for the target regions of the callees of bar().
@@ -826,7 +829,7 @@ int bar(int n){
 // OMP50:   call void [[HVT0:@.+]]([[S2]]* [[LOCAL_THIS1]])
 // OMP50-NEXT:  br label %[[END]]
 // OMP50:   [[END]]
- 
+
 void bar () {
 #define pragma_target _Pragma("omp target")
 pragma_target
@@ -838,6 +841,7 @@ class S2 {
 
 public:
   void zee() {
+#pragma omp critical
 #pragma omp target map(this[0])
   a++;
   }



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


[PATCH] D68720: Support -fstack-clash-protection for x86

2020-08-12 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

I filed https://bugs.llvm.org/show_bug.cgi?id=47139 "Misspelled 
-fnostack-clash-protection" now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68720

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


[PATCH] D84908: [darwin][compiler-rt] build libclang_rt.sim.a Apple Silicon slice, if SDK supports it

2020-08-12 Thread Steven Wu via Phabricator via cfe-commits
steven_wu accepted this revision.
steven_wu added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D84908

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


[clang-tools-extra] fc915d1 - [clang-tidy] use stable_sort instead of sort to fix EXPENSIVE_CHECKS tests

2020-08-12 Thread Erik Pilkington via cfe-commits

Author: Erik Pilkington
Date: 2020-08-12T12:12:10-04:00
New Revision: fc915d13b8671ceddea06e3f2f2d0e18869c41fe

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

LOG: [clang-tidy] use stable_sort instead of sort to fix EXPENSIVE_CHECKS tests

http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-expensive/17317/console

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 1471301a3431..079d57477216 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -744,7 +744,7 @@ struct EqualClangTidyError {
 std::vector ClangTidyDiagnosticConsumer::take() {
   finalizeLastError();
 
-  llvm::sort(Errors, LessClangTidyError());
+  llvm::stable_sort(Errors, LessClangTidyError());
   Errors.erase(std::unique(Errors.begin(), Errors.end(), 
EqualClangTidyError()),
Errors.end());
   if (RemoveIncompatibleErrors)



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


[PATCH] D85193: [clang] Check `expr` inside `InitListChecker::UpdateStructuredListElement()`

2020-08-12 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX updated this revision to Diff 285101.
ArcsinX added a comment.

Fix comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85193

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/init-invalid-struct-array.c


Index: clang/test/Sema/init-invalid-struct-array.c
===
--- /dev/null
+++ clang/test/Sema/init-invalid-struct-array.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+struct S {
+  Unknown u; // expected-error {{unknown type name 'Unknown'}}
+  int i;
+};
+// Should not crash
+struct S s[] = {[0].i = 0, [1].i = 1, {}};
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -1585,10 +1585,7 @@
   IList->setInit(Index, ResultExpr);
 }
   }
-  if (hadError)
-++StructuredIndex;
-  else
-UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
+  UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
   ++Index;
 }
 
@@ -1643,10 +1640,7 @@
   if (!VerifyOnly && expr)
 IList->setInit(Index, expr);
 
-  if (hadError)
-++StructuredIndex;
-  else
-UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
+  UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
   ++Index;
 }
 
@@ -1697,11 +1691,7 @@
   IList->setInit(Index, ResultExpr);
 }
   }
-  if (hadError)
-++StructuredIndex;
-  else
-UpdateStructuredListElement(StructuredList, StructuredIndex,
-ResultExpr);
+  UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
   ++Index;
   return;
 }
@@ -3100,8 +3090,12 @@
 
   if (Expr *PrevInit = StructuredList->updateInit(SemaRef.Context,
   StructuredIndex, expr)) {
-// This initializer overwrites a previous initializer. Warn.
-diagnoseInitOverride(PrevInit, expr->getSourceRange());
+// This initializer overwrites a previous initializer.
+// No need to diagnose when `expr` is nullptr because a more relevant
+// diagnostic has already been issued and this diagnostic is potentially
+// noise.
+if (expr)
+  diagnoseInitOverride(PrevInit, expr->getSourceRange());
   }
 
   ++StructuredIndex;


Index: clang/test/Sema/init-invalid-struct-array.c
===
--- /dev/null
+++ clang/test/Sema/init-invalid-struct-array.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+struct S {
+  Unknown u; // expected-error {{unknown type name 'Unknown'}}
+  int i;
+};
+// Should not crash
+struct S s[] = {[0].i = 0, [1].i = 1, {}};
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -1585,10 +1585,7 @@
   IList->setInit(Index, ResultExpr);
 }
   }
-  if (hadError)
-++StructuredIndex;
-  else
-UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
+  UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
   ++Index;
 }
 
@@ -1643,10 +1640,7 @@
   if (!VerifyOnly && expr)
 IList->setInit(Index, expr);
 
-  if (hadError)
-++StructuredIndex;
-  else
-UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
+  UpdateStructuredListElement(StructuredList, StructuredIndex, expr);
   ++Index;
 }
 
@@ -1697,11 +1691,7 @@
   IList->setInit(Index, ResultExpr);
 }
   }
-  if (hadError)
-++StructuredIndex;
-  else
-UpdateStructuredListElement(StructuredList, StructuredIndex,
-ResultExpr);
+  UpdateStructuredListElement(StructuredList, StructuredIndex, ResultExpr);
   ++Index;
   return;
 }
@@ -3100,8 +3090,12 @@
 
   if (Expr *PrevInit = StructuredList->updateInit(SemaRef.Context,
   StructuredIndex, expr)) {
-// This initializer overwrites a previous initializer. Warn.
-diagnoseInitOverride(PrevInit, expr->getSourceRange());
+// This initializer overwrites a previous initializer.
+// No need to diagnose when `expr` is nullptr because a more relevant
+// diagnostic has already been issued and this diagnostic is potentially
+// noise.
+if (expr)
+  diagnoseInitOverride(PrevInit, expr->getSourceRange());
   }
 
   ++StructuredIndex;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84248: [analyzer][StdLibraryFunctionsChecker] Add POSIX time handling functions

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



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:2040
+
+if (ConstStructTimevalPtrTy && StructTimespecPtrTy)
+  // int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);

Should be `ConstStructTimespecPtrTy`.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:2092
+  .ArgConstraint(NotNull(ArgNo(0)))
+  .ArgConstraint(NotNull(ArgNo(1;
+

Is it possible to check for the size of the passed buffer? The man page says 
that `buf` should have room for 26 bytes (for `ctime_r` too).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84248

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


[PATCH] D85193: [clang] Check `expr` inside `InitListChecker::UpdateStructuredListElement()`

2020-08-12 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added a comment.

In D85193#2212976 , @aaron.ballman 
wrote:

> I have a suggestion for the added comment,

Fixed comment according to your suggestion.

> but I also forgot to ask, do you need someone to commit on your behalf?

I already have commit access.

Thanks for review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85193

___
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-08-12 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

In D72705#2213300 , @whisperity wrote:

> In D72705#2210255 , @balazske wrote:
>
>> More results in CodeChecker: emacs_errorreturn 
>> 
>
> Something's not quite right, e.g. at 
> https://codechecker-demo.eastus.cloudapp.azure.com/Default/report-detail?run=emacs_errorreturn&review-status=Unreviewed&review-status=Confirmed%20bug&detection-status=New&detection-status=Reopened&detection-status=Unresolved&report-id=7258
>  there's a bug path element `Function '???' called [...]`. This seems to be 
> the case for almost every report... but I found no indication where this 
> "???" could come from, in the patch...

Because that is an improved version of the checker. The current form is not 
testable because it detects too less functions. To have more results functions 
were added that may return NULL on error and a missing comparison to NULL is 
detected (similar as missing comparison to `EOF` in this patch). (To have the 
check for NULL some other improvements were made.) The '???' is part of 
development of note tags, the name of the called function is to be placed there 
(probably there is better way of doing these reports).


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] D85842: Fix `NestedNameSpecifierLoc::getLocalSourceRange()`

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

>From the documentation comment above 
>`NestedNameSpecifierLoc::getLocalSourceRange()`

  /// Retrieve the source range covering just the last part of
  /// this nested-name-specifier, not including the prefix.
  ///
  /// For example, if this instance refers to a nested-name-specifier
  /// \c \::std::vector::, the returned source range would cover
  /// from "vector" to the last '::'.

We would expect that for a nested-name-specifier with a dependent
template specialization type: `T::template ST::`
`NestedNameSpecifierLoc::getLocalSourceRange()` would return `template
ST::` but instead it returns `T::template ST::`.

The issue might as well be on
`DependentTemplateSpecializationTypeLoc::getLocalSourceRange()` which is
indirectly called from `NestedNameSpecifierLoc::getLocalSourceRange()`.
I think not.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85842

Files:
  clang/lib/AST/NestedNameSpecifier.cpp


Index: clang/lib/AST/NestedNameSpecifier.cpp
===
--- clang/lib/AST/NestedNameSpecifier.cpp
+++ clang/lib/AST/NestedNameSpecifier.cpp
@@ -439,6 +439,14 @@
 // Note: the 'template' keyword is part of the TypeLoc.
 void *TypeData = LoadPointer(Data, Offset);
 TypeLoc TL(Qualifier->getAsType(), TypeData);
+// For `T::template ST::x`
+// `NestedNameSpecifierLoc::getLocalSourceRange()` should return `template
+// ST::` but `DependentTemplateSpecializationTypeLoc::getBeginLoc()`
+// returns `^T::temp...`
+if (auto DependentTL = TL.getAs()) 
{
+  return SourceRange(DependentTL.getTemplateKeywordLoc(),
+ LoadSourceLocation(Data, Offset + sizeof(void *)));
+}
 return SourceRange(TL.getBeginLoc(),
LoadSourceLocation(Data, Offset + sizeof(void*)));
   }


Index: clang/lib/AST/NestedNameSpecifier.cpp
===
--- clang/lib/AST/NestedNameSpecifier.cpp
+++ clang/lib/AST/NestedNameSpecifier.cpp
@@ -439,6 +439,14 @@
 // Note: the 'template' keyword is part of the TypeLoc.
 void *TypeData = LoadPointer(Data, Offset);
 TypeLoc TL(Qualifier->getAsType(), TypeData);
+// For `T::template ST::x`
+// `NestedNameSpecifierLoc::getLocalSourceRange()` should return `template
+// ST::` but `DependentTemplateSpecializationTypeLoc::getBeginLoc()`
+// returns `^T::temp...`
+if (auto DependentTL = TL.getAs()) {
+  return SourceRange(DependentTL.getTemplateKeywordLoc(),
+ LoadSourceLocation(Data, Offset + sizeof(void *)));
+}
 return SourceRange(TL.getBeginLoc(),
LoadSourceLocation(Data, Offset + sizeof(void*)));
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85843: Add "status" to the list of absl libraries.

2020-08-12 Thread Vy Nguyen via Phabricator via cfe-commits
oontvoo created this revision.
oontvoo added a reviewer: sbenza.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
oontvoo requested review of this revision.

The Abseil-NoInternalDependenciesCheck currently mistakenly triggers on any 
usage of internal helpers even if it is within absl/status.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85843

Files:
  clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h


Index: clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
===
--- clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
+++ clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
@@ -50,8 +50,8 @@
   static const char *AbseilLibraries[] = {
   "algorithm", "base", "container",   "debugging", "flags",
   "hash",  "iterator", "memory",  "meta",  "numeric",
-  "random","strings",  "synchronization", "time",  "types",
-  "utility"};
+  "random","strings",  "synchronization", "status","time",
+  "types", "utility"};
   return std::any_of(
   std::begin(AbseilLibraries), std::end(AbseilLibraries),
   [&](const char *Library) { return Path.startswith(Library); });


Index: clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
===
--- clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
+++ clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
@@ -50,8 +50,8 @@
   static const char *AbseilLibraries[] = {
   "algorithm", "base", "container",   "debugging", "flags",
   "hash",  "iterator", "memory",  "meta",  "numeric",
-  "random","strings",  "synchronization", "time",  "types",
-  "utility"};
+  "random","strings",  "synchronization", "status","time",
+  "types", "utility"};
   return std::any_of(
   std::begin(AbseilLibraries), std::end(AbseilLibraries),
   [&](const char *Library) { return Path.startswith(Library); });
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85844: [Driver] Change -fnostack-clash-protection to -fno-stack-clash-protection

2020-08-12 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 created this revision.
xbolva00 added a reviewer: sberg.
Herald added subscribers: cfe-commits, dang.
Herald added a project: clang.
xbolva00 requested review of this revision.

Clang command line docs mention `-fno-stack-clash-protection`, and GCC also 
uses  -fno-stack-clash-protection.

Fixes PR47139


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85844

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/stack-clash-protection.c


Index: clang/test/Driver/stack-clash-protection.c
===
--- clang/test/Driver/stack-clash-protection.c
+++ clang/test/Driver/stack-clash-protection.c
@@ -1,6 +1,6 @@
 // RUN: %clang -target i386-unknown-linux -fstack-clash-protection -### %s 
2>&1 | FileCheck %s -check-prefix=SCP-i386
-// RUN: %clang -target i386-unknown-linux -fnostack-clash-protection 
-fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386
-// RUN: %clang -target i386-unknown-linux -fstack-clash-protection 
-fnostack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386-NO
+// RUN: %clang -target i386-unknown-linux -fno-stack-clash-protection 
-fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386
+// RUN: %clang -target i386-unknown-linux -fstack-clash-protection 
-fno-stack-clash-protection -### %s 2>&1 | FileCheck %s 
-check-prefix=SCP-i386-NO
 // SCP-i386: "-fstack-clash-protection"
 // SCP-i386-NO-NOT: "-fstack-clash-protection"
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2978,7 +2978,7 @@
 return;
 
   if (Args.hasFlag(options::OPT_fstack_clash_protection,
-   options::OPT_fnostack_clash_protection, false))
+   options::OPT_fno_stack_clash_protection, false))
 CmdArgs.push_back("-fstack-clash-protection");
 }
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1794,7 +1794,7 @@
   HelpText<"Enable stack protectors for all functions">;
 def fstack_clash_protection : Flag<["-"], "fstack-clash-protection">, 
Group, Flags<[CC1Option]>,
   HelpText<"Enable stack clash protection">;
-def fnostack_clash_protection : Flag<["-"], "fnostack-clash-protection">, 
Group,
+def fno_stack_clash_protection : Flag<["-"], "fno-stack-clash-protection">, 
Group,
   HelpText<"Disable stack clash protection">;
 def fstack_protector_strong : Flag<["-"], "fstack-protector-strong">, 
Group,
   HelpText<"Enable stack protectors for some functions vulnerable to stack 
smashing. "


Index: clang/test/Driver/stack-clash-protection.c
===
--- clang/test/Driver/stack-clash-protection.c
+++ clang/test/Driver/stack-clash-protection.c
@@ -1,6 +1,6 @@
 // RUN: %clang -target i386-unknown-linux -fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386
-// RUN: %clang -target i386-unknown-linux -fnostack-clash-protection -fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386
-// RUN: %clang -target i386-unknown-linux -fstack-clash-protection -fnostack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386-NO
+// RUN: %clang -target i386-unknown-linux -fno-stack-clash-protection -fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386
+// RUN: %clang -target i386-unknown-linux -fstack-clash-protection -fno-stack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386-NO
 // SCP-i386: "-fstack-clash-protection"
 // SCP-i386-NO-NOT: "-fstack-clash-protection"
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2978,7 +2978,7 @@
 return;
 
   if (Args.hasFlag(options::OPT_fstack_clash_protection,
-   options::OPT_fnostack_clash_protection, false))
+   options::OPT_fno_stack_clash_protection, false))
 CmdArgs.push_back("-fstack-clash-protection");
 }
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1794,7 +1794,7 @@
   HelpText<"Enable stack protectors for all functions">;
 def fstack_clash_protection : Flag<["-"], "fstack-clash-protection">, Group, Flags<[CC1Option]>,
   HelpText<"Enable stack clash protection">;
-def fnostack_clash_protection : Flag<["-"], "fnostack-clash-protection">, Group,
+def fno_stack_clash_protection : Flag<["-"], "fno-stack-clash-protection">, Group,
   HelpText<"Disable stack clash protection">

[PATCH] D85817: [analyzer] Fix crash with pointer to members values

2020-08-12 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

That's a fix for https://bugs.llvm.org/show_bug.cgi?id=46264.

Your code looks great but i don't understand at a glance what the crash was 
caused by and how does your code fix it, can you explain? Like, the original 
test doesn't have any `void *`s and it doesn't have any indirect fields. Also 
the crash happens during visitor phase but the fixes are entirely during 
modeling phase.




Comment at: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:2533-2534
   if (isa(D) || isa(D)) {
-// FIXME: Compute lvalue of field pointers-to-member.
-// Right now we just use a non-null void pointer, so that it gives proper
-// results in boolean contexts.
-// FIXME: Maybe delegate this to the surrounding operator&.
-// Note how this expression is lvalue, however pointer-to-member is NonLoc.
-SVal V = svalBuilder.conjureSymbolVal(Ex, LCtx, getContext().VoidPtrTy,
-  currBldrCtx->blockCount());
-state = state->assume(V.castAs(), true);
-Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), nullptr,
-  ProgramPoint::PostLValueKind);
+// Delegate all work related to pointer to members to the surrounding
+// operator&.
 return;

Ok so you're saying that there's *always* going to be a surrounding operator 
`&`? That kind of makes sense but if you add more explanation/proof of how you 
figured this out that'd be great.



Comment at: clang/test/Analysis/PR46264.cpp:5
+
+namespace a {
+class b {

I'm pretty sure the namespace is not actually important for the test. `creduce` 
is great but sometimes it misses stuff. Generally, i'm a big fan of manually 
cleaning up `creduce`d test to make them look more like real code. At least 
turn things like `b h;` and `e *i;` into something like `A a;` and `B *b;`. 
Also replace `class` with `struct` because we never care about this entire 
public/private business and `struct` provides a nice default.



Comment at: clang/test/Analysis/PR46264.cpp:9
+  typedef int b::*c;
+  operator c() { return &b::d; }
+  int d;

It's worth it to comment where exactly is this conversion operator used in the 
text (i.e., within the if-condition). People do in fact sometimes do this kind 
of thing in real life: provide a conversion to pointer-to-member *instead of* 
conversion to `bool` because it causes fewer potential further accidental 
implicit conversions to be possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85817

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


[PATCH] D85844: [Driver] Change -fnostack-clash-protection to -fno-stack-clash-protection

2020-08-12 Thread Tom Stellard via Phabricator via cfe-commits
tstellar accepted this revision.
tstellar added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85844

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


[PATCH] D85826: [clang] Make signature help work with dependent args

2020-08-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 285116.
kadircet added a comment.

- Add tests into clang-lit
- Make sure current number of args is less than overloads param count.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85826

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/call.cpp

Index: clang/test/CodeCompletion/call.cpp
===
--- clang/test/CodeCompletion/call.cpp
+++ clang/test/CodeCompletion/call.cpp
@@ -32,3 +32,17 @@
   // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#int i#>, int j, int k)
   // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#float x#>, float y)
 }
+
+template 
+void foo(T t) {
+  f(t, t, t);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:38:5 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
+  // CHECK-CC4: f()
+  // CHECK-CC4-NEXT: f(<#X#>)
+  // CHECK-CC4-NEXT: f(<#int i#>, int j, int k)
+  // CHECK-CC4-NEXT: f(<#float x#>, float y)
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:38:8 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
+  // CHECK-CC5-NOT: f()
+  // CHECK-CC5: f(int i, <#int j#>, int k)
+  // CHECK-CC5-NEXT: f(float x, <#float y#>)
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5562,22 +5562,43 @@
 
   // FIXME: Provide support for variadic template functions.
   // Ignore type-dependent call expressions entirely.
-  if (!Fn || Fn->isTypeDependent() || anyNullArguments(Args) ||
-  Expr::hasAnyTypeDependentArguments(Args)) {
+  if (!Fn || Fn->isTypeDependent() || anyNullArguments(Args))
 return QualType();
+
+  SmallVector Results;
+
+  Expr *NakedFn = Fn->IgnoreParenCasts();
+  // In presence of dependent args we surface all posible signatures, without
+  // performing any semantic checks on availability. That's to improve user
+  // experience, it is better to see all overloads rather than none.
+  if (Expr::hasAnyTypeDependentArguments(Args)) {
+auto AddIfArgCountChecks = [&Results, &Args](FunctionDecl *FD) {
+  if (FD->getNumParams() < Args.size())
+return;
+  Results.push_back(ResultCandidate(FD));
+};
+if (auto *ULE = dyn_cast(NakedFn)) {
+  for (auto *D : ULE->decls())
+AddIfArgCountChecks(D->getAsFunction());
+} else if (auto *UME = dyn_cast(NakedFn)) {
+  for (auto *D : UME->decls())
+AddIfArgCountChecks(D->getAsFunction());
+} else if (auto *ME = dyn_cast(NakedFn)) {
+  if (auto *FD = ME->getMemberDecl()->getAsFunction())
+AddIfArgCountChecks(FD);
+}
+// FIXME: handle function pointers and lambdas.
+return ProduceSignatureHelp(*this, S, Results, Args.size(), OpenParLoc);
   }
 
   // Build an overload candidate set based on the functions we find.
   SourceLocation Loc = Fn->getExprLoc();
   OverloadCandidateSet CandidateSet(Loc, OverloadCandidateSet::CSK_Normal);
 
-  SmallVector Results;
-
-  Expr *NakedFn = Fn->IgnoreParenCasts();
-  if (auto ULE = dyn_cast(NakedFn))
+  if (auto ULE = dyn_cast(NakedFn)) {
 AddOverloadedCallCandidates(ULE, Args, CandidateSet,
 /*PartialOverloading=*/true);
-  else if (auto UME = dyn_cast(NakedFn)) {
+  } else if (auto UME = dyn_cast(NakedFn)) {
 TemplateArgumentListInfo TemplateArgsBuffer, *TemplateArgs = nullptr;
 if (UME->hasExplicitTemplateArgs()) {
   UME->copyTemplateArgumentsInto(TemplateArgsBuffer);
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1166,46 +1166,75 @@
 }
 
 TEST(SignatureHelpTest, OpeningParen) {
-  llvm::StringLiteral Tests[] = {// Recursive function call.
- R"cpp(
-int foo(int a, int b, int c);
-int main() {
-  foo(foo $p^( foo(10, 10, 10), ^ )));
-})cpp",
- // Functional type cast.
- R"cpp(
-struct Foo {
-  Foo(int a, int b, int c);
-};
-int main() {
-  Foo $p^( 10, ^ );
-})cpp",
- // New expression.
- R"cpp(
-struct Foo {
-  Foo(int a, int b, int c);
-};
-int main() {
-  new Foo $p^( 10, ^ );
-})cpp",
- // Macro expansion.
- R"cpp(
-int foo(int a, int b, int c);
-#define FOO foo(
-
-int main() {
-  // Macro expansions.
-  $p^FOO 10, ^ );
-})cpp",
- // Macro arguments.
- R"cpp(
-int foo(int a, int b, int

[PATCH] D85826: [clang] Make signature help work with dependent args

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

- Fix typo in comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85826

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/call.cpp

Index: clang/test/CodeCompletion/call.cpp
===
--- clang/test/CodeCompletion/call.cpp
+++ clang/test/CodeCompletion/call.cpp
@@ -32,3 +32,17 @@
   // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#int i#>, int j, int k)
   // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#float x#>, float y)
 }
+
+template 
+void foo(T t) {
+  f(t, t, t);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:38:5 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
+  // CHECK-CC4: f()
+  // CHECK-CC4-NEXT: f(<#X#>)
+  // CHECK-CC4-NEXT: f(<#int i#>, int j, int k)
+  // CHECK-CC4-NEXT: f(<#float x#>, float y)
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:38:8 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
+  // CHECK-CC5-NOT: f()
+  // CHECK-CC5: f(int i, <#int j#>, int k)
+  // CHECK-CC5-NEXT: f(float x, <#float y#>)
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5562,22 +5562,43 @@
 
   // FIXME: Provide support for variadic template functions.
   // Ignore type-dependent call expressions entirely.
-  if (!Fn || Fn->isTypeDependent() || anyNullArguments(Args) ||
-  Expr::hasAnyTypeDependentArguments(Args)) {
+  if (!Fn || Fn->isTypeDependent() || anyNullArguments(Args))
 return QualType();
+
+  SmallVector Results;
+
+  Expr *NakedFn = Fn->IgnoreParenCasts();
+  // In presence of dependent args we surface all possible signatures, without
+  // performing any semantic checks on availability. That's to improve user
+  // experience, it is better to see all overloads rather than none.
+  if (Expr::hasAnyTypeDependentArguments(Args)) {
+auto AddIfArgCountChecks = [&Results, &Args](FunctionDecl *FD) {
+  if (FD->getNumParams() < Args.size())
+return;
+  Results.push_back(ResultCandidate(FD));
+};
+if (auto *ULE = dyn_cast(NakedFn)) {
+  for (auto *D : ULE->decls())
+AddIfArgCountChecks(D->getAsFunction());
+} else if (auto *UME = dyn_cast(NakedFn)) {
+  for (auto *D : UME->decls())
+AddIfArgCountChecks(D->getAsFunction());
+} else if (auto *ME = dyn_cast(NakedFn)) {
+  if (auto *FD = ME->getMemberDecl()->getAsFunction())
+AddIfArgCountChecks(FD);
+}
+// FIXME: handle function pointers and lambdas.
+return ProduceSignatureHelp(*this, S, Results, Args.size(), OpenParLoc);
   }
 
   // Build an overload candidate set based on the functions we find.
   SourceLocation Loc = Fn->getExprLoc();
   OverloadCandidateSet CandidateSet(Loc, OverloadCandidateSet::CSK_Normal);
 
-  SmallVector Results;
-
-  Expr *NakedFn = Fn->IgnoreParenCasts();
-  if (auto ULE = dyn_cast(NakedFn))
+  if (auto ULE = dyn_cast(NakedFn)) {
 AddOverloadedCallCandidates(ULE, Args, CandidateSet,
 /*PartialOverloading=*/true);
-  else if (auto UME = dyn_cast(NakedFn)) {
+  } else if (auto UME = dyn_cast(NakedFn)) {
 TemplateArgumentListInfo TemplateArgsBuffer, *TemplateArgs = nullptr;
 if (UME->hasExplicitTemplateArgs()) {
   UME->copyTemplateArgumentsInto(TemplateArgsBuffer);
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1166,46 +1166,75 @@
 }
 
 TEST(SignatureHelpTest, OpeningParen) {
-  llvm::StringLiteral Tests[] = {// Recursive function call.
- R"cpp(
-int foo(int a, int b, int c);
-int main() {
-  foo(foo $p^( foo(10, 10, 10), ^ )));
-})cpp",
- // Functional type cast.
- R"cpp(
-struct Foo {
-  Foo(int a, int b, int c);
-};
-int main() {
-  Foo $p^( 10, ^ );
-})cpp",
- // New expression.
- R"cpp(
-struct Foo {
-  Foo(int a, int b, int c);
-};
-int main() {
-  new Foo $p^( 10, ^ );
-})cpp",
- // Macro expansion.
- R"cpp(
-int foo(int a, int b, int c);
-#define FOO foo(
-
-int main() {
-  // Macro expansions.
-  $p^FOO 10, ^ );
-})cpp",
- // Macro arguments.
- R"cpp(
-int foo(int a, int b, int c);
-int main() {
-#def

[PATCH] D85844: [Driver] Change -fnostack-clash-protection to -fno-stack-clash-protection

2020-08-12 Thread Dávid Bolvanský via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdf3bfaa39071: [Driver] Change -fnostack-clash-protection to  
-fno-stack-clash-protection (authored by xbolva00).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85844

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/stack-clash-protection.c


Index: clang/test/Driver/stack-clash-protection.c
===
--- clang/test/Driver/stack-clash-protection.c
+++ clang/test/Driver/stack-clash-protection.c
@@ -1,6 +1,6 @@
 // RUN: %clang -target i386-unknown-linux -fstack-clash-protection -### %s 
2>&1 | FileCheck %s -check-prefix=SCP-i386
-// RUN: %clang -target i386-unknown-linux -fnostack-clash-protection 
-fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386
-// RUN: %clang -target i386-unknown-linux -fstack-clash-protection 
-fnostack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386-NO
+// RUN: %clang -target i386-unknown-linux -fno-stack-clash-protection 
-fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386
+// RUN: %clang -target i386-unknown-linux -fstack-clash-protection 
-fno-stack-clash-protection -### %s 2>&1 | FileCheck %s 
-check-prefix=SCP-i386-NO
 // SCP-i386: "-fstack-clash-protection"
 // SCP-i386-NO-NOT: "-fstack-clash-protection"
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2978,7 +2978,7 @@
 return;
 
   if (Args.hasFlag(options::OPT_fstack_clash_protection,
-   options::OPT_fnostack_clash_protection, false))
+   options::OPT_fno_stack_clash_protection, false))
 CmdArgs.push_back("-fstack-clash-protection");
 }
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1794,7 +1794,7 @@
   HelpText<"Enable stack protectors for all functions">;
 def fstack_clash_protection : Flag<["-"], "fstack-clash-protection">, 
Group, Flags<[CC1Option]>,
   HelpText<"Enable stack clash protection">;
-def fnostack_clash_protection : Flag<["-"], "fnostack-clash-protection">, 
Group,
+def fno_stack_clash_protection : Flag<["-"], "fno-stack-clash-protection">, 
Group,
   HelpText<"Disable stack clash protection">;
 def fstack_protector_strong : Flag<["-"], "fstack-protector-strong">, 
Group,
   HelpText<"Enable stack protectors for some functions vulnerable to stack 
smashing. "


Index: clang/test/Driver/stack-clash-protection.c
===
--- clang/test/Driver/stack-clash-protection.c
+++ clang/test/Driver/stack-clash-protection.c
@@ -1,6 +1,6 @@
 // RUN: %clang -target i386-unknown-linux -fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386
-// RUN: %clang -target i386-unknown-linux -fnostack-clash-protection -fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386
-// RUN: %clang -target i386-unknown-linux -fstack-clash-protection -fnostack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386-NO
+// RUN: %clang -target i386-unknown-linux -fno-stack-clash-protection -fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386
+// RUN: %clang -target i386-unknown-linux -fstack-clash-protection -fno-stack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386-NO
 // SCP-i386: "-fstack-clash-protection"
 // SCP-i386-NO-NOT: "-fstack-clash-protection"
 
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2978,7 +2978,7 @@
 return;
 
   if (Args.hasFlag(options::OPT_fstack_clash_protection,
-   options::OPT_fnostack_clash_protection, false))
+   options::OPT_fno_stack_clash_protection, false))
 CmdArgs.push_back("-fstack-clash-protection");
 }
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1794,7 +1794,7 @@
   HelpText<"Enable stack protectors for all functions">;
 def fstack_clash_protection : Flag<["-"], "fstack-clash-protection">, Group, Flags<[CC1Option]>,
   HelpText<"Enable stack clash protection">;
-def fnostack_clash_protection : Flag<["-"], "fnostack-clash-protection">, Group,
+def fno_stack_clash_protection : Flag<["-"], "fno-stack-clash-protection">, Group,
   HelpText<"Disable stack clas

[clang] df3bfaa - [Driver] Change -fnostack-clash-protection to -fno-stack-clash-protection

2020-08-12 Thread Dávid Bolvanský via cfe-commits

Author: Dávid Bolvanský
Date: 2020-08-12T18:36:26+02:00
New Revision: df3bfaa39071a1382a59a94658ee1a2da30d92fd

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

LOG: [Driver] Change -fnostack-clash-protection to  -fno-stack-clash-protection

Clang command line docs mention `-fno-stack-clash-protection`, and GCC also 
uses  -fno-stack-clash-protection.

Fixes PR47139

Reviewed By: tstellar

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/stack-clash-protection.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e09b6468eea7..99a2ec7ad2d4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1794,7 +1794,7 @@ def fstack_protector_all : Flag<["-"], 
"fstack-protector-all">, Group,
   HelpText<"Enable stack protectors for all functions">;
 def fstack_clash_protection : Flag<["-"], "fstack-clash-protection">, 
Group, Flags<[CC1Option]>,
   HelpText<"Enable stack clash protection">;
-def fnostack_clash_protection : Flag<["-"], "fnostack-clash-protection">, 
Group,
+def fno_stack_clash_protection : Flag<["-"], "fno-stack-clash-protection">, 
Group,
   HelpText<"Disable stack clash protection">;
 def fstack_protector_strong : Flag<["-"], "fstack-protector-strong">, 
Group,
   HelpText<"Enable stack protectors for some functions vulnerable to stack 
smashing. "

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 50fe1fcd1615..82cf2538338f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2978,7 +2978,7 @@ static void RenderSCPOptions(const ToolChain &TC, const 
ArgList &Args,
 return;
 
   if (Args.hasFlag(options::OPT_fstack_clash_protection,
-   options::OPT_fnostack_clash_protection, false))
+   options::OPT_fno_stack_clash_protection, false))
 CmdArgs.push_back("-fstack-clash-protection");
 }
 

diff  --git a/clang/test/Driver/stack-clash-protection.c 
b/clang/test/Driver/stack-clash-protection.c
index a2cf3f82a8fd..5217ed26a5b1 100644
--- a/clang/test/Driver/stack-clash-protection.c
+++ b/clang/test/Driver/stack-clash-protection.c
@@ -1,6 +1,6 @@
 // RUN: %clang -target i386-unknown-linux -fstack-clash-protection -### %s 
2>&1 | FileCheck %s -check-prefix=SCP-i386
-// RUN: %clang -target i386-unknown-linux -fnostack-clash-protection 
-fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386
-// RUN: %clang -target i386-unknown-linux -fstack-clash-protection 
-fnostack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386-NO
+// RUN: %clang -target i386-unknown-linux -fno-stack-clash-protection 
-fstack-clash-protection -### %s 2>&1 | FileCheck %s -check-prefix=SCP-i386
+// RUN: %clang -target i386-unknown-linux -fstack-clash-protection 
-fno-stack-clash-protection -### %s 2>&1 | FileCheck %s 
-check-prefix=SCP-i386-NO
 // SCP-i386: "-fstack-clash-protection"
 // SCP-i386-NO-NOT: "-fstack-clash-protection"
 



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


[PATCH] D85842: Fix `NestedNameSpecifierLoc::getLocalSourceRange()`

2020-08-12 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 285122.
eduucaldas added a comment.

Don't assume the code is completely correct


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85842

Files:
  clang/lib/AST/NestedNameSpecifier.cpp


Index: clang/lib/AST/NestedNameSpecifier.cpp
===
--- clang/lib/AST/NestedNameSpecifier.cpp
+++ clang/lib/AST/NestedNameSpecifier.cpp
@@ -439,6 +439,17 @@
 // Note: the 'template' keyword is part of the TypeLoc.
 void *TypeData = LoadPointer(Data, Offset);
 TypeLoc TL(Qualifier->getAsType(), TypeData);
+// For `T::template ST::x`
+// `NestedNameSpecifierLoc::getLocalSourceRange()` should return `template
+// ST::` but `DependentTemplateSpecializationTypeLoc::getBeginLoc()`
+// returns `^T::temp...`
+if (auto DependentTL = TL.getAs()) 
{
+  if (getTemplateKeywordLoc().isValid())
+return SourceRange(getTemplateKeywordLoc(),
+   LoadSourceLocation(Data, Offset + sizeof(void *)));
+  return SourceRange(getTemplateNameLoc(),
+ LoadSourceLocation(Data, Offset + sizeof(void *)));
+}
 return SourceRange(TL.getBeginLoc(),
LoadSourceLocation(Data, Offset + sizeof(void*)));
   }


Index: clang/lib/AST/NestedNameSpecifier.cpp
===
--- clang/lib/AST/NestedNameSpecifier.cpp
+++ clang/lib/AST/NestedNameSpecifier.cpp
@@ -439,6 +439,17 @@
 // Note: the 'template' keyword is part of the TypeLoc.
 void *TypeData = LoadPointer(Data, Offset);
 TypeLoc TL(Qualifier->getAsType(), TypeData);
+// For `T::template ST::x`
+// `NestedNameSpecifierLoc::getLocalSourceRange()` should return `template
+// ST::` but `DependentTemplateSpecializationTypeLoc::getBeginLoc()`
+// returns `^T::temp...`
+if (auto DependentTL = TL.getAs()) {
+  if (getTemplateKeywordLoc().isValid())
+return SourceRange(getTemplateKeywordLoc(),
+   LoadSourceLocation(Data, Offset + sizeof(void *)));
+  return SourceRange(getTemplateNameLoc(),
+ LoadSourceLocation(Data, Offset + sizeof(void *)));
+}
 return SourceRange(TL.getBeginLoc(),
LoadSourceLocation(Data, Offset + sizeof(void*)));
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85099: [UpdateTestChecks] Match unnamed values like "@[0-9]+" and "![0-9]+"

2020-08-12 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: llvm/utils/UpdateTestChecks/common.py:390
+for nameless_value in nameless_values:
+if re.fullmatch(nameless_value.ir_prefix + r'[0-9]+?', var, 
re.IGNORECASE):
+warn("Change IR value name '%s' to prevent possible conflict with 
scripted FileCheck name." % (var,))

This is Py3.4+. Per https://llvm.org/docs/GettingStarted.html#id7 we still 
support 2.7, which is why all my bots run that, which is why this breaks my 
bots :) (...and everyone still using Python 2.7 locally). Can you do this some 
other way? Maybe just surround the re with "^..$'?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85099

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


[PATCH] D66324: clang-misexpect: Profile Guided Validation of Performance Annotations in LLVM

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



Comment at: cfe/trunk/lib/Frontend/CompilerInvocation.cpp:3457
+  if (Diags.isIgnored(diag::warn_profile_data_misexpect, SourceLocation()))
+Res.FrontendOpts.LLVMArgs.push_back("-pgo-warn-misexpect");
+

rnk wrote:
> Clang generally tries to avoid relying on LLVM option parsing if at all 
> possible. It is not thread-safe, among other things. This causes essentially 
> every compile to call `llvm::cl::ParseCommandLineOptions`, when previously it 
> would only happen if the user passed unstable -mllvm flags.
And it is buggy, if you add "!" as a fix, there are many test failures...
http://45.33.8.238/linux/18098/step_7.txt


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66324

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


[PATCH] D85842: Fix `NestedNameSpecifierLoc::getLocalSourceRange()`

2020-08-12 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 285129.
eduucaldas added a comment.

Update comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85842

Files:
  clang/lib/AST/NestedNameSpecifier.cpp


Index: clang/lib/AST/NestedNameSpecifier.cpp
===
--- clang/lib/AST/NestedNameSpecifier.cpp
+++ clang/lib/AST/NestedNameSpecifier.cpp
@@ -439,6 +439,20 @@
 // Note: the 'template' keyword is part of the TypeLoc.
 void *TypeData = LoadPointer(Data, Offset);
 TypeLoc TL(Qualifier->getAsType(), TypeData);
+// For `T::template ST::x`
+// `NestedNameSpecifierLoc::getLocalSourceRange()` should return `template
+// ST::`.
+// For any TypeLoc we can just use `TypeLoc::getBeginLoc()` to
+// get the beginning of this LocalSourceRange but for dependent template
+// specializations `getBeginLoc` returns the location of `T` yielding
+// `T::template ST::`.
+if (auto DependentTL = TL.getAs()) 
{
+  if (getTemplateKeywordLoc().isValid())
+return SourceRange(getTemplateKeywordLoc(),
+   LoadSourceLocation(Data, Offset + sizeof(void *)));
+  return SourceRange(getTemplateNameLoc(),
+ LoadSourceLocation(Data, Offset + sizeof(void *)));
+}
 return SourceRange(TL.getBeginLoc(),
LoadSourceLocation(Data, Offset + sizeof(void*)));
   }


Index: clang/lib/AST/NestedNameSpecifier.cpp
===
--- clang/lib/AST/NestedNameSpecifier.cpp
+++ clang/lib/AST/NestedNameSpecifier.cpp
@@ -439,6 +439,20 @@
 // Note: the 'template' keyword is part of the TypeLoc.
 void *TypeData = LoadPointer(Data, Offset);
 TypeLoc TL(Qualifier->getAsType(), TypeData);
+// For `T::template ST::x`
+// `NestedNameSpecifierLoc::getLocalSourceRange()` should return `template
+// ST::`.
+// For any TypeLoc we can just use `TypeLoc::getBeginLoc()` to
+// get the beginning of this LocalSourceRange but for dependent template
+// specializations `getBeginLoc` returns the location of `T` yielding
+// `T::template ST::`.
+if (auto DependentTL = TL.getAs()) {
+  if (getTemplateKeywordLoc().isValid())
+return SourceRange(getTemplateKeywordLoc(),
+   LoadSourceLocation(Data, Offset + sizeof(void *)));
+  return SourceRange(getTemplateNameLoc(),
+ LoadSourceLocation(Data, Offset + sizeof(void *)));
+}
 return SourceRange(TL.getBeginLoc(),
LoadSourceLocation(Data, Offset + sizeof(void*)));
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85826: [clang] Make signature help work with dependent args

2020-08-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:5573
+  // performing any semantic checks on availability. That's to improve user
+  // experience, it is better to see all overloads rather than none.
+  if (Expr::hasAnyTypeDependentArguments(Args)) {

hokein wrote:
> I'm a bit nervous to show all overloads regardlessly, I think we could do 
> some smarter things like
> 
> 1. if there are some prefix non-type-dependent arguments, we could use these 
> type information to filter out some unrelated candidates;
> 2. different overloads may have different number of parameters, this is an 
> important signal, e.g. `foo(t, ^t)` should not give `void foo(int)` result;
> 
> 2 seems quite critical and trivial to implement, maybe we can do it in this 
> patch.
> if there are some prefix non-type-dependent arguments, we could use these 
> type information to filter out some unrelated candidates;

well actually now that I think about it, this is actually not that hard. 
possibly even easier than current version. changing the logic surface every 
candidate using the prefix, and do a post-filtering instead of trying to mock 
all the results.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85826

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


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

2020-08-12 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki added a comment.

For intrinsics that are plain functions (not macros) you could just check the 
signatures using assignments to function pointers, e.g.:

  #include 
  uint16_t (*fp1)(int32_t) = &vqmovuns_s32;



  $ clang -target=aarch64-arm-none-eabi -march=armv8-a+simd -c neon.c 
-fsyntax-only -Werror=incompatible-function-pointer-types
  neon.c:2:12: error: incompatible function pointer types initializing 
'uint16_t (*)(int32_t)' (aka 'unsigned short (*)(int)') with an expression of 
type 'int16_t (*)(int32_t)' (aka 'short (*)(int)') 
[-Werror,-Wincompatible-function-pointer-types]
  uint16_t (*fp1)(int32_t) = &vqmovuns_s32;
 ^   ~
  1 error generated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85118

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


[PATCH] D85736: [Sema][AArch64] Support arm_sve_vector_bits attribute

2020-08-12 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes updated this revision to Diff 285124.
c-rhodes added a comment.

Added missing implicit conversions for C++. I considered handling this with the
existing implicit vector conversion although one side of the conversion will be
an SVE builtin, so instead I've added a new conversion specifically for SVE. I
suspect the existing one could support this but I wasn't sure if that was a good
idea (?). In C++ implicit conversions between VLA/VLS have a rank just below
derived-to-base conversion.


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

https://reviews.llvm.org/D85736

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Overload.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Sema/attr-arm-sve-vector-bits.c
  clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp

Index: clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -fsyntax-only -verify -std=c++11 -msve-vector-bits=512 -fallow-half-arguments-and-returns %s
+// expected-no-diagnostics
+
+#define N __ARM_FEATURE_SVE_BITS_EXPERIMENTAL
+
+typedef __SVInt8_t svint8_t;
+typedef svint8_t fixed_int8_t __attribute__((arm_sve_vector_bits(N)));
+
+template struct S { T var; };
+
+S s;
+
+svint8_t to_svint8_t(fixed_int8_t x) { return x; }
+fixed_int8_t from_svint8_t(svint8_t x) { return x; }
Index: clang/test/Sema/attr-arm-sve-vector-bits.c
===
--- clang/test/Sema/attr-arm-sve-vector-bits.c
+++ clang/test/Sema/attr-arm-sve-vector-bits.c
@@ -102,8 +102,11 @@
   svint8_t ss8;
 
   void *sel __attribute__((unused));
-  sel = c ? ss8 : fs8; // expected-error {{incompatible operand types ('svint8_t' (aka '__SVInt8_t') and 'fixed_int8_t' (aka '__SVInt8_t'))}}
-  sel = c ? fs8 : ss8; // expected-error {{incompatible operand types ('fixed_int8_t' (aka '__SVInt8_t') and 'svint8_t' (aka '__SVInt8_t'))}}
+  sel = c ? ss8 : fs8; // expected-error {{cannot convert between fixed-length and sizeless vector}}
+  sel = c ? fs8 : ss8; // expected-error {{cannot convert between fixed-length and sizeless vector}}
+
+  sel = fs8 + ss8; // expected-error {{cannot convert between fixed-length and sizeless vector}}
+  sel = ss8 + fs8; // expected-error {{cannot convert between fixed-length and sizeless vector}}
 }
 
 // --//
@@ -192,14 +195,18 @@
 TEST_CAST(bool)
 
 // Test the implicit conversion only applies to valid types
-fixed_int8_t to_fixed_int8_t__from_svuint8_t(svuint8_t x) { return x; } // expected-error {{returning 'svuint8_t' (aka '__SVUint8_t') from a function with incompatible result type 'fixed_int8_t' (aka '__SVInt8_t')}}
-fixed_bool_t to_fixed_bool_t__from_svint32_t(svint32_t x) { return x; } // expected-error {{returning 'svint32_t' (aka '__SVInt32_t') from a function with incompatible result type 'fixed_bool_t' (aka '__SVBool_t')}}
+fixed_int8_t to_fixed_int8_t__from_svuint8_t(svuint8_t x) { return x; } // expected-error-re {{returning 'svuint8_t' (aka '__SVUint8_t') from a function with incompatible result type 'fixed_int8_t' (vector of {{[0-9]+}} 'signed char' values)}}
+fixed_bool_t to_fixed_bool_t__from_svint32_t(svint32_t x) { return x; } // expected-error-re {{returning 'svint32_t' (aka '__SVInt32_t') from a function with incompatible result type 'fixed_bool_t' (vector of {{[0-9]+}} 'unsigned char' values)}}
+
+// Test conversion between predicate and uint8 is invalid, both have the same
+// memory representation.
+fixed_bool_t to_fixed_bool_t__from_svuint8_t(svuint8_t x) { return x; } // expected-error-re {{returning 'svuint8_t' (aka '__SVUint8_t') from a function with incompatible result type 'fixed_bool_t' (vector of {{[0-9]+}} 'unsigned char' values)}}
 
 // Test the implicit conversion only applies to fixed-length types
 typedef signed int vSInt32 __attribute__((__vector_size__(16)));
-svint32_t to_svint32_t_from_gnut(vSInt32 x) { return x; } // expected-error {{returning 'vSInt32' (vector of 4 'int' values) from a function with incompatible result type 'svint32_t' (aka '__SVInt32_t')}}
+svint32_t to_svint32_t_from_gnut(vSInt32 x) { return x; } // expected-error-re {{returning 'vSInt32' (vector of {{[0-9]+}} 'int' values) from a function with incompatible result type 'svint32_t' (aka '__SVInt32_t')}}
 
-vSInt32 to_gnut_f

[PATCH] D85842: Fix `NestedNameSpecifierLoc::getLocalSourceRange()`

2020-08-12 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added a comment.

Unit tests will be provided once we decide that this is the way to go ;)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85842

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


  1   2   >