[PATCH] D38479: Make -mgeneral-regs-only more like GCC's

2019-05-19 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv added a comment.

I'm happy to give rebasing it a shot later this week. My recollection of the 
prior state of this patch was that we wanted some backend work done to 
double-check that no illegal ops get generated by optimizations and such, since 
these checks are purely done in the frontend. I don't foresee myself having 
time in the near future to make that happen, so is that something that we want 
to continue to block this patch on? If so, then someone else is probably going 
to need to do that piece. Otherwise, I think people were happy enough with this 
patch as-is?


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

https://reviews.llvm.org/D38479



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


[PATCH] D62116: [Sema] raise nullptr check to cover additional uses

2019-05-19 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

A similar case exists and was flagged in https://www.viva64.com/en/b/0629/ 
under "Snippet No. 16" (see under #13), 
`clang/lib/Sema/SemaTemplateInstantiate.cpp` `Sema::InstantiateClass()`.  I'll 
wait for feedback on this patch, then either roll up the additional fix into 
this or create it as a separate patch (or change both, abandon, etc).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62116



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


[PATCH] D62116: [Sema] raise nullptr check to cover additional uses

2019-05-19 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

Note that this changes when the destructor for `CXXThisScopeRAII` runs.  It's 
not clear to me why `ThisScope` is constructed at all.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62116



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


[PATCH] D62116: [Sema] raise nullptr check to cover additional uses

2019-05-19 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
nickdesaulniers added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This was flagged in https://www.viva64.com/en/b/0629/ under "Snippet No.
14" (see under #13). It looks like PVS studio flags nullptr checks where
the ptr is used inbetween creation and checking against nullptr.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62116

Files:
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp


Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -551,11 +551,12 @@
   LateAttrs->push_back(LateInstantiatedAttribute(TmplAttr, Saved, New));
 } else {
   // Allow 'this' within late-parsed attributes.
-  NamedDecl *ND = dyn_cast(New);
-  CXXRecordDecl *ThisContext =
-  dyn_cast_or_null(ND->getDeclContext());
-  CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(),
- ND && ND->isCXXInstanceMember());
+  if (NamedDecl *ND = dyn_cast(New)) {
+CXXRecordDecl *ThisContext =
+dyn_cast_or_null(ND->getDeclContext());
+CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(),
+   ND->isCXXInstanceMember());
+  }
 
   Attr *NewAttr = sema::instantiateTemplateAttribute(TmplAttr, Context,
  *this, TemplateArgs);


Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -551,11 +551,12 @@
   LateAttrs->push_back(LateInstantiatedAttribute(TmplAttr, Saved, New));
 } else {
   // Allow 'this' within late-parsed attributes.
-  NamedDecl *ND = dyn_cast(New);
-  CXXRecordDecl *ThisContext =
-  dyn_cast_or_null(ND->getDeclContext());
-  CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(),
- ND && ND->isCXXInstanceMember());
+  if (NamedDecl *ND = dyn_cast(New)) {
+CXXRecordDecl *ThisContext =
+dyn_cast_or_null(ND->getDeclContext());
+CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(),
+   ND->isCXXInstanceMember());
+  }
 
   Attr *NewAttr = sema::instantiateTemplateAttribute(TmplAttr, Context,
  *this, TemplateArgs);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62115: fix a issue that clang is incompatible with gcc with -H option.

2019-05-19 Thread Kan Shengchen via Phabricator via cfe-commits
skan created this revision.
skan added reviewers: xiangzhangllvm, LuoYuanke, craig.topper.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

clang behaves differently with gcc when compiling
a file with -H option, gcc will omit the "./", but
clang will not. I fix it to make clang more
compatible with gcc.


Repository:
  rC Clang

https://reviews.llvm.org/D62115

Files:
  lib/Frontend/HeaderIncludeGen.cpp
  test/Driver/clang_H_opt.c
  test/Driver/clang_H_opt.h


Index: test/Driver/clang_H_opt.h
===
--- /dev/null
+++ test/Driver/clang_H_opt.h
@@ -0,0 +1,2 @@
+// This header file is included by clang_H_opt.c It can not be deleted,
+// otherwise Clang will complain when compiling the clang_H_opt.c.
Index: test/Driver/clang_H_opt.c
===
--- /dev/null
+++ test/Driver/clang_H_opt.c
@@ -0,0 +1,6 @@
+// RUN: %clang -H -fsyntax-only %s 2>&1 | FileCheck %s
+
+#include"clang_H_opt.h"
+// CHECK: .
+// CHECK-NOT: ./
+// CHECK-SAME: clang_H_opt.h
Index: lib/Frontend/HeaderIncludeGen.cpp
===
--- lib/Frontend/HeaderIncludeGen.cpp
+++ lib/Frontend/HeaderIncludeGen.cpp
@@ -51,6 +51,10 @@
 static void PrintHeaderInfo(raw_ostream *OutputFile, StringRef Filename,
 bool ShowDepth, unsigned CurrentIncludeDepth,
 bool MSStyle) {
+  // Simplify Filename that starts with "./"
+  if (Filename.startswith("./"));
+Filename=Filename.substr(2);
+
   // Write to a temporary string to avoid unnecessary flushing on errs().
   SmallString<512> Pathname(Filename);
   if (!MSStyle)


Index: test/Driver/clang_H_opt.h
===
--- /dev/null
+++ test/Driver/clang_H_opt.h
@@ -0,0 +1,2 @@
+// This header file is included by clang_H_opt.c It can not be deleted,
+// otherwise Clang will complain when compiling the clang_H_opt.c.
Index: test/Driver/clang_H_opt.c
===
--- /dev/null
+++ test/Driver/clang_H_opt.c
@@ -0,0 +1,6 @@
+// RUN: %clang -H -fsyntax-only %s 2>&1 | FileCheck %s
+
+#include"clang_H_opt.h"
+// CHECK: .
+// CHECK-NOT: ./
+// CHECK-SAME: clang_H_opt.h
Index: lib/Frontend/HeaderIncludeGen.cpp
===
--- lib/Frontend/HeaderIncludeGen.cpp
+++ lib/Frontend/HeaderIncludeGen.cpp
@@ -51,6 +51,10 @@
 static void PrintHeaderInfo(raw_ostream *OutputFile, StringRef Filename,
 bool ShowDepth, unsigned CurrentIncludeDepth,
 bool MSStyle) {
+  // Simplify Filename that starts with "./"
+  if (Filename.startswith("./"));
+Filename=Filename.substr(2);
+
   // Write to a temporary string to avoid unnecessary flushing on errs().
   SmallString<512> Pathname(Filename);
   if (!MSStyle)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62066: [ASTImporter] Enable disabled but passing tests

2019-05-19 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin accepted this revision.
a_sidorin added a comment.
This revision is now accepted and ready to land.

Cool!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62066



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


[PATCH] D62064: [ASTImporter] Fix unhandled cases in ASTImporterLookupTable

2019-05-19 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin added a comment.

Hi Gabor,
This looks fine, but I have a question inline.




Comment at: clang/unittests/AST/ASTImporterTest.cpp:4259
 static const RecordDecl * getRecordDeclOfFriend(FriendDecl *FD) {
   QualType Ty = FD->getFriendType()->getType();
+  if (auto *Inner = dyn_cast(Ty.getTypePtr())) {

Will getCanonicalType() do the job?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62064



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


[PATCH] D61814: [CFG] NFC: Remove implicit conversion from CFGTerminator to Stmt *, make it a variant class instead.

2019-05-19 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin added inline comments.



Comment at: clang/lib/Analysis/ReachableCode.cpp:465
+  CFGTerminator T = Block->getTerminator();
+  if (T.getKind() == CFGTerminator::StmtBranch) {
+const Stmt *S = T.getStmt();

isStmtBranch()?


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

https://reviews.llvm.org/D61814



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


r361120 - Fix buildbot: Use correct Consume*() for braces.

2019-05-19 Thread Nicolas Lesser via cfe-commits
Author: rakete
Date: Sun May 19 08:30:00 2019
New Revision: 361120

URL: http://llvm.org/viewvc/llvm-project?rev=361120=rev
Log:
Fix buildbot: Use correct Consume*() for braces.

Modified:
cfe/trunk/lib/Parse/ParseExprCXX.cpp

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=361120=361119=361120=diff
==
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Sun May 19 08:30:00 2019
@@ -3052,7 +3052,8 @@ Parser::ParseCXXDeleteExpression(bool Us
   SkipUntil({tok::l_brace, tok::less}, StopBeforeMatch);
   SourceLocation RBraceLoc;
   bool EmitFixIt = false;
-  if (TryConsumeToken(tok::l_brace)) {
+  if (Tok.is(tok::l_brace)) {
+ConsumeBrace();
 SkipUntil(tok::r_brace, StopBeforeMatch);
 RBraceLoc = Tok.getLocation();
 EmitFixIt = true;


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


[PATCH] D36357: Added a better diagnostic when using the delete operator with lambdas

2019-05-19 Thread Nicolas Lesser via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL361119: Added a better diagnostic when using the delete 
operator with lambdas (authored by Rakete, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D36357?vs=199566=200180#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D36357

Files:
  cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
  cfe/trunk/lib/Parse/ParseExprCXX.cpp
  cfe/trunk/test/FixIt/fixit-cxx0x.cpp
  cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp
  cfe/trunk/test/SemaCXX/new-delete-0x.cpp

Index: cfe/trunk/lib/Parse/ParseExprCXX.cpp
===
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp
@@ -3034,8 +3034,58 @@
 //   [Footnote: A lambda expression with a lambda-introducer that consists
 //  of empty square brackets can follow the delete keyword if
 //  the lambda expression is enclosed in parentheses.]
-// FIXME: Produce a better diagnostic if the '[]' is unambiguously a
-//lambda-introducer.
+
+const Token Next = GetLookAheadToken(2);
+
+// Basic lookahead to check if we have a lambda expression.
+if (Next.isOneOf(tok::l_brace, tok::less) ||
+(Next.is(tok::l_paren) &&
+ (GetLookAheadToken(3).is(tok::r_paren) ||
+  (GetLookAheadToken(3).is(tok::identifier) &&
+   GetLookAheadToken(4).is(tok::identifier) {
+  TentativeParsingAction TPA(*this);
+  SourceLocation LSquareLoc = Tok.getLocation();
+  SourceLocation RSquareLoc = NextToken().getLocation();
+
+  // SkipUntil can't skip pairs of ; don't emit a FixIt in this
+  // case.
+  SkipUntil({tok::l_brace, tok::less}, StopBeforeMatch);
+  SourceLocation RBraceLoc;
+  bool EmitFixIt = false;
+  if (TryConsumeToken(tok::l_brace)) {
+SkipUntil(tok::r_brace, StopBeforeMatch);
+RBraceLoc = Tok.getLocation();
+EmitFixIt = true;
+  }
+
+  TPA.Revert();
+
+  if (EmitFixIt)
+Diag(Start, diag::err_lambda_after_delete)
+<< SourceRange(Start, RSquareLoc)
+<< FixItHint::CreateInsertion(LSquareLoc, "(")
+<< FixItHint::CreateInsertion(
+   Lexer::getLocForEndOfToken(
+   RBraceLoc, 0, Actions.getSourceManager(), getLangOpts()),
+   ")");
+  else
+Diag(Start, diag::err_lambda_after_delete)
+<< SourceRange(Start, RSquareLoc);
+
+  // Warn that the non-capturing lambda isn't surrounded by parentheses
+  // to disambiguate it from 'delete[]'.
+  ExprResult Lambda = ParseLambdaExpression();
+  if (Lambda.isInvalid())
+return ExprError();
+
+  // Evaluate any postfix expressions used on the lambda.
+  Lambda = ParsePostfixExpressionSuffix(Lambda);
+  if (Lambda.isInvalid())
+return ExprError();
+  return Actions.ActOnCXXDelete(Start, UseGlobal, /*ArrayForm=*/false,
+Lambda.get());
+}
+
 ArrayDelete = true;
 BalancedDelimiterTracker T(*this, tok::l_square);
 
Index: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
@@ -109,6 +109,8 @@
   InGroup, DefaultIgnore;
 def ext_alignof_expr : ExtWarn<
   "%0 applied to an expression is a GNU extension">, InGroup;
+def err_lambda_after_delete : Error<
+  "'[]' after delete interpreted as 'delete[]'; add parentheses to treat this as a lambda-expression">;
 
 def warn_microsoft_dependent_exists : Warning<
   "dependent %select{__if_not_exists|__if_exists}0 declarations are ignored">,
Index: cfe/trunk/test/SemaCXX/new-delete-0x.cpp
===
--- cfe/trunk/test/SemaCXX/new-delete-0x.cpp
+++ cfe/trunk/test/SemaCXX/new-delete-0x.cpp
@@ -34,6 +34,5 @@
 void bad_deletes()
 {
   // 'delete []' is always array delete, per [expr.delete]p1.
-  // FIXME: Give a better diagnostic.
-  delete []{ return (int*)0; }(); // expected-error {{expected expression}}
+  delete []{ return (int*)0; }(); // expected-error {{'[]' after delete interpreted as 'delete[]'}}
 }
Index: cfe/trunk/test/FixIt/fixit-cxx0x.cpp
===
--- cfe/trunk/test/FixIt/fixit-cxx0x.cpp
+++ cfe/trunk/test/FixIt/fixit-cxx0x.cpp
@@ -58,6 +58,9 @@
   (void)[&, i, i]{ }; // expected-error{{'i' can appear only once in a capture list}}
   (void)[] mutable { }; // expected-error{{lambda requires '()' before 'mutable'}}
   (void)[] -> int { }; // expected-error{{lambda requires '()' before return 

r361119 - Added a better diagnostic when using the delete operator with lambdas

2019-05-19 Thread Nicolas Lesser via cfe-commits
Author: rakete
Date: Sun May 19 08:07:58 2019
New Revision: 361119

URL: http://llvm.org/viewvc/llvm-project?rev=361119=rev
Log:
Added a better diagnostic when using the delete operator with lambdas

Summary:
This adds a new error for missing parentheses around lambdas in delete 
operators.

```
int main() {
  delete []() { return new int(); }();
}
```

This will result in:

```
test.cpp:2:3: error: '[]' after delete interpreted as 'delete[]'
  delete []() { return new int(); }();
  ^
test.cpp:2:9: note: add parentheses around the lambda
  delete []() { return new int(); }();
^
(  )
```

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: riccibruno, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/test/FixIt/fixit-cxx0x.cpp
cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp
cfe/trunk/test/SemaCXX/new-delete-0x.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=361119=361118=361119=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Sun May 19 08:07:58 
2019
@@ -109,6 +109,8 @@ def warn_cxx98_compat_alignof : Warning<
   InGroup, DefaultIgnore;
 def ext_alignof_expr : ExtWarn<
   "%0 applied to an expression is a GNU extension">, 
InGroup;
+def err_lambda_after_delete : Error<
+  "'[]' after delete interpreted as 'delete[]'; add parentheses to treat this 
as a lambda-expression">;
 
 def warn_microsoft_dependent_exists : Warning<
   "dependent %select{__if_not_exists|__if_exists}0 declarations are ignored">,

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=361119=361118=361119=diff
==
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Sun May 19 08:07:58 2019
@@ -3034,8 +3034,58 @@ Parser::ParseCXXDeleteExpression(bool Us
 //   [Footnote: A lambda expression with a lambda-introducer that consists
 //  of empty square brackets can follow the delete keyword if
 //  the lambda expression is enclosed in parentheses.]
-// FIXME: Produce a better diagnostic if the '[]' is unambiguously a
-//lambda-introducer.
+
+const Token Next = GetLookAheadToken(2);
+
+// Basic lookahead to check if we have a lambda expression.
+if (Next.isOneOf(tok::l_brace, tok::less) ||
+(Next.is(tok::l_paren) &&
+ (GetLookAheadToken(3).is(tok::r_paren) ||
+  (GetLookAheadToken(3).is(tok::identifier) &&
+   GetLookAheadToken(4).is(tok::identifier) {
+  TentativeParsingAction TPA(*this);
+  SourceLocation LSquareLoc = Tok.getLocation();
+  SourceLocation RSquareLoc = NextToken().getLocation();
+
+  // SkipUntil can't skip pairs of ; don't emit a FixIt in this
+  // case.
+  SkipUntil({tok::l_brace, tok::less}, StopBeforeMatch);
+  SourceLocation RBraceLoc;
+  bool EmitFixIt = false;
+  if (TryConsumeToken(tok::l_brace)) {
+SkipUntil(tok::r_brace, StopBeforeMatch);
+RBraceLoc = Tok.getLocation();
+EmitFixIt = true;
+  }
+
+  TPA.Revert();
+
+  if (EmitFixIt)
+Diag(Start, diag::err_lambda_after_delete)
+<< SourceRange(Start, RSquareLoc)
+<< FixItHint::CreateInsertion(LSquareLoc, "(")
+<< FixItHint::CreateInsertion(
+   Lexer::getLocForEndOfToken(
+   RBraceLoc, 0, Actions.getSourceManager(), 
getLangOpts()),
+   ")");
+  else
+Diag(Start, diag::err_lambda_after_delete)
+<< SourceRange(Start, RSquareLoc);
+
+  // Warn that the non-capturing lambda isn't surrounded by parentheses
+  // to disambiguate it from 'delete[]'.
+  ExprResult Lambda = ParseLambdaExpression();
+  if (Lambda.isInvalid())
+return ExprError();
+
+  // Evaluate any postfix expressions used on the lambda.
+  Lambda = ParsePostfixExpressionSuffix(Lambda);
+  if (Lambda.isInvalid())
+return ExprError();
+  return Actions.ActOnCXXDelete(Start, UseGlobal, /*ArrayForm=*/false,
+Lambda.get());
+}
+
 ArrayDelete = true;
 BalancedDelimiterTracker T(*this, tok::l_square);
 

Modified: cfe/trunk/test/FixIt/fixit-cxx0x.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-cxx0x.cpp?rev=361119=361118=361119=diff
==
--- 

r361117 - Add a Visit overload for DynTypedNode to ASTNodeTraverser

2019-05-19 Thread Stephen Kelly via cfe-commits
Author: steveire
Date: Sun May 19 06:03:48 2019
New Revision: 361117

URL: http://llvm.org/viewvc/llvm-project?rev=361117=rev
Log:
Add a Visit overload for DynTypedNode to ASTNodeTraverser

Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

Added:
cfe/trunk/unittests/AST/ASTTraverserTest.cpp
Modified:
cfe/trunk/include/clang/AST/ASTNodeTraverser.h
cfe/trunk/unittests/AST/CMakeLists.txt

Modified: cfe/trunk/include/clang/AST/ASTNodeTraverser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTNodeTraverser.h?rev=361117=361116=361117=diff
==
--- cfe/trunk/include/clang/AST/ASTNodeTraverser.h (original)
+++ cfe/trunk/include/clang/AST/ASTNodeTraverser.h Sun May 19 06:03:48 2019
@@ -205,6 +205,24 @@ public:
 });
   }
 
+  void Visit(const ast_type_traits::DynTypedNode ) {
+// FIXME: Improve this with a switch or a visitor pattern.
+if (const auto *D = N.get())
+  Visit(D);
+else if (const auto *S = N.get())
+  Visit(S);
+else if (const auto *QT = N.get())
+  Visit(*QT);
+else if (const auto *T = N.get())
+  Visit(T);
+else if (const auto *C = N.get())
+  Visit(C);
+else if (const auto *C = N.get())
+  Visit(C);
+else if (const auto *T = N.get())
+  Visit(*T);
+  }
+
   void dumpDeclContext(const DeclContext *DC) {
 if (!DC)
   return;

Added: cfe/trunk/unittests/AST/ASTTraverserTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTTraverserTest.cpp?rev=361117=auto
==
--- cfe/trunk/unittests/AST/ASTTraverserTest.cpp (added)
+++ cfe/trunk/unittests/AST/ASTTraverserTest.cpp Sun May 19 06:03:48 2019
@@ -0,0 +1,224 @@
+//===- 
unittests/AST/ASTTraverserTest.h===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTNodeTraverser.h"
+#include "clang/AST/TextNodeDumper.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang::tooling;
+using namespace clang::ast_matchers;
+
+namespace clang {
+
+class NodeTreePrinter : public TextTreeStructure {
+  llvm::raw_ostream 
+
+public:
+  NodeTreePrinter(llvm::raw_ostream )
+  : TextTreeStructure(OS, /* showColors */ false), OS(OS) {}
+
+  void Visit(const Decl *D) { OS << D->getDeclKindName() << "Decl"; }
+
+  void Visit(const Stmt *S) { OS << S->getStmtClassName(); }
+
+  void Visit(QualType QT) {
+OS << "QualType " << QT.split().Quals.getAsString();
+  }
+
+  void Visit(const Type *T) { OS << T->getTypeClassName() << "Type"; }
+
+  void Visit(const comments::Comment *C, const comments::FullComment *FC) {
+OS << C->getCommentKindName();
+  }
+
+  void Visit(const CXXCtorInitializer *Init) { OS << "CXXCtorInitializer"; }
+
+  void Visit(const Attr *A) {
+switch (A->getKind()) {
+#define ATTR(X)
\
+  case attr::X:
\
+OS << #X;  
\
+break;
+#include "clang/Basic/AttrList.inc"
+}
+OS << "Attr";
+  }
+
+  void Visit(const OMPClause *C) { OS << "OMPClause"; }
+  void Visit(const TemplateArgument , SourceRange R = {},
+ const Decl *From = nullptr, const char *Label = nullptr) {
+OS << "TemplateArgument";
+  }
+
+  template  void Visit(T...) {}
+};
+
+class TestASTDumper : public ASTNodeTraverser {
+
+  NodeTreePrinter MyNodeRecorder;
+
+public:
+  TestASTDumper(llvm::raw_ostream ) : MyNodeRecorder(OS) {}
+  NodeTreePrinter () { return MyNodeRecorder; }
+};
+
+template  std::string dumpASTString(NodeType &&... N) {
+  std::string Buffer;
+  llvm::raw_string_ostream OS(Buffer);
+
+  TestASTDumper Dumper(OS);
+
+  OS << "\n";
+
+  Dumper.Visit(std::forward(N)...);
+
+  return OS.str();
+}
+
+const FunctionDecl *getFunctionNode(clang::ASTUnit *AST,
+const std::string ) {
+  auto Result = ast_matchers::match(functionDecl(hasName(Name)).bind("fn"),
+AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("fn");
+}
+
+template  struct Verifier {
+  static void withDynNode(T Node, const std::string ) {
+EXPECT_EQ(dumpASTString(ast_type_traits::DynTypedNode::create(Node)),
+  DumpString);
+  }
+};
+
+template 

[PATCH] D54334: [AVR] Automatically link CRT and libgcc from the system avr-gcc

2019-05-19 Thread Dylan McKay 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 rC361116: [AVR] Automatically link CRT and libgcc from the 
system avr-gcc (authored by dylanmckay, committed by ).
Herald added a subscriber: ormris.

Changed prior to commit:
  https://reviews.llvm.org/D54334?vs=174362=200177#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D54334

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Basic/DiagnosticGroups.td
  lib/Driver/ToolChains/AVR.cpp
  lib/Driver/ToolChains/AVR.h
  lib/Driver/ToolChains/Gnu.cpp
  test/Driver/avr-link-mcu-family-unimplemented.c
  test/Driver/avr-link-no-mcu-specified.c
  test/Driver/avr-link-nostdlib-nodefaultlibs.c

Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -1033,6 +1033,10 @@
 // compiling CUDA C/C++ but which is not compatible with the CUDA spec.
 def CudaCompat : DiagGroup<"cuda-compat">;
 
+// Warnings which cause linking of the runtime libraries like
+// libc and the CRT to be skipped.
+def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">;
+
 // A warning group for things that will change semantics in the future.
 def FutureCompat : DiagGroup<"future-compat">;
 
Index: include/clang/Basic/DiagnosticDriverKinds.td
===
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -27,6 +27,25 @@
   "invalid arch name '%0', %1">;
 def err_drv_invalid_riscv_ext_arch_name : Error<
   "invalid arch name '%0', %1 '%2'">;
+def warn_drv_avr_mcu_not_specified : Warning<
+  "no target microcontroller specified on command line, cannot "
+  "link standard libraries, please pass -mmcu=">,
+  InGroup;
+def warn_drv_avr_gcc_not_found: Warning<
+  "no avr-gcc installation can be found on the system, "
+  "cannot link standard libraries">,
+  InGroup;
+def warn_drv_avr_libc_not_found: Warning<
+  "no avr-libc installation can be found on the system, "
+  "cannot link standard libraries">,
+  InGroup;
+def warn_drv_avr_family_linking_stdlibs_not_implemented: Warning<
+  "support for linking stdlibs for microcontroller '%0' is not implemented">,
+  InGroup;
+def warn_drv_avr_stdlib_not_linked: Warning<
+  "standard library not linked and so no interrupt vector table or "
+  "compiler runtime routines will be linked">,
+  InGroup;
 def err_drv_cuda_bad_gpu_arch : Error<"Unsupported CUDA gpu architecture: %0">;
 def err_drv_no_cuda_installation : Error<
   "cannot find CUDA installation.  Provide its path via --cuda-path, or pass "
Index: test/Driver/avr-link-no-mcu-specified.c
===
--- test/Driver/avr-link-no-mcu-specified.c
+++ test/Driver/avr-link-no-mcu-specified.c
@@ -0,0 +1,10 @@
+// RUN: %clang -### -target avr -no-canonical-prefixes -save-temps %s 2>&1 | FileCheck --check-prefix=WARN %s
+// RUN: %clang -### -target avr -no-canonical-prefixes -save-temps -mmcu=atmega328 %s 2>&1 | FileCheck --check-prefix=NOWARN %s
+
+// WARN: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu=
+// WARN: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked
+
+// NOWARN: main
+
+int main() { return 0; }
+
Index: test/Driver/avr-link-nostdlib-nodefaultlibs.c
===
--- test/Driver/avr-link-nostdlib-nodefaultlibs.c
+++ test/Driver/avr-link-nostdlib-nodefaultlibs.c
@@ -0,0 +1,8 @@
+// RUN: %clang -### -target avr -no-canonical-prefixes -save-temps -mmcu=atmega328 -nostdlib %s 2>&1 | FileCheck %s
+// RUN: %clang -### -target avr -no-canonical-prefixes -save-temps -mmcu=atmega328 -nodefaultlibs %s 2>&1 | FileCheck %s
+
+// nostdlib and nodefaultlibs programs should compile fine.
+
+// CHECK: main
+int main() { return 0; }
+
Index: test/Driver/avr-link-mcu-family-unimplemented.c
===
--- test/Driver/avr-link-mcu-family-unimplemented.c
+++ test/Driver/avr-link-mcu-family-unimplemented.c
@@ -0,0 +1,7 @@
+// RUN: %clang -### -target avr -no-canonical-prefixes -save-temps -mmcu=attiny13a %s 2>&1 | FileCheck --check-prefix=WARN %s
+
+// WARN: warning: support for linking stdlibs for microcontroller 'attiny13a' is not implemented
+// WARN: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked
+
+int main() { return 0; }
+
Index: lib/Driver/ToolChains/AVR.cpp
===
--- lib/Driver/ToolChains/AVR.cpp
+++ 

r361116 - [AVR] Automatically link CRT and libgcc from the system avr-gcc

2019-05-19 Thread Dylan McKay via cfe-commits
Author: dylanmckay
Date: Sun May 19 02:54:14 2019
New Revision: 361116

URL: http://llvm.org/viewvc/llvm-project?rev=361116=rev
Log:
[AVR] Automatically link CRT and libgcc from the system avr-gcc

Summary:
This patch modifies the AVR toolchain so that if avr-gcc and avr-libc
are detected during compilation, the CRT, libgcc, libm, and libc anre
linked.

This matches avr-gcc's default behaviour, and the expected behaviour of
all C compilers - including the C runtime.

avr-gcc also needs a -mmcu specified in order to link runtime libraries.

The difference betwen this patch and avr-gcc is that this patch will
warn users whenever they compile without a runtime, as opposed to GCC,
which silently trims the runtime libs from the linker arguments when no
-mmcu is specified.

Reviewers: aaron.ballman, kparzysz, asb, hfinkel, brucehoult, TimNN

Subscribers: cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/Driver/avr-link-mcu-family-unimplemented.c
cfe/trunk/test/Driver/avr-link-no-mcu-specified.c
cfe/trunk/test/Driver/avr-link-nostdlib-nodefaultlibs.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/lib/Driver/ToolChains/AVR.cpp
cfe/trunk/lib/Driver/ToolChains/AVR.h
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=361116=361115=361116=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Sun May 19 02:54:14 
2019
@@ -27,6 +27,25 @@ def err_drv_invalid_riscv_arch_name : Er
   "invalid arch name '%0', %1">;
 def err_drv_invalid_riscv_ext_arch_name : Error<
   "invalid arch name '%0', %1 '%2'">;
+def warn_drv_avr_mcu_not_specified : Warning<
+  "no target microcontroller specified on command line, cannot "
+  "link standard libraries, please pass -mmcu=">,
+  InGroup;
+def warn_drv_avr_gcc_not_found: Warning<
+  "no avr-gcc installation can be found on the system, "
+  "cannot link standard libraries">,
+  InGroup;
+def warn_drv_avr_libc_not_found: Warning<
+  "no avr-libc installation can be found on the system, "
+  "cannot link standard libraries">,
+  InGroup;
+def warn_drv_avr_family_linking_stdlibs_not_implemented: Warning<
+  "support for linking stdlibs for microcontroller '%0' is not implemented">,
+  InGroup;
+def warn_drv_avr_stdlib_not_linked: Warning<
+  "standard library not linked and so no interrupt vector table or "
+  "compiler runtime routines will be linked">,
+  InGroup;
 def err_drv_cuda_bad_gpu_arch : Error<"Unsupported CUDA gpu architecture: %0">;
 def err_drv_no_cuda_installation : Error<
   "cannot find CUDA installation.  Provide its path via --cuda-path, or pass "

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=361116=361115=361116=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Sun May 19 02:54:14 2019
@@ -1033,6 +1033,10 @@ def SerializedDiagnostics : DiagGroup<"s
 // compiling CUDA C/C++ but which is not compatible with the CUDA spec.
 def CudaCompat : DiagGroup<"cuda-compat">;
 
+// Warnings which cause linking of the runtime libraries like
+// libc and the CRT to be skipped.
+def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">;
+
 // A warning group for things that will change semantics in the future.
 def FutureCompat : DiagGroup<"future-compat">;
 

Modified: cfe/trunk/lib/Driver/ToolChains/AVR.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/AVR.cpp?rev=361116=361115=361116=diff
==
--- cfe/trunk/lib/Driver/ToolChains/AVR.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/AVR.cpp Sun May 19 02:54:14 2019
@@ -10,7 +10,14 @@
 #include "CommonArgs.h"
 #include "InputInfo.h"
 #include "clang/Driver/Compilation.h"
+#include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/Options.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/MC/MCSubtargetInfo.h"
+#include "llvm/MC/SubtargetFeature.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/FileSystem.h"
 
 using namespace clang::driver;
 using namespace clang::driver::toolchains;
@@ -18,12 +25,76 @@ using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
+namespace {
+
+// TODO: Consider merging this into the AVR device table
+// array in Targets/AVR.cpp.
+llvm::Optional GetMcuFamilyName(StringRef MCU) {

[PATCH] D38479: Make -mgeneral-regs-only more like GCC's

2019-05-19 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

In D38479#1507435 , @phosek wrote:

> We (Fuchsia) would like to see this landed as well so we can start using this 
> in our kernel.


I get the feeling that this patch has been abandoned by the author. Would 
someone like to resurrect it?


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

https://reviews.llvm.org/D38479



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