[PATCH] D25939: PP: Replace some uses of unsigned with size_t

2016-10-26 Thread Erik Verbruggen via cfe-commits
erikjv updated the summary for this revision.
erikjv updated this revision to Diff 75836.

https://reviews.llvm.org/D25939

Files:
  lib/Lex/PPDirectives.cpp


Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -471,7 +471,7 @@
   Directive = RI;
 } else {
   std::string DirectiveStr = getSpelling(Tok);
-  unsigned IdLen = DirectiveStr.size();
+  size_t IdLen = DirectiveStr.size();
   if (IdLen >= 20) {
 CurPPLexer->ParsingPreprocessorDirective = false;
 // Restore comment saving mode.
@@ -801,8 +801,7 @@
 // headers included by quoted include directives.
 // See: http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx
 if (LangOpts.MSVCCompat && !isAngled) {
-  for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
-IncludeStackInfo &ISEntry = IncludeMacroStack[e - i - 1];
+  for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
 if (IsFileLexer(ISEntry))
   if ((FileEnt = ISEntry.ThePPLexer->getFileEntry()))
 Includers.push_back(std::make_pair(FileEnt, FileEnt->getDir()));
@@ -865,8 +864,7 @@
 }
   }
 
-  for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
-IncludeStackInfo &ISEntry = IncludeMacroStack[e-i-1];
+  for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
 if (IsFileLexer(ISEntry)) {
   if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) {
 if ((FE = HeaderInfo.LookupSubframeworkHeader(
@@ -1567,7 +1565,7 @@
   FilenameBuffer.push_back(' ');
 
 // Get the spelling of the token, directly into FilenameBuffer if possible.
-unsigned PreAppendSize = FilenameBuffer.size();
+size_t PreAppendSize = FilenameBuffer.size();
 FilenameBuffer.resize(PreAppendSize+CurTok.getLength());
 
 const char *BufPtr = &FilenameBuffer[PreAppendSize];
@@ -1618,7 +1616,7 @@
   assert(PP.getLangOpts().ObjC2 && "no import syntax available");
 
   SmallString<128> PathString;
-  for (unsigned I = 0, N = Path.size(); I != N; ++I) {
+  for (size_t I = 0, N = Path.size(); I != N; ++I) {
 if (I)
   PathString += '.';
 PathString += Path[I].first->getName();


Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -471,7 +471,7 @@
   Directive = RI;
 } else {
   std::string DirectiveStr = getSpelling(Tok);
-  unsigned IdLen = DirectiveStr.size();
+  size_t IdLen = DirectiveStr.size();
   if (IdLen >= 20) {
 CurPPLexer->ParsingPreprocessorDirective = false;
 // Restore comment saving mode.
@@ -801,8 +801,7 @@
 // headers included by quoted include directives.
 // See: http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx
 if (LangOpts.MSVCCompat && !isAngled) {
-  for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
-IncludeStackInfo &ISEntry = IncludeMacroStack[e - i - 1];
+  for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
 if (IsFileLexer(ISEntry))
   if ((FileEnt = ISEntry.ThePPLexer->getFileEntry()))
 Includers.push_back(std::make_pair(FileEnt, FileEnt->getDir()));
@@ -865,8 +864,7 @@
 }
   }
 
-  for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
-IncludeStackInfo &ISEntry = IncludeMacroStack[e-i-1];
+  for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
 if (IsFileLexer(ISEntry)) {
   if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) {
 if ((FE = HeaderInfo.LookupSubframeworkHeader(
@@ -1567,7 +1565,7 @@
   FilenameBuffer.push_back(' ');
 
 // Get the spelling of the token, directly into FilenameBuffer if possible.
-unsigned PreAppendSize = FilenameBuffer.size();
+size_t PreAppendSize = FilenameBuffer.size();
 FilenameBuffer.resize(PreAppendSize+CurTok.getLength());
 
 const char *BufPtr = &FilenameBuffer[PreAppendSize];
@@ -1618,7 +1616,7 @@
   assert(PP.getLangOpts().ObjC2 && "no import syntax available");
 
   SmallString<128> PathString;
-  for (unsigned I = 0, N = Path.size(); I != N; ++I) {
+  for (size_t I = 0, N = Path.size(); I != N; ++I) {
 if (I)
   PathString += '.';
 PathString += Path[I].first->getName();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25939: PP: Replace some uses of unsigned with size_t

2016-10-26 Thread Benjamin Kramer via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lg


https://reviews.llvm.org/D25939



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


[PATCH] D25938: PP: Remove unused parameters from methods

2016-10-26 Thread Erik Verbruggen via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285180: PP: Remove unused parameters from methods (authored 
by erikjv).

Changed prior to commit:
  https://reviews.llvm.org/D25938?vs=75693&id=75837#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25938

Files:
  cfe/trunk/include/clang/Lex/Preprocessor.h
  cfe/trunk/lib/Lex/PPDirectives.cpp


Index: cfe/trunk/include/clang/Lex/Preprocessor.h
===
--- cfe/trunk/include/clang/Lex/Preprocessor.h
+++ cfe/trunk/include/clang/Lex/Preprocessor.h
@@ -1876,12 +1876,12 @@
   /// Handle*Directive - implement the various preprocessor directives.  These
   /// should side-effect the current preprocessor object so that the next call
   /// to Lex() will return the appropriate token next.
-  void HandleLineDirective(Token &Tok);
+  void HandleLineDirective();
   void HandleDigitDirective(Token &Tok);
   void HandleUserDiagnosticDirective(Token &Tok, bool isWarning);
   void HandleIdentSCCSDirective(Token &Tok);
   void HandleMacroPublicDirective(Token &Tok);
-  void HandleMacroPrivateDirective(Token &Tok);
+  void HandleMacroPrivateDirective();
 
   // File inclusion.
   void HandleIncludeDirective(SourceLocation HashLoc,
@@ -1921,7 +1921,7 @@
 private:
   // Macro handling.
   void HandleDefineDirective(Token &Tok, bool ImmediatelyAfterTopLevelIfndef);
-  void HandleUndefDirective(Token &Tok);
+  void HandleUndefDirective();
 
   // Conditional Inclusion.
   void HandleIfdefDirective(Token &Tok, bool isIfndef,
Index: cfe/trunk/lib/Lex/PPDirectives.cpp
===
--- cfe/trunk/lib/Lex/PPDirectives.cpp
+++ cfe/trunk/lib/Lex/PPDirectives.cpp
@@ -1014,11 +1014,11 @@
 case tok::pp_define:
   return HandleDefineDirective(Result, ImmediatelyAfterTopLevelIfndef);
 case tok::pp_undef:
-  return HandleUndefDirective(Result);
+  return HandleUndefDirective();
 
 // C99 6.10.4 - Line Control.
 case tok::pp_line:
-  return HandleLineDirective(Result);
+  return HandleLineDirective();
 
 // C99 6.10.5 - Error Directive.
 case tok::pp_error:
@@ -1055,7 +1055,7 @@
 
 case tok::pp___private_macro:
   if (getLangOpts().Modules)
-return HandleMacroPrivateDirective(Result);
+return HandleMacroPrivateDirective();
   break;
 }
 break;
@@ -1153,7 +1153,7 @@
 ///   # line digit-sequence
 ///   # line digit-sequence "s-char-sequence"
 /// \endverbatim
-void Preprocessor::HandleLineDirective(Token &Tok) {
+void Preprocessor::HandleLineDirective() {
   // Read the line # and string argument.  Per C99 6.10.4p5, these tokens are
   // expanded.
   Token DigitTok;
@@ -1458,7 +1458,7 @@
 }
 
 /// \brief Handle a #private directive.
-void Preprocessor::HandleMacroPrivateDirective(Token &Tok) {
+void Preprocessor::HandleMacroPrivateDirective() {
   Token MacroNameTok;
   ReadMacroName(MacroNameTok, MU_Undef);
 
@@ -2553,7 +2553,7 @@
 
 /// HandleUndefDirective - Implements \#undef.
 ///
-void Preprocessor::HandleUndefDirective(Token &UndefTok) {
+void Preprocessor::HandleUndefDirective() {
   ++NumUndefined;
 
   Token MacroNameTok;


Index: cfe/trunk/include/clang/Lex/Preprocessor.h
===
--- cfe/trunk/include/clang/Lex/Preprocessor.h
+++ cfe/trunk/include/clang/Lex/Preprocessor.h
@@ -1876,12 +1876,12 @@
   /// Handle*Directive - implement the various preprocessor directives.  These
   /// should side-effect the current preprocessor object so that the next call
   /// to Lex() will return the appropriate token next.
-  void HandleLineDirective(Token &Tok);
+  void HandleLineDirective();
   void HandleDigitDirective(Token &Tok);
   void HandleUserDiagnosticDirective(Token &Tok, bool isWarning);
   void HandleIdentSCCSDirective(Token &Tok);
   void HandleMacroPublicDirective(Token &Tok);
-  void HandleMacroPrivateDirective(Token &Tok);
+  void HandleMacroPrivateDirective();
 
   // File inclusion.
   void HandleIncludeDirective(SourceLocation HashLoc,
@@ -1921,7 +1921,7 @@
 private:
   // Macro handling.
   void HandleDefineDirective(Token &Tok, bool ImmediatelyAfterTopLevelIfndef);
-  void HandleUndefDirective(Token &Tok);
+  void HandleUndefDirective();
 
   // Conditional Inclusion.
   void HandleIfdefDirective(Token &Tok, bool isIfndef,
Index: cfe/trunk/lib/Lex/PPDirectives.cpp
===
--- cfe/trunk/lib/Lex/PPDirectives.cpp
+++ cfe/trunk/lib/Lex/PPDirectives.cpp
@@ -1014,11 +1014,11 @@
 case tok::pp_define:
   return HandleDefineDirective(Result, ImmediatelyAfterTopLevelIfndef);
 case tok::pp_undef:
-  return HandleUndefDirective(Result);
+  return HandleUndefDirective();
 
 // C99 6.10.4 - Line Control.
 case tok::pp_line:
-  return HandleLineDirective(Result);
+  return HandleLineDirective();
 
 

r285180 - PP: Remove unused parameters from methods

2016-10-26 Thread Erik Verbruggen via cfe-commits
Author: erikjv
Date: Wed Oct 26 03:52:41 2016
New Revision: 285180

URL: http://llvm.org/viewvc/llvm-project?rev=285180&view=rev
Log:
PP: Remove unused parameters from methods

NFC

Differential Revision: http://reviews.llvm.org/D25938

Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=285180&r1=285179&r2=285180&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Oct 26 03:52:41 2016
@@ -1876,12 +1876,12 @@ private:
   /// Handle*Directive - implement the various preprocessor directives.  These
   /// should side-effect the current preprocessor object so that the next call
   /// to Lex() will return the appropriate token next.
-  void HandleLineDirective(Token &Tok);
+  void HandleLineDirective();
   void HandleDigitDirective(Token &Tok);
   void HandleUserDiagnosticDirective(Token &Tok, bool isWarning);
   void HandleIdentSCCSDirective(Token &Tok);
   void HandleMacroPublicDirective(Token &Tok);
-  void HandleMacroPrivateDirective(Token &Tok);
+  void HandleMacroPrivateDirective();
 
   // File inclusion.
   void HandleIncludeDirective(SourceLocation HashLoc,
@@ -1921,7 +1921,7 @@ public:
 private:
   // Macro handling.
   void HandleDefineDirective(Token &Tok, bool ImmediatelyAfterTopLevelIfndef);
-  void HandleUndefDirective(Token &Tok);
+  void HandleUndefDirective();
 
   // Conditional Inclusion.
   void HandleIfdefDirective(Token &Tok, bool isIfndef,

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=285180&r1=285179&r2=285180&view=diff
==
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Oct 26 03:52:41 2016
@@ -1014,11 +1014,11 @@ void Preprocessor::HandleDirective(Token
 case tok::pp_define:
   return HandleDefineDirective(Result, ImmediatelyAfterTopLevelIfndef);
 case tok::pp_undef:
-  return HandleUndefDirective(Result);
+  return HandleUndefDirective();
 
 // C99 6.10.4 - Line Control.
 case tok::pp_line:
-  return HandleLineDirective(Result);
+  return HandleLineDirective();
 
 // C99 6.10.5 - Error Directive.
 case tok::pp_error:
@@ -1055,7 +1055,7 @@ void Preprocessor::HandleDirective(Token
 
 case tok::pp___private_macro:
   if (getLangOpts().Modules)
-return HandleMacroPrivateDirective(Result);
+return HandleMacroPrivateDirective();
   break;
 }
 break;
@@ -1153,7 +1153,7 @@ static bool GetLineValue(Token &DigitTok
 ///   # line digit-sequence
 ///   # line digit-sequence "s-char-sequence"
 /// \endverbatim
-void Preprocessor::HandleLineDirective(Token &Tok) {
+void Preprocessor::HandleLineDirective() {
   // Read the line # and string argument.  Per C99 6.10.4p5, these tokens are
   // expanded.
   Token DigitTok;
@@ -1458,7 +1458,7 @@ void Preprocessor::HandleMacroPublicDire
 }
 
 /// \brief Handle a #private directive.
-void Preprocessor::HandleMacroPrivateDirective(Token &Tok) {
+void Preprocessor::HandleMacroPrivateDirective() {
   Token MacroNameTok;
   ReadMacroName(MacroNameTok, MU_Undef);
 
@@ -2553,7 +2553,7 @@ void Preprocessor::HandleDefineDirective
 
 /// HandleUndefDirective - Implements \#undef.
 ///
-void Preprocessor::HandleUndefDirective(Token &UndefTok) {
+void Preprocessor::HandleUndefDirective() {
   ++NumUndefined;
 
   Token MacroNameTok;


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


[PATCH] D25363: [Sema] Store a SourceRange for multi-token builtin types

2016-10-26 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.



Comment at: include/clang/AST/TypeLoc.h:533
+} else {
+  BuiltinRange.setBegin(std::min(Range.getBegin(), 
BuiltinRange.getBegin()));
+  BuiltinRange.setEnd(std::max(Range.getEnd(), BuiltinRange.getEnd()));

aaron.ballman wrote:
> malcolm.parsons wrote:
> > aaron.ballman wrote:
> > > malcolm.parsons wrote:
> > > > I suspect that using `min` and `max` on `SourceLocation`s is only valid 
> > > > if both locations are in the same file.
> > > > 
> > > > Doing this
> > > > long.h:
> > > > ```
> > > > long
> > > > ```
> > > > unsigned.cpp:
> > > > ```
> > > > unsigned
> > > > #include "long.h"
> > > > i;
> > > > ```
> > > > 
> > > > causes
> > > > clang-query> match typeLoc()
> > > > ...
> > > > clang-query: llvm/tools/clang/lib/Frontend/DiagnosticRenderer.cpp:273: 
> > > > clang::SourceLocation retrieveMacroLocation(clang::SourceLocation, 
> > > > clang::FileID, clang::FileID, const 
> > > > llvm::SmallVectorImpl&, bool, const 
> > > > clang::SourceManager*): Assertion `SM->getFileID(Loc) == MacroFileID' 
> > > > failed.
> > > > 
> > > > Is there a better way to combine `SourceRange`s, or should the final 
> > > > range be accumulated in DeclSpec.cpp?
> > > Hmm, that's a good point, but I'm not aware of a better utility. Perhaps 
> > > @rsmith knows of one?
> > I get the same assertion failure from a clang-query without my changes if I 
> > match a `CompoundStmt` that starts and ends in different files.
> > So I don't think it's my fault.
> > It's also a very rare case.
> > OK to commit?
> Thank you for checking. I think you are okay to commit, we can correct the 
> bug in another patch. However, if you wouldn't mind filing a bug in bugzilla 
> so that we don't lose this information, that would be great.
PR30765.


Repository:
  rL LLVM

https://reviews.llvm.org/D25363



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


r285182 - [PP] Replace some uses of unsigned with size_t

2016-10-26 Thread Erik Verbruggen via cfe-commits
Author: erikjv
Date: Wed Oct 26 04:58:31 2016
New Revision: 285182

URL: http://llvm.org/viewvc/llvm-project?rev=285182&view=rev
Log:
[PP] Replace some uses of unsigned with size_t

All values are returned by a method as size_t, and subsequently passed
to functions taking a size_t, or used where a size_t is also valid.
Better still, two loops (which had an unsigned), can be replaced by
a range-based for loop.

Differential Revision: http://reviews.llvm.org/D25939

Modified:
cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=285182&r1=285181&r2=285182&view=diff
==
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Oct 26 04:58:31 2016
@@ -471,7 +471,7 @@ void Preprocessor::SkipExcludedCondition
   Directive = RI;
 } else {
   std::string DirectiveStr = getSpelling(Tok);
-  unsigned IdLen = DirectiveStr.size();
+  size_t IdLen = DirectiveStr.size();
   if (IdLen >= 20) {
 CurPPLexer->ParsingPreprocessorDirective = false;
 // Restore comment saving mode.
@@ -801,8 +801,7 @@ const FileEntry *Preprocessor::LookupFil
 // headers included by quoted include directives.
 // See: http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx
 if (LangOpts.MSVCCompat && !isAngled) {
-  for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
-IncludeStackInfo &ISEntry = IncludeMacroStack[e - i - 1];
+  for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
 if (IsFileLexer(ISEntry))
   if ((FileEnt = ISEntry.ThePPLexer->getFileEntry()))
 Includers.push_back(std::make_pair(FileEnt, FileEnt->getDir()));
@@ -865,8 +864,7 @@ const FileEntry *Preprocessor::LookupFil
 }
   }
 
-  for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
-IncludeStackInfo &ISEntry = IncludeMacroStack[e-i-1];
+  for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
 if (IsFileLexer(ISEntry)) {
   if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) {
 if ((FE = HeaderInfo.LookupSubframeworkHeader(
@@ -1567,7 +1565,7 @@ bool Preprocessor::ConcatenateIncludeNam
   FilenameBuffer.push_back(' ');
 
 // Get the spelling of the token, directly into FilenameBuffer if possible.
-unsigned PreAppendSize = FilenameBuffer.size();
+size_t PreAppendSize = FilenameBuffer.size();
 FilenameBuffer.resize(PreAppendSize+CurTok.getLength());
 
 const char *BufPtr = &FilenameBuffer[PreAppendSize];
@@ -1618,7 +1616,7 @@ static void diagnoseAutoModuleImport(
   assert(PP.getLangOpts().ObjC2 && "no import syntax available");
 
   SmallString<128> PathString;
-  for (unsigned I = 0, N = Path.size(); I != N; ++I) {
+  for (size_t I = 0, N = Path.size(); I != N; ++I) {
 if (I)
   PathString += '.';
 PathString += Path[I].first->getName();


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


[PATCH] D25939: PP: Replace some uses of unsigned with size_t

2016-10-26 Thread Erik Verbruggen via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285182: [PP] Replace some uses of unsigned with size_t 
(authored by erikjv).

Changed prior to commit:
  https://reviews.llvm.org/D25939?vs=75836&id=75841#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25939

Files:
  cfe/trunk/lib/Lex/PPDirectives.cpp


Index: cfe/trunk/lib/Lex/PPDirectives.cpp
===
--- cfe/trunk/lib/Lex/PPDirectives.cpp
+++ cfe/trunk/lib/Lex/PPDirectives.cpp
@@ -471,7 +471,7 @@
   Directive = RI;
 } else {
   std::string DirectiveStr = getSpelling(Tok);
-  unsigned IdLen = DirectiveStr.size();
+  size_t IdLen = DirectiveStr.size();
   if (IdLen >= 20) {
 CurPPLexer->ParsingPreprocessorDirective = false;
 // Restore comment saving mode.
@@ -801,8 +801,7 @@
 // headers included by quoted include directives.
 // See: http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx
 if (LangOpts.MSVCCompat && !isAngled) {
-  for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
-IncludeStackInfo &ISEntry = IncludeMacroStack[e - i - 1];
+  for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
 if (IsFileLexer(ISEntry))
   if ((FileEnt = ISEntry.ThePPLexer->getFileEntry()))
 Includers.push_back(std::make_pair(FileEnt, FileEnt->getDir()));
@@ -865,8 +864,7 @@
 }
   }
 
-  for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
-IncludeStackInfo &ISEntry = IncludeMacroStack[e-i-1];
+  for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
 if (IsFileLexer(ISEntry)) {
   if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) {
 if ((FE = HeaderInfo.LookupSubframeworkHeader(
@@ -1567,7 +1565,7 @@
   FilenameBuffer.push_back(' ');
 
 // Get the spelling of the token, directly into FilenameBuffer if possible.
-unsigned PreAppendSize = FilenameBuffer.size();
+size_t PreAppendSize = FilenameBuffer.size();
 FilenameBuffer.resize(PreAppendSize+CurTok.getLength());
 
 const char *BufPtr = &FilenameBuffer[PreAppendSize];
@@ -1618,7 +1616,7 @@
   assert(PP.getLangOpts().ObjC2 && "no import syntax available");
 
   SmallString<128> PathString;
-  for (unsigned I = 0, N = Path.size(); I != N; ++I) {
+  for (size_t I = 0, N = Path.size(); I != N; ++I) {
 if (I)
   PathString += '.';
 PathString += Path[I].first->getName();


Index: cfe/trunk/lib/Lex/PPDirectives.cpp
===
--- cfe/trunk/lib/Lex/PPDirectives.cpp
+++ cfe/trunk/lib/Lex/PPDirectives.cpp
@@ -471,7 +471,7 @@
   Directive = RI;
 } else {
   std::string DirectiveStr = getSpelling(Tok);
-  unsigned IdLen = DirectiveStr.size();
+  size_t IdLen = DirectiveStr.size();
   if (IdLen >= 20) {
 CurPPLexer->ParsingPreprocessorDirective = false;
 // Restore comment saving mode.
@@ -801,8 +801,7 @@
 // headers included by quoted include directives.
 // See: http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx
 if (LangOpts.MSVCCompat && !isAngled) {
-  for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
-IncludeStackInfo &ISEntry = IncludeMacroStack[e - i - 1];
+  for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
 if (IsFileLexer(ISEntry))
   if ((FileEnt = ISEntry.ThePPLexer->getFileEntry()))
 Includers.push_back(std::make_pair(FileEnt, FileEnt->getDir()));
@@ -865,8 +864,7 @@
 }
   }
 
-  for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
-IncludeStackInfo &ISEntry = IncludeMacroStack[e-i-1];
+  for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
 if (IsFileLexer(ISEntry)) {
   if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) {
 if ((FE = HeaderInfo.LookupSubframeworkHeader(
@@ -1567,7 +1565,7 @@
   FilenameBuffer.push_back(' ');
 
 // Get the spelling of the token, directly into FilenameBuffer if possible.
-unsigned PreAppendSize = FilenameBuffer.size();
+size_t PreAppendSize = FilenameBuffer.size();
 FilenameBuffer.resize(PreAppendSize+CurTok.getLength());
 
 const char *BufPtr = &FilenameBuffer[PreAppendSize];
@@ -1618,7 +1616,7 @@
   assert(PP.getLangOpts().ObjC2 && "no import syntax available");
 
   SmallString<128> PathString;
-  for (unsigned I = 0, N = Path.size(); I != N; ++I) {
+  for (size_t I = 0, N = Path.size(); I != N; ++I) {
 if (I)
   PathString += '.';
 PathString += Path[I].first->getName();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r285184 - [modules] PR28812: Modules can return duplicate field decls.

2016-10-26 Thread Vassil Vassilev via cfe-commits
Author: vvassilev
Date: Wed Oct 26 05:24:29 2016
New Revision: 285184

URL: http://llvm.org/viewvc/llvm-project?rev=285184&view=rev
Log:
[modules] PR28812: Modules can return duplicate field decls.

If two modules contain duplicate class definitions the lookup result can contain
more than 2 elements. Sift the lookup results until we find a field decl.

It is not necessary to do ODR checks in place as they done elsewhere.

This should fix issues when compiling with libstdc++ 5.2 and 6.2.

Patch developed in collaboration with Richard Smith!

Added:
cfe/trunk/test/Modules/Inputs/PR28812/
cfe/trunk/test/Modules/Inputs/PR28812/Textual.h
cfe/trunk/test/Modules/Inputs/PR28812/a.h
cfe/trunk/test/Modules/Inputs/PR28812/b.h
cfe/trunk/test/Modules/Inputs/PR28812/module.modulemap
cfe/trunk/test/Modules/pr28812.cpp
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=285184&r1=285183&r2=285184&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Oct 26 05:24:29 2016
@@ -12321,13 +12321,20 @@ ExprResult Sema::BuildCXXDefaultInitExpr
 // Lookup can return at most two results: the pattern for the field, or the
 // injected class name of the parent record. No other member can have the
 // same name as the field.
-assert(!Lookup.empty() && Lookup.size() <= 2 &&
+// In modules mode, lookup can return multiple results (coming from
+// different modules).
+assert((getLangOpts().Modules || (!Lookup.empty() && Lookup.size() <= 2)) 
&&
"more than two lookup results for field name");
 FieldDecl *Pattern = dyn_cast(Lookup[0]);
 if (!Pattern) {
   assert(isa(Lookup[0]) &&
  "cannot have other non-field member with same name");
-  Pattern = cast(Lookup[1]);
+  for (auto L : Lookup)
+if (isa(L)) {
+  Pattern = cast(L);
+  break;
+}
+  assert(Pattern && "We must have set the Pattern!");
 }
 
 if (InstantiateInClassInitializer(Loc, Field, Pattern,

Added: cfe/trunk/test/Modules/Inputs/PR28812/Textual.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28812/Textual.h?rev=285184&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR28812/Textual.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR28812/Textual.h Wed Oct 26 05:24:29 2016
@@ -0,0 +1,11 @@
+#ifndef T_H
+#define T_H
+
+template  struct VarStreamArray;
+
+template  struct VarStreamArrayIterator {
+  VarStreamArrayIterator(VarStreamArray) {}
+  bool HasError{};
+};
+
+#endif // T_H

Added: cfe/trunk/test/Modules/Inputs/PR28812/a.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28812/a.h?rev=285184&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR28812/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR28812/a.h Wed Oct 26 05:24:29 2016
@@ -0,0 +1 @@
+#include "Textual.h"

Added: cfe/trunk/test/Modules/Inputs/PR28812/b.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28812/b.h?rev=285184&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR28812/b.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR28812/b.h Wed Oct 26 05:24:29 2016
@@ -0,0 +1 @@
+#include "Textual.h"

Added: cfe/trunk/test/Modules/Inputs/PR28812/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28812/module.modulemap?rev=285184&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR28812/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/PR28812/module.modulemap Wed Oct 26 05:24:29 
2016
@@ -0,0 +1,6 @@
+module "A" {
+  header "a.h"
+}
+module "B" { 
+  header "b.h"
+}

Added: cfe/trunk/test/Modules/pr28812.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/pr28812.cpp?rev=285184&view=auto
==
--- cfe/trunk/test/Modules/pr28812.cpp (added)
+++ cfe/trunk/test/Modules/pr28812.cpp Wed Oct 26 05:24:29 2016
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -nostdsysteminc -I%S/Inputs/PR28812 -verify %s
+// RUN: %clang_cc1 -std=c++11 -nostdsysteminc -fmodules -fimplicit-module-maps 
\
+// RUN:-fmodules-cache-path=%t -I%S/Inputs/PR28812 -verify %s
+
+template  struct VarStreamArrayIterator;
+template 
+struct VarStreamArray {
+  typedef VarStreamArrayIterator Iterator;
+  Iterator begin() { return Iterator(*this); }
+};
+
+#include "Textual.h"
+
+#include "a.h"
+#include "b.h"
+
+VarStreamArray a;
+auto b = a.begin();

[PATCH] D25981: [PP] Remove another unused parameter

2016-10-26 Thread Erik Verbruggen via cfe-commits
erikjv created this revision.
erikjv added a reviewer: bkramer.
erikjv added a subscriber: cfe-commits.

https://reviews.llvm.org/D25981

Files:
  include/clang/Lex/Preprocessor.h
  lib/Lex/Pragma.cpp


Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -393,7 +393,7 @@
 
 /// HandlePragmaPoison - Handle \#pragma GCC poison.  PoisonTok is the 
'poison'.
 ///
-void Preprocessor::HandlePragmaPoison(Token &PoisonTok) {
+void Preprocessor::HandlePragmaPoison() {
   Token Tok;
 
   while (true) {
@@ -853,7 +853,7 @@
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
 Token &PoisonTok) override {
-PP.HandlePragmaPoison(PoisonTok);
+PP.HandlePragmaPoison();
   }
 };
 
Index: include/clang/Lex/Preprocessor.h
===
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -2011,7 +2011,7 @@
 public:
   void HandlePragmaOnce(Token &OnceTok);
   void HandlePragmaMark();
-  void HandlePragmaPoison(Token &PoisonTok);
+  void HandlePragmaPoison();
   void HandlePragmaSystemHeader(Token &SysHeaderTok);
   void HandlePragmaDependency(Token &DependencyTok);
   void HandlePragmaPushMacro(Token &Tok);


Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -393,7 +393,7 @@
 
 /// HandlePragmaPoison - Handle \#pragma GCC poison.  PoisonTok is the 'poison'.
 ///
-void Preprocessor::HandlePragmaPoison(Token &PoisonTok) {
+void Preprocessor::HandlePragmaPoison() {
   Token Tok;
 
   while (true) {
@@ -853,7 +853,7 @@
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
 Token &PoisonTok) override {
-PP.HandlePragmaPoison(PoisonTok);
+PP.HandlePragmaPoison();
   }
 };
 
Index: include/clang/Lex/Preprocessor.h
===
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -2011,7 +2011,7 @@
 public:
   void HandlePragmaOnce(Token &OnceTok);
   void HandlePragmaMark();
-  void HandlePragmaPoison(Token &PoisonTok);
+  void HandlePragmaPoison();
   void HandlePragmaSystemHeader(Token &SysHeaderTok);
   void HandlePragmaDependency(Token &DependencyTok);
   void HandlePragmaPushMacro(Token &Tok);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25982: [PP] Replace some index based for loops with range based ones

2016-10-26 Thread Erik Verbruggen via cfe-commits
erikjv created this revision.
erikjv added a reviewer: bkramer.
erikjv added a subscriber: cfe-commits.
Herald added subscribers: anna, nemanjai.

While in the area, also change some unsigned variables to size_t, and
introduce an LLVM_FALLTHROUGH instead of a comment stating that.


https://reviews.llvm.org/D25982

Files:
  lib/Lex/PPCaching.cpp
  lib/Lex/PPLexerChange.cpp
  lib/Lex/PPMacroExpansion.cpp
  lib/Lex/Pragma.cpp
  lib/Lex/TokenConcatenation.cpp
  lib/Lex/TokenLexer.cpp

Index: lib/Lex/TokenLexer.cpp
===
--- lib/Lex/TokenLexer.cpp
+++ lib/Lex/TokenLexer.cpp
@@ -275,7 +275,7 @@
 
   // If the arg token expanded into anything, append it.
   if (ResultArgToks->isNot(tok::eof)) {
-unsigned FirstResult = ResultToks.size();
+size_t FirstResult = ResultToks.size();
 unsigned NumToks = MacroArgs::getArgLength(ResultArgToks);
 ResultToks.append(ResultArgToks, ResultArgToks+NumToks);
 
@@ -289,8 +289,8 @@
 
 // If the '##' came from expanding an argument, turn it into 'unknown'
 // to avoid pasting.
-for (unsigned i = FirstResult, e = ResultToks.size(); i != e; ++i) {
-  Token &Tok = ResultToks[i];
+for (Token &Tok : llvm::make_range(ResultToks.begin() + FirstResult,
+   ResultToks.end())) {
   if (Tok.is(tok::hashhash))
 Tok.setKind(tok::unknown);
 }
@@ -333,9 +333,8 @@
 
   // If the '##' came from expanding an argument, turn it into 'unknown'
   // to avoid pasting.
-  for (unsigned i = ResultToks.size() - NumToks, e = ResultToks.size();
- i != e; ++i) {
-Token &Tok = ResultToks[i];
+  for (Token &Tok : llvm::make_range(ResultToks.end() - NumToks,
+ ResultToks.end())) {
 if (Tok.is(tok::hashhash))
   Tok.setKind(tok::unknown);
   }
Index: lib/Lex/TokenConcatenation.cpp
===
--- lib/Lex/TokenConcatenation.cpp
+++ lib/Lex/TokenConcatenation.cpp
@@ -232,7 +232,7 @@
 // it as an identifier.
 if (!PrevTok.hasUDSuffix())
   return false;
-// FALL THROUGH.
+LLVM_FALLTHROUGH;
   case tok::identifier:   // id+id or id+number or id+L"foo".
 // id+'.'... will not append.
 if (Tok.is(tok::numeric_constant))
Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -281,7 +281,7 @@
 
 // Remove escaped quotes and escapes.
 unsigned ResultPos = 1;
-for (unsigned i = 1, e = StrVal.size() - 1; i != e; ++i) {
+for (size_t i = 1, e = StrVal.size() - 1; i != e; ++i) {
   // Skip escapes.  \\ -> '\' and \" -> '"'.
   if (StrVal[i] == '\\' && i + 1 < e &&
   (StrVal[i + 1] == '\\' || StrVal[i + 1] == '"'))
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -411,8 +411,7 @@
 // macro stack.
 if (CurPPLexer)
   return false;
-for (unsigned i = IncludeMacroStack.size(); i != 0; --i) {
-  IncludeStackInfo &Entry = IncludeMacroStack[i-1];
+for (const IncludeStackInfo &Entry : llvm::reverse(IncludeMacroStack)) {
   if (Entry.TheLexer)
 Val = Entry.TheLexer->isNextPPTokenLParen();
   else if (Entry.ThePTHLexer)
@@ -501,9 +500,7 @@
 } else {
   Callbacks->MacroExpands(Identifier, M, ExpansionRange, Args);
   if (!DelayedMacroExpandsCallbacks.empty()) {
-for (unsigned i = 0, e = DelayedMacroExpandsCallbacks.size(); i != e;
- ++i) {
-  MacroExpandsInfo &Info = DelayedMacroExpandsCallbacks[i];
+for (const MacroExpandsInfo &Info : DelayedMacroExpandsCallbacks) {
   // FIXME: We lose macro args info with delayed callback.
   Callbacks->MacroExpands(Info.Tok, Info.MD, Info.Range,
   /*Args=*/nullptr);
@@ -757,7 +754,7 @@
 assert(Tok.isOneOf(tok::l_paren, tok::comma) &&
"only expect argument separators here");
 
-unsigned ArgTokenStart = ArgTokens.size();
+size_t ArgTokenStart = ArgTokens.size();
 SourceLocation ArgStartLoc = Tok.getLocation();
 
 // C99 6.10.3p11: Keep track of the number of l_parens we have seen.  Note
@@ -1009,10 +1006,10 @@
   if (cacheNeedsToGrow) {
 // Go through all the TokenLexers whose 'Tokens' pointer points in the
 // buffer and update the pointers to the (potential) new buffer array.
-for (unsigned i = 0, e = MacroExpandingLexersStack.size(); i != e; ++i) {
+for (const auto &Lexer : MacroExpandingLexersStack) {
   TokenLexer *prevLexer;
   size_t tokIndex;
-  std::tie(prevLexer, tokIndex) = MacroExpandingLexersStack[i];
+  std::tie(prevLexer, tokIndex) = Lexer;
   prevLexer->Tokens =

r285188 - [PP] Remove another unused parameter

2016-10-26 Thread Erik Verbruggen via cfe-commits
Author: erikjv
Date: Wed Oct 26 06:46:10 2016
New Revision: 285188

URL: http://llvm.org/viewvc/llvm-project?rev=285188&view=rev
Log:
[PP] Remove another unused parameter

Differential Revision: http://reviews.llvm.org/D25981

Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/Pragma.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=285188&r1=285187&r2=285188&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Oct 26 06:46:10 2016
@@ -1937,7 +1937,7 @@ private:
 public:
   void HandlePragmaOnce(Token &OnceTok);
   void HandlePragmaMark();
-  void HandlePragmaPoison(Token &PoisonTok);
+  void HandlePragmaPoison();
   void HandlePragmaSystemHeader(Token &SysHeaderTok);
   void HandlePragmaDependency(Token &DependencyTok);
   void HandlePragmaPushMacro(Token &Tok);

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=285188&r1=285187&r2=285188&view=diff
==
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Wed Oct 26 06:46:10 2016
@@ -393,7 +393,7 @@ void Preprocessor::HandlePragmaMark() {
 
 /// HandlePragmaPoison - Handle \#pragma GCC poison.  PoisonTok is the 
'poison'.
 ///
-void Preprocessor::HandlePragmaPoison(Token &PoisonTok) {
+void Preprocessor::HandlePragmaPoison() {
   Token Tok;
 
   while (true) {
@@ -853,7 +853,7 @@ struct PragmaPoisonHandler : public Prag
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
 Token &PoisonTok) override {
-PP.HandlePragmaPoison(PoisonTok);
+PP.HandlePragmaPoison();
   }
 };
 


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


[PATCH] D25981: [PP] Remove another unused parameter

2016-10-26 Thread Erik Verbruggen via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285188: [PP] Remove another unused parameter (authored by 
erikjv).

Changed prior to commit:
  https://reviews.llvm.org/D25981?vs=75850&id=75853#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25981

Files:
  cfe/trunk/include/clang/Lex/Preprocessor.h
  cfe/trunk/lib/Lex/Pragma.cpp


Index: cfe/trunk/include/clang/Lex/Preprocessor.h
===
--- cfe/trunk/include/clang/Lex/Preprocessor.h
+++ cfe/trunk/include/clang/Lex/Preprocessor.h
@@ -1937,7 +1937,7 @@
 public:
   void HandlePragmaOnce(Token &OnceTok);
   void HandlePragmaMark();
-  void HandlePragmaPoison(Token &PoisonTok);
+  void HandlePragmaPoison();
   void HandlePragmaSystemHeader(Token &SysHeaderTok);
   void HandlePragmaDependency(Token &DependencyTok);
   void HandlePragmaPushMacro(Token &Tok);
Index: cfe/trunk/lib/Lex/Pragma.cpp
===
--- cfe/trunk/lib/Lex/Pragma.cpp
+++ cfe/trunk/lib/Lex/Pragma.cpp
@@ -393,7 +393,7 @@
 
 /// HandlePragmaPoison - Handle \#pragma GCC poison.  PoisonTok is the 
'poison'.
 ///
-void Preprocessor::HandlePragmaPoison(Token &PoisonTok) {
+void Preprocessor::HandlePragmaPoison() {
   Token Tok;
 
   while (true) {
@@ -853,7 +853,7 @@
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
 Token &PoisonTok) override {
-PP.HandlePragmaPoison(PoisonTok);
+PP.HandlePragmaPoison();
   }
 };
 


Index: cfe/trunk/include/clang/Lex/Preprocessor.h
===
--- cfe/trunk/include/clang/Lex/Preprocessor.h
+++ cfe/trunk/include/clang/Lex/Preprocessor.h
@@ -1937,7 +1937,7 @@
 public:
   void HandlePragmaOnce(Token &OnceTok);
   void HandlePragmaMark();
-  void HandlePragmaPoison(Token &PoisonTok);
+  void HandlePragmaPoison();
   void HandlePragmaSystemHeader(Token &SysHeaderTok);
   void HandlePragmaDependency(Token &DependencyTok);
   void HandlePragmaPushMacro(Token &Tok);
Index: cfe/trunk/lib/Lex/Pragma.cpp
===
--- cfe/trunk/lib/Lex/Pragma.cpp
+++ cfe/trunk/lib/Lex/Pragma.cpp
@@ -393,7 +393,7 @@
 
 /// HandlePragmaPoison - Handle \#pragma GCC poison.  PoisonTok is the 'poison'.
 ///
-void Preprocessor::HandlePragmaPoison(Token &PoisonTok) {
+void Preprocessor::HandlePragmaPoison() {
   Token Tok;
 
   while (true) {
@@ -853,7 +853,7 @@
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
 Token &PoisonTok) override {
-PP.HandlePragmaPoison(PoisonTok);
+PP.HandlePragmaPoison();
   }
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25982: [PP] Replace some index based for loops with range based ones

2016-10-26 Thread Benjamin Kramer via cfe-commits
bkramer added inline comments.



Comment at: lib/Lex/PPLexerChange.cpp:43
  "Top level include stack isn't our primary lexer?");
-  for (unsigned i = 1, e = IncludeMacroStack.size(); i != e; ++i)
-if (IsFileLexer(IncludeMacroStack[i]))
+  for (const IncludeStackInfo &ISI : llvm::reverse(
+ llvm::make_range(IncludeMacroStack.begin() + 1,

This wasn't a reverse loop?

Also I think at this point writing it with none_of is more readable:
```
return std::none_of(IncludeMacroStack.begin() + 1, IncludeMacroStack.end(), 
IsFileLexer);
```


https://reviews.llvm.org/D25982



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


r285178 - Bug 28065 - clang-format incorrectly aligns backslash.

2016-10-26 Thread Andi-Bogdan Postelnicu via cfe-commits
Author: abpostelnicu
Date: Wed Oct 26 02:44:51 2016
New Revision: 285178

URL: http://llvm.org/viewvc/llvm-project?rev=285178&view=rev
Log:
Bug 28065 - clang-format incorrectly aligns backslash.

Modified:
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=285178&r1=285177&r2=285178&view=diff
==
--- cfe/trunk/lib/Format/WhitespaceManager.cpp (original)
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp Wed Oct 26 02:44:51 2016
@@ -432,7 +432,7 @@ void WhitespaceManager::alignTrailingCom
 }
 assert(Shift >= 0);
 Changes[i].Spaces += Shift;
-if (i + 1 != End)
+if (i + 1 != Changes.size())
   Changes[i + 1].PreviousEndOfTokenColumn += Shift;
 Changes[i].StartOfTokenColumn += Shift;
   }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=285178&r1=285177&r2=285178&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Oct 26 02:44:51 2016
@@ -11597,6 +11597,17 @@ TEST_F(ReplacementTest, SortIncludesAfte
   EXPECT_EQ(Expected, *Result);
 }
 
+TEST_F(FormatTest, AllignTrailingComments) {
+  EXPECT_EQ("#define MACRO(V)   \\\n"
+"  V(Rt2) /* one more char */   \\\n"
+"  V(Rs)  /* than here  */  \\\n"
+"/* comment 3 */\n",
+format("#define MACRO(V)\\\n"
+   "V(Rt2)  /* one more char */ \\\n"
+   "V(Rs) /* than here  */\\\n"
+   "/* comment 3 */ \\\n",
+   getLLVMStyleWithColumns(40)));
+}
 } // end namespace
 } // end namespace format
 } // end namespace clang


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


[PATCH] D25982: [PP] Replace some index based for loops with range based ones

2016-10-26 Thread Erik Verbruggen via cfe-commits
erikjv updated this revision to Diff 75854.
erikjv marked an inline comment as done.

https://reviews.llvm.org/D25982

Files:
  lib/Lex/PPCaching.cpp
  lib/Lex/PPLexerChange.cpp
  lib/Lex/PPMacroExpansion.cpp
  lib/Lex/Pragma.cpp
  lib/Lex/TokenConcatenation.cpp
  lib/Lex/TokenLexer.cpp

Index: lib/Lex/TokenLexer.cpp
===
--- lib/Lex/TokenLexer.cpp
+++ lib/Lex/TokenLexer.cpp
@@ -275,7 +275,7 @@
 
   // If the arg token expanded into anything, append it.
   if (ResultArgToks->isNot(tok::eof)) {
-unsigned FirstResult = ResultToks.size();
+size_t FirstResult = ResultToks.size();
 unsigned NumToks = MacroArgs::getArgLength(ResultArgToks);
 ResultToks.append(ResultArgToks, ResultArgToks+NumToks);
 
@@ -289,8 +289,8 @@
 
 // If the '##' came from expanding an argument, turn it into 'unknown'
 // to avoid pasting.
-for (unsigned i = FirstResult, e = ResultToks.size(); i != e; ++i) {
-  Token &Tok = ResultToks[i];
+for (Token &Tok : llvm::make_range(ResultToks.begin() + FirstResult,
+   ResultToks.end())) {
   if (Tok.is(tok::hashhash))
 Tok.setKind(tok::unknown);
 }
@@ -333,9 +333,8 @@
 
   // If the '##' came from expanding an argument, turn it into 'unknown'
   // to avoid pasting.
-  for (unsigned i = ResultToks.size() - NumToks, e = ResultToks.size();
- i != e; ++i) {
-Token &Tok = ResultToks[i];
+  for (Token &Tok : llvm::make_range(ResultToks.end() - NumToks,
+ ResultToks.end())) {
 if (Tok.is(tok::hashhash))
   Tok.setKind(tok::unknown);
   }
Index: lib/Lex/TokenConcatenation.cpp
===
--- lib/Lex/TokenConcatenation.cpp
+++ lib/Lex/TokenConcatenation.cpp
@@ -232,7 +232,7 @@
 // it as an identifier.
 if (!PrevTok.hasUDSuffix())
   return false;
-// FALL THROUGH.
+LLVM_FALLTHROUGH;
   case tok::identifier:   // id+id or id+number or id+L"foo".
 // id+'.'... will not append.
 if (Tok.is(tok::numeric_constant))
Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -281,7 +281,7 @@
 
 // Remove escaped quotes and escapes.
 unsigned ResultPos = 1;
-for (unsigned i = 1, e = StrVal.size() - 1; i != e; ++i) {
+for (size_t i = 1, e = StrVal.size() - 1; i != e; ++i) {
   // Skip escapes.  \\ -> '\' and \" -> '"'.
   if (StrVal[i] == '\\' && i + 1 < e &&
   (StrVal[i + 1] == '\\' || StrVal[i + 1] == '"'))
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -411,8 +411,7 @@
 // macro stack.
 if (CurPPLexer)
   return false;
-for (unsigned i = IncludeMacroStack.size(); i != 0; --i) {
-  IncludeStackInfo &Entry = IncludeMacroStack[i-1];
+for (const IncludeStackInfo &Entry : llvm::reverse(IncludeMacroStack)) {
   if (Entry.TheLexer)
 Val = Entry.TheLexer->isNextPPTokenLParen();
   else if (Entry.ThePTHLexer)
@@ -501,9 +500,7 @@
 } else {
   Callbacks->MacroExpands(Identifier, M, ExpansionRange, Args);
   if (!DelayedMacroExpandsCallbacks.empty()) {
-for (unsigned i = 0, e = DelayedMacroExpandsCallbacks.size(); i != e;
- ++i) {
-  MacroExpandsInfo &Info = DelayedMacroExpandsCallbacks[i];
+for (const MacroExpandsInfo &Info : DelayedMacroExpandsCallbacks) {
   // FIXME: We lose macro args info with delayed callback.
   Callbacks->MacroExpands(Info.Tok, Info.MD, Info.Range,
   /*Args=*/nullptr);
@@ -757,7 +754,7 @@
 assert(Tok.isOneOf(tok::l_paren, tok::comma) &&
"only expect argument separators here");
 
-unsigned ArgTokenStart = ArgTokens.size();
+size_t ArgTokenStart = ArgTokens.size();
 SourceLocation ArgStartLoc = Tok.getLocation();
 
 // C99 6.10.3p11: Keep track of the number of l_parens we have seen.  Note
@@ -1009,10 +1006,10 @@
   if (cacheNeedsToGrow) {
 // Go through all the TokenLexers whose 'Tokens' pointer points in the
 // buffer and update the pointers to the (potential) new buffer array.
-for (unsigned i = 0, e = MacroExpandingLexersStack.size(); i != e; ++i) {
+for (const auto &Lexer : MacroExpandingLexersStack) {
   TokenLexer *prevLexer;
   size_t tokIndex;
-  std::tie(prevLexer, tokIndex) = MacroExpandingLexersStack[i];
+  std::tie(prevLexer, tokIndex) = Lexer;
   prevLexer->Tokens = MacroExpandedTokens.data() + tokIndex;
 }
   }
Index: lib/Lex/PPLexerChange.cpp
===
--- lib/Lex/PPLexerChange.cpp
+++ lib/Lex/PPL

[PATCH] D25982: [PP] Replace some index based for loops with range based ones

2016-10-26 Thread Benjamin Kramer via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lgtm


https://reviews.llvm.org/D25982



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


[PATCH] D25983: Fix use-after-free in ASTContext.

2016-10-26 Thread Sam McCall via cfe-commits
sammccall created this revision.
sammccall added a reviewer: bkramer.
sammccall added subscribers: cfe-commits, rsmith.

Extend lifetime of ExceptionTypeStorage, as it is referenced by
CanonicalEPI and used outside the block (ExceptionSpec.Exceptions is an 
ArrayRef)


https://reviews.llvm.org/D25983

Files:
  lib/AST/ASTContext.cpp


Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -3230,13 +3230,13 @@
 for (unsigned i = 0; i != NumArgs; ++i)
   CanonicalArgs.push_back(getCanonicalParamType(ArgArray[i]));
 
+llvm::SmallVector ExceptionTypeStorage;
 FunctionProtoType::ExtProtoInfo CanonicalEPI = EPI;
 CanonicalEPI.HasTrailingReturn = false;
 
 if (IsCanonicalExceptionSpec) {
   // Exception spec is already OK.
 } else if (NoexceptInType) {
-  llvm::SmallVector ExceptionTypeStorage;
   switch (EPI.ExceptionSpec.Type) {
   case EST_Unparsed: case EST_Unevaluated: case EST_Uninstantiated:
 // We don't know yet. It shouldn't matter what we pick here; no-one


Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -3230,13 +3230,13 @@
 for (unsigned i = 0; i != NumArgs; ++i)
   CanonicalArgs.push_back(getCanonicalParamType(ArgArray[i]));
 
+llvm::SmallVector ExceptionTypeStorage;
 FunctionProtoType::ExtProtoInfo CanonicalEPI = EPI;
 CanonicalEPI.HasTrailingReturn = false;
 
 if (IsCanonicalExceptionSpec) {
   // Exception spec is already OK.
 } else if (NoexceptInType) {
-  llvm::SmallVector ExceptionTypeStorage;
   switch (EPI.ExceptionSpec.Type) {
   case EST_Unparsed: case EST_Unevaluated: case EST_Uninstantiated:
 // We don't know yet. It shouldn't matter what we pick here; no-one
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r285192 - Fix use-after-scope in ASTContext.

2016-10-26 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Oct 26 07:51:45 2016
New Revision: 285192

URL: http://llvm.org/viewvc/llvm-project?rev=285192&view=rev
Log:
Fix use-after-scope in ASTContext.

Extend lifetime of ExceptionTypeStorage, as it is referenced by
CanonicalEPI and used outside the block (ExceptionSpec.Exceptions is an
ArrayRef)

Patch by Sam McCall!

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

Modified:
cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=285192&r1=285191&r2=285192&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Oct 26 07:51:45 2016
@@ -3230,13 +3230,13 @@ QualType ASTContext::getFunctionTypeInte
 for (unsigned i = 0; i != NumArgs; ++i)
   CanonicalArgs.push_back(getCanonicalParamType(ArgArray[i]));
 
+llvm::SmallVector ExceptionTypeStorage;
 FunctionProtoType::ExtProtoInfo CanonicalEPI = EPI;
 CanonicalEPI.HasTrailingReturn = false;
 
 if (IsCanonicalExceptionSpec) {
   // Exception spec is already OK.
 } else if (NoexceptInType) {
-  llvm::SmallVector ExceptionTypeStorage;
   switch (EPI.ExceptionSpec.Type) {
   case EST_Unparsed: case EST_Unevaluated: case EST_Uninstantiated:
 // We don't know yet. It shouldn't matter what we pick here; no-one


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


[PATCH] D25983: Fix use-after-free in ASTContext.

2016-10-26 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285192: Fix use-after-scope in ASTContext. (authored by d0k).

Changed prior to commit:
  https://reviews.llvm.org/D25983?vs=75860&id=75865#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25983

Files:
  cfe/trunk/lib/AST/ASTContext.cpp


Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -3230,13 +3230,13 @@
 for (unsigned i = 0; i != NumArgs; ++i)
   CanonicalArgs.push_back(getCanonicalParamType(ArgArray[i]));
 
+llvm::SmallVector ExceptionTypeStorage;
 FunctionProtoType::ExtProtoInfo CanonicalEPI = EPI;
 CanonicalEPI.HasTrailingReturn = false;
 
 if (IsCanonicalExceptionSpec) {
   // Exception spec is already OK.
 } else if (NoexceptInType) {
-  llvm::SmallVector ExceptionTypeStorage;
   switch (EPI.ExceptionSpec.Type) {
   case EST_Unparsed: case EST_Unevaluated: case EST_Uninstantiated:
 // We don't know yet. It shouldn't matter what we pick here; no-one


Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -3230,13 +3230,13 @@
 for (unsigned i = 0; i != NumArgs; ++i)
   CanonicalArgs.push_back(getCanonicalParamType(ArgArray[i]));
 
+llvm::SmallVector ExceptionTypeStorage;
 FunctionProtoType::ExtProtoInfo CanonicalEPI = EPI;
 CanonicalEPI.HasTrailingReturn = false;
 
 if (IsCanonicalExceptionSpec) {
   // Exception spec is already OK.
 } else if (NoexceptInType) {
-  llvm::SmallVector ExceptionTypeStorage;
   switch (EPI.ExceptionSpec.Type) {
   case EST_Unparsed: case EST_Unevaluated: case EST_Uninstantiated:
 // We don't know yet. It shouldn't matter what we pick here; no-one
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25669: [Driver] Simplify ToolChain::GetCXXStdlibType (NFC)

2016-10-26 Thread Alexey Bataev via cfe-commits
ABataev added inline comments.



Comment at: lib/Driver/ToolChain.cpp:553-559
+  // "platform" is only used in tests to override CLANG_DEFAULT_CXX_STDLIB
+  if (LibName == "libc++")
+return ToolChain::CST_Libcxx;
+  else if (LibName == "libstdc++")
+return ToolChain::CST_Libstdcxx;
+  else if (LibName == "platform")
+return GetDefaultCXXStdlibType();

Hahnfeld wrote:
> mgorny wrote:
> > ABataev wrote:
> > > I believe you can use StringSwitch here
> > I think you are changing the meaning of this comment. The original sounded 
> > like a request not to use this type anywhere else. Your version only 
> > explains where it's used (right now).
> I'm uncertain how to apply it while also preserving the `Diag` for an invalid 
> argument: I would probably need an additional `CST_Unknown` which I don't 
> like more...
I think you can try something like this:
```
llvm::Optional Res = 
StringSwitch(LibName).Case("libc++", 
ToolChain::CST_Libcxx).Case("libstdc++", 
ToolChain::CST_Libstdcxx).Case("platform", 
GetDefaultCXXStdlibType()).Default(llvm::None);
if (Res)
  return Res.getValue();
```


https://reviews.llvm.org/D25669



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


[PATCH] D25982: [PP] Replace some index based for loops with range based ones

2016-10-26 Thread Erik Verbruggen via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285193: [PP] Replace some index based for loops with range 
based ones (authored by erikjv).

Changed prior to commit:
  https://reviews.llvm.org/D25982?vs=75854&id=75867#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25982

Files:
  cfe/trunk/lib/Lex/PPCaching.cpp
  cfe/trunk/lib/Lex/PPLexerChange.cpp
  cfe/trunk/lib/Lex/PPMacroExpansion.cpp
  cfe/trunk/lib/Lex/Pragma.cpp
  cfe/trunk/lib/Lex/TokenConcatenation.cpp
  cfe/trunk/lib/Lex/TokenLexer.cpp

Index: cfe/trunk/lib/Lex/Pragma.cpp
===
--- cfe/trunk/lib/Lex/Pragma.cpp
+++ cfe/trunk/lib/Lex/Pragma.cpp
@@ -281,7 +281,7 @@
 
 // Remove escaped quotes and escapes.
 unsigned ResultPos = 1;
-for (unsigned i = 1, e = StrVal.size() - 1; i != e; ++i) {
+for (size_t i = 1, e = StrVal.size() - 1; i != e; ++i) {
   // Skip escapes.  \\ -> '\' and \" -> '"'.
   if (StrVal[i] == '\\' && i + 1 < e &&
   (StrVal[i + 1] == '\\' || StrVal[i + 1] == '"'))
Index: cfe/trunk/lib/Lex/PPCaching.cpp
===
--- cfe/trunk/lib/Lex/PPCaching.cpp
+++ cfe/trunk/lib/Lex/PPCaching.cpp
@@ -86,7 +86,7 @@
 const Token &Preprocessor::PeekAhead(unsigned N) {
   assert(CachedLexPos + N > CachedTokens.size() && "Confused caching.");
   ExitCachingLexMode();
-  for (unsigned C = CachedLexPos + N - CachedTokens.size(); C > 0; --C) {
+  for (size_t C = CachedLexPos + N - CachedTokens.size(); C > 0; --C) {
 CachedTokens.push_back(Token());
 Lex(CachedTokens.back());
   }
Index: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
===
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp
@@ -411,8 +411,7 @@
 // macro stack.
 if (CurPPLexer)
   return false;
-for (unsigned i = IncludeMacroStack.size(); i != 0; --i) {
-  IncludeStackInfo &Entry = IncludeMacroStack[i-1];
+for (const IncludeStackInfo &Entry : llvm::reverse(IncludeMacroStack)) {
   if (Entry.TheLexer)
 Val = Entry.TheLexer->isNextPPTokenLParen();
   else if (Entry.ThePTHLexer)
@@ -501,9 +500,7 @@
 } else {
   Callbacks->MacroExpands(Identifier, M, ExpansionRange, Args);
   if (!DelayedMacroExpandsCallbacks.empty()) {
-for (unsigned i = 0, e = DelayedMacroExpandsCallbacks.size(); i != e;
- ++i) {
-  MacroExpandsInfo &Info = DelayedMacroExpandsCallbacks[i];
+for (const MacroExpandsInfo &Info : DelayedMacroExpandsCallbacks) {
   // FIXME: We lose macro args info with delayed callback.
   Callbacks->MacroExpands(Info.Tok, Info.MD, Info.Range,
   /*Args=*/nullptr);
@@ -757,7 +754,7 @@
 assert(Tok.isOneOf(tok::l_paren, tok::comma) &&
"only expect argument separators here");
 
-unsigned ArgTokenStart = ArgTokens.size();
+size_t ArgTokenStart = ArgTokens.size();
 SourceLocation ArgStartLoc = Tok.getLocation();
 
 // C99 6.10.3p11: Keep track of the number of l_parens we have seen.  Note
@@ -1009,10 +1006,10 @@
   if (cacheNeedsToGrow) {
 // Go through all the TokenLexers whose 'Tokens' pointer points in the
 // buffer and update the pointers to the (potential) new buffer array.
-for (unsigned i = 0, e = MacroExpandingLexersStack.size(); i != e; ++i) {
+for (const auto &Lexer : MacroExpandingLexersStack) {
   TokenLexer *prevLexer;
   size_t tokIndex;
-  std::tie(prevLexer, tokIndex) = MacroExpandingLexersStack[i];
+  std::tie(prevLexer, tokIndex) = Lexer;
   prevLexer->Tokens = MacroExpandedTokens.data() + tokIndex;
 }
   }
Index: cfe/trunk/lib/Lex/TokenConcatenation.cpp
===
--- cfe/trunk/lib/Lex/TokenConcatenation.cpp
+++ cfe/trunk/lib/Lex/TokenConcatenation.cpp
@@ -232,7 +232,7 @@
 // it as an identifier.
 if (!PrevTok.hasUDSuffix())
   return false;
-// FALL THROUGH.
+LLVM_FALLTHROUGH;
   case tok::identifier:   // id+id or id+number or id+L"foo".
 // id+'.'... will not append.
 if (Tok.is(tok::numeric_constant))
Index: cfe/trunk/lib/Lex/PPLexerChange.cpp
===
--- cfe/trunk/lib/Lex/PPLexerChange.cpp
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp
@@ -40,10 +40,10 @@
   // If there are any stacked lexers, we're in a #include.
   assert(IsFileLexer(IncludeMacroStack[0]) &&
  "Top level include stack isn't our primary lexer?");
-  for (unsigned i = 1, e = IncludeMacroStack.size(); i != e; ++i)
-if (IsFileLexer(IncludeMacroStack[i]))
-  return false;
-  return true;
+  return std::none_of(IncludeMacroStack.begin() + 1, IncludeMacroStack.end(),
+  [](const IncludeStackInfo &ISI) -> bool {
+return IsFileLexer(ISI);
+ 

r285193 - [PP] Replace some index based for loops with range based ones

2016-10-26 Thread Erik Verbruggen via cfe-commits
Author: erikjv
Date: Wed Oct 26 08:06:13 2016
New Revision: 285193

URL: http://llvm.org/viewvc/llvm-project?rev=285193&view=rev
Log:
[PP] Replace some index based for loops with range based ones

While in the area, also change some unsigned variables to size_t, and
introduce an LLVM_FALLTHROUGH instead of a comment stating that.

Differential Revision: http://reviews.llvm.org/D25982

Modified:
cfe/trunk/lib/Lex/PPCaching.cpp
cfe/trunk/lib/Lex/PPLexerChange.cpp
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/lib/Lex/Pragma.cpp
cfe/trunk/lib/Lex/TokenConcatenation.cpp
cfe/trunk/lib/Lex/TokenLexer.cpp

Modified: cfe/trunk/lib/Lex/PPCaching.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPCaching.cpp?rev=285193&r1=285192&r2=285193&view=diff
==
--- cfe/trunk/lib/Lex/PPCaching.cpp (original)
+++ cfe/trunk/lib/Lex/PPCaching.cpp Wed Oct 26 08:06:13 2016
@@ -86,7 +86,7 @@ void Preprocessor::EnterCachingLexMode()
 const Token &Preprocessor::PeekAhead(unsigned N) {
   assert(CachedLexPos + N > CachedTokens.size() && "Confused caching.");
   ExitCachingLexMode();
-  for (unsigned C = CachedLexPos + N - CachedTokens.size(); C > 0; --C) {
+  for (size_t C = CachedLexPos + N - CachedTokens.size(); C > 0; --C) {
 CachedTokens.push_back(Token());
 Lex(CachedTokens.back());
   }

Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=285193&r1=285192&r2=285193&view=diff
==
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Wed Oct 26 08:06:13 2016
@@ -40,10 +40,10 @@ bool Preprocessor::isInPrimaryFile() con
   // If there are any stacked lexers, we're in a #include.
   assert(IsFileLexer(IncludeMacroStack[0]) &&
  "Top level include stack isn't our primary lexer?");
-  for (unsigned i = 1, e = IncludeMacroStack.size(); i != e; ++i)
-if (IsFileLexer(IncludeMacroStack[i]))
-  return false;
-  return true;
+  return std::none_of(IncludeMacroStack.begin() + 1, IncludeMacroStack.end(),
+  [](const IncludeStackInfo &ISI) -> bool {
+return IsFileLexer(ISI);
+  });
 }
 
 /// getCurrentLexer - Return the current file lexer being lexed from.  Note
@@ -54,8 +54,7 @@ PreprocessorLexer *Preprocessor::getCurr
 return CurPPLexer;
 
   // Look for a stacked lexer.
-  for (unsigned i = IncludeMacroStack.size(); i != 0; --i) {
-const IncludeStackInfo& ISI = IncludeMacroStack[i-1];
+  for (const IncludeStackInfo &ISI : llvm::reverse(IncludeMacroStack)) {
 if (IsFileLexer(ISI))
   return ISI.ThePPLexer;
   }
@@ -566,8 +565,7 @@ void Preprocessor::HandleMicrosoftCommen
   // explicit EOD token.
   PreprocessorLexer *FoundLexer = nullptr;
   bool LexerWasInPPMode = false;
-  for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
-IncludeStackInfo &ISI = *(IncludeMacroStack.end()-i-1);
+  for (const IncludeStackInfo &ISI : llvm::reverse(IncludeMacroStack)) {
 if (ISI.ThePPLexer == nullptr) continue;  // Scan for a real lexer.
 
 // Once we find a real lexer, mark it as raw mode (disabling macro

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=285193&r1=285192&r2=285193&view=diff
==
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Wed Oct 26 08:06:13 2016
@@ -411,8 +411,7 @@ bool Preprocessor::isNextPPTokenLParen()
 // macro stack.
 if (CurPPLexer)
   return false;
-for (unsigned i = IncludeMacroStack.size(); i != 0; --i) {
-  IncludeStackInfo &Entry = IncludeMacroStack[i-1];
+for (const IncludeStackInfo &Entry : llvm::reverse(IncludeMacroStack)) {
   if (Entry.TheLexer)
 Val = Entry.TheLexer->isNextPPTokenLParen();
   else if (Entry.ThePTHLexer)
@@ -501,9 +500,7 @@ bool Preprocessor::HandleMacroExpandedId
 } else {
   Callbacks->MacroExpands(Identifier, M, ExpansionRange, Args);
   if (!DelayedMacroExpandsCallbacks.empty()) {
-for (unsigned i = 0, e = DelayedMacroExpandsCallbacks.size(); i != e;
- ++i) {
-  MacroExpandsInfo &Info = DelayedMacroExpandsCallbacks[i];
+for (const MacroExpandsInfo &Info : DelayedMacroExpandsCallbacks) {
   // FIXME: We lose macro args info with delayed callback.
   Callbacks->MacroExpands(Info.Tok, Info.MD, Info.Range,
   /*Args=*/nullptr);
@@ -757,7 +754,7 @@ MacroArgs *Preprocessor::ReadFunctionLik
 assert(Tok.isOneOf(tok::l_paren, tok::comma) &&
"only expect argument separators here");
 
-unsigned ArgTokenStart = ArgTokens.size();
+size_t ArgTokenStart = ArgTokens.

[PATCH] D25604: Add support for Mageia Linux

2016-10-26 Thread Vassil Vassilev via cfe-commits
v.g.vassilev removed rL LLVM as the repository for this revision.
v.g.vassilev updated this revision to Diff 75868.
v.g.vassilev added a comment.

Add another triple we use.


https://reviews.llvm.org/D25604

Files:
  lib/Driver/ToolChains.cpp


Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -1521,6 +1521,7 @@
   "x86_64-redhat-linux","x86_64-suse-linux",
   "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
   "x86_64-slackware-linux", "x86_64-linux-android",
+  "x86_64-mageia-linux-gnu", "x86_64-redhat-linux-gnu"
   "x86_64-unknown-linux"};
   static const char *const X32LibDirs[] = {"/libx32"};
   static const char *const X86LibDirs[] = {"/lib32", "/lib"};
@@ -1529,6 +1530,7 @@
   "i386-linux-gnu",   "i386-redhat-linux6E",   "i686-redhat-linux",
   "i586-redhat-linux","i386-redhat-linux", "i586-suse-linux",
   "i486-slackware-linux", "i686-montavista-linux", "i686-linux-android",
+  "i586-mageia-linux-gnu", "i586-redhat-linux-gnu"
   "i586-linux-gnu"};
 
   static const char *const MIPSLibDirs[] = {"/lib"};


Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -1521,6 +1521,7 @@
   "x86_64-redhat-linux","x86_64-suse-linux",
   "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
   "x86_64-slackware-linux", "x86_64-linux-android",
+  "x86_64-mageia-linux-gnu", "x86_64-redhat-linux-gnu"
   "x86_64-unknown-linux"};
   static const char *const X32LibDirs[] = {"/libx32"};
   static const char *const X86LibDirs[] = {"/lib32", "/lib"};
@@ -1529,6 +1530,7 @@
   "i386-linux-gnu",   "i386-redhat-linux6E",   "i686-redhat-linux",
   "i586-redhat-linux","i386-redhat-linux", "i586-suse-linux",
   "i486-slackware-linux", "i686-montavista-linux", "i686-linux-android",
+  "i586-mageia-linux-gnu", "i586-redhat-linux-gnu"
   "i586-linux-gnu"};
 
   static const char *const MIPSLibDirs[] = {"/lib"};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25669: [Driver] Simplify ToolChain::GetCXXStdlibType (NFC)

2016-10-26 Thread Jonas Hahnfeld via cfe-commits
Hahnfeld added inline comments.



Comment at: lib/Driver/ToolChain.cpp:553-559
+  // "platform" is only used in tests to override CLANG_DEFAULT_CXX_STDLIB
+  if (LibName == "libc++")
+return ToolChain::CST_Libcxx;
+  else if (LibName == "libstdc++")
+return ToolChain::CST_Libstdcxx;
+  else if (LibName == "platform")
+return GetDefaultCXXStdlibType();

ABataev wrote:
> Hahnfeld wrote:
> > mgorny wrote:
> > > ABataev wrote:
> > > > I believe you can use StringSwitch here
> > > I think you are changing the meaning of this comment. The original 
> > > sounded like a request not to use this type anywhere else. Your version 
> > > only explains where it's used (right now).
> > I'm uncertain how to apply it while also preserving the `Diag` for an 
> > invalid argument: I would probably need an additional `CST_Unknown` which I 
> > don't like more...
> I think you can try something like this:
> ```
> llvm::Optional Res = 
> StringSwitch llvm::NoneType>(LibName).Case("libc++", 
> ToolChain::CST_Libcxx).Case("libstdc++", 
> ToolChain::CST_Libstdcxx).Case("platform", 
> GetDefaultCXXStdlibType()).Default(llvm::None);
> if (Res)
>   return Res.getValue();
> ```
Does that really improve readability? `StringSwitch` is currently never used in 
`ToolChain.cpp` and the cascade with `if`s is one line shorter in this case...


https://reviews.llvm.org/D25669



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


[PATCH] D25660: [Analyzer] Checker for iterators dereferenced beyond their range.

2016-10-26 Thread Balogh , Ádám via cfe-commits
baloghadamsoftware updated this revision to Diff 75875.
baloghadamsoftware added a comment.

Updated according to the comments. Also fixed a bug and moved access check to 
pre-call instead of post-call.


https://reviews.llvm.org/D25660

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/Inputs/system-header-simulator-for-iterators.h
  test/Analysis/iterator-past-end.cpp

Index: test/Analysis/iterator-past-end.cpp
===
--- /dev/null
+++ test/Analysis/iterator-past-end.cpp
@@ -0,0 +1,180 @@
+// RUN: %clang_cc1 -std=c++11 -analyze -analyzer-checker=core,cplusplus,alpha.cplusplus.IteratorPastEnd %s -verify
+
+#include "Inputs/system-header-simulator-for-iterators.h"
+
+void simple_good(const std::vector &v) {
+  auto i = v.end();
+  if (i != v.end())
+*i; // no-warning
+}
+
+void simple_bad(const std::vector &v) {
+  auto i = v.end();
+  *i; // expected-warning{{Iterator accessed past its end}}
+}
+
+void copy(const std::vector &v) {
+  auto i1 = v.end();
+  auto i2 = i1;
+  *i2; // expected-warning{{Iterator accessed past its end}}
+}
+
+void decrease(const std::vector &v) {
+  auto i = v.end();
+  --i;
+  *i; // no-warning
+}
+
+void copy_and_decrease1(const std::vector &v) {
+  auto i1 = v.end();
+  auto i2 = i1;
+  --i1;
+  *i1; // no-warning
+}
+
+void copy_and_decrease2(const std::vector &v) {
+  auto i1 = v.end();
+  auto i2 = i1;
+  --i1;
+  *i2; // expected-warning{{Iterator accessed past its end}}
+}
+
+void copy_and_increase1(const std::vector &v) {
+  auto i1 = v.begin();
+  auto i2 = i1;
+  ++i1;
+  if (i1 == v.end())
+*i2; // no-warning
+}
+
+void copy_and_increase2(const std::vector &v) {
+  auto i1 = v.begin();
+  auto i2 = i1;
+  ++i1;
+  if (i2 == v.end())
+*i2; // expected-warning{{Iterator accessed past its end}}
+}
+
+void good_find(std::vector &vec, int e) {
+  auto first = std::find(vec.begin(), vec.end(), e);
+  if (vec.end() != first)
+*first; // no-warning
+}
+
+void bad_find(std::vector &vec, int e) {
+  auto first = std::find(vec.begin(), vec.end(), e);
+  *first; // expected-warning{{Iterator accessed past its end}}
+}
+
+void good_find_end(std::vector &vec, std::vector &seq) {
+  auto last = std::find_end(vec.begin(), vec.end(), seq.begin(), seq.end());
+  if (vec.end() != last)
+*last; // no-warning
+}
+
+void bad_find_end(std::vector &vec, std::vector &seq) {
+  auto last = std::find_end(vec.begin(), vec.end(), seq.begin(), seq.end());
+  *last; // expected-warning{{Iterator accessed past its end}}
+}
+
+void good_find_first_of(std::vector &vec, std::vector &seq) {
+  auto first =
+  std::find_first_of(vec.begin(), vec.end(), seq.begin(), seq.end());
+  if (vec.end() != first)
+*first; // no-warning
+}
+
+void bad_find_first_of(std::vector &vec, std::vector &seq) {
+  auto first = std::find_end(vec.begin(), vec.end(), seq.begin(), seq.end());
+  *first; // expected-warning{{Iterator accessed past its end}}
+}
+
+bool odd(int i) { return i % 2; }
+
+void good_find_if(std::vector &vec) {
+  auto first = std::find_if(vec.begin(), vec.end(), odd);
+  if (vec.end() != first)
+*first; // no-warning
+}
+
+void bad_find_if(std::vector &vec, int e) {
+  auto first = std::find_if(vec.begin(), vec.end(), odd);
+  *first; // expected-warning{{Iterator accessed past its end}}
+}
+
+void good_find_if_not(std::vector &vec) {
+  auto first = std::find_if_not(vec.begin(), vec.end(), odd);
+  if (vec.end() != first)
+*first; // no-warning
+}
+
+void bad_find_if_not(std::vector &vec, int e) {
+  auto first = std::find_if_not(vec.begin(), vec.end(), odd);
+  *first; // expected-warning{{Iterator accessed past its end}}
+}
+
+void good_lower_bound(std::vector &vec, int e) {
+  auto first = std::lower_bound(vec.begin(), vec.end(), e);
+  if (vec.end() != first)
+*first; // no-warning
+}
+
+void bad_lower_bound(std::vector &vec, int e) {
+  auto first = std::lower_bound(vec.begin(), vec.end(), e);
+  *first; // expected-warning{{Iterator accessed past its end}}
+}
+
+void good_upper_bound(std::vector &vec, int e) {
+  auto last = std::lower_bound(vec.begin(), vec.end(), e);
+  if (vec.end() != last)
+*last; // no-warning
+}
+
+void bad_upper_bound(std::vector &vec, int e) {
+  auto last = std::lower_bound(vec.begin(), vec.end(), e);
+  *last; // expected-warning{{Iterator accessed past its end}}
+}
+
+void good_search(std::vector &vec, std::vector &seq) {
+  auto first = std::search(vec.begin(), vec.end(), seq.begin(), seq.end());
+  if (vec.end() != first)
+*first; // no-warning
+}
+
+void bad_search(std::vector &vec, std::vector &seq) {
+  auto first = std::search(vec.begin(), vec.end(), seq.begin(), seq.end());
+  *first; // expected-warning{{Iterator accessed past its end}}
+}
+
+void good_search_n(std::vector &vec, std::ve

[PATCH] D25985: [analyzer] Export coverage information from the analyzer.

2016-10-26 Thread Gábor Horváth via cfe-commits
xazax.hun created this revision.
xazax.hun added reviewers: zaks.anna, NoQ, a.sidorin, dcoughlin.
xazax.hun added subscribers: cfe-commits, dkrupp, o.gyorgy, szepet.
xazax.hun set the repository for this revision to rL LLVM.

This patch adds a new option to export an optimistic basic block coverage from 
the static analyzer.

Example usage:

  clang++ --analyze -Xclang -analyzer-config -Xclang record-coverage=gcovfiles 
foo.cpp

Example output:

   -:0:Source:foo.cpp
  -:0:Runs:1
  -:0:Programs:1
  -:1:#include 
  -:2:
  -:3:int main() {
  -:4:  int i = 2;
  1:5:  ++i;
  1:6:  if (i) {
  1:7:std::cout << "foo" << std::endl;
  1:8:  } else {
  -:9:std::cout << "bar" << std::endl;
  -:10:  }
  -:11:}

It will generate a gcov file (sourcename.gcov) for each non system header 
source file in the directory that was given with the record-coverage option.

The gcov format is relatively easy to read, but HTML can be generated using 
gcovr:

  gcovr -g gcovfiles --html --html-details -r . -o example.html

In the future I also plan to contribute a python script that can aggregate the 
gcov files from different translation units into one folder.
Possible use cases:

- Get an overview about the coverage of the static analyzer on a given codebase.
- Collect ideas how to increase the coverage and test them.
- Evaluate possible cross translation unit coverage patterns.


Repository:
  rL LLVM

https://reviews.llvm.org/D25985

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/analyzer-config.c
  test/Analysis/analyzer-config.cpp
  test/Analysis/record-coverage.cpp
  test/Analysis/record-coverage.cpp.expected

Index: test/Analysis/record-coverage.cpp.expected
===
--- /dev/null
+++ test/Analysis/record-coverage.cpp.expected
@@ -0,0 +1,9 @@
+// CHECK:  -:4:int main() {
+// CHECK-NEXT: -:5:  int i = 2;
+// CHECK-NEXT: 1:6:  ++i;
+// CHECK-NEXT: 1:7:  if (i != 0) {
+// CHECK-NEXT: 1:8:++i;
+// CHECK-NEXT: 1:9:  } else {
+// CHECK-NEXT: -:10:--i;
+// CHECK-NEXT: -:11:  }
+// CHECK-NEXT: -:12:}
Index: test/Analysis/record-coverage.cpp
===
--- /dev/null
+++ test/Analysis/record-coverage.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-config record-coverage=%T %s
+// RUN: FileCheck -input-file %T/%s.gcov %s.expected
+
+int main() {
+  int i = 2;
+  ++i;
+  if (i != 0) {
+++i;
+  } else {
+--i;
+  }
+}
Index: test/Analysis/analyzer-config.cpp
===
--- test/Analysis/analyzer-config.cpp
+++ test/Analysis/analyzer-config.cpp
@@ -35,7 +35,8 @@
 // CHECK-NEXT: max-times-inline-large = 32
 // CHECK-NEXT: min-cfg-size-treat-functions-as-large = 14
 // CHECK-NEXT: mode = deep
+// CHECK-NEXT: record-coverage =
 // CHECK-NEXT: region-store-small-struct-limit = 2
 // CHECK-NEXT: widen-loops = false
 // CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 20
+// CHECK-NEXT: num-entries = 21
Index: test/Analysis/analyzer-config.c
===
--- test/Analysis/analyzer-config.c
+++ test/Analysis/analyzer-config.c
@@ -24,8 +24,9 @@
 // CHECK-NEXT: max-times-inline-large = 32
 // CHECK-NEXT: min-cfg-size-treat-functions-as-large = 14
 // CHECK-NEXT: mode = deep
+// CHECK-NEXT: record-coverage =
 // CHECK-NEXT: region-store-small-struct-limit = 2
 // CHECK-NEXT: widen-loops = false
 // CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 15
+// CHECK-NEXT: num-entries = 16
 
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -28,8 +28,13 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/LoopWidening.h"
 #include "llvm/ADT/Statistic.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/LineIterator.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/raw_os_ostream.h"
+#include 
 
 #ifndef NDEBUG
 #include "llvm/Support/GraphWriter.h"
@@ -251,6 +256,45 @@
   return State;
 }
 
+// Mapping from file to line indexed hit count vector.
+static llvm::DenseMap> CoverageInfo;
+
+static void dumpCoverageInfo(llvm::SmallVectorImpl &Path,
+ SourceManager &SM) {
+  for (auto &Entry : CoverageInfo) {
+SmallString<128> FilePath;
+const FileEntry *FE = Entry.getFirst();
+llvm::sys::path::append(FilePath, Path, FE->getName() + ".gcov");
+SmallString<128> DirPath = FilePath;
+llvm::sys::path::remove_filename(DirPath);
+llvm::sys::fs::create_directories(DirPath);
+bool Invalid = false;
+  

[PATCH] D25937: [Sema] -Wunused-variable warning for variables with array types should behave similarly to variables with scalar types

2016-10-26 Thread Alex Lorenz via cfe-commits
arphaman updated this revision to Diff 75877.
arphaman added a comment.

The updated patch incorporates John's suggestions into code.


Repository:
  rL LLVM

https://reviews.llvm.org/D25937

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaCXX/warn-everthing.cpp
  test/SemaCXX/warn-unused-variables.cpp


Index: test/SemaCXX/warn-unused-variables.cpp
===
--- test/SemaCXX/warn-unused-variables.cpp
+++ test/SemaCXX/warn-unused-variables.cpp
@@ -150,3 +150,51 @@
 }
 
 #include "Inputs/warn-unused-variables.h"
+
+namespace arrayRecords {
+
+int total = 0;
+
+class Adder {
+public:
+  Adder(int x); // out of line below
+  ~Adder() {}
+};
+
+Adder::Adder(int x) {
+  total += x;
+}
+
+struct Foo {
+  int x;
+  Foo(int x) : x(x) {}
+};
+
+struct S1 {
+  S1();
+};
+
+void foo(int size) {
+  S1 y; // no warning
+  S1 yarray[2]; // no warning
+  S1 dynArray[size]; // no warning
+
+  Adder scalerInFuncScope = 134; // no warning
+  Adder arrayInFuncScope[] = { 135, 136 };  // no warning
+
+  Foo fooScalar = 1; // expected-warning {{unused variable 'fooScalar'}}
+  Foo fooArray[] = {1,2}; // expected-warning {{unused variable 'fooArray'}}
+}
+
+template
+void bar() {
+  Adder scaler = 123; // no warning
+  Adder array[N] = {1,2}; // no warning
+}
+
+void test() {
+  foo(10);
+  bar<2>();
+}
+
+}
Index: test/SemaCXX/warn-everthing.cpp
===
--- test/SemaCXX/warn-everthing.cpp
+++ test/SemaCXX/warn-everthing.cpp
@@ -9,5 +9,5 @@
 };
 
 void testPR12271() { // expected-warning {{no previous prototype for function 
'testPR12271'}}
-  PR12271 a[1][1]; // expected-warning {{unused variable 'a'}}
+  PR12271 a[1][1];
 }
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -1522,7 +1522,7 @@
   if (const VarDecl *VD = dyn_cast(D)) {
 
 // White-list anything with an __attribute__((unused)) type.
-QualType Ty = VD->getType();
+const auto *Ty = VD->getType().getTypePtr();
 
 // Only look at the outermost level of typedef.
 if (const TypedefType *TT = Ty->getAs()) {
@@ -1535,6 +1535,10 @@
 if (Ty->isIncompleteType() || Ty->isDependentType())
   return false;
 
+// Look at the element type to ensure that the warning behaviour is
+// consistent for both scalars and arrays.
+Ty = Ty->getBaseElementTypeUnsafe();
+
 if (const TagType *TT = Ty->getAs()) {
   const TagDecl *Tag = TT->getDecl();
   if (Tag->hasAttr())


Index: test/SemaCXX/warn-unused-variables.cpp
===
--- test/SemaCXX/warn-unused-variables.cpp
+++ test/SemaCXX/warn-unused-variables.cpp
@@ -150,3 +150,51 @@
 }
 
 #include "Inputs/warn-unused-variables.h"
+
+namespace arrayRecords {
+
+int total = 0;
+
+class Adder {
+public:
+  Adder(int x); // out of line below
+  ~Adder() {}
+};
+
+Adder::Adder(int x) {
+  total += x;
+}
+
+struct Foo {
+  int x;
+  Foo(int x) : x(x) {}
+};
+
+struct S1 {
+  S1();
+};
+
+void foo(int size) {
+  S1 y; // no warning
+  S1 yarray[2]; // no warning
+  S1 dynArray[size]; // no warning
+
+  Adder scalerInFuncScope = 134; // no warning
+  Adder arrayInFuncScope[] = { 135, 136 };  // no warning
+
+  Foo fooScalar = 1; // expected-warning {{unused variable 'fooScalar'}}
+  Foo fooArray[] = {1,2}; // expected-warning {{unused variable 'fooArray'}}
+}
+
+template
+void bar() {
+  Adder scaler = 123; // no warning
+  Adder array[N] = {1,2}; // no warning
+}
+
+void test() {
+  foo(10);
+  bar<2>();
+}
+
+}
Index: test/SemaCXX/warn-everthing.cpp
===
--- test/SemaCXX/warn-everthing.cpp
+++ test/SemaCXX/warn-everthing.cpp
@@ -9,5 +9,5 @@
 };
 
 void testPR12271() { // expected-warning {{no previous prototype for function 'testPR12271'}}
-  PR12271 a[1][1]; // expected-warning {{unused variable 'a'}}
+  PR12271 a[1][1];
 }
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -1522,7 +1522,7 @@
   if (const VarDecl *VD = dyn_cast(D)) {
 
 // White-list anything with an __attribute__((unused)) type.
-QualType Ty = VD->getType();
+const auto *Ty = VD->getType().getTypePtr();
 
 // Only look at the outermost level of typedef.
 if (const TypedefType *TT = Ty->getAs()) {
@@ -1535,6 +1535,10 @@
 if (Ty->isIncompleteType() || Ty->isDependentType())
   return false;
 
+// Look at the element type to ensure that the warning behaviour is
+// consistent for both scalars and arrays.
+Ty = Ty->getBaseElementTypeUnsafe();
+
 if (const TagType *TT = Ty->getAs()) {
   const TagDecl *Tag = TT->getDecl();
   if (Tag->hasAttr())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://l

[PATCH] D25660: [Analyzer] Checker for iterators dereferenced beyond their range.

2016-10-26 Thread Balogh , Ádám via cfe-commits
baloghadamsoftware added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp:195
+auto Param = State->getLValue(P, LCtx);
+auto Arg = State->getSVal(CE->getArg(idx++), LCtx->getParent());
+const auto *Pos = getIteratorPosition(State, Arg);

NoQ wrote:
> I think this trick needs more comments/explaining. It is very unusual. Are 
> you trying to model effects of passing an iterator by value into a function? 
> What part of these effects are not modeled magically by the core?
If I pass an iterator by value (the most usual case) I have to assign its 
position (in or out of range) to the formal parameter from the actual one.



Comment at: lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp:568
+  // We also should check for copy assignment operator, but for some reason
+  // it is not provided implicitly in Clang Static Analyzer
+  for (const auto *M : CRD->methods()) {

NoQ wrote:
> It's not analyzer's fault :) We're inspecting the AST here.
> 
> Anyway, does `CXXRecordDecl::needsImplicitCopyAssignment()` look useful?
No, it does not. I need to check whether the type is copiable, since that is a 
criteria for being an operator (copiable via constructor and assignment, 
deleteable, incrementable and dereferencable). It seems that while copy 
constructor and destructor is generated automatically, copy assignment not, at 
least not in this simple case. So I defaulted it to true, and I set it to false 
if I find a deleted or a non-public copy assignment.



Comment at: test/Analysis/iterator-past-end.cpp:3
+
+template  struct __iterator {
+  typedef __iterator iterator;

NoQ wrote:
> We should probably separate this into an #include-able header in 
> `test/Analysis/Inputs/`.
> 
> Also, there's always a bit of concern that it wasn't copy-pasted from a 
> standard library implementation with an incompatible license such as (L)GPL. 
> Which often happens when you do your best to emulate the normal way of 
> defining things as closely as possible.
I did it now, but first one of my tests failed. I fixed the bug, but it turned 
out that if I include these types and functions, no method or function is 
checked, just conjured symbols are generated. Should including not behave the 
same as copying the contents? This happened even if I removed the pragma.


https://reviews.llvm.org/D25660



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


[PATCH] D22374: [analyzer] Copy and move constructors - ExprEngine extended for "almost trivial" copy and move constructors

2016-10-26 Thread Balogh , Ádám via cfe-commits
baloghadamsoftware added a comment.

In https://reviews.llvm.org/D22374#575579, @NoQ wrote:

> Ping!~ Did my idea sound completely wrong to you? :)
>
> Does https://reviews.llvm.org/D25660 depend on this patch? And/or did you 
> find another workaround?
>
> upd.: I also thought that this deserves more code comments - the purpose of 
> the new mechanism should be more obvious by reading the code.


Sorry, since it turned out that https://reviews.llvm.org/D25660 does not depend 
on this patch I downprioritized it.

By some mistake I missed the notification about your patch-over-patch. It seems 
OK to me.


https://reviews.llvm.org/D22374



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


[PATCH] D25989: Do not print include_next/pragma once warnings when input is a header.

2016-10-26 Thread Erik Verbruggen via cfe-commits
erikjv created this revision.
erikjv added a reviewer: bkramer.
erikjv added a subscriber: cfe-commits.

r276653 suppressed the pragma once warning when generating a PCH file.
This patch extends that to any main file for which clang is told (with
the -x option) that it's a header file. It will also suppress the
warning "#include_next in primary source file".


https://reviews.llvm.org/D25989

Files:
  include/clang/Basic/LangOptions.h
  lib/Basic/LangOptions.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PPMacroExpansion.cpp
  lib/Lex/Pragma.cpp
  test/Preprocessor/header_is_main_file.c

Index: test/Preprocessor/header_is_main_file.c
===
--- /dev/null
+++ test/Preprocessor/header_is_main_file.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -x c-header -ffreestanding -Eonly -verify %s
+// expected-no-diagnostics
+
+#pragma once
+#include_next "stdint.h"
+#if !__has_include_next("stdint.h")
+#error "__has_include_next failed"
+#endif
Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -372,8 +372,10 @@
 ///
 void Preprocessor::HandlePragmaOnce(Token &OnceTok) {
   // Don't honor the 'once' when handling the primary source file, unless
-  // this is a prefix to a TU, which indicates we're generating a PCH file.
-  if (isInPrimaryFile() && TUKind != TU_Prefix) {
+  // this is a prefix to a TU, which indicates we're generating a PCH file, or
+  // when the main file is a header (e.g. when -xc-header is provided on the
+  // commandline).
+  if (isInPrimaryFile() && TUKind != TU_Prefix && !getLangOpts().IsHeaderFile) {
 Diag(OnceTok, diag::pp_pragma_once_in_main_file);
 return;
   }
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -1421,7 +1421,11 @@
   // Preprocessor::HandleIncludeNextDirective.
   const DirectoryLookup *Lookup = PP.GetCurDirLookup();
   const FileEntry *LookupFromFile = nullptr;
-  if (PP.isInPrimaryFile()) {
+  if (PP.isInPrimaryFile() && PP.getLangOpts().IsHeaderFile) {
+// If the main file is a header, then it's either for PCH/AST generation,
+// or libclang opened it. Either way, handle it as a normal include below
+// and do not complain about __has_include_next.
+  } else if (PP.isInPrimaryFile()) {
 Lookup = nullptr;
 PP.Diag(Tok, diag::pp_include_next_in_primary);
   } else if (PP.getCurrentSubmodule()) {
Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -2058,7 +2058,11 @@
   // diagnostic.
   const DirectoryLookup *Lookup = CurDirLookup;
   const FileEntry *LookupFromFile = nullptr;
-  if (isInPrimaryFile()) {
+  if (isInPrimaryFile() && LangOpts.IsHeaderFile) {
+// If the main file is a header, then it's either for PCH/AST generation,
+// or libclang opened it. Either way, handle it as a normal include below
+// and do not complain about include_next.
+  } else if (isInPrimaryFile()) {
 Lookup = nullptr;
 Diag(IncludeNextTok, diag::pp_include_next_in_primary);
   } else if (CurSubmodule) {
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -,7 +,8 @@
 }
 
 static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
-   DiagnosticsEngine &Diags) {
+   DiagnosticsEngine &Diags,
+   bool &IsHeaderFile) {
   using namespace options;
   Opts.ProgramAction = frontend::ParseSyntaxOnly;
   if (const Arg *A = Args.getLastArg(OPT_Action_Group)) {
@@ -1358,6 +1359,13 @@
 if (DashX == IK_None)
   Diags.Report(diag::err_drv_invalid_value)
 << A->getAsString(Args) << A->getValue();
+IsHeaderFile = llvm::StringSwitch(A->getValue())
+  .Case("c-header", true)
+  .Case("cl-header", true)
+  .Case("objective-c-header", true)
+  .Case("c++-header", true)
+  .Case("objective-c++-header", true)
+  .Default(false);
   }
 
   // '-' is the default input if none is given.
@@ -2415,7 +2423,8 @@
   ParseCommentArgs(LangOpts.CommentOpts, Args);
   ParseFileSystemArgs(Res.getFileSystemOpts(), Args);
   // FIXME: We shouldn't have to pass the DashX option around here
-  InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), Args, Diags);
+  InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), Args, Diags,
+  LangOpts.IsHeaderFile);
   ParseTargetArgs(Res.getTargetOpts(), Args, Diags);
   Success &= ParseCodeGenArgs(Res.getCodeGenOpts(), Args, DashX, Diags,
   Res.getTargetOpts());
Index: 

[PATCH] D25990: Sema: do not warn about unused const vars if main file is a header

2016-10-26 Thread Erik Verbruggen via cfe-commits
erikjv created this revision.
erikjv added a reviewer: bkramer.
erikjv added a subscriber: cfe-commits.

If we pass a header to libclang, e.g. because it's open in an editor in
an IDE, warnings about unused const vars are not useful: other files
that include the header might use those constants. So when -x *-header
is passed as command-line option, suppress this warning.


https://reviews.llvm.org/D25990

Files:
  lib/Sema/Sema.cpp
  test/Sema/no-warn-unused-const-variables.c


Index: test/Sema/no-warn-unused-const-variables.c
===
--- /dev/null
+++ test/Sema/no-warn-unused-const-variables.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-const-variable -x c-header 
-ffreestanding -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-const-variable -x c++-header 
-ffreestanding -verify %s
+// expected-no-diagnostics
+static const int unused[] = { 2, 3, 5, 7, 11, 13 };
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -865,8 +865,11 @@
   Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
 << /*variable*/1 << DiagD->getDeclName();
 } else if (DiagD->getType().isConstQualified()) {
-  Diag(DiagD->getLocation(), diag::warn_unused_const_variable)
-  << DiagD->getDeclName();
+  const SourceManager &SM = SourceMgr;
+  if (SM.getMainFileID() != SM.getFileID(DiagD->getLocation())
+  || !PP.getLangOpts().IsHeaderFile)
+Diag(DiagD->getLocation(), diag::warn_unused_const_variable)
+<< DiagD->getDeclName();
 } else {
   Diag(DiagD->getLocation(), diag::warn_unused_variable)
   << DiagD->getDeclName();


Index: test/Sema/no-warn-unused-const-variables.c
===
--- /dev/null
+++ test/Sema/no-warn-unused-const-variables.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-const-variable -x c-header -ffreestanding -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-const-variable -x c++-header -ffreestanding -verify %s
+// expected-no-diagnostics
+static const int unused[] = { 2, 3, 5, 7, 11, 13 };
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -865,8 +865,11 @@
   Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
 << /*variable*/1 << DiagD->getDeclName();
 } else if (DiagD->getType().isConstQualified()) {
-  Diag(DiagD->getLocation(), diag::warn_unused_const_variable)
-  << DiagD->getDeclName();
+  const SourceManager &SM = SourceMgr;
+  if (SM.getMainFileID() != SM.getFileID(DiagD->getLocation())
+  || !PP.getLangOpts().IsHeaderFile)
+Diag(DiagD->getLocation(), diag::warn_unused_const_variable)
+<< DiagD->getDeclName();
 } else {
   Diag(DiagD->getLocation(), diag::warn_unused_variable)
   << DiagD->getDeclName();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25992: [RecursiveASTVisitor] Visit the implicit expression of a CXXDefaultArgExpr

2016-10-26 Thread Malcolm Parsons via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added reviewers: klimek, jdennett, alexfh.
malcolm.parsons added a subscriber: cfe-commits.

The matcher
varDecl(hasDescendant(

  callExpr(hasDeclaration(functionDecl(unless(isNoThrow()))

didn't match calls from default arguments because the expression
for a CXXDefaultArgExpr was not visited.


https://reviews.llvm.org/D25992

Files:
  include/clang/AST/RecursiveASTVisitor.h
  unittests/Tooling/RecursiveASTVisitorTest.cpp


Index: unittests/Tooling/RecursiveASTVisitorTest.cpp
===
--- unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -152,4 +152,21 @@
   "};\n"));
 }
 
+// Check to ensure that implicit default argument expressions are visited.
+class IntegerLiteralVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool VisitIntegerLiteral(const IntegerLiteral *IL) {
+Match("literal", IL->getLocation());
+return true;
+  }
+};
+
+TEST(RecursiveASTVisitor, DefaultArgumentsAreVisited) {
+  IntegerLiteralVisitor Visitor;
+  Visitor.ExpectMatch("literal", 1, 15, 2);
+  EXPECT_TRUE(Visitor.runOver("int f(int i = 1);\n"
+  "static int k = f();\n"));
+}
+
 } // end anonymous namespace
Index: include/clang/AST/RecursiveASTVisitor.h
===
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -2354,7 +2354,10 @@
 })
 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
-DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {})
+DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {
+  if (getDerived().shouldVisitImplicitCode())
+TRY_TO(TraverseStmt(S->getExpr()));
+})
 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
 DEF_TRAVERSE_STMT(ExprWithCleanups, {})


Index: unittests/Tooling/RecursiveASTVisitorTest.cpp
===
--- unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -152,4 +152,21 @@
   "};\n"));
 }
 
+// Check to ensure that implicit default argument expressions are visited.
+class IntegerLiteralVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool VisitIntegerLiteral(const IntegerLiteral *IL) {
+Match("literal", IL->getLocation());
+return true;
+  }
+};
+
+TEST(RecursiveASTVisitor, DefaultArgumentsAreVisited) {
+  IntegerLiteralVisitor Visitor;
+  Visitor.ExpectMatch("literal", 1, 15, 2);
+  EXPECT_TRUE(Visitor.runOver("int f(int i = 1);\n"
+  "static int k = f();\n"));
+}
+
 } // end anonymous namespace
Index: include/clang/AST/RecursiveASTVisitor.h
===
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -2354,7 +2354,10 @@
 })
 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
-DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {})
+DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {
+  if (getDerived().shouldVisitImplicitCode())
+TRY_TO(TraverseStmt(S->getExpr()));
+})
 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
 DEF_TRAVERSE_STMT(ExprWithCleanups, {})
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25993: [Objective-C] Add objc_subclassing_restricted attribute

2016-10-26 Thread Alex Lorenz via cfe-commits
arphaman created this revision.
arphaman added reviewers: aaron.ballman, jordan_rose.
arphaman added a subscriber: cfe-commits.
arphaman set the repository for this revision to rL LLVM.

This patch adds an `objc_subclassing_restricted` attribute into clang. This 
attribute acts similarly to 'final' - Objective-C classes with this attribute 
can't be subclassed. However, `@interface` declarations that have 
`objc_subclassing_restricted` but don't have `@implementation` are allowed to 
inherit other `@interface` declarations with `objc_subclassing_restricted`. 
This is needed to describe the Swift class hierarchy in clang while making sure 
that the Objective-C classes can't subclass the Swift classes.

This attribute is already implemented in a fork of clang that's used for Swift 
(https://github.com/apple/swift-clang) and this patch migrates that code to the 
upstream clang repository.


Repository:
  rL LLVM

https://reviews.llvm.org/D25993

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclObjC.cpp
  test/SemaObjC/subclassing-restricted-attr.m

Index: test/SemaObjC/subclassing-restricted-attr.m
===
--- /dev/null
+++ test/SemaObjC/subclassing-restricted-attr.m
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1  -fsyntax-only -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s
+// rdar://16560476
+
+__attribute__((objc_subclassing_restricted))
+@interface Leaf // okay
+@end
+
+__attribute__((objc_subclassing_restricted))
+@interface SubClassOfLeaf : Leaf // expected-note {{class is declared here}}
+@end
+
+
+@interface SubClass : SubClassOfLeaf // expected-error {{cannot subclass a class with objc_subclassing_restricted attribute}}
+@end
+
+__attribute__((objc_root_class))
+@interface PlainRoot
+@end
+
+__attribute__((objc_subclassing_restricted))
+@interface Sub2Class : PlainRoot // okay
+@end
+
+// rdar://28753587
+__attribute__((objc_subclassing_restricted))
+@interface SuperImplClass // expected-note {{class is declared here}}
+@end
+@implementation SuperImplClass
+@end
+
+__attribute__((objc_subclassing_restricted))
+@interface SubImplClass : SuperImplClass
+@end
+@implementation SubImplClass // expected-error {{cannot subclass a class with objc_subclassing_restricted attribute}}
+@end
Index: lib/Sema/SemaDeclObjC.cpp
===
--- lib/Sema/SemaDeclObjC.cpp
+++ lib/Sema/SemaDeclObjC.cpp
@@ -3853,6 +3853,18 @@
 Diag(IDecl->getLocation(), diag::err_objc_root_class_subclass);
   }
 
+  if (const ObjCInterfaceDecl *Super = IDecl->getSuperClass()) {
+// An interface can subclass another interface with a
+// objc_subclassing_restricted attribute when it has that attribute as
+// well (because of interfaces imported from Swift). Therefore we have
+// to check if we can subclass in the implementation as well.
+if (IDecl->hasAttr() &&
+Super->hasAttr()) {
+  Diag(IC->getLocation(), diag::err_restricted_superclass_mismatch);
+  Diag(Super->getLocation(), diag::note_class_declared);
+}
+  }
+
   if (LangOpts.ObjCRuntime.isNonFragile()) {
 while (IDecl->getSuperClass()) {
   DiagnoseDuplicateIvars(IDecl, IDecl->getSuperClass());
@@ -3873,6 +3885,15 @@
 ImplMethodsVsClassMethods(S, CatImplClass, Cat);
   }
 }
+  } else if (const ObjCInterfaceDecl *IntfDecl =
+ dyn_cast(ClassDecl)) {
+if (const ObjCInterfaceDecl *Super = IntfDecl->getSuperClass()) {
+  if (!IntfDecl->hasAttr() &&
+  Super->hasAttr()) {
+Diag(IntfDecl->getLocation(), diag::err_restricted_superclass_mismatch);
+Diag(Super->getLocation(), diag::note_class_declared);
+  }
+}
   }
   if (isInterfaceDeclKind) {
 // Reject invalid vardecls.
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5776,6 +5776,9 @@
   case AttributeList::AT_ObjCRootClass:
 handleSimpleAttribute(S, D, Attr);
 break;
+  case AttributeList::AT_ObjCSubclassingRestricted:
+handleSimpleAttribute(S, D, Attr);
+break;
   case AttributeList::AT_ObjCExplicitProtocolImpl:
 handleObjCSuppresProtocolAttr(S, D, Attr);
 break;
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -772,6 +772,8 @@
   "class with specified objc_requires_property_definitions attribute is declared here">;
 def err_objc_root_class_subclass : Error<
   "objc_root_class attribute may only be specified on a root class declaration">;
+def err_restricted_superclass_mismatch : Error<
+  "cannot

[PATCH] D25305: [OpenCL] Setting constant address space for array initializers

2016-10-26 Thread Alexey Sotkin via cfe-commits
AlexeySotkin updated this revision to Diff 75893.
AlexeySotkin added a comment.

Setting UnnamedAddr to Global


https://reviews.llvm.org/D25305

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGenOpenCL/private-array-initialization.cl


Index: test/CodeGenOpenCL/private-array-initialization.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/private-array-initialization.cl
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -O0 -emit-llvm -o - | 
FileCheck %s
+
+// CHECK: @test.arr = private addrspace(2) constant [3 x i32] [i32 1, i32 2, 
i32 3], align 4
+
+void test() {
+  __private int arr[] = {1, 2, 3};
+// CHECK:  %[[arr_i8_ptr:[0-9]+]] = bitcast [3 x i32]* %arr to i8*
+// CHECK:  call void @llvm.memcpy.p0i8.p2i8.i32(i8* %[[arr_i8_ptr]], i8 
addrspace(2)* bitcast ([3 x i32] addrspace(2)* @test.arr to i8 addrspace(2)*), 
i32 12, i32 4, i1 false)
+}
\ No newline at end of file
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -1266,10 +1266,16 @@
 // Otherwise, create a temporary global with the initializer then
 // memcpy from the global to the alloca.
 std::string Name = getStaticDeclName(CGM, D);
+unsigned AS = 0;
+if (getLangOpts().OpenCL) {
+  AS = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);
+  BP = llvm::PointerType::getInt8PtrTy(getLLVMContext(), AS);
+}
 llvm::GlobalVariable *GV =
   new llvm::GlobalVariable(CGM.getModule(), constant->getType(), true,
llvm::GlobalValue::PrivateLinkage,
-   constant, Name);
+   constant, Name, nullptr,
+   llvm::GlobalValue::NotThreadLocal, AS);
 GV->setAlignment(Loc.getAlignment().getQuantity());
 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 


Index: test/CodeGenOpenCL/private-array-initialization.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/private-array-initialization.cl
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -O0 -emit-llvm -o - | FileCheck %s
+
+// CHECK: @test.arr = private addrspace(2) constant [3 x i32] [i32 1, i32 2, i32 3], align 4
+
+void test() {
+  __private int arr[] = {1, 2, 3};
+// CHECK:  %[[arr_i8_ptr:[0-9]+]] = bitcast [3 x i32]* %arr to i8*
+// CHECK:  call void @llvm.memcpy.p0i8.p2i8.i32(i8* %[[arr_i8_ptr]], i8 addrspace(2)* bitcast ([3 x i32] addrspace(2)* @test.arr to i8 addrspace(2)*), i32 12, i32 4, i1 false)
+}
\ No newline at end of file
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -1266,10 +1266,16 @@
 // Otherwise, create a temporary global with the initializer then
 // memcpy from the global to the alloca.
 std::string Name = getStaticDeclName(CGM, D);
+unsigned AS = 0;
+if (getLangOpts().OpenCL) {
+  AS = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);
+  BP = llvm::PointerType::getInt8PtrTy(getLLVMContext(), AS);
+}
 llvm::GlobalVariable *GV =
   new llvm::GlobalVariable(CGM.getModule(), constant->getType(), true,
llvm::GlobalValue::PrivateLinkage,
-   constant, Name);
+   constant, Name, nullptr,
+   llvm::GlobalValue::NotThreadLocal, AS);
 GV->setAlignment(Loc.getAlignment().getQuantity());
 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25305: [OpenCL] Setting constant address space for array initializers

2016-10-26 Thread Alexey Sotkin via cfe-commits
AlexeySotkin added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1272
+if (getLangOpts().OpenCL) {
+  UA = llvm::GlobalValue::UnnamedAddr::None;
+  AS = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);

Anastasia wrote:
> AlexeySotkin wrote:
> > bader wrote:
> > > Anastasia wrote:
> > > > bader wrote:
> > > > > AlexeySotkin wrote:
> > > > > > Anastasia wrote:
> > > > > > > Why this change?
> > > > > > Without this change, global variables with unnamed address space 
> > > > > > are translated to SPIR-V as variables with "Function" storage 
> > > > > > class, which is wrong.
> > > > > > This should fix this issue: 
> > > > > > https://github.com/KhronosGroup/SPIRV-LLVM/issues/50
> > > > > There is inconsistency with how Clang maps initializers to OpenCL 
> > > > > memory model.
> > > > > Consider example from the test case:
> > > > > ```
> > > > > __private int arr[] = {1, 2, 3};
> > > > > ```
> > > > > This code allocates a global constant for initializer {1, 2, 3} and 
> > > > > later copies values from this global constant to the private array 
> > > > > using memcpy intrinsic. The global constant must be allocated in 
> > > > > constant address space, but old code do assign any address space, 
> > > > > which is considered to be a private memory region.
> > > > > This patch puts global constant objects to constant address space.
> > > > Yes, this is perfectly fine. I was specifically asking about setting 
> > > > llvm::GlobalValue::UnnamedAddr::None attribute. I can't see why this 
> > > > has to be done or is it because we now assign concrete address space 
> > > > and private was treated as no address space at all?
> > > This attribute has nothing to do with address spaces.
> > > See http://llvm.org/docs/LangRef.html#global-variables for 
> > > local_unnamed_addr and unnamed_addr attributes description.
> > > My understanding is that llvm::GlobalValue::UnnamedAddr::Global should be 
> > > fine here.
> > llvm::GlobalValue::UnnamedAddr::None is default value of UnnamedAddr for 
> > GlobalValue. This line can be removed, but extra "if" statement must be 
> > added before GV->setUnnamedAddr(UA);
> Yes, I also think that leaving global should be fine here. So could we just 
> undo the change to line 1274?
Changed to Global


https://reviews.llvm.org/D25305



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


[PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-10-26 Thread Nico Weber via cfe-commits
thakis added a comment.

Erik, are you planning on adding the later phases soon? At the moment, due to 
this patch, clang emits "enclose 'setAllowsAutomaticWindowTabbing:' in an 
@available check to silence this warning" but then errors out when trying to 
use @available. This is proving to be confusing to folks :-)


Repository:
  rL LLVM

https://reviews.llvm.org/D23003



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


r285206 - [CMake] Adding example distribution CMake cache files

2016-10-26 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Wed Oct 26 10:41:38 2016
New Revision: 285206

URL: http://llvm.org/viewvc/llvm-project?rev=285206&view=rev
Log:
[CMake] Adding example distribution CMake cache files

These cache file are provided as an example of how to set up simple multi-stage 
CMake builds. I have a batch of documentation updates for LLVM.org which 
reference these files.

Added:
cfe/trunk/cmake/caches/DistributionExample-stage2.cmake
cfe/trunk/cmake/caches/DistributionExample.cmake

Added: cfe/trunk/cmake/caches/DistributionExample-stage2.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/DistributionExample-stage2.cmake?rev=285206&view=auto
==
--- cfe/trunk/cmake/caches/DistributionExample-stage2.cmake (added)
+++ cfe/trunk/cmake/caches/DistributionExample-stage2.cmake Wed Oct 26 10:41:38 
2016
@@ -0,0 +1,30 @@
+# This file sets up a CMakeCache for the second stage of a simple distribution
+# bootstrap build.
+
+set(LLVM_TARGETS_TO_BUILD X86;ARM;AArch64 CACHE STRING "")
+
+set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
+
+# setup toolchain
+set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
+set(LLVM_TOOLCHAIN_TOOLS
+  llvm-dsymutil
+  llvm-cov
+  llvm-dwarfdump
+  llvm-profdata
+  llvm-objdump
+  llvm-nm
+  llvm-size
+  CACHE STRING "")
+
+set(LLVM_DISTRIBUTION_COMPONENTS
+  clang
+  LTO
+  clang-format
+  clang-headers
+  builtins
+  runtimes
+  ${LLVM_TOOLCHAIN_TOOLS}
+  CACHE STRING "")

Added: cfe/trunk/cmake/caches/DistributionExample.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/DistributionExample.cmake?rev=285206&view=auto
==
--- cfe/trunk/cmake/caches/DistributionExample.cmake (added)
+++ cfe/trunk/cmake/caches/DistributionExample.cmake Wed Oct 26 10:41:38 2016
@@ -0,0 +1,34 @@
+# This file sets up a CMakeCache for a simple distribution bootstrap build.
+
+# Only build the native target in stage1 since it is a throwaway build.
+set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
+
+# Optimize the stage1 compiler, but don't LTO it because that wastes time.
+set(CMAKE_BUILD_TYPE Release CACHE STRING "")
+
+# Setup vendor-specific settings.
+set(PACKAGE_VENDOR LLVM.org CACHE STRING "")
+
+# Setting up the stage2 LTO option needs to be done on the stage1 build so that
+# the proper LTO library dependencies can be connected.
+set(BOOTSTRAP_LLVM_ENABLE_LTO ON CACHE BOOL "")
+
+# Expose stage2 targets through the stage1 build configuration.
+set(CLANG_BOOTSTRAP_TARGETS
+  check-all
+  check-llvm
+  check-clang
+  llvm-config
+  test-suite
+  test-depends
+  llvm-test-depends
+  clang-test-depends
+  distribution
+  install-distribution
+  clang CACHE STRING "")
+
+# Setup the bootstrap build.
+set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
+set(CLANG_BOOTSTRAP_CMAKE_ARGS
+  -C ${CMAKE_CURRENT_LIST_DIR}/DistributionExample-stage2.cmake
+  CACHE STRING "")


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


Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-10-26 Thread Erik Pilkington via cfe-commits
Hi Nico,
All that is left for the diagnostic to make sense it CodeGen support for 
@available, which is something I’m working on now. I should have a patch up for 
it in a couple days. I suppose it was a mistake to mention upgrading to 
something that doesn’t work yet, if this is an inconvenience for you I would be 
happy to temporarily remove that note!

Thanks for pinging, and sorry for any confusion that I caused,
Erik

> On Oct 26, 2016, at 11:44 AM, Nico Weber  wrote:
> 
> thakis added a comment.
> 
> Erik, are you planning on adding the later phases soon? At the moment, due to 
> this patch, clang emits "enclose 'setAllowsAutomaticWindowTabbing:' in an 
> @available check to silence this warning" but then errors out when trying to 
> use @available. This is proving to be confusing to folks :-)
> 
> 
> Repository:
>  rL LLVM
> 
> https://reviews.llvm.org/D23003
> 
> 
> 

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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread Erich Keane via cfe-commits
erichkeane updated this revision to Diff 75903.
erichkeane added a comment.

Corrected Decoration settings to match the soon-to-be-updated spec.


https://reviews.llvm.org/D25204

Files:
  include/clang-c/Index.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  lib/AST/Expr.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/Mangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/regcall.c
  test/CodeGenCXX/regcall.cpp
  tools/libclang/CXType.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -605,6 +605,7 @@
 case tok::kw___fastcall:
 case tok::kw___stdcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___cdecl:
 case tok::kw___vectorcall:
 case tok::kw___ptr64:
@@ -3137,6 +3138,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   ParseMicrosoftTypeAttributes(DS.getAttributes());
   continue;
@@ -4454,6 +4456,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___ptr64:
@@ -4638,6 +4641,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
@@ -4876,6 +4880,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   if (AttrReqs & AR_DeclspecAttributesParsed) {
 ParseMicrosoftTypeAttributes(DS.getAttributes());
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -909,7 +909,7 @@
   // '(' abstract-declarator ')'
   if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
   tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
-  tok::kw___vectorcall))
+  tok::kw___regcall, tok::kw___vectorcall))
 return TPResult::True; // attributes indicate declaration
   TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
   if (TPR != TPResult::Ambiguous)
@@ -1058,6 +1058,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___unaligned:
   case tok::kw___vector:
@@ -1351,6 +1352,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -673,7 +673,16 @@
   } else {
 IdentifierInfo *II = ND->getIdentifier();
 assert(II && "Attempt to mangle unnamed decl.");
-Str = II->getName();
+const auto *FD = dyn_cast(ND);
+
+if (FD &&
+FD->getType()->castAs()->getCallConv() == CC_X86RegCall) {
+  llvm::raw_svector_ostream Out(Buffer);
+  Out << "__regcall3__" << II->getName();
+  Str = Out.str();
+} else {
+  Str = II->getName();
+}
   }
 
   // Keep the first result in the case of a mangling collision.
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -48,6 +48,7 @@
   default: return llvm::CallingConv::C;
   case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
   case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
+  case CC_X86RegCall: return llvm::CallingConv::X86_RegCall;
   case CC_X86ThisCall: return llvm::CallingConv::X86_ThisCall;
   case CC_X86_64Win64: return llvm::CallingConv::X86_64_Win64;
   case CC_X86_64SysV: return llvm::CallingConv::X86_64_SysV;
@@ -173,6 +174,9 @@
   if (D->hasAttr())
 return CC_X86FastCall;
 
+  if (D->hasAttr())
+return CC_X86RegCall;
+
   if (D->hasAttr())
 return CC_X86ThisCall;
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -904,6 +904,7 @@
   case CC_Swift:
   case CC_PreserveMost:
   case CC_PreserveAll:
+ 

[PATCH] D25995: Add documentation for transparent_union attribute

2016-10-26 Thread Alex Lorenz via cfe-commits
arphaman created this revision.
arphaman added a reviewer: aaron.ballman.
arphaman added a subscriber: cfe-commits.
arphaman set the repository for this revision to rL LLVM.

This patch adds a bit of documentation for the `transparent_union` attribute.


Repository:
  rL LLVM

https://reviews.llvm.org/D25995

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td


Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -2649,3 +2649,21 @@
 If a function has neither of these attributes, they become subject to the XRay 
heuristics used to determine whether a function should be instrumented or 
otherwise.
   }];
 }
+
+def TransparentUnionDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute can be applied to a union to change the behaviour of calls to
+functions that have an argument with a transparent union type. The compiler
+behaviour is changed in the following manner:
+
+- A value whose type is any member of the transparent union can be passed as an
+argument without the need to cast that value.
+
+- The argument is passed to the function using the calling convention of the
+first member of the transparent union. Consequently, all the members of the
+transparent union should have the same calling convention as its first member.
+
+Transparent unions are not supported in C++.
+  }];
+}
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -1542,7 +1542,7 @@
 def TransparentUnion : InheritableAttr {
   let Spellings = [GCC<"transparent_union">];
 //  let Subjects = SubjectList<[Record, TypedefName]>;
-  let Documentation = [Undocumented];
+  let Documentation = [TransparentUnionDocs];
   let LangOpts = [COnly];
 }
 


Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -2649,3 +2649,21 @@
 If a function has neither of these attributes, they become subject to the XRay heuristics used to determine whether a function should be instrumented or otherwise.
   }];
 }
+
+def TransparentUnionDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute can be applied to a union to change the behaviour of calls to
+functions that have an argument with a transparent union type. The compiler
+behaviour is changed in the following manner:
+
+- A value whose type is any member of the transparent union can be passed as an
+argument without the need to cast that value.
+
+- The argument is passed to the function using the calling convention of the
+first member of the transparent union. Consequently, all the members of the
+transparent union should have the same calling convention as its first member.
+
+Transparent unions are not supported in C++.
+  }];
+}
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -1542,7 +1542,7 @@
 def TransparentUnion : InheritableAttr {
   let Spellings = [GCC<"transparent_union">];
 //  let Subjects = SubjectList<[Record, TypedefName]>;
-  let Documentation = [Undocumented];
+  let Documentation = [TransparentUnionDocs];
   let LangOpts = [COnly];
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread Erich Keane via cfe-commits
erichkeane added a comment.

After much debate, the architects have agreed to change the "Decoration" 
section to the following.

The next patch does these, so I'm ready for continued review.  Thanks for your 
patience!
-Erich

__regcall Decoration
Names of functions that use __regcall are decorated. This helps avoid improper 
linking with a function using a different calling convention.
The name of a C function is prefixed with __regcalln__. For example, the name 
foo would be decorated as follows: __regcall3__foo. The n part of the 
decoration specifies the version of the __regcall convention in effect (the 
current convention revision number is 3). In a GCC compatibility environment, 
this decoration is also done for a C++ function or template function whose 
function or template name is an identifier (excluding constructors and operator 
functions, for example); this happens before C++ name mangling.
In a Microsoft compatibility environment, C++ name mangling uses the (lower 
case) letter w to encode revision 3 of the __regcall calling convention.


https://reviews.llvm.org/D25204



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


[PATCH] D25920: AMDGPU: Add missing ISA versions gfx7.x.x and 8.x.x.

2016-10-26 Thread Tom Stellard via cfe-commits
tstellarAMD added a comment.

LGTM.


https://reviews.llvm.org/D25920



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


[PATCH] D24991: Inline hot functions in libcxx shared_ptr implementation.

2016-10-26 Thread Sebastian Pop via cfe-commits
sebpop removed rL LLVM as the repository for this revision.
sebpop updated this revision to Diff 75908.
sebpop added a comment.

The patch also implements the idea that Marshall proposed in:
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20161010/173780.html

> I have an idea; it involves a macro that is sometimes "inline" and
>  sometimes not, and changes when you're building the library vs. when you're
>  just including the headers.

Tested on x86_64-linux.
The symbols for the functions that are now inlined still appear in the 
libc++.so.

Ok to commit?


https://reviews.llvm.org/D24991

Files:
  libcxx/include/__atomic_support
  libcxx/include/memory
  libcxx/src/include/atomic_support.h
  libcxx/src/memory.cpp
  libcxx/src/mutex.cpp

Index: libcxx/src/mutex.cpp
===
--- libcxx/src/mutex.cpp
+++ libcxx/src/mutex.cpp
@@ -12,7 +12,7 @@
 #include "limits"
 #include "system_error"
 #include "cassert"
-#include "include/atomic_support.h"
+#include "__atomic_support"
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 #ifndef _LIBCPP_HAS_NO_THREADS
Index: libcxx/src/memory.cpp
===
--- libcxx/src/memory.cpp
+++ libcxx/src/memory.cpp
@@ -13,32 +13,10 @@
 #include "mutex"
 #include "thread"
 #endif
-#include "include/atomic_support.h"
+#include "__atomic_support"
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-namespace
-{
-
-// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
-// should be sufficient for thread safety.
-// See https://llvm.org/bugs/show_bug.cgi?id=22803
-template 
-inline T
-increment(T& t) _NOEXCEPT
-{
-return __libcpp_atomic_add(&t, 1, _AO_Relaxed);
-}
-
-template 
-inline T
-decrement(T& t) _NOEXCEPT
-{
-return __libcpp_atomic_add(&t, -1, _AO_Acq_Rel);
-}
-
-}  // namespace
-
 const allocator_arg_t allocator_arg = allocator_arg_t();
 
 bad_weak_ptr::~bad_weak_ptr() _NOEXCEPT {}
@@ -53,27 +31,27 @@
 {
 }
 
+__shared_weak_count::~__shared_weak_count()
+{
+}
+
 void
 __shared_count::__add_shared() _NOEXCEPT
 {
-increment(__shared_owners_);
+__atomic_inc_dec::increment(__shared_owners_);
 }
 
 bool
 __shared_count::__release_shared() _NOEXCEPT
 {
-if (decrement(__shared_owners_) == -1)
+if (__atomic_inc_dec::decrement(__shared_owners_) == -1)
 {
 __on_zero_shared();
 return true;
 }
 return false;
 }
 
-__shared_weak_count::~__shared_weak_count()
-{
-}
-
 void
 __shared_weak_count::__add_shared() _NOEXCEPT
 {
@@ -83,7 +61,7 @@
 void
 __shared_weak_count::__add_weak() _NOEXCEPT
 {
-increment(__shared_weak_owners_);
+__atomic_inc_dec::increment(__shared_weak_owners_);
 }
 
 void
@@ -124,7 +102,7 @@
 //__libcpp_atomic_store(&__shared_weak_owners_, -1, _AO_Release);
 __on_zero_shared_weak();
 }
-else if (decrement(__shared_weak_owners_) == -1)
+else if (__atomic_inc_dec::decrement(__shared_weak_owners_) == -1)
 __on_zero_shared_weak();
 }
 
Index: libcxx/src/include/atomic_support.h
===
--- libcxx/src/include/atomic_support.h
+++ /dev/null
@@ -1,158 +0,0 @@
-//===--===
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===--===
-
-#ifndef ATOMIC_SUPPORT_H
-#define ATOMIC_SUPPORT_H
-
-#include "__config"
-#include "memory" // for __libcpp_relaxed_load
-
-#if defined(__clang__) && __has_builtin(__atomic_load_n) \
-   && __has_builtin(__atomic_store_n)\
-   && __has_builtin(__atomic_add_fetch)  \
-   && __has_builtin(__atomic_compare_exchange_n) \
-   && defined(__ATOMIC_RELAXED)  \
-   && defined(__ATOMIC_CONSUME)  \
-   && defined(__ATOMIC_ACQUIRE)  \
-   && defined(__ATOMIC_RELEASE)  \
-   && defined(__ATOMIC_ACQ_REL)  \
-   && defined(__ATOMIC_SEQ_CST)
-#   define _LIBCPP_HAS_ATOMIC_BUILTINS
-#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
-#   define _LIBCPP_HAS_ATOMIC_BUILTINS
-#endif
-
-#if !defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && !defined(_LIBCPP_HAS_NO_THREADS)
-# if defined(_MSC_VER) && !defined(__clang__)
-_LIBCPP_WARNING("Building libc++ without __atomic builtins is unsupported")
-# else
-#   warning Building libc++ without __atomic builtins is unsupported
-# endif
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-namespace {
-
-#if defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && !defined(_LIBCPP_HAS_NO_THREADS)
-
-enum _

[PATCH] D24991: Inline hot functions in libcxx shared_ptr implementation.

2016-10-26 Thread Sebastian Pop via cfe-commits
sebpop marked 2 inline comments as done.
sebpop added inline comments.



Comment at: libcxx/include/memory:3802
+{
+  return __libcpp_atomic_add(&t, 1, _AO_Relaxed);
+}

EricWF wrote:
> Why add `increment` and `decrement` at all? Just manually inline 
> `__libcpp_atomic_add` at the callsites.
I like the idea to manually inline the inc and dec functions.
What should we do with the NOTE: above?

// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
// should be sufficient for thread safety.
// See https://llvm.org/bugs/show_bug.cgi?id=22803

should we just go ahead and remove the note, or you want to have it where 
inc/dec are called?  (about a dozen places.) 


https://reviews.llvm.org/D24991



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


[PATCH] D25920: AMDGPU: Add missing ISA versions gfx7.x.x and 8.x.x.

2016-10-26 Thread Yaxun Liu via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285211: AMDGPU: Add missing ISA versions gfx7.x.x and 8.x.x. 
(authored by yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D25920?vs=75627&id=75912#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25920

Files:
  cfe/trunk/lib/Basic/Targets.cpp


Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -2176,13 +2176,22 @@
   .Case("kaveri",GK_GFX7)
   .Case("hawaii",GK_GFX7)
   .Case("mullins",   GK_GFX7)
+  .Case("gfx700",GK_GFX7)
+  .Case("gfx701",GK_GFX7)
+  .Case("gfx702",GK_GFX7)
   .Case("tonga", GK_GFX8)
   .Case("iceland",   GK_GFX8)
   .Case("carrizo",   GK_GFX8)
   .Case("fiji",  GK_GFX8)
   .Case("stoney",GK_GFX8)
   .Case("polaris10", GK_GFX8)
   .Case("polaris11", GK_GFX8)
+  .Case("gfx800",GK_GFX8)
+  .Case("gfx801",GK_GFX8)
+  .Case("gfx802",GK_GFX8)
+  .Case("gfx803",GK_GFX8)
+  .Case("gfx804",GK_GFX8)
+  .Case("gfx810",GK_GFX8)
   .Default(GK_NONE);
   }
 


Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -2176,13 +2176,22 @@
   .Case("kaveri",GK_GFX7)
   .Case("hawaii",GK_GFX7)
   .Case("mullins",   GK_GFX7)
+  .Case("gfx700",GK_GFX7)
+  .Case("gfx701",GK_GFX7)
+  .Case("gfx702",GK_GFX7)
   .Case("tonga", GK_GFX8)
   .Case("iceland",   GK_GFX8)
   .Case("carrizo",   GK_GFX8)
   .Case("fiji",  GK_GFX8)
   .Case("stoney",GK_GFX8)
   .Case("polaris10", GK_GFX8)
   .Case("polaris11", GK_GFX8)
+  .Case("gfx800",GK_GFX8)
+  .Case("gfx801",GK_GFX8)
+  .Case("gfx802",GK_GFX8)
+  .Case("gfx803",GK_GFX8)
+  .Case("gfx804",GK_GFX8)
+  .Case("gfx810",GK_GFX8)
   .Default(GK_NONE);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r285211 - AMDGPU: Add missing ISA versions gfx7.x.x and 8.x.x.

2016-10-26 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Wed Oct 26 11:40:21 2016
New Revision: 285211

URL: http://llvm.org/viewvc/llvm-project?rev=285211&view=rev
Log:
AMDGPU: Add missing ISA versions gfx7.x.x and 8.x.x.

Patch by Laurent Morichetti.

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

Modified:
cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=285211&r1=285210&r2=285211&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Oct 26 11:40:21 2016
@@ -2176,6 +2176,9 @@ public:
   .Case("kaveri",GK_GFX7)
   .Case("hawaii",GK_GFX7)
   .Case("mullins",   GK_GFX7)
+  .Case("gfx700",GK_GFX7)
+  .Case("gfx701",GK_GFX7)
+  .Case("gfx702",GK_GFX7)
   .Case("tonga", GK_GFX8)
   .Case("iceland",   GK_GFX8)
   .Case("carrizo",   GK_GFX8)
@@ -2183,6 +2186,12 @@ public:
   .Case("stoney",GK_GFX8)
   .Case("polaris10", GK_GFX8)
   .Case("polaris11", GK_GFX8)
+  .Case("gfx800",GK_GFX8)
+  .Case("gfx801",GK_GFX8)
+  .Case("gfx802",GK_GFX8)
+  .Case("gfx803",GK_GFX8)
+  .Case("gfx804",GK_GFX8)
+  .Case("gfx810",GK_GFX8)
   .Default(GK_NONE);
   }
 


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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread Reid Kleckner via cfe-commits
rnk added inline comments.



Comment at: include/clang/Basic/AttrDocs.td:1263
+On x86 targets, this attribute changes the calling convention to
+__regcall convention. This convention aims to pass as many arguments
+as possible in registers. It also tries to utilize registers for the

If you want `__regcall` to appear as a link, you want to put backticks and 
around it and underscore after it, like is done for __fastcall above:
  `__regcall`_



Comment at: include/clang/Basic/AttrDocs.td:1265
+as possible in registers. It also tries to utilize registers for the
+return value whenever it is possible.'
+

I don't think you need this trailing single quote.



Comment at: lib/AST/MicrosoftMangle.cpp:2006
   //  ::= J # __export __fastcall
   //  ::= Q # __vectorcall
   // The 'export' calling conventions are from a bygone era

Update the EBNF comment



Comment at: lib/CodeGen/TargetInfo.cpp:3324
+  for (const auto *FD : RT->getDecl()->fields()) {
+if (FD->getType()->isStructureType()) {
+  if (classifyRegCallStructTypeImpl(FD->getType(), NeededInt, NeededSSE)

This will return false for class fields, which I don't think you want. You 
probably want to do this for record types that aren't unions.



Comment at: lib/CodeGen/TargetInfo.cpp:3396
 
-unsigned neededInt, neededSSE;
-it->info = classifyArgumentType(it->type, freeIntRegs, neededInt,
-neededSSE, IsNamedArg);
+if (IsRegCall && it->type->isStructureType())
+  it->info = classifyRegCallStructType(it->type, NeededInt, NeededSSE);

You probably wanted isRecordType().


https://reviews.llvm.org/D25204



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


[PATCH] D25993: [Objective-C] Add objc_subclassing_restricted attribute

2016-10-26 Thread Jordan Rose via cfe-commits
jordan_rose added a comment.

Looks good from my end.


Repository:
  rL LLVM

https://reviews.llvm.org/D25993



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


[PATCH] D25937: [Sema] -Wunused-variable warning for variables with array types should behave similarly to variables with scalar types

2016-10-26 Thread John McCall via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Please add a line testing the nested-array case to warn-unused-variables.cpp, 
but with that, LGTM.


Repository:
  rL LLVM

https://reviews.llvm.org/D25937



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


[PATCH] D25624: Added 'inline' attribute to basic_string's destructor

2016-10-26 Thread Aditya Kumar via cfe-commits
hiraditya updated this revision to Diff 75915.
hiraditya added a comment.

Added macro to keep the definition of destructor of basic_string in string.cpp


https://reviews.llvm.org/D25624

Files:
  libcxx/include/string
  libcxx/src/string.cpp


Index: libcxx/src/string.cpp
===
--- libcxx/src/string.cpp
+++ libcxx/src/string.cpp
@@ -7,6 +7,8 @@
 //
 
//===--===//
 
+#define _LIBCPP_HEADER_INLINE_VISIBILITY
+
 #include "string"
 #include "cstdlib"
 #include "cwchar"
Index: libcxx/include/string
===
--- libcxx/include/string
+++ libcxx/include/string
@@ -11,6 +11,10 @@
 #ifndef _LIBCPP_STRING
 #define _LIBCPP_STRING
 
+#ifndef _LIBCPP_HEADER_INLINE_VISIBILITY
+#define _LIBCPP_HEADER_INLINE_VISIBILITY _LIBCPP_INLINE_VISIBILITY
+#endif
+
 /*
 string synopsis
 
@@ -1834,6 +1838,7 @@
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 template 
+inline _LIBCPP_HEADER_INLINE_VISIBILITY
 basic_string<_CharT, _Traits, _Allocator>::~basic_string()
 {
 #if _LIBCPP_DEBUG_LEVEL >= 2


Index: libcxx/src/string.cpp
===
--- libcxx/src/string.cpp
+++ libcxx/src/string.cpp
@@ -7,6 +7,8 @@
 //
 //===--===//
 
+#define _LIBCPP_HEADER_INLINE_VISIBILITY
+
 #include "string"
 #include "cstdlib"
 #include "cwchar"
Index: libcxx/include/string
===
--- libcxx/include/string
+++ libcxx/include/string
@@ -11,6 +11,10 @@
 #ifndef _LIBCPP_STRING
 #define _LIBCPP_STRING
 
+#ifndef _LIBCPP_HEADER_INLINE_VISIBILITY
+#define _LIBCPP_HEADER_INLINE_VISIBILITY _LIBCPP_INLINE_VISIBILITY
+#endif
+
 /*
 string synopsis
 
@@ -1834,6 +1838,7 @@
 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
 
 template 
+inline _LIBCPP_HEADER_INLINE_VISIBILITY
 basic_string<_CharT, _Traits, _Allocator>::~basic_string()
 {
 #if _LIBCPP_DEBUG_LEVEL >= 2
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25305: [OpenCL] Setting constant address space for array initializers

2016-10-26 Thread Anastasia Stulova via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.

LGTM! Thanks!


https://reviews.llvm.org/D25305



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


Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-10-26 Thread Nico Weber via cfe-commits
If you're working on it, let's just wait for that :-)

On Wed, Oct 26, 2016 at 12:01 PM, Erik Pilkington  wrote:

> Hi Nico,
> All that is left for the diagnostic to make sense it CodeGen support for
> @available, which is something I’m working on now. I should have a patch up
> for it in a couple days. I suppose it was a mistake to mention upgrading to
> something that doesn’t work yet, if this is an inconvenience for you I
> would be happy to temporarily remove that note!
>
> Thanks for pinging, and sorry for any confusion that I caused,
> Erik
>
> > On Oct 26, 2016, at 11:44 AM, Nico Weber  wrote:
> >
> > thakis added a comment.
> >
> > Erik, are you planning on adding the later phases soon? At the moment,
> due to this patch, clang emits "enclose 'setAllowsAutomaticWindowTabbing:'
> in an @available check to silence this warning" but then errors out when
> trying to use @available. This is proving to be confusing to folks :-)
> >
> >
> > Repository:
> >  rL LLVM
> >
> > https://reviews.llvm.org/D23003
> >
> >
> >
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25993: [Objective-C] Add objc_subclassing_restricted attribute

2016-10-26 Thread Manman Ren via cfe-commits
manmanren accepted this revision.
manmanren added a reviewer: manmanren.
manmanren added a comment.
This revision is now accepted and ready to land.

LGTM.

Manman


Repository:
  rL LLVM

https://reviews.llvm.org/D25993



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


[libcxx] r285213 - Silence unused parameter warnings in archetypes.hpp

2016-10-26 Thread Casey Carter via cfe-commits
Author: caseycarter
Date: Wed Oct 26 12:22:25 2016
New Revision: 285213

URL: http://llvm.org/viewvc/llvm-project?rev=285213&view=rev
Log:
Silence unused parameter warnings in archetypes.hpp
Reviewed at: https://reviews.llvm.org/D25958


Modified:
libcxx/trunk/test/support/archetypes.hpp

Modified: libcxx/trunk/test/support/archetypes.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/archetypes.hpp?rev=285213&r1=285212&r2=285213&view=diff
==
--- libcxx/trunk/test/support/archetypes.hpp (original)
+++ libcxx/trunk/test/support/archetypes.hpp Wed Oct 26 12:22:25 2016
@@ -68,12 +68,12 @@ struct TestBase {
 ++alive; ++constructed; ++value_constructed;
 }
 template ::type = true>
-explicit TestBase(std::initializer_list& il, int y = 0) noexcept
+explicit TestBase(std::initializer_list& il, int = 0) noexcept
   : value(il.size()) {
 ++alive; ++constructed; ++value_constructed;
 }
 template ::type = true>
-explicit TestBase(std::initializer_list& il, int y = 0) noexcept : 
value(il.size()) {
+explicit TestBase(std::initializer_list& il, int = 0) noexcept : 
value(il.size()) {
 ++alive; ++constructed; ++value_constructed;
 }
 TestBase& operator=(int xvalue) noexcept {
@@ -135,9 +135,9 @@ struct ValueBase {
 template ::type = true>
 constexpr ValueBase(int, int y) : value(y) {}
 template ::type = true>
-explicit constexpr ValueBase(std::initializer_list& il, int y = 0) : 
value(il.size()) {}
+explicit constexpr ValueBase(std::initializer_list& il, int = 0) : 
value(il.size()) {}
 template ::type = true>
-constexpr ValueBase(std::initializer_list& il, int y = 0) : 
value(il.size()) {}
+constexpr ValueBase(std::initializer_list& il, int = 0) : 
value(il.size()) {}
 TEST_CONSTEXPR_CXX14 ValueBase& operator=(int xvalue) noexcept {
 value = xvalue;
 return *this;
@@ -193,9 +193,9 @@ struct TrivialValueBase {
 template ::type = true>
 constexpr TrivialValueBase(int, int y) : value(y) {}
 template ::type = true>
-explicit constexpr TrivialValueBase(std::initializer_list& il, int y 
= 0) : value(il.size()) {}
+explicit constexpr TrivialValueBase(std::initializer_list& il, int = 
0) : value(il.size()) {}
 template ::type = true>
-constexpr TrivialValueBase(std::initializer_list& il, int y = 0) : 
value(il.size()) {};
+constexpr TrivialValueBase(std::initializer_list& il, int = 0) : 
value(il.size()) {};
 int value;
 protected:
 constexpr TrivialValueBase() noexcept : value(0) {}


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


[PATCH] D25993: [Objective-C] Add objc_subclassing_restricted attribute

2016-10-26 Thread Aaron Ballman via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added inline comments.
This revision now requires changes to proceed.



Comment at: include/clang/Basic/Attr.td:1291
+  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
+  let Documentation = [Undocumented];
+}

No new undocumented attributes, please.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:776
+def err_restricted_superclass_mismatch : Error<
+  "cannot subclass a class with objc_subclassing_restricted attribute">;
 def warn_objc_root_class_missing : Warning<

Please quote the attribute name in the diagnostic; also, this reads a bit 
strangely. Perhaps: `cannot subclass a class that was declared with the 
'objc_subclassing_restricted' attribute`?



Comment at: lib/Sema/SemaDeclObjC.cpp:3888
 }
+  } else if (const ObjCInterfaceDecl *IntfDecl =
+ dyn_cast(ClassDecl)) {

Can use `auto` here.


Repository:
  rL LLVM

https://reviews.llvm.org/D25993



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread David Majnemer via cfe-commits
majnemer added inline comments.



Comment at: lib/AST/MicrosoftMangle.cpp:433
   Out << Prefix;
+
   mangleName(D);

Please remove this stray newline.



Comment at: lib/CodeGen/TargetInfo.cpp:
+  if (classifyArgumentType(FD->getType(),
+   std::numeric_limits::max(),
+   LocalNeededInt, LocalNeededSSE, true)

I think UINT_MAX is more popular than using `std::numeric_limits` for this 
purpose in LLVM/Clang.



Comment at: lib/CodeGen/TargetInfo.cpp:3337-3338
+NeededInt = NeededSSE = 0;
+return getIndirectReturnResult(Ty);
+  } else {
+NeededInt += LocalNeededInt;

Please avoid else after return: 
http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread Erich Keane via cfe-commits
erichkeane marked 8 inline comments as done.
erichkeane added a comment.

New diff coming that fixes Reid & David's comments


https://reviews.llvm.org/D25204



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


[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread Erich Keane via cfe-commits
erichkeane updated this revision to Diff 75919.

https://reviews.llvm.org/D25204

Files:
  include/clang-c/Index.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  lib/AST/Expr.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/Mangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/regcall.c
  test/CodeGenCXX/regcall.cpp
  tools/libclang/CXType.cpp

Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -605,6 +605,7 @@
 case tok::kw___fastcall:
 case tok::kw___stdcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___cdecl:
 case tok::kw___vectorcall:
 case tok::kw___ptr64:
@@ -3137,6 +3138,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   ParseMicrosoftTypeAttributes(DS.getAttributes());
   continue;
@@ -4454,6 +4456,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___ptr64:
@@ -4638,6 +4641,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
@@ -4876,6 +4880,7 @@
 case tok::kw___stdcall:
 case tok::kw___fastcall:
 case tok::kw___thiscall:
+case tok::kw___regcall:
 case tok::kw___vectorcall:
   if (AttrReqs & AR_DeclspecAttributesParsed) {
 ParseMicrosoftTypeAttributes(DS.getAttributes());
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -909,7 +909,7 @@
   // '(' abstract-declarator ')'
   if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
   tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
-  tok::kw___vectorcall))
+  tok::kw___regcall, tok::kw___vectorcall))
 return TPResult::True; // attributes indicate declaration
   TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
   if (TPR != TPResult::Ambiguous)
@@ -1058,6 +1058,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___unaligned:
   case tok::kw___vector:
@@ -1351,6 +1352,7 @@
   case tok::kw___stdcall:
   case tok::kw___fastcall:
   case tok::kw___thiscall:
+  case tok::kw___regcall:
   case tok::kw___vectorcall:
   case tok::kw___w64:
   case tok::kw___sptr:
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -673,7 +673,16 @@
   } else {
 IdentifierInfo *II = ND->getIdentifier();
 assert(II && "Attempt to mangle unnamed decl.");
-Str = II->getName();
+const auto *FD = dyn_cast(ND);
+
+if (FD &&
+FD->getType()->castAs()->getCallConv() == CC_X86RegCall) {
+  llvm::raw_svector_ostream Out(Buffer);
+  Out << "__regcall3__" << II->getName();
+  Str = Out.str();
+} else {
+  Str = II->getName();
+}
   }
 
   // Keep the first result in the case of a mangling collision.
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -48,6 +48,7 @@
   default: return llvm::CallingConv::C;
   case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
   case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
+  case CC_X86RegCall: return llvm::CallingConv::X86_RegCall;
   case CC_X86ThisCall: return llvm::CallingConv::X86_ThisCall;
   case CC_X86_64Win64: return llvm::CallingConv::X86_64_Win64;
   case CC_X86_64SysV: return llvm::CallingConv::X86_64_SysV;
@@ -173,6 +174,9 @@
   if (D->hasAttr())
 return CC_X86FastCall;
 
+  if (D->hasAttr())
+return CC_X86RegCall;
+
   if (D->hasAttr())
 return CC_X86ThisCall;
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -904,6 +904,7 @@
   case CC_Swift:
   case CC_PreserveMost:
   case CC_PreserveAll:
+  case CC_X86RegCall:
 return 0;
   }
   return 0;
Index: lib/CodeGen/TargetInfo.cpp
==

[PATCH] D25604: Add support for Mageia Linux

2016-10-26 Thread Chandler Carruth via cfe-commits
chandlerc requested changes to this revision.
chandlerc added a comment.
This revision now requires changes to proceed.

Please add a stub tree and tests. You can find similar tests for other Linux 
distros in 'tests/Driver'.


https://reviews.llvm.org/D25604



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


r285218 - [PPC] Implement vector reverse elements builtins (vec_reve)

2016-10-26 Thread Nemanja Ivanovic via cfe-commits
Author: nemanjai
Date: Wed Oct 26 13:25:45 2016
New Revision: 285218

URL: http://llvm.org/viewvc/llvm-project?rev=285218&view=rev
Log:
[PPC] Implement vector reverse elements builtins (vec_reve)

This patch corresponds to review https://reviews.llvm.org/D25906.
Committing on behalf of Tony Jiang.


Modified:
cfe/trunk/lib/Headers/altivec.h
cfe/trunk/test/CodeGen/builtins-ppc-altivec.c
cfe/trunk/test/CodeGen/builtins-ppc-vsx.c

Modified: cfe/trunk/lib/Headers/altivec.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/altivec.h?rev=285218&r1=285217&r2=285218&view=diff
==
--- cfe/trunk/lib/Headers/altivec.h (original)
+++ cfe/trunk/lib/Headers/altivec.h Wed Oct 26 13:25:45 2016
@@ -15034,6 +15034,77 @@ vec_bperm(vector unsigned __int128 __a,
 #endif
 #endif
 
+
+/* vec_reve */
+
+static inline __ATTRS_o_ai vector bool char vec_reve(vector bool char __a) {
+  return __builtin_shufflevector(__a, __a, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6,
+ 5, 4, 3, 2, 1, 0);
+}
+
+static inline __ATTRS_o_ai vector signed char vec_reve(vector signed char __a) 
{
+  return __builtin_shufflevector(__a, __a, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6,
+ 5, 4, 3, 2, 1, 0);
+}
+
+static inline __ATTRS_o_ai vector unsigned char
+vec_reve(vector unsigned char __a) {
+  return __builtin_shufflevector(__a, __a, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6,
+ 5, 4, 3, 2, 1, 0);
+}
+
+static inline __ATTRS_o_ai vector bool int vec_reve(vector bool int __a) {
+  return __builtin_shufflevector(__a, __a, 3, 2, 1, 0);
+}
+
+static inline __ATTRS_o_ai vector signed int vec_reve(vector signed int __a) {
+  return __builtin_shufflevector(__a, __a, 3, 2, 1, 0);
+}
+
+static inline __ATTRS_o_ai vector unsigned int
+vec_reve(vector unsigned int __a) {
+  return __builtin_shufflevector(__a, __a, 3, 2, 1, 0);
+}
+
+static inline __ATTRS_o_ai vector bool short vec_reve(vector bool short __a) {
+  return __builtin_shufflevector(__a, __a, 7, 6, 5, 4, 3, 2, 1, 0);
+}
+
+static inline __ATTRS_o_ai vector signed short
+vec_reve(vector signed short __a) {
+  return __builtin_shufflevector(__a, __a, 7, 6, 5, 4, 3, 2, 1, 0);
+}
+
+static inline __ATTRS_o_ai vector unsigned short
+vec_reve(vector unsigned short __a) {
+  return __builtin_shufflevector(__a, __a, 7, 6, 5, 4, 3, 2, 1, 0);
+}
+
+static inline __ATTRS_o_ai vector float vec_reve(vector float __a) {
+  return __builtin_shufflevector(__a, __a, 3, 2, 1, 0);
+}
+
+#ifdef __VSX__
+static inline __ATTRS_o_ai vector bool long long
+vec_reve(vector bool long long __a) {
+  return __builtin_shufflevector(__a, __a, 1, 0);
+}
+
+static inline __ATTRS_o_ai vector signed long long
+vec_reve(vector signed long long __a) {
+  return __builtin_shufflevector(__a, __a, 1, 0);
+}
+
+static inline __ATTRS_o_ai vector unsigned long long
+vec_reve(vector unsigned long long __a) {
+  return __builtin_shufflevector(__a, __a, 1, 0);
+}
+
+static inline __ATTRS_o_ai vector double vec_reve(vector double __a) {
+  return __builtin_shufflevector(__a, __a, 1, 0);
+}
+#endif
+
 #undef __ATTRS_o_ai
 
 #endif /* __ALTIVEC_H */

Modified: cfe/trunk/test/CodeGen/builtins-ppc-altivec.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-ppc-altivec.c?rev=285218&r1=285217&r2=285218&view=diff
==
--- cfe/trunk/test/CodeGen/builtins-ppc-altivec.c (original)
+++ cfe/trunk/test/CodeGen/builtins-ppc-altivec.c Wed Oct 26 13:25:45 2016
@@ -8996,3 +8996,48 @@ void test7() {
 // CHECK: @llvm.ppc.altivec.vcmpgefp.p(i32 2
 // CHECK-LE: @llvm.ppc.altivec.vcmpgefp.p(i32 2
 }
+
+void test8() {
+  // CHECK-LABEL: define void @test8
+  // CHECK-LE-LABEL: define void @test8
+  res_vbc = vec_reve(vbc);
+  // CHECK: shufflevector <16 x i8> %{{[0-9]+}}, <16 x i8> %{{[0-9]+}}, <16 x 
i32> 
+  // CHECK-LE: shufflevector <16 x i8> %{{[0-9]+}}, <16 x i8> %{{[0-9]+}}, <16 
x i32> 
+
+  res_vsc = vec_reve(vsc);
+  // CHECK: shufflevector <16 x i8> %{{[0-9]+}}, <16 x i8> %{{[0-9]+}}, <16 x 
i32> 
+  // CHECK-LE: shufflevector <16 x i8> %{{[0-9]+}}, <16 x i8> %{{[0-9]+}}, <16 
x i32> 
+
+  res_vuc = vec_reve(vuc);
+  // CHECK: shufflevector <16 x i8> %{{[0-9]+}}, <16 x i8> %{{[0-9]+}}, <16 x 
i32> 
+  // CHECK-LE: shufflevector <16 x i8> %{{[0-9]+}}, <16 x i8> %{{[0-9]+}}, <16 
x i32> 
+
+  res_vbi = vec_reve(vbi);
+  // CHECK: shufflevector <4 x i32> %{{[0-9]+}}, <4 x i32> %{{[0-9]+}}, <4 x 
i32> 
+  // CHECK-LE: shufflevector <4 x i32> %{{[0-9]+}}, <4 x i32> %{{[0-9]+}}, <4 
x i32> 
+
+  res_vi = vec_reve(vi);
+  // CHECK: shufflevector <4 x i32> %{{[0-9]+}}, <4 x i32> %{{[0-9]+}}, <4 x 
i32> 
+  // CHECK-LE: shufflevector <4 x i32> %{{[0-9]+}}, <4 x i32> %{{[0-9]+}}, <4 
x i32> 
+
+  res_vui = vec_reve(vui);
+  // CHECK: shufflevector <4 x i32> %{{[0-9]+}}, <4 x i32> %{{[0-9]+}}, <4 x 
i32

[PATCH] D26002: Implement vector count leading/trailing bytes with zero lsb and vector parity builtins - clang portion

2016-10-26 Thread Zaara Syeda via cfe-commits
syzaara created this revision.
syzaara added reviewers: nemanjai, kbarton, amehsan, sfertile, jtony, lei.
syzaara added subscribers: cfe-commits, echristo.

Implement builtins for prototypes:
signed int vec_cntlz_lsbb (vector signed char);
signed int vec_cntlz_lsbb (vector unsigned char);
signed int vec_cnttz_lsbb (vector signed char);
signed int vec_cnttz_lsbb (vector unsigned char);
vector unsigned int vec_parity_lsbb (vector signed int);
vector unsigned int vec_parity_lsbb (vector unsigned int);
vector unsigned __int128 vec_parity_lsbb (vector signed __int128);
vector unsigned __int128 vec_parity_lsbb (vector unsigned __int128);
vector unsigned long long vec_parity_lsbb (vector signed long long);
vector unsigned long long vec_parity_lsbb (vector unsigned long long);


https://reviews.llvm.org/D26002

Files:
  include/clang/Basic/BuiltinsPPC.def
  lib/Headers/altivec.h
  test/CodeGen/builtins-ppc-p9vector.c

Index: test/CodeGen/builtins-ppc-p9vector.c
===
--- test/CodeGen/builtins-ppc-p9vector.c
+++ test/CodeGen/builtins-ppc-p9vector.c
@@ -23,6 +23,8 @@
 vector bool long long vbla, vblb;
 vector float vfa, vfb;
 vector double vda, vdb;
+vector unsigned __int128 vui128a, vui128b;
+vector signed __int128 vsi128a, vsi128b;
 
 unsigned test1(void) {
 // CHECK-BE: @llvm.ppc.altivec.vcmpequb(<16 x i8>
@@ -698,3 +700,78 @@
 // CHECK-NEXT: ret <8 x i16>
   return vec_popcnt (vusa);
 }
+signed int test59(void) {
+// CHECK-BE: @llvm.ppc.altivec.vclzlsbb(<16 x i8>
+// CHECK-BE-NEXT: ret i32
+// CHECK-LE: @llvm.ppc.altivec.vctzlsbb(<16 x i8>
+// CHECK-LE-NEXT: ret i32
+  return vec_cntlz_lsbb (vuca);
+}
+signed int test60(void) {
+// CHECK-BE: @llvm.ppc.altivec.vclzlsbb(<16 x i8>
+// CHECK-BE-NEXT: ret i32
+// CHECK-LE: @llvm.ppc.altivec.vctzlsbb(<16 x i8>
+// CHECK-LE-NEXT: ret i32
+  return vec_cntlz_lsbb (vsca);
+}
+signed int test61(void) {
+// CHECK-BE: @llvm.ppc.altivec.vctzlsbb(<16 x i8>
+// CHECK-BE-NEXT: ret i32
+// CHECK-LE: @llvm.ppc.altivec.vclzlsbb(<16 x i8>
+// CHECK-LE-NEXT: ret i32
+  return vec_cnttz_lsbb (vsca);
+}
+signed int test62(void) {
+// CHECK-BE: @llvm.ppc.altivec.vctzlsbb(<16 x i8>
+// CHECK-BE-NEXT: ret i32
+// CHECK-LE: @llvm.ppc.altivec.vclzlsbb(<16 x i8>
+// CHECK-LE-NEXT: ret i32
+  return vec_cnttz_lsbb (vuca);
+}
+
+vector unsigned int test63(void) {
+// CHECK-BE: @llvm.ppc.altivec.vprtybw(<4 x i32>
+// CHECK-BE-NEXT: ret <4 x i32>
+// CHECK: @llvm.ppc.altivec.vprtybw(<4 x i32>
+// CHECK-NEXT: ret <4 x i32>
+  return vec_parity_lsbb (vuia);
+}
+
+vector unsigned int test64(void) {
+// CHECK-BE: @llvm.ppc.altivec.vprtybw(<4 x i32>
+// CHECK-BE-NEXT: ret <4 x i32>
+// CHECK: @llvm.ppc.altivec.vprtybw(<4 x i32>
+// CHECK-NEXT: ret <4 x i32>
+  return vec_parity_lsbb (vsia);
+}
+
+vector unsigned long long test65(void) {
+// CHECK-BE: @llvm.ppc.altivec.vprtybd(<2 x i64>
+// CHECK-BE-NEXT: ret <2 x i64>
+// CHECK: @llvm.ppc.altivec.vprtybd(<2 x i64>
+// CHECK-NEXT: ret <2 x i64>
+  return vec_parity_lsbb (vula);
+}
+
+vector unsigned long long test66(void) {
+// CHECK-BE: @llvm.ppc.altivec.vprtybd(<2 x i64>
+// CHECK-BE-NEXT: ret <2 x i64>
+// CHECK: @llvm.ppc.altivec.vprtybd(<2 x i64>
+// CHECK-NEXT: ret <2 x i64>
+  return vec_parity_lsbb (vsla);
+}
+vector unsigned __int128 test67(void) {
+// CHECK-BE: @llvm.ppc.altivec.vprtybq(<1 x i128>
+// CHECK-BE-NEXT: ret <1 x i128>
+// CHECK: @llvm.ppc.altivec.vprtybq(<1 x i128>
+// CHECK-NEXT: ret <1 x i128>
+  return vec_parity_lsbb (vui128a);
+}
+
+vector unsigned __int128 test68(void) {
+// CHECK-BE: @llvm.ppc.altivec.vprtybq(<1 x i128>
+// CHECK-BE-NEXT: ret <1 x i128>
+// CHECK: @llvm.ppc.altivec.vprtybq(<1 x i128>
+// CHECK-NEXT: ret <1 x i128>
+  return vec_parity_lsbb (vsi128a);
+}
Index: lib/Headers/altivec.h
===
--- lib/Headers/altivec.h
+++ lib/Headers/altivec.h
@@ -2497,6 +2497,72 @@
   return __res[0] >> 5;
 }
 
+static __inline__ signed int __ATTRS_o_ai
+vec_cntlz_lsbb(vector signed char __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vctzlsbb(__a);
+#else
+  return __builtin_altivec_vclzlsbb(__a);
+#endif
+}
+
+static __inline__ signed int __ATTRS_o_ai
+vec_cntlz_lsbb(vector unsigned char __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vctzlsbb(__a);
+#else
+  return __builtin_altivec_vclzlsbb(__a);
+#endif
+}
+
+static __inline__ signed int __ATTRS_o_ai
+vec_cnttz_lsbb(vector signed char __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vclzlsbb(__a);
+#else
+  return __builtin_altivec_vctzlsbb(__a);
+#endif
+}
+
+static __inline__ signed int __ATTRS_o_ai
+vec_cnttz_lsbb(vector unsigned char __a) {
+#ifdef __LITTLE_ENDIAN__
+  return __builtin_altivec_vclzlsbb(__a);
+#else
+  return __builtin_altivec_vctzlsbb(__a);
+#endif
+}
+
+static __inline__ vector unsigned int __ATTRS_o_ai
+vec_parity_lsbb(vector unsigned int __a) {
+  return __builtin_altivec_vprtybw(__a);
+

[PATCH] D22346: [Clang-tidy] CERT-MSC50-CPP (std:rand() )

2016-10-26 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

clang-tidy/cert/.LimitedRandomnessCheck.cpp.swo was added and should not have 
been; also, there's one minor issue with the diagnostic wording that is still 
outstanding.




Comment at: clang-tidy/cert/LimitedRandomnessCheck.cpp:35
+  diag(MatchedDecl->getLocStart(),
+   "rand() function has limited randomness; " + msg);
+}

aaron.ballman wrote:
> For C code, this diagnostic will read strangely due to the trailing 
> semicolon. You should move the semicolon into the `msg` above. Perhaps we can 
> also drop "function" from the diagnostic as well.
This comment does not appear to have been handled -- the semicolon is still 
present even when `msg` is empty.


https://reviews.llvm.org/D22346



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


[PATCH] D25985: [analyzer] Export coverage information from the analyzer.

2016-10-26 Thread Gábor Horváth via cfe-commits
xazax.hun removed rL LLVM as the repository for this revision.
xazax.hun updated this revision to Diff 75923.

https://reviews.llvm.org/D25985

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/analyzer-config.c
  test/Analysis/analyzer-config.cpp
  test/Analysis/record-coverage.cpp
  test/Analysis/record-coverage.cpp.expected

Index: test/Analysis/record-coverage.cpp.expected
===
--- /dev/null
+++ test/Analysis/record-coverage.cpp.expected
@@ -0,0 +1,9 @@
+// CHECK:  -:4:int main() {
+// CHECK-NEXT: -:5:  int i = 2;
+// CHECK-NEXT: 1:6:  ++i;
+// CHECK-NEXT: 1:7:  if (i != 0) {
+// CHECK-NEXT: 1:8:++i;
+// CHECK-NEXT: 1:9:  } else {
+// CHECK-NEXT: -:10:--i;
+// CHECK-NEXT: -:11:  }
+// CHECK-NEXT: -:12:}
Index: test/Analysis/record-coverage.cpp
===
--- /dev/null
+++ test/Analysis/record-coverage.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-config record-coverage=%T %s
+// RUN: FileCheck -input-file %T/%s.gcov %s.expected
+
+int main() {
+  int i = 2;
+  ++i;
+  if (i != 0) {
+++i;
+  } else {
+--i;
+  }
+}
Index: test/Analysis/analyzer-config.cpp
===
--- test/Analysis/analyzer-config.cpp
+++ test/Analysis/analyzer-config.cpp
@@ -35,7 +35,8 @@
 // CHECK-NEXT: max-times-inline-large = 32
 // CHECK-NEXT: min-cfg-size-treat-functions-as-large = 14
 // CHECK-NEXT: mode = deep
+// CHECK-NEXT: record-coverage =
 // CHECK-NEXT: region-store-small-struct-limit = 2
 // CHECK-NEXT: widen-loops = false
 // CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 20
+// CHECK-NEXT: num-entries = 21
Index: test/Analysis/analyzer-config.c
===
--- test/Analysis/analyzer-config.c
+++ test/Analysis/analyzer-config.c
@@ -24,8 +24,9 @@
 // CHECK-NEXT: max-times-inline-large = 32
 // CHECK-NEXT: min-cfg-size-treat-functions-as-large = 14
 // CHECK-NEXT: mode = deep
+// CHECK-NEXT: record-coverage =
 // CHECK-NEXT: region-store-small-struct-limit = 2
 // CHECK-NEXT: widen-loops = false
 // CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 15
+// CHECK-NEXT: num-entries = 16
 
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -28,8 +28,13 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/LoopWidening.h"
 #include "llvm/ADT/Statistic.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/LineIterator.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/raw_os_ostream.h"
+#include 
 
 #ifndef NDEBUG
 #include "llvm/Support/GraphWriter.h"
@@ -251,6 +256,45 @@
   return State;
 }
 
+// Mapping from file to line indexed hit count vector.
+static llvm::DenseMap> CoverageInfo;
+
+static void dumpCoverageInfo(llvm::SmallVectorImpl &Path,
+ SourceManager &SM) {
+  for (auto &Entry : CoverageInfo) {
+SmallString<128> FilePath;
+const FileEntry *FE = Entry.getFirst();
+llvm::sys::path::append(FilePath, Path, FE->getName() + ".gcov");
+SmallString<128> DirPath = FilePath;
+llvm::sys::path::remove_filename(DirPath);
+llvm::sys::fs::create_directories(DirPath);
+bool Invalid = false;
+llvm::MemoryBuffer *Buf = SM.getMemoryBufferForFile(FE, &Invalid);
+if (Invalid)
+  continue;
+std::ofstream OutFile(FilePath.c_str());
+if (!OutFile) {
+  llvm::errs() << FilePath << " not found!\n";
+  continue;
+}
+llvm::raw_os_ostream Out(OutFile);
+Out << "-:0:Source:" << FE->getName() << '\n';
+Out << "-:0:Runs:1\n";
+Out << "-:0:Programs:1\n";
+for (llvm::line_iterator LI(*Buf, false); !LI.is_at_eof(); ++LI) {
+  int Count = Entry.getSecond()[LI.line_number()-1];
+  if (Count != 0) {
+Out << Count;
+  } else if (Count < 0) {
+Out << "#";
+  } else {
+Out << '-';
+  }
+  Out << ':' << LI.line_number() << ':' << *LI << '\n';
+}
+  }
+}
+
 //===--===//
 // Top-level transfer function logic (Dispatcher).
 //===--===//
@@ -282,6 +326,12 @@
 }
 
 void ExprEngine::processEndWorklist(bool hasWorkRemaining) {
+  if (!AMgr.options.coverageExportDir().empty()) {
+SmallString<128> Path = AMgr.options.coverageExportDir();
+SourceManager &SM = getContext().getSourceManager();
+SM.getFileManager().makeAbsolutePath(Path);
+dumpCoverag

[PATCH] D24894: [clang-tidy] Prefer transparent functors to non-transparent one.

2016-10-26 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/modernize/UseTransparentFunctorsCheck.cpp:26
+  unless(hasAnyTemplateArgument(refersToType(voidType(,
+  hasAnyName("::std::plus", "::std::minus", "::std::multiplies",
+ "::std::divides", "::std::modulus", "::std::negate",

xazax.hun wrote:
> aaron.ballman wrote:
> > Should we make this a configurable list that users can add to?
> I am not sure how frequent is that somebody would like to add some types to 
> this list, but it can be added in a follow up patch.
I'm fine with a follow-on patch.



Comment at: clang-tidy/modernize/UseTransparentFunctorsCheck.cpp:61
+  Result.Nodes.getNodeAs("FuncInst")) {
+diag(FuncInst->getLocStart(), "prefer transparent functors");
+return;

xazax.hun wrote:
> aaron.ballman wrote:
> > This diagnostic is too terse; anyone that is unaware of what a transparent 
> > functor is will likely be stumped by it, especially since there is no fixit.
> > 
> > Since this is the case where we cannot be sure that a transparent functor 
> > is the correct solution, should this be enabled via an option (default on)?
> I also extended the error message to refer to the alternative name (diamond 
> operators) as well. 
> 
> I did add an option but I am not happy with the name of the option. Do you 
> have a suggestion?
`SafeMode` is a bit dramatic-sounding, but I can't come up with something 
better, so it's probably fine.


https://reviews.llvm.org/D24894



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


[PATCH] D25958: [libc++] Silence "unused parameter" warnings in test/support/archetypes.hpp

2016-10-26 Thread Casey Carter via cfe-commits
CaseyCarter closed this revision.
CaseyCarter added a comment.

Committed as r285213.


https://reviews.llvm.org/D25958



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


r285229 - [PowerPC] Implement vector_insert_exp builtins - clang portion

2016-10-26 Thread Nemanja Ivanovic via cfe-commits
Author: nemanjai
Date: Wed Oct 26 14:27:11 2016
New Revision: 285229

URL: http://llvm.org/viewvc/llvm-project?rev=285229&view=rev
Log:
[PowerPC] Implement vector_insert_exp builtins - clang portion

This patch corresponds to review https://reviews.llvm.org/D25956.
Committing on behalf of Zaara Syeda.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsPPC.def
cfe/trunk/lib/Headers/altivec.h
cfe/trunk/test/CodeGen/builtins-ppc-p9vector.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsPPC.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsPPC.def?rev=285229&r1=285228&r2=285229&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsPPC.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsPPC.def Wed Oct 26 14:27:11 2016
@@ -362,6 +362,9 @@ BUILTIN(__builtin_vsx_xvcpsgnsp, "V4fV4f
 BUILTIN(__builtin_vsx_xvabssp, "V4fV4f", "")
 BUILTIN(__builtin_vsx_xvabsdp, "V2dV2d", "")
 
+BUILTIN(__builtin_vsx_xviexpdp, "V2dV2ULLiV2ULLi", "")
+BUILTIN(__builtin_vsx_xviexpsp, "V4fV4UiV4Ui", "")
+
 // HTM builtins
 BUILTIN(__builtin_tbegin, "UiUIi", "")
 BUILTIN(__builtin_tend, "UiUIi", "")

Modified: cfe/trunk/lib/Headers/altivec.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/altivec.h?rev=285229&r1=285228&r2=285229&view=diff
==
--- cfe/trunk/lib/Headers/altivec.h (original)
+++ cfe/trunk/lib/Headers/altivec.h Wed Oct 26 14:27:11 2016
@@ -2497,6 +2497,26 @@ vec_first_mismatch_or_eos_index(vector u
   return __res[0] >> 5;
 }
 
+static __inline__ vector double  __ATTRS_o_ai
+vec_insert_exp(vector double __a, vector unsigned long long __b) {
+  return __builtin_vsx_xviexpdp((vector unsigned long long)__a,__b);
+}
+
+static __inline__ vector double  __ATTRS_o_ai
+vec_insert_exp(vector unsigned long long __a, vector unsigned long long __b) {
+  return __builtin_vsx_xviexpdp(__a,__b);
+}
+
+static __inline__ vector float  __ATTRS_o_ai
+vec_insert_exp(vector float __a, vector unsigned int __b) {
+  return __builtin_vsx_xviexpsp((vector unsigned int)__a,__b);
+}
+
+static __inline__ vector float  __ATTRS_o_ai
+vec_insert_exp(vector unsigned int __a, vector unsigned int __b) {
+  return __builtin_vsx_xviexpsp(__a,__b);
+}
+
 #endif
 
 /* vec_cpsgn */

Modified: cfe/trunk/test/CodeGen/builtins-ppc-p9vector.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-ppc-p9vector.c?rev=285229&r1=285228&r2=285229&view=diff
==
--- cfe/trunk/test/CodeGen/builtins-ppc-p9vector.c (original)
+++ cfe/trunk/test/CodeGen/builtins-ppc-p9vector.c Wed Oct 26 14:27:11 2016
@@ -698,3 +698,31 @@ vector unsigned short test54(void) {
 // CHECK-NEXT: ret <8 x i16>
   return vec_popcnt (vusa);
 }
+vector double test55(void) {
+// CHECK-BE: @llvm.ppc.vsx.xviexpdp(<2 x i64> %{{.+}}, <2 x i64>
+// CHECK-BE-NEXT: ret <2 x double>
+// CHECK: @llvm.ppc.vsx.xviexpdp(<2 x i64> %{{.+}}, <2 x i64>
+// CHECK-NEXT: ret <2 x double>
+  return vec_insert_exp (vda,vulb);
+}
+vector double test56(void) {
+// CHECK-BE: @llvm.ppc.vsx.xviexpdp(<2 x i64> %{{.+}}, <2 x i64>
+// CHECK-BE-NEXT: ret <2 x double>
+// CHECK: @llvm.ppc.vsx.xviexpdp(<2 x i64> %{{.+}}, <2 x i64>
+// CHECK-NEXT: ret <2 x double>
+  return vec_insert_exp (vula, vulb);
+}
+vector float test57(void) {
+// CHECK-BE: @llvm.ppc.vsx.xviexpsp(<4 x i32> %{{.+}}, <4 x i32>
+// CHECK-BE-NEXT: ret <4 x float>
+// CHECK: @llvm.ppc.vsx.xviexpsp(<4 x i32> %{{.+}}, <4 x i32>
+// CHECK-NEXT: ret <4 x float>
+  return vec_insert_exp (vfa,vuib);
+}
+vector float test58(void) {
+// CHECK-BE: @llvm.ppc.vsx.xviexpsp(<4 x i32> %{{.+}}, <4 x i32>
+// CHECK-BE-NEXT: ret <4 x float>
+// CHECK: @llvm.ppc.vsx.xviexpsp(<4 x i32> %{{.+}}, <4 x i32>
+// CHECK-NEXT: ret <4 x float>
+  return vec_insert_exp (vuia,vuib);
+}


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


[PATCH] D24085: arm: Fix ttype encoding assertion failure.

2016-10-26 Thread Marshall Clow via cfe-commits
mclow.lists added inline comments.



Comment at: src/cxa_personality.cpp:363
+   "Unexpected TTypeEncoding");
 (void)ttypeEncoding;
 

logan wrote:
> mclow.lists wrote:
> > It's not clear to me how this accomplishes what you want.
> > You're looking for `00/10/90`, right?  Why not just check for that?
> > 
> > Why are you anding with 0x0f ?
> > Before, this would pass only a single value - `DW_EH_PE_absptr` (aka 0)
> > With this change, it passes 32 values: 00, 03, 10, 13, 20, 23, and so on.
> > 
> > Was that your intent?
> > 
> `ttypeEncoding` is encoded with following rules:
> 
> 1. Lower 4 bits stand for the representation of the data, such as `absptr`, 
> `uleb128`, `udata1`, `udata2`, `udata4`, `udata8`, etc.  These bits control 
> the way we extract the bytes from the exception table.
> 
> 2. Upper 4 bits stand for the post processing action, such as `pcrel`, 
> `indirect`, etc.  For example, if `pcrel` is specified, then we should add 
> the value, which was read in step 1, with the address of the value.
> 
> My intention is to weaken the assertion (only assert the essential 
> assumption) so that we don't have to alter the assertion  if there are new 
> configurations that I am not aware of or new compiler which is generating 
> different ttypeEncoding.
> 
> Since the upcoming lines (L365) only uses `sizeof(uintptr_t)` to decode the 
> TType pointer, it is not necessary to impose restriction on the upper 4 bits. 
>  That's the reason why I wrote `ttypeEncoding & 0xf`.  For the same reason, 
> both `absptr` and `udata` have the same meaning (4 bytes in the exception 
> table) in this context, thus I am adding extra `(ttypeEncoding & 0x0f) == 
> DW_EH_PE_udata4`.
Ok; thanks for the explanation. However, I'm still concerned. 
The assert is there to catch bad assumptions. (i.e, this can never happen).

the old code would assert on 255 of 256 possible values.
It turns out that this is too strict - there are at least three values that we 
need to pass.

But your assertion passes 32 possible values (out of 256). So if something goes 
wrong, and a random value for  `ttypeEncoding` gets passed in here, there's a 1 
in 8 chance that the assertion will not fire.  *Thats* my concern.   It should 
never be an issue, because we don't have bugs, and never pass random values 
around, right? ;-)

As for "dealing with new configurations" or "new compilers", I would say those 
are very infrequent events; and I wouldn't worry about them until they happen.  
(Demonstrations that I am misinformed here are welcome)


https://reviews.llvm.org/D24085



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


[PATCH] D21075: Correct invalid end location in diagnostics for some identifiers.

2016-10-26 Thread Richard Smith via cfe-commits
rsmith added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:2061-2062
+  auto Builder = Diag(R.getNameLoc(), diagnostic) << Name;
+  if (Name.isIdentifier())
+Builder << SourceRange(R.getNameLoc());
   return true;

I'm indifferent on this change: I don't see much point in adding a single-token 
range when we already point the caret at that token, but I don't see any harm 
either.



Comment at: lib/Sema/SemaType.cpp:1339
+auto R = DS.getSourceRange();
+if (R.getEnd().isInvalid())
+  R.setEnd(R.getBegin());

klimek wrote:
> erikjv wrote:
> > klimek wrote:
> > > Do you know in which cases we get source ranges that are half valid?
> > In Parser::ParseTypeofSpecifier the 'cast range' for a typeof(...) is 
> > parsed, but is found to be invalid. Then it explicitly sets the DeclSpec's 
> > end location to an invalid location.
> Ok, in this case, we'll need Richard to verify whether he intended half-valid 
> source locations something that users need to deal with.
The code in `ParseTypeofSpecifier` does this:

```
  if (CastRange.getEnd().isInvalid())
// FIXME: Not accurate, the range gets one token more than it should.
DS.SetRangeEnd(Tok.getLocation());
  else
DS.SetRangeEnd(CastRange.getEnd());
```

This should always set the end of the range to a valid location. Generally, I 
think we should avoid half-valid ranges rather than trying to cope with them 
downstream.


https://reviews.llvm.org/D21075



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


[PATCH] D26007: [libc++] Cleanup non-portable std::any tests

2016-10-26 Thread Casey Carter via cfe-commits
CaseyCarter created this revision.
CaseyCarter added reviewers: EricWF, mclow.lists.
CaseyCarter added a subscriber: cfe-commits.
CaseyCarter set the repository for this revision to rL LLVM.

Cleanup nonportable behavior in tests for `std::any`

Fixes MS issues 63, 64, and 65.

test/std/utilities/any/any.class/any.cons/move.pass.cpp:

- "Moves are always destructive" is not a portable assumption; check with 
`LIBCPP_ASSERT`.

test/std/utilities/any/any.class/any.cons/value.pass.cpp:
test/libcxx/utilities/any/any.class/any.cons/value.pass.cpp:

- The standard does not forbid initializing `std::any` from any 
pointer-to-function type. The `DecayTag` test is a libc++ extension (at best); 
factor it out into a test in the libcxx hierarchy.

test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp:

- Self-swap is not specified to perform no moves; check with `LIBCPP_ASSERT`.


Repository:
  rL LLVM

https://reviews.llvm.org/D26007

Files:
  test/libcxx/utilities/any/any.class/any.cons/value.pass.cpp
  test/std/utilities/any/any.class/any.cons/move.pass.cpp
  test/std/utilities/any/any.class/any.cons/value.pass.cpp
  test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp


Index: test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
===
--- test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
+++ test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
@@ -104,7 +104,7 @@
 assertContains(a, 42);
 assert(T::count == 1);
 assert(T::copied == 0);
-assert(T::moved == 0);
+LIBCPP_ASSERT(T::moved == 0);
 }
 assert(small::count == 0);
 { // large
@@ -113,9 +113,9 @@
 T::reset();
 a.swap(a);
 assertContains(a, 42);
-assert(T::copied == 0);
-assert(T::moved == 0);
 assert(T::count == 1);
+assert(T::copied == 0);
+LIBCPP_ASSERT(T::moved == 0);
 }
 assert(large::count == 0);
 }
Index: test/std/utilities/any/any.class/any.cons/value.pass.cpp
===
--- test/std/utilities/any/any.class/any.cons/value.pass.cpp
+++ test/std/utilities/any/any.class/any.cons/value.pass.cpp
@@ -137,10 +137,6 @@
 static_assert(!std::is_constructible::value, "");
 }
 {
-using DecayTag = std::decay_t;
-static_assert(!std::is_constructible::value, "");
-}
-{
 // Test that the ValueType&& constructor SFINAE's away when the
 // argument is non-copyable
 struct NoCopy {
Index: test/std/utilities/any/any.class/any.cons/move.pass.cpp
===
--- test/std/utilities/any/any.class/any.cons/move.pass.cpp
+++ test/std/utilities/any/any.class/any.cons/move.pass.cpp
@@ -80,8 +80,8 @@
 assert(Type::moved == 1 || Type::moved == 2); // zero or more move 
operations can be performed.
 assert(Type::copied == 0); // no copies can be performed.
 assert(Type::count == 1 + a.has_value());
-assertEmpty(a); // Moves are always destructive.
 assertContains(a2, 42);
+LIBCPP_ASSERT(!a.has_value()); // Moves are always destructive.
 if (a.has_value())
 assertContains(a, 0);
 }
Index: test/libcxx/utilities/any/any.class/any.cons/value.pass.cpp
===
--- /dev/null
+++ test/libcxx/utilities/any/any.class/any.cons/value.pass.cpp
@@ -0,0 +1,37 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+// 
+
+// template  any(Value &&)
+
+// Test construction from a value.
+// Concerns:
+// -
+// 1. The value is properly move/copied depending on the value category.
+// 2. Both small and large values are properly handled.
+
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+using std::any;
+using std::any_cast;
+
+int main() {
+// Test that any(ValueType&&) is *never* selected for a std::in_place type.
+// Test that the tag type is properly handled in SFINAE
+using BadTag = std::in_place_type_t;
+using DecayTag = std::decay_t;
+static_assert(!std::is_constructible::value, "");
+}


Index: test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
===
--- test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
+++ test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
@@ -104,7 +104,7 @@
 assertContains(a, 42);
 assert(T::count == 1);
 assert(T::copied == 0);
-assert(T:

[PATCH] D26007: [libc++] Cleanup non-portable std::any tests

2016-10-26 Thread Casey Carter via cfe-commits
CaseyCarter added inline comments.



Comment at: test/libcxx/utilities/any/any.class/any.cons/value.pass.cpp:36
+using DecayTag = std::decay_t;
+static_assert(!std::is_constructible::value, "");
+}

I'm generously calling this a "libc++ extension." From my interpretation of 
N4606, LWG2744, and LWG2754, this appears to be a bug.


Repository:
  rL LLVM

https://reviews.llvm.org/D26007



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


[PATCH] D24886: Add [[clang::suppress(rule, ...)]] attribute

2016-10-26 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/Basic/AttrDocs.td:2509
+to suppress specific clang-tidy warnings. They can be attached to a scope,
+statement or type. The ``[[gsl::suppress]]`` is an alias of 
``[[clang::suppress]]``
+which is intended to be used for suppressing rules of the C++ Core Guidelines_

mgehre wrote:
> aaron.ballman wrote:
> > This statement does not match the test cases -- it does not appear to be 
> > possible to attach the attribute to a type.
> It is true that you cannot attach the attribute to an existing type during 
> declaration of a variable,
> but the attribute can be attached when declaring a new type. (See line 22 of 
> the test case, where the attribute is attached to the union type U)
> I would propose to says "type declaration" instead of "type", ok?
> 
I think that "type declaration" would be an improvement.


https://reviews.llvm.org/D24886



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


[PATCH] D21075: Correct invalid end location in diagnostics for some identifiers.

2016-10-26 Thread Erik Verbruggen via cfe-commits
erikjv added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:2061-2062
+  auto Builder = Diag(R.getNameLoc(), diagnostic) << Name;
+  if (Name.isIdentifier())
+Builder << SourceRange(R.getNameLoc());
   return true;

rsmith wrote:
> I'm indifferent on this change: I don't see much point in adding a 
> single-token range when we already point the caret at that token, but I don't 
> see any harm either.
It's mostly about how much is "underlined". If there is only a caret, that 
quite often translates into a single character being pointed out, instead of an 
identifier (i.e. the first character). Hene the extension of the range.


https://reviews.llvm.org/D21075



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


[PATCH] D15994: Allow for unfinished #if blocks in preambles.

2016-10-26 Thread Richard Smith via cfe-commits
rsmith added inline comments.



Comment at: include/clang/Lex/Preprocessor.h:283-286
+  Off = 0,
+  Recording = 1,
+  Replaying = 2,
+  Done = 3

What's the difference between the `Off` and `Done` states? They seem to be the 
same to me?



Comment at: include/clang/Lex/Preprocessor.h:317
+void setStack(const Stack &s)
+{
+  if (!isRecording() && !isReplaying())

`{` on previous line.



Comment at: include/clang/Lex/Preprocessor.h:326
+
+bool HasRecordedPreamble() const { return ConditionalStack.getPointer(); }
+

Start function names with a lowercase letter.



Comment at: include/clang/Lex/Preprocessor.h:329
+  private:
+llvm::PointerIntPair ConditionalStack;
+  } PreambleConditionalStack;

We don't really care much about the `Preprocessor` object getting a few dozen 
bytes larger, since there will typically only be one of them.  I don't think 
the complexity of a dynamically-allocated stack and a `PointerIntPair` is 
worthwhile here. Just store a `Stack` and a `State` directly as members.



Comment at: include/clang/Lex/Preprocessor.h:1959-1963
+  bool IsRecordingPreamble() const {
+return PreambleConditionalStack.isRecording();
+  }
+
+  bool HasRecordedPreamble() const {

Start function names with a lowercase letter.



Comment at: lib/Lex/Lexer.cpp:622
 StringRef Keyword = TheTok.getRawIdentifier();
 PreambleDirectiveKind PDK
   = llvm::StringSwitch(Keyword)

You can remove the special-case handling for `#if`/`#else`/`#endif` here.



Comment at: lib/Lex/Lexer.cpp:2529-2532
+  if (PP->IsRecordingPreamble()) {
+PP->setRecordedPreambleConditionalStack(ConditionalStack);
+ConditionalStack.clear();
+  }

We should only do this if we reach the end of the main source file. If we reach 
the end of a `#include`'d file with a `#if` still open, we should diagnose that.



Comment at: lib/Serialization/ASTReader.cpp:2816
+}
+PP.setReplayablePreambleConditionalStack(ConditionalStack);
+  }

Why can't we set the conditional stack on the `PPLexer` directly from here? 
(Why do we need to store it separately?)


https://reviews.llvm.org/D15994



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


[PATCH] D25898: [clang-tidy] Enhance modernize-make-unique to handle unique_ptr.reset()

2016-10-26 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:74
 
+  if (Construct) {
+checkConstruct(SM, Construct, Type, New);

Can elide the braces for the `if` and `else`.



Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:147
+  CharSourceRange::getCharRange(OperatorLoc, ExprEnd),
+  " = " + makeSmartPtrFunctionName + "<" +
+  New->getAllocatedType().getAsString(getLangOpts()) + ">");

I kind of wonder if this should be using `Twine` to avoid a lot of extra 
allocations and copies.



Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:150
+
+  if (Expr->isArrow()) {
+Diag << FixItHint::CreateInsertion(ExprStart, "*");

Elide braces


https://reviews.llvm.org/D25898



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


[PATCH] D26007: [libc++] Cleanup non-portable std::any tests

2016-10-26 Thread Eric Fiselier via cfe-commits
EricWF accepted this revision.
EricWF added inline comments.
This revision is now accepted and ready to land.



Comment at: test/libcxx/utilities/any/any.class/any.cons/value.pass.cpp:1
+//===--===//
+//

Just kill this test entirely. I'm going to change the behavior shortly.


Repository:
  rL LLVM

https://reviews.llvm.org/D26007



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


[PATCH] D25992: [RecursiveASTVisitor] Visit the implicit expression of a CXXDefaultArgExpr

2016-10-26 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


https://reviews.llvm.org/D25992



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


[PATCH] D25995: Add documentation for transparent_union attribute

2016-10-26 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you for the improved docs!


Repository:
  rL LLVM

https://reviews.llvm.org/D25995



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


[PATCH] D26007: [libc++] Cleanup non-portable std::any tests

2016-10-26 Thread Casey Carter via cfe-commits
CaseyCarter removed rL LLVM as the repository for this revision.
CaseyCarter updated this revision to Diff 75936.
CaseyCarter added a comment.

Cleanup nonportable behavior in tests for `std::any`

Fixes MS issues 63, 64, and 65.

test/std/utilities/any/any.class/any.cons/move.pass.cpp:

- "Moves are always destructive" is not a portable assumption; check with 
`LIBCPP_ASSERT`.

test/std/utilities/any/any.class/any.cons/value.pass.cpp:

- The standard does not forbid initializing `std::any` from any 
pointer-to-function type. Remove the non-conforming `DecayTag` test.

test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp:

- Self-swap is not specified to perform no moves; check with `LIBCPP_ASSERT`.


https://reviews.llvm.org/D26007

Files:
  test/std/utilities/any/any.class/any.cons/move.pass.cpp
  test/std/utilities/any/any.class/any.cons/value.pass.cpp
  test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp


Index: test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
===
--- test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
+++ test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
@@ -104,7 +104,7 @@
 assertContains(a, 42);
 assert(T::count == 1);
 assert(T::copied == 0);
-assert(T::moved == 0);
+LIBCPP_ASSERT(T::moved == 0);
 }
 assert(small::count == 0);
 { // large
@@ -113,9 +113,9 @@
 T::reset();
 a.swap(a);
 assertContains(a, 42);
-assert(T::copied == 0);
-assert(T::moved == 0);
 assert(T::count == 1);
+assert(T::copied == 0);
+LIBCPP_ASSERT(T::moved == 0);
 }
 assert(large::count == 0);
 }
Index: test/std/utilities/any/any.class/any.cons/value.pass.cpp
===
--- test/std/utilities/any/any.class/any.cons/value.pass.cpp
+++ test/std/utilities/any/any.class/any.cons/value.pass.cpp
@@ -137,10 +137,6 @@
 static_assert(!std::is_constructible::value, "");
 }
 {
-using DecayTag = std::decay_t;
-static_assert(!std::is_constructible::value, "");
-}
-{
 // Test that the ValueType&& constructor SFINAE's away when the
 // argument is non-copyable
 struct NoCopy {
Index: test/std/utilities/any/any.class/any.cons/move.pass.cpp
===
--- test/std/utilities/any/any.class/any.cons/move.pass.cpp
+++ test/std/utilities/any/any.class/any.cons/move.pass.cpp
@@ -80,8 +80,8 @@
 assert(Type::moved == 1 || Type::moved == 2); // zero or more move 
operations can be performed.
 assert(Type::copied == 0); // no copies can be performed.
 assert(Type::count == 1 + a.has_value());
-assertEmpty(a); // Moves are always destructive.
 assertContains(a2, 42);
+LIBCPP_ASSERT(!a.has_value()); // Moves are always destructive.
 if (a.has_value())
 assertContains(a, 0);
 }


Index: test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
===
--- test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
+++ test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
@@ -104,7 +104,7 @@
 assertContains(a, 42);
 assert(T::count == 1);
 assert(T::copied == 0);
-assert(T::moved == 0);
+LIBCPP_ASSERT(T::moved == 0);
 }
 assert(small::count == 0);
 { // large
@@ -113,9 +113,9 @@
 T::reset();
 a.swap(a);
 assertContains(a, 42);
-assert(T::copied == 0);
-assert(T::moved == 0);
 assert(T::count == 1);
+assert(T::copied == 0);
+LIBCPP_ASSERT(T::moved == 0);
 }
 assert(large::count == 0);
 }
Index: test/std/utilities/any/any.class/any.cons/value.pass.cpp
===
--- test/std/utilities/any/any.class/any.cons/value.pass.cpp
+++ test/std/utilities/any/any.class/any.cons/value.pass.cpp
@@ -137,10 +137,6 @@
 static_assert(!std::is_constructible::value, "");
 }
 {
-using DecayTag = std::decay_t;
-static_assert(!std::is_constructible::value, "");
-}
-{
 // Test that the ValueType&& constructor SFINAE's away when the
 // argument is non-copyable
 struct NoCopy {
Index: test/std/utilities/any/any.class/any.cons/move.pass.cpp
===
--- test/std/utilities/any/any.class/any.cons/move.pass.cpp
+++ test/std/utilities/any/any.class/any.cons/move.pass.cpp
@@ -80,8 +80,8 @@
 assert(Type::moved == 1 || Type::moved == 2); // zero or more move operations can be performed.
 assert(Type::copied == 0); // no copies can be performed.
 assert(Type::count == 1 + a.has_value());
-assertEmpt

[PATCH] D26007: [libc++] Cleanup non-portable std::any tests

2016-10-26 Thread Casey Carter via cfe-commits
CaseyCarter marked 2 inline comments as done.
CaseyCarter added a comment.

DecayTag destroyed.


https://reviews.llvm.org/D26007



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


[libcxx] r285234 - Cleanup nonportable behavior in tests for std::any

2016-10-26 Thread Casey Carter via cfe-commits
Author: caseycarter
Date: Wed Oct 26 15:18:13 2016
New Revision: 285234

URL: http://llvm.org/viewvc/llvm-project?rev=285234&view=rev
Log:
Cleanup nonportable behavior in tests for std::any

Fixes MS issues 63, 64, and 65.

test/std/utilities/any/any.class/any.cons/move.pass.cpp:
* "Moves are always destructive" is not a portable assumption; check with 
LIBCPP_ASSERT.

test/std/utilities/any/any.class/any.cons/value.pass.cpp:
* The standard does not forbid initializing std::any from any 
pointer-to-function type. Remove the non-conforming "DecayTag" test.

test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp:
* Self-swap is not specified to perform no moves; check with LIBCPP_ASSERT.

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


Modified:
libcxx/trunk/test/std/utilities/any/any.class/any.cons/move.pass.cpp
libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp
libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp

Modified: libcxx/trunk/test/std/utilities/any/any.class/any.cons/move.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/any/any.class/any.cons/move.pass.cpp?rev=285234&r1=285233&r2=285234&view=diff
==
--- libcxx/trunk/test/std/utilities/any/any.class/any.cons/move.pass.cpp 
(original)
+++ libcxx/trunk/test/std/utilities/any/any.class/any.cons/move.pass.cpp Wed 
Oct 26 15:18:13 2016
@@ -80,8 +80,8 @@ void test_move() {
 assert(Type::moved == 1 || Type::moved == 2); // zero or more move 
operations can be performed.
 assert(Type::copied == 0); // no copies can be performed.
 assert(Type::count == 1 + a.has_value());
-assertEmpty(a); // Moves are always destructive.
 assertContains(a2, 42);
+LIBCPP_ASSERT(!a.has_value()); // Moves are always destructive.
 if (a.has_value())
 assertContains(a, 0);
 }

Modified: libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp?rev=285234&r1=285233&r2=285234&view=diff
==
--- libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp 
(original)
+++ libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp Wed 
Oct 26 15:18:13 2016
@@ -137,10 +137,6 @@ void test_sfinae_constraints() {
 static_assert(!std::is_constructible::value, "");
 }
 {
-using DecayTag = std::decay_t;
-static_assert(!std::is_constructible::value, "");
-}
-{
 // Test that the ValueType&& constructor SFINAE's away when the
 // argument is non-copyable
 struct NoCopy {

Modified: 
libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp?rev=285234&r1=285233&r2=285234&view=diff
==
--- libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp 
(original)
+++ libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp 
Wed Oct 26 15:18:13 2016
@@ -104,7 +104,7 @@ void test_self_swap() {
 assertContains(a, 42);
 assert(T::count == 1);
 assert(T::copied == 0);
-assert(T::moved == 0);
+LIBCPP_ASSERT(T::moved == 0);
 }
 assert(small::count == 0);
 { // large
@@ -113,9 +113,9 @@ void test_self_swap() {
 T::reset();
 a.swap(a);
 assertContains(a, 42);
-assert(T::copied == 0);
-assert(T::moved == 0);
 assert(T::count == 1);
+assert(T::copied == 0);
+LIBCPP_ASSERT(T::moved == 0);
 }
 assert(large::count == 0);
 }


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


[PATCH] D26007: [libc++] Cleanup non-portable std::any tests

2016-10-26 Thread Casey Carter via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285234: Cleanup nonportable behavior in tests for std::any 
(authored by CaseyCarter).

Changed prior to commit:
  https://reviews.llvm.org/D26007?vs=75936&id=75938#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26007

Files:
  libcxx/trunk/test/std/utilities/any/any.class/any.cons/move.pass.cpp
  libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp
  libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp


Index: libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp
===
--- libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp
+++ libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp
@@ -137,10 +137,6 @@
 static_assert(!std::is_constructible::value, "");
 }
 {
-using DecayTag = std::decay_t;
-static_assert(!std::is_constructible::value, "");
-}
-{
 // Test that the ValueType&& constructor SFINAE's away when the
 // argument is non-copyable
 struct NoCopy {
Index: libcxx/trunk/test/std/utilities/any/any.class/any.cons/move.pass.cpp
===
--- libcxx/trunk/test/std/utilities/any/any.class/any.cons/move.pass.cpp
+++ libcxx/trunk/test/std/utilities/any/any.class/any.cons/move.pass.cpp
@@ -80,8 +80,8 @@
 assert(Type::moved == 1 || Type::moved == 2); // zero or more move 
operations can be performed.
 assert(Type::copied == 0); // no copies can be performed.
 assert(Type::count == 1 + a.has_value());
-assertEmpty(a); // Moves are always destructive.
 assertContains(a2, 42);
+LIBCPP_ASSERT(!a.has_value()); // Moves are always destructive.
 if (a.has_value())
 assertContains(a, 0);
 }
Index: libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
===
--- libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
+++ libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
@@ -104,18 +104,18 @@
 assertContains(a, 42);
 assert(T::count == 1);
 assert(T::copied == 0);
-assert(T::moved == 0);
+LIBCPP_ASSERT(T::moved == 0);
 }
 assert(small::count == 0);
 { // large
 using T = large;
 any a{T{42}};
 T::reset();
 a.swap(a);
 assertContains(a, 42);
-assert(T::copied == 0);
-assert(T::moved == 0);
 assert(T::count == 1);
+assert(T::copied == 0);
+LIBCPP_ASSERT(T::moved == 0);
 }
 assert(large::count == 0);
 }


Index: libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp
===
--- libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp
+++ libcxx/trunk/test/std/utilities/any/any.class/any.cons/value.pass.cpp
@@ -137,10 +137,6 @@
 static_assert(!std::is_constructible::value, "");
 }
 {
-using DecayTag = std::decay_t;
-static_assert(!std::is_constructible::value, "");
-}
-{
 // Test that the ValueType&& constructor SFINAE's away when the
 // argument is non-copyable
 struct NoCopy {
Index: libcxx/trunk/test/std/utilities/any/any.class/any.cons/move.pass.cpp
===
--- libcxx/trunk/test/std/utilities/any/any.class/any.cons/move.pass.cpp
+++ libcxx/trunk/test/std/utilities/any/any.class/any.cons/move.pass.cpp
@@ -80,8 +80,8 @@
 assert(Type::moved == 1 || Type::moved == 2); // zero or more move operations can be performed.
 assert(Type::copied == 0); // no copies can be performed.
 assert(Type::count == 1 + a.has_value());
-assertEmpty(a); // Moves are always destructive.
 assertContains(a2, 42);
+LIBCPP_ASSERT(!a.has_value()); // Moves are always destructive.
 if (a.has_value())
 assertContains(a, 0);
 }
Index: libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
===
--- libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
+++ libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/swap.pass.cpp
@@ -104,18 +104,18 @@
 assertContains(a, 42);
 assert(T::count == 1);
 assert(T::copied == 0);
-assert(T::moved == 0);
+LIBCPP_ASSERT(T::moved == 0);
 }
 assert(small::count == 0);
 { // large
 using T = large;
 any a{T{42}};
 T::reset();
 a.swap(a);
 assertContains(a, 42);
-assert(T::copied == 0);
-assert(T::moved == 0);
 assert(T::count == 1

[PATCH] D26007: [libc++] Cleanup non-portable std::any tests

2016-10-26 Thread Eric Fiselier via cfe-commits
EricWF added inline comments.



Comment at: test/libcxx/utilities/any/any.class/any.cons/value.pass.cpp:36
+using DecayTag = std::decay_t;
+static_assert(!std::is_constructible::value, "");
+}

CaseyCarter wrote:
> I'm generously calling this a "libc++ extension." From my interpretation of 
> N4606, LWG2744, and LWG2754, this appears to be a bug.
I agree. I want this to be a diagnostic of some sort. Preferably a static 
warning because if you've managed to decay the tags your in for a treat.


Repository:
  rL LLVM

https://reviews.llvm.org/D26007



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


[PATCH] D25483: [libcxx] [test] Fix non-Standard assumptions about how many elements are allocated

2016-10-26 Thread Eric Fiselier via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

LGTM. I appreciate the doc for each of the magic numbers.


https://reviews.llvm.org/D25483



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


r285239 - [RecursiveASTVisitor] Visit the implicit expression of a CXXDefaultArgExpr

2016-10-26 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Wed Oct 26 15:39:54 2016
New Revision: 285239

URL: http://llvm.org/viewvc/llvm-project?rev=285239&view=rev
Log:
[RecursiveASTVisitor] Visit the implicit expression of a CXXDefaultArgExpr

Summary:
The matcher
varDecl(hasDescendant(
callExpr(hasDeclaration(functionDecl(unless(isNoThrow()))
didn't match calls from default arguments because the expression
for a CXXDefaultArgExpr was not visited.

Reviewers: klimek, jdennett, alexfh, aaron.ballman

Subscribers: aaron.ballman, cfe-commits

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

Modified:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=285239&r1=285238&r2=285239&view=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Wed Oct 26 15:39:54 2016
@@ -2354,7 +2354,10 @@ DEF_TRAVERSE_STMT(CompoundLiteralExpr, {
 })
 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
-DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {})
+DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {
+  if (getDerived().shouldVisitImplicitCode())
+TRY_TO(TraverseStmt(S->getExpr()));
+})
 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
 DEF_TRAVERSE_STMT(ExprWithCleanups, {})

Modified: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp?rev=285239&r1=285238&r2=285239&view=diff
==
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp Wed Oct 26 15:39:54 
2016
@@ -152,4 +152,21 @@ TEST(RecursiveASTVisitor, ArrayInitializ
   "};\n"));
 }
 
+// Check to ensure that implicit default argument expressions are visited.
+class IntegerLiteralVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool VisitIntegerLiteral(const IntegerLiteral *IL) {
+Match("literal", IL->getLocation());
+return true;
+  }
+};
+
+TEST(RecursiveASTVisitor, DefaultArgumentsAreVisited) {
+  IntegerLiteralVisitor Visitor;
+  Visitor.ExpectMatch("literal", 1, 15, 2);
+  EXPECT_TRUE(Visitor.runOver("int f(int i = 1);\n"
+  "static int k = f();\n"));
+}
+
 } // end anonymous namespace


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


[PATCH] D25992: [RecursiveASTVisitor] Visit the implicit expression of a CXXDefaultArgExpr

2016-10-26 Thread Malcolm Parsons via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL285239: [RecursiveASTVisitor] Visit the implicit expression 
of a CXXDefaultArgExpr (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D25992?vs=75899&id=75944#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25992

Files:
  cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
  cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp


Index: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
===
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -152,4 +152,21 @@
   "};\n"));
 }
 
+// Check to ensure that implicit default argument expressions are visited.
+class IntegerLiteralVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool VisitIntegerLiteral(const IntegerLiteral *IL) {
+Match("literal", IL->getLocation());
+return true;
+  }
+};
+
+TEST(RecursiveASTVisitor, DefaultArgumentsAreVisited) {
+  IntegerLiteralVisitor Visitor;
+  Visitor.ExpectMatch("literal", 1, 15, 2);
+  EXPECT_TRUE(Visitor.runOver("int f(int i = 1);\n"
+  "static int k = f();\n"));
+}
+
 } // end anonymous namespace
Index: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
===
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
@@ -2354,7 +2354,10 @@
 })
 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
-DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {})
+DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {
+  if (getDerived().shouldVisitImplicitCode())
+TRY_TO(TraverseStmt(S->getExpr()));
+})
 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
 DEF_TRAVERSE_STMT(ExprWithCleanups, {})


Index: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
===
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -152,4 +152,21 @@
   "};\n"));
 }
 
+// Check to ensure that implicit default argument expressions are visited.
+class IntegerLiteralVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool VisitIntegerLiteral(const IntegerLiteral *IL) {
+Match("literal", IL->getLocation());
+return true;
+  }
+};
+
+TEST(RecursiveASTVisitor, DefaultArgumentsAreVisited) {
+  IntegerLiteralVisitor Visitor;
+  Visitor.ExpectMatch("literal", 1, 15, 2);
+  EXPECT_TRUE(Visitor.runOver("int f(int i = 1);\n"
+  "static int k = f();\n"));
+}
+
 } // end anonymous namespace
Index: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
===
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
@@ -2354,7 +2354,10 @@
 })
 DEF_TRAVERSE_STMT(CXXBindTemporaryExpr, {})
 DEF_TRAVERSE_STMT(CXXBoolLiteralExpr, {})
-DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {})
+DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {
+  if (getDerived().shouldVisitImplicitCode())
+TRY_TO(TraverseStmt(S->getExpr()));
+})
 DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
 DEF_TRAVERSE_STMT(ExprWithCleanups, {})
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D23754: cmake: Add CLANG_GOLD_LIBDIR_SUFFIX to specify loc of LLVMgold.so

2016-10-26 Thread Chris Bieneman via cfe-commits
beanz added a comment.

@mgorny, I don't think LLVMgold qualifies as a runtime in the traditional 
sense. It more closely aligns with the tools vended by LLVM even though it is a 
shared library not an executable.

Runtime libraries are specifically libraries that products of clang are linked 
against (builtins, sanitizers, libcxx, libunwind...).

That bit of semantics aside, I don't think there is any situation where 
LLVMgold's libdir suffix would be different from LLVM's libdir suffix. Since 
LLVMgold is built and installed as part of LLVM, there is no mechanism (nor do 
I think there should be) to cause such a differentiation.

@rafael may disagree, and I will defer to his judgment if he does. My take is 
that we should just use LLVM_LIBDIR_SUFFIX for LLVMgold, and not have a 
separate variable.


https://reviews.llvm.org/D23754



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


[PATCH] D18172: [CUDA][OpenMP] Add a generic offload action builder

2016-10-26 Thread Justin Lebar via cfe-commits
jlebar added a comment.

Hi, Samuel.

This change introduced a new crash / assertion failure in the driver.

  $ echo | llvm-run clang -emit-llvm -c -x cuda - -o /dev/null

Before this patch, we get an error (perhaps not as helpful as we might want, 
but still):

  clang-3.8: error: cannot specify -o when generating multiple output files

After this patch, we get an assertion failure:

  clang: ../clang/lib/Driver/Driver.cpp:1610: virtual (anonymous 
namespace)::OffloadingActionBuilder::DeviceActionBuilder::ActionBuilderReturnCode
 (anonymous 
namespace)::OffloadingActionBuilder::CudaActionBuilder::getDeviceDepences(OffloadAction::DeviceDependences
 &, phases::ID, phases::ID, PhasesTy &): Assertion `CurPhase < phases::Backend 
&& "Generating single CUDA " "instructions should only occur " "before the 
backend phase!"' failed.
  #0 0x01b07e28 llvm::sys::PrintStackTrace(llvm::raw_ostream&) 
(/usr/local/google/home/jlebar/llvm/release/bin/clang+0x1b07e28)
  #1 0x01b08566 SignalHandler(int) 
(/usr/local/google/home/jlebar/llvm/release/bin/clang+0x1b08566)
  #2 0x7f4bb7f89330 __restore_rt 
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
  #3 0x7f4bb6b7cc37 gsignal 
/build/eglibc-oGUzwX/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
  #4 0x7f4bb6b80028 abort 
/build/eglibc-oGUzwX/eglibc-2.19/stdlib/abort.c:91:0
  #5 0x7f4bb6b75bf6 __assert_fail_base 
/build/eglibc-oGUzwX/eglibc-2.19/assert/assert.c:92:0
  #6 0x7f4bb6b75ca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
  #7 0x01fa809b 
(/usr/local/google/home/jlebar/llvm/release/bin/clang+0x1fa809b)
  #8 0x01f99981 
clang::driver::Driver::BuildActions(clang::driver::Compilation&, 
llvm::opt::DerivedArgList&, 
llvm::SmallVector, 
16u> const&, llvm::SmallVector&) const 
(/usr/local/google/home/jlebar/llvm/release/bin/clang+0x1f99981)
  #9 0x01f9431c 
clang::driver::Driver::BuildCompilation(llvm::ArrayRef) 
(/usr/local/google/home/jlebar/llvm/release/bin/clang+0x1f9431c)
  #10 0x007c0254 main 
(/usr/local/google/home/jlebar/llvm/release/bin/clang+0x7c0254)
  #11 0x7f4bb6b67f45 __libc_start_main 
/build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:321:0
  #12 0x007bd9a2 _start 
(/usr/local/google/home/jlebar/llvm/release/bin/clang+0x7bd9a2)
  Stack dump:
  0.Program arguments: /usr/local/google/home/jlebar/llvm/release/bin/clang 
-emit-llvm -c -x cuda - -o /dev/null 
  1.Compilation construction
  2.Building compilation actions
  Aborted (core dumped)

This was reported two weeks ago by Gurunath Kadam on cfe-dev, but I just got 
around to bisecting it.

Would you mind spinning a fix for this?


Repository:
  rL LLVM

https://reviews.llvm.org/D18172



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


[PATCH] D23754: cmake: Add CLANG_GOLD_LIBDIR_SUFFIX to specify loc of LLVMgold.so

2016-10-26 Thread Michał Górny via cfe-commits
mgorny added a comment.

In https://reviews.llvm.org/D23754#580268, @beanz wrote:

> @mgorny, I don't think LLVMgold qualifies as a runtime in the traditional 
> sense. It more closely aligns with the tools vended by LLVM even though it is 
> a shared library not an executable.
>
> Runtime libraries are specifically libraries that products of clang are 
> linked against (builtins, sanitizers, libcxx, libunwind...).
>
> That bit of semantics aside, I don't think there is any situation where 
> LLVMgold's libdir suffix would be different from LLVM's libdir suffix. Since 
> LLVMgold is built and installed as part of LLVM, there is no mechanism (nor 
> do I think there should be) to cause such a differentiation.
>
> @rafael may disagree, and I will defer to his judgment if he does. My take is 
> that we should just use LLVM_LIBDIR_SUFFIX for LLVMgold, and not have a 
> separate variable.


The difference is that LLVMgold.so is not used by LLVM or clang directly but by 
the system binutils, and so it must match the ABI of the linker. If you have 
32-bit libclang*, LLVM_LIBDIR_SUFFIX is 32 but ld is still a 64-bit executable 
that needs 64-bit LLVMgold.so.


https://reviews.llvm.org/D23754



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


[PATCH] D25985: [analyzer] Export coverage information from the analyzer.

2016-10-26 Thread Anna Zaks via cfe-commits
zaks.anna added a comment.

Please, add multi-file tests and tests where a line is covered more than once.




Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:262
+
+static void dumpCoverageInfo(llvm::SmallVectorImpl &Path,
+ SourceManager &SM) {

Can this be a debug checker?



Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:274
+if (Invalid)
+  continue;
+std::ofstream OutFile(FilePath.c_str());

Would it be better to break if the buffer is invalid?
Should this be hoisted out of the loop?



Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:277
+if (!OutFile) {
+  llvm::errs() << FilePath << " Fuck!\n";
+  continue;

Please, come up with constructive error messages.



Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:281
+llvm::raw_os_ostream Out(OutFile);
+Out << "-:0:Source:" << FE->getName() << '\n';
+Out << "-:0:Runs:1\n";

What does '-' mean in this case? Why is it needed?



Comment at: test/Analysis/record-coverage.cpp.expected:2
+// CHECK:  -:4:int main() {
+// CHECK-NEXT: -:5:  int i = 2;
+// CHECK-NEXT: 1:6:  ++i;

Does '-' mean not covered? If so, why the first 2 statements are not covered?


https://reviews.llvm.org/D25985



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


[PATCH] D25898: [clang-tidy] Enhance modernize-make-unique to handle unique_ptr.reset()

2016-10-26 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 75947.
malcolm.parsons added a comment.

Remove braces.
Use Twine.


https://reviews.llvm.org/D25898

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/modernize-make-shared.rst
  docs/clang-tidy/checks/modernize-make-unique.rst
  test/clang-tidy/modernize-make-shared.cpp
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -8,6 +8,7 @@
 template >
 class unique_ptr {
 public:
+  unique_ptr();
   unique_ptr(type *ptr);
   unique_ptr(const unique_ptr &t) = delete;
   unique_ptr(unique_ptr &&t);
@@ -17,11 +18,13 @@
   type *release();
   void reset();
   void reset(type *pt);
+  unique_ptr &operator=(unique_ptr &&);
+  template 
+  unique_ptr &operator=(unique_ptr &&);
 
 private:
   type *ptr;
 };
-
 }
 
 struct Base {
@@ -46,7 +49,8 @@
 
 struct Empty {};
 
-template using unique_ptr_ = std::unique_ptr;
+template 
+using unique_ptr_ = std::unique_ptr;
 
 void *operator new(__SIZE_TYPE__ Count, void *Ptr);
 
@@ -63,11 +67,27 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use std::make_unique instead [modernize-make-unique]
   // CHECK-FIXES: std::unique_ptr P1 = std::make_unique();
 
+  P1.reset(new int());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique]
+  // CHECK-FIXES: P1 = std::make_unique();
+
+  P1 = std::unique_ptr(new int());
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use std::make_unique instead [modernize-make-unique]
+  // CHECK-FIXES: P1 = std::make_unique();
+
   // Without parenthesis.
   std::unique_ptr P2 = std::unique_ptr(new int);
   // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use std::make_unique instead [modernize-make-unique]
   // CHECK-FIXES: std::unique_ptr P2 = std::make_unique();
 
+  P2.reset(new int);
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead [modernize-make-unique]
+  // CHECK-FIXES: P2 = std::make_unique();
+
+  P2 = std::unique_ptr(new int);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use std::make_unique instead [modernize-make-unique]
+  // CHECK-FIXES: P2 = std::make_unique();
+
   // With auto.
   auto P3 = std::unique_ptr(new int());
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead
@@ -79,6 +99,10 @@
 unique_ptr Q = unique_ptr(new int());
 // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use std::make_unique instead
 // CHECK-FIXES: unique_ptr Q = std::make_unique();
+
+Q = unique_ptr(new int());
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use std::make_unique instead
+// CHECK-FIXES: Q = std::make_unique();
   }
 
   std::unique_ptr R(new int());
@@ -88,19 +112,36 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead
   // CHECK-FIXES: int T = g(std::make_unique());
 
-  // Only replace if the type in the template is the same than the type returned
+  // Only replace if the type in the template is the same as the type returned
   // by the new operator.
   auto Pderived = std::unique_ptr(new Derived());
 
+  // OK to replace for reset and assign
+  Pderived.reset(new Derived());
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use std::make_unique instead
+  // CHECK-FIXES: Pderived = std::make_unique();
+
+  Pderived = std::unique_ptr(new Derived());
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use std::make_unique instead
+  // CHECK-FIXES: Pderived = std::make_unique();
+
+  // FIXME: OK to replace if assigned to unique_ptr
+  Pderived = std::unique_ptr(new Derived());
+
+  // FIXME: OK to replace when auto is not used
+  std::unique_ptr PBase = std::unique_ptr(new Derived());
+
   // The pointer is returned by the function, nothing to do.
   std::unique_ptr RetPtr = getPointer();
 
   // This emulates std::move.
-  std::unique_ptr Move = static_cast&&>(P1);
+  std::unique_ptr Move = static_cast &&>(P1);
 
-  // Placemenet arguments should not be removed.
+  // Placement arguments should not be removed.
   int *PInt = new int;
   std::unique_ptr Placement = std::unique_ptr(new (PInt) int{3});
+  Placement.reset(new (PInt) int{3});
+  Placement = std::unique_ptr(new (PInt) int{3});
 }
 
 // Calling make_smart_ptr from within a member function of a type with a
@@ -116,6 +157,8 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_unique instead
 // CHECK-FIXES: auto callsPublic = std::make_unique();
 auto ptr = std::unique_ptr(new Private(42));
+ptr.reset(new Private(42));
+ptr = std::unique_ptr(new Private(42));
   }
 
   virtual ~Private();
@@ -132,6 +175,8 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_unique instead
 // CHECK-FIXES: auto callsPublic = std::make_unique(1, 2);
 auto ptr = std::unique_p

[PATCH] D25204: Register Calling Convention, Clang changes

2016-10-26 Thread Joerg Sonnenberger via cfe-commits
joerg added a comment.

Can we please avoid adding more (pseudo) keywords in the double-underscore name 
space? Those tend to be used a lot by existing libc implementations and 
existing attribute cases like __strong and __weak have created enough trouble.


https://reviews.llvm.org/D25204



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


[PATCH] D18172: [CUDA][OpenMP] Add a generic offload action builder

2016-10-26 Thread Samuel Antao via cfe-commits
sfantao added a comment.

Hi Justin

Thanks for letting me know. I'm looking into it.

Thanks again,
Samuel


Repository:
  rL LLVM

https://reviews.llvm.org/D18172



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


[PATCH] D25985: [analyzer] Export coverage information from the analyzer.

2016-10-26 Thread Anna Zaks via cfe-commits
zaks.anna added inline comments.



Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:274
+if (Invalid)
+  continue;
+std::ofstream OutFile(FilePath.c_str());

zaks.anna wrote:
> Would it be better to break if the buffer is invalid?
> Should this be hoisted out of the loop?
I see why this cannot be hoisted.


https://reviews.llvm.org/D25985



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


[PATCH] D25925: [clang-tidy] Update cert-err58-cpp to match its new generalised form.

2016-10-26 Thread Malcolm Parsons via cfe-commits
malcolm.parsons updated this revision to Diff 75951.
malcolm.parsons added a comment.

Add more tests.


https://reviews.llvm.org/D25925

Files:
  clang-tidy/cert/StaticObjectExceptionCheck.cpp
  docs/clang-tidy/checks/cert-err58-cpp.rst
  test/clang-tidy/cert-static-object-exception.cpp

Index: test/clang-tidy/cert-static-object-exception.cpp
===
--- test/clang-tidy/cert-static-object-exception.cpp
+++ test/clang-tidy/cert-static-object-exception.cpp
@@ -16,39 +16,87 @@
   explicit V(const char *) {} // Can throw
 };
 
-struct Cleanup
-{
+struct Cleanup {
   ~Cleanup() {}
 };
 
 struct W {
   W(Cleanup c = {}) noexcept(false);
 };
 
+struct X {
+  X(S = {}) noexcept;
+};
+
+struct Y {
+  S s;
+};
+
+struct Z {
+  T t;
+};
+
+int f();
+int g() noexcept(false);
+int h() noexcept(true);
+
+struct UserConv_Bad {
+  operator int() noexcept(false);
+};
+
+struct UserConv_Good {
+  operator int() noexcept;
+};
+
+UserConv_Bad some_bad_func() noexcept;
+UserConv_Good some_good_func() noexcept;
 
 S s;
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 's' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 's' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
 // CHECK-MESSAGES: 4:3: note: possibly throwing constructor declared here
 T t; // ok
 U u;
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'u' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 'u' with static storage duration may throw an exception that cannot be caught
 // CHECK-MESSAGES: 12:3: note: possibly throwing constructor declared here
 V v("v");
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 'v' with static storage duration may throw an exception that cannot be caught
 // CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
 W w;
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
-// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 'w' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 24:3: note: possibly throwing constructor declared here
+X x1(S{});
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 'x1' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 4:3: note: possibly throwing constructor declared here
+X x2;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 'x2' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 4:3: note: possibly throwing constructor declared here
+Y y;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 'y' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 31:8: note: possibly throwing constructor declared here
+Z z;
+
+int i = f();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: initialization of 'i' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 39:5: note: possibly throwing function declared here
+int j = g();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: initialization of 'j' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 40:5: note: possibly throwing function declared here
+int k = h();
+int l = some_bad_func();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: initialization of 'l' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 44:3: note: possibly throwing function declared here
+int m = some_good_func();
+
 
 thread_local S s3;
-// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 's3' with thread_local storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: initialization of 's3' with thread_local storage duration may throw an exception that cannot be caught
 thread_local T t3; // ok
 thread_local U u3;
-// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'u3' with thread_local storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: initialization of 'u3' with thread_local storage duration may throw an exception that cannot be caught
 thread_local V v3("v");
-// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'v3' with thread_local storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: initialization of 'v3' with thread_local storage durati

[PATCH] D22346: [Clang-tidy] CERT-MSC50-CPP (std:rand() )

2016-10-26 Thread Benedek Kiss via cfe-commits
falho updated this revision to Diff 75935.
falho marked an inline comment as done.
falho added a comment.

removed semicolon, and replaced it with a comma that only appears in .cpp 
diagnostics
test cases corrected according to this

removed junk .swo file


https://reviews.llvm.org/D22346

Files:
  clang-tidy/cert/CERTTidyModule.cpp
  clang-tidy/cert/CMakeLists.txt
  clang-tidy/cert/LimitedRandomnessCheck.cpp
  clang-tidy/cert/LimitedRandomnessCheck.h
  docs/clang-tidy/checks/cert-msc30-c.rst
  docs/clang-tidy/checks/cert-msc50-cpp.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cert-limited-randomness.c
  test/clang-tidy/cert-limited-randomness.cpp

Index: test/clang-tidy/cert-limited-randomness.cpp
===
--- /dev/null
+++ test/clang-tidy/cert-limited-randomness.cpp
@@ -0,0 +1,28 @@
+// RUN: %check_clang_tidy %s cert-msc50-cpp %t
+
+int rand();
+int rand(int);
+
+namespace std {
+using ::rand;
+}
+
+namespace nonstd {
+  int rand();
+}
+
+void testFunction1() {
+  int i = std::rand();
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness, use C++11 random library instead [cert-msc50-cpp]
+
+  int j = ::rand();
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness, use C++11 random library instead [cert-msc50-cpp]
+
+  int k = rand(i);
+
+  int l = nonstd::rand();
+
+  int m = rand();
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness, use C++11 random library instead [cert-msc50-cpp]
+}
+
Index: test/clang-tidy/cert-limited-randomness.c
===
--- /dev/null
+++ test/clang-tidy/cert-limited-randomness.c
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s cert-msc30-c %t
+
+extern int rand(void);
+int nonrand();
+
+int cTest() {
+  int i = rand();
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: rand() has limited randomness [cert-msc30-c]
+
+  int k = nonrand();
+
+  return 0;
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -18,6 +18,8 @@
cert-err61-cpp (redirects to misc-throw-by-value-catch-by-reference) 
cert-fio38-c (redirects to misc-non-copyable-objects) 
cert-flp30-c
+   cert-msc30-c (redirects to cert-limited-randomness) 
+   cert-msc50-cpp
cert-oop11-cpp (redirects to misc-move-constructor-init) 
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-pro-bounds-array-to-pointer-decay
Index: docs/clang-tidy/checks/cert-msc50-cpp.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cert-msc50-cpp.rst
@@ -0,0 +1,6 @@
+.. title:: clang-tidy - cert-msc50-cpp
+
+cert-msc50-cpp
+==
+
+Pseudorandom number generators use mathematical algorithms to produce a sequence of numbers with good statistical properties, but the numbers produced are not genuinely random. The ``std::rand()`` function takes a seed (number), runs a mathematical operation on it and returns the result. By manipulating the seed the result can be predictible. This check warns for the usage of ``std::rand()``.
Index: docs/clang-tidy/checks/cert-msc30-c.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cert-msc30-c.rst
@@ -0,0 +1,7 @@
+.. title:: clang-tidy - cert-msc30-c
+
+cert-msc30-c
+
+
+The cert-msc30-c check is an alias, please see
+`cert-msc50-cpp `_ for more information.
Index: clang-tidy/cert/LimitedRandomnessCheck.h
===
--- /dev/null
+++ clang-tidy/cert/LimitedRandomnessCheck.h
@@ -0,0 +1,38 @@
+//===--- LimitedRandomnessCheck.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_LIMITED_RANDOMNESS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_LIMITED_RANDOMNESS_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace cert {
+
+/// Pseudorandom number generators are not genuinely random. The result of the
+/// std::rand() function makes no guarantees as to the quality of the random
+/// sequence produced.
+/// This check warns for the usage of std::rand() function.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/cert-msc50-cpp.html
+class LimitedRandomnessCheck : public ClangTidyCheck {
+public:
+  LimitedRandomnessCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void 

[PATCH] D22346: [Clang-tidy] CERT-MSC50-CPP (std:rand() )

2016-10-26 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D22346#580242, @falho wrote:

> removed semicolon, and replaced it with a comma that only appears in .cpp 
> diagnostics


The semicolon was the correct punctuator to use, but thank you for moving it 
into the cpp message.

> test cases corrected according to this
> 
> removed junk .swo file

Thanks!




Comment at: clang-tidy/cert/LimitedRandomnessCheck.cpp:30
+  if (getLangOpts().CPlusPlus) {
+msg = ", use C++11 random library instead";
+  }

Switch the "," to ";", and remove the curly braces.


https://reviews.llvm.org/D22346



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


[PATCH] D25925: [clang-tidy] Update cert-err58-cpp to match its new generalised form.

2016-10-26 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you!


https://reviews.llvm.org/D25925



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


[PATCH] D21840: [Driver][CUDA][OpenMP] Reimplement tool selection in the driver.

2016-10-26 Thread Hal Finkel via cfe-commits
hfinkel accepted this revision.
hfinkel added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D21840



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


[PATCH] D21843: [Driver][OpenMP] Create tool chains for OpenMP offloading kind.

2016-10-26 Thread Hal Finkel via cfe-commits
hfinkel accepted this revision.
hfinkel added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D21843



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


[PATCH] D25556: [Sema] Add variable captured by a block to the enclosing lambda's potential capture list

2016-10-26 Thread Akira Hatanaka via cfe-commits
ahatanak updated this revision to Diff 75956.
ahatanak added a comment.

Add the variable to the list of potential captures only if it's declared 
outside of the lambda expression. I don't think we need to check that the 
variable is declared outside of the lambda because 
getStackIndexOfNearestEnclosingCaptureCapableLambda will prevent it from being 
captured, but it's better not to add the variable to the list needlessly.


https://reviews.llvm.org/D25556

Files:
  include/clang/Sema/Sema.h
  lib/Sema/Sema.cpp
  lib/Sema/SemaExpr.cpp
  test/SemaObjCXX/blocks.mm


Index: test/SemaObjCXX/blocks.mm
===
--- test/SemaObjCXX/blocks.mm
+++ test/SemaObjCXX/blocks.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class 
-std=c++14 %s
 @protocol NSObject;
 
 void bar(id(^)(void));
@@ -144,3 +144,14 @@
 
   template void f(X);
 }
+
+namespace GenericLambdaCapture {
+  int test(int outerp) {
+auto lambda =[&](auto p) {
+  return ^{
+return p + outerp;
+  }();
+};
+return lambda(1);
+  }
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14013,7 +14013,8 @@
 (SemaRef.CurContext != Var->getDeclContext() &&
  Var->getDeclContext()->isFunctionOrMethod() && 
Var->hasLocalStorage());
 if (RefersToEnclosingScope) {
-  if (LambdaScopeInfo *const LSI = SemaRef.getCurLambda()) {
+  LambdaScopeInfo *const LSI = SemaRef.getInnermostLambda();
+  if (LSI && !LSI->CallOperator->Encloses(Var->getDeclContext())) {
 // If a variable could potentially be odr-used, defer marking it so
 // until we finish analyzing the full expression for any
 // lvalue-to-rvalue
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -1220,6 +1220,13 @@
   return nullptr;
 }
 
+LambdaScopeInfo *Sema::getInnermostLambda() {
+  for (auto I = FunctionScopes.rbegin(), E = FunctionScopes.rend(); I != E; 
++I)
+if (auto LSI = dyn_cast(*I))
+  return LSI;
+
+  return nullptr;
+}
 
 void Sema::ActOnComment(SourceRange Comment) {
   if (!LangOpts.RetainCommentsFromSystemHeaders &&
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -1247,6 +1247,9 @@
   /// \brief Retrieve the current generic lambda info, if any.
   sema::LambdaScopeInfo *getCurGenericLambda();
 
+  /// Retrieve the innermost lambda scope info, if any.
+  sema::LambdaScopeInfo *getInnermostLambda();
+
   /// \brief Retrieve the current captured region, if any.
   sema::CapturedRegionScopeInfo *getCurCapturedRegion();
 


Index: test/SemaObjCXX/blocks.mm
===
--- test/SemaObjCXX/blocks.mm
+++ test/SemaObjCXX/blocks.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class -std=c++14 %s
 @protocol NSObject;
 
 void bar(id(^)(void));
@@ -144,3 +144,14 @@
 
   template void f(X);
 }
+
+namespace GenericLambdaCapture {
+  int test(int outerp) {
+auto lambda =[&](auto p) {
+  return ^{
+return p + outerp;
+  }();
+};
+return lambda(1);
+  }
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14013,7 +14013,8 @@
 (SemaRef.CurContext != Var->getDeclContext() &&
  Var->getDeclContext()->isFunctionOrMethod() && Var->hasLocalStorage());
 if (RefersToEnclosingScope) {
-  if (LambdaScopeInfo *const LSI = SemaRef.getCurLambda()) {
+  LambdaScopeInfo *const LSI = SemaRef.getInnermostLambda();
+  if (LSI && !LSI->CallOperator->Encloses(Var->getDeclContext())) {
 // If a variable could potentially be odr-used, defer marking it so
 // until we finish analyzing the full expression for any
 // lvalue-to-rvalue
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -1220,6 +1220,13 @@
   return nullptr;
 }
 
+LambdaScopeInfo *Sema::getInnermostLambda() {
+  for (auto I = FunctionScopes.rbegin(), E = FunctionScopes.rend(); I != E; ++I)
+if (auto LSI = dyn_cast(*I))
+  return LSI;
+
+  return nullptr;
+}
 
 void Sema::ActOnComment(SourceRange Comment) {
   if (!LangOpts.RetainCommentsFromSystemHeaders &&
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -1247,6 +1247,9 @@
   /// \brief Retrieve the current

  1   2   >